コード例 #1
0
 /**
  * Validates against a *-to-many one or more rule
  *
  * @param  fActiveRecord $object            The object being checked
  * @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 related class
  * @param  string        $route             The name of the route from the class to the related class
  * @return string  An error message for the rule
  */
 private static function checkRelatedOneOrMoreRule($object, &$values, &$related_records, $related_class, $route)
 {
     $related_table = fORM::tablize($related_class);
     $class = get_class($object);
     $exists = $object->exists();
     $records_are_set = isset($related_records[$related_table][$route]);
     $has_records = $records_are_set && $related_records[$related_table][$route]['count'];
     if ($exists && (!$records_are_set || $has_records)) {
         return;
     }
     if (!$exists && $has_records) {
         return;
     }
     return self::compose('%sPlease select at least one', fValidationException::formatField(fGrammar::pluralize(fORMRelated::getRelatedRecordName($class, $related_class, $route))));
 }
コード例 #2
0
ファイル: fORMRelated.php プロジェクト: jsuarez/MyDesign
 /**
  * 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 = fORMRelated::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[] = self::compose('%sPlease select a %3$s', fValidationException::formatField(self::compose('%1$s #%2$s', $related_record_name, $record_number)), $related_record_name);
         }
         $record_number++;
     }
     return $messages;
 }