/** * Set the state of one or more questions * * @return void */ public function stateTask() { // Check for request forgeries Request::checkToken(['get', 'post']); if (!User::authorise('core.edit.state', $this->_option)) { App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR')); } // Incoming $ids = Request::getVar('id', array()); $ids = !is_array($ids) ? array($ids) : $ids; $publish = $this->_task == 'close' ? 1 : 0; // Check for an ID if (count($ids) < 1) { $action = $publish == 1 ? Lang::txt('COM_ANSWERS_SET_STATE_CLOSE') : Lang::txt('COM_ANSWERS_SET_STATE_OPEN'); Notify::warning(Lang::txt('COM_ANSWERS_ERROR_SELECT_QUESTION_TO', $action)); return $this->cancelTask(); } $i = 0; foreach ($ids as $id) { // Update record(s) $aq = Question::oneOrFail(intval($id)); $aq->set('state', $publish); if (!$aq->save()) { Notify::error($aq->getError()); continue; } $i++; } // Set message if ($i) { if ($publish == 1) { $message = Lang::txt('COM_ANSWERS_QUESTIONS_CLOSED', $i); } else { if ($publish == 0) { $message = Lang::txt('COM_ANSWERS_QUESTIONS_OPENED', $i); } } Notify::success($message); } $this->cancelTask(); }
/** * Update a question * * @apiMethod PUT * @apiUri /answers/questions/{id} * @apiParameter { * "name": "id", * "description": "Question identifier", * "type": "integer", * "required": true, * "default": null * } * @apiParameter { * "name": "email", * "description": "Notify user of responses", * "type": "integer", * "required": false, * "default": null * } * @apiParameter { * "name": "anonymous", * "description": "List author as anonymous or not", * "type": "integer", * "required": false, * "default": null * } * @apiParameter { * "name": "subject", * "description": "Short, one-line question", * "type": "string", * "required": false, * "default": null * } * @apiParameter { * "name": "question", * "description": "Longer, detailed question", * "type": "string", * "required": false, * "default": null * } * @apiParameter { * "name": "created", * "description": "Created timestamp (YYYY-MM-DD HH:mm:ss)", * "type": "string", * "required": false, * "default": null * } * @apiParameter { * "name": "crated_by", * "description": "User ID of entry creator", * "type": "integer", * "required": false, * "default": null * } * @apiParameter { * "name": "state", * "description": "Published state (0 = unpublished, 1 = published)", * "type": "integer", * "required": false, * "default": null * } * @apiParameter { * "name": "reward", * "description": "Reward points", * "type": "integer", * "required": false, * "default": null * } * @apiParameter { * "name": "tags", * "description": "Comma-separated list of tags", * "type": "string", * "required": false, * "default": null * } * @return void */ public function updateTask() { $this->requiresAuthentication(); $fields = array('id' => Request::getInt('id', 0, 'post'), 'email' => Request::getInt('email', null), 'anonymous' => Request::getInt('anonymous', null), 'subject' => Request::getVar('subject', null, '', 'none', 2), 'question' => Request::getVar('question', null, '', 'none', 2), 'created' => Request::getVar('created', null), 'created_by' => Request::getInt('created_by', null), 'state' => Request::getInt('state', null), 'reward' => Request::getInt('reward', null), 'tags' => Request::getVar('tags', null)); $row = Question::oneOrFail($fields['id']); if (!$row->get('id')) { throw new Exception(Lang::txt('COM_ANSWERS_ERROR_MISSING_RECORD'), 404); } if (!$row->set($fields)) { throw new Exception(Lang::txt('COM_ANSWERS_ERROR_BINDING_DATA'), 422); } $row->set('email', isset($fields['email']) ? 1 : 0); $row->set('anonymous', isset($fields['anonymous']) ? 1 : 0); if (!$row->save()) { throw new Exception(Lang::txt('COM_ANSWERS_ERROR_SAVING_DATA'), 500); } if (isset($fields['tags'])) { if (!$row->tag($fields['tags'], User::get('id'))) { throw new Exception(Lang::txt('COM_ANSWERS_ERROR_SAVING_TAGS'), 500); } } $this->send($row->toObject()); }
/** * Set the state of one or more questions * * @return void */ public function stateTask() { // Check for request forgeries Request::checkToken(['get', 'post']); // Incoming $ids = Request::getVar('id', array()); $ids = !is_array($ids) ? array($ids) : $ids; $publish = $this->_task == 'close' ? 1 : 0; // Check for an ID if (count($ids) < 1) { $action = $publish == 1 ? Lang::txt('COM_ANSWERS_SET_STATE_CLOSE') : Lang::txt('COM_ANSWERS_SET_STATE_OPEN'); App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_ANSWERS_ERROR_SELECT_QUESTION_TO', $action), 'error'); return; } foreach ($ids as $id) { // Update record(s) $aq = Question::oneOrFail(intval($id)); $aq->set('state', $publish); /*if ($publish == 1) { $aq->adjustCredits(); }*/ if (!$aq->save()) { Notify::error($aq->getError()); } } // Set message if ($publish == 1) { $message = Lang::txt('COM_ANSWERS_QUESTIONS_CLOSED', count($ids)); } else { if ($publish == 0) { $message = Lang::txt('COM_ANSWERS_QUESTIONS_OPENED', count($ids)); } } App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), $message); }
/** * 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 ''; }
/** * Displays a question response for editing * * @param object $row * @return void */ public function editTask($row = null) { Request::setVar('hidemainmenu', 1); if (!is_object($row)) { $id = Request::getVar('id', array(0)); $id = is_array($id) && !empty($id) ? $id[0] : $id; $row = Response::oneOrNew($id); } $qid = Request::getInt('qid', 0); $qid = $qid ?: $row->get('question_id'); $question = Question::oneOrFail($qid); // Output the HTML $this->view->set('question', $question)->set('row', $row)->setLayout('edit')->display(); }
/** * Displays a question response for editing * * @param object $row * @return void */ public function editTask($row = null) { if (!User::authorise('core.edit', $this->_option) && !User::authorise('core.create', $this->_option)) { App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR')); } Request::setVar('hidemainmenu', 1); if (!is_object($row)) { $id = Request::getVar('id', array(0)); $id = is_array($id) && !empty($id) ? $id[0] : $id; $row = Response::oneOrNew($id); } $qid = Request::getInt('qid', 0); $qid = $qid ?: $row->get('question_id'); $question = Question::oneOrFail($qid); // Output the HTML $this->view->set('question', $question)->set('row', $row)->setLayout('edit')->display(); }
/** * 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()); } // 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()), $this->getError() ? $this->getError() : Lang::txt('COM_ANSWERS_NOTICE_QUESTION_CLOSED'), $this->getError() ? 'error' : 'success'); }