/** * Execute the controller. * * @return boolean True if controller finished execution, false if the controller did not * finish execution. A controller might return false if some precondition for * the controller to run has not been satisfied. * * @since 12.1 * @throws LogicException * @throws RuntimeException */ public function execute() { $model = new MonitorModelIssue(); $id = $this->input->getInt('id'); $user = JFactory::getUser(); // Get the params // TODO: may be removed when new MVC is implemented completely $this->app = JFactory::getApplication(); if ($this->app instanceof JApplicationSite) { $params = $this->app->getParams(); } 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) { $model->setIssueId($id); } $model->loadForm(); $view = new MonitorViewIssueHtml($model); $view->setLayout('edit'); $view->loadForm(); echo $view->render(); return true; }
/** * Execute the controller, instantiate model and view and display the issue. * * @return boolean True if controller finished execution. */ public function execute() { $issueId = $this->input->getInt('id'); $user = JFactory::getUser(); $model = new MonitorModelIssue(); $model->setIssueId($issueId); $modelComment = new MonitorModelComment(); $modelSubscriptions = new MonitorModelSubscription(); $view = new MonitorViewIssueHtml($model, null, $modelComment, $modelSubscriptions); echo $view->render(); if (!$user->guest) { $modelNotifications = new MonitorModelNotifications(); $modelNotifications->markRead($issueId, $user->id); } }
/** * Execute the controller. * * @return boolean True if controller finished execution, false if the controller did not * finish execution. A controller might return false if some precondition for * the controller to run has not been satisfied. * * @since 12.1 * @throws LogicException * @throws RuntimeException */ public function execute() { $model = new MonitorModelIssue(); $cid = $this->input->get('cid', array(), 'array'); $id = $cid ? $cid[0] : $this->input->getInt('id'); if (!$model->canEdit(JFactory::getUser(), $id)) { throw new Exception(JText::_('JERROR_ALERTNOAUTHOR'), 403); } $model->setIssueId($id); $model->loadForm(); $view = new MonitorViewIssueHtml($model); $view->setLayout('edit'); echo $view->render(); return true; }
/** * Notifies all users who have subscribed to the project. * * @param int $projectId ID of the project. * @param JUser $author The user who created a new issue. * @param int $issueId Direct link to the newly created issue. * * @return null */ public function notifyProject($projectId, $author, $issueId) { // Get subscribing users. $query = $this->db->getQuery(true); $query->select('u.email, u.name, u.username')->from('#__monitor_subscriptions_projects AS s')->leftJoin('#__users AS u ON s.user_id = u.id')->where('s.item_id = ' . $projectId)->where('s.user_id != ' . $author->get('id')); $users = $this->db->setQuery($query)->loadObjectList(); // Set values that are common for every notification mail. $authorName = $author->get('name', $author->get('username')); $issueLink = JRoute::_('index.php?option=com_monitor&view=issue&id=' . (int) $issueId, false); $unsubscribeLink = JRoute::_('index.php?option=com_monitor&task=project.unsubscribe&id=' . (int) $projectId, false); $baseUrl = JUri::getInstance()->toString(array('scheme', 'user', 'pass', 'host', 'port')); $modelIssue = new MonitorModelIssue($this->app, false); $modelIssue->setIssueId($issueId); $issue = $modelIssue->getIssue(); $modelProject = new MonitorModelProject($this->app, false); $modelProject->setProjectId($projectId); $project = $modelProject->getProject(); foreach ($users as $user) { $recipientName = empty($user->name) ? $user->username : $user->name; $subject = JText::sprintf('COM_MONITOR_MAIL_NOTIFICATION_PROJECT_HEADER', $project->name, $issue->title); $message = JText::sprintf('COM_MONITOR_MAIL_NOTIFICATION_PROJECT_TEXT', $recipientName, $authorName, $issue->title, $project->name, $baseUrl . $issueLink, $baseUrl . $unsubscribeLink); $mail = JFactory::getMailer(); $mail->isHtml(false); $mail->setSubject($subject); $mail->setBody($message); $mail->addRecipient($user->email, $recipientName); $mail->Send(); } }