Beispiel #1
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     if (!$this->isShow()) {
         return false;
     }
     $place = Place::find()->published()->andWhere(["code" => $this->code])->one();
     if ($place) {
         $models = $place->getBanners()->published()->all();
         if (empty($models)) {
             return false;
         }
         $i = rand(0, count($models) - 1);
         $this->model = $models[$i];
     }
 }
Beispiel #2
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     if (!$this->isShow()) {
         return false;
     }
     $place = Place::find()->published()->andWhere(["code" => $this->code])->one();
     if ($place) {
         $this->models = $place->getBanners()->published()->orderBy(["sort" => SORT_ASC])->all();
         foreach ($this->models as $k => $banner) {
             if (!$banner->isSuitable()) {
                 unset($this->models[$k]);
             }
         }
     }
 }
Beispiel #3
0
<?php

use app\modules\banners\models;
return ['controllerMap' => ['migrate' => ['migrationLookup' => ['@webapp/modules/banners/migrations']]], 'modules' => ['banners' => ['class' => 'app\\modules\\banners\\Banners', 'controllerNamespace' => 'app\\modules\\banners\\controllers', 'components' => ['rendererFactory' => \app\modules\banners\components\RendererFactory::className()], 'modules' => ['admin' => ['class' => 'app\\modules\\banners\\modules\\admin\\Admin', 'controllerNamespace' => 'app\\modules\\banners\\modules\\admin\\controllers', 'menuItems' => function () {
    return [['label' => Yii::t('banners/app', 'Banners module'), 'icon' => 'glyphicon glyphicon-picture', 'items' => [['label' => Yii::t('banners/app', 'Banners'), 'url' => ['/admin/banners/banner'], "permission" => ["listModels", ["model" => Yii::createObject(models\Banner::className())]]], ['label' => Yii::t('banners/app', 'Places'), 'url' => ['/admin/banners/place'], "permission" => ["listModels", ["model" => Yii::createObject(models\Place::className())]]]]]];
}]]]], 'components' => ['i18n' => ['translations' => ['banners/*' => ['class' => 'yii\\i18n\\PhpMessageSource', 'basePath' => '@webapp/modules/banners/messages', 'fileMap' => ['banners/app' => 'app.php']]]], 'urlManager' => ['rules' => []]]];
 /**
  * Действия
  * @return array
  */
 public function actions()
 {
     $class = Place::className();
     return ['index' => ['class' => crud\Admin::className(), 'modelClass' => $class], 'create' => ['class' => crud\Create::className(), 'modelClass' => $class], 'update' => ['class' => crud\Update::className(), 'modelClass' => $class], 'view' => ['class' => crud\View::className(), 'modelClass' => $class], 'delete' => ['class' => crud\Delete::className(), 'modelClass' => $class], 'groupdelete' => ['class' => crud\GroupDelete::className(), 'modelClass' => $class], 'editable' => ['class' => crud\XEditable::className(), 'modelClass' => $class]];
 }
Beispiel #5
0
 /**
  * Связь с баннерами
  * @return \yii\db\ActiveQuery
  */
 public function getPlace()
 {
     return $this->hasOne(Place::className(), ["id" => "place_id"]);
 }
Beispiel #6
0
 /**
  * Возвращает массив для привязкт к баннерным местам
  * @return array
  */
 public function getPlaces()
 {
     $models = Place::find()->published()->orderBy(["title" => SORT_ASC])->all();
     return ArrayHelper::map($models, "id", "title");
 }