Object::extraBeforeSave PHP Method

extraBeforeSave() public static method

public static extraBeforeSave ( $type = 'update', $object )
    public static function extraBeforeSave($type = 'update', $object)
    {
        switch ($type) {
            case 'update':
                $current_time = time();
                $current_time_gmt = local_to_gmt(time());
                $object->object_modified = $current_time;
                $object->object_modified_gmt = $current_time_gmt;
                break;
            case 'create':
                if (!isConsoleApp() && user()->id) {
                    $object->object_author = user()->id;
                } else {
                    $object->object_author = 0;
                }
                $current_time = time();
                $current_time_gmt = local_to_gmt(time());
                $object->object_date = $current_time;
                $object->object_date_gmt = $current_time_gmt;
                $object->object_modified = $current_time;
                $object->object_modified_gmt = $current_time_gmt;
                if ($object->guid == '') {
                    $object->guid = uniqid();
                }
                break;
        }
    }

Usage Example

Ejemplo n.º 1
0
 protected function beforeSave()
 {
     if (parent::beforeSave()) {
         if ($this->isNewRecord) {
             $this->object_type = 'product';
             Object::extraBeforeSave('create', $this);
         } else {
             Object::extraBeforeSave('update', $this);
         }
         return true;
     } else {
         return false;
     }
 }