当前位置: 首页>>代码示例>>PHP>>正文


PHP fORMDatabase::createPrimaryKeyWhereClause方法代码示例

本文整理汇总了PHP中fORMDatabase::createPrimaryKeyWhereClause方法的典型用法代码示例。如果您正苦于以下问题:PHP fORMDatabase::createPrimaryKeyWhereClause方法的具体用法?PHP fORMDatabase::createPrimaryKeyWhereClause怎么用?PHP fORMDatabase::createPrimaryKeyWhereClause使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在fORMDatabase的用法示例。


在下文中一共展示了fORMDatabase::createPrimaryKeyWhereClause方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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);
     $column = self::$ordering_columns[$class]['column'];
     $other_columns = self::$ordering_columns[$class]['other_columns'];
     $current_value = $values[$column];
     if (!$object->exists()) {
         $old_value = fActiveRecord::retrieveOld($old_values, $column);
     } else {
         $old_value = fORMDatabase::retrieve()->translatedQuery("SELECT " . $column . " FROM " . $table . " WHERE " . fORMDatabase::createPrimaryKeyWhereClause($table, $table, $values, $old_values))->fetchScalar();
     }
     // Figure out the range we are dealing with
     $sql = "SELECT max(" . $column . ") FROM " . $table;
     if ($other_columns) {
         $sql .= " WHERE " . self::createOtherFieldsWhereClause($table, $other_columns, $values);
     }
     $current_max_value = (int) fORMDatabase::retrieve()->translatedQuery($sql)->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) {
         return;
     }
     // 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) {
         return;
     }
     // 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()) {
         $sql = "SELECT " . $column . " FROM " . $table . " WHERE ";
         $sql .= fORMDatabase::createPrimaryKeyWhereClause($table, $table, $values, $old_values);
         $db_value = (int) fORMDatabase::retrieve()->translatedQuery($sql)->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;
         // 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;
             $down_condition = $column . " >= " . $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;
             $down_condition = $column . " < " . $db_value . " AND " . $column . " >= " . $current_value;
             // If we are moving a value up in a set, we push values in the difference zone down one
         } else {
             $shift_up = $new_max_value + 9;
             $down_condition = $column . " > " . $db_value . " AND " . $column . " <= " . $current_value;
         }
         // To prevent issues with the unique constraint, we move everything below 0
         $sql = "UPDATE " . $table . " SET " . $column . " = " . $column . " - " . $shift_down;
         $sql .= " WHERE " . $down_condition;
         if ($other_columns) {
             $sql .= " AND " . self::createOtherFieldsWhereClause($table, $other_columns, $values);
         }
         fORMDatabase::retrieve()->translatedQuery($sql);
         if ($object->exists()) {
             // Put the actual record we are changing in limbo to be updated when the actual update happens
//.........这里部分代码省略.........
开发者ID:jsuarez,项目名称:MyDesign,代码行数:101,代码来源:fORMOrdering.php

示例2: 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);
     if (fORM::getActiveRecordMethod($class, 'load')) {
         return $this->__call('load', array());
     }
     try {
         $table = fORM::tablize($class);
         $sql = 'SELECT * FROM ' . $table . ' WHERE ' . fORMDatabase::createPrimaryKeyWhereClause($table, $table, $this->values, $this->old_values);
         $result = fORMDatabase::retrieve()->translatedQuery($sql);
         $result->tossIfNoRows();
     } catch (fExpectedException $e) {
         throw new fNotFoundException('The %s requested could not be found', fORM::getRecordName($class));
     }
     $this->loadFromResult($result, TRUE);
     return $this;
 }
开发者ID:jsuarez,项目名称:MyDesign,代码行数:24,代码来源:fActiveRecord.php


注:本文中的fORMDatabase::createPrimaryKeyWhereClause方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。