Beispiel #1
0
 /**
  * Release a reported item
  *
  * @param      string $refid    ID of the database table row
  * @param      string $parent   If the element has a parent element
  * @param      string $category Element type (determines table to look in)
  * @return     array
  */
 public function releaseReportedItem($refid, $parent, $category)
 {
     if (!$this->_canHandle($category)) {
         return null;
     }
     require_once PATH_CORE . DS . 'components' . DS . 'com_answers' . DS . 'models' . DS . 'question.php';
     $database = App::get('db');
     $state = 1;
     switch ($category) {
         case 'answer':
             $comment = \Components\Answers\Models\Response::oneOrFail($refid);
             $state = 0;
             break;
         case 'question':
             $comment = \Components\Answers\Models\Question::oneOrFail($refid);
             break;
         case 'answercomment':
             $comment = \Components\Answers\Models\Comment::oneOrFail($refid);
             break;
     }
     $comment->set('state', $state);
     $comment->save();
     return '';
 }
Beispiel #2
0
 /**
  * Vote for an item
  *
  * @return  void
  */
 public function voteTask()
 {
     $no_html = Request::getInt('no_html', 0);
     // Is the user logged in?
     if (User::isGuest()) {
         if (!$no_html) {
             $this->setError(Lang::txt('COM_ANSWERS_PLEASE_LOGIN_TO_VOTE'));
             $this->loginTask();
         }
         return;
     }
     // Incoming
     $id = Request::getInt('id', 0);
     $type = Request::getVar('category', '');
     $vote = Request::getVar('vote', '');
     $ip = Request::ip();
     // Check for reference ID
     if (!$id) {
         // cannot proceed
         if (!$no_html) {
             App::redirect(Route::url('index.php?option=' . $this->_option), Lang::txt('COM_ANSWERS_ERROR_ID_NOT_FOUND'), 'error');
         }
         return;
     }
     if ($type == 'question') {
         $row = Question::oneOrFail($id);
         $scope = 'question';
     } elseif ($type == 'response') {
         $row = Response::oneOrFail($id);
         $scope = 'question.answer';
     } elseif ($type == 'comment') {
         $row = Comment::oneOrFail($id);
         $scope = 'question.answer.comment';
     }
     // Can't vote for your own comment
     if ($row->get('created_by') == User::get('id')) {
         if (!$no_html) {
             App::redirect(Route::url($row->link()), Lang::txt('COM_ANSWERS_ERROR_CANNOT_VOTE_FOR_OWN'), 'warning');
         }
         return;
     }
     if (!$vote) {
         if (!$no_html) {
             App::redirect(Route::url($row->link()), Lang::txt('COM_ANSWERS_ERROR_VOTE_NOT_FOUND'), 'warning');
         }
         return;
     }
     if (!$row->vote($vote, User::get('id'), $ip)) {
         $this->setError($row->getError());
     }
     if (!$this->getError()) {
         // Log activity
         $recipients = array(User::get('id'));
         if ($row instanceof Question) {
             $question = $row;
             $txt = $row->get('subject');
         }
         if ($row instanceof Response) {
             $question = Question::oneOrFail($row->get('question_id'));
             $txt = Lang::txt('COM_ANSWERS_ACTIVITY_ANSWER_ON', $row->get('id'), $question->get('subject'));
         }
         if ($row instanceof Comment) {
             $question = Question::oneOrFail($row->get('question_id'));
             $txt = Lang::txt('COM_ANSWERS_ACTIVITY_COMMENT_ON', $row->get('id'), $question->get('subject'));
         }
         Event::trigger('system.logActivity', ['activity' => ['action' => 'voted', 'scope' => $scope, 'scope_id' => $id, 'description' => Lang::txt('COM_ANSWERS_ACTIVITY_VOTED_' . ($vote == 'yes' ? 'UP' : 'DOWN'), '<a href="' . Route::url($row->link()) . '">' . $txt . '</a>'), 'details' => array('title' => $question->get('title'), 'question_id' => $question->get('id'), 'url' => $question->link())], 'recipients' => $recipients]);
     }
     // update display
     if ($no_html) {
         $row->set('vote', $vote);
         $this->view->setError($this->getErrors())->set('item', $row)->set('vote', $row->ballot())->setLayout('_vote')->display();
     } else {
         App::redirect(Route::url($row->link()));
     }
 }
Beispiel #3
0
 /**
  * Vote for an item
  *
  * @return  void
  */
 public function voteTask()
 {
     $no_html = Request::getInt('no_html', 0);
     // Is the user logged in?
     if (User::isGuest()) {
         if (!$no_html) {
             $this->setError(Lang::txt('COM_ANSWERS_PLEASE_LOGIN_TO_VOTE'));
             $this->loginTask();
         }
         return;
     }
     // Incoming
     $id = Request::getInt('id', 0);
     $type = Request::getVar('category', '');
     $vote = Request::getVar('vote', '');
     $ip = Request::ip();
     // Check for reference ID
     if (!$id) {
         // cannot proceed
         if (!$no_html) {
             App::redirect(Route::url('index.php?option=' . $this->_option), Lang::txt('No ID provided.'), 'error');
         }
         return;
     }
     if ($type == 'question') {
         $row = Question::oneOrFail($id);
     } elseif ($type == 'response') {
         $row = Response::oneOrFail($id);
     } elseif ($type == 'comment') {
         $row = Comment::oneOrFail($id);
     }
     // Can't vote for your own comment
     if ($row->get('created_by') == User::get('id')) {
         if (!$no_html) {
             App::redirect(Route::url($row->link()), Lang::txt('Cannot vote for your own entries.'), 'warning');
         }
         return;
     }
     if (!$vote) {
         if (!$no_html) {
             App::redirect(Route::url($row->link()), Lang::txt('No vote provided.'), 'warning');
         }
         return;
     }
     if (!$row->vote($vote, User::get('id'), $ip)) {
         $this->setError($row->getError());
     }
     // update display
     if ($no_html) {
         $row->set('vote', $vote);
         $this->view->setError($this->getErrors())->set('item', $row)->set('vote', $row->ballot())->setLayout('_vote')->display();
     } else {
         App::redirect(Route::url($row->link()));
     }
 }