Selaa lähdekoodia

Adaptations refactoring/traduction frontend/controllers/SiteController

dev
Guillaume Bourgeois 6 vuotta sitten
vanhempi
commit
7588486561
1 muutettua tiedostoa jossa 51 lisäystä ja 49 poistoa
  1. +51
    -49
      frontend/controllers/SiteController.php

+ 51
- 49
frontend/controllers/SiteController.php Näytä tiedosto

@@ -39,9 +39,9 @@ termes.
namespace frontend\controllers;

use Yii;
use common\models\Produit;
use common\models\Product;
use common\models\LoginForm;
use common\models\Etablissement;
use common\models\Producer;
use frontend\models\PasswordResetRequestForm;
use frontend\models\ResetPasswordForm;
use frontend\models\SignupForm;
@@ -53,7 +53,7 @@ use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use yii\helpers\Html;
use frontend\controllers\FrontendController;
use common\models\UserEtablissement;
use common\models\UserProducer;
use dosamigos\leaflet\types\LatLng;
use dosamigos\leaflet\layers\Marker;
use dosamigos\leaflet\layers\TileLayer;
@@ -119,7 +119,7 @@ class SiteController extends FrontendController
{
$exception = Yii::$app->errorHandler->exception;
if($exception->getMessage() == 'Établissement introuvable' || Yii::$app->getRequest()->getQueryParam('producer_not_found')) {
if($exception->getMessage() == 'Producteur introuvable' || Yii::$app->getRequest()->getQueryParam('producer_not_found')) {
return $this->render('error-404-producer', ['exception' => $exception]);
}
@@ -145,19 +145,19 @@ class SiteController extends FrontendController
*/
public function actionProducers()
{
$data_provider_producers = new ActiveDataProvider([
'query' => Etablissement::find()
$dataProviderProducers = new ActiveDataProvider([
'query' => Producer::find()
->where([
'actif' => true,
'active' => true,
])
->orderBy('nom ASC'),
->orderBy('name ASC'),
'pagination' => [
'pageSize' => 100,
],
]);
return $this->render('producers',[
'data_provider_producers' => $data_provider_producers
'dataProviderProducers' => $dataProviderProducers
]);
}

@@ -184,16 +184,16 @@ class SiteController extends FrontendController

$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
$return_url = Yii::$app->request->get('return_url');
if($return_url){
return $this->redirect($return_url);
$returnUrl = Yii::$app->request->get('return_url');
if($returnUrl){
return $this->redirect($returnUrl);
}
else {
return $this->goBack();
}
} else {
return $this->render('@frontend/views/site/login', [
'model' => $model,
'model' => $model,
]);
}
}
@@ -249,14 +249,14 @@ class SiteController extends FrontendController
}

// liste des établissements disponibles
$etablissements = Etablissement::getEtablissementsPopulateDropdown();
$data_etablissements_dispos = $etablissements['data'];
$options_etablissements_dispos = $etablissements['options'];
$producersArray = Producer::getProducerPopulateDropdown() ;
$dataProducers = $producersArray['data'];
$optionsProducers = $producersArray['options'];

return $this->render('signup', [
'model' => $model,
'data_etablissements_dispos' => $data_etablissements_dispos,
'options_etablissements_dispos' => $options_etablissements_dispos,
'model' => $model,
'dataProducers' => $dataProducers,
'optionsProducers' => $optionsProducers,
]);
}

@@ -320,12 +320,13 @@ class SiteController extends FrontendController
}

/**
* Affiche les précisions concernant l'utilisation du crédit pain.
* @return type
* Affiche les précisions concernant l'utilisation du crédit.
*
* @return string
*/
public function actionCreditpain()
public function actionCredit()
{
return $this->render('creditpain');
return $this->render('credit');
}
/**
@@ -338,22 +339,23 @@ class SiteController extends FrontendController
*/
public function actionProducerCode($id)
{
$producer = Producer::searchOne($id);
$producer = Etablissement::findOne($id);
if(!$producer)
throw new \yii\web\HttpException(404, 'Établissement introuvable');
$model_producer_code = new ProducerCodeForm ;
$model_producer_code->id_producer = $id ;
if(!$producer) {
throw new \yii\web\HttpException(404, 'Producteur introuvable');
}
$producerCodeForm = new ProducerCodeForm ;
$producerCodeForm->id_producer = $id ;
if($model_producer_code->load(Yii::$app->request->post()) && $model_producer_code->validate()) {
Etablissement::addUser(Yii::$app->user->id, $id) ;
if($producerCodeForm->load(Yii::$app->request->post()) && $producerCodeForm->validate()) {
Producer::addUser(User::getId(), $id) ;
$this->redirect(Yii::$app->urlManagerProducer->createAbsoluteUrl(['site/index','slug_producer' => $producer->slug]));
}
return $this->render('producer_code',[
'producer' => $producer,
'model_producer_code' => $model_producer_code,
'producerCodeForm' => $producerCodeForm,
]) ;
}

@@ -366,38 +368,38 @@ class SiteController extends FrontendController
*/
public function actionProducer($id)
{
$model_login = new LoginForm();
$model_signup = new SignupForm();
$loginForm = new LoginForm();
$signupForm = new SignupForm();
$etablissement = Etablissement::findOne($id);
$producer = Producer::searchOne($id);
$model_login->id_etablissement = $id;
$model_signup->id_etablissement = $id;
$model_signup->option_client_boulanger = 'client';
$loginForm->id_producer = $id;
$signupForm->id_producer = $id;
$signupForm->option_user_producer = 'user';
$return_url = Yii::$app->request->get('return_url', Yii::$app->urlManagerProducer->createAbsoluteUrl(['site/index','slug_producer' => $etablissement->slug]));
$returnUrl = Yii::$app->request->get('returnUrl', Yii::$app->urlManagerProducer->createAbsoluteUrl(['site/index','slug_producer' => $producer->slug]));
if (Yii::$app->user->isGuest) {
if ($model_login->load(Yii::$app->request->post()) && $model_login->login()) {
Etablissement::addUser(Yii::$app->user->id, $id) ;
$this->redirect($return_url);
if ($loginForm->load(Yii::$app->request->post()) && $loginForm->login()) {
Producer::addUser(User::getId(), $id) ;
$this->redirect($returnUrl);
}

if ($model_signup->load(Yii::$app->request->post())) {
if ($user = $model_signup->signup()) {
if ($signupForm->load(Yii::$app->request->post())) {
if ($user = $signupForm->signup()) {
if (Yii::$app->getUser()->login($user)) {
$this->redirect($return_url);
$this->redirect($returnUrl);
}
}
}
} else {
$this->redirect($return_url);
$this->redirect($returnUrl);
}

return $this->render('producer', [
'model_login' => $model_login,
'model_signup' => $model_signup,
'etablissement' => $etablissement,
'loginForm' => $loginForm,
'signupForm' => $signupForm,
'producer' => $producer,
]);
}


Loading…
Peruuta
Tallenna