public function display($tpl = null) { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ $this->option = JFactory::getApplication()->input->getCmd('option'); $this->state = $this->get('State'); $this->item = $this->get('Item'); $this->params = $this->state->get('params'); $this->category = new Userideas\Category\Category(JFactory::getDbo()); $this->category->load($this->item->catid); $user = JFactory::getUser(); $this->userId = $user->get('id'); // Set permission state. Is it possible to be edited items? $this->canEdit = $user->authorise('core.edit.own', 'com_userideas'); $this->commentsEnabled = $this->params->get('comments_enabled', 1); $this->canComment = $user->authorise('userideas.comment.create', 'com_userideas'); $this->canEditComment = $user->authorise('userideas.comment.edit.own', 'com_userideas'); // Get the model of the comments // that I will use to load all comments for this item. $modelComments = JModelLegacy::getInstance('Comments', 'UserIdeasModel'); $this->comments = $modelComments->getItems(); // Get the model of the comment $commentModelForm = JModelLegacy::getInstance('Comment', 'UserIdeasModel'); // Validate the owner of the comment, // If someone wants to edit it. $commentId = (int) $commentModelForm->getState('comment_id'); if ($commentId > 0) { $comment = $commentModelForm->getItem($commentId, $this->userId); if (!$comment) { $app->enqueueMessage(JText::_('COM_USERIDEAS_ERROR_INVALID_COMMENT'), 'error'); $app->redirect(JRoute::_(UserIdeasHelperRoute::getItemsRoute(), false)); return; } } // Get comment form $this->form = $commentModelForm->getForm(); // Prepare integration. Load avatars and profiles. $this->prepareIntegration($this->params); // Prepare the link to the details page. $this->item->link = UserIdeasHelperRoute::getDetailsRoute($this->item->slug, $this->item->catslug); $this->item->text = $this->item->description; $this->prepareDebugMode(); $this->prepareDocument(); // Events JPluginHelper::importPlugin('content'); $dispatcher = JEventDispatcher::getInstance(); $this->item->event = new stdClass(); $offset = 0; $dispatcher->trigger('onContentPrepare', array('com_userideas.details', &$this->item, &$this->params, $offset)); $results = $dispatcher->trigger('onContentBeforeDisplay', array('com_userideas.details', &$this->item, &$this->params, $offset)); $this->item->event->beforeDisplayContent = trim(implode("\n", $results)); $results = $dispatcher->trigger('onContentAfterDisplay', array('com_userideas.details', &$this->item, &$this->params, $offset)); $this->item->event->onContentAfterDisplay = trim(implode("\n", $results)); $this->item->description = $this->item->text; unset($this->item->text); // Count hits $model = $this->getModel(); $model->hit($this->item->id); parent::display($tpl); }
/** * Display the view. */ public function display($tpl = null) { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ // Initialise variables $this->state = $this->get('State'); $this->item = $this->get('Item'); $this->params = $this->state->get("params"); jimport("userideas.category"); $this->category = new UserIdeasCategory(JFactory::getDbo()); $this->category->load($this->item->catid); $this->userId = JFactory::getUser()->get("id"); // Get the model of the comments // that I will use to load all comments for this item. $modelComments = JModelLegacy::getInstance("Comments", "UserIdeasModel"); $this->comments = $modelComments->getItems(); // Get the model of the comment $commentModelForm = JModelLegacy::getInstance("Comment", "UserIdeasModel"); // Validate the owner of the comment, // If someone wants to edit it. $commentId = $commentModelForm->getState("comment_id"); if (!empty($commentId)) { $comment = $commentModelForm->getItem($commentId, $this->userId); if (!$comment) { $app->enqueueMessage(JText::_("COM_USERIDEAS_ERROR_INVALID_COMMENT"), "error"); $app->redirect(JRoute::_(UserIdeasHelperRoute::getItemsRoute(), false)); return; } } // Get comment form $this->form = $commentModelForm->getForm(); // Prepare integration. Load avatars and profiles. $this->prepareIntegration($this->params); // Prepare the link to the details page. $this->item->link = UserIdeasHelperRoute::getDetailsRoute($this->item->slug, $this->item->catslug); $this->item->text = $this->item->description; $this->version = new UserIdeasVersion(); $this->prepareDebugMode(); $this->prepareDocument(); // Events JPluginHelper::importPlugin('content'); $dispatcher = JEventDispatcher::getInstance(); $this->item->event = new stdClass(); $offset = 0; $dispatcher->trigger('onContentPrepare', array('com_userideas.details', &$this->item, &$this->params, $offset)); $results = $dispatcher->trigger('onContentBeforeDisplay', array('com_userideas.details', &$this->item, &$this->params, $offset)); $this->item->event->beforeDisplayContent = trim(implode("\n", $results)); $results = $dispatcher->trigger('onContentAfterDisplay', array('com_userideas.details', &$this->item, &$this->params, $offset)); $this->item->event->onContentAfterDisplay = trim(implode("\n", $results)); $this->item->description = $this->item->text; unset($this->item->text); // Count hits $model = $this->getModel(); $model->hit($this->item->id); parent::display($tpl); }
public function save($key = null, $urlVar = null) { // Check for request forgeries. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); // Get the data from the form POST $data = $this->input->post->get('jform', array(), 'array'); $itemId = JArrayHelper::getValue($data, "id", 0, "int"); $redirectOptions = array("view" => "form", "id" => $itemId); // Check for valid user $userId = JFactory::getUser()->id; if (!$userId) { $redirectOptions = array("force_direction" => "index.php?option=com_users&view=login"); $this->displayNotice(JText::_('COM_USERIDEAS_ERROR_NOT_LOG_IN'), $redirectOptions); return; } // Check for valid owner of the item if (!empty($itemId)) { jimport("userideas.validator.item.owner"); $itemValidator = new UserIdeasValidatorItemOwner(JFactory::getDbo(), $itemId, $userId); if (!$itemValidator->isValid($itemId, $userId)) { $redirectOptions = array("force_direction" => UserIdeasHelperRoute::getItemsRoute()); $this->displayNotice(JText::_('COM_USERIDEAS_ERROR_INVALID_ITEM'), $redirectOptions); return; } } $model = $this->getModel(); /** @var $model UserIdeasModelForm */ $form = $model->getForm($data, false); /** @var $form JForm */ if (!$form) { throw new Exception(JText::_("COM_USERIDEAS_ERROR_FORM_CANNOT_BE_LOADED"), 500); } // Test if the data is valid. $validData = $model->validate($form, $data); // Check for validation errors. if ($validData === false) { $this->displayNotice($form->getErrors(), $redirectOptions); return; } try { $validData["user_id"] = $userId; $itemId = $model->save($validData); $redirectOptions["id"] = $itemId; } catch (Exception $e) { JLog::add($e->getMessage()); throw new Exception(JText::_('COM_USERIDEAS_ERROR_SYSTEM')); } // Redirect to next page $this->displayMessage(JText::_('COM_USERIDEAS_ITEM_SAVED_SUCCESSFULLY'), $redirectOptions); }
public function save($key = null, $urlVar = null) { // Check for request forgeries. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); // Get the data from the form POST $data = $this->input->post->get('jform', array(), 'array'); $itemId = JArrayHelper::getValue($data, "id", 0, "int"); $redirectOptions = array("view" => "form", "id" => $itemId); // Check for valid user $user = JFactory::getUser(); $userId = $user->get("id"); if (!$this->allowSave($data)) { $redirectOptions = array("force_direction" => "index.php?option=com_users&view=login"); $this->displayNotice(JText::_('COM_USERIDEAS_ERROR_NO_PERMISSIONS_TO_DO_ACTION'), $redirectOptions); return; } // Get params $params = JComponentHelper::getParams("com_userideas"); $model = $this->getModel(); /** @var $model UserIdeasModelForm */ $form = $model->getForm($data, false); /** @var $form JForm */ if (!$form) { throw new Exception(JText::_("COM_USERIDEAS_ERROR_FORM_CANNOT_BE_LOADED"), 500); } // Test if the data is valid. $validData = $model->validate($form, $data); // Check for validation errors. if ($validData === false) { $this->displayNotice($form->getErrors(), $redirectOptions); return; } try { // Set the user ID. $validData["user_id"] = (int) $userId; $itemId = $model->save($validData); $redirectOptions["id"] = $itemId; } catch (Exception $e) { JLog::add($e->getMessage()); throw new Exception(JText::_('COM_USERIDEAS_ERROR_SYSTEM')); } $redirectOptions = array("force_direction" => (!$userId or strcmp("list", $params->get("redirect_when_post")) == 0) ? UserIdeasHelperRoute::getItemsRoute() : UserIdeasHelperRoute::getFormRoute($itemId)); // Redirect to next page $this->displayMessage(JText::_('COM_USERIDEAS_ITEM_SAVED_SUCCESSFULLY'), $redirectOptions); }
public static function status(UserIdeasStatus $status, $displayLink = true) { if (!$status->getId()) { return ""; } $styles = $status->getParam("style_class", ""); if (!empty($displayLink)) { $html = ' <a href="' . UserIdeasHelperRoute::getItemsRoute($status->getId()) . '" class="ui-status-label"> <span class="label' . $styles . '">' . htmlspecialchars($status->getName(), ENT_QUOTES, "utf-8") . '</span> </a>'; } else { $html = '<span class="label ui-status-label ' . $styles . '">' . htmlspecialchars($status->getName(), ENT_QUOTES, "utf-8") . '</span>'; } return $html; }