|
|
|
|
|
|
|
|
*/ |
|
|
*/ |
|
|
class Product extends \yii\db\ActiveRecord |
|
|
class Product extends \yii\db\ActiveRecord |
|
|
{ |
|
|
{ |
|
|
|
|
|
var $total = 0; |
|
|
|
|
|
|
|
|
var $total = 0; |
|
|
|
|
|
|
|
|
|
|
|
const SALE_MODE_UNIT = 'unit' ; |
|
|
|
|
|
const SALE_MODE_WEIGHT = 'weight' ; |
|
|
|
|
|
|
|
|
const SALE_MODE_UNIT = 'unit' ; |
|
|
|
|
|
const SALE_MODE_WEIGHT = 'weight' ; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @inheritdoc |
|
|
* @inheritdoc |
|
|
|
|
|
|
|
|
public function rules() |
|
|
public function rules() |
|
|
{ |
|
|
{ |
|
|
return [ |
|
|
return [ |
|
|
[['nom', 'id_etablissement'], 'required'], |
|
|
|
|
|
[['actif', 'order', 'quantite_max', 'id_etablissement'], 'integer'], |
|
|
|
|
|
[['lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche', 'epuise'], 'boolean'], |
|
|
|
|
|
[['prix', 'poids'], 'number'], |
|
|
|
|
|
[['illustration', 'photo'], 'file'], |
|
|
|
|
|
[['nom', 'description', 'illustration', 'photo', 'saison', 'diminutif'], 'string', 'max' => 255], |
|
|
|
|
|
[['recette'], 'string', 'max' => 1000], |
|
|
|
|
|
|
|
|
[['name', 'id_producer'], 'required'], |
|
|
|
|
|
[['active', 'order', 'quantity_max', 'id_producer'], 'integer'], |
|
|
|
|
|
[['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saterday', 'sunday', 'unavailable'], 'boolean'], |
|
|
|
|
|
[['price', 'weight'], 'number'], |
|
|
|
|
|
[[ 'photo'], 'file'], |
|
|
|
|
|
[['name', 'description', 'photo'], 'string', 'max' => 255], |
|
|
|
|
|
[['recipe'], 'string', 'max' => 1000], |
|
|
]; |
|
|
]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
{ |
|
|
return [ |
|
|
return [ |
|
|
'id' => 'ID', |
|
|
'id' => 'ID', |
|
|
'nom' => 'Nom', |
|
|
|
|
|
|
|
|
'name' => 'Nom', |
|
|
'description' => 'Description', |
|
|
'description' => 'Description', |
|
|
'actif' => 'Actif', |
|
|
|
|
|
'illustration' => 'Illustration', |
|
|
|
|
|
|
|
|
'active' => 'Actif', |
|
|
'photo' => 'Photo', |
|
|
'photo' => 'Photo', |
|
|
'saison' => 'Saison', |
|
|
|
|
|
'prix' => 'Prix', |
|
|
|
|
|
'poids' => 'Poids (g)', |
|
|
|
|
|
'recette' => 'Recette', |
|
|
|
|
|
'lundi' => 'Lundi', |
|
|
|
|
|
'mardi' => 'Mardi', |
|
|
|
|
|
'mercredi' => 'Mercredi', |
|
|
|
|
|
'jeudi' => 'Jeudi', |
|
|
|
|
|
'vendredi' => 'Vendredi', |
|
|
|
|
|
'samedi' => 'Samedi', |
|
|
|
|
|
'dimanche' => 'Dimanche', |
|
|
|
|
|
|
|
|
'price' => 'Prix', |
|
|
|
|
|
'weight' => 'Poids (g)', |
|
|
|
|
|
'recipe' => 'Recette', |
|
|
|
|
|
'monday' => 'Lundi', |
|
|
|
|
|
'tuesday' => 'Mardi', |
|
|
|
|
|
'wednesday' => 'Mercredi', |
|
|
|
|
|
'thursday' => 'Jeudi', |
|
|
|
|
|
'friday' => 'Vendredi', |
|
|
|
|
|
'saterday' => 'Samedi', |
|
|
|
|
|
'sunday' => 'Dimanche', |
|
|
'order' => 'Ordre', |
|
|
'order' => 'Ordre', |
|
|
'quantite_max' => 'Quantité max par défaut', |
|
|
|
|
|
'epuise' => 'Épuisé', |
|
|
|
|
|
|
|
|
'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. |
|
|
* Retourne la description du produit. |
|
|
|
|
|
|
|
|
public function getDescription() |
|
|
public function getDescription() |
|
|
{ |
|
|
{ |
|
|
$description = $this->description; |
|
|
$description = $this->description; |
|
|
if (isset($this->poids) && is_numeric($this->poids) && $this->poids > 0) { |
|
|
|
|
|
if ($this->poids >= 1000) { |
|
|
|
|
|
$description .= ' (' . ($this->poids / 1000) . 'kg)'; |
|
|
|
|
|
|
|
|
if (isset($this->weight) && is_numeric($this->weight) && $this->weight > 0) { |
|
|
|
|
|
if ($this->weight >= 1000) { |
|
|
|
|
|
$description .= ' (' . ($this->weight / 1000) . 'kg)'; |
|
|
} else { |
|
|
} else { |
|
|
$description .= ' (' . $this->poids . 'g)'; |
|
|
|
|
|
|
|
|
$description .= ' (' . $this->weight . 'g)'; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return $description; |
|
|
return $description; |
|
|
|
|
|
|
|
|
* Retourne le libellé (admin) du produit. |
|
|
* Retourne le libellé (admin) du produit. |
|
|
* @return type |
|
|
* @return type |
|
|
*/ |
|
|
*/ |
|
|
public function getLibelleAdmin() |
|
|
|
|
|
|
|
|
public function getStrWordingAdmin() |
|
|
{ |
|
|
{ |
|
|
return $this->nom; |
|
|
|
|
|
|
|
|
return $this->name; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
|
|
|
|
|
|
*/ |
|
|
*/ |
|
|
public function save($runValidation = true, $attributeNames = NULL) |
|
|
public function save($runValidation = true, $attributeNames = NULL) |
|
|
{ |
|
|
{ |
|
|
$this->id_etablissement = Yii::$app->user->identity->id_etablissement; |
|
|
|
|
|
|
|
|
$this->id_producer = Producer::getCurrentId(); |
|
|
return parent::save($runValidation, $attributeNames); |
|
|
return parent::save($runValidation, $attributeNames); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Retourne les produits de l'établissement courant. |
|
|
|
|
|
* |
|
|
|
|
|
* @return array |
|
|
|
|
|
*/ |
|
|
|
|
|
public function getAll() |
|
|
|
|
|
{ |
|
|
|
|
|
return Produit::find() |
|
|
|
|
|
->where([ |
|
|
|
|
|
'id_etablissement' => Yii::$app->user->identity->id_etablissement, |
|
|
|
|
|
]) |
|
|
|
|
|
->orderBy('order ASC') |
|
|
|
|
|
->all(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Retourne les produits d'une production donnée. |
|
|
* Retourne les produits d'une production donnée. |
|
|
* |
|
|
* |
|
|
* @param integer $id_production |
|
|
|
|
|
|
|
|
* @param integer $idDistribution |
|
|
* @return array |
|
|
* @return array |
|
|
*/ |
|
|
*/ |
|
|
public function getByProduction($id_production) |
|
|
|
|
|
|
|
|
public function searchByDistribution($idDistribution) |
|
|
{ |
|
|
{ |
|
|
return Produit::find() |
|
|
|
|
|
->leftJoin('production_produit', 'produit.id = production_produit.id_produit') |
|
|
|
|
|
|
|
|
return Product::find() |
|
|
|
|
|
->leftJoin('product_distribution', 'product.id = product_distribution.id_product') |
|
|
->where([ |
|
|
->where([ |
|
|
'id_etablissement' => Yii::$app->user->identity->id_etablissement, |
|
|
|
|
|
'production_produit.id_production' => $id_production |
|
|
|
|
|
|
|
|
'id_producer' => Producer::getCurrentId(), |
|
|
|
|
|
'product_distribution.id_distribution' => $idDistribution |
|
|
]) |
|
|
]) |
|
|
->orderBy('production_produit.actif DESC, produit.order ASC') |
|
|
|
|
|
|
|
|
->orderBy('product_distribution.active DESC, product.order ASC') |
|
|
->all(); |
|
|
->all(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
|
*/ |
|
|
public static function count() |
|
|
public static function count() |
|
|
{ |
|
|
{ |
|
|
return Produit::find() |
|
|
|
|
|
->where([ |
|
|
|
|
|
'id_etablissement' => Yii::$app->user->identity->id_etablissement |
|
|
|
|
|
]) |
|
|
|
|
|
->count(); |
|
|
|
|
|
|
|
|
return self::searchCount() ; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |