Example #1
0
 /**
  * Set the UpdatedAt property to the current time.
  *
  * @param
  *        	Model Model object subject of this observer method
  */
 public function before_update(Model $obj)
 {
     if ($obj->is_changed()) {
         $obj->{$this->_property} = $this->_mysql_timestamp ? \Date::time()->format('mysql') : \Date::time()->get_timestamp();
     }
 }
Example #2
0
 /**
  * Creates a new slug (unique by default) and update the object
  *
  * @param  Model  Model object subject of this observer method
  */
 public function before_update(Model $obj)
 {
     // determine the slug
     $properties = (array) $this->_source;
     $source = '';
     foreach ($properties as $property) {
         $source .= $this->_separator . $obj->{$property};
     }
     $slug = \Inflector::friendly_title(substr($source, 1), $this->_separator, true);
     // update it if it's different from the current one
     // and is not manually assigned
     if ($obj->{$this->_property} !== $slug) {
         $overwrite = $this->_overwrite;
         if ($overwrite === false and !$obj->is_changed($this->_property)) {
             $this->_overwrite = true;
         }
         $this->before_insert($obj);
         $this->_overwrite = $overwrite;
     }
 }
Example #3
0
 public function before_save(Model $obj)
 {
     if ($obj->is_new() or $obj->is_changed()) {
         $obj->{static::$property} = static::$mysql_timestamp ? \Date::time()->format('mysql') : \Date::time()->get_timestamp();
     }
 }