|
|
|
|
|
|
|
|
* @property double $poids |
|
|
* @property double $poids |
|
|
* @property string $recette |
|
|
* @property string $recette |
|
|
*/ |
|
|
*/ |
|
|
class Produit extends \yii\db\ActiveRecord { |
|
|
|
|
|
|
|
|
class Produit extends \yii\db\ActiveRecord |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
var $total = 0; |
|
|
var $total = 0; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @inheritdoc |
|
|
* @inheritdoc |
|
|
*/ |
|
|
*/ |
|
|
public static function tableName() { |
|
|
|
|
|
|
|
|
public static function tableName() |
|
|
|
|
|
{ |
|
|
return 'produit'; |
|
|
return 'produit'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @inheritdoc |
|
|
* @inheritdoc |
|
|
*/ |
|
|
*/ |
|
|
public function rules() { |
|
|
|
|
|
|
|
|
public function rules() |
|
|
|
|
|
{ |
|
|
return [ |
|
|
return [ |
|
|
[['nom', 'id_etablissement'], 'required'], |
|
|
[['nom', 'id_etablissement'], 'required'], |
|
|
[['actif', 'order', 'quantite_max', 'id_etablissement'], 'integer'], |
|
|
[['actif', 'order', 'quantite_max', 'id_etablissement'], 'integer'], |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @inheritdoc |
|
|
* @inheritdoc |
|
|
*/ |
|
|
*/ |
|
|
public function attributeLabels() { |
|
|
|
|
|
|
|
|
public function attributeLabels() |
|
|
|
|
|
{ |
|
|
return [ |
|
|
return [ |
|
|
'id' => 'ID', |
|
|
'id' => 'ID', |
|
|
'nom' => 'Nom', |
|
|
'nom' => 'Nom', |
|
|
|
|
|
|
|
|
]; |
|
|
]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getDescription() { |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Retourne la description du produit. |
|
|
|
|
|
* |
|
|
|
|
|
* @return string |
|
|
|
|
|
*/ |
|
|
|
|
|
public function getDescription() |
|
|
|
|
|
{ |
|
|
$description = $this->description; |
|
|
$description = $this->description; |
|
|
if (isset($this->poids) && is_numeric($this->poids) && $this->poids > 0) { |
|
|
if (isset($this->poids) && is_numeric($this->poids) && $this->poids > 0) { |
|
|
if ($this->poids >= 1000) { |
|
|
if ($this->poids >= 1000) { |
|
|
|
|
|
|
|
|
return $description; |
|
|
return $description; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getLibelleAdmin() { |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Retourne le libellé (admin) du produit. |
|
|
|
|
|
* @return type |
|
|
|
|
|
*/ |
|
|
|
|
|
public function getLibelleAdmin() |
|
|
|
|
|
{ |
|
|
return $this->nom; |
|
|
return $this->nom; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function save($runValidation = true, $attributeNames = NULL) { |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Enregistre le produit. |
|
|
|
|
|
* |
|
|
|
|
|
* @param boolean $runValidation |
|
|
|
|
|
* @param array $attributeNames |
|
|
|
|
|
* @return boolean |
|
|
|
|
|
*/ |
|
|
|
|
|
public function save($runValidation = true, $attributeNames = NULL) |
|
|
|
|
|
{ |
|
|
$this->id_etablissement = Yii::$app->user->identity->id_etablissement; |
|
|
$this->id_etablissement = Yii::$app->user->identity->id_etablissement; |
|
|
return parent::save($runValidation, $attributeNames); |
|
|
return parent::save($runValidation, $attributeNames); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getAll() { |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Retourne les produits de l'établissement courant. |
|
|
|
|
|
* |
|
|
|
|
|
* @return array |
|
|
|
|
|
*/ |
|
|
|
|
|
public function getAll() |
|
|
|
|
|
{ |
|
|
return Produit::find() |
|
|
return Produit::find() |
|
|
->where([ |
|
|
->where([ |
|
|
'id_etablissement' => Yii::$app->user->identity->id_etablissement, |
|
|
'id_etablissement' => Yii::$app->user->identity->id_etablissement, |
|
|
|
|
|
|
|
|
->all(); |
|
|
->all(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getByProduction($id_production) { |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Retourne les produits d'une production donnée. |
|
|
|
|
|
* |
|
|
|
|
|
* @param integer $id_production |
|
|
|
|
|
* @return array |
|
|
|
|
|
*/ |
|
|
|
|
|
public function getByProduction($id_production) |
|
|
|
|
|
{ |
|
|
return Produit::find() |
|
|
return Produit::find() |
|
|
->leftJoin('production_produit', 'produit.id = production_produit.id_produit') |
|
|
->leftJoin('production_produit', 'produit.id = production_produit.id_produit') |
|
|
->where([ |
|
|
->where([ |
|
|
|
|
|
|
|
|
->all(); |
|
|
->all(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public static function count() { |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Retourne le nombre de produits du producteur courant. |
|
|
|
|
|
* |
|
|
|
|
|
* @return integer |
|
|
|
|
|
*/ |
|
|
|
|
|
public static function count() |
|
|
|
|
|
{ |
|
|
return Produit::find() |
|
|
return Produit::find() |
|
|
->where([ |
|
|
->where([ |
|
|
'id_etablissement' => Yii::$app->user->identity->id_etablissement |
|
|
'id_etablissement' => Yii::$app->user->identity->id_etablissement |