/**
  * @param $region
  * @param bool $big
  * @return array Data
  */
 public static function getBanner($region, $big = false)
 {
     $regions = Banner::dropdownRegions();
     $regions = array_keys($regions);
     if (!in_array($region, $regions)) {
         return false;
     }
     $allBanners = self::getBannerModels();
     foreach ($allBanners as $banner) {
         if (!$banner) {
             continue;
         }
         if (in_array($banner->id, self::$postedBannerIds)) {
             continue;
         }
         if ($big && !$banner->size) {
             continue;
         }
         if ($banner->region != $region) {
             continue;
         }
         self::$postedBannerIds[] = $banner->id;
         $block = ['view' => '@frontend/views/blocks/banner_block', 'data' => compact('banner')];
         return $block;
     }
     return false;
 }
 public function actionDelete($id)
 {
     $model = Banner::findOne($id);
     $model->delete();
     // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
     if (!isset($_GET['ajax'])) {
         $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : ['index']);
     }
 }
Exemple #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Banner::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Banner::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'description', $this->description], ['like', 'title', $this->title]);
     return $dataProvider;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Banner::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'size' => $this->size, 'region' => $this->region, 'weight' => $this->weight, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'content', $this->content]);
     return $dataProvider;
 }
 /**
  * Displays homepage.
  *
  * @return mixed
  */
 public function actionIndex()
 {
     //Banner
     $banner_mod = \common\models\Banner::find()->where(['status' => \common\enum\BannerStatus::ACTIVE])->orderBy(['sequence' => SORT_ASC])->all();
     if ($banner_mod) {
         foreach ($banner_mod as $rec) {
             $banner[] = ['title' => $rec->title, 'image' => $rec->image ? \Yii::$app->params['pathBannerImage'] . $rec->image : '', 'description' => $rec->description];
         }
     } else {
         $banner[] = ['title' => 'Fafediesel Group', 'image' => \Yii::$app->params['pathBannerImage'] . 'rectangle1.png', 'description' => 'Um parceiro ao seu serviço.'];
     }
     //News - Widget
     $model = \common\models\News::find()->where(['status' => \common\enum\NewsStatus::ACTIVE])->orderBy(['date' => SORT_DESC])->all();
     if ($model) {
         foreach ($model as $rec) {
             $news[] = ['title' => $rec->title, 'logo' => $rec->logo ? \common\models\News::$default_data_location . '/icon/' . $rec->logo : '', 'intro' => $rec->intro, 'link' => '/news/view/#' . $rec->id, 'date' => $rec->date];
         }
     } else {
         $news[] = ['title' => 'sem notícias no momento', 'logo' => '', 'intro' => '', 'link' => '', 'date' => ''];
     }
     $this->layout = 'main_plain';
     return $this->render('index', ['banner' => $banner, 'news' => $news]);
 }
 public function actionChangeActivety()
 {
     $arrResult = [];
     $id = Yii::$app->request->post('id');
     $state = Yii::$app->request->post('state');
     //vd( $id .': ' .$state );
     if ($state == 'true') {
         $status = 0;
     } else {
         $status = 1;
     }
     if ($id) {
         $model = Banner::find()->where(['id' => $id])->one();
         $model->status = $status;
         $model->updateAttributes(['status']);
     }
     Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     $arrResult['state'] = $status;
     $arrResult['id'] = $id;
     return $arrResult;
 }
 public function actionBlogDetail($id)
 {
     $data = $this->getCommonDate();
     $modelGoodsCategories = GoodsCategory::find()->all();
     $modelBanner = Banner::find()->where(['status' => 0])->all();
     $modelBrends = Brend::find()->all();
     $modelBlog = Blog::findOne($id);
     $modelBlogComents = BlogComments::getComentsByBlogId($id);
     return $this->render('blog-detail', ['modelBlog' => $modelBlog, 'data' => $data, 'modelGoodsCategories' => $modelGoodsCategories, 'modelBrends' => $modelBrends, 'modelBanner' => $modelBanner, 'modelBlogComents' => $modelBlogComents]);
 }
 /**
  * Finds the Banner model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Banner the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Banner::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }