本文整理汇总了PHP中eZPersistentObject::conditionTextByRow方法的典型用法代码示例。如果您正苦于以下问题:PHP eZPersistentObject::conditionTextByRow方法的具体用法?PHP eZPersistentObject::conditionTextByRow怎么用?PHP eZPersistentObject::conditionTextByRow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eZPersistentObject
的用法示例。
在下文中一共展示了eZPersistentObject::conditionTextByRow方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: reorderObject
/**
* Moves a row in a database table.
*
* Uses $orderField to determine the order of objects in a table, usually this
* is a placement of some kind. It uses this order field to figure out how move
* the row, the row is either swapped with another row which is either above or
* below according to whether $down is true or false, or it is swapped
* with the first item or the last item depending on whether this row
* is first or last.
* Uses $conditions to figure out unique rows.
*
* 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.
*
* @param array $def A definition array of all fields, table name and sorting (see {@link eZPersistentObject::definition()} for more info)
* @param array $orderField Associative array with one element, the key is the order id and values is order value.
* @param array $conditions
* @param bool $down
* @return void
*/
public static function reorderObject($def, $orderField, $conditions, $down = true)
{
$db = eZDB::instance();
$table = $def["name"];
$keys = $def["keys"];
reset($orderField);
$order_id = key($orderField);
$order_val = $orderField[$order_id];
if ($down) {
$order_operator = ">=";
$order_type = "asc";
$order_add = -1;
} else {
$order_operator = "<=";
$order_type = "desc";
$order_add = 1;
}
$fields = array_merge($keys, array($order_id));
$rows = eZPersistentObject::fetchObjectList($def, $fields, array_merge($conditions, array($order_id => array($order_operator, $order_val))), array($order_id => $order_type), array("length" => 2), false);
if (count($rows) == 2) {
$swapSQL1 = eZPersistentObject::swapRow($table, $keys, $order_id, $rows, 1, 0);
$swapSQL2 = eZPersistentObject::swapRow($table, $keys, $order_id, $rows, 0, 1);
$db->begin();
$db->query($swapSQL1);
$db->query($swapSQL2);
$db->commit();
} else {
$tmp = eZPersistentObject::fetchObjectList($def, $fields, $conditions, array($order_id => $order_type), array("length" => 1), false);
$where_text = eZPersistentObject::conditionTextByRow($keys, $rows[0]);
$db->query("UPDATE {$table} SET {$order_id}='" . ($tmp[0][$order_id] + $order_add) . "'{$where_text}");
}
}