|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
-
- namespace domain\Product\Accessory;
-
- use common\components\ActiveRecordCommon;
- use domain\Producer\Producer\Producer;
- use domain\Product\ProductAccessory\ProductAccessory;
- use yii\db\ActiveQuery;
-
- class Accessory extends ActiveRecordCommon
- {
- // Produits sélectionnés dans le formulaire
- public $selected_products_ids;
-
- public static function tableName()
- {
- return 'accessory';
- }
-
- public function rules()
- {
- return [
- [['name', 'id_producer', 'quantity'], 'required'],
- [['name'], 'string', 'max' => 255],
- [['quantity', 'id_producer'], 'integer'],
- [['selected_products_ids'], 'safe'],
- ];
- }
-
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'name' => 'Nom',
- 'quantity' => 'Quantité',
- ];
- }
-
- /* Getters / Setters */
-
- public function getId(): ?int
- {
- return $this->id;
- }
-
- public function getProducer(): Producer
- {
- return $this->producerRelation;
- }
-
- public function setProducer(Producer $producer): self
- {
- $this->populateFieldObject('id_producer', 'producerRelation', $producer);
- return $this;
- }
-
- public function getName(): string
- {
- return $this->name;
- }
-
- public function setName(string $name): self
- {
- $this->name = $name;
- return $this;
- }
-
- public function getQuantity(): int
- {
- return $this->quantity;
- }
-
- public function setQuantity(int $quantity): self
- {
- $this->quantity = $quantity;
- return $this;
- }
-
- public function getProductAccessories(): array
- {
- return $this->productAccessoriesRelation;
- }
-
- public function getSelectedProductsIds()
- {
- return $this->selected_products_ids;
- }
-
- public function setSelectedProductsIds(array $selectedProductsIdsArray): self
- {
- $this->selected_products_ids = $selectedProductsIdsArray;
- return $this;
- }
-
- /* Relations */
-
- public function getProducerRelation(): ActiveQuery
- {
- return $this->hasOne(Producer::class, ['id' => 'id_producer']);
- }
-
- public function getProductAccessoriesRelation(): ActiveQuery
- {
- return $this->hasMany(ProductAccessory::class, ['id_accessory' => 'id']);
- }
- }
|