Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

Rotating.php 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. namespace domain\Product\Rotating;
  3. use common\components\ActiveRecordCommon;
  4. use common\components\Date;
  5. use domain\Producer\Producer\Producer;
  6. use domain\Product\RotatingProduct\RotatingProduct;
  7. use yii\db\ActiveQuery;
  8. class Rotating extends ActiveRecordCommon
  9. {
  10. // Produits sélectionnés dans le formulaire
  11. public $selected_products_ids;
  12. public static function tableName()
  13. {
  14. return 'rotating';
  15. }
  16. public function rules()
  17. {
  18. return [
  19. [['id_producer', 'name', 'day'], 'required'],
  20. [['name'], 'string', 'max' => 255],
  21. [['id_producer', 'day', 'status'], 'integer'],
  22. [['selected_products_ids'], 'safe'],
  23. ];
  24. }
  25. public function attributeLabels()
  26. {
  27. return [
  28. 'id' => 'ID',
  29. 'id_producer' => 'Producteur',
  30. 'name' => 'Nom',
  31. 'day' => 'Jour',
  32. 'status' => 'Statut',
  33. ];
  34. }
  35. /* Getters / Setters */
  36. public function getId(): ?int
  37. {
  38. return $this->id;
  39. }
  40. public function getProducer(): Producer
  41. {
  42. return $this->producerRelation;
  43. }
  44. public function setProducer(Producer $producer): self
  45. {
  46. $this->populateFieldObject('id_producer', 'producerRelation', $producer);
  47. return $this;
  48. }
  49. public function getName(): string
  50. {
  51. return $this->name;
  52. }
  53. public function setName(string $name): self
  54. {
  55. $this->name = $name;
  56. return $this;
  57. }
  58. public function getDay(): int
  59. {
  60. return $this->day;
  61. }
  62. public function setDay(int $day): self
  63. {
  64. $this->day = $day;
  65. return $this;
  66. }
  67. public function getStatus(): int
  68. {
  69. return $this->status;
  70. }
  71. public function setStatus(int $status): self
  72. {
  73. $this->status = $status;
  74. return $this;
  75. }
  76. public function getSelectedProductsIds()
  77. {
  78. return $this->selected_products_ids;
  79. }
  80. public function setSelectedProductsIds(array $selectedProductsIdsArray): self
  81. {
  82. $this->selected_products_ids = $selectedProductsIdsArray;
  83. return $this;
  84. }
  85. public function getRotatingProducts(): array
  86. {
  87. return $this->rotatingProductsRelation;
  88. }
  89. /* Relations */
  90. public function getProducerRelation(): ActiveQuery
  91. {
  92. return $this->hasOne(Producer::class, ['id' => 'id_producer']);
  93. }
  94. public function getRotatingProductsRelation()
  95. {
  96. return $this->hasMany(RotatingProduct::class, ['id_rotating' => 'id']);
  97. }
  98. /* Méthodes */
  99. public function getDayAsString(): string
  100. {
  101. return Date::getDayOfWeekStringByNumber($this->getDay());
  102. }
  103. }