|
|
@@ -38,438 +38,428 @@ |
|
|
|
|
|
|
|
namespace frontend\controllers; |
|
|
|
|
|
|
|
use common\models\ProducerPriceRange; |
|
|
|
use common\models\User; |
|
|
|
use Yii; |
|
|
|
use common\models\Product; |
|
|
|
use common\models\LoginForm; |
|
|
|
use common\models\Producer; |
|
|
|
use frontend\models\PasswordResetRequestForm; |
|
|
|
use frontend\models\ResetPasswordForm; |
|
|
|
use frontend\models\SignupForm; |
|
|
|
use common\models\ContactForm; |
|
|
|
use common\forms\ContactForm; |
|
|
|
use yii\base\InvalidParamException; |
|
|
|
use yii\data\ActiveDataProvider; |
|
|
|
use yii\web\BadRequestHttpException; |
|
|
|
use yii\web\Controller; |
|
|
|
use yii\filters\VerbFilter; |
|
|
|
use yii\filters\AccessControl; |
|
|
|
use yii\helpers\Html; |
|
|
|
use frontend\controllers\FrontendController; |
|
|
|
use common\models\UserProducer; |
|
|
|
use dosamigos\leaflet\types\LatLng; |
|
|
|
use dosamigos\leaflet\layers\Marker; |
|
|
|
use dosamigos\leaflet\layers\TileLayer; |
|
|
|
use dosamigos\leaflet\LeafLet; |
|
|
|
use dosamigos\leaflet\widgets\Map; |
|
|
|
use common\forms\LoginForm; |
|
|
|
|
|
|
|
/** |
|
|
|
* Site controller |
|
|
|
*/ |
|
|
|
class SiteController extends FrontendController |
|
|
|
{ |
|
|
|
|
|
|
|
/** |
|
|
|
* @inheritdoc |
|
|
|
*/ |
|
|
|
public function behaviors() |
|
|
|
{ |
|
|
|
return [ |
|
|
|
'access' => [ |
|
|
|
'class' => AccessControl::className(), |
|
|
|
'only' => ['logout', 'signup'], |
|
|
|
'rules' => [ |
|
|
|
[ |
|
|
|
'actions' => ['signup'], |
|
|
|
'allow' => true, |
|
|
|
'roles' => ['?'], |
|
|
|
], |
|
|
|
[ |
|
|
|
'actions' => ['logout'], |
|
|
|
'allow' => true, |
|
|
|
'roles' => ['@'], |
|
|
|
], |
|
|
|
], |
|
|
|
], |
|
|
|
'verbs' => [ |
|
|
|
'class' => VerbFilter::className(), |
|
|
|
'actions' => [ |
|
|
|
'logout' => ['get'], |
|
|
|
], |
|
|
|
], |
|
|
|
]; |
|
|
|
/** |
|
|
|
* @inheritdoc |
|
|
|
*/ |
|
|
|
public function behaviors() |
|
|
|
{ |
|
|
|
return [ |
|
|
|
'access' => [ |
|
|
|
'class' => AccessControl::className(), |
|
|
|
'only' => ['logout', 'signup'], |
|
|
|
'rules' => [ |
|
|
|
[ |
|
|
|
'actions' => ['signup'], |
|
|
|
'allow' => true, |
|
|
|
'roles' => ['?'], |
|
|
|
], |
|
|
|
[ |
|
|
|
'actions' => ['logout'], |
|
|
|
'allow' => true, |
|
|
|
'roles' => ['@'], |
|
|
|
], |
|
|
|
], |
|
|
|
], |
|
|
|
'verbs' => [ |
|
|
|
'class' => VerbFilter::className(), |
|
|
|
'actions' => [ |
|
|
|
'logout' => ['get'], |
|
|
|
], |
|
|
|
], |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @inheritdoc |
|
|
|
*/ |
|
|
|
public function actions() |
|
|
|
{ |
|
|
|
return [ |
|
|
|
'captcha' => [ |
|
|
|
'class' => 'yii\captcha\CaptchaAction', |
|
|
|
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null, |
|
|
|
], |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Affiche la page d'erreur. |
|
|
|
* |
|
|
|
* @return mixed |
|
|
|
*/ |
|
|
|
public function actionError() |
|
|
|
{ |
|
|
|
$exception = Yii::$app->errorHandler->exception; |
|
|
|
|
|
|
|
if ($exception->getMessage() == 'Producteur introuvable' |
|
|
|
|| Yii::$app->getRequest()->getQueryParam('producer_not_found')) { |
|
|
|
return $this->render('error-404-producer', ['exception' => $exception]); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @inheritdoc |
|
|
|
*/ |
|
|
|
public function actions() |
|
|
|
{ |
|
|
|
return [ |
|
|
|
'captcha' => [ |
|
|
|
'class' => 'yii\captcha\CaptchaAction', |
|
|
|
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null, |
|
|
|
], |
|
|
|
]; |
|
|
|
if ($exception !== null) { |
|
|
|
return $this->render('error', ['exception' => $exception]); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Affiche la page d'erreur. |
|
|
|
* |
|
|
|
* @return mixed |
|
|
|
*/ |
|
|
|
public function actionError() |
|
|
|
{ |
|
|
|
$exception = Yii::$app->errorHandler->exception; |
|
|
|
|
|
|
|
if ($exception->getMessage() == 'Producteur introuvable' || Yii::$app->getRequest()->getQueryParam('producer_not_found')) { |
|
|
|
return $this->render('error-404-producer', ['exception' => $exception]); |
|
|
|
} |
|
|
|
|
|
|
|
if ($exception !== null) { |
|
|
|
return $this->render('error', ['exception' => $exception]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Affiche la page d'accueil. |
|
|
|
* |
|
|
|
* @return mixed |
|
|
|
*/ |
|
|
|
public function actionIndex() |
|
|
|
{ |
|
|
|
return $this->render('index', [ |
|
|
|
'producerDemoAccount' => Producer::getDemoAccount(), |
|
|
|
'dataProviderPrices' => $this->getDataProviderPrices() |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Affiche la page d'accueil. |
|
|
|
* |
|
|
|
* @return mixed |
|
|
|
*/ |
|
|
|
public function actionIndex() |
|
|
|
{ |
|
|
|
$producerRepository = $this->getLogic()->getProducerContainer()->getRepository(); |
|
|
|
|
|
|
|
return $this->render('index', [ |
|
|
|
'producerDemoAccount' => $producerRepository->getDemoAccount(), |
|
|
|
'dataProviderPrices' => $this->getDataProviderPrices() |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Page de présentation des tarifs |
|
|
|
* |
|
|
|
* @return mixed |
|
|
|
*/ |
|
|
|
public function actionPrices() |
|
|
|
{ |
|
|
|
return $this->render('prices', [ |
|
|
|
'dataProviderPrices' => $this->getDataProviderPrices() |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
public function getDataProviderPrices() |
|
|
|
{ |
|
|
|
$producerPriceRangeRepository = $this->getLogic()->getProducerPriceRangeContainer()->getRepository(); |
|
|
|
|
|
|
|
return new ActiveDataProvider([ |
|
|
|
'query' => $producerPriceRangeRepository->query(), |
|
|
|
'pagination' => [ |
|
|
|
'pageSize' => 100, |
|
|
|
], |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Liste les producteurs utilisant la plateforme. |
|
|
|
* |
|
|
|
* @return mixed |
|
|
|
*/ |
|
|
|
public function actionProducers() |
|
|
|
{ |
|
|
|
$producerRepository = $this->getLogic()->getProducerContainer()->getRepository(); |
|
|
|
|
|
|
|
$dataProviderProducers = new ActiveDataProvider([ |
|
|
|
'query' => $producerRepository->queryActive(), |
|
|
|
'pagination' => [ |
|
|
|
'pageSize' => 100, |
|
|
|
], |
|
|
|
]); |
|
|
|
|
|
|
|
return $this->render('producers', [ |
|
|
|
'dataProviderProducers' => $dataProviderProducers |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Affiche les mentions légales. |
|
|
|
* |
|
|
|
* @return mixed |
|
|
|
*/ |
|
|
|
public function actionMentions() |
|
|
|
{ |
|
|
|
return $this->render('mentions'); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Affiche la page de connexion et traite le formulaire de connexion. |
|
|
|
* |
|
|
|
* @return mixed |
|
|
|
*/ |
|
|
|
public function actionLogin() |
|
|
|
{ |
|
|
|
if (!\Yii::$app->user->isGuest) { |
|
|
|
return Yii::$app->getResponse()->redirect(['site/index']); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Page de présentation des tarifs |
|
|
|
* |
|
|
|
* @return mixed |
|
|
|
*/ |
|
|
|
public function actionPrices() |
|
|
|
{ |
|
|
|
return $this->render('prices', [ |
|
|
|
'dataProviderPrices' => $this->getDataProviderPrices() |
|
|
|
$model = new LoginForm(); |
|
|
|
if ($model->load(Yii::$app->request->post()) && $model->login()) { |
|
|
|
$returnUrl = Yii::$app->request->get('return_url'); |
|
|
|
if ($returnUrl) { |
|
|
|
return $this->redirect($returnUrl); |
|
|
|
} |
|
|
|
else { |
|
|
|
$userProducerArray = $this->getLogic()->getUserProducerContainer()->getBy(User::getCurrentId()); |
|
|
|
|
|
|
|
if ($userProducerArray && is_array($userProducerArray) && count($userProducerArray) == 1) { |
|
|
|
return $this->redirect(Yii::$app->urlManagerProducer->createAbsoluteUrl(['site/index', 'slug_producer' => $userProducerArray[0]->producer->slug])); |
|
|
|
} else { |
|
|
|
return $this->goBack(); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
return $this->render('@frontend/views/site/login', [ |
|
|
|
'model' => $model, |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
public function getDataProviderPrices(){ |
|
|
|
return new ActiveDataProvider([ |
|
|
|
'query' => ProducerPriceRange::find() |
|
|
|
->orderBy('id ASC'), |
|
|
|
'pagination' => [ |
|
|
|
'pageSize' => 100, |
|
|
|
], |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Liste les producteurs utilisant la plateforme. |
|
|
|
* |
|
|
|
* @return mixed |
|
|
|
*/ |
|
|
|
public function actionProducers() |
|
|
|
{ |
|
|
|
$dataProviderProducers = new ActiveDataProvider([ |
|
|
|
'query' => Producer::find() |
|
|
|
->where([ |
|
|
|
'active' => true, |
|
|
|
]) |
|
|
|
->orderBy('name ASC'), |
|
|
|
'pagination' => [ |
|
|
|
'pageSize' => 100, |
|
|
|
], |
|
|
|
]); |
|
|
|
|
|
|
|
return $this->render('producers', [ |
|
|
|
'dataProviderProducers' => $dataProviderProducers |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Déconnecte l'utilisateur. |
|
|
|
* |
|
|
|
* @return mixed |
|
|
|
*/ |
|
|
|
public function actionLogout() |
|
|
|
{ |
|
|
|
Yii::$app->user->logout(); |
|
|
|
return $this->goHome(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Affiche la page de contact et traite le formulaire s'il est soumis. |
|
|
|
* |
|
|
|
* @return mixed |
|
|
|
*/ |
|
|
|
public function actionContact() |
|
|
|
{ |
|
|
|
$model = new ContactForm(); |
|
|
|
|
|
|
|
if ($model->load(Yii::$app->request->post()) && $model->validate()) { |
|
|
|
if ($model->sendEmail(Yii::$app->params['adminEmail'])) { |
|
|
|
$this->setFlash('success', 'Votre message a bien été envoyé. Nous vous répondrons dès que possible.'); |
|
|
|
} |
|
|
|
else { |
|
|
|
$this->setFlash('error', 'Il y a eu une erreur lors de l\'envoi de votre message.'); |
|
|
|
} |
|
|
|
|
|
|
|
return $this->refresh(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Affiche les mentions légales. |
|
|
|
* |
|
|
|
* @return mixed |
|
|
|
*/ |
|
|
|
public function actionMentions() |
|
|
|
{ |
|
|
|
return $this->render('mentions'); |
|
|
|
else { |
|
|
|
return $this->render('contact', [ |
|
|
|
'model' => $model, |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Affiche la page de connexion et traite le formulaire de connexion. |
|
|
|
* |
|
|
|
* @return mixed |
|
|
|
*/ |
|
|
|
public function actionLogin() |
|
|
|
{ |
|
|
|
if (!\Yii::$app->user->isGuest) { |
|
|
|
return Yii::$app->getResponse()->redirect(['site/index']); |
|
|
|
} |
|
|
|
|
|
|
|
$model = new LoginForm(); |
|
|
|
if ($model->load(Yii::$app->request->post()) && $model->login()) { |
|
|
|
$returnUrl = Yii::$app->request->get('return_url'); |
|
|
|
if ($returnUrl) { |
|
|
|
return $this->redirect($returnUrl); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Affiche la page d'inscription et traite son formulaire. |
|
|
|
* |
|
|
|
* @return mixed |
|
|
|
*/ |
|
|
|
public function actionSignup() |
|
|
|
{ |
|
|
|
$model = new SignupForm(); |
|
|
|
if ($model->load(Yii::$app->request->post())) { |
|
|
|
$user = $model->signup(); |
|
|
|
|
|
|
|
if ($user) { |
|
|
|
if (Yii::$app->getUser()->login($user)) { |
|
|
|
if ($model->option_user_producer == 'producer') { |
|
|
|
$this->redirect(Yii::$app->urlManagerBackend->createAbsoluteUrl(['site/index'])); |
|
|
|
} else { |
|
|
|
$producer = Producer::findOne($model->id_producer); |
|
|
|
if ($producer) { |
|
|
|
$this->redirect(Yii::$app->urlManagerProducer->createAbsoluteUrl(['site/index', 'slug_producer' => $producer->slug])); |
|
|
|
} else { |
|
|
|
$userProducerArray = UserProducer::find() |
|
|
|
->with(['producer']) |
|
|
|
->where(['id_user' => User::getCurrentId(), 'active' => 1, 'bookmark' => 1]) |
|
|
|
->all(); |
|
|
|
|
|
|
|
if ($userProducerArray && is_array($userProducerArray) && count($userProducerArray) == 1) { |
|
|
|
return $this->redirect(Yii::$app->urlManagerProducer->createAbsoluteUrl(['site/index', 'slug_producer' => $userProducerArray[0]->producer->slug])); |
|
|
|
} else { |
|
|
|
return $this->goBack(); |
|
|
|
} |
|
|
|
$this->redirect(['site/index']); |
|
|
|
} |
|
|
|
} else { |
|
|
|
return $this->render('@frontend/views/site/login', [ |
|
|
|
'model' => $model, |
|
|
|
]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Déconnecte l'utilisateur. |
|
|
|
* |
|
|
|
* @return mixed |
|
|
|
*/ |
|
|
|
public function actionLogout() |
|
|
|
{ |
|
|
|
Yii::$app->user->logout(); |
|
|
|
return $this->goHome(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Affiche la page de contact et traite le formulaire s'il est soumis. |
|
|
|
* |
|
|
|
* @return mixed |
|
|
|
*/ |
|
|
|
public function actionContact() |
|
|
|
{ |
|
|
|
$model = new ContactForm(); |
|
|
|
if ($model->load(Yii::$app->request->post()) && $model->validate()) { |
|
|
|
if ($model->sendEmail(Yii::$app->params['adminEmail'])) { |
|
|
|
Yii::$app->session->setFlash('success', 'Votre message a bien été envoyé. Nous vous répondrons dès que possible.'); |
|
|
|
} else { |
|
|
|
Yii::$app->session->setFlash('error', 'Il y a eu une erreur lors de l\'envoi de votre message.'); |
|
|
|
} |
|
|
|
// liste des producteurs disponibles |
|
|
|
$producersArray = Producer::getProducerPopulateDropdown(); |
|
|
|
$dataProducers = $producersArray['data']; |
|
|
|
$optionsProducers = $producersArray['options']; |
|
|
|
|
|
|
|
return $this->render('signup', [ |
|
|
|
'model' => $model, |
|
|
|
'dataProducers' => $dataProducers, |
|
|
|
'dataProviderPrices' => $this->getDataProviderPrices(), |
|
|
|
'optionsProducers' => $optionsProducers, |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Affiche la page de demande de nouveau mot de passe. |
|
|
|
* Traitement du formulaire. |
|
|
|
* |
|
|
|
* @return mixed |
|
|
|
*/ |
|
|
|
public function actionRequestPasswordReset() |
|
|
|
{ |
|
|
|
$model = new PasswordResetRequestForm(); |
|
|
|
if ($model->load(Yii::$app->request->post()) && $model->validate()) { |
|
|
|
if ($model->sendEmail()) { |
|
|
|
Yii::$app->getSession()->setFlash('success', 'Un lien vous permettant de réinitialiser votre mot de passe vient d\'être envoyé sur votre boîte mail.'); |
|
|
|
|
|
|
|
return $this->refresh(); |
|
|
|
} else { |
|
|
|
return $this->render('contact', [ |
|
|
|
'model' => $model, |
|
|
|
]); |
|
|
|
} |
|
|
|
return $this->goHome(); |
|
|
|
} else { |
|
|
|
Yii::$app->getSession()->setFlash('error', 'Sorry, we are unable to reset password for email provided.'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Affiche la page d'inscription et traite son formulaire. |
|
|
|
* |
|
|
|
* @return mixed |
|
|
|
*/ |
|
|
|
public function actionSignup() |
|
|
|
{ |
|
|
|
$model = new SignupForm(); |
|
|
|
if ($model->load(Yii::$app->request->post())) { |
|
|
|
$user = $model->signup(); |
|
|
|
|
|
|
|
if ($user) { |
|
|
|
if (Yii::$app->getUser()->login($user)) { |
|
|
|
if ($model->option_user_producer == 'producer') { |
|
|
|
$this->redirect(Yii::$app->urlManagerBackend->createAbsoluteUrl(['site/index'])); |
|
|
|
} else { |
|
|
|
$producer = Producer::findOne($model->id_producer); |
|
|
|
if ($producer) { |
|
|
|
$this->redirect(Yii::$app->urlManagerProducer->createAbsoluteUrl(['site/index', 'slug_producer' => $producer->slug])); |
|
|
|
} else { |
|
|
|
$this->redirect(['site/index']); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// liste des établissements disponibles |
|
|
|
$producersArray = Producer::getProducerPopulateDropdown(); |
|
|
|
$dataProducers = $producersArray['data']; |
|
|
|
$optionsProducers = $producersArray['options']; |
|
|
|
|
|
|
|
return $this->render('signup', [ |
|
|
|
'model' => $model, |
|
|
|
'dataProducers' => $dataProducers, |
|
|
|
'dataProviderPrices' => $this->getDataProviderPrices(), |
|
|
|
'optionsProducers' => $optionsProducers, |
|
|
|
]); |
|
|
|
return $this->render('requestPasswordResetToken', [ |
|
|
|
'model' => $model, |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Met à jour le mot de passe de l'utilisateur. |
|
|
|
* |
|
|
|
* @param string $token |
|
|
|
* @return mixed |
|
|
|
* @throws BadRequestHttpException |
|
|
|
*/ |
|
|
|
public function actionResetPassword($token) |
|
|
|
{ |
|
|
|
try { |
|
|
|
$model = new ResetPasswordForm($token); |
|
|
|
} catch (InvalidParamException $e) { |
|
|
|
throw new BadRequestHttpException($e->getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Affiche la page de demande de nouveau mot de passe. |
|
|
|
* Traitement du formulaire. |
|
|
|
* |
|
|
|
* @return mixed |
|
|
|
*/ |
|
|
|
public function actionRequestPasswordReset() |
|
|
|
{ |
|
|
|
$model = new PasswordResetRequestForm(); |
|
|
|
if ($model->load(Yii::$app->request->post()) && $model->validate()) { |
|
|
|
if ($model->sendEmail()) { |
|
|
|
Yii::$app->getSession()->setFlash('success', 'Un lien vous permettant de réinitialiser votre mot de passe vient d\'être envoyé sur votre boîte mail.'); |
|
|
|
|
|
|
|
return $this->goHome(); |
|
|
|
} else { |
|
|
|
Yii::$app->getSession()->setFlash('error', 'Sorry, we are unable to reset password for email provided.'); |
|
|
|
} |
|
|
|
} |
|
|
|
if ($model->load(Yii::$app->request->post()) && $model->validate() && $model->resetPassword()) { |
|
|
|
Yii::$app->getSession()->setFlash('success', 'Votre nouveau mot de passe vient d\'être sauvegardé.'); |
|
|
|
|
|
|
|
return $this->render('requestPasswordResetToken', [ |
|
|
|
'model' => $model, |
|
|
|
]); |
|
|
|
return $this->goHome(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Met à jour le mot de passe de l'utilisateur. |
|
|
|
* |
|
|
|
* @param string $token |
|
|
|
* @return mixed |
|
|
|
* @throws BadRequestHttpException |
|
|
|
*/ |
|
|
|
public function actionResetPassword($token) |
|
|
|
{ |
|
|
|
try { |
|
|
|
$model = new ResetPasswordForm($token); |
|
|
|
} catch (InvalidParamException $e) { |
|
|
|
throw new BadRequestHttpException($e->getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
if ($model->load(Yii::$app->request->post()) && $model->validate() && $model->resetPassword()) { |
|
|
|
Yii::$app->getSession()->setFlash('success', 'Votre nouveau mot de passe vient d\'être sauvegardé.'); |
|
|
|
|
|
|
|
return $this->goHome(); |
|
|
|
} |
|
|
|
|
|
|
|
return $this->render('resetPassword', [ |
|
|
|
'model' => $model, |
|
|
|
]); |
|
|
|
return $this->render('resetPassword', [ |
|
|
|
'model' => $model, |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Affiche les conditions générale de service. |
|
|
|
* |
|
|
|
* @return mixed |
|
|
|
*/ |
|
|
|
public function actionCgv() |
|
|
|
{ |
|
|
|
return $this->render('cgv'); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Affiche les précisions concernant l'utilisation du crédit. |
|
|
|
* |
|
|
|
* @return string |
|
|
|
*/ |
|
|
|
public function actionCredit() |
|
|
|
{ |
|
|
|
return $this->render('credit'); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Affiche le formulaire de demande de code pour accéder à certains |
|
|
|
* producteurs. |
|
|
|
* |
|
|
|
* @param integer $id |
|
|
|
* @return mixed |
|
|
|
* @throws \yii\web\HttpException |
|
|
|
*/ |
|
|
|
public function actionProducerCode($id) |
|
|
|
{ |
|
|
|
$producer = Producer::findOne($id); |
|
|
|
|
|
|
|
if (!$producer) { |
|
|
|
throw new \yii\web\HttpException(404, 'Producteur introuvable'); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Affiche les conditions générale de service. |
|
|
|
* |
|
|
|
* @return mixed |
|
|
|
*/ |
|
|
|
public function actionCgv() |
|
|
|
{ |
|
|
|
return $this->render('cgv'); |
|
|
|
} |
|
|
|
$producerCodeForm = new ProducerCodeForm; |
|
|
|
$producerCodeForm->id_producer = $id; |
|
|
|
|
|
|
|
/** |
|
|
|
* Affiche les précisions concernant l'utilisation du crédit. |
|
|
|
* |
|
|
|
* @return string |
|
|
|
*/ |
|
|
|
public function actionCredit() |
|
|
|
{ |
|
|
|
return $this->render('credit'); |
|
|
|
if ($producerCodeForm->load(Yii::$app->request->post()) && $producerCodeForm->validate()) { |
|
|
|
Producer::addUser(User::getCurrentId(), $id); |
|
|
|
$this->redirect(Yii::$app->urlManagerProducer->createAbsoluteUrl(['site/index', 'slug_producer' => $producer->slug])); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Affiche le formulaire de demande de code pour accéder à certains |
|
|
|
* producteurs. |
|
|
|
* |
|
|
|
* @param integer $id |
|
|
|
* @return mixed |
|
|
|
* @throws \yii\web\HttpException |
|
|
|
*/ |
|
|
|
public function actionProducerCode($id) |
|
|
|
{ |
|
|
|
$producer = Producer::findOne($id); |
|
|
|
|
|
|
|
if (!$producer) { |
|
|
|
throw new \yii\web\HttpException(404, 'Producteur introuvable'); |
|
|
|
} |
|
|
|
|
|
|
|
$producerCodeForm = new ProducerCodeForm; |
|
|
|
$producerCodeForm->id_producer = $id; |
|
|
|
|
|
|
|
if ($producerCodeForm->load(Yii::$app->request->post()) && $producerCodeForm->validate()) { |
|
|
|
Producer::addUser(User::getCurrentId(), $id); |
|
|
|
$this->redirect(Yii::$app->urlManagerProducer->createAbsoluteUrl(['site/index', 'slug_producer' => $producer->slug])); |
|
|
|
return $this->render('producer_code', [ |
|
|
|
'producer' => $producer, |
|
|
|
'producerCodeForm' => $producerCodeForm, |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Affiche la page de connexion / inscription pour accéder notamment au |
|
|
|
* formulaire de commande des producteurs. |
|
|
|
* |
|
|
|
* @param integer $id |
|
|
|
* @return mixed |
|
|
|
*/ |
|
|
|
public function actionProducer($id) |
|
|
|
{ |
|
|
|
$loginForm = new LoginForm(); |
|
|
|
$signupForm = new SignupForm(); |
|
|
|
|
|
|
|
$producer = Producer::searchOne([ |
|
|
|
'id' => $id |
|
|
|
]); |
|
|
|
|
|
|
|
$loginForm->id_producer = $id; |
|
|
|
$signupForm->id_producer = $id; |
|
|
|
$signupForm->option_user_producer = 'user'; |
|
|
|
|
|
|
|
$returnUrl = Yii::$app->request->get('returnUrl', Yii::$app->urlManagerProducer->createAbsoluteUrl(['site/index', 'slug_producer' => $producer->slug])); |
|
|
|
|
|
|
|
if (Yii::$app->user->isGuest) { |
|
|
|
if ($loginForm->load(Yii::$app->request->post()) && $loginForm->login()) { |
|
|
|
if (!strlen($producer->code)) { |
|
|
|
Producer::addUser(User::getCurrentId(), $id); |
|
|
|
} |
|
|
|
$this->redirect($returnUrl); |
|
|
|
} |
|
|
|
|
|
|
|
return $this->render('producer_code', [ |
|
|
|
'producer' => $producer, |
|
|
|
'producerCodeForm' => $producerCodeForm, |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Affiche la page de connexion / inscription pour accéder notamment au |
|
|
|
* formulaire de commande des producteirs. |
|
|
|
* |
|
|
|
* @param integer $id |
|
|
|
* @return mixed |
|
|
|
*/ |
|
|
|
public function actionProducer($id) |
|
|
|
{ |
|
|
|
$loginForm = new LoginForm(); |
|
|
|
$signupForm = new SignupForm(); |
|
|
|
|
|
|
|
$producer = Producer::searchOne([ |
|
|
|
'id' => $id |
|
|
|
]); |
|
|
|
|
|
|
|
$loginForm->id_producer = $id; |
|
|
|
$signupForm->id_producer = $id; |
|
|
|
$signupForm->option_user_producer = 'user'; |
|
|
|
|
|
|
|
$returnUrl = Yii::$app->request->get('returnUrl', Yii::$app->urlManagerProducer->createAbsoluteUrl(['site/index', 'slug_producer' => $producer->slug])); |
|
|
|
|
|
|
|
if (Yii::$app->user->isGuest) { |
|
|
|
if ($loginForm->load(Yii::$app->request->post()) && $loginForm->login()) { |
|
|
|
if (!strlen($producer->code)) { |
|
|
|
Producer::addUser(User::getCurrentId(), $id); |
|
|
|
} |
|
|
|
$this->redirect($returnUrl); |
|
|
|
} |
|
|
|
|
|
|
|
if ($signupForm->load(Yii::$app->request->post())) { |
|
|
|
if ($user = $signupForm->signup()) { |
|
|
|
if (Yii::$app->getUser()->login($user)) { |
|
|
|
$this->redirect($returnUrl); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
if ($signupForm->load(Yii::$app->request->post())) { |
|
|
|
if ($user = $signupForm->signup()) { |
|
|
|
if (Yii::$app->getUser()->login($user)) { |
|
|
|
$this->redirect($returnUrl); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return $this->render('producer', [ |
|
|
|
'loginForm' => $loginForm, |
|
|
|
'signupForm' => $signupForm, |
|
|
|
'producer' => $producer, |
|
|
|
]); |
|
|
|
} |
|
|
|
} else { |
|
|
|
$this->redirect($returnUrl); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Indique à l'utilisateur que l'espace d'un producteur est hors ligne |
|
|
|
* |
|
|
|
* @param integer $id |
|
|
|
* @return mixed |
|
|
|
*/ |
|
|
|
public function actionProducerOffline($id) |
|
|
|
{ |
|
|
|
$producer = Producer::searchOne([ |
|
|
|
'id' => $id |
|
|
|
]); |
|
|
|
|
|
|
|
return $this->render('producer_offline', [ |
|
|
|
'producer' => $producer, |
|
|
|
]); |
|
|
|
} |
|
|
|
return $this->render('producer', [ |
|
|
|
'loginForm' => $loginForm, |
|
|
|
'signupForm' => $signupForm, |
|
|
|
'producer' => $producer, |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Indique à l'utilisateur que l'espace d'un producteur est hors ligne |
|
|
|
* |
|
|
|
* @param integer $id |
|
|
|
* @return mixed |
|
|
|
*/ |
|
|
|
public function actionProducerOffline($id) |
|
|
|
{ |
|
|
|
$producerRepository = $this->getLogic()->getProducerContainer()->getRepository(); |
|
|
|
return $this->render('producer_offline', [ |
|
|
|
'producer' => $producerRepository->getOneById($id), |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
} |