diff --git a/backend/controllers/PartnerController.php b/backend/controllers/PartnerController.php new file mode 100755 index 0000000..06248b2 --- /dev/null +++ b/backend/controllers/PartnerController.php @@ -0,0 +1,165 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => [ 'POST' ], + ], + ], + 'access' => [ + 'class' => AccessControl::className(), + 'rules' => [ + [ + 'allow' => true, + 'roles' => [ '@' ], + ], + ], + ], + ]; + } + public function actions() + { + return [ + 'index' => [ + 'class' => Index::className(), + 'columns' => [ + 'title' => [ + 'type' => Index::ACTION_COL, + ], + 'sort' => [ + 'type' => Index::POSITION_COL, + ], + 'status' => [ + 'type' => Index::STATUS_COL, + ], + ], + 'model' => Partner::className(), + 'hasLanguage' => true, + 'enableMassDelete' => true, + 'modelPrimaryKey' => 'id', + ], + 'create' => array_merge([ 'class' => Create::className() ], self::fieldsConfig()), + 'update' => array_merge([ 'class' => Update::className() ], self::fieldsConfig()), + 'view' => [ + 'class' => View::className(), + 'model' => Partner::className(), + 'hasAlias' => true, + 'hasGallery' => true, + 'languageFields' => [ + [ + 'name' => 'title', + 'type' => Form::STRING, + ], + [ + 'name' => 'description', + 'type' => Form::WYSIWYG, + ], + + ], + 'fields' => [ + [ + 'name' => 'image_id', + 'type' => Form::IMAGE, + ], + ], + ], + 'delete' => [ + 'class' => Delete::className(), + ], + ]; + } + + public function findModel($id) + { + $model = Partner::find() + ->with('languages') + ->where([ 'id' => $id ]) + ->one(); + if ($model !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } + + public function newModel() + { + return new Partner(); + } + + public function deleteModel($id) + { + $page = Partner::find() + ->with('languages') + ->where( + [ + 'id' => $id, + ] + ) + ->one(); + + return $page->delete(); + } + + protected static function fieldsConfig() + { + return [ + 'model' => Partner::className(), + 'hasAlias' => false, + 'hasGallery' => false, + 'languageFields' => [ + [ + 'name' => 'title', + 'type' => Form::STRING, + ], + [ + 'name' => 'description', + 'type' => Form::TEXTAREA, + ], + + + ], + 'fields' => [ + + [ + 'name' => 'image_id', + 'type' => Form::IMAGE, + ], + [ + 'name' => 'status', + 'type' => Form::BOOL, + ], + [ + 'name' => 'sort', + 'type' => Form::NUMBER, + ], + ], + ]; + } + + public function actionSettings() + { + return $this->render('settings'); + } + } \ No newline at end of file diff --git a/common/models/partners/Partner.php b/common/models/partners/Partner.php new file mode 100755 index 0000000..67bf38d --- /dev/null +++ b/common/models/partners/Partner.php @@ -0,0 +1,118 @@ + [ + 'class' => VariationBehavior::className(), + 'variationsRelation' => 'languages', + 'defaultVariationRelation' => 'language', + 'variationOptionReferenceAttribute' => 'language_id', + 'optionModelClass' => Language::className(), + 'defaultVariationOptionReference' => function () { + return Language::getCurrent()->id; + }, + 'optionQueryFilter' => function (ActiveQuery $query) { + $query->where( + [ + 'status' => true, + ] + ); + }, + ], + 'positionBehavior' => [ + 'class' => PositionBehavior::className(), + 'positionAttribute' => 'sort', + ], + ]; + } + + public static function tableName() + { + return 'partner'; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguages() + { + return $this->hasMany(PartnerLang::className(), [ 'partner_id' => 'id' ]); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasOne(PartnerLang::className(), [ 'partner_id' => 'id' ]) + ->where( + [ + 'language_id' => Language::getCurrent()->id, + ] + ); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getImage() + { + return $this->hasOne(Image::className(), [ 'id' => 'image_id' ]); + } + + /** + * @return array + */ + public function attributeLabels() + { + return [ + 'sort' => \Yii::t('core', 'Sort'), + 'status' => \Yii::t('core', 'Status'), + 'image_id' => \Yii::t('core', 'Image'), + + ]; + } + } \ No newline at end of file diff --git a/common/models/partners/PartnerLang.php b/common/models/partners/PartnerLang.php new file mode 100755 index 0000000..52a2a2b --- /dev/null +++ b/common/models/partners/PartnerLang.php @@ -0,0 +1,59 @@ + \Yii::t('app', 'Partner title'), + 'description' => \Yii::t('app', 'Partner description'), + + ]; + } + } \ No newline at end of file diff --git a/console/migrations/m181031_104142_parthner_create_table_and_lang_tab.php b/console/migrations/m181031_104142_parthner_create_table_and_lang_tab.php new file mode 100644 index 0000000..e4b2825 --- /dev/null +++ b/console/migrations/m181031_104142_parthner_create_table_and_lang_tab.php @@ -0,0 +1,86 @@ +createTable( + 'partner', + [ + 'id' => $this->primaryKey(), + 'sort' => $this->integer(), + 'image_id' => $this->integer(), + 'status' => $this->boolean(), + ] + ); + + $this->createTable( + 'partner_lang', + [ + 'partner_id' => $this->integer(), + 'language_id' => $this->integer(), + 'title' => $this->string(), + 'description' => $this->text(), + + ] + ); + + $this->createIndex( + 'prtnr_idx', + 'partner_lang', + [ + 'partner_id', + 'language_id', + ], + true + ); + + $this->addForeignKey( + 'prtnr_fk', + 'partner_lang', + 'partner_id', + 'partner', + 'id', + 'CASCADE', + 'CASCADE'); + + $this->addForeignKey( + 'lng_fk', + 'partner_lang', + 'language_id', + 'language', + 'id', + 'CASCADE', + 'CASCADE'); + + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropForeignKey('lng_fk', 'speaker_lang'); + + $this->dropForeignKey('prtnr_fk', 'partner_lang'); + + $this->dropIndex( + 'prtnr_idx', + 'partner_lang' + ); + + $this->dropTable('partner_lang'); + + $this->dropTable('partner'); + } + + +} diff --git a/frontend/controllers/SiteController.php b/frontend/controllers/SiteController.php index 4af531d..491fa83 100755 --- a/frontend/controllers/SiteController.php +++ b/frontend/controllers/SiteController.php @@ -5,6 +5,7 @@ use artbox\core\models\Feedback; use common\models\Customer; use common\models\Logo; + use common\models\partners\Partner; use common\models\Settings; use common\models\speaker\Speaker; use Yii; @@ -74,11 +75,22 @@ ->all(); $partners = Logo::find() ->all(); + $generalPartners = Partner::find() + ->with( + [ + 'language', + 'image', + ] + ) + ->where([ 'status' => true ]) + ->orderBy('sort') + ->all(); return $this->render( 'index', [ 'speakers' => $speakers, 'partners' => $partners, + 'generalPartners' => $generalPartners, ] ); } @@ -121,12 +133,15 @@ ->all(); $partners = Logo::find() ->all(); + + return $this->render( 'speakers', [ 'speakers' => $speakers, 'partners' => $partners, 'currentSpeaker' => $currentSpeaker, + ] ); } diff --git a/frontend/views/site/index.php b/frontend/views/site/index.php index f612ebe..f9620c0 100755 --- a/frontend/views/site/index.php +++ b/frontend/views/site/index.php @@ -137,6 +137,8 @@ +
+
@@ -234,6 +236,49 @@
+ + + + + + +
+
+
+
+ +
+
+
+
+ +
+
+ + + + + + + + + +
-- libgit2 0.21.4