Ejemplo n.º 1
0
 /**
  * Add validation so that if you change any fields that are considered frozen,
  * it would add an error.
  * In case of associations, if the count of the items has been changed,
  * also add an error.
  *
  * @param  Jam_Model      $model
  * @param  Jam_Event_Data $data
  */
 public function model_after_check(Jam_Model $model, Jam_Event_Data $data)
 {
     if ($model->loaded() and $model->is_frozen() and !$model->is_just_frozen()) {
         foreach ($this->_associations as $name) {
             if ($model->meta()->association($name) instanceof Jam_Association_Collection and count($model->{$name}) !== count($model->{$name}->original())) {
                 $model->errors()->add($name, 'frozen');
             }
         }
         foreach ($this->_fields as $name) {
             if ($model->changed($name)) {
                 $model->errors()->add($name, 'frozen');
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Perform checks on all changed items from this collection
  * @param  Jam_Model $model
  */
 public function model_after_check(Jam_Model $model)
 {
     if ($model->changed($this->name) and !$model->{$this->name}->check_changed()) {
         $model->errors()->add($this->name, 'association_collection');
     }
 }
Ejemplo n.º 3
0
 /**
  * Perform validation on the belonging model, if it was changed.
  * @param  Jam_Model      $model
  * @param  Jam_Event_Data $data
  * @param  array         $changed
  */
 public function model_after_check(Jam_Model $model, Jam_Event_Data $data, $changed)
 {
     if ($value = Arr::get($changed, $this->name) and Jam_Association::is_changed($value)) {
         if (!$model->{$this->name}->is_validating() and !$model->{$this->name}->check()) {
             $model->errors()->add($this->name, 'association', array(':errors' => $model->{$this->name}->errors()));
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * After the validation for this field passes without any errors, fire up transformations and thumbnail generation
  * @param  Jam_Model $model
  */
 public function model_after_check(Jam_Model $model)
 {
     if ($model->changed($this->name) and !$model->errors($this->name) and $upload_file = $model->{$this->name} and $upload_file->source()) {
         $upload_file->transform();
     }
 }
Ejemplo n.º 5
0
 private function _model_messages_dump(Jam_Model $model)
 {
     $messages = array();
     foreach ($model->errors() as $attribute_name => $errors) {
         if ($model->meta()->association($attribute_name) instanceof Jam_Association_Collection) {
             foreach ($model->{$attribute_name} as $i => $item) {
                 if (!$item->is_valid()) {
                     $messages[] = UTF8::ucfirst(Inflector::humanize($attribute_name)) . ' (' . $i . '): ' . join(', ', $this->_model_messages_dump($item));
                 }
             }
         } elseif ($model->meta()->association($attribute_name) and $model->{$attribute_name}) {
             $messages[] = UTF8::ucfirst(Inflector::humanize($attribute_name)) . ': ' . join(', ', $this->_model_messages_dump($model->{$attribute_name}));
         } else {
             foreach ($errors as $error => $params) {
                 $messages[] = Jam_Errors::message($model->meta()->errors_filename(), $attribute_name, $error, Arr::merge($params, array(':model' => $model->meta()->model(), ':attribute' => Jam_Errors::attribute_label($model->meta(), $attribute_name))));
             }
         }
     }
     return $messages;
 }