/** * @return bool * @throws \yii\db\Exception * Сохранение файлов для возможных файлов "быстрых" полей */ public function savePhoto() { for ($i = 1; $i <= Template::OPTIONS_COUNT; $i++) { $option_file = 'option_' . $i . '_file'; $option = 'option_' . $i; if ($this->{$option_file}) { $this->deletePhoto($i); $ext = "." . end(explode(".", $this->{$option_file})); if ($ext === ".") { $ext = '.jpg'; } $name = $this->alias . "_" . $i; $path = self::FROM_ADM_PATH . self::FILES_PATH . $this->id . '/'; $fullname = $path . $name . $ext; if (!file_exists($path)) { mkdir($path, 0777, true); } $this->{$option_file}->saveAs($fullname); $this->{$option_file} = $fullname; Image::thumbnail($fullname, 300, 200, $mode = ManipulatorInterface::THUMBNAIL_OUTBOUND)->save($path . $name . '_thumb' . $ext, ['quality' => 100]); $this->{$option} = self::FILES_PATH . $this->id . '/' . $name . $ext; if (!$this->isNewRecord) { $db = Document::getDb(); $db->createCommand()->update('document', [$option => $this->{$option}], ['id' => $this->id])->execute(); } else { $this->save(); } } } return true; }
/** * Деактивация нескольких документов единовременно. * @return bool */ public function actionMulticlose() { $keys = Yii::$app->request->post('keys'); if ($keys) { $db = Document::getDb(); $db->createCommand()->update('document', ['status' => 0], ['id' => $keys, 'status' => [1, 2]])->execute(); } Yii::$app->getSession()->setFlash('documents-close-success'); return true; }