Przeglądaj źródła

Adaptations refactoring/traduction producer/controllers/SiteController

dev
Guillaume Bourgeois 6 lat temu
rodzic
commit
3e506251f4
2 zmienionych plików z 22 dodań i 24 usunięć
  1. +1
    -1
      common/models/UserProducer.php
  2. +21
    -23
      producer/controllers/SiteController.php

+ 1
- 1
common/models/UserProducer.php Wyświetl plik

@@ -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 Wyświetl plik

@@ -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() ;
}

Ładowanie…
Anuluj
Zapisz