|
- <?php
-
-
-
- namespace frontend\controllers;
-
- use yii\helpers\Html;
- use yii\filters\VerbFilter;
- use yii\filters\AccessControl;
- use yii\web\NotFoundHttpException;
-
- class BookmarkController extends FrontendController
- {
-
-
- public function behaviors()
- {
- return [
- 'verbs' => [
- 'class' => VerbFilter::class,
- 'actions' => [
- ],
- ],
- 'access' => [
- 'class' => AccessControl::class,
- 'rules' => [
- [
- 'allow' => true,
- 'roles' => ['@'],
- ]
- ],
- ],
- ];
- }
-
- public function actionAdd(int $idProducer)
- {
- $userProducerModule = $this->getUserProducerModule();
- $producer = $this->findProducer($idProducer);
- $userCurrent = $this->getUserCurrent();
-
- $this->getLogic()->setProducerContext($producer);
- $userProducerModule->addProducerBookmark($userCurrent);
-
- $this->setFlash('success', 'Le producteur <strong>' . Html::encode($producer->name) . '</strong> vient d\'être ajouté à votre liste de producteurs.');
-
- return $this->redirectReferer();
- }
-
- public function actionRemove(int $idProducer)
- {
- $userProducerModule = $this->getUserProducerModule();
- $producer = $this->findProducer($idProducer);
- $userCurrent = $this->getUserCurrent();
-
- $this->getLogic()->setProducerContext($producer);
- $userProducerModule->removeProducerBookmark($userCurrent);
-
- $this->setFlash('success', 'Le producteur <strong>' . Html::encode($producer->name) . '</strong> vient d\'être supprimé de votre liste de producteurs.');
-
- return $this->redirectReferer();
- }
-
- public function findProducer(int $idProducer)
- {
- $producerModule = $this->getProducerModule();
- $producer = $producerModule->findOneProducerById($idProducer);
- if($producer) {
- return $producer;
- }
- else {
- throw new NotFoundHttpException('Producteur introuvable.');
- }
- }
- }
|