예제 #1
0
 public function save($key = null, $urlVar = null)
 {
     // Check for request forgeries.
     JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
     $app = JFactory::getApplication();
     /** @var $app JApplicationSite */
     // Get the data from the form POST
     $data = $app->input->post->get('jform', array(), 'array');
     $itemId = Joomla\Utilities\ArrayHelper::getValue($data, 'item_id');
     // Prepare response data
     $redirectOptions = array('view' => 'details', 'id' => $itemId);
     // Check for valid user 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;
     }
     $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);
         $item = new Userideas\Item\Item(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);
 }
예제 #2
0
 /**
  * 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 = (int) $this->params->get('post_comment_email_id', 0);
     // Check for enabled option for sending mail
     // when user sends a comment.
     if ($emailId > 0 and ($isNew and $row->id > 0)) {
         $item = new Userideas\Item\Item(JFactory::getDbo());
         $item->load($row->get('item_id'));
         $success = $this->sendMail($emailId, $item->getTitle(), $item->getSlug(), $item->getCategorySlug());
         if (!$success) {
             return false;
         }
     }
     return true;
 }