Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

75 lines
1.6KB

  1. <?php
  2. namespace common\models;
  3. use Yii;
  4. use common\models\Commande;
  5. /**
  6. * This is the model class for table "production".
  7. *
  8. * @property integer $id
  9. * @property string $date
  10. * @property integer $actif
  11. */
  12. class Production extends \yii\db\ActiveRecord {
  13. /**
  14. * @inheritdoc
  15. */
  16. public static function tableName() {
  17. return 'production';
  18. }
  19. public function getEtablissement() {
  20. return $this->hasOne(Etablissement::className(), ['id' => 'id_etablissement']);
  21. }
  22. /**
  23. * @inheritdoc
  24. */
  25. public function rules() {
  26. return [
  27. [['date'], 'required'],
  28. [['date'], 'safe'],
  29. [['actif'], 'integer']
  30. ];
  31. }
  32. /**
  33. * @inheritdoc
  34. */
  35. public function attributeLabels() {
  36. return [
  37. 'id' => 'ID',
  38. 'date' => 'Date',
  39. 'actif' => 'Actif',
  40. ];
  41. }
  42. public function getCommande() {
  43. return $this->hasMany(Commande::className(), ['id_production' => 'id']);
  44. }
  45. public function getProductionProduit() {
  46. return $this->hasMany(ProductionProduit::className(), ['id_production' => 'id']);
  47. }
  48. public function produitActif($id_produit) {
  49. if ($id_produit &&
  50. isset($this->productionProduit) &&
  51. count($this->productionProduit) > 0) {
  52. foreach ($this->productionProduit as $production_produit) {
  53. if ($production_produit['id_produit'] == $id_produit &&
  54. $production_produit['actif']) {
  55. return true;
  56. }
  57. }
  58. }
  59. return false;
  60. }
  61. }