public function display($tpl = null) { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ $itemId = $app->input->getUint("id"); $userId = JFactory::getUser()->get("id"); $model = $this->getModel(); // Initialise variables $this->item = $model->getItem($itemId, $userId); $this->state = $this->get('State'); $this->params = $this->state->get('params'); $notification = new Gamification\Notification\Notification(JFactory::getDbo()); $notification->load(array("id" => $itemId, "user_id" => $userId)); if ($notification->getId() and !$notification->isRead()) { $notification->updateStatus(Prism\Constants::READ); } $this->prepareDocument(); parent::display($tpl); }
/** * This method remove a notification. */ public function remove() { $itemId = $this->input->getUint("id"); $userId = JFactory::getUser()->get("id"); $response = new Prism\Response\Json(); $validatorOwner = new Gamification\Validator\Notification\Owner(JFactory::getDbo(), $itemId, $userId); if (!$validatorOwner->isValid()) { $response->setTitle(JText::_('COM_GAMIFICATION_FAIL'))->setText(JText::_('COM_GAMIFICATION_INVALID_NOTIFICATION'))->failure(); echo $response; JFactory::getApplication()->close(); } try { $notification = new Gamification\Notification\Notification(JFactory::getDbo()); $notification->load($itemId); $notification->remove(); } catch (Exception $e) { JLog::add($e->getMessage()); throw new Exception(JText::_('COM_GAMIFICATION_ERROR_SYSTEM')); } $response->setTitle(JText::_('COM_GAMIFICATION_SUCCESS'))->setText(JText::_('COM_GAMIFICATION_NOTIFICATION_REMOVED_SUCCESSFULLY'))->success(); echo $response; JFactory::getApplication()->close(); }