/**
  * 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;
 }
Esempio n. 2
0
 /**
  * Pre-processor for $table->delete($pk)
  *
  * @param   mixed $pk An optional primary key value to delete.  If not set the instance property value is used.
  *
  * @return  void
  *
  * @since   3.1.2
  * @throws  UnexpectedValueException
  */
 public function onAfterDelete($pk)
 {
     $db = $this->table->getDbo();
     jimport("userideas.item");
     $item = new UserIdeasItem($db);
     $item->load($this->table->item_id);
     $item->decreaseVote($this->table->votes);
 }
Esempio n. 3
0
 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);
 }
Esempio n. 4
0
 /**
  * Store user vote.
  *
  * @param string                   $context
  * @param array                    $data   This is a data about user and his vote
  * @param Joomla\Registry\Registry $params The parameters of the component
  *
  * @return  null|array
  */
 public function onVote($context, &$data, $params)
 {
     $app = JFactory::getApplication();
     /** @var $app JApplicationSite */
     if ($app->isAdmin()) {
         return;
     }
     $doc = JFactory::getDocument();
     /**  @var $doc JDocumentHtml */
     // Check document type
     $docType = $doc->getType();
     if (strcmp("raw", $docType) != 0) {
         return;
     }
     if (strcmp("com_userideas.vote", $context) != 0) {
         return;
     }
     $itemId = JArrayHelper::getValue($data, "id", 0, "int");
     $userId = JArrayHelper::getValue($data, "user_id", 0, "int");
     // Save vote
     jimport("userideas.item");
     $item = new UserIdeasItem(JFactory::getDbo());
     $item->load($itemId);
     if (!$item->getId()) {
         return null;
     }
     $item->vote();
     // Add record to history table
     jimport("userideas.vote");
     $history = new UserIdeasVote(JFactory::getDbo());
     if (!$userId) {
         $hash = $this->generateHash();
         $history->setHash($hash);
     } else {
         $history->setUserId($userId);
     }
     $history->setItemId($itemId)->setVotes(1)->store();
     // Prepare response data
     $data["response_data"] = array("user_votes" => 1, "votes" => $item->getVotes());
 }