/** * This method is executed when someone sends a comment. * * @param string $context * @param UserIdeasTableItem $row * @param boolean $isNew * * @return null|boolean */ public function onCommentAfterSave($context, $row, $isNew) { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ if ($app->isAdmin()) { return null; } if (strcmp("com_userideas.comment", $context) != 0) { return null; } $emailId = $this->params->get("post_comment_email_id", 0); // Check for enabled option for sending mail // when user sends a comment. if (!empty($emailId)) { if ($isNew and !empty($row->id)) { jimport("userideas.item"); $item = new UserIdeasItem(JFactory::getDbo()); $item->load($row->get("item_id")); $success = $this->sendMail($emailId, $item->getTitle(), $item->getSlug(), $item->getCategorySlug()); if (!$success) { return false; } } } return true; }
public function save($key = null, $urlVar = null) { // Check for request forgeries. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); // Check for valid user id $userId = JFactory::getUser()->get("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; } $app = JFactory::getApplication(); /** @var $app JApplicationSite */ // Get the data from the form POST $data = $app->input->post->get('jform', array(), 'array'); $itemId = JArrayHelper::getValue($data, "item_id"); // Prepare response data $redirectOptions = array("view" => "details", "id" => $itemId); $model = $this->getModel(); /** @var $model UserIdeasModelComment */ $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 { $model->save($validData); jimport("userideas.item"); $item = new UserIdeasItem(JFactory::getDbo()); $item->load($itemId); } catch (Exception $e) { JLog::add($e->getMessage()); throw new Exception(JText::_('COM_USERIDEAS_ERROR_SYSTEM')); } $redirectOptions = array("force_direction" => UserIdeasHelperRoute::getDetailsRoute($item->getSlug(), $item->getCategorySlug())); // Redirect to next page $this->displayMessage(JText::_("COM_USERIDEAS_COMMENT_SENT_SUCCESSFULLY"), $redirectOptions); }