/**
  * Deletes an existing PromoCategory model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $promoModel = Promo::find()->andWhere(['category_id' => $id])->one();
     if (null === $promoModel) {
         $this->findModel($id)->delete();
     } else {
         Yii::$app->session->setFlash('alert', ['body' => \Yii::t('backend', 'Can not delete category #' . $id . '. It used in other table. Change category for promo #' . $promoModel->id . ' before delete.'), 'options' => ['class' => 'alert-error']]);
     }
     return $this->redirect(['index']);
 }
Example #2
0
 /**
  * Creates data provider instance with search query applied
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Promo::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'slug' => $this->slug, 'author_id' => $this->author_id, 'category_id' => $this->category_id, 'updater_id' => $this->updater_id, 'status' => $this->status, 'published_at' => $this->published_at, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'weight', $this->weight])->andFilterWhere(['like', 'body', $this->body]);
     return $dataProvider;
 }
Example #3
0
 /**
  * Creates data provider instance with search query applied
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Promo::find();
     if (!\Yii::$app->user->can('administrator')) {
         $query->forDomain();
     }
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'slug' => $this->slug, 'author_id' => $this->author_id, 'category_id' => $this->category_id, 'updater_id' => $this->updater_id, 'status' => $this->status, 'published_at' => $this->published_at, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'domain_id' => $this->domain_id]);
     $query->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'weight', $this->weight])->andFilterWhere(['like', 'body', $this->body])->andFilterWhere(['like', 'before_body', $this->before_body])->andFilterWhere(['like', 'after_body', $this->after_body])->andFilterWhere(['like', 'on_scenario', $this->on_scenario]);
     return $dataProvider;
 }
Example #4
0
 /**
  * Creates data provider instance with search query applied
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Promo::find();
     $query->joinWith(['author']);
     if (!\Yii::$app->user->can('administrator')) {
         $query->forDomain();
     }
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'slug' => $this->slug, 'author_id' => $this->author_id, 'category_id' => $this->category_id, 'updater_id' => $this->updater_id, 'status' => $this->status, 'domain_id' => $this->domain_id]);
     if ($this->search_date_published != '') {
         $this->data_begin_published = strtotime($this->search_date_published);
         $this->data_end_published = strtotime($this->search_date_published) + 24 * 60 * 60;
     }
     $query->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'weight', $this->weight])->andFilterWhere(['like', 'body', $this->body])->andFilterWhere(['like', 'before_body', $this->before_body])->andFilterWhere(['like', 'after_body', $this->after_body])->andFilterWhere(['like', 'on_scenario', $this->on_scenario])->andFilterWhere(['between', 'promo.published_at', $this->data_begin_published, $this->data_end_published])->andFilterWhere(['like', 'user.username', $this->author]);
     return $dataProvider;
 }
Example #5
0
 /**
  * Creates a new Promo model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     foreach (Yii::$app->params['availableLocales'] as $key => $value) {
         $currentModel = Promo::getLocaleInstance($key);
         $currentModel->locale = $key;
         if (Yii::$app->request->get('scenario')) {
             $currentModel->on_scenario = Yii::$app->request->get('scenario');
         }
         $models[$key] = $currentModel;
     }
     //set data from default model
     if (Yii::$app->request->get('locale_group_id')) {
         $defaultDomainModels = Promo::find()->andFilterWhere(['domain_id' => Yii::getAlias('@defaultDomainId'), 'locale_group_id' => Yii::$app->request->get('locale_group_id')])->all();
         foreach ($defaultDomainModels as $key => $value) {
             if (!in_array($value->locale, array_keys(Yii::$app->params['availableLocales']))) {
                 continue;
             }
             $models[$value->locale]->slug = $value->slug;
             $models[$value->locale]->title = $value->title;
             $models[$value->locale]->head = $value->head;
             $models[$value->locale]->body = $value->body;
             $models[$value->locale]->thumbnail = $value->thumbnail;
             $models[$value->locale]->categoriesList = $this->getCategoriesListIds($value->id);
             $models[$value->locale]->before_body = $value->before_body;
             $models[$value->locale]->after_body = $value->after_body;
         }
     }
     $model = new MultiModel(['models' => $models]);
     if ($model->load(Yii::$app->request->post()) && Promo::multiSave($model)) {
         return $this->redirect(['index']);
     } else {
         switch (Yii::$app->request->get('scenario')) {
             case 'extend':
                 $viewName = 'extend';
                 break;
             default:
                 $viewName = 'create';
         }
         return $this->render($viewName, ['model' => $model, 'categories' => PromoCategory::find()->orFilterWhere(['domain_id' => Yii::getAlias('@defaultDomainId')])->orFilterWhere(['domain_id' => \Yii::$app->user->identity->domain_id])->active()->all(), 'domains' => array_combine(explode(',', Yii::getAlias('@frontendUrls')), explode(',', Yii::getAlias('@frontendUrls')))]);
     }
 }
Example #6
0
 public function afterDelete()
 {
     $model = Promo::find()->andWhere(['locale_group_id' => $this->locale_group_id, 'domain_id' => Yii::$app->user->identity->domain_id])->one();
     if ($model) {
         $model->delete();
     }
     return parent::afterDelete();
 }
Example #7
0
 public static function getMetaTags()
 {
     $tags = [];
     $locale = null;
     $arr = self::parseUrl(Yii::$app->request->pathInfo);
     if (!empty($arr[0]) and !empty($arr[1]) and !empty($arr[2]) and !empty($arr[3])) {
         $shortLocale = $arr[0];
         $controller = $arr[1];
         $action = $arr[2];
         $slug = $arr[3];
         foreach (Yii::$app->params['availableLocales'] as $k => $v) {
             if ($shortLocale == explode('-', $k)[0]) {
                 $locale = $k;
             }
         }
         switch ($controller) {
             case 'page':
                 $model = self::find()->published()->andWhere(['slug' => $slug, 'locale' => $locale])->one();
                 break;
             case 'article':
                 $model = Article::find()->published()->andWhere(['slug' => $slug, 'locale' => $locale])->one();
                 break;
             case 'promo':
                 $model = Promo::find()->published()->andWhere(['slug' => $slug, 'locale' => $locale])->one();
                 break;
             case 'project':
                 $model = Project::find()->published()->andWhere(['slug' => $slug, 'locale' => $locale])->one();
                 break;
         }
         //hardcore :) json to array
         if (!empty($model) and !empty($model->head)) {
             $arr = json_decode($model->head, true);
             foreach ($arr as $key => $value) {
                 foreach ($value as $key2 => $value2) {
                     //custom meta tag
                     if (4 == count($value2)) {
                         $value2 = array_values($value2);
                         $value2 = [$value2[0] => $value2[1], $value2[2] => $value2[3]];
                     }
                     $tags[] = $value2;
                 }
             }
         }
         if (empty($model)) {
             throw new NotFoundHttpException('The requested page does not exist.');
         }
         if (!empty($tags[0]) and !empty($tags[0]['name']) and 'title' == !empty($tags[0]['name']) and !empty($tags[0]['content'])) {
             Yii::$app->view->title = $tags[0]['content'];
         } else {
             Yii::$app->view->title = $model->title;
         }
     }
     return $tags;
 }