/**
  * Updates an existing MarketingImage model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param string $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post())) {
         $imageName = $model->marketing_image_name;
         $oldImage = MarketingImage::find('marketing_image_name')->where(['id' => $id])->one();
         if ($oldImage->marketing_image_name != $imageName) {
             throw new ForbiddenHttpException('You cannot change the name, you must delete instead.');
         }
         if ($model->file = UploadedFile::getInstance($model, 'file')) {
             $thumbName = 'uploads/' . 'thumbnail/' . $imageName . 'thumb.' . $model->file->extension;
             $model->save();
         } else {
             $model->save();
         }
         if ($model->file) {
             $fileName = 'uploads/' . $imageName . '.' . $model->file->extension;
             $model->file->saveAs($fileName);
             Image::thumbnail($fileName, 60, 60)->save($thumbName, ['quality' => 50]);
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model]);
     }
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = MarketingImage::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->setSort(['attributes' => ['id', 'marketing_image_name', 'marketing_image_path', 'marketing_image_caption', 'marketing_image_caption_title', 'marketing_image_is_featured', 'marketing_image_is_active', 'marketing_image_weight', 'statusName' => ['asc' => ['status.status_name' => SORT_ASC], 'desc' => ['status.status_name' => SORT_DESC], 'label' => 'Status']]]);
     if (!($this->load($params) && $this->validate())) {
         $query->joinWith(['status']);
         return $dataProvider;
     }
     $this->addSearchParameter($query, 'id');
     $this->addSearchParameter($query, 'marketing_image_name', true);
     $this->addSearchParameter($query, 'marketing_image_path', true);
     $this->addSearchParameter($query, 'marketing_image_caption', true);
     $this->addSearchParameter($query, 'marketing_image_caption_title', true);
     $this->addSearchParameter($query, 'marketing_image_is_featured');
     $this->addSearchParameter($query, 'marketing_image_is_active');
     $this->addSearchParameter($query, 'marketing_image_weight');
     $this->addSearchParameter($query, 'status_id');
     // filter by gender name
     $query->joinWith(['status' => function ($q) {
         $q->andFilterWhere(['=', 'status.status_name', $this->statusName]);
     }]);
     return $dataProvider;
 }