/** * Display a list of questions * * @apiMethod GET * @apiUri /answers/questions/list * @apiParameter { * "name": "limit", * "description": "Number of result to return.", * "required": false, * "default": 25 * } * @apiParameter { * "name": "start", * "description": "Number of where to start returning results.", * "required": false, * "default": 0 * } * @apiParameter { * "name": "search", * "description": "A word or phrase to search for.", * "required": false, * "default": "" * } * @apiParameter { * "name": "sort", * "description": "Field to sort results by.", * "required": false, * "default": "created", * "allowedValues": "created, title, alias, id, publish_up, publish_down, state" * } * @apiParameter { * "name": "sort_Dir", * "description": "Direction to sort results by.", * "required": false, * "default": "desc", * "allowedValues": "asc, desc" * } * @return void */ public function listTask() { $database = \App::get('db'); $model = new \Components\Answers\Tables\Question($database); $filters = array('limit' => Request::getInt('limit', 25), 'start' => Request::getInt('limitstart', 0), 'search' => Request::getVar('search', ''), 'filterby' => Request::getword('filterby', ''), 'sortby' => Request::getWord('sort', 'date'), 'sort_Dir' => strtoupper(Request::getWord('sortDir', 'DESC'))); $response = new stdClass(); $response->questions = array(); $response->total = $model->getCount($filters); if ($response->total) { $base = rtrim(Request::base(), '/'); foreach ($model->getResults($filters) as $i => $q) { $question = new \Components\Answers\Models\Question($q); $obj = new stdClass(); $obj->id = $question->get('id'); $obj->subject = $question->subject(); $obj->quesion = $question->content(); $obj->state = $question->get('state'); $obj->url = str_replace('/api', '', $base . '/' . ltrim(Route::url($question->link()), '/')); $obj->responses = $question->comments('count'); $response->questions[] = $obj; } } $response->success = true; $this->send($response); }
/** * Store changes to this offering * * @param boolean $check Perform data validation check? * @return boolean False if error, True on success */ public function store($check = true) { $res = parent::store($check); // If marked as chosen answer if ($res && $this->get('state') == 1) { require_once __DIR__ . DS . 'question.php'; $aq = new Question($this->get('question_id')); if ($aq->exists() && $aq->get('state') != 1) { $aq->set('state', 1); //$aq->set('reward', 0); // This was giving out points twice for one closed question /* if ($aq->config('banking')) { // Calculate and distribute earned points $AE = new Economy($this->_db); $AE->distribute_points($this->get('question_id'), $aq->get('created_by'), $this->get('created_by'), 'closure'); // Call the plugin if ( !Event::trigger('xmessage.onTakeAction', array( 'answers_reply_submitted', array($aq->creator('id')), 'com_answers', $this->get('question_id') )) ) { $this->setError(Lang::txt('Failed to remove alert.')); } } */ if (!$aq->store()) { $this->setError($aq->getError()); return false; } } } return $res; }
/** * Mark an answer as accepted * * @return void */ public function acceptTask() { // Login required if (User::isGuest()) { $this->setError(Lang::txt('COM_ANSWERS_PLEASE_LOGIN')); $this->loginTask(); return; } // Incoming $id = Request::getInt('id', 0); $rid = Request::getInt('rid', 0); $question = new Question($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()); } // Call the plugin if (!Event::trigger('xmessage.onTakeAction', array('answers_reply_submitted', array(User::get('id')), $this->_option, $rid))) { $this->setError(Lang::txt('COM_ANSWERS_ACTION_FAILED')); } // Redirect to the question App::redirect(Route::url($question->link() . '¬e=10'), Lang::txt('COM_ANSWERS_NOTICE_QUESTION_CLOSED'), 'success'); }