本文整理汇总了PHP中eZPersistentObject::replaceFieldsWithShortNames方法的典型用法代码示例。如果您正苦于以下问题:PHP eZPersistentObject::replaceFieldsWithShortNames方法的具体用法?PHP eZPersistentObject::replaceFieldsWithShortNames怎么用?PHP eZPersistentObject::replaceFieldsWithShortNames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eZPersistentObject
的用法示例。
在下文中一共展示了eZPersistentObject::replaceFieldsWithShortNames方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: storeObject
//.........这里部分代码省略.........
}
unset($value);
$important_keys = $keys;
if (is_array($relations)) {
// $important_keys = array();
foreach ($relations as $relation => $relation_data) {
if (!in_array($relation, $keys)) {
$important_keys[] = $relation;
}
}
}
if (count($important_keys) == 0 && !$useFieldFilters) {
$insert_object = true;
} else {
if (!$insert_object) {
$rows = eZPersistentObject::fetchObjectList($def, $keys, $key_conds, array(), null, false, null, null);
if (count($rows) == 0) {
/* If we only want to update some fields in a record
* and that records does not exist, then we should do nothing, only return.
*/
if ($useFieldFilters) {
return;
}
$insert_object = true;
}
}
}
if ($insert_object) {
// Note: When inserting we cannot hone the $fieldFilters parameters
$use_fields = array_diff(array_keys($fields), $exclude_fields);
$use_field_names = $use_fields;
if ($db->useShortNames()) {
$use_short_field_names = $use_field_names;
eZPersistentObject::replaceFieldsWithShortNames($db, $fields, $use_short_field_names);
$field_text = implode(', ', $use_short_field_names);
unset($use_short_field_names);
} else {
$field_text = implode(', ', $use_field_names);
}
$use_values_hash = array();
$escapeFields = array_diff($use_fields, $doNotEscapeFields);
foreach ($escapeFields as $key) {
//$value = $obj->attribute( $key );
$value = $obj->attributeContentToStore($key);
$field_def = $fields[$key];
if ($field_def['datatype'] == 'float' || $field_def['datatype'] == 'double') {
if ($value === null) {
$use_values_hash[$key] = 'NULL';
} else {
$use_values_hash[$key] = sprintf('%F', $value);
}
} else {
if ($field_def['datatype'] == 'int' || $field_def['datatype'] == 'integer') {
if ($value === null) {
$use_values_hash[$key] = 'NULL';
} else {
$use_values_hash[$key] = sprintf('%d', $value);
}
} else {
// Note: for more colherence, we might use NULL for sql strings if the php value is NULL and not an empty sring
// but to keep compatibility with ez db, where most string columns are "not null default ''",
// and code feeding us a php null value without meaning it, we do not.
$use_values_hash[$key] = "'" . $db->escapeString($value) . "'";
}
}
}
示例2: fetchObjectList
//.........这里部分代码省略.........
* <code>array( 'priority' => array( '>', 5 ) )</code> generates SQL <code>priority > 5</code>
* - Array with range: The first value is <code>false</code>, the second value is an array with start and stop of range in array
* <code>array( 'type' => array( false, array( 1, 5 ) ) )</code> generates SQL <code>type BETWEEN 1 AND 5</code>
* - Array with multiple elements: The first value is the field identifier, the second is an array with scalar values
* <code>array( 'id' => array( array( 1, 5, 7 ) ) )</code> generates SQL <code>id IN ( 1, 5, 7 )</code>
* @param array|null|bool $sorts An associative array of sorting conditions, if set to false ignores settings in $def, if set to null uses settingss in $def.
* Syntax is FIELD => DIRECTION.
* DIRECTION must either be 'asc' for ascending or 'desc' for descending.
* @param array|null $limit An associative array with limitiations, can contain
* - 'offset': Numerical value defining the start offset for the fetch
* - 'length': Numerical value defining the max number of items to return
* @param bool $asObject If true then it will return an array with objects, objects are created from class defined in $def.
* If falseit will just return the rows fetch from database.
* @param array|null|bool $grouping An array of fields to group by or null to use grouping in defintion $def.
* @param null $custom_fields Array of FIELD elements to add to SQL, can be used to perform custom fetches, e.g counts.
* FIELD is an associative array containing:
* - 'operation': A text field which is included in the field list
* - 'name': If present it adds <code>AS name</code> to the operation.
* @param array|null $custom_tables Array of additional tables
* @param string|null $custom_conds String with sql conditions for 'WHERE' clause.
* @return eZPersistentObject[]|array|null An array of objects or rows, null on error
*/
public static function fetchObjectList($def, $field_filters = null, $conds = null, $sorts = null, $limit = null, $asObject = true, $grouping = false, $custom_fields = null, $custom_tables = null, $custom_conds = null)
{
$db = eZDB::instance();
$fields = $def["fields"];
$tables = $def["name"];
$class_name = $def["class_name"];
if (is_array($custom_tables)) {
foreach ($custom_tables as $custom_table) {
$tables .= ', ' . $db->escapeString($custom_table);
}
}
eZPersistentObject::replaceFieldsWithShortNames($db, $fields, $conds);
if (is_array($field_filters)) {
$field_array = array_unique(array_intersect($field_filters, array_keys($fields)));
} else {
$field_array = array_keys($fields);
}
if ($custom_fields !== null and is_array($custom_fields)) {
foreach ($custom_fields as $custom_field) {
if (is_array($custom_field)) {
$custom_text = $custom_field["operation"];
if (isset($custom_field["name"])) {
$field_name = $custom_field["name"];
$custom_text .= " AS {$field_name}";
}
} else {
$custom_text = $custom_field;
}
$field_array[] = $custom_text;
}
}
eZPersistentObject::replaceFieldsWithShortNames($db, $fields, $field_array);
$field_text = '';
$i = 0;
foreach ($field_array as $field_item) {
if ($i % 7 == 0 and $i > 0) {
$field_text .= ", ";
} else {
if ($i > 0) {
$field_text .= ', ';
}
}
$field_text .= $field_item;
++$i;