Ejemplo n.º 1
0
 public function testClassToDatabaseMapping()
 {
     $this->assertEquals('default', fORM::getDatabaseName('User'));
     $this->assertEquals('default', fORM::getDatabaseName('PhotoGallery'));
     fORM::mapClassToDatabase('User', 'second_db');
     $this->assertEquals('second_db', fORM::getDatabaseName('User'));
 }
 public static function setUpBeforeClass()
 {
     if (defined('SKIPPING')) {
         return;
     }
     $db = new fDatabase(DB_TYPE, DB, DB_USERNAME, DB_PASSWORD, DB_HOST, DB_PORT);
     if (DB_TYPE == 'sqlite') {
         $db->execute(file_get_contents(DB_SETUP_FILE));
         $db->execute(file_get_contents(DB_EXTENDED_SETUP_FILE));
     }
     $db->execute(file_get_contents(DB_POPULATE_FILE));
     $db->execute(file_get_contents(DB_EXTENDED_POPULATE_FILE));
     self::$db = $db;
     self::$schema = new fSchema($db);
     fORMDatabase::attach(self::$db);
     fORMSchema::attach(self::$schema);
     fORMOrdering::configureOrderingColumn('TopAlbum', 'position');
     fORMOrdering::configureOrderingColumn('FavoriteAlbum', 'position');
     fORMOrdering::configureOrderingColumn('YearFavoriteAlbum', 'position');
     if (defined('MAP_TABLES')) {
         fORM::mapClassToTable('User', 'user');
         fORM::mapClassToTable('Group', 'group');
         fORM::mapClassToTable('Artist', 'popular_artists');
         fORM::mapClassToTable('Album', 'records');
     }
 }
Ejemplo n.º 3
0
 /**
  * @param array $where
  * @return WpTesting_Model_AbstractTerm
  * @throws fNotFoundException
  */
 protected function findByParams(array $where = array())
 {
     $taxonomyTable = fORM::tablize('WpTesting_Model_Taxonomy');
     try {
         return fRecordSet::build($this->modelName, array($taxonomyTable . '.taxonomy=' => $this->getTaxonomy()) + $where)->getRecord(0);
     } catch (fNoRemainingException $e) {
         throw new fNotFoundException($this->modelName . ' not found by conditions: ' . var_export($where, true));
     }
 }
 public function setUp()
 {
     if (defined('SKIPPING')) {
         $this->markTestSkipped();
     }
     fORMDatabase::attach($this->sharedFixture['db']);
     fORMDatabase::attach($this->sharedFixture['db2'], 'db2');
     fORMSchema::attach($this->sharedFixture['schema']);
     fORMSchema::attach($this->sharedFixture['schema2'], 'db2');
     fORM::mapClassToTable('Db2User', 'users');
     fORM::mapClassToDatabase('Db2User', 'db2');
     fORM::mapClassToTable('Db2Group', 'groups');
     fORM::mapClassToDatabase('Db2Group', 'db2');
 }
 public function setUp()
 {
     if (defined('SKIPPING')) {
         $this->markTestSkipped();
     }
     fORMDatabase::attach(self::$db);
     fORMDatabase::attach(self::$db2, 'db2');
     fORMSchema::attach(self::$schema);
     fORMSchema::attach(self::$schema2, 'db2');
     fORM::mapClassToTable('Db2User', 'users');
     fORM::mapClassToDatabase('Db2User', 'db2');
     fORM::mapClassToTable('Db2Group', 'groups');
     fORM::mapClassToDatabase('Db2Group', 'db2');
 }
 protected function setUp()
 {
     if (defined('SKIPPING')) {
         return;
     }
     $db = new fDatabase(DB_TYPE, DB, DB_USERNAME, DB_PASSWORD, DB_HOST, DB_PORT);
     $db->execute(file_get_contents(DB_SETUP_FILE));
     $db->execute(file_get_contents(DB_EXTENDED_SETUP_FILE));
     $db->execute(fix_schema(file_get_contents(DB_ALTERNATE_SCHEMA_SETUP_FILE)));
     $db->clearCache();
     fORMDatabase::attach($db);
     $this->sharedFixture = $db;
     fORM::mapClassToTable('Flourish2User', fix_schema('flourish2.users'));
     fORM::mapClassToTable('Flourish2Group', fix_schema('flourish2.groups'));
     fORM::mapClassToTable('Flourish2Artist', fix_schema('flourish2.artists'));
     fORM::mapClassToTable('Flourish2Album', fix_schema('flourish2.albums'));
 }
 protected function setUp()
 {
     if (defined('SKIPPING')) {
         return;
     }
     $db = new fDatabase(DB_TYPE, DB, DB_USERNAME, DB_PASSWORD, DB_HOST, DB_PORT);
     $db->execute(file_get_contents(DB_SETUP_FILE));
     $db2 = new fDatabase(DB_TYPE, DB_2, DB_2_USERNAME, DB_2_PASSWORD, DB_2_HOST, DB_2_PORT);
     $db2->execute(file_get_contents(DB_2_SETUP_FILE));
     $this->sharedFixture = array($db, $db2);
     fORMDatabase::attach($db);
     fORMDatabase::attach($db2, 'db2');
     fORM::mapClassToTable('Db2User', 'users');
     fORM::mapClassToDatabase('Db2User', 'db2');
     fORM::mapClassToTable('Db2Group', 'groups');
     fORM::mapClassToDatabase('Db2Group', 'db2');
 }
 public static function setUpBeforeClass()
 {
     if (defined('SKIPPING')) {
         return;
     }
     $db = new fDatabase(DB_TYPE, DB, DB_USERNAME, DB_PASSWORD, DB_HOST, DB_PORT);
     $db->execute(file_get_contents(DB_SETUP_FILE));
     $db2 = new fDatabase(DB_TYPE, DB_2, DB_2_USERNAME, DB_2_PASSWORD, DB_2_HOST, DB_2_PORT);
     $db2->execute(file_get_contents(DB_2_SETUP_FILE));
     self::$db = $db;
     self::$db2 = $db2;
     fORMDatabase::attach($db);
     fORMDatabase::attach($db2, 'db2');
     fORM::mapClassToTable('Db2User', 'users');
     fORM::mapClassToDatabase('Db2User', 'db2');
     fORM::mapClassToTable('Db2Group', 'groups');
     fORM::mapClassToDatabase('Db2Group', 'db2');
 }
Ejemplo n.º 9
0
 public function setUp()
 {
     if (defined('SKIPPING')) {
         $this->markTestSkipped();
     }
     $db = $this->sharedFixture['db'];
     $db->execute(file_get_contents(DB_EXTENDED_SETUP_FILE));
     $db->clearCache();
     fORMDatabase::attach($db);
     fORMSchema::attach($this->sharedFixture['schema']);
     fORMOrdering::configureOrderingColumn('TopAlbum', 'position');
     fORMOrdering::configureOrderingColumn('FavoriteAlbum', 'position');
     fORMOrdering::configureOrderingColumn('YearFavoriteAlbum', 'position');
     if (defined('MAP_TABLES')) {
         fORM::mapClassToTable('User', 'user');
         fORM::mapClassToTable('Group', 'group');
         fORM::mapClassToTable('Artist', 'popular_artists');
         fORM::mapClassToTable('Album', 'records');
     }
 }
 public static function setUpBeforeClass()
 {
     if (defined('SKIPPING')) {
         return;
     }
     $db = new fDatabase(DB_TYPE, DB, DB_USERNAME, DB_PASSWORD, DB_HOST, DB_PORT);
     if (DB_TYPE == 'sqlite') {
         $db->execute(file_get_contents(DB_SETUP_FILE));
         $db->execute(file_get_contents(DB_EXTENDED_SETUP_FILE));
         $db->execute(fix_schema(file_get_contents(DB_ALTERNATE_SCHEMA_SETUP_FILE)));
     }
     $db->execute(file_get_contents(DB_POPULATE_FILE));
     $db->execute(file_get_contents(DB_EXTENDED_POPULATE_FILE));
     $db->execute(fix_schema(file_get_contents(DB_ALTERNATE_SCHEMA_POPULATE_FILE)));
     $db->clearCache();
     fORMDatabase::attach($db);
     self::$db = $db;
     fORM::mapClassToTable('Flourish2User', fix_schema('flourish2.users'));
     fORM::mapClassToTable('Flourish2Group', fix_schema('flourish2.groups'));
     fORM::mapClassToTable('Flourish2Artist', fix_schema('flourish2.artists'));
     fORM::mapClassToTable('Flourish2Album', fix_schema('flourish2.albums'));
 }
Ejemplo n.º 11
0
 public function testBuildFromSQLNonLimitedCount()
 {
     $set = fRecordSet::buildFromSQL('User', sprintf("SELECT %s.* FROM %s LIMIT 2", fORM::tablize('User'), fORM::tablize('User')), sprintf("SELECT count(*) FROM %s", fORM::tablize('User')));
     $this->assertEquals(array(1, 2), $set->getPrimaryKeys());
     $this->assertEquals(4, $set->count(TRUE));
 }
Ejemplo n.º 12
0
 /**
  * Validates many-to-many related records
  *
  * @param  string $class          The class to validate the related records for
  * @param  string $related_class  The name of the class for this record set
  * @param  string $route          The route between the table and related table
  * @param  array  $related_info   The related info to validate
  * @return array  An array of validation messages
  */
 private static function validateManyToMany($class, $related_class, $route, $related_info)
 {
     $related_record_name = self::getRelatedRecordName($class, $related_class, $route);
     $record_number = 1;
     $messages = array();
     $related_records = $related_info['record_set'] ? $related_info['record_set'] : $related_info['primary_keys'];
     foreach ($related_records as $record) {
         if (is_object($record) && !$record->exists() || !$record) {
             $messages[fORM::tablize($related_class)] = self::compose('%1$sPlease select a %2$s', fValidationException::formatField(self::compose('%1$s #%2$s', $related_record_name, $record_number)), $related_record_name);
         }
         $record_number++;
     }
     return $messages;
 }
Ejemplo n.º 13
0
 /**
  * Validates all timestamp/timezone columns
  *
  * @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  array         &$validation_messages  An array of ordered validation messages
  * @return void
  */
 public static function validateTimezoneColumns($object, &$values, &$old_values, &$related_records, &$cache, &$validation_messages)
 {
     $class = get_class($object);
     if (empty(self::$timezone_columns[$class])) {
         return;
     }
     foreach (self::$timezone_columns[$class] as $timezone_column => $timestamp_column) {
         if ($values[$timestamp_column] instanceof fTimestamp || $values[$timestamp_column] === NULL) {
             continue;
         }
         if (!fTimestamp::isValidTimezone($values[$timezone_column])) {
             $validation_messages[$timezone_column] = self::compose('%sThe timezone specified is invalid', fValidationException::formatField(fORM::getColumnName($class, $timezone_column)));
         } else {
             $validation_messages[$timestamp_column] = self::compose('%sPlease enter a date/time', fValidationException::formatField(fORM::getColumnName($class, $timestamp_column)));
         }
     }
 }
Ejemplo n.º 14
0
 /**
  * Overlays user data over info from the record set
  *
  * @param array        $data   The user data
  * @param string|array $class  The class or classes present in the record set
  * @return array  The merged data
  */
 private static function extendRecordSetInfo($data, $class)
 {
     if (is_array($class)) {
         $record_name = array_map(array('fORM', 'getRecordName'), $class);
     } else {
         $record_name = fORM::getRecordName($class);
     }
     return array_merge(array('class' => $class, 'record_name' => $record_name), $data);
 }
Ejemplo n.º 15
0
 /**
  * Throws an fEmptySetException if the record set is empty
  * 
  * @throws fEmptySetException  When there are no record in the set
  * 
  * @param  string $message  The message to use for the exception if there are no records in this set
  * @return fRecordSet  The record set object, to allow for method chaining
  */
 public function tossIfEmpty($message = NULL)
 {
     if ($this->records) {
         return $this;
     }
     if ($message === NULL) {
         if (is_array($this->class)) {
             $names = array_map(array('fORM', 'getRecordName'), $this->class);
             $names = array_map(array('fGrammar', 'pluralize'), $names);
             $name = join(', ', $names);
         } else {
             $name = fGrammar::pluralize(fORM::getRecordName($this->class));
         }
         $message = self::compose('No %s could be found', $name);
     }
     throw new fEmptySetException($message);
 }
Ejemplo n.º 16
0
 protected function __construct()
 {
     $this->modelName = str_replace('_Query_', '_Model_', get_class($this));
     $this->tableName = fORM::tablize($this->modelName);
     $this->db = fORMDatabase::retrieve($this->modelName, 'read');
 }
Ejemplo n.º 17
0
 /**
  * Adds the method `toJSON()` to fActiveRecord and fRecordSet instances
  *
  * @return void
  */
 public static function extend()
 {
     fORM::registerReflectCallback('*', self::reflect);
     fORM::registerActiveRecordMethod('*', 'toJSON', self::toJSON);
     fORM::registerRecordSetMethod('toJSON', self::toJSONRecordSet);
 }
Ejemplo n.º 18
0
 /**
  * Validates all money columns
  * 
  * @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  array         &$validation_messages  An array of ordered validation messages
  * @return void
  */
 public static function validateMoneyColumns($object, &$values, &$old_values, &$related_records, &$cache, &$validation_messages)
 {
     $class = get_class($object);
     if (empty(self::$money_columns[$class])) {
         return;
     }
     foreach (self::$money_columns[$class] as $column => $currency_column) {
         if ($values[$column] instanceof fMoney || $values[$column] === NULL) {
             continue;
         }
         // Remove any previous validation warnings
         unset($validation_messages[$column]);
         $column_name = fValidationException::formatField(fORM::getColumnName($class, $currency_column));
         if ($currency_column && !in_array($values[$currency_column], fMoney::getCurrencies())) {
             $validation_messages[$column] = self::compose('%sThe currency specified is invalid', $column_name);
         } else {
             $validation_messages[$column] = self::compose('%sPlease enter a monetary value', $column_name);
         }
     }
 }
Ejemplo n.º 19
0
 /**
  * Validates the values of the record against the database and any additional validation rules
  * 
  * @throws fValidationException  When the record, or one of the associated records, violates one of the validation rules for the class or can not be properly stored in the database
  * 
  * @param  boolean $return_messages      If an array of validation messages should be returned instead of an exception being thrown
  * @param  boolean $remove_column_names  If column names should be removed from the returned messages, leaving just the message itself
  * @return void|array  If $return_messages is TRUE, an array of validation messages will be returned
  */
 public function validate($return_messages = FALSE, $remove_column_names = FALSE)
 {
     $class = get_class($this);
     if (fORM::getActiveRecordMethod($class, 'validate')) {
         return $this->__call('validate', array($return_messages));
     }
     $validation_messages = array();
     fORM::callHookCallbacks($this, 'pre::validate()', $this->values, $this->old_values, $this->related_records, $this->cache, $validation_messages);
     // Validate the local values
     $local_validation_messages = fORMValidation::validate($this, $this->values, $this->old_values);
     // Validate related records
     $related_validation_messages = fORMValidation::validateRelated($this, $this->values, $this->related_records);
     $validation_messages = array_merge($validation_messages, $local_validation_messages, $related_validation_messages);
     fORM::callHookCallbacks($this, 'post::validate()', $this->values, $this->old_values, $this->related_records, $this->cache, $validation_messages);
     $validation_messages = fORMValidation::replaceMessages($class, $validation_messages);
     $validation_messages = fORMValidation::reorderMessages($class, $validation_messages);
     if ($return_messages) {
         if ($remove_column_names) {
             $validation_messages = fValidationException::removeFieldNames($validation_messages);
         }
         return $validation_messages;
     }
     if (!empty($validation_messages)) {
         throw new fValidationException('The following problems were found:', $validation_messages);
     }
 }
Ejemplo n.º 20
0
 /**
  * Return the instance of the fSchema class
  * 
  * @param  string $class  The class the object will be used with
  * @return fSchema  The schema instance
  */
 public static function retrieve($class = 'fActiveRecord')
 {
     if (substr($class, 0, 5) == 'name:') {
         $database_name = substr($class, 5);
     } else {
         $database_name = fORM::getDatabaseName($class);
     }
     if (!isset(self::$schema_objects[$database_name])) {
         self::$schema_objects[$database_name] = new fSchema(fORMDatabase::retrieve($class));
     }
     return self::$schema_objects[$database_name];
 }
Ejemplo n.º 21
0
 protected function configure()
 {
     parent::configure();
     fORM::registerHookCallback($this, 'post::validate()', array($this, 'validateSource'));
 }
 public function setUp()
 {
     if (defined('SKIPPING')) {
         $this->markTestSkipped();
     }
     fORMDatabase::attach($this->sharedFixture['db']);
     fORMSchema::attach($this->sharedFixture['schema']);
     fORM::mapClassToTable('Flourish2User', fix_schema('flourish2.users'));
     fORM::mapClassToTable('Flourish2Group', fix_schema('flourish2.groups'));
     fORM::mapClassToTable('Flourish2Artist', fix_schema('flourish2.artists'));
     fORM::mapClassToTable('Flourish2Album', fix_schema('flourish2.albums'));
 }
Ejemplo n.º 23
0
 /**
  * Resets the configuration of the class
  *
  * @internal
  *
  * @return void
  */
 public static function reset()
 {
     self::$active_record_method_callbacks = array();
     self::$cache = array('parseMethod' => array(), 'getActiveRecordMethod' => array(), 'objectify' => array());
     self::$class_database_map = array('fActiveRecord' => 'default');
     self::$class_table_map = array();
     self::$column_names = array();
     self::$hook_callbacks = array();
     self::$inspect_callbacks = array();
     self::$objectify_callbacks = array();
     self::$record_names = array('fActiveRecord' => 'Active Record');
     self::$record_set_method_callbacks = array();
     self::$reflect_callbacks = array();
     self::$related_class_names = array();
     self::$replicate_callbacks = array();
     self::$scalarize_callbacks = array();
 }
Ejemplo n.º 24
0
 /**
  * @param bool $isRecursive
  * @return WpTesting_Model_Test
  */
 public function populateQuestions($isRecursive = false)
 {
     $this->populateWpTesting_Model_Questions($isRecursive);
     $table = fORM::tablize('WpTesting_Model_Question');
     $records =& $this->related_records[$table]['test_id']['record_set'];
     $records = $records->filter(array('getTitle!=' => ''));
     return $this;
 }
Ejemplo n.º 25
0
 protected function configure()
 {
     fORM::registerHookCallback($this, 'post::store()', 'Permission::invalidateCache');
 }
Ejemplo n.º 26
0
 /**
  * Makes sure the ordering value is sane, removes error messages about missing values
  *
  * @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  array         &$validation_messages  An array of ordered validation messages
  * @return void
  */
 public static function validate($object, &$values, &$old_values, &$related_records, &$cache, &$validation_messages)
 {
     $class = get_class($object);
     $table = fORM::tablize($class);
     $db = fORMDatabase::retrieve($class, 'read');
     $schema = fORMSchema::retrieve($class);
     foreach (self::$ordering_columns[$class] as $column => $other_columns) {
         $current_value = $values[$column];
         $old_value = fActiveRecord::retrieveOld($old_values, $column);
         $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;
             $new_set_new_value = fActiveRecord::changed($values, $old_values, $column);
         }
         $column_name = fORM::getColumnName($class, $column);
         // Remove any previous validation warnings
         $filtered_messages = array();
         foreach ($validation_messages as $validation_column => $validation_message) {
             if (!preg_match('#(^|,)' . preg_quote($column, '#') . '(,|$)#D', $validation_column)) {
                 $filtered_messages[$validation_column] = $validation_message;
             }
         }
         $validation_messages = $filtered_messages;
         // If we have a completely empty value, we don't need to validate since a valid value will be generated
         if ($current_value === '' || $current_value === NULL) {
             continue;
         }
         if (!is_numeric($current_value) || strlen((int) $current_value) != strlen($current_value)) {
             $validation_messages[$column] = self::compose('%sPlease enter an integer', fValidationException::formatField($column_name));
         } elseif ($current_value < 1) {
             $validation_messages[$column] = self::compose('%sThe value can not be less than 1', fValidationException::formatField($column_name));
         }
     }
 }
Ejemplo n.º 27
0
 /**
  * Validates uploaded files to ensure they match all of the criteria defined
  * 
  * @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  array         &$validation_messages  The existing validation messages
  * @return void
  */
 public static function validate($object, &$values, &$old_values, &$related_records, &$cache, &$validation_messages)
 {
     $class = get_class($object);
     foreach (self::$file_upload_columns[$class] as $column => $directory) {
         $column_name = fORM::getColumnName($class, $column);
         if (isset($validation_messages[$column])) {
             $search_message = self::compose('%sPlease enter a value', fValidationException::formatField($column_name));
             $replace_message = self::compose('%sPlease upload a file', fValidationException::formatField($column_name));
             $validation_messages[$column] = str_replace($search_message, $replace_message, $validation_messages[$column]);
         }
         // Grab the error that occured
         try {
             if (fUpload::check($column)) {
                 $uploader = self::setUpFUpload($class, $column);
                 $uploader->validate($column);
             }
         } catch (fValidationException $e) {
             if ($e->getMessage() != self::compose('Please upload a file')) {
                 $validation_messages[$column] = fValidationException::formatField($column_name) . $e->getMessage();
             }
         }
     }
 }
Ejemplo n.º 28
0
 public function tearDown()
 {
     if (defined('SKIPPING')) {
         return;
     }
     self::$db->query('DELETE FROM %r WHERE user_id > 4', fORM::tablize('User'));
     __reset();
 }
Ejemplo n.º 29
0
 /**
  * Validates related records for an fActiveRecord object
  *
  * @internal
  *
  * @param  fActiveRecord $object            The object to validate
  * @param  array         &$values           The values for the object
  * @param  array         &$related_records  The related records for the object
  * @return array         An array of messages
  */
 public static function validateRelated($object, &$values, &$related_records)
 {
     $class = get_class($object);
     $table = fORM::tablize($class);
     $validation_messages = array();
     // Check related rules
     foreach (self::$related_one_or_more_rules[$class] as $related_class => $routes) {
         foreach ($routes as $route => $enabled) {
             $message = self::checkRelatedOneOrMoreRule($object, $values, $related_records, $related_class, $route);
             if ($message) {
                 $validation_messages[fORM::tablize($related_class)] = $message;
             }
         }
     }
     $related_messages = fORMRelated::validate($class, $values, $related_records);
     $validation_messages = array_merge($validation_messages, $related_messages);
     return $validation_messages;
 }
Ejemplo n.º 30
0
 /**
  * Makes sure the ordering value is sane, removes error messages about missing values
  * 
  * @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  array         &$validation_messages  An array of ordered validation messages
  * @return void
  */
 public static function validate($object, &$values, &$old_values, &$related_records, &$cache, &$validation_messages)
 {
     $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];
     $old_value = fActiveRecord::retrieveOld($old_values, $column);
     $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;
         $new_set_new_value = fActiveRecord::changed($values, $old_values, $column);
     }
     $column_name = fORM::getColumnName($class, $column);
     // Remove any previous validation warnings
     $filtered_messages = array();
     foreach ($validation_messages as $validation_message) {
         if (!preg_match('#^' . str_replace('___', '(.*?)', preg_quote(fValidationException::formatField('___' . $column_name . '___'), '#')) . '#', $validation_message)) {
             $filtered_messages[] = $validation_message;
         }
     }
     $validation_messages = $filtered_messages;
     // If we have a completely empty value, we don't need to validate since a valid value will be generated
     if ($current_value === '' || $current_value === NULL) {
         return;
     }
     if (!is_numeric($current_value) || strlen((int) $current_value) != strlen($current_value)) {
         $validation_messages[] = self::compose('%sPlease enter an integer', fValidationException::formatField($column_name));
     } elseif ($current_value < 1) {
         $validation_messages[] = self::compose('%sThe value can not be less than 1', fValidationException::formatField($column_name));
     }
 }