diff --git a/backend/controllers/SpeakerController.php b/backend/controllers/SpeakerController.php new file mode 100755 index 0000000..c4009ef --- /dev/null +++ b/backend/controllers/SpeakerController.php @@ -0,0 +1,166 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => [ 'POST' ], + ], + ], + 'access' => [ + 'class' => AccessControl::className(), + 'rules' => [ + [ + 'allow' => true, + 'roles' => [ '@' ], + ], + ], + ], + ]; + } + public function actions() + { + return [ + 'index' => [ + 'class' => Index::className(), + 'columns' => [ + 'name' => [ + 'type' => Index::ACTION_COL, + ], + 'sort' => [ + 'type' => Index::POSITION_COL, + ], + 'status' => [ + 'type' => Index::STATUS_COL, + ], + ], + 'model' => Speaker::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' => Speaker::className(), + 'hasAlias' => true, + 'hasGallery' => true, + 'languageFields' => [ + [ + 'name' => 'title', + 'type' => Form::STRING, + ], + [ + 'name' => 'body', + 'type' => Form::WYSIWYG, + ], + ], + 'fields' => [ + [ + 'name' => 'image_id', + 'type' => Form::IMAGE, + ], + ], + ], + 'delete' => [ + 'class' => Delete::className(), + ], + ]; + } + + public function findModel($id) + { + $model = Speaker::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 Speaker(); + } + + public function deleteModel($id) + { + $page = Speaker::find() + ->with('languages') + ->where( + [ + 'id' => $id, + ] + ) + ->one(); + + return $page->delete(); + } + + protected static function fieldsConfig() + { + return [ + 'model' => Speaker::className(), + 'hasAlias' => false, + 'hasGallery' => false, + 'languageFields' => [ + [ + 'name' => 'name', + 'type' => Form::STRING, + ], + [ + 'name' => 'position', + 'type' => Form::TEXTAREA, + ], + [ + 'name' => 'organization', + '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/speaker/Speaker.php b/common/models/speaker/Speaker.php new file mode 100755 index 0000000..e481852 --- /dev/null +++ b/common/models/speaker/Speaker.php @@ -0,0 +1,115 @@ + [ + '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 'speaker'; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguages() + { + return $this->hasMany(SpeakerLang::className(), [ 'speaker_id' => 'id' ]); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasMany(SpeakerLang::className(), [ 'speaker_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/speaker/SpeakerLang.php b/common/models/speaker/SpeakerLang.php new file mode 100755 index 0000000..6a74de3 --- /dev/null +++ b/common/models/speaker/SpeakerLang.php @@ -0,0 +1,61 @@ + \Yii::t('app', 'Speaker Name'), + 'organization' => \Yii::t('app', 'Organization'), + 'position' => \Yii::t('app', 'Position'), + ]; + } + } \ No newline at end of file diff --git a/console/migrations/m180830_085211_create_speakers_tables.php b/console/migrations/m180830_085211_create_speakers_tables.php new file mode 100644 index 0000000..7501ca6 --- /dev/null +++ b/console/migrations/m180830_085211_create_speakers_tables.php @@ -0,0 +1,69 @@ +createTable( + 'speaker', + [ + 'id' => $this->primaryKey(), + 'sort' => $this->integer(), + 'image_id' => $this->integer(), + 'status' => $this->boolean(), + ] + ); + + $this->createTable( + 'speaker_lang', + [ + 'speaker_id' => $this->integer(), + 'language_id' => $this->integer(), + 'name' => $this->string(), + 'organization' => $this->text(), + 'position' => $this->text(), + ] + ); + + $this->createIndex( + 'spkr_idx', + 'speaker_lang', + [ + 'speaker_id', + 'language_id', + ], + true + ); + + $this->addForeignKey('spkr_fk', 'speaker_lang', 'speaker_id', 'speaker', 'id', 'CASCADE', 'CASCADE'); + + $this->addForeignKey('lng_fk', 'speaker_lang', 'language_id', 'language', 'id', 'CASCADE', 'CASCADE'); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropForeignKey('lng_fk', 'speaker_lang'); + + $this->dropForeignKey('spkr_fk', 'speaker_lang'); + + $this->dropIndex( + 'spkr_idx', + 'speaker_lang' + ); + + $this->dropTable('speaker_lang'); + + $this->dropTable('speaker'); + } + } -- libgit2 0.21.4