protected function doClean($values)
 {
     $errorSchema = new sfValidatorErrorSchema($this);
     foreach ($values as $key => $value) {
         $errorSchemaLocal = new sfValidatorErrorSchema($this);
         if (trim($value['quantity']) !== '') {
             foreach ($this->getOption('attributes') as $attribute) {
                 $this->addMessage($attribute->getId(), 'The ' . $attribute->getDisplayTitle() . ' is required.');
                 // quantity is filled but no variation selected
                 if (!$value['rt_shop_variations_list_' . $attribute->getId()]) {
                     $errorSchemaLocal->addError(new sfValidatorError($this, 'required'), 'rt_shop_variations_list_' . $attribute->getId());
                 }
             }
         }
         // no caption and no filename, remove the empty values
         if (trim($value['quantity']) === '') {
             unset($values[$key]);
         }
         // some error for this embedded-form
         if (count($errorSchemaLocal)) {
             $errorSchema->addError($errorSchemaLocal, (string) $key);
         }
     }
     // throws the error for the main form
     if (count($errorSchema)) {
         throw new sfValidatorErrorSchema($this, $errorSchema);
     }
     return $values;
 }
 /**
  * Permet de définir si le formulaire de paramètre pour les jeux de données est valide ou non.
  *
  * @param type $values
  * @return type
  * @throws sfValidatorErrorSchema 
  */
 protected function doClean($values)
 {
     $errorSchema = new sfValidatorErrorSchema($this);
     $name = MyFunction::sluggifyForXML($values['name']);
     $id = isset($values["id"]) ? $values["id"] : -1;
     if ($this->str->getEiDatasetStructureParentId()) {
         /** @var Doctrine_Collection $existing */
         $existing = Doctrine_Core::getTable('EiDataSetStructure')->findByEiDatasetStructureParentIdAndSlug($this->str->getEiDatasetStructureParentId(), $name);
         /** @var EiDataSetStructure $node */
         foreach ($existing as $key => $node) {
             if ($node->getId() == $id) {
                 $existing->remove($key);
             }
         }
     } else {
         $existing = Doctrine_Core::getTable('EiDataSetStructure')->findByEiDatasetStructureParentIdAndSlug("is null", $name);
     }
     if ($existing->count() > 0 && $this->isNew || $existing->count() >= 1 && !$this->isNew) {
         $errorSchema->addError(new sfValidatorError($this, 'name'), 'name');
     }
     // si l'on a trouvé des erreurs, alors on transmet une exception
     if (count($errorSchema)) {
         throw new sfValidatorErrorSchema($this, $errorSchema);
     }
     return $values;
 }
 /**
  * Permet de vérifier, si, dans une sous version, les noms de ses sous versions
  * sont uniques.
  * 
  * @param type $values Les sous versions reçues à la soumission du formulaire
  * @return type
  * @throws sfValidatorErrorSchema 
  */
 protected function doClean($values)
 {
     $errorSchema = new sfValidatorErrorSchema($this);
     //on parcourt chaque sous_versions reçues
     foreach ($values as $key => $value) {
         $errorSchemaLocal = new sfValidatorErrorSchema($this);
         //si le champ delete est a true on supprime la clé
         if ($value['delete'] == true) {
             unset($values[$key]);
         } else {
             if (trim($value['libelle']) == "") {
                 $errorSchemaLocal->addError(new sfValidatorError($this, 'requis'), 'libelle');
             }
             foreach ($values as $keyAux => $valueAux) {
                 //on compare les sous_versions les une par rapport aux autres.
                 //si les libellés sont identiques pour deux sous versions différentes, alors
                 //on ajoute une erreur
                 if ($value['libelle'] == $valueAux['libelle'] && $key != $keyAux) {
                     $errorSchemaLocal->addError(new sfValidatorError($this, 'libelle'), 'libelle');
                 }
             }
         }
         // Si des erreurs sont trouvées, on les ajoute au tableau d'erreurs
         if (count($errorSchemaLocal)) {
             $errorSchema->addError($errorSchemaLocal, (string) $key);
         }
     }
     // si l'on a trouvé des erreurs, alors on transmet une exception
     if (count($errorSchema)) {
         throw new sfValidatorErrorSchema($this, $errorSchema);
     }
     return $values;
 }
 protected function doClean($values)
 {
     $errorSchema = new sfValidatorErrorSchema($this);
     //count($values);
     foreach ($values as $key => $value) {
         $errorSchemaLocal = new sfValidatorErrorSchema($this);
         // parlamentario rellenado pero no el campo voto
         if ($value['id_parlamentario'] && !$value['voto']) {
             $errorSchemaLocal->addError(new sfValidatorError($this, 'required'), 'voto');
         }
         // voto rellenado pero no el campo parlamentario
         if ($value['voto'] && !$value['id_parlamentario']) {
             $errorSchemaLocal->addError(new sfValidatorError($this, 'required'), 'id_parlamentario');
         }
         // no esta ni el parlamentario ni el voto rellando
         if (!$value['id_parlamentario'] && !$value['voto']) {
             unset($values[$key]);
         }
         // some error for this embedded-form
         if (count($errorSchemaLocal)) {
             $errorSchema->addError($errorSchemaLocal, (string) $key);
         }
     }
     // throws the error for the main form
     if (count($errorSchema)) {
         throw new sfValidatorErrorSchema($this, $errorSchema);
     }
     return $values;
 }
Ejemplo n.º 5
0
 public function CheckDates($validator, $values)
 {
     // Additionaly validation
     // Access to form items using  $values['value_name'];
     $apartment = Doctrine_Core::getTable('Apartment')->find($values['apartment_id']);
     $periods = $apartment->Period;
     $error_schema = new sfValidatorErrorSchema($validator);
     $history_period_error = new sfValidatorError($validator, 'Dates are in past or invalid ! Date must be in future.');
     $period_difference_error = new sfValidatorError($validator, 'Period with this date is allready in use !');
     /* Dates are in past for date_from ?! */
     if (strtotime($values['date_from']) < time()) {
         $error_schema->addError($history_period_error, 'date_from');
     }
     /* Dates are in past for date_to ?! */
     if (strtotime($values['date_to']) < time()) {
         $error_schema->addError($history_period_error, 'date_to');
     }
     /* Is date_from already in use ?*/
     foreach ($periods as $period) {
         if (in_array(strtotime($values['date_from']), $period->getDatesBetween())) {
             $error_schema->addError($period_difference_error, 'date_from');
         }
     }
     /* Is date_to already in use ?*/
     foreach ($periods as $period) {
         if (in_array(strtotime($values['date_to']), $period->getDatesBetween())) {
             $error_schema->addError($period_difference_error, 'date_to');
         }
     }
     throw $error_schema;
     return $values;
 }
 protected function doClean($values)
 {
     $errorSchema = new sfValidatorErrorSchema($this);
     foreach ($values as $key => $value) {
         $errorSchemaLocal = new sfValidatorErrorSchema($this);
         // pic is filled but no title
         if ($value['pic'] && !$value['title']) {
             $errorSchemaLocal->addError(new sfValidatorError($this, 'required'), 'title');
         }
         // title is filled but no pic
         if ($value['title'] && !$value['pic']) {
             $errorSchemaLocal->addError(new sfValidatorError($this, 'required'), 'pic');
         }
         // no title and no pic, remove the empty values
         if (!$value['pic'] && !$value['title']) {
             unset($values[$key]);
         }
         // some error for this embedded-form
         if (count($errorSchemaLocal)) {
             $errorSchema->addError($errorSchemaLocal, (string) $key);
         }
     }
     // throws the error for the main form
     if (count($errorSchema)) {
         throw new sfValidatorErrorSchema($this, $errorSchema);
     }
     return $values;
 }
 protected function doClean($value)
 {
     $errorSchema = new sfValidatorErrorSchema($this);
     $errorSchemaLocal = new sfValidatorErrorSchema($this);
     if (!$value['mime_type']) {
         return array();
     } elseif (!$value['title']) {
         $errorSchemaLocal->addError(new sfValidatorError($this, 'title'));
     }
     if (isset($value['uri'])) {
         if (!preg_match("/^[a-zA-Z0-9\\.]+\$/", $value['uri'])) {
             $errorSchemaLocal->addError(new sfValidatorError($this, 'file_not_found'));
         }
         if (!file_exists(sfConfig::get('sf_upload_dir') . '/multimedia/temp/' . $value['uri'])) {
             $errorSchemaLocal->addError(new sfValidatorError($this, 'file_not_found'));
         }
     }
     if (count($errorSchemaLocal)) {
         $errorSchema->addError($errorSchemaLocal, 'title');
     }
     if (count($errorSchema)) {
         throw new sfValidatorErrorSchema($this, $errorSchema);
     }
     return $value;
 }
 protected function doClean($value)
 {
     $errorSchema = new sfValidatorErrorSchema($this);
     $errorSchemaLocal = new sfValidatorErrorSchema($this);
     if ($value['catalogue_unit_ref']) {
         if (!is_numeric($value['catalogue_unit_ref']) && !strpos($value['catalogue_unit_ref'], ',')) {
             $errorSchemaLocal->addError(new sfValidatorError($this, 'wrong_type'), 'catalogue_unit_ref');
         } elseif (strpos($value['catalogue_unit_ref'], ',')) {
             $ids = preg_split('/[,]/', $value['catalogue_unit_ref']);
             foreach ($ids as $key => $id_value) {
                 if (!is_numeric($id_value)) {
                     $errorSchemaLocal->addError(new sfValidatorError($this, 'wrong_structure'), 'catalogue_unit_ref');
                     break;
                 }
             }
         }
     }
     if (count($errorSchemaLocal)) {
         $errorSchema->addError($errorSchemaLocal, 'catalogue_unit_ref');
     }
     if (count($errorSchema)) {
         throw new sfValidatorErrorSchema($this, $errorSchema);
     }
     return $value;
 }
 /**
  * Permet de définir si le formulaire de paramètre pour les versions est valide ou non
  * @param type $values
  * @return type
  * @throws sfValidatorErrorSchema 
  */
 protected function doClean($values)
 {
     $errorSchema = new sfValidatorErrorSchema($this);
     foreach ($values as $key => $value) {
         $errorSchemaLocal = new sfValidatorErrorSchema($this);
         //ni le nom ni la valeur ne sont saisis : on ignore le paramètre
         if (!$value['valeur'] && !$value['nom_param'] || $value['delete'] == true) {
             unset($values[$key]);
         } else {
             // le nom est saisie mais pas la valeur
             if ($value['nom_param'] && !$value['valeur']) {
                 $errorSchemaLocal->addError(new sfValidatorError($this, 'valeur'), 'valeur');
             }
             // valeur saisie mais pas le nom
             if ($value['valeur'] && !$value['nom_param']) {
                 $errorSchemaLocal->addError(new sfValidatorError($this, 'nom_param'), 'nom_param');
             }
             // Si des erreurs sont trouvées, on les ajoute au tableau d'erreurs
             if (count($errorSchemaLocal)) {
                 $errorSchema->addError($errorSchemaLocal, (string) $key);
             }
         }
     }
     // si l'on a trouvé des erreurs, alors on transmet une exception
     if (count($errorSchema)) {
         throw new sfValidatorErrorSchema($this, $errorSchema);
     }
     return $values;
 }
 /**
  * Adds a collection of errors.
  *
  * @param sfValidatorErrorSchema $errorsAn sfValidatorErrorSchema instance
  *
  * @return sfValidatorErrorSchema The current error schema instance
  */
 public function addErrors(sfValidatorErrorSchema $errors)
 {
     foreach ($errors->getGlobalErrors() as $error) {
         $this->addError($error);
     }
     foreach ($errors->getNamedErrors() as $name => $error) {
         $this->addError($error, $name);
     }
     return $this;
 }
 /**
  * Run validation check.
  *
  * @param sfValidatorErrorSchema $errorSchema
  * @param array $values
  */
 private function validate($errorSchema, $values)
 {
     if ($this->isEmpty($values['address_1'])) {
         $errorSchema->addError(new sfValidatorError($this, 'required'), 'address_1');
     }
     if ($this->isEmpty($values['town'])) {
         $errorSchema->addError(new sfValidatorError($this, 'required'), 'town');
     }
     // Not all countries have regions, so this validator is conditional.
     $widget = new rtWidgetFormSelectRegion(array('country' => $values['country']));
     if (count($widget->getRegions()) > 0 && $this->isEmpty($values['state'])) {
         $errorSchema->addError(new sfValidatorError($this, 'required'), 'state');
     }
     if ($this->isEmpty($values['country'])) {
         $errorSchema->addError(new sfValidatorError($this, 'required'), 'country');
     }
     if ($this->isEmpty($values['postcode'])) {
         $errorSchema->addError(new sfValidatorError($this, 'required'), 'postcode');
     }
     if (!sfConfig::get('app_rt_account_phone_is_optional', true) && $this->isEmpty($values['phone'])) {
         $errorSchema->addError(new sfValidatorError($this, 'required'), 'phone');
     }
     if ($this->getOption('use_names')) {
         if ($this->isEmpty($values['first_name'])) {
             $errorSchema->addError(new sfValidatorError($this, 'required'), 'first_name');
         }
         if ($this->isEmpty($values['last_name'])) {
             $errorSchema->addError(new sfValidatorError($this, 'required'), 'last_name');
         }
     }
 }
 protected function doClean($values)
 {
     $errorSchema = new sfValidatorErrorSchema($this);
     // Both month and year must be set.
     if ($values['cc_expire']['month'] === '' || $values['cc_expire']['year'] === '') {
         $errorSchema->addError(new sfValidatorError($this, 'expiry'), 'cc_expire');
     }
     if (count($errorSchema)) {
         throw new sfValidatorErrorSchema($this, $errorSchema);
     }
     return $values;
 }
 protected function throwError($numValid, $error)
 {
     $errorSchema = new sfValidatorErrorSchema($this);
     if ($this->getOption('throw_global_error')) {
         // Add global error
         $errorSchema->addError(new sfValidatorError($this, 'global_invalid', array($error => $this->getOption($error), 'num_valid' => $numValid, 'fields' => implode(', ', $this->getOption('fields')), 'labels' => implode(', ', $this->getOption('labels')))));
     }
     $error = new sfValidatorError($this, 'invalid', array($error => $this->getOption($error)));
     // Add an error for each of the fields
     foreach ($this->getOption('fields') as $field) {
         $errorSchema->addError($error, $field);
     }
     throw $errorSchema;
 }
 protected function doClean($value)
 {
     $errorSchema = new sfValidatorErrorSchema($this);
     $errorSchemaLocal = new sfValidatorErrorSchema($this);
     if (!$value['comment']) {
         return array();
     }
     if (count($errorSchemaLocal)) {
         $errorSchema->addError($errorSchemaLocal, 'comment');
     }
     if (count($errorSchema)) {
         throw new sfValidatorErrorSchema($this, $errorSchema);
     }
     return $value;
 }
 /**
  * Permet de définir si le formulaire de paramètre pour les versions est valide ou non
  * @param type $values
  * @return type
  * @throws sfValidatorErrorSchema 
  */
 protected function doClean($values)
 {
     $errorSchema = new sfValidatorErrorSchema($this);
     $name = $values['name'];
     try {
         $tag = new DOMElement($name);
     } catch (Exception $e) {
         $errorSchema->addError(new sfValidatorError($this, 'name'), 'name');
     }
     // si l'on a trouvé des erreurs, alors on transmet une exception
     if (count($errorSchema)) {
         throw new sfValidatorErrorSchema($this, $errorSchema);
     }
     return $values;
 }
 public function bind(array $taintedValues = null, array $taintedFiles = null)
 {
     parent::bind($taintedValues, $taintedFiles);
     if (count($this->errorSchema)) {
         $newErrorSchema = new sfValidatorErrorSchema($this->validatorSchema);
         foreach ($this->errorSchema as $name => $error) {
             if ($this->pluginFieldKey === $name) {
                 $newErrorSchema->addError($error);
             } else {
                 $newErrorSchema->addError($error, $name);
             }
         }
         $this->errorSchema = $newErrorSchema;
     }
 }
 protected function doClean($value)
 {
     $errorSchema = new sfValidatorErrorSchema($this);
     $errorSchemaLocal = new sfValidatorErrorSchema($this);
     if ($value['user_ref'] == 0) {
         return array();
     }
     if (count($errorSchemaLocal)) {
         $errorSchema->addError($errorSchemaLocal, 'user_ref_value');
     }
     if (count($errorSchema)) {
         throw new sfValidatorErrorSchema($this, $errorSchema);
     }
     return $value;
 }
 protected function doClean($values)
 {
     $errorSchema = new sfValidatorErrorSchema($this);
     foreach ($values as $key => $value) {
         $errorSchemaLocal = new sfValidatorErrorSchema($this);
         // no se han rellenado los campos, se eliminan los valores vacíos
         if (!$value['direccion'] && !$value['alias'] && !$value['zip']) {
             unset($values[$key]);
         }
         // Si al menos si direccion esta pero no alias o zip
         if ($value['direccion'] && (!$value['alias'] || !$value['zip'])) {
             if (!$value['alias']) {
                 $errorSchemaLocal->addError(new sfValidatorError($this, 'required'), 'alias');
             }
             if (!$value['zip']) {
                 $errorSchemaLocal->addError(new sfValidatorError($this, 'required'), 'zip');
             }
         }
         // Si al menos alias esta pero no direccion o zip
         if ($value['alias'] && (!$value['direccion'] || !$value['zip'])) {
             if (!$value['direccion']) {
                 $errorSchemaLocal->addError(new sfValidatorError($this, 'required'), 'direccion');
             }
             if (!$value['zip']) {
                 $errorSchemaLocal->addError(new sfValidatorError($this, 'required'), 'zip');
             }
         }
         // Si al menos zip esta pero no alias o zip
         if ($value['zip'] && (!$value['alias'] || !$value['direccion'])) {
             if (!$value['alias']) {
                 $errorSchemaLocal->addError(new sfValidatorError($this, 'required'), 'alias');
             }
             if (!$value['direccion']) {
                 $errorSchemaLocal->addError(new sfValidatorError($this, 'required'), 'direccion');
             }
         }
         // algun error para este formulario embebido
         if (count($errorSchemaLocal)) {
             $errorSchema->addError($errorSchemaLocal, (string) $key);
         }
     }
     // lanza un error para el formulario principal
     if (count($errorSchema)) {
         throw new sfValidatorErrorSchema($this, $errorSchema);
     }
     return $values;
 }
 protected function doClean($value)
 {
     $errorSchema = new sfValidatorErrorSchema($this);
     $errorSchemaLocal = new sfValidatorErrorSchema($this);
     if (!$value['value_defined'] && $value['notion_concerned']) {
         $errorSchemaLocal->addError(new sfValidatorError($this, 'value_defined'));
     } elseif (!$value['value_defined'] && !$value['notion_concerned']) {
         return array();
     }
     if (count($errorSchemaLocal)) {
         $errorSchema->addError($errorSchemaLocal, 'value_defined');
     }
     if (count($errorSchema)) {
         throw new sfValidatorErrorSchema($this, $errorSchema);
     }
     return $value;
 }
 protected function doClean($value)
 {
     $errorSchema = new sfValidatorErrorSchema($this);
     $errorSchemaLocal = new sfValidatorErrorSchema($this);
     if ($value['insurance_currency'] && !$value['insurance_value']) {
         $errorSchemaLocal->addError(new sfValidatorError($this, 'insurance_value'));
     } elseif (!$value['insurance_value'] && !$value['insurance_currency']) {
         return array();
     }
     if (count($errorSchemaLocal)) {
         $errorSchema->addError($errorSchemaLocal, 'insurance_value');
     }
     if (count($errorSchema)) {
         throw new sfValidatorErrorSchema($this, $errorSchema);
     }
     return $value;
 }
 protected function doClean($value)
 {
     $errorSchema = new sfValidatorErrorSchema($this);
     $errorSchemaLocal = new sfValidatorErrorSchema($this);
     if (!$value['code_category']) {
         return array();
     } elseif (!$value['code'] && !$value['code_prefix'] && !$value['code_suffix']) {
         $errorSchemaLocal->addError(new sfValidatorError($this, 'code'));
     }
     if (count($errorSchemaLocal)) {
         $errorSchema->addError($errorSchemaLocal, 'code');
     }
     if (count($errorSchema)) {
         throw new sfValidatorErrorSchema($this, $errorSchema);
     }
     return $value;
 }
 protected function doClean($value)
 {
     $errorSchema = new sfValidatorErrorSchema($this);
     $errorSchemaLocal = new sfValidatorErrorSchema($this);
     if ($value['item_visible'] != "true") {
         return array();
     }
     if ($value['from_date'] != '' && $value['to_date'] != '' && $value['from_date'] > $value['to_date']) {
         $errorSchema->addError(new sfValidatorError($this, 'from_date'));
     }
     if (count($errorSchemaLocal)) {
         $errorSchema->addError($errorSchemaLocal, 'details');
     }
     if (count($errorSchema)) {
         throw new sfValidatorErrorSchema($this, $errorSchema);
     }
     return $value;
 }
 protected function doClean($value)
 {
     $errorSchema = new sfValidatorErrorSchema($this);
     $errorSchemaLocal = new sfValidatorErrorSchema($this);
     if ($value['from_date'] != '' && $value['to_date'] != '' && $value['from_date'] > $value['to_date']) {
         $errorSchema->addError(new sfValidatorError($this, 'from_date'));
     }
     if ($value['from_date'] != '' && $value['extended_to_date'] != '' && $value['from_date'] > $value['extended_to_date']) {
         $errorSchema->addError(new sfValidatorError($this, 'from_date'));
     }
     if ($value['to_date'] != '' && $value['extended_to_date'] != '' && $value['to_date'] > $value['extended_to_date']) {
         $errorSchema->addError(new sfValidatorError($this, 'end_date'));
     }
     if (count($errorSchema)) {
         throw new sfValidatorErrorSchema($this, $errorSchema);
     }
     return $value;
 }
 protected function doClean($value)
 {
     $errorSchema = new sfValidatorErrorSchema($this);
     $user = Doctrine::getTable('Users')->getUserByLoginAndEMail($value['user_name'], $value['user_email']);
     if (!$user) {
         $user = Doctrine::getTable('Users')->getUserByLoginWithEmailOnly($value['user_name']);
         if ($user && count($user->UsersComm) == 0) {
             $user = null;
         }
     }
     if (!$user) {
         $errorSchema->addError(new sfValidatorError($this, 'no_association'), 'global');
     }
     if (count($errorSchema)) {
         throw new sfValidatorErrorSchema($this, $errorSchema);
     }
     return $value;
 }
 protected function doClean($values)
 {
     $size = 0;
     foreach (array('nametype' => array(Petition::NAMETYPE_SPLIT => 2, Petition::NAMETYPE_FULL => 1), 'with_address' => array(0 => 0, '0' => 0, 1 => 1, '1' => 1, 2 => 2, '2' => 2), 'with_country' => array(0 => 0, '0' => 0, 1 => 1, '1' => 1), 'with_comments' => array(0 => 0, '0' => 0, 1 => 1, '1' => 2)) as $field => $opt) {
         $size += $opt[$values[$field]];
     }
     $errorSchema = new sfValidatorErrorSchema($this);
     if ($size > 5) {
         $errorSchema->addError(new sfValidatorError($this, 'You have selected too many form fields.'), 'customise');
     }
     if (!$values['with_country'] && !$values['default_country']) {
         $errorSchema->addError(new sfValidatorError($this, 'Required if you do not ask for country.'), 'default_country');
     }
     if ($errorSchema->count()) {
         throw $errorSchema;
     }
     return $values;
 }
 protected function doClean($value)
 {
     $errorSchema = new sfValidatorErrorSchema($this);
     $errorSchemaLocal = new sfValidatorErrorSchema($this);
     if ($value['property_accuracy'] && !$value['property_value']) {
         $errorSchemaLocal->addError(new sfValidatorError($this, 'required'), 'property_value');
     }
     if (!$value['property_value'] && !$value['property_accuracy']) {
         return array();
     }
     if (count($errorSchemaLocal)) {
         $errorSchema->addError($errorSchemaLocal, 'property_value');
     }
     if (count($errorSchema)) {
         throw new sfValidatorErrorSchema($this, $errorSchema);
     }
     return $value;
 }
 /**
  * @see sfValidatorBase
  */
 protected function doClean($values)
 {
     if (null === $values) {
         $values = array();
     }
     if (!is_array($values)) {
         throw new InvalidArgumentException(sprintf('You must pass an array parameter to the clean() method for filter field "%s"', $this->getOption('field')));
     }
     $value = isset($values[$this->getOption('field')]) ? $values[$this->getOption('field')] : null;
     try {
         $values[$this->getOption('field')] = $this->getOption('validator')->clean($value);
     } catch (sfValidatorError $error) {
         $errorSchema = new sfValidatorErrorSchema($this);
         $errorSchema->addError($error, $this->getOption('field'));
         throw $errorSchema;
     }
     return $values;
 }
Ejemplo n.º 28
0
 /**
  * Returns the form field associated with the name (implements the ArrayAccess interface).
  *
  * @param string $name The offset of the value to get
  *
  * @return sfFormField A form field instance
  */
 public function offsetGet($name)
 {
     if (!isset($this->fields[$name])) {
         if (is_null($widget = $this->widget[$name])) {
             throw new InvalidArgumentException(sprintf('Widget "%s" does not exist.', $name));
         }
         $error = isset($this->error[$name]) ? $this->error[$name] : null;
         if ($widget instanceof sfWidgetFormSchema) {
             $class = 'sfFormFieldSchema';
             if ($error && !$error instanceof sfValidatorErrorSchema) {
                 $error = new sfValidatorErrorSchema($error->getValidator(), array($error));
             }
         } else {
             $class = 'sfFormField';
         }
         $this->fields[$name] = new $class($widget, $this, $name, isset($this->value[$name]) ? $this->value[$name] : null, $error);
     }
     return $this->fields[$name];
 }
 protected function doClean($values)
 {
     $errorSchema = new sfValidatorErrorSchema($this);
     foreach ($values as $key => $value) {
         $errorSchemaLocal = new sfValidatorErrorSchema($this);
         // no caption and no filename, remove the empty values
         if (!$value['title']) {
             unset($values[$key]);
         }
         // some error for this embedded-form
         if (count($errorSchemaLocal)) {
             $errorSchema->addError($errorSchemaLocal, (string) $key);
         }
     }
     // throws the error for the main form
     if (count($errorSchema)) {
         throw new sfValidatorErrorSchema($this, $errorSchema);
     }
     return $values;
 }
 protected function doClean($value)
 {
     $errorSchema = new sfValidatorErrorSchema($this);
     $errorSchemaLocal = new sfValidatorErrorSchema($this);
     if ($value['unit_type'] == 'specimens') {
         $value['mineral_ref'] = null;
         $value['taxon_ref'] = null;
         $value['institution_ref'] = null;
         $value['quantity'] = null;
         $value['source_name'] = null;
         $value['source_id'] = null;
     } elseif ($value['unit_type'] == 'taxon') {
         $value['mineral_ref'] = null;
         $value['specimen_related_ref'] = null;
         $value['institution_ref'] = null;
         $value['quantity'] = null;
         $value['source_name'] = null;
         $value['source_id'] = null;
     } elseif ($value['unit_type'] == 'mineral') {
         $value['taxon_ref'] = null;
         $value['specimen_related_ref'] = null;
         $value['institution_ref'] = null;
         $value['source_name'] = null;
         $value['source_id'] = null;
     }
     // If type is known but nothing else
     if (!$value['taxon_ref'] && !$value['mineral_ref'] && !$value['specimen_related_ref'] && !$value['source_id'] && $value['relationship_type']) {
         $errorSchemaLocal->addError(new sfValidatorError($this, 'unit_ref'));
     }
     if (!$value['taxon_ref'] && !$value['mineral_ref'] && !$value['specimen_related_ref'] && !$value['source_id'] && !$value['relationship_type']) {
         return array();
     }
     if (count($errorSchemaLocal)) {
         $errorSchema->addError($errorSchemaLocal, 'unit_ref');
     }
     if (count($errorSchema)) {
         throw new sfValidatorErrorSchema($this, $errorSchema);
     }
     return $value;
 }