Browse Source

Adaptations refactoring/traduction producer/controllers/SiteController

dev
Guillaume Bourgeois 6 years ago
parent
commit
3e506251f4
2 changed files with 22 additions and 24 deletions
  1. +1
    -1
      common/models/UserProducer.php
  2. +21
    -23
      producer/controllers/SiteController.php

+ 1
- 1
common/models/UserProducer.php View File

return [ return [
[['id_user', 'id_producer'], 'required'], [['id_user', 'id_producer'], 'required'],
[['id_user', 'id_producer'], 'integer'], [['id_user', 'id_producer'], 'integer'],
[['active','favoris'], 'boolean'],
[['active','bookmark'], 'boolean'],
[['credit'], 'double'], [['credit'], 'double'],
]; ];
} }

+ 21
- 23
producer/controllers/SiteController.php View File

$exception = Yii::$app->errorHandler->exception; $exception = Yii::$app->errorHandler->exception;
if ($exception !== null) { if ($exception !== null) {
if($exception->getMessage() == 'Établissement introuvable') {
if($exception->getMessage() == 'Producteur introuvable') {
Yii::$app->getResponse()->redirect(Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/error', 'producer_not_found' => true]))->send(); Yii::$app->getResponse()->redirect(Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/error', 'producer_not_found' => true]))->send();
return; return;
} }
public function actionIndex() public function actionIndex()
{ {
// points de vente // points de vente
$data_provider_points_vente = new ActiveDataProvider([
'query' => PointVente::find()
$dataProviderPointsSale = new ActiveDataProvider([
'query' => PointSale::find()
->where([ ->where([
'id_etablissement' => $this->getProducer()->id,
'id_producer' => $this->getProducer()->id,
]), ]),
'pagination' => [ 'pagination' => [
'pageSize' => 50, 'pageSize' => 50,
]); ]);
// produits // produits
$data_provider_produits = new ActiveDataProvider([
'query' => Produit::find()
->where('(vrac IS NULL OR vrac = 0)')
$dataProviderProducts = new ActiveDataProvider([
'query' => Product::find()
->andWhere([ ->andWhere([
'id_etablissement' => $this->getProducer()->id,
'actif' => true
'id_producer' => $this->getProducer()->id,
'active' => true
]) ])
->orderBy('order ASC'), ->orderBy('order ASC'),
'pagination' => [ 'pagination' => [
]); ]);
return $this->render('index',[ return $this->render('index',[
'data_provider_points_vente' => $data_provider_points_vente,
'data_provider_produits' => $data_provider_produits
'dataProviderPointsSale' => $dataProviderPointsSale,
'dataProviderProducts' => $dataProviderProducts
]) ; ]) ;
} }
* *
* @param $action 'add' ou 'delete' * @param $action 'add' ou 'delete'
*/ */
public function actionFavorite($action)
public function actionBookmarks($action)
{ {
$producer = $this->getProducer() ; $producer = $this->getProducer() ;
$user_etablissement = UserEtablissement::find()
$userProducer = UserProducer::find()
->where([ ->where([
'id_user' => Yii::$app->user->id,
'id_etablissement' => $producer->id
'id_user' => User::getId(),
'id_producer' => $producer->id
]) ])
->one() ; ->one() ;
if(!$user_etablissement) {
$user_etablissement = Etablissement::addUser(Yii::$app->user->id, $producer->id) ;
if(!$userProducer) {
$userProducer = Producer::addUser(User::getId(), $producer->id) ;
} }
if($user_etablissement) {
if($userProducer) {
if($action == 'add') { if($action == 'add') {
$user_etablissement->favoris = 1 ;
Yii::$app->session->setFlash('success','Le producteur <strong>'.Html::encode($producer->nom).'</strong> vient d\'être ajouté à vos favoris.') ;
$userProducer->bookmark = 1 ;
Yii::$app->session->setFlash('success','Le producteur <strong>'.Html::encode($producer->name).'</strong> vient d\'être ajouté à vos favoris.') ;
} }
else { else {
$user_etablissement->favoris = 0 ;
Yii::$app->session->setFlash('success','Le producteur <strong>'.Html::encode($producer->nom).'</strong> vient d\'être supprimé de vos favoris.') ;
$user_etablissement->bookmark = 0 ;
Yii::$app->session->setFlash('success','Le producteur <strong>'.Html::encode($producer->name).'</strong> vient d\'être supprimé de vos favoris.') ;
} }
$user_etablissement->save() ; $user_etablissement->save() ;
} }

Loading…
Cancel
Save