示例#1
0
文件: Collection.php 项目: Konro1/pms
 /**
  * Persist this collection in the database
  * @param  Jam_Model $model
  */
 public function model_after_save(Jam_Model $model)
 {
     if ($model->changed($this->name) and $collection = $model->{$this->name} and $collection->changed()) {
         $collection->save_changed();
         $this->save($model, $collection);
     }
 }
示例#2
0
文件: Uploadable.php 项目: Konro1/pms
 public function model_after_check(Jam_Model $model, Jam_Event_Data $data)
 {
     if ($model->changed($this->_name) and is_file($model->{$this->_name}->file())) {
         $dims = @getimagesize($model->{$this->_name}->file());
         if ($dims) {
             list($model->{$this->_name . '_width'}, $model->{$this->_name . '_height'}) = $dims;
         }
     }
 }
示例#3
0
 public function model_before_check(Jam_Model $model)
 {
     foreach ($this->_parents as $child => $parent) {
         $child_association = $model->meta()->association_insist($child);
         $parent_association = $model->meta()->association_insist($parent);
         if ($model->changed($child) and $model->{$child} and !$model->{$child}->parent and $model->{$parent}) {
             $model->{$child}->parent = $model->{$parent};
         }
     }
 }
示例#4
0
 public function model_before_check(Jam_Model $model)
 {
     if (!$model->loaded() or $model->changed($this->_ip_field)) {
         $info = $this->geoip_record($model->{$this->_ip_field});
         foreach ($this->_locations as $association => $info_name) {
             if (isset($info[$info_name])) {
                 $model->{$association} = Jam::find_or_build('location', array('name' => $info[$info_name]));
             }
         }
     }
 }
示例#5
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');
             }
         }
     }
 }
示例#6
0
文件: Sluggable.php 项目: Konro1/pms
 /**
  * Called after save.
  * If the slug uses the primary key it is built after save and it is updated
  * with an additional database query.
  *
  * @param  Jam_Model $model
  */
 public function model_after_save(Jam_Model $model)
 {
     if ($this->auto_save() and $this->uses_primary_key() and !$model->changed('slug')) {
         // Use the built in slug transformation
         $model->slug = $model->build_slug();
         if ($model->slug != $model->original('slug')) {
             Jam::update($this->_model)->where_key($model->id())->value('slug', $model->slug)->execute();
         }
     }
 }
示例#7
0
文件: Upload.php 项目: Konro1/pms
 /**
  * Cleanup temporary file directories when the files are successfully saved
  * @param  Jam_Model $model
  * @param  boolean $is_changed
  */
 public function model_after_save(Jam_Model $model)
 {
     if ($model->changed($this->name) and $upload_file = $model->{$this->name} and $upload_file->source()) {
         $upload_file->server($this->dynamic_server ? $model->{$this->dynamic_server} : $this->server)->path($this->path($model));
         // Delete the old file if there was one
         if ($this->delete_file and $original = $model->original($this->name)) {
             $this->upload_file($model)->filename($original)->delete();
         }
         $upload_file->save();
     }
     if ($model->changed($this->name) and $upload_file = $model->{$this->name}) {
         $upload_file->clear();
     }
 }
示例#8
0
文件: Sortable.php 项目: Konro1/pms
 private function _is_scope_changed(Jam_Model $model)
 {
     if (!$this->_scope) {
         return FALSE;
     }
     foreach ((array) $this->_scope as $scope_field) {
         if ($model->changed($scope_field)) {
             return TRUE;
         }
     }
     return FALSE;
 }