From 43618764a4149378173ed8a4ec6e33b2caafdacb Mon Sep 17 00:00:00 2001 From: Roland Schneider Date: Sat, 12 Sep 2020 12:17:21 +0200 Subject: [PATCH] add equipment_type objects --- common/models/EventEquipmentType.php | 68 +++++++++++++++++ .../models/EventEquipmentTypeAssignment.php | 72 ++++++++++++++++++ ...entRegistrationEquipmentTypeAssignment.php | 70 +++++++++++++++++ .../m200911_200200_add_table_equipment.php | 75 +++++++++++++++++++ 4 files changed, 285 insertions(+) create mode 100644 common/models/EventEquipmentType.php create mode 100644 common/models/EventEquipmentTypeAssignment.php create mode 100644 common/models/EventRegistrationEquipmentTypeAssignment.php create mode 100644 console/migrations/m200911_200200_add_table_equipment.php diff --git a/common/models/EventEquipmentType.php b/common/models/EventEquipmentType.php new file mode 100644 index 0000000..4520f14 --- /dev/null +++ b/common/models/EventEquipmentType.php @@ -0,0 +1,68 @@ + 255] + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id' => Yii::t('common/event', 'ID'), + 'name' => Yii::t('common/event', 'Name'), + 'created_at' => Yii::t('common/event', 'Created At'), + 'updated_at' => Yii::t('common/event', 'Updated At'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getEventEquipmentTypeAssignments() + { + return $this->hasMany(EventEquipmentTypeAssignment::className(), ['id_event_equipment_type' => 'id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getEventRegistrationEquipmentTypeAssignments() + { + return $this->hasMany(EventRegistrationEquipmentTypeAssignment::className(), ['id_event_equipment_type' => 'id']); + } +} diff --git a/common/models/EventEquipmentTypeAssignment.php b/common/models/EventEquipmentTypeAssignment.php new file mode 100644 index 0000000..ff27913 --- /dev/null +++ b/common/models/EventEquipmentTypeAssignment.php @@ -0,0 +1,72 @@ + Yii::t('common/event', 'ID'), + 'id_event' => Yii::t('common/event', 'Id Event'), + 'id_event_equipment_type' => Yii::t('common/event', 'Id Event Equipment Type'), + 'count' => Yii::t('common/event', 'Count'), + 'created_at' => Yii::t('common/event', 'Created At'), + 'updated_at' => Yii::t('common/event', 'Updated At'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getIdEvent() + { + return $this->hasOne(Event::className(), ['id' => 'id_event']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getIdEventEquipmentType() + { + return $this->hasOne(EventEquipmentType::className(), ['id' => 'id_event_equipment_type']); + } +} diff --git a/common/models/EventRegistrationEquipmentTypeAssignment.php b/common/models/EventRegistrationEquipmentTypeAssignment.php new file mode 100644 index 0000000..b386ae6 --- /dev/null +++ b/common/models/EventRegistrationEquipmentTypeAssignment.php @@ -0,0 +1,70 @@ + Yii::t('common/event', 'ID'), + 'id_event_equipment_type' => Yii::t('common/event', 'Id Event Equipment Type'), + 'id_event_registration' => Yii::t('common/event', 'Id Event Registration'), + 'created_at' => Yii::t('common/event', 'Created At'), + 'updated_at' => Yii::t('common/event', 'Updated At'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getIdEventRegistration() + { + return $this->hasOne(EventRegistration::className(), ['id' => 'id_event_registration']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getIdEventEquipmentType() + { + return $this->hasOne(EventEquipmentType::className(), ['id' => 'id_event_equipment_type']); + } +} diff --git a/console/migrations/m200911_200200_add_table_equipment.php b/console/migrations/m200911_200200_add_table_equipment.php new file mode 100644 index 0000000..5369620 --- /dev/null +++ b/console/migrations/m200911_200200_add_table_equipment.php @@ -0,0 +1,75 @@ +db->driverName === 'mysql') { + // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci + $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; + } + $this->createTable('{{%event_equipment_type}}', [ + 'id' => $this->primaryKey(), + 'name' => $this->string(255), + 'created_at' => $this->dateTime()->notNull(), + 'updated_at' => $this->dateTime()->notNull(), + ], $tableOptions); + + $this->createTable('{{%event_equipment_type_assignment}}', [ + 'id' => $this->primaryKey(), + 'id_event' => $this->integer(), + 'id_event_equipment_type' => $this->integer(), + 'count' => $this->integer(), + 'created_at' => $this->dateTime()->notNull(), + 'updated_at' => $this->dateTime()->notNull(), + 'FOREIGN KEY (id_event) REFERENCES event (id) ON DELETE CASCADE ON UPDATE CASCADE', + 'FOREIGN KEY (id_event_equipment_type) REFERENCES event_equipment_type (id) ON DELETE CASCADE ON UPDATE CASCADE', + ], $tableOptions); + + $this->createTable('{{%event_registration_equipment_type_assignment}}', [ + 'id' => $this->primaryKey(), + 'id_event_equipment_type' => $this->integer(), + 'id_event_registration' => $this->integer(), + 'created_at' => $this->dateTime()->notNull(), + 'updated_at' => $this->dateTime()->notNull(), + 'FOREIGN KEY (id_event_registration) REFERENCES event_registration (id) ON DELETE CASCADE ON UPDATE CASCADE', + 'FOREIGN KEY (id_event_equipment_type) REFERENCES event_equipment_type (id) ON DELETE CASCADE ON UPDATE CASCADE', + + ], $tableOptions); + + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + echo "m200911_200200_add_table_equipment cannot be reverted.\n"; + + return false; + } + + /* + // Use up()/down() to run migration code without a transaction. + public function up() + { + + } + + public function down() + { + echo "m200911_200200_add_table_equipment cannot be reverted.\n"; + + return false; + } + */ +}