本文整理汇总了PHP中PodsForm::simple_tableless_objects方法的典型用法代码示例。如果您正苦于以下问题:PHP PodsForm::simple_tableless_objects方法的具体用法?PHP PodsForm::simple_tableless_objects怎么用?PHP PodsForm::simple_tableless_objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PodsForm
的用法示例。
在下文中一共展示了PodsForm::simple_tableless_objects方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: import
/**
* Import data from an array or a CSV file.
*
* @param mixed $import_data PHP associative array or CSV input
* @param bool $numeric_mode Use IDs instead of the name field when matching
* @param string $format Format of import data, options are php or csv
*
* @return array IDs of imported items
*
* @since 1.7.1
* @todo This needs some love and use of table_info etc for relationships
*/
public function import($import_data, $numeric_mode = false, $format = null)
{
/**
* @var $wpdb wpdb
*/
global $wpdb;
if (null === $format && null !== $this->format) {
$format = $this->format;
}
if ('csv' == $format && !is_array($import_data)) {
$data = pods_migrate('sv', ',')->parse($import_data);
$import_data = $data['items'];
}
pods_query("SET NAMES utf8");
pods_query("SET CHARACTER SET utf8");
// Loop through the array of items
$ids = array();
// Test to see if it's an array of arrays
if (!is_array(@current($import_data))) {
$import_data = array($import_data);
}
$pod = $this->load_pod(array('name' => $this->pod));
if (false === $pod) {
return pods_error(__('Pod not found', 'pods'), $this);
}
$fields = array_merge($pod['fields'], $pod['object_fields']);
$simple_tableless_objects = PodsForm::simple_tableless_objects();
foreach ($import_data as $key => $data_row) {
$data = array();
// Loop through each field (use $fields so only valid fields get parsed)
foreach ($fields as $field_name => $field_data) {
if (!isset($data_row[$field_name]) && !isset($data_row[$field_data['label']])) {
continue;
}
$field_id = $field_data['id'];
$type = $field_data['type'];
$pick_object = isset($field_data['pick_object']) ? $field_data['pick_object'] : '';
$pick_val = isset($field_data['pick_val']) ? $field_data['pick_val'] : '';
if (isset($data_row[$field_name])) {
$field_value = $data_row[$field_name];
} else {
$field_value = $data_row[$field_data['label']];
}
if (null !== $field_value && false !== $field_value && '' !== $field_value) {
if ('pick' == $type || in_array($type, PodsForm::file_field_types())) {
$field_values = is_array($field_value) ? $field_value : array($field_value);
$pick_values = array();
foreach ($field_values as $pick_value) {
if (in_array($type, PodsForm::file_field_types()) || 'media' == $pick_object) {
$where = "`guid` = '" . pods_sanitize($pick_value) . "'";
if (0 < pods_absint($pick_value) && false !== $numeric_mode) {
$where = "`ID` = " . pods_absint($pick_value);
}
$result = pods_query("SELECT `ID` AS `id` FROM `{$wpdb->posts}` WHERE `post_type` = 'attachment' AND {$where} ORDER BY `ID`", $this);
if (!empty($result)) {
$pick_values[] = $result[0]->id;
}
} elseif ('pick' == $type) {
$related_pod = false;
if ('pod' == $pick_object) {
$related_pod = $this->load_pod(array('name' => $pick_val, 'table_info' => true), false);
}
if (empty($related_pod)) {
$related_pod = array('id' => 0, 'type' => $pick_object);
}
if (in_array('taxonomy', array($pick_object, $related_pod['type']))) {
$where = "`t`.`name` = '" . pods_sanitize($pick_value) . "'";
if (0 < pods_absint($pick_value) && false !== $numeric_mode) {
$where = "`tt`.`term_id` = " . pods_absint($pick_value);
}
$result = pods_query("SELECT `t`.`term_id` AS `id` FROM `{$wpdb->term_taxonomy}` AS `tt` LEFT JOIN `{$wpdb->terms}` AS `t` ON `t`.`term_id` = `tt`.`term_id` WHERE `taxonomy` = '{$pick_val}' AND {$where} ORDER BY `t`.`term_id`", $this);
if (!empty($result)) {
$pick_values[] = $result[0]->id;
}
} elseif (in_array('post_type', array($pick_object, $related_pod['type'])) || in_array('media', array($pick_object, $related_pod['type']))) {
$where = "`post_title` = '" . pods_sanitize($pick_value) . "'";
if (0 < pods_absint($pick_value) && false !== $numeric_mode) {
$where = "`ID` = " . pods_absint($pick_value);
}
$result = pods_query("SELECT `ID` AS `id` FROM `{$wpdb->posts}` WHERE `post_type` = '{$pick_val}' AND {$where} ORDER BY `ID`", $this);
if (!empty($result)) {
$pick_values[] = $result[0]->id;
}
} elseif (in_array('user', array($pick_object, $related_pod['type']))) {
$where = "`user_login` = '" . pods_sanitize($pick_value) . "'";
if (0 < pods_absint($pick_value) && false !== $numeric_mode) {
$where = "`ID` = " . pods_absint($pick_value);
}
//.........这里部分代码省略.........
示例2: traverse_recurse
/**
* Recursively join tables based on fields
*
* @param array $traverse_recurse Array of traversal options
*
* @return array Array of table joins
*
* @since 2.0
*/
function traverse_recurse($traverse_recurse)
{
global $wpdb;
$defaults = array('pod' => null, 'fields' => array(), 'joined' => 't', 'depth' => 0, 'joined_id' => 'id', 'joined_index' => 'id', 'params' => new stdClass(), 'last_table_info' => array());
$traverse_recurse = array_merge($defaults, $traverse_recurse);
$joins = array();
if (0 == $traverse_recurse['depth'] && !empty($traverse_recurse['pod']) && !empty($traverse_recurse['last_table_info']) && isset($traverse_recurse['last_table_info']['id'])) {
$pod_data = $traverse_recurse['last_table_info'];
} elseif (empty($traverse_recurse['pod'])) {
if (!empty($traverse_recurse['params']) && !empty($traverse_recurse['params']->table) && 0 === strpos($traverse_recurse['params']->table, $wpdb->prefix)) {
if ($wpdb->posts == $traverse_recurse['params']->table) {
$traverse_recurse['pod'] = 'post_type';
} elseif ($wpdb->terms == $traverse_recurse['params']->table) {
$traverse_recurse['pod'] = 'taxonomy';
} elseif ($wpdb->users == $traverse_recurse['params']->table) {
$traverse_recurse['pod'] = 'user';
} elseif ($wpdb->comments == $traverse_recurse['params']->table) {
$traverse_recurse['pod'] = 'comment';
} else {
return $joins;
}
$pod_data = array();
if (in_array($traverse_recurse['pod'], array('user', 'comment'))) {
$pod = $this->api->load_pod(array('name' => $traverse_recurse['pod'], 'table_info' => true));
if (!empty($pod) && $pod['type'] == $pod) {
$pod_data = $pod;
}
}
if (empty($pod_data)) {
$pod_data = array('id' => 0, 'name' => '_table_' . $traverse_recurse['pod'], 'type' => $traverse_recurse['pod'], 'storage' => 'taxonomy' == $traverse_recurse['pod'] ? 'none' : 'meta', 'fields' => array(), 'object_fields' => $this->api->get_wp_object_fields($traverse_recurse['pod']));
$pod_data = array_merge($this->api->get_table_info($traverse_recurse['pod'], ''), $pod_data);
}
$traverse_recurse['pod'] = $pod_data['name'];
} else {
return $joins;
}
} else {
$pod_data = $this->api->load_pod(array('name' => $traverse_recurse['pod'], 'table_info' => true), false);
if (empty($pod_data)) {
return $joins;
}
}
if (isset($pod_data['object_fields'])) {
$pod_data['fields'] = array_merge($pod_data['fields'], $pod_data['object_fields']);
}
$tableless_field_types = PodsForm::tableless_field_types();
$simple_tableless_objects = PodsForm::simple_tableless_objects();
$file_field_types = PodsForm::file_field_types();
if (!isset($this->traversal[$traverse_recurse['pod']])) {
$this->traversal[$traverse_recurse['pod']] = array();
}
if ((empty($pod_data['meta_table']) || $pod_data['meta_table'] == $pod_data['table']) && (empty($traverse_recurse['fields']) || empty($traverse_recurse['fields'][$traverse_recurse['depth']]))) {
return $joins;
}
$field = $traverse_recurse['fields'][$traverse_recurse['depth']];
$ignore_aliases = array('wpml_languages', 'polylang_languages');
$ignore_aliases = apply_filters('pods_data_traverse_recurse_ignore_aliases', $ignore_aliases, $field, $traverse_recurse, $this);
if (in_array($field, $ignore_aliases)) {
return $joins;
}
$meta_data_table = false;
if (!isset($pod_data['fields'][$field]) && 'd' == $field && isset($traverse_recurse['fields'][$traverse_recurse['depth'] - 1])) {
$field = $traverse_recurse['fields'][$traverse_recurse['depth'] - 1];
$field_type = 'pick';
if (isset($traverse_recurse['last_table_info']['pod']['fields'][$field])) {
$field_type = $traverse_recurse['last_table_info']['pod']['fields'][$field]['type'];
} elseif (isset($traverse_recurse['last_table_info']['pod']['object_fields'][$field])) {
$field_type = $traverse_recurse['last_table_info']['pod']['object_fields'][$field]['type'];
}
$pod_data['fields'][$field] = array('id' => 0, 'name' => $field, 'type' => $field_type, 'pick_object' => $traverse_recurse['last_table_info']['pod']['type'], 'pick_val' => $traverse_recurse['last_table_info']['pod']['name']);
$meta_data_table = true;
}
// Fallback to meta table if the pod type supports it
if (!isset($pod_data['fields'][$field])) {
$last = end($traverse_recurse['fields']);
if ('post_type' == $pod_data['type'] && !isset($pod_data['object_fields'])) {
$pod_data['object_fields'] = $this->api->get_wp_object_fields('post_type', $pod_data);
}
if ('post_type' == $pod_data['type'] && isset($pod_data['object_fields'][$field]) && in_array($pod_data['object_fields'][$field]['type'], $tableless_field_types)) {
$pod_data['fields'][$field] = $pod_data['object_fields'][$field];
} elseif ('meta_value' === $last && in_array($pod_data['type'], array('post_type', 'media', 'user', 'comment'))) {
$pod_data['fields'][$field] = PodsForm::field_setup(array('name' => $field));
} else {
if ('post_type' == $pod_data['type']) {
$pod_data['object_fields'] = $this->api->get_wp_object_fields('post_type', $pod_data, true);
if ('post_type' == $pod_data['type'] && isset($pod_data['object_fields'][$field]) && in_array($pod_data['object_fields'][$field]['type'], $tableless_field_types)) {
$pod_data['fields'][$field] = $pod_data['object_fields'][$field];
} else {
return $joins;
}
} else {
//.........这里部分代码省略.........
示例3: pods_serial_comma
/**
* Split an array into human readable text (Item, Item, and Item)
*
* @param array $value
* @param string $field
* @param array $fields
* @param string $and
* @param string $field_index
*
* @return string
*
* @since 2.0
*/
function pods_serial_comma($value, $field = null, $fields = null, $and = null, $field_index = null)
{
if (is_object($value)) {
$value = get_object_vars($value);
}
$defaults = array('field' => $field, 'fields' => $fields, 'and' => $and, 'field_index' => $field_index, 'separator' => ',', 'serial' => true);
if (is_array($field)) {
$defaults['field'] = null;
$params = array_merge($defaults, $field);
} else {
$params = $defaults;
}
$params = (object) $params;
$simple = false;
if (!empty($params->fields) && is_array($params->fields) && isset($params->fields[$params->field])) {
$params->field = $params->fields[$params->field];
$simple_tableless_objects = PodsForm::simple_tableless_objects();
if (!empty($params->field) && is_array($params->field) && in_array($params->field['type'], PodsForm::tableless_field_types())) {
if (in_array($params->field['type'], PodsForm::file_field_types())) {
if (null === $params->field_index) {
$params->field_index = 'guid';
}
} elseif (in_array($params->field['pick_object'], $simple_tableless_objects)) {
$simple = true;
} else {
$table = pods_api()->get_table_info($params->field['pick_object'], $params->field['pick_val'], null, null, $params->field);
if (!empty($table)) {
if (null === $params->field_index) {
$params->field_index = $table['field_index'];
}
}
}
}
} else {
$params->field = null;
}
if ($simple && is_array($params->field) && !is_array($value) && '' !== $value && null !== $value) {
$value = PodsForm::field_method('pick', 'simple_value', $params->field['name'], $value, $params->field);
}
if (!is_array($value)) {
return $value;
}
if (null === $params->and) {
$params->and = ' ' . __('and', 'pods') . ' ';
}
$last = '';
$original_value = $value;
if (!empty($value)) {
$last = array_pop($value);
}
if ($simple && is_array($params->field) && !is_array($last) && '' !== $last && null !== $last) {
$last = PodsForm::field_method('pick', 'simple_value', $params->field['name'], $last, $params->field);
}
if (is_array($last)) {
if (null !== $params->field_index && isset($last[$params->field_index])) {
$last = $last[$params->field_index];
} elseif (isset($last[0])) {
$last = $last[0];
} elseif ($simple) {
$last = current($last);
} else {
$last = '';
}
}
if (!empty($value)) {
if (null !== $params->field_index && isset($original_value[$params->field_index])) {
return $original_value[$params->field_index];
} elseif (null !== $params->field_index && isset($value[$params->field_index])) {
return $value[$params->field_index];
} elseif (!isset($value[0])) {
$value = array($value);
}
foreach ($value as $k => $v) {
if ($simple && is_array($params->field) && !is_array($v) && '' !== $v && null !== $v) {
$v = PodsForm::field_method('pick', 'simple_value', $params->field['name'], $v, $params->field);
}
if (is_array($v)) {
if (null !== $params->field_index && isset($v[$params->field_index])) {
$v = $v[$params->field_index];
} elseif ($simple) {
$v = trim(implode($params->separator . ' ', $v), $params->separator . ' ');
} else {
unset($value[$k]);
continue;
}
}
$value[$k] = $v;
//.........这里部分代码省略.........
示例4: remove_from
/**
* Remove an item from the values of a relationship field, remove a value from a number field (field-1), remove time to a date field
*
* @see PodsAPI::save_pod_item
*
* @param string $field Field name
* @param mixed $value ID(s) to add, int|float to add to number field, string for dates (-1 week), or string for text
* @param int $id (optional) ID of the pod item to update
*
* @return int The item ID
*
* @since 2.3.3
*/
public function remove_from($field, $value = null, $id = null)
{
$pod =& $this;
$fetch = false;
if (null === $id) {
$fetch = true;
$id = $this->id();
} elseif ($id != $this->id()) {
$pod = pods($this->pod, $id);
}
$this->do_hook('remove_from', $field, $value, $id);
if (!isset($this->fields[$field])) {
return $id;
}
// Tableless fields
if (in_array($this->fields[$field]['type'], PodsForm::tableless_field_types())) {
if (empty($value)) {
$value = array();
}
if (!empty($value)) {
if (!is_array($value)) {
$value = explode(',', $value);
}
if ('pick' == $this->fields[$field]['type'] && in_array($this->fields[$field]['pick_object'], PodsForm::simple_tableless_objects())) {
$current_value = $pod->raw($field);
if (!empty($current_value)) {
$current_value = (array) $current_value;
}
foreach ($current_value as $k => $v) {
if (in_array($v, $value)) {
unset($current_value[$k]);
}
}
$value = $current_value;
} else {
$related_ids = $this->api->lookup_related_items($this->fields[$field]['id'], $this->pod_data['id'], $id, $this->fields[$field], $this->pod_data);
foreach ($value as $k => $v) {
if (!preg_match('/[^0-9]/', $v)) {
$value[$k] = (int) $v;
} else {
}
}
foreach ($related_ids as $k => $v) {
if (in_array($v, $value)) {
unset($related_ids[$k]);
}
}
$value = $related_ids;
}
if (!empty($value)) {
$value = array_filter(array_unique($value));
} else {
$value = array();
}
}
} elseif (in_array($this->fields[$field]['type'], PodsForm::number_field_types())) {
// Date fields don't support empty for removing
if (empty($value)) {
return $id;
}
$current_value = (double) $pod->raw($field);
$value = $current_value - (double) $value;
} elseif (in_array($this->fields[$field]['type'], PodsForm::date_field_types())) {
// Date fields don't support empty for removing
if (empty($value)) {
return $id;
}
$current_value = $pod->raw($field);
if (0 < strlen($current_value)) {
$value = strtotime($value, strtotime($current_value));
} else {
$value = strtotime($value);
}
$value = date_i18n('Y-m-d h:i:s', $value);
}
// @todo handle object fields and taxonomies
$params = array('pod' => $this->pod, 'id' => $id, 'data' => array($field => $value));
$id = $this->api->save_pod_item($params);
if (0 < $id && $fetch) {
$pod->fetch($id, false);
}
return $id;
}