Esempio 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');
             }
         }
     }
 }