/** * Display the view */ public function display($tpl = null) { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ // Initialise variables $this->state = $this->get('State'); $this->form = $this->get('Form'); $this->params = $this->state->get("params"); $user = JFactory::getUser(); $userId = $user->get("id"); $model = $this->getModel(); if (!$user->authorise('core.create', 'com_userideas')) { $returnUrl = UserIdeasHelperRoute::getFormRoute(); $app->enqueueMessage(JText::_("COM_USERIDEAS_ERROR_NO_PERMISSIONS_TO_DO_ACTION"), "notice"); $app->redirect(JRoute::_('index.php?option=com_users&view=login&return=' . base64_encode($returnUrl), false)); return; } $itemId = $this->state->get("form.id"); if (!empty($itemId) and !$model->canEditOwn($itemId, $userId)) { $returnUrl = UserIdeasHelperRoute::getFormRoute(); $app->enqueueMessage(JText::_("COM_USERIDEAS_ERROR_NO_PERMISSIONS_TO_DO_ACTION"), "notice"); $app->redirect(JRoute::_('index.php?option=com_users&view=login&return=' . base64_encode($returnUrl), false)); return; } $this->prepareDebugMode(); $this->prepareDocument(); 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 $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); }
<?php echo JText::_("COM_USERIDEAS_COMMENTS"); ?> <?php echo "( " . $commentsNumber . " )"; ?> </a> <?php } ?> <?php if (UserIdeasHelper::isValidOwner($this->userId, $item->user_id) and $this->canEdit) { ?> <a class="btn btn-small" href="<?php echo JRoute::_(UserIdeasHelperRoute::getFormRoute($item->id)); ?> " > <i class="icon-edit"></i> <?php echo JText::_("COM_USERIDEAS_EDIT"); ?> </a> <?php } ?> </div> </div> </div> <?php }
<?php if ($this->params->get('show_cat_description', 0)) { echo $this->category->getDescription(); } if ($this->params->get('show_cat_tags', 0) and count($this->tags) > 0) { $tagLayout = new JLayoutFile('joomla.content.tags'); echo $tagLayout->render($this->tags); echo '<br />'; } ?> <?php if ($this->params->get('items_display_button', 1)) { ?> <a href="<?php echo JRoute::_(UserIdeasHelperRoute::getFormRoute(0)); ?> " class="btn btn-default"> <span class="fa fa-plus"></span> <?php echo JText::_('COM_USERIDEAS_POST_ITEM'); ?> </a> <?php } ?> <?php foreach ($this->items as $item) { // Load parameters. $registry = new Joomla\Registry\Registry();