Esempio n. 1
0
 protected function configure()
 {
     fORMValidation::addStringReplacement($this, 'Login Name: The value specified must be unique, however it already exists', '不能重复创建个人信息');
     fORMValidation::addStringReplacement($this, 'Start Year: Please enter a value', '请选择入学年份');
     fORMValidation::addStringReplacement($this, 'Birthday: Please enter a value', '请选择生日');
     fORMValidation::addStringReplacement($this, 'Gender: Please enter a value', '请选择性别');
     fORMValidation::addStringReplacement($this, 'Location: Please enter a value', '请填写现居住地');
     fORMValidation::addStringReplacement($this, 'Hometown: Please enter a value', '请填写家乡');
     fORMValidation::addStringReplacement($this, 'High School: Please enter a value', '请填写高中名称');
 }
Esempio n. 2
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);
     }
 }
 /**
  * Resets the configuration of the class
  *
  * @internal
  *
  * @return void
  */
 public static function reset()
 {
     self::$case_insensitive_columns = array();
     self::$conditional_rules = array();
     self::$message_orders = array();
     self::$one_or_more_rules = array();
     self::$only_one_rules = array();
     self::$regex_replacements = array();
     self::$related_one_or_more_rules = array();
     self::$regex_rules = array();
     self::$required_rules = array();
     self::$string_replacements = array();
     self::$valid_values_rules = array();
 }
Esempio n. 4
0
 public function testOnlyOneBothValues()
 {
     fORMValidation::addOnlyOneRule('User', array('is_validated', 'time_of_last_login'));
     $this->setExpectedException('fValidationException');
     $user = $this->createUser();
     $user->setIsValidated(TRUE);
     $user->setTimeOfLastLogin(new fTimestamp());
     $user->validate();
 }
Esempio n. 5
0
 /**
  * Saves all objects related to test.
  *
  * @throws fValidationException
  * @return WpTesting_Model_Test
  */
 public function storeAll()
 {
     $this->transactionStart();
     $this->wp->doAction('wp_testing_test_store_all_before', $this);
     $this->buildQuestionsWithAnswersAndScores();
     fORMValidation::disableForeignKeyConstraintsCheck();
     $this->populateAll()->store(true)->syncQuestionsAnswers();
     $this->wp->doAction('wp_testing_test_store_all_after', $this);
     $this->transactionFinish();
     return $this;
 }
Esempio n. 6
0
 protected function configure()
 {
     fORMValidation::addStringReplacement($this, 'Type: Please enter a value', '请选择类型');
     fORMValidation::addStringReplacement($this, 'Major: Please enter a value', '请输入专业/方向');
     fORMValidation::addStringReplacement($this, 'Location: Please enter a value', '请输入学校/单位');
 }
Esempio n. 7
0
 protected function configure()
 {
     fORMValidation::addStringReplacement($this, 'Title: Please enter a value', '请输入标题');
     fORMValidation::addStringReplacement($this, 'Content: Please enter a value', '请输入文章内容');
 }
Esempio n. 8
0
 protected function configure()
 {
     fORMValidation::addStringReplacement($this, 'Description: Please enter a value', '请填写荣誉描述');
 }
Esempio n. 9
0
 /**
  * Validates one-to-* related records
  *
  * @param  string $class             The class to validate the related records for
  * @param  array  &$values           The values for the object
  * @param  array  &$related_records  The related records for the object
  * @param  string $related_class     The name of the class for this record set
  * @param  string $route             The route between the table and related table
  * @return array  An array of validation messages
  */
 private static function validateOneToStar($class, &$values, &$related_records, $related_class, $route)
 {
     $table = fORM::tablize($class);
     $related_table = fORM::tablize($related_class);
     $first_pk_column = self::determineFirstPKColumn($class, $related_class, $route);
     $filter = self::determineRequestFilter($class, $related_class, $route);
     $pk_field = $filter . $first_pk_column;
     $input_keys = array_keys(fRequest::get($pk_field, 'array', array()));
     $related_record_name = self::getRelatedRecordName($class, $related_class, $route);
     $messages = array();
     $one_to_one = fORMSchema::isOneToOne($table, $related_table, $route);
     if ($one_to_one) {
         $records = array(self::createRecord($class, $values, $related_records, $related_class, $route));
     } else {
         $records = self::buildRecords($class, $values, $related_records, $related_class, $route);
     }
     // Ignore validation messages about the primary key since it will be added
     $primary_key_name = fValidationException::formatField(fORM::getColumnName($related_class, $route));
     $primary_key_regex = '#^' . preg_quote($primary_key_name, '#') . '.*$#D';
     fORMValidation::addRegexReplacement($related_class, $primary_key_regex, '');
     foreach ($records as $i => $record) {
         fRequest::filter($filter, isset($input_keys[$i]) ? $input_keys[$i] : $i);
         $record_messages = $record->validate(TRUE);
         foreach ($record_messages as $record_message) {
             $token_field = fValidationException::formatField('__TOKEN__');
             $extract_message_regex = '#' . str_replace('__TOKEN__', '(.*?)', preg_quote($token_field, '#')) . '(.*)$#D';
             preg_match($extract_message_regex, $record_message, $matches);
             if ($one_to_one) {
                 $column_name = self::compose('%1$s %2$s', $related_record_name, $matches[1]);
             } else {
                 $column_name = self::compose('%1$s #%2$s %3$s', $related_record_name, $i + 1, $matches[1]);
             }
             $messages[] = self::compose('%1$s%2$s', fValidationException::formatField($column_name), $matches[2]);
         }
         fRequest::unfilter();
     }
     fORMValidation::removeRegexReplacement($related_class, $primary_key_regex, '');
     return $messages;
 }
Esempio n. 10
0
 protected function configure()
 {
     fORMValidation::addStringReplacement($this, 'Title: Please enter a value', '请填写标题');
     fORMValidation::addStringReplacement($this, 'Authors: Please enter a value', '请填写作者列表');
     fORMValidation::addStringReplacement($this, 'Publish Place: Please enter a value', '请填写论文发表在哪里');
 }