本文整理汇总了PHP中fORMDatabase::addPrimaryKeyWhereParams方法的典型用法代码示例。如果您正苦于以下问题:PHP fORMDatabase::addPrimaryKeyWhereParams方法的具体用法?PHP fORMDatabase::addPrimaryKeyWhereParams怎么用?PHP fORMDatabase::addPrimaryKeyWhereParams使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fORMDatabase
的用法示例。
在下文中一共展示了fORMDatabase::addPrimaryKeyWhereParams方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load
/**
* Loads a record from the database
*
* @throws fNotFoundException When the record could not be found in the database
*
* @return fActiveRecord The record object, to allow for method chaining
*/
public function load()
{
$class = get_class($this);
$db = fORMDatabase::retrieve($class, 'read');
$schema = fORMSchema::retrieve($class);
if (fORM::getActiveRecordMethod($class, 'load')) {
return $this->__call('load', array());
}
try {
$table = fORM::tablize($class);
$params = array('SELECT * FROM %r WHERE ', $table);
$params = fORMDatabase::addPrimaryKeyWhereParams($schema, $params, $table, $table, $this->values, $this->old_values);
$result = call_user_func_array($db->translatedQuery, $params);
$result->tossIfNoRows();
} catch (fExpectedException $e) {
throw new fNotFoundException('The %s requested could not be found', fORM::getRecordName($class));
}
$this->loadFromResult($result, TRUE);
// Clears the cached related records so they get pulled from the database
$this->related_records = array();
return $this;
}
示例2: reorder
/**
* Re-orders the object based on it's current state and new position
*
* @internal
*
* @param fActiveRecord $object The fActiveRecord instance
* @param array &$values The current values
* @param array &$old_values The old values
* @param array &$related_records Any records related to this record
* @param array &$cache The cache array for the record
* @return void
*/
public static function reorder($object, &$values, &$old_values, &$related_records, &$cache)
{
$class = get_class($object);
$table = fORM::tablize($class);
$db = fORMDatabase::retrieve($class, 'write');
$schema = fORMSchema::retrieve($class);
foreach (self::$ordering_columns[$class] as $column => $other_columns) {
$current_value = $values[$column];
if (!$object->exists()) {
$old_value = fActiveRecord::retrieveOld($old_values, $column);
} else {
$params = array("SELECT %r FROM %r WHERE ", $column, $table);
$params = fORMDatabase::addPrimaryKeyWhereParams($schema, $params, $table, $table, $values, $old_values);
$old_value = call_user_func_array($db->translatedQuery, $params)->fetchScalar();
}
// Figure out the range we are dealing with
$params = array("SELECT MAX(%r) FROM %r", $column, $table);
if ($other_columns) {
$params[0] .= ' WHERE ';
$params = self::addOtherFieldsWhereParams($schema, $params, $table, $other_columns, $values);
}
$current_max_value = (int) call_user_func_array($db->translatedQuery, $params)->fetchScalar();
$new_max_value = $current_max_value;
if ($new_set = self::isInNewSet($column, $other_columns, $values, $old_values)) {
$new_max_value = $current_max_value + 1;
}
$changed = FALSE;
// If a blank value was set, correct it to the old value (if there
// was one), or a new value at the end of the set
if ($current_value === '' || $current_value === NULL) {
if ($old_value) {
$current_value = $old_value;
} else {
$current_value = $new_max_value;
}
$changed = TRUE;
}
// When we move an object into a new set and the value didn't change then move it to the end of the new set
if ($new_set && $object->exists() && ($old_value === NULL || $old_value == $current_value)) {
$current_value = $new_max_value;
$changed = TRUE;
}
// If the value is too high, then set it to the last value
if ($current_value > $new_max_value) {
$current_value = $new_max_value;
$changed = TRUE;
}
if ($changed) {
fActiveRecord::assign($values, $old_values, $column, $current_value);
}
// If the value didn't change, we can exit
$value_didnt_change = $old_value && $current_value == $old_value || !$old_value;
if (!$new_set && $value_didnt_change) {
continue;
}
// If we are entering a new record at the end of the set we don't need to shuffle anything either
if (!$object->exists() && $new_set && $current_value == $new_max_value) {
continue;
}
// If the object already exists in the database, grab the ordering value
// right now in case some other object reordered it since it was loaded
if ($object->exists()) {
$params = array("SELECT %r FROM %r WHERE ", $column, $table);
$params = fORMDatabase::addPrimaryKeyWhereParams($schema, $params, $table, $table, $values, $old_values);
$db_value = (int) call_user_func_array($db->translatedQuery, $params)->fetchScalar();
}
// We only need to move things in the new set around if we are inserting into the middle
// of a new set, or if we are moving around in the current set
if (!$new_set || $new_set && $current_value != $new_max_value) {
$shift_down = $new_max_value + 10;
// To prevent issues with the unique constraint, we move everything below 0
$params = array("UPDATE %r SET %r = %r - %i WHERE ", $table, $column, $column, $shift_down);
$conditions = array();
// If we are moving into the middle of a new set we just push everything up one value
if ($new_set) {
$shift_up = $new_max_value + 11;
$conditions[] = fORMDatabase::makeCondition($schema, $table, $column, '>=', $current_value);
$params[] = $table . '.' . $column;
$params[] = $current_value;
// If we are moving a value down in a set, we push values in the difference zone up one
} elseif ($current_value < $db_value) {
$shift_up = $new_max_value + 11;
$conditions[] = fORMDatabase::makeCondition($schema, $table, $column, '<', $db_value);
$params[] = $table . '.' . $column;
$params[] = $db_value;
$conditions[] = fORMDatabase::makeCondition($schema, $table, $column, '>=', $current_value);
$params[] = $table . '.' . $column;
$params[] = $current_value;
//.........这里部分代码省略.........