You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
2.3KB

  1. <?php
  2. namespace domain\Product\Accessory;
  3. use common\components\ActiveRecordCommon;
  4. use domain\Producer\Producer\Producer;
  5. use domain\Product\ProductAccessory\ProductAccessory;
  6. use yii\db\ActiveQuery;
  7. class Accessory extends ActiveRecordCommon
  8. {
  9. // Produits sélectionnés dans le formulaire
  10. public $selected_products_ids;
  11. public static function tableName()
  12. {
  13. return 'accessory';
  14. }
  15. public function rules()
  16. {
  17. return [
  18. [['name', 'id_producer', 'quantity'], 'required'],
  19. [['name'], 'string', 'max' => 255],
  20. [['quantity', 'id_producer'], 'integer'],
  21. [['selected_products_ids'], 'safe'],
  22. ];
  23. }
  24. public function attributeLabels()
  25. {
  26. return [
  27. 'id' => 'ID',
  28. 'name' => 'Nom',
  29. 'quantity' => 'Quantité',
  30. ];
  31. }
  32. /* Getters / Setters */
  33. public function getId(): ?int
  34. {
  35. return $this->id;
  36. }
  37. public function getProducer(): Producer
  38. {
  39. return $this->producerRelation;
  40. }
  41. public function setProducer(Producer $producer): self
  42. {
  43. $this->populateFieldObject('id_producer', 'producerRelation', $producer);
  44. return $this;
  45. }
  46. public function getName(): string
  47. {
  48. return $this->name;
  49. }
  50. public function setName(string $name): self
  51. {
  52. $this->name = $name;
  53. return $this;
  54. }
  55. public function getQuantity(): int
  56. {
  57. return $this->quantity;
  58. }
  59. public function setQuantity(int $quantity): self
  60. {
  61. $this->quantity = $quantity;
  62. return $this;
  63. }
  64. public function getProductAccessories(): array
  65. {
  66. return $this->productAccessoriesRelation;
  67. }
  68. public function getSelectedProductsIds()
  69. {
  70. return $this->selected_products_ids;
  71. }
  72. public function setSelectedProductsIds(array $selectedProductsIdsArray): self
  73. {
  74. $this->selected_products_ids = $selectedProductsIdsArray;
  75. return $this;
  76. }
  77. /* Relations */
  78. public function getProducerRelation(): ActiveQuery
  79. {
  80. return $this->hasOne(Producer::class, ['id' => 'id_producer']);
  81. }
  82. public function getProductAccessoriesRelation(): ActiveQuery
  83. {
  84. return $this->hasMany(ProductAccessory::class, ['id_accessory' => 'id']);
  85. }
  86. }