Exemplo n.º 1
0
 /**
  * Delete one or more questions and associated data
  *
  * @return  void
  */
 public function removeTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $ids = Request::getVar('id', array());
     $ids = !is_array($ids) ? array($ids) : $ids;
     if (count($ids) <= 0) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false));
         return;
     }
     foreach ($ids as $id) {
         // Load the record
         $aq = new Question(intval($id));
         // Delete the question
         if (!$aq->delete()) {
             $this->setError($aq->getError());
         }
     }
     // Redirect
     if ($this->getError()) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), implode('<br />', $this->getErrors()), 'error');
         return;
     }
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_ANSWERS_QUESTION_DELETED'));
 }
Exemplo n.º 2
0
 /**
  * Delete a question
  *
  * @apiMethod DELETE
  * @apiUri    /answers/questions/{id}
  * @apiParameter {
  * 		"name":        "id",
  * 		"description": "Question identifier",
  * 		"type":        "integer",
  * 		"required":    true,
  * 		"default":     0
  * }
  * @return    void
  */
 public function deleteTask()
 {
     $this->requiresAuthentication();
     $ids = Request::getVar('id', array());
     $ids = !is_array($ids) ? array($ids) : $ids;
     if (count($ids) <= 0) {
         throw new Exception(Lang::txt('COM_ANSWERS_ERROR_MISSING_ID'), 500);
     }
     foreach ($ids as $id) {
         $row = new Question(intval($id));
         if (!$row->exists()) {
             throw new Exception(Lang::txt('COM_ANSWERS_ERROR_MISSING_RECORD'), 404);
         }
         if (!$row->delete()) {
             throw new Exception($row->getError(), 500);
         }
     }
     $this->send(null, 204);
 }