|
- <?php
-
-
-
- namespace producer\controllers;
-
- class SiteController extends ProducerBaseController
- {
-
-
-
- public function behaviors()
- {
- return [];
- }
-
- public function actions()
- {
- return [
- 'captcha' => [
- 'class' => 'yii\captcha\CaptchaAction',
- 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
- ],
- ];
- }
-
-
-
- public function actionError()
- {
- $exception = Yii::$app->errorHandler->exception;
-
- if ($exception !== null) {
- if($exception->getMessage() == 'Producteur introuvable') {
- Yii::$app->getResponse()->redirect(Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/error', 'producer_not_found' => true]))->send();
- return;
- }
- else {
- return $this->render('error', ['exception' => $exception]);
- }
- }
- }
-
-
-
- public function actionIndex()
- {
-
- $dataProviderPointsSale = new ActiveDataProvider([
- 'query' => PointSale::find()
- ->where([
- 'id_producer' => $this->getProducer()->id,
- ]),
- 'pagination' => [
- 'pageSize' => 50,
- ],
- 'sort' => false,
- ]);
-
-
- $dataProviderProducts = new ActiveDataProvider([
- 'query' => Product::find()
- ->andWhere([
- 'id_producer' => $this->getProducer()->id,
- 'active' => true
- ])
- ->orderBy('order ASC'),
- 'pagination' => [
- 'pageSize' => 50,
- ],
- 'sort' => false,
- ]);
-
- return $this->render('index',[
- 'dataProviderPointsSale' => $dataProviderPointsSale,
- 'dataProviderProducts' => $dataProviderProducts
- ]) ;
- }
-
-
-
- public function actionContact()
- {
-
- $model = new ContactForm();
- $producer = $this->getProducer() ;
-
- if ($model->load(Yii::$app->request->post()) && $model->validate()) {
- if (is_array($producer->contact) && $model->sendEmail($producer->contact[0]->email)) {
- Yii::$app->session->setFlash('success', 'Votre message a bien été envoyé.');
- }
- else {
- Yii::$app->session->setFlash('error', 'Il y a eu une erreur lors de l\'envoi de votre message.');
- }
- return $this->refresh();
- }
- else {
- return $this->render('contact', [
- 'model' => $model,
- ]);
- }
- }
-
-
-
- public function actionBookmarks($action)
- {
- $producer = $this->getProducer() ;
- $userProducer = UserProducer::find()
- ->where([
- 'id_user' => User::getCurrentId(),
- 'id_producer' => $producer->id
- ])
- ->one() ;
-
- if(!$userProducer) {
- $userProducer = Producer::addUser(User::getCurrentId(), $producer->id) ;
- }
-
- if($userProducer) {
- if($action == 'add') {
- $userProducer->bookmark = 1 ;
- Yii::$app->session->setFlash('success','Le producteur <strong>'.Html::encode($producer->name).'</strong> vient d\'être ajouté à vos favoris.') ;
- }
- else {
- $userProducer->bookmark = 0 ;
- Yii::$app->session->setFlash('success','Le producteur <strong>'.Html::encode($producer->name).'</strong> vient d\'être supprimé de vos favoris.') ;
- }
- $userProducer->save() ;
- }
-
- $this->redirect(['site/index']) ;
- }
- }
-
- ?>
|