Browse Source

Adaptations refactoring/traduction producer/controllers/SiteController

refactoring
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

@@ -67,7 +67,7 @@ class UserProducer extends \yii\db\ActiveRecord
return [
[['id_user', 'id_producer'], 'required'],
[['id_user', 'id_producer'], 'integer'],
[['active','favoris'], 'boolean'],
[['active','bookmark'], 'boolean'],
[['credit'], 'double'],
];
}

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

@@ -69,7 +69,7 @@ class SiteController extends ProducerBaseController
$exception = Yii::$app->errorHandler->exception;
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();
return;
}
@@ -88,10 +88,10 @@ class SiteController extends ProducerBaseController
public function actionIndex()
{
// points de vente
$data_provider_points_vente = new ActiveDataProvider([
'query' => PointVente::find()
$dataProviderPointsSale = new ActiveDataProvider([
'query' => PointSale::find()
->where([
'id_etablissement' => $this->getProducer()->id,
'id_producer' => $this->getProducer()->id,
]),
'pagination' => [
'pageSize' => 50,
@@ -100,12 +100,11 @@ class SiteController extends ProducerBaseController
]);
// produits
$data_provider_produits = new ActiveDataProvider([
'query' => Produit::find()
->where('(vrac IS NULL OR vrac = 0)')
$dataProviderProducts = new ActiveDataProvider([
'query' => Product::find()
->andWhere([
'id_etablissement' => $this->getProducer()->id,
'actif' => true
'id_producer' => $this->getProducer()->id,
'active' => true
])
->orderBy('order ASC'),
'pagination' => [
@@ -115,8 +114,8 @@ class SiteController extends ProducerBaseController
]);
return $this->render('index',[
'data_provider_points_vente' => $data_provider_points_vente,
'data_provider_produits' => $data_provider_produits
'dataProviderPointsSale' => $dataProviderPointsSale,
'dataProviderProducts' => $dataProviderProducts
]) ;
}
@@ -153,29 +152,28 @@ class SiteController extends ProducerBaseController
*
* @param $action 'add' ou 'delete'
*/
public function actionFavorite($action)
public function actionBookmarks($action)
{
$producer = $this->getProducer() ;
$user_etablissement = UserEtablissement::find()
$userProducer = UserProducer::find()
->where([
'id_user' => Yii::$app->user->id,
'id_etablissement' => $producer->id
'id_user' => User::getId(),
'id_producer' => $producer->id
])
->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') {
$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 {
$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() ;
}

Loading…
Cancel
Save