/** * List all comments. * * @return void */ public function viewAction($pageKey = null, $redirect = '') { $this->initialize(); $all = $this->comments->findAll($pageKey); $this->theme->setTitle("Kommentarer"); $this->views->add('comment/comments', ['comments' => $all, 'pageKey' => $pageKey, 'redirect' => 'comments', 'controller' => 'comments']); $form = new \Anax\HTMLForm\CFormCommentAdd($pageKey, $redirect); $form->setDI($this->di); $status = $form->check(); $this->views->add('comment/form', ['title' => "Lägg till en kommentar", 'content' => $form->getHTML()], 'main'); }
/** * List all comments. * * @return void */ public function viewAction($key = null, $type = null, $redirect = '') { $this->initialize(); $comments = $this->comments->findAll($key, $type); $user = $this->users; if ($this->di->request->getGet('edit-comment')) { $commentId = $this->di->request->getGet('edit-comment'); for ($i = 0; $i < count($comments); $i++) { if ($comments[$i]->id == $commentId) { $url = current(explode('?', $this->di->request->getCurrentUrl())); $redirect = $this->url->create($url); if ($user->isAuthenticated() && $user->isCurrentUser($comments[$i]->getProperties()['userId'] || $user->isAdmin())) { $value = $comments[$i]->content; $updateForm = new \Anax\HTMLForm\CFormCommentEdit($commentId, $value, $redirect); $updateForm->setDI($this->di); $status = $updateForm->check(); $comments[$i] = $updateForm->getHTML(); } else { $this->response->redirect($url); } } } } $form = null; if ($user->isAuthenticated() && $this->di->request->getGet('comment-reply') != null) { $commentId = $this->di->request->getGet('comment-reply'); $commentType = $this->di->request->getGet('type'); if ($key == $commentId && $type == $commentType) { $form = new \Anax\HTMLForm\CFormCommentAdd($commentId, $commentType, $redirect); $form->setDI($this->di); $status = $form->check(); $form = $form->getHTML(); } } $scores = $this->scores; $this->views->add('comment/comments', ['comments' => $comments, 'questionId' => $key, 'type' => $type, 'user' => $user, 'scores' => $scores, 'form' => $form], 'main'); }