Ejemplo n.º 1
0
 /**
  * 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']);
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPromos()
 {
     return $this->hasMany(Promo::className(), ['category_id' => 'id']);
 }
Ejemplo n.º 6
0
 public function afterDelete()
 {
     Promo::deleteAll(['locale_group_id' => $this->locale_group_id]);
     return parent::afterDelete();
 }
Ejemplo n.º 7
0
 /**
  * Finds the Promo model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Promo the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Promo::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Ejemplo n.º 8
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPromo()
 {
     return $this->hasOne(Promo::className(), ['id' => 'promo_id']);
 }
Ejemplo n.º 9
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();
 }
Ejemplo n.º 10
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;
 }