Ver código fonte

Refactoring/traduction modèle Produit > Product

dev
Guillaume Bourgeois 6 anos atrás
pai
commit
bd73151814
5 arquivos alterados com 59 adições e 67 exclusões
  1. +1
    -1
      common/components/ActiveRecordCommon.php
  2. +1
    -1
      common/models/Development.php
  3. +2
    -2
      common/models/PointSale.php
  4. +2
    -2
      common/models/Producer.php
  5. +53
    -61
      common/models/Product.php

+ 1
- 1
common/components/ActiveRecordCommon.php Ver arquivo

@@ -71,7 +71,7 @@ class ActiveRecordCommon extends \yii\db\ActiveRecord
$pk = $class::tableName().'.'.$pk[0] ;
if (!isset($params[$options['attribute_id_producer']]) && !Yii::$app->user->isGuest) {
$params[$options['attribute_id_producer']] = Producer::getCurrent();
$params[$options['attribute_id_producer']] = Producer::getCurrentId();
}
if(!isset($options['type_search'])) {

+ 1
- 1
common/models/Development.php Ver arquivo

@@ -100,7 +100,7 @@ class Development extends \yii\db\ActiveRecord
return $this->hasOne(
DevelopmentPriority::className(),
['id_development' => 'id'])
->where(['id_producer' => Producer::getCurrent()])
->where(['id_producer' => Producer::getCurrentId()])
->with('producer');
}


+ 2
- 2
common/models/PointSale.php Ver arquivo

@@ -183,7 +183,7 @@ class PointSale extends \yii\db\ActiveRecord
*/
public function save($runValidation = true, $attributeNames = NULL)
{
$this->id_producer = Producer::getCurrent();
$this->id_producer = Producer::getCurrentId();
return parent::save($runValidation, $attributeNames);
}

@@ -249,7 +249,7 @@ class PointSale extends \yii\db\ActiveRecord
*/
public static function count()
{
return self::searchCount(['id_producer' => Producer::getCurrent()]) ;
return self::searchCount(['id_producer' => Producer::getCurrentId()]) ;
}

/**

+ 2
- 2
common/models/Producer.php Ver arquivo

@@ -268,7 +268,7 @@ class Producer extends \yii\db\ActiveRecord
{
if (strlen($config)) {
if (!$idProducer) {
$idProducer = Producer::getCurrent() ;
$idProducer = Producer::getCurrentId() ;
}
$producer = self::findOne($idProducer);
@@ -337,7 +337,7 @@ class Producer extends \yii\db\ActiveRecord
*
* @return boolean
*/
public static function getCurrent()
public static function getCurrentId()
{
if(!Yii::$app->user->isGuest) {
return Yii::$app->user->identity->id_producer ;

+ 53
- 61
common/models/Product.php Ver arquivo

@@ -56,11 +56,10 @@ use Yii;
*/
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
@@ -76,13 +75,13 @@ class Product extends \yii\db\ActiveRecord
public function rules()
{
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],
];
}

@@ -93,27 +92,39 @@ class Product extends \yii\db\ActiveRecord
{
return [
'id' => 'ID',
'nom' => 'Nom',
'name' => 'Nom',
'description' => 'Description',
'actif' => 'Actif',
'illustration' => 'Illustration',
'active' => 'Actif',
'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',
'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.
@@ -123,11 +134,11 @@ class Product extends \yii\db\ActiveRecord
public function getDescription()
{
$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 {
$description .= ' (' . $this->poids . 'g)';
$description .= ' (' . $this->weight . 'g)';
}
}
return $description;
@@ -137,9 +148,9 @@ class Product extends \yii\db\ActiveRecord
* Retourne le libellé (admin) du produit.
* @return type
*/
public function getLibelleAdmin()
public function getStrWordingAdmin()
{
return $this->nom;
return $this->name;
}

/**
@@ -151,40 +162,25 @@ class Product extends \yii\db\ActiveRecord
*/
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);
}

/**
* 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.
*
* @param integer $id_production
* @param integer $idDistribution
* @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([
'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();
}

@@ -195,11 +191,7 @@ class Product extends \yii\db\ActiveRecord
*/
public static function count()
{
return Produit::find()
->where([
'id_etablissement' => Yii::$app->user->identity->id_etablissement
])
->count();
return self::searchCount() ;
}

}

Carregando…
Cancelar
Salvar