/** * Returns the metadata about a column including features added by this class * * @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 * @param string $method_name The method that was called * @param array $parameters The parameters passed to the method * @return mixed The metadata array or element specified */ public static function inspect($object, &$values, &$old_values, &$related_records, &$cache, $method_name, $parameters) { list($action, $subject) = fORM::parseMethod($method_name); $column = fGrammar::underscorize($subject); $class = get_class($object); $table = fORM::tablize($class); $db = fORMDatabase::retrieve($class, 'read'); $schema = fORMSchema::retrieve($class); $info = $schema->getColumnInfo($table, $column); $element = isset($parameters[0]) ? $parameters[0] : NULL; $other_columns = self::$ordering_columns[$class][$column]; // Retrieve the current max ordering index from the database $params = array("SELECT MAX(%r) FROM %r", $column, $table); if ($other_columns) { $params[0] .= " WHERE "; $params = self::addOtherFieldsWhereParams($schema, $params, $table, $other_columns, $values); } $max_value = (int) call_user_func_array($db->translatedQuery, $params)->fetchScalar(); // If this is a new record, or in a new set, we need one more space in the ordering index if (self::isInNewSet($column, $other_columns, $values, $old_values)) { $max_value += 1; } $info['max_ordering_value'] = $max_value; $info['feature'] = 'ordering'; fORM::callInspectCallbacks($class, $column, $info); if ($element) { return isset($info[$element]) ? $info[$element] : NULL; } return $info; }
/** * Retrieves information about a column * * @param string $column The name of the column to inspect * @param string $element The metadata element to retrieve * @return mixed The metadata array for the column, or the metadata element specified */ protected function inspect($column, $element = NULL) { if (!array_key_exists($column, $this->values)) { throw new fProgrammerException('The column specified, %s, does not exist', $column); } $class = get_class($this); $table = fORM::tablize($class); $schema = fORMSchema::retrieve($class); $info = $schema->getColumnInfo($table, $column); if (!in_array($info['type'], array('varchar', 'char', 'text'))) { unset($info['valid_values']); unset($info['max_length']); } if ($info['type'] != 'float') { unset($info['decimal_places']); } if ($info['type'] != 'integer') { unset($info['auto_increment']); } if (!in_array($info['type'], array('integer', 'float'))) { unset($info['min_value']); unset($info['max_value']); } $info['feature'] = NULL; fORM::callInspectCallbacks(get_class($this), $column, $info); if ($element) { if (!isset($info[$element]) && !array_key_exists($element, $info)) { throw new fProgrammerException('The element specified, %1$s, is invalid. Must be one of: %2$s.', $element, join(', ', array_keys($info))); } return $info[$element]; } return $info; }
/** * Returns the metadata about a column including features added by this class * * @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 * @param string $method_name The method that was called * @param array $parameters The parameters passed to the method * @return mixed The metadata array or element specified */ public static function inspect($object, &$values, &$old_values, &$related_records, &$cache, $method_name, $parameters) { list($action, $column) = fORM::parseMethod($method_name); $class = get_class($object); $table = fORM::tablize($class); $info = fORMSchema::retrieve()->getColumnInfo($table, $column); $element = isset($parameters[0]) ? $parameters[0] : NULL; $column = self::$ordering_columns[$class]['column']; $other_columns = self::$ordering_columns[$class]['other_columns']; // Retrieve the current max ordering index from the database $sql = "SELECT max(" . $column . ") FROM " . $table; if ($other_columns) { $sql .= " WHERE " . self::createOtherFieldsWhereClause($table, $other_columns, $values); } $max_value = (int) fORMDatabase::retrieve()->translatedQuery($sql)->fetchScalar(); // If this is a new record, or in a new set, we need one more space in the ordering index if (self::isInNewSet($column, $other_columns, $values, $old_values)) { $max_value += 1; } $info['max_ordering_value'] = $max_value; $info['feature'] = 'ordering'; fORM::callInspectCallbacks($class, $column, $info); if ($element) { return isset($info[$element]) ? $info[$element] : NULL; } return $info; }