本文整理汇总了PHP中eZPersistentObject::definition方法的典型用法代码示例。如果您正苦于以下问题:PHP eZPersistentObject::definition方法的具体用法?PHP eZPersistentObject::definition怎么用?PHP eZPersistentObject::definition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eZPersistentObject
的用法示例。
在下文中一共展示了eZPersistentObject::definition方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: storeObject
/**
* Stores the data in $obj to database.
*
* Note: Transaction unsafe. If you call several transaction unsafe methods
* you must enclose the calls within a db transaction; thus within db->begin
* and db->commit.
*
* @todo Change the actual access to protected instead of just marking it as such
* @access protected
* @param eZPersistentObject $obj
* @param array|null $fieldFilters If specified only certain fields will be stored.
* @return void
*/
public static function storeObject($obj, $fieldFilters = null)
{
$db = eZDB::instance();
$useFieldFilters = isset($fieldFilters) && is_array($fieldFilters) && $fieldFilters;
$def = $obj->definition();
$fields = $def["fields"];
$keys = $def["keys"];
$table = $def["name"];
$relations = isset($def["relations"]) ? $def["relations"] : null;
$insert_object = false;
$exclude_fields = array();
foreach ($keys as $key) {
$value = $obj->attribute($key);
if ($value === null) {
$insert_object = true;
$exclude_fields[] = $key;
}
}
if ($useFieldFilters) {
$insert_object = false;
}
$use_fields = array_diff(array_keys($fields), $exclude_fields);
// If we filter out some of the fields we need to intersect it with $use_fields
if (is_array($fieldFilters)) {
$use_fields = array_intersect($use_fields, $fieldFilters);
}
$doNotEscapeFields = array();
$changedValueFields = array();
$numericDataTypes = array('integer', 'float', 'double');
foreach ($use_fields as $field_name) {
$field_def = $fields[$field_name];
$value = $obj->attribute($field_name);
if ($value === null) {
if (!is_array($field_def)) {
$exclude_fields[] = $field_name;
} else {
if (array_key_exists('default', $field_def) && ($field_def['default'] !== null || $field_name == 'data_int' && array_key_exists('required', $field_def) && $field_def['required'] == false)) {
$obj->setAttribute($field_name, $field_def['default']);
} else {
//if ( in_array( $field_def['datatype'], $numericDataTypes )
$exclude_fields[] = $field_name;
}
}
}
if (strlen($value) == 0 && is_array($field_def) && in_array($field_def['datatype'], $numericDataTypes) && array_key_exists('default', $field_def) && ($field_def['default'] === null || is_numeric($field_def['default']))) {
$obj->setAttribute($field_name, $field_def['default']);
}
if ($value !== null && $field_def['datatype'] === 'string' && array_key_exists('max_length', $field_def) && $field_def['max_length'] > 0) {
$obj->setAttribute($field_name, $db->truncateString($value, $field_def['max_length'], $field_name));
}
$bindDataTypes = array('text');
if ($db->bindingType() != eZDBInterface::BINDING_NO && $db->countStringSize($value) > 2000 && is_array($field_def) && in_array($field_def['datatype'], $bindDataTypes)) {
$boundValue = $db->bindVariable($value, $field_def);
// $obj->setAttribute( $field_name, $value );
$doNotEscapeFields[] = $field_name;
$changedValueFields[$field_name] = $boundValue;
}
}
$key_conds = array();
foreach ($keys as $key) {
$value = $obj->attribute($key);
$key_conds[$key] = $value;
}
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;
}
//.........这里部分代码省略.........