diff --git a/README.md b/README.md index b495ab0..7d2bcd4 100644 --- a/README.md +++ b/README.md @@ -13,28 +13,34 @@ - BelongsTo MemberRank - HasMany ExamMemberRankAnswer +- BelongsToMany ExamMemberRank ## ExamTyperatingQuestion - BelongsTo Typerating - HasMany ExamTyperatingAnswer +- BelongsToMany ExamTyperating ## ExamMemberRankAnswer - BelongsTo ExamMemberRankQuestion +- BelongsToMany ExamMemberRank ## ExamTyperatingAnswer - BelongsTo ExamTyperatingQuestion +- BelongsToMany ExamTyperating ## ExamMemberRank - BelongsTo MemberRank - **TODO** BelongsTo Member (External DB) -- **TODO** HasMany ExamMemberRankQuestion +- BelongsToMany ExamMemberRankQuestion +- BelongsToMany ExamMemberRankAnswers ## ExamTyperating - BelongsTo Typerating - **TODO** BelongsTo Member (External DB) -- **TODO** HasMany ExamTyperatingQuestion +- BelongsToMany ExamTyperatingQuestion +- BelongsToMany ExamTyperatingAnswers diff --git a/controllers/ExamMemberRank.php b/controllers/ExamMemberRank.php index c55e534..9da94d1 100644 --- a/controllers/ExamMemberRank.php +++ b/controllers/ExamMemberRank.php @@ -12,9 +12,4 @@ class ExamMemberRank extends Controller { parent::__construct(); } - - public function listExtendQuery($query) - { - $query->where('member_rank_id', '<>', null); - } } diff --git a/controllers/ExamMemberRankAnswer.php b/controllers/ExamMemberRankAnswer.php index ab0dd74..af55294 100644 --- a/controllers/ExamMemberRankAnswer.php +++ b/controllers/ExamMemberRankAnswer.php @@ -13,10 +13,4 @@ class ExamMemberRankAnswer extends Controller { parent::__construct(); } - - public function listExtendQuery($query) - { - $query->leftJoin('exam_questions', 'exam_questions.id', 'exam_answers.exam_question_id'); - $query->where('exam_questions.member_rank_id', '<>', null); - } } diff --git a/controllers/ExamMemberRankQuestion.php b/controllers/ExamMemberRankQuestion.php index 87484d5..547f6c8 100644 --- a/controllers/ExamMemberRankQuestion.php +++ b/controllers/ExamMemberRankQuestion.php @@ -13,9 +13,4 @@ class ExamMemberRankQuestion extends Controller { parent::__construct(); } - - public function listExtendQuery($query) - { - $query->where('member_rank_id', '<>', null); - } } diff --git a/controllers/ExamTyperating.php b/controllers/ExamTyperating.php index ca29424..11f53b7 100644 --- a/controllers/ExamTyperating.php +++ b/controllers/ExamTyperating.php @@ -12,9 +12,4 @@ class ExamTyperating extends Controller { parent::__construct(); } - - public function listExtendQuery($query) - { - $query->where('typerating_id', '<>', null); - } } diff --git a/controllers/ExamTyperatingAnswer.php b/controllers/ExamTyperatingAnswer.php index a5c1a66..6846c35 100644 --- a/controllers/ExamTyperatingAnswer.php +++ b/controllers/ExamTyperatingAnswer.php @@ -13,10 +13,4 @@ class ExamTyperatingAnswer extends Controller { parent::__construct(); } - - public function listExtendQuery($query) - { - $query->leftJoin('exam_questions', 'exam_questions.id', 'exam_answers.exam_question_id'); - $query->where('exam_questions.typerating_id', '<>', null); - } } diff --git a/controllers/ExamTyperatingQuestion.php b/controllers/ExamTyperatingQuestion.php index f8473d4..0f837cf 100644 --- a/controllers/ExamTyperatingQuestion.php +++ b/controllers/ExamTyperatingQuestion.php @@ -13,9 +13,4 @@ class ExamTyperatingQuestion extends Controller { parent::__construct(); } - - public function listExtendQuery($query) - { - $query->where('typerating_id', '<>', null); - } } diff --git a/controllers/examtyperatinganswer/config_form.yaml b/controllers/examtyperatinganswer/config_form.yaml index 393b372..80f8606 100644 --- a/controllers/examtyperatinganswer/config_form.yaml +++ b/controllers/examtyperatinganswer/config_form.yaml @@ -1,6 +1,6 @@ name: Exam Typerating Answer form: $/germanairlinesva/schooling/models/examtyperatinganswer/fields.yaml -modelClass: GermanAirlinesVa\Schooling\Models\ExamMemberRankAnswer +modelClass: GermanAirlinesVa\Schooling\Models\ExamTyperatingAnswer defaultRedirect: germanairlinesva/schooling/examtyperatinganswer create: redirect: 'germanairlinesva/schooling/examtyperatinganswer/update/:id' diff --git a/controllers/examtyperatinganswer/config_list.yaml b/controllers/examtyperatinganswer/config_list.yaml index a853a76..4fa1664 100644 --- a/controllers/examtyperatinganswer/config_list.yaml +++ b/controllers/examtyperatinganswer/config_list.yaml @@ -1,5 +1,5 @@ list: $/germanairlinesva/schooling/models/examtyperatinganswer/columns.yaml -modelClass: GermanAirlinesVa\Schooling\Models\ExamMemberRankAnswer +modelClass: GermanAirlinesVa\Schooling\Models\ExamTyperatingAnswer title: Exam Typerating Answers noRecordsMessage: 'backend::lang.list.no_records' showSetup: true diff --git a/models/ExamMemberRank.php b/models/ExamMemberRank.php index dcaae07..98e623b 100644 --- a/models/ExamMemberRank.php +++ b/models/ExamMemberRank.php @@ -34,4 +34,33 @@ class ExamMemberRank extends Model public $belongsTo = [ 'member_rank' => 'GermanAirlinesVa\Schooling\Models\MemberRank', ]; + + public $belongsToMany = [ + 'exam_questions' => [ + 'GermanAirlinesVa\Schooling\Models\ExamMemberRankQuestion', + 'table' => 'exam_exam_answer_exam_question', + 'key' => 'exam_id', + 'otherKey' => 'exam_question_id', + ], + 'exam_answers' => [ + 'GermanAirlinesVa\Schooling\Models\ExamMemberRankAnswer', + 'table' => 'exam_exam_answer_exam_question', + 'key' => 'exam_id', + 'otherKey' => 'exam_answer_id', + ], + ]; + + /** + * The "booting" method of the model. + * + * @return void + */ + protected static function boot() + { + parent::boot(); + + static::addGlobalScope('exam_member_rank_member_rank_id', function ($builder) { + $builder->where('member_rank_id', '<>', null); + }); + } } diff --git a/models/ExamMemberRankAnswer.php b/models/ExamMemberRankAnswer.php index e95d698..1f2feb3 100644 --- a/models/ExamMemberRankAnswer.php +++ b/models/ExamMemberRankAnswer.php @@ -33,4 +33,29 @@ class ExamMemberRankAnswer extends Model public $belongsTo = [ 'exam_question' => ['GermanAirlinesVa\Schooling\Models\ExamMemberRankQuestion', 'key' => 'exam_question_id'], ]; + + public $belongsToMany = [ + 'exam_member_ranks' => [ + 'GermanAirlinesVa\Schooling\Models\ExamMemberRank', + 'table' => 'exam_exam_answer_exam_question', + 'key' => 'exam_answer_id', + 'otherKey' => 'exam_id', + ], + ]; + + /** + * The "booting" method of the model. + * + * @return void + */ + protected static function boot() + { + parent::boot(); + + static::addGlobalScope('exam_member_rank_answer_member_rank_id', function ($builder) { + $builder->whereHas('exam_question', function ($query) { + $query->where('member_rank_id', '<>', null); + }); + }); + } } diff --git a/models/ExamMemberRankQuestion.php b/models/ExamMemberRankQuestion.php index 53afb5a..637db74 100644 --- a/models/ExamMemberRankQuestion.php +++ b/models/ExamMemberRankQuestion.php @@ -32,10 +32,36 @@ class ExamMemberRankQuestion extends Model ]; public $hasMany = [ - 'exam_answers' => 'GermanAirlinesVa\Schooling\Models\ExamMemberRankAnswer', + 'exam_answers' => [ + 'GermanAirlinesVa\Schooling\Models\ExamMemberRankAnswer', + 'key' => 'exam_question_id', + ], ]; public $belongsTo = [ 'member_rank' => 'GermanAirlinesVa\Schooling\Models\MemberRank', ]; + + public $belongsToMany = [ + 'exam_member_ranks' => [ + 'GermanAirlinesVa\Schooling\Models\ExamMemberRank', + 'table' => 'exam_exam_answer_exam_question', + 'key' => 'exam_question_id', + 'otherKey' => 'exam_id', + ], + ]; + + /** + * The "booting" method of the model. + * + * @return void + */ + protected static function boot() + { + parent::boot(); + + static::addGlobalScope('exam_member_rank_question_member_rank_id', function ($builder) { + $builder->where('member_rank_id', '<>', null); + }); + } } diff --git a/models/ExamTyperating.php b/models/ExamTyperating.php index 6603279..89958ce 100644 --- a/models/ExamTyperating.php +++ b/models/ExamTyperating.php @@ -34,4 +34,33 @@ class ExamTyperating extends Model public $belongsTo = [ 'typerating' => 'GermanAirlinesVa\Schooling\Models\Typerating', ]; + + public $belongsToMany = [ + 'exam_questions' => [ + 'GermanAirlinesVa\Schooling\Models\ExamTyperatingQuestion', + 'table' => 'exam_exam_answer_exam_question', + 'key' => 'exam_id', + 'otherKey' => 'exam_question_id', + ], + 'exam_answers' => [ + 'GermanAirlinesVa\Schooling\Models\ExamTyperatingAnswer', + 'table' => 'exam_exam_answer_exam_question', + 'key' => 'exam_id', + 'otherKey' => 'exam_answer_id', + ], + ]; + + /** + * The "booting" method of the model. + * + * @return void + */ + protected static function boot() + { + parent::boot(); + + static::addGlobalScope('exam_typerating_typerating_id', function ($builder) { + $builder->where('typerating_id', '<>', null); + }); + } } diff --git a/models/ExamTyperatingAnswer.php b/models/ExamTyperatingAnswer.php index b08874e..e317627 100644 --- a/models/ExamTyperatingAnswer.php +++ b/models/ExamTyperatingAnswer.php @@ -1,6 +1,7 @@ ['GermanAirlinesVa\Schooling\Models\ExamTyperatingQuestion', 'key' => 'exam_question_id'], ]; + + public $belongsToMany = [ + 'exam_typeratings' => [ + 'GermanAirlinesVa\Schooling\Models\ExamTyperating', + 'table' => 'exam_exam_answer_exam_question', + 'key' => 'exam_answer_id', + 'otherKey' => 'exam_id', + ], + ]; + + /** + * The "booting" method of the model. + * + * @return void + */ + protected static function boot() + { + parent::boot(); + + static::addGlobalScope('exam_typerating_answer_typerating_id', function (Builder $builder) { + $builder->whereHas('exam_question', function ($query) { + $query->where('typerating_id', '<>', null); + }); + }); + } } diff --git a/models/ExamTyperatingQuestion.php b/models/ExamTyperatingQuestion.php index 0fbded9..ce71308 100644 --- a/models/ExamTyperatingQuestion.php +++ b/models/ExamTyperatingQuestion.php @@ -32,10 +32,36 @@ class ExamTyperatingQuestion extends Model ]; public $hasMany = [ - 'exam_answers' => 'GermanAirlinesVa\Schooling\Models\ExamTyperatingAnswer', + 'exam_answers' => [ + 'GermanAirlinesVa\Schooling\Models\ExamTyperatingAnswer', + 'key' => 'exam_question_id', + ], ]; public $belongsTo = [ 'typerating' => 'GermanAirlinesVa\Schooling\Models\Typerating', ]; + + public $belongsToMany = [ + 'exam_typeratings' => [ + 'GermanAirlinesVa\Schooling\Models\ExamTyperating', + 'table' => 'exam_exam_answer_exam_question', + 'key' => 'exam_question_id', + 'otherKey' => 'exam_id', + ], + ]; + + /** + * The "booting" method of the model. + * + * @return void + */ + protected static function boot() + { + parent::boot(); + + static::addGlobalScope('exam_typerating_question_typerating_id', function ($builder) { + $builder->where('typerating_id', '<>', null); + }); + } } diff --git a/updates/builder_table_create_exam_exam_answer_exam_question.php b/updates/builder_table_create_exam_exam_answer_exam_question.php new file mode 100644 index 0000000..4c440c7 --- /dev/null +++ b/updates/builder_table_create_exam_exam_answer_exam_question.php @@ -0,0 +1,38 @@ +create('exam_exam_answer_exam_question', function($table) + { + $table->engine = 'InnoDB'; + $table->bigIncrements('id')->unsigned(); + $table->bigInteger('exam_id')->unsigned(); + $table + ->foreign('exam_id') + ->references('id') + ->on('exams'); + $table->bigInteger('exam_answer_id')->unsigned(); + $table + ->foreign('exam_answer_id') + ->references('id') + ->on('exam_answers'); + $table->bigInteger('exam_question_id')->unsigned(); + $table + ->foreign('exam_question_id') + ->references('id') + ->on('exam_questions'); + }); + } + + public function down() + { + Schema::connection('germanairlinesva_schooling')->disableForeignKeyConstraints(); + Schema::dropIfExists('germanairlinesva_schooling_exam_exam_answer_exam_question'); + Schema::connection('germanairlinesva_schooling')->disableForeignKeyConstraints(); + } +} diff --git a/updates/version.yaml b/updates/version.yaml index ca30741..342d4c8 100644 --- a/updates/version.yaml +++ b/updates/version.yaml @@ -1,15 +1,17 @@ 1.0.1: - - 'Initialize plugin.' - - 'Create table deferred_bindings' - - builder_table_create_deferred_bindings.php + - 'Initialize plugin.' + - 'Create table deferred_bindings' + - builder_table_create_deferred_bindings.php 1.0.2: - - 'Created table typeratings' - - builder_table_create_typeratings.php - - 'Created table member_ranks' - - builder_table_create_member_ranks.php - - 'Created table exam_questions' - - builder_table_create_exam_questions.php - - 'Created table exam_answers' - - builder_table_create_exam_answers.php - - 'Created table exams' - - builder_table_create_exams.php + - 'Created table typeratings' + - builder_table_create_typeratings.php + - 'Created table member_ranks' + - builder_table_create_member_ranks.php + - 'Created table exam_questions' + - builder_table_create_exam_questions.php + - 'Created table exam_answers' + - builder_table_create_exam_answers.php + - 'Created table exams' + - builder_table_create_exams.php + - 'Created table exam_exam_answer_exam_question' + - builder_table_create_exam_exam_answer_exam_question.php