Example #1
0
 public function save()
 {
     $filterId = $this->getFilterId();
     $processed = [];
     foreach ($this->getChain() as $chain) {
         $model = \admin\models\StorageFilterChain::find()->where(['filter_id' => $filterId, 'effect_id' => $chain['effect_id']])->one();
         if ($model) {
             $model->effect_json_values = $chain['effect_json_values'];
             if ($model->save()) {
                 $this->log[] = "updated existing chain value for {$filterId}.";
                 $processed[] = $model->id;
             }
         } else {
             $insert = new \admin\models\StorageFilterChain();
             $insert->attributes = ['filter_id' => $filterId, 'effect_id' => $chain['effect_id'], 'effect_json_values' => $chain['effect_json_values']];
             if ($insert->save()) {
                 $this->log[] = "insert new chain value for {$filterId} and {$chain['effect_id']}.";
                 $processed[] = $insert->id;
             }
         }
     }
     $where = [];
     foreach ($processed as $id) {
         $where[] = 'id <> ' . $id;
     }
     // find old effects
     $data = \admin\models\StorageFilterChain::find()->where('(' . implode(' AND ', $where) . ') AND filter_id=' . $filterId)->all();
     foreach ($data as $deletion) {
         $this->log[] = "deleted old chain value {$deletion->id}.";
         $deletion->delete();
     }
     return $this->log;
 }
Example #2
0
 public function callbackAddEffect($effectId, $effectArguments)
 {
     $model = new \admin\models\StorageFilterChain();
     $model->setAttributes(['filter_id' => $this->getItemId(), 'effect_id' => $effectId, 'effect_json_values' => $effectArguments]);
     if ($model->save()) {
         return $this->response(true, []);
     }
     return $this->response(false, $model->getErrors());
 }