/** * Execute the controller, load a form for the given comment. * * @return boolean True if controller finished execution. */ public function execute() { $cid = $this->input->get('cid', array(), 'array'); $id = $cid ? $cid[0] : $this->input->getInt('id'); $model = new MonitorModelComment(); if (!$model->canEdit(JFactory::getUser(), $id)) { throw new Exception(JText::_('JERROR_ALERTNOAUTHOR'), 403); } $model->setCommentId($id); $model->loadForm(); $view = new MonitorViewCommentHtml($model); $view->setLayout('edit'); echo $view->render(); return true; }
/** * Execute the controller, save the values from the form and redirect to comments view. * * @return boolean True if controller finished execution. */ public function execute() { $app = JFactory::getApplication(); $issue_id = $this->input->getInt('issue_id'); $id = $this->input->getInt('id'); $model = new MonitorModelComment($app); $user = JFactory::getUser(); if (!$model->canEdit($user, $id)) { throw new Exception(JText::_('JERROR_ALERTNOAUTHOR'), 403); } $result = $model->save($this->input); if ($result === false) { $url = 'index.php?option=com_monitor&task=comment.edit'; if ($id) { $url .= '&id=' . $id; } elseif ($issue_id) { $url .= '&issue_id=' . $issue_id; } $app->redirect(JRoute::_($url, false)); return false; } $app->enqueueMessage(JText::_('COM_MONITOR_COMMENT_SAVED')); $commentLink = JRoute::_('index.php?option=com_monitor&view=issue&id=' . $issue_id . '#comment-' . $result, false); if (!$id) { // Send notification mails for new comments. $modelSubscription = new MonitorModelSubscription(); $modelSubscription->notifyIssue($issue_id, $user, $commentLink); // Mark issue as unread. $modelNotification = new MonitorModelNotifications(); $modelNotification->markUnread($issue_id, $result); } if ($app->isAdmin()) { $app->redirect(JRoute::_('index.php?option=com_monitor&view=comments', false)); } else { $app->redirect($commentLink); } return true; }
/** * Execute the controller, load a form for the given comment. * * @return boolean True if controller finished execution. */ public function execute() { $model = new MonitorModelComment(); $id = $this->input->getInt('id'); // Get the params // TODO: may be removed when new MVC is implemented completely $app = JFactory::getApplication(); if ($app instanceof JApplicationSite) { $params = $app->getParams(); } // ACL: Check if user can create $user = JFactory::getUser(); if (!$model->canEdit($user, $id)) { if ($user->guest && isset($params) && $params->get('redirect_login', 1)) { $this->app->enqueueMessage(JText::_('JGLOBAL_YOU_MUST_LOGIN_FIRST'), 'error'); $this->app->redirect(JRoute::_('index.php?option=com_users&view=login&return=' . base64_encode(JUri::getInstance()->toString()), '403')); } else { throw new Exception(JText::_('JERROR_ALERTNOAUTHOR'), 403); } } if ($id != 0) { $model->setCommentId($id); } else { $issue_id = $this->input->getInt('issue_id'); if ($issue_id == 0) { $this->app->enqueueMessage(JText::_('COM_MONITOR_ERROR_INVALID_ID'), 'error'); return false; } $model->setIssueId($issue_id); } $model->loadForm(); $view = new MonitorViewCommentHtml($model); $view->setLayout('edit'); echo $view->render(); return true; }