/** * Mark an answer as accepted * * @return void */ public function acceptTask() { // Login required if (User::isGuest()) { $this->setError(Lang::txt('COM_ANSWERS_PLEASE_LOGIN')); return $this->loginTask(); } // Incoming $id = Request::getInt('id', 0); $rid = Request::getInt('rid', 0); $question = Question::oneOrFail($id); // verify the orignial poster is the only one accepting the answer if ($question->get('created_by') != User::get('id')) { App::redirect(Route::url($question->link()), Lang::txt('COM_ANSWERS_ERROR_MUST_BE_ASKER'), 'error'); } // Check changes if (!$question->accept($rid)) { $this->setError($question->getError()); } // Log the activity if (!$this->getError()) { $answer = Response::oneOrFail($rid); $recipients = array($answer->get('created_by')); if ($answer->get('created_by') != $question->get('created_by')) { $recipients[] = $question->get('created_by'); } Event::trigger('system.logActivity', ['activity' => ['action' => 'accepted', 'scope' => 'question.answer', 'scope_id' => $rid, 'description' => Lang::txt('COM_ANSWERS_ACTIVITY_ANSWER_ACCEPTED', $rid, '<a href="' . Route::url($question->link() . '#a' . $rid) . '">' . $question->get('subject') . '</a>'), 'details' => array('title' => $question->get('title'), 'question_id' => $question->get('id'), 'url' => $question->link())], 'recipients' => $recipients]); } // Redirect to the question App::redirect(Route::url($question->link()), $this->getError() ? $this->getError() : Lang::txt('COM_ANSWERS_NOTICE_QUESTION_CLOSED'), $this->getError() ? 'error' : 'success'); }
/** * 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 ''; }
/** * Accept a response as the chosen answer * * @param integer $answer_id ID of response to be chosen * @return boolean False if error, True on success */ public function accept($answer_id = 0) { if (!$answer_id) { $this->addError(Lang::txt('No answer ID provided.')); return false; } // Load the answer $answer = Response::oneOrFail($answer_id); // Mark it at the chosen one $answer->set('state', 1); if (!$answer->save()) { $this->addError($answer->getError()); return false; } // Mark the question as answered $this->set('state', 1); // If banking is enabled if ($this->config('banking')) { $db = \App::get('db'); // Accepted answer is same person as question submitter? if ($this->get('created_by') == $answer->get('created_by')) { $reward = Transaction::getAmount('answers', 'hold', $this->get('id')); // Remove hold Transaction::deleteRecords('answers', 'hold', $this->get('id')); // Make credit adjustment $BTL_Q = new Teller(User::get('id')); $BTL_Q->credit_adjustment($BTL_Q->credit_summary() - $reward); } else { // Calculate and distribute earned points $AE = new Economy($db); $AE->distribute_points($this->get('id'), $this->get('created_by'), $answer->get('created_by'), 'closure'); } // Set the reward value $this->set('reward', 0); } // Save changes return $this->save(); }
/** * Reset the vote count for an entry * * @return void */ public function resetTask() { // Check for request forgeries Request::checkToken(); // Incoming $answer = Request::getVar('answer', array()); // Reset some values $model = Response::oneOrFail(intval($answer['id'])); if (!$model->reset()) { Notify::error($ar->getError()); } else { Notify::success(Lang::txt('COM_ANSWERS_VOTE_LOG_RESET')); } // Redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false)); }
/** * Reset the vote count for an entry * * @return void */ public function resetTask() { // Check for request forgeries Request::checkToken(); if (!User::authorise('core.edit', $this->_option) && !User::authorise('core.edit.state', $this->_option)) { App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR')); } // Incoming $answer = Request::getVar('answer', array()); // Reset some values $model = Response::oneOrFail(intval($answer['id'])); if (!$model->reset()) { Notify::error($ar->getError()); } else { Notify::success(Lang::txt('COM_ANSWERS_VOTE_LOG_RESET')); } // Redirect $this->cancelTask(); }
/** * 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())); } }