Commit d35e15a6be93f47bfae46e18eb7b0abeaea69749

Authored by alex
1 parent 4cf6fdea

partners block test

backend/controllers/PartnerController.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace backend\controllers;
  4 +
  5 + use function array_merge;
  6 + use artbox\core\admin\actions\Create;
  7 + use artbox\core\admin\actions\Delete;
  8 + use backend\actions\Index;
  9 + use artbox\core\admin\actions\Update;
  10 + use artbox\core\admin\actions\View;
  11 + use artbox\core\admin\interfaces\ControllerInterface;
  12 + use artbox\core\admin\widgets\Form;
  13 + use common\models\partners\Partner;
  14 + use yii\filters\AccessControl;
  15 + use yii\filters\VerbFilter;
  16 + use yii\web\Controller;
  17 + use yii\web\NotFoundHttpException;
  18 +
  19 + class PartnerController extends Controller implements ControllerInterface
  20 + {
  21 + public function behaviors()
  22 + {
  23 + return [
  24 + 'verbs' => [
  25 + 'class' => VerbFilter::className(),
  26 + 'actions' => [
  27 + 'delete' => [ 'POST' ],
  28 + ],
  29 + ],
  30 + 'access' => [
  31 + 'class' => AccessControl::className(),
  32 + 'rules' => [
  33 + [
  34 + 'allow' => true,
  35 + 'roles' => [ '@' ],
  36 + ],
  37 + ],
  38 + ],
  39 + ];
  40 + }
  41 + public function actions()
  42 + {
  43 + return [
  44 + 'index' => [
  45 + 'class' => Index::className(),
  46 + 'columns' => [
  47 + 'title' => [
  48 + 'type' => Index::ACTION_COL,
  49 + ],
  50 + 'sort' => [
  51 + 'type' => Index::POSITION_COL,
  52 + ],
  53 + 'status' => [
  54 + 'type' => Index::STATUS_COL,
  55 + ],
  56 + ],
  57 + 'model' => Partner::className(),
  58 + 'hasLanguage' => true,
  59 + 'enableMassDelete' => true,
  60 + 'modelPrimaryKey' => 'id',
  61 + ],
  62 + 'create' => array_merge([ 'class' => Create::className() ], self::fieldsConfig()),
  63 + 'update' => array_merge([ 'class' => Update::className() ], self::fieldsConfig()),
  64 + 'view' => [
  65 + 'class' => View::className(),
  66 + 'model' => Partner::className(),
  67 + 'hasAlias' => true,
  68 + 'hasGallery' => true,
  69 + 'languageFields' => [
  70 + [
  71 + 'name' => 'title',
  72 + 'type' => Form::STRING,
  73 + ],
  74 + [
  75 + 'name' => 'description',
  76 + 'type' => Form::WYSIWYG,
  77 + ],
  78 +
  79 + ],
  80 + 'fields' => [
  81 + [
  82 + 'name' => 'image_id',
  83 + 'type' => Form::IMAGE,
  84 + ],
  85 + ],
  86 + ],
  87 + 'delete' => [
  88 + 'class' => Delete::className(),
  89 + ],
  90 + ];
  91 + }
  92 +
  93 + public function findModel($id)
  94 + {
  95 + $model = Partner::find()
  96 + ->with('languages')
  97 + ->where([ 'id' => $id ])
  98 + ->one();
  99 + if ($model !== null) {
  100 + return $model;
  101 + } else {
  102 + throw new NotFoundHttpException('The requested page does not exist.');
  103 + }
  104 + }
  105 +
  106 + public function newModel()
  107 + {
  108 + return new Partner();
  109 + }
  110 +
  111 + public function deleteModel($id)
  112 + {
  113 + $page = Partner::find()
  114 + ->with('languages')
  115 + ->where(
  116 + [
  117 + 'id' => $id,
  118 + ]
  119 + )
  120 + ->one();
  121 +
  122 + return $page->delete();
  123 + }
  124 +
  125 + protected static function fieldsConfig()
  126 + {
  127 + return [
  128 + 'model' => Partner::className(),
  129 + 'hasAlias' => false,
  130 + 'hasGallery' => false,
  131 + 'languageFields' => [
  132 + [
  133 + 'name' => 'title',
  134 + 'type' => Form::STRING,
  135 + ],
  136 + [
  137 + 'name' => 'description',
  138 + 'type' => Form::TEXTAREA,
  139 + ],
  140 +
  141 +
  142 + ],
  143 + 'fields' => [
  144 +
  145 + [
  146 + 'name' => 'image_id',
  147 + 'type' => Form::IMAGE,
  148 + ],
  149 + [
  150 + 'name' => 'status',
  151 + 'type' => Form::BOOL,
  152 + ],
  153 + [
  154 + 'name' => 'sort',
  155 + 'type' => Form::NUMBER,
  156 + ],
  157 + ],
  158 + ];
  159 + }
  160 +
  161 + public function actionSettings()
  162 + {
  163 + return $this->render('settings');
  164 + }
  165 + }
0 166 \ No newline at end of file
... ...
common/models/partners/Partner.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace common\models\partners;
  4 +
  5 + use artbox\core\models\Image;
  6 + use artbox\core\models\Language;
  7 + use yii\db\ActiveQuery;
  8 + use yii\db\ActiveRecord;
  9 + use yii2tech\ar\position\PositionBehavior;
  10 + use yii2tech\ar\variation\VariationBehavior;
  11 +
  12 + /**
  13 + * Class Page
  14 + *
  15 + * @package common\models\speaker
  16 + * @property integer $id
  17 + * @property integer $sort
  18 + * @property boolean $status
  19 + * @property Image $image
  20 +
  21 + * @method ActiveQuery hasDefaultVariationRelation();
  22 + */
  23 + class Partner extends ActiveRecord
  24 + {
  25 + public function rules()
  26 + {
  27 + return [
  28 + [
  29 + [
  30 + 'sort',
  31 + 'image_id',
  32 + ],
  33 + 'integer',
  34 + ],
  35 +
  36 + [
  37 + [
  38 + 'status',
  39 + ],
  40 + 'boolean',
  41 + ],
  42 + ];
  43 + }
  44 +
  45 + public function behaviors()
  46 + {
  47 + return [
  48 + 'translations' => [
  49 + 'class' => VariationBehavior::className(),
  50 + 'variationsRelation' => 'languages',
  51 + 'defaultVariationRelation' => 'language',
  52 + 'variationOptionReferenceAttribute' => 'language_id',
  53 + 'optionModelClass' => Language::className(),
  54 + 'defaultVariationOptionReference' => function () {
  55 + return Language::getCurrent()->id;
  56 + },
  57 + 'optionQueryFilter' => function (ActiveQuery $query) {
  58 + $query->where(
  59 + [
  60 + 'status' => true,
  61 + ]
  62 + );
  63 + },
  64 + ],
  65 + 'positionBehavior' => [
  66 + 'class' => PositionBehavior::className(),
  67 + 'positionAttribute' => 'sort',
  68 + ],
  69 + ];
  70 + }
  71 +
  72 + public static function tableName()
  73 + {
  74 + return 'partner';
  75 + }
  76 +
  77 + /**
  78 + * @return \yii\db\ActiveQuery
  79 + */
  80 + public function getLanguages()
  81 + {
  82 + return $this->hasMany(PartnerLang::className(), [ 'partner_id' => 'id' ]);
  83 + }
  84 +
  85 + /**
  86 + * @return \yii\db\ActiveQuery
  87 + */
  88 + public function getLanguage()
  89 + {
  90 + return $this->hasOne(PartnerLang::className(), [ 'partner_id' => 'id' ])
  91 + ->where(
  92 + [
  93 + 'language_id' => Language::getCurrent()->id,
  94 + ]
  95 + );
  96 + }
  97 +
  98 + /**
  99 + * @return \yii\db\ActiveQuery
  100 + */
  101 + public function getImage()
  102 + {
  103 + return $this->hasOne(Image::className(), [ 'id' => 'image_id' ]);
  104 + }
  105 +
  106 + /**
  107 + * @return array
  108 + */
  109 + public function attributeLabels()
  110 + {
  111 + return [
  112 + 'sort' => \Yii::t('core', 'Sort'),
  113 + 'status' => \Yii::t('core', 'Status'),
  114 + 'image_id' => \Yii::t('core', 'Image'),
  115 +
  116 + ];
  117 + }
  118 + }
0 119 \ No newline at end of file
... ...
common/models/partners/PartnerLang.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace common\models\partners;
  4 +
  5 + use yii\db\ActiveRecord;
  6 +
  7 + /**
  8 + * Class SpeakerLang
  9 + *
  10 + * @property string $description
  11 + * @property string $title
  12 + * @property integer $partner_id
  13 + * @property integer $language_id
  14 + * @package common\models\page
  15 + */
  16 + class PartnerLang extends ActiveRecord
  17 + {
  18 + public static function primaryKey()
  19 + {
  20 + return [
  21 + 'partner_id',
  22 + 'language_id',
  23 + ];
  24 + }
  25 +
  26 + public function rules()
  27 + {
  28 + return [
  29 + [
  30 + [
  31 + 'title',
  32 + 'description',
  33 + ],
  34 + 'string',
  35 + ],
  36 + [
  37 + [
  38 + 'partner_id',
  39 + 'language_id',
  40 + ],
  41 + 'integer',
  42 + ],
  43 + ];
  44 + }
  45 +
  46 + public static function tableName()
  47 + {
  48 + return 'partner_lang';
  49 + }
  50 +
  51 + public function attributeLabels()
  52 + {
  53 + return [
  54 + 'title' => \Yii::t('app', 'Partner title'),
  55 + 'description' => \Yii::t('app', 'Partner description'),
  56 +
  57 + ];
  58 + }
  59 + }
0 60 \ No newline at end of file
... ...
console/migrations/m181031_104142_parthner_create_table_and_lang_tab.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\db\Migration;
  4 +
  5 +/**
  6 + * Class m181031_104142_parthner_create_table_and_lang_tab
  7 + */
  8 +class m181031_104142_parthner_create_table_and_lang_tab extends Migration
  9 +{
  10 + /**
  11 + * {@inheritdoc}
  12 + */
  13 + public function safeUp()
  14 + {
  15 + $this->createTable(
  16 + 'partner',
  17 + [
  18 + 'id' => $this->primaryKey(),
  19 + 'sort' => $this->integer(),
  20 + 'image_id' => $this->integer(),
  21 + 'status' => $this->boolean(),
  22 + ]
  23 + );
  24 +
  25 + $this->createTable(
  26 + 'partner_lang',
  27 + [
  28 + 'partner_id' => $this->integer(),
  29 + 'language_id' => $this->integer(),
  30 + 'title' => $this->string(),
  31 + 'description' => $this->text(),
  32 +
  33 + ]
  34 + );
  35 +
  36 + $this->createIndex(
  37 + 'prtnr_idx',
  38 + 'partner_lang',
  39 + [
  40 + 'partner_id',
  41 + 'language_id',
  42 + ],
  43 + true
  44 + );
  45 +
  46 + $this->addForeignKey(
  47 + 'prtnr_fk',
  48 + 'partner_lang',
  49 + 'partner_id',
  50 + 'partner',
  51 + 'id',
  52 + 'CASCADE',
  53 + 'CASCADE');
  54 +
  55 + $this->addForeignKey(
  56 + 'lng_fk',
  57 + 'partner_lang',
  58 + 'language_id',
  59 + 'language',
  60 + 'id',
  61 + 'CASCADE',
  62 + 'CASCADE');
  63 +
  64 + }
  65 +
  66 + /**
  67 + * {@inheritdoc}
  68 + */
  69 + public function safeDown()
  70 + {
  71 + $this->dropForeignKey('lng_fk', 'speaker_lang');
  72 +
  73 + $this->dropForeignKey('prtnr_fk', 'partner_lang');
  74 +
  75 + $this->dropIndex(
  76 + 'prtnr_idx',
  77 + 'partner_lang'
  78 + );
  79 +
  80 + $this->dropTable('partner_lang');
  81 +
  82 + $this->dropTable('partner');
  83 + }
  84 +
  85 +
  86 +}
... ...
frontend/controllers/SiteController.php
... ... @@ -5,6 +5,7 @@
5 5 use artbox\core\models\Feedback;
6 6 use common\models\Customer;
7 7 use common\models\Logo;
  8 + use common\models\partners\Partner;
8 9 use common\models\Settings;
9 10 use common\models\speaker\Speaker;
10 11 use Yii;
... ... @@ -74,11 +75,22 @@
74 75 ->all();
75 76 $partners = Logo::find()
76 77 ->all();
  78 + $generalPartners = Partner::find()
  79 + ->with(
  80 + [
  81 + 'language',
  82 + 'image',
  83 + ]
  84 + )
  85 + ->where([ 'status' => true ])
  86 + ->orderBy('sort')
  87 + ->all();
77 88 return $this->render(
78 89 'index',
79 90 [
80 91 'speakers' => $speakers,
81 92 'partners' => $partners,
  93 + 'generalPartners' => $generalPartners,
82 94 ]
83 95 );
84 96 }
... ... @@ -121,12 +133,15 @@
121 133 ->all();
122 134 $partners = Logo::find()
123 135 ->all();
  136 +
  137 +
124 138 return $this->render(
125 139 'speakers',
126 140 [
127 141 'speakers' => $speakers,
128 142 'partners' => $partners,
129 143 'currentSpeaker' => $currentSpeaker,
  144 +
130 145 ]
131 146 );
132 147 }
... ...
frontend/views/site/index.php
... ... @@ -137,6 +137,8 @@
137 137 </a>
138 138 </div>
139 139 </div>
  140 + <div class="partners-wr col-xs-13 col-sm-12">
  141 + </div>
140 142 <div class="partners-wr col-xs-3 col-sm-2">
141 143 <div>
142 144 <a href="http://www.unece.org/index.php?id=49144" target="_blank">
... ... @@ -234,6 +236,49 @@
234 236 </div>
235 237 </div>
236 238 </div>
  239 +
  240 +
  241 +
  242 +
  243 +
  244 +
  245 + <div class="col-xs-12 col-sm-12 col-md-12" data-ddd="222">
  246 + <div class="row">
  247 + <div class="col-xs-12">
  248 + <div class="style partners-title"><span>
  249 + <?=\Yii::t('app','General Partners')?>
  250 + </span></div>
  251 + </div>
  252 + </div>
  253 + <div class="row">
  254 + <div class="col-xs-12 partners-col">
  255 + <div class="row slider-partners">
  256 + <?php foreach ($generalPartners as $partner2) { ?>
  257 + <div class="partners-wr col-xs-12 col-sm-2">
  258 + <div>
  259 + <a href="#" target="_blank">
  260 + <img src="<?= ImageHelper::set($partner2->image->getPath())
  261 + ->resize(263, 210)
  262 + ->render() ?>" alt="">
  263 + </a>
  264 + </div>
  265 + </div>
  266 + <?php } ?>
  267 + </div>
  268 + <div class="border-mobile hidden visible-xs"></div>
  269 + </div>
  270 + </div>
  271 + </div>
  272 +
  273 +
  274 +
  275 +
  276 +
  277 +
  278 +
  279 +
  280 +
  281 +
237 282 <div class="col-xs-12 col-sm-12 col-md-12">
238 283 <div class="row">
239 284 <div class="col-xs-12">
... ...