[ 'class' => AccessControl::class, 'rules' => [ [ 'allow' => true, 'roles' => ['@'], 'matchCallback' => function ($rule, $action) { return $this->getUserModule() ->getAuthorizationChecker() ->isGrantedAsProducer($this->getUserCurrent()); } ] ], ], ]; } public function actionIndex() { $searchTicket = new TicketSearch(); $dataProviderTicketOpen = $searchTicket->search('producer', ['TicketSearch' => ['status' => Ticket::STATUS_OPEN]]); $dataProviderTicketClosed = $searchTicket->search('producer', ['TicketSearch' => ['status' => Ticket::STATUS_CLOSED]]); return $this->render('index', [ 'context' => 'producer', 'searchTicket' => $searchTicket, 'dataProviderTicketOpen' => $dataProviderTicketOpen, 'dataProviderTicketClosed' => $dataProviderTicketClosed ]); } public function actionCreate() { $userCurrent = $this->getUserCurrent(); $ticketModule = $this->getTicketModule(); $ticketMessageModule = $this->getTicketMessageModule(); $ticket = $ticketModule->instanciateTicket($this->getProducerCurrent(), $userCurrent); if ($ticket->load(\Yii::$app->request->post()) && $ticket->validate() && $ticketModule->create($ticket)) { $ticketMessageModule->createTicketMessage($ticket, $userCurrent, $ticket->message); $this->setFlash('success', 'Le ticket a bien été créé.'); return $this->redirect(['view', 'id' => $ticket->id]); } else { return $this->render('@backend/views/support/create', [ 'ticket' => $ticket ]); } } public function actionView(int $id) { $ticketModule = $this->getTicketModule(); $ticketMessageModule = $this->getTicketMessageModule(); $ticket = $this->findTicket($id); $ticketModule->viewTicket($ticket, $this->getUserCurrent()); $ticketMessage = $ticketMessageModule->instanciateTicketMessage($ticket, $this->getUserCurrent()); if ($ticketMessage->load(\Yii::$app->request->post()) && $ticketModule->createTicketMessage($ticketMessage)) { return $this->redirect(['view', 'id' => $ticket->id, '#' => 'bottom']); } return $this->render('@backend/views/support/view', [ 'ticket' => $ticket, 'ticketMessageResponse' => $ticketMessage ]); } public function actionClose(int $id) { $ticketModule = $this->getTicketModule(); $ticket = $this->findTicket($id); $ticketModule->closeTicket($ticket); $this->addFlash('success', "Le ticket ".Html::encode($ticket->subject)." a bien été fermé."); return $this->redirect(['index']); } public function actionOpen(int $id) { $ticketModule = $this->getTicketModule(); $ticket = $this->findTicket($id); $ticketModule->openTicket($ticket); $this->addFlash('success', "Le ticket a bien été ouvert."); return $this->redirect(['index']); } public function findTicket(int $id) { $ticketModule = $this->getTicketModule(); $ticket = $ticketModule->findOneTicketById($id); if ($ticket && $ticketModule->hasTicketAccess($ticket, $this->getUserCurrent())) { return $ticket; } else { throw new NotFoundHttpException("Le ticket est introuvable."); } } }