255], [['recipe'], 'string', 'max' => 1000], ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'id' => 'ID', 'name' => 'Nom', 'description' => 'Description', 'active' => 'Actif', 'photo' => 'Photo', 'price' => 'Prix', 'weight' => 'Poids (g)', 'recipe' => 'Recette', 'monday' => 'Lundi', 'tuesday' => 'Mardi', 'wednesday' => 'Mercredi', 'thursday' => 'Jeudi', 'friday' => 'Vendredi', 'saterday' => 'Samedi', 'sunday' => 'Dimanche', 'order' => 'Ordre', 'quantity_max' => 'Quantité max par défaut', 'unavailable' => 'Épuisé', ]; } /** * Retourne les options de base nécessaires à la fonction de recherche. * * @return array */ public static function defaultOptionsSearch() { return [ 'with' => [], 'join_with' => [], 'orderby' => 'order ASC', 'attribute_id_producer' => 'order.id_producer' ] ; } /** * Retourne la description du produit. * * @return string */ public function getDescription() { $description = $this->description; if (isset($this->weight) && is_numeric($this->weight) && $this->weight > 0) { if ($this->weight >= 1000) { $description .= ' (' . ($this->weight / 1000) . 'kg)'; } else { $description .= ' (' . $this->weight . 'g)'; } } return $description; } /** * Retourne le libellé (admin) du produit. * @return type */ public function getStrWordingAdmin() { return $this->name; } /** * Enregistre le produit. * * @param boolean $runValidation * @param array $attributeNames * @return boolean */ public function save($runValidation = true, $attributeNames = NULL) { $this->id_producer = Producer::getId(); return parent::save($runValidation, $attributeNames); } /** * Retourne les produits d'une production donnée. * * @param integer $idDistribution * @return array */ public static function searchByDistribution($idDistribution) { return Product::find() ->leftJoin('product_distribution', 'product.id = product_distribution.id_product') ->where([ 'id_producer' => Producer::getId(), 'product_distribution.id_distribution' => $idDistribution ]) ->orderBy('product_distribution.active DESC, product.order ASC') ->all(); } /** * Retourne le nombre de produits du producteur courant. * * @return integer */ public static function count() { return self::searchCount() ; } }