示例#1
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();
     $item = new Userideas\Item\Item($db);
     $item->load($this->table->item_id);
     $item->decreaseVote($this->table->votes);
 }
示例#2
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);
 }
示例#3
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;
 }
示例#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 = !empty($data['id']) ? (int) $data['id'] : 0;
     $userId = !empty($data['user_id']) ? (int) $data['user_id'] : 0;
     // Save vote
     $item = new Userideas\Item\Item(JFactory::getDbo());
     $item->load($itemId);
     if (!$item->getId()) {
         return null;
     }
     $item->vote();
     // Add record to history table
     $history = new Userideas\Vote\Vote(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());
 }