Beispiel #1
0
 /**
  * Initialize a behaviour for a model
  *
  * @param \Quaver\Model\Base $model
  */
 public function initialize($model)
 {
     $model->on('getChange', function ($change, $event) {
         $model = $event['target'];
         $field = $event['field'];
         if (ucfirst($model->fields[$field]['type']) === 'Hash') {
             if ($model->{$field} !== null && $model->{$field} !== $model->getOriginalValue($field)) {
                 if (!empty($model->{$field}) || $model->getOriginalValue($field) !== null) {
                     return $model->{$field};
                 } else {
                     return null;
                 }
             }
         }
         return $change;
     });
     $model->on('hasChanges', function ($hasChanges, $event) {
         if (!$hasChanges) {
             $model = $event['target'];
             foreach ($model->fields as $field => &$def) {
                 if (ucfirst($def['type']) === 'Hash' && $model->{$field} !== $model->getOriginalValue($field)) {
                     if (!empty($model->{$field}) || $model->getOriginalValue($field) !== null) {
                         return true;
                     }
                 }
             }
         }
         return $hasChanges;
     });
     $model->on('getChanges', function ($changes, $event) {
         $model = $event['target'];
         foreach ($model->fields as $field => &$def) {
             if (ucfirst($def['type']) === 'Hash' && $model->{$field} !== $model->getOriginalValue($field)) {
                 if (!empty($model->{$field}) || $model->getOriginalValue($field) !== null) {
                     $changes[$field] = $model->{$field};
                 } else {
                     unset($changes[$field]);
                 }
             }
         }
         return $changes;
     });
 }
Beispiel #2
0
 /**
  * Initialize a behaviour for a model
  *
  * @param \Quaver\Model\Base $model
  * @param array $options
  */
 public function initialize($model, $options)
 {
     $model->on('preSave', [$this, 'preSave']);
 }
Beispiel #3
0
 /**
  * Initialize a behaviour for a model
  *
  * @param \Quaver\Model\Base $model
  * @param array $options
  */
 public function initialize($model, $options)
 {
     $model->on('preDelete', [$this, 'preDelete']);
     $model->on('isDeleted', [$this, 'isDeleted']);
 }