Beispiel #1
0
 /**
  * Mark an entry as "accepted" and unmark any previously accepted entry
  *
  * @return  void
  */
 public function acceptTask()
 {
     // Check for request forgeries
     Request::checkToken(['get', 'post']);
     // Incoming
     $qid = Request::getInt('qid', 0);
     $id = Request::getVar('id', array(0));
     if (!is_array($id)) {
         $id = array($id);
     }
     $publish = $this->getTask() == 'accept' ? 1 : 0;
     // Check for an ID
     if (count($id) < 1) {
         $action = $publish == 1 ? 'accept' : 'reject';
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_ANSWERS_ERROR_SELECT_ANSWER_TO', $action), 'error');
         return;
     } else {
         if (count($id) > 1) {
             App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_ANSWERS_ERROR_ONLY_ONE_ACCEPTED_ANSWER'), 'error');
             return;
         }
     }
     $ar = new Response($id[0]);
     if (!$ar->exists()) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false));
         return;
     }
     if ($publish == 1) {
         // Unmark all other entries
         $tbl = new Tables\Response($this->database);
         if ($results = $tbl->find('list', array('question_id' => $ar->get('question_id')))) {
             foreach ($results as $result) {
                 $result = new Response($result);
                 if ($result->get('state') != 0 && $result->get('state') != 1) {
                     continue;
                 }
                 $result->set('state', 0);
                 $result->store(false);
             }
         }
     }
     // Mark this entry
     $ar->set('state', $publish);
     if (!$ar->store(false)) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), $ar->getError(), 'error');
         return;
     }
     // Set message
     if ($publish == '1') {
         $message = Lang::txt('COM_ANSWERS_ANSWER_ACCEPTED');
     } else {
         if ($publish == '0') {
             $message = Lang::txt('COM_ANSWERS_ANSWER_REJECTED');
         }
     }
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), $message);
 }
Beispiel #2
0
 /**
  * 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->setError(Lang::txt('No answer ID provided.'));
         return false;
     }
     // Load the answer
     $answer = new Response($answer_id);
     if (!$answer->exists()) {
         $this->setError(Lang::txt('Answer not found.'));
         return false;
     }
     // Mark it at the chosen one
     $answer->set('state', 1);
     if (!$answer->store(true)) {
         $this->setError($answer->getError());
         return false;
     }
     // Mark the question as answered
     $this->set('state', 1);
     // If banking is enabled
     if ($this->config('banking')) {
         // Accepted answer is same person as question submitter?
         if ($this->get('created_by') == $answer->get('created_by')) {
             $BT = new Transaction($this->_db);
             $reward = $BT->getAmount('answers', 'hold', $this->get('id'));
             // Remove hold
             $BT->deleteRecords('answers', 'hold', $this->get('id'));
             // Make credit adjustment
             $BTL_Q = new Teller($this->_db, User::get('id'));
             $BTL_Q->credit_adjustment($BTL_Q->credit_summary() - $reward);
         } else {
             // Calculate and distribute earned points
             $AE = new Helpers\Economy($this->_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->store(true);
 }