/** * 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(); $model->setProjectId($this->input->getInt('project_id')); $view = new MonitorViewIssuesList($model); echo $view->render(); }
/** * 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. * * @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() { $app = JFactory::getApplication(); $id = $this->input->getInt('id'); $model = new MonitorModelIssue($app); $user = JFactory::getUser(); if (!$model->canEdit($user, $id)) { throw new Exception(JText::_('JERROR_ALERTNOAUTHOR'), 403); } $issue_id = $model->save($this->input); if ($issue_id === false) { $url = 'index.php?option=com_monitor&task=issue.edit'; if ($id) { $url .= '&id=' . $id; } $app->redirect(JRoute::_($url, false)); return false; } $app->enqueueMessage(\JText::_('COM_MONITOR_ISSUE_SAVED')); if (!$id) { // Send notification mails for new issues. $project_id = $this->input->get('project_id'); $modelSubscription = new MonitorModelSubscription(); $modelSubscription->notifyProject($project_id, $user, $issue_id); // Mark issue as unread. $modelNotification = new MonitorModelNotifications(); $modelNotification->markUnread($issue_id); } if ($app->isAdmin()) { $app->redirect(JRoute::_('index.php?option=com_monitor&view=issues', false)); } else { $app->redirect(JRoute::_('index.php?option=com_monitor&view=issue&id=' . $issue_id, false)); } return true; }
/** * Method to render the view. * * @return string The rendered view. * * @since 12.1 * @throws RuntimeException */ public function render() { $this->prefix = 'issue'; $this->items = $this->model->getIssues(); $this->setLayout('default'); $this->addToolbar(); return parent::render(); }
/** * 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() { if (!JFactory::getUser()->authorise('issue.delete', 'com_monitor')) { throw new Exception(JText::_('JERROR_ALERTNOAUTHOR'), 403); } $app = JFactory::getApplication(); $model = new MonitorModelIssue($app); $model->delete($app->input->get('cid', array(), 'array')); $app->enqueueMessage(JText::_('COM_MONITOR_ISSUE_DELETED')); $app->redirect(JRoute::_('index.php?option=com_monitor&view=issues', false)); return true; }
/** * Method to get the field input markup. * * @return string The field input markup. * * @since 11.1 */ protected function getOptions() { $options = array(); JLoader::register('MonitorModelAbstract', JPATH_ROOT . '/administrator/components/com_monitor/model/abstract.php'); JLoader::register('MonitorModelIssue', JPATH_ROOT . '/administrator/components/com_monitor/model/issue.php'); $model = new MonitorModelIssue(null, false); $issues = $model->getIssues(); foreach ($issues as $issue) { $options[] = JHtml::_('select.option', $issue->id, $issue->title); } $options = array_merge(parent::getOptions(), $options); return $options; }
/** * 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; }
/** * Method to render the view. * * @return string The rendered view. * * @throws RuntimeException */ public function render() { $this->item = $this->model->getIssue(); $user = JFactory::getUser(); if ($this->item) { if (!in_array($this->item->access, $user->getAuthorisedViewLevels())) { throw new Exception(JText::_('JERROR_ALERTNOAUTHOR'), 403); } $this->canEditIssue = $this->model->canEdit($user, $this->item->id); } if ($this->getLayout() == null) { $this->setLayout('edit'); } $this->form = $this->model->getForm(); // Attachments $this->attachments = $this->model->getAttachments(); $this->addToolbar(); return parent::render(); }
/** * Method to render the view. * * @return string The rendered view. * * @since 12.1 * @throws RuntimeException */ public function render() { $this->items = $this->model->getIssues(); $this->filterForm = $this->model->getFilterForm(); $this->defaultTitle = JText::_('COM_MONITOR_ISSUES'); $this->setLayout('default'); $projectId = $this->model->getProjectId(); if ($projectId !== null) { $this->buttons['new-issue'] = array('url' => 'index.php?option=com_monitor&task=issue.edit&project_id=' . $projectId, 'text' => 'COM_MONITOR_CREATE_ISSUE', 'title' => 'COM_MONITOR_CREATE_ISSUE', 'icon' => 'icon-new'); $user = JFactory::getUser(); if (!$user->guest) { $this->modelSubscription = new MonitorModelSubscription(); $this->modelNotifications = new MonitorModelNotifications(); if ($this->params->get('enable_notifications', 1)) { $subscribed = $this->modelSubscription->isSubscriberProject($projectId, $user->id); $task = $subscribed ? 'unsubscribe' : 'subscribe'; $this->buttons['subscribe'] = array('url' => 'index.php?option=com_monitor&task=project.' . $task . '&id=' . $projectId . '&return=' . base64_encode(JUri::getInstance()->toString()), 'text' => $subscribed ? 'COM_MONITOR_UNSUBSCRIBE_PROJECT' : 'COM_MONITOR_SUBSCRIBE_PROJECT', 'title' => $subscribed ? 'COM_MONITOR_UNSUBSCRIBE_PROJECT_DESC' : 'COM_MONITOR_SUBSCRIBE_PROJECT_DESC', 'icon' => $subscribed ? 'icon-star' : 'icon-star-empty'); } $this->buttons['all-read'] = array('url' => 'index.php?option=com_monitor&task=project.read&id=' . $projectId, 'text' => 'COM_MONITOR_PROJECT_MARK_ALL_READ', 'title' => 'COM_MONITOR_PROJECT_MARK_ALL_READ_DESC', 'icon' => 'icon-eye'); } } return parent::render(); }
/** * Event called after display of content. * * @param string $context The context of the content being passed to the plugin. * @param mixed &$item The item displayed. * @param mixed $params Additional parameters. * @param integer $page Optional page number. * * @return string Returned value from this event will be displayed after the content of the item. */ public function onContentAfterDisplay($context, &$item, $params, $page = 0) { $allowed_contexts = array('com_contact.contact'); if (!in_array($context, $allowed_contexts)) { return null; } // Check if the component is installed and enabled. if (!JComponentHelper::isEnabled('com_monitor')) { return null; } JLoader::register('MonitorHelper', JPATH_ROOT . '/administrator/components/com_monitor/helper/helper.php'); JLoader::register('MonitorModelAbstract', JPATH_ROOT . '/administrator/components/com_monitor/model/abstract.php'); JLoader::register('MonitorModelComment', JPATH_ROOT . '/administrator/components/com_monitor/model/comment.php'); JLoader::register('MonitorModelIssue', JPATH_ROOT . '/administrator/components/com_monitor/model/issue.php'); $modelIssue = new MonitorModelIssue(null, false); $modelComment = new MonitorModelComment(null, false); // Load language files from the component. $lang = JFactory::getLanguage(); $lang->load('com_monitor', JPATH_SITE . '/components/com_monitor'); $filters = array('author' => $item->user_id); $listIssues = array('fullordering' => 'i.created DESC', 'limit' => $this->params->get('limit_issues', 10)); $listComments = array('fullordering' => 'c.created DESC', 'limit' => $this->params->get('limit_comments', 10)); $comments = $modelComment->getComments($filters, $listComments); // Process the content plugins on comments. $dispatcher = JEventDispatcher::getInstance(); JPluginHelper::importPlugin('content'); if ($comments) { foreach ($comments as $comment) { $dispatcher->trigger('onContentPrepare', array('plg_monitorcontributions.comment', &$comment, &$this->params, 0)); } } $displayData = array('item' => $item); $displayData['issues'] = $modelIssue->getIssues($filters, $listIssues); $displayData['comments'] = $comments; $displayData['params'] = $this->params->merge(JComponentHelper::getParams('com_monitor')); return JLayoutHelper::render('contributions', $displayData, __DIR__ . '/layouts'); }
/** * Loads the default status from the database. * * @return mixed Object for the default status, if set; null, if no default status is set. */ public static function getDefaultStatus() { if (self::$defaultStatus) { return self::$defaultStatus; } $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('name, id, style, open')->from('#__monitor_status')->where('`is_default` = 1'); $db->setQuery($query); self::$defaultStatus = $db->loadObject(); return self::$defaultStatus; }
private function lookupQuery($query) { // Build the lookup array. if (!$this->lookup) { $this->makeLookup(); } if (!isset($query['view'])) { return null; } // View matches. if (isset($this->lookup[$query['view']])) { // More complex view. if (is_array($this->lookup[$query['view']])) { $key = isset($query['id']) ? $query['id'] : (isset($query['project_id']) ? $query['project_id'] : '_'); // Use "new" as layout for view=issue&project_id=* and view=comment&issue_id=* if ($query['layout'] === 'edit') { if ($query['view'] === 'issue' && isset($query['project_id']) || $query['view'] === 'comment' && isset($query['issue_id'])) { $query['layout'] = 'new'; } } // View and ID match. if (isset($this->lookup[$query['view']][$key])) { if (is_array($this->lookup[$query['view']][$key])) { if (isset($query['layout'])) { // View, ID and layout match. if (isset($this->lookup[$query['view']][$key][$query['layout']])) { return $this->lookup[$query['view']][$key][$query['layout']]; } elseif ($query['layout'] === 'default' && isset($this->lookup[$query['view']][$key]['edit'])) { return $this->lookup[$query['view']][$key]['edit']; } elseif ($query['layout'] === 'default' && isset($this->lookup[$query['view']][$key]['new'])) { return $this->lookup[$query['view']][$key]['new']; } } } else { return $this->lookup[$query['view']][$key]; } } } else { return $this->lookup[$query['view']]; } } // View doesn't match. // Menu: Project, URL: Issues for the same project. if ($query['view'] === 'issues' && isset($query['project_id'])) { if (isset($this->lookup['project']) && isset($this->lookup['project'][$query['project_id']])) { return $this->lookup['project'][$query['project_id']]; } } elseif ($query['view'] === 'issue') { if (isset($query['id'])) { $projectId = $this->modelIssue->getIssueProject($query['id']); if ($projectId) { // Found menu item for the same project. if (isset($this->lookup['project']) && isset($this->lookup['project'][$projectId])) { return $this->lookup['project'][$projectId]; } elseif (isset($this->lookup['issues']) && isset($this->lookup['issues'][$projectId])) { return $this->lookup['issues'][$projectId]; } } } } elseif ($query['view'] === 'project') { if (isset($this->lookup['projects'])) { return $this->lookup['projects']; } } return null; }
/** * Loads the form. * * @return void */ public function loadForm() { $this->form = $this->model->getForm(); }
/** * 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(); } }