public function applyFilterChain(Item $file, $fileSavePath) { $loadFrom = $file->getServerSource(); foreach (StorageFilterChain::find()->where(['filter_id' => $this->id])->joinWith('effect')->all() as $chain) { $response = $chain->applyFilter($loadFrom, $fileSavePath); $loadFrom = $fileSavePath; } return true; }
/** * Update and save filter corresponding to the model, refresh chain values. * * @return bool */ public function save() { // get the filter model based on the current filter. $filterModel = $this->findModel(); // update the name of the filter if changed if ($filterModel->name !== $this->name()) { $filterModel->setAttribute('name', $this->name()); $filterModel->update(false); $this->addLog("Filter name '" . $this->name() . "' have been updated for identifier '" . static::identifier() . "'."); } // array containing the processed chain ids $processed = []; $removeImages = false; foreach ($this->getChain() as $chain) { // get filter chain for filter and effect $model = StorageFilterChain::find()->where(['filter_id' => $filterModel->id, 'effect_id' => $chain['effect_id']])->one(); if ($model) { if (Json::decode($chain['effect_json_values']) != $model->effect_json_values) { $model->effect_json_values = $chain['effect_json_values']; if ($model->update(false)) { $removeImages = true; $this->addLog("Effect chain option have been updated for '{$filterModel->name}'."); } } } else { $model = new StorageFilterChain(); $model->setAttributes(['filter_id' => $filterModel->id, 'effect_id' => $chain['effect_id'], 'effect_json_values' => $chain['effect_json_values']]); if ($model->save(false)) { $removeImages = true; $this->addLog("Effect chain option have been added for '{$filterModel->name}'."); } } $processed[] = $model->id; } // remove not used chains for the current filter foreach (StorageFilterChain::find()->where(['not in', 'id', $processed])->andWhere(['=', 'filter_id', $filterModel->id])->all() as $deletion) { $this->addLog("Effect chain option have been removed for '{$filterModel->name}'"); $deletion->delete(); $removeImages = true; } if ($removeImages) { $this->addLog("remove image filter source cache."); $filterModel->removeImageSources(); } return true; }