/** * For initializing members of the class. * * @param array $argarray misc. arguments * * @return boolean true */ function prepare($argarray) { parent::prepare($argarray); if ($this->boolean('ajax')) { GNUsocial::setApi(true); } $this->user = common_current_user(); if (empty($this->user)) { throw new ClientException(_m("You must be logged in to answer to a question."), 403); } $id = substr($this->trimmed('id'), 7); $this->answer = QnA_Answer::getKV('id', $id); $this->question = $this->answer->getQuestion(); if (empty($this->answer) || empty($this->question)) { throw new ClientException(_m('Invalid or missing answer.'), 404); } $this->answerText = $this->trimmed('answer'); return true; }
/** * For initializing members of the class. * * @param array $argarray misc. arguments * * @return boolean true */ function prepare($argarray) { Action::prepare($argarray); $this->id = $this->trimmed('id'); $this->answer = QnA_Answer::getKV('id', $this->id); if (empty($this->answer)) { // TRANS: Client exception thrown when requesting a non-existing answer. throw new ClientException(_m('No such answer.'), 404); } $this->question = $this->answer->getQuestion(); if (empty($this->question)) { // TRANS: Client exception thrown when requesting an answer that has no connected question. throw new ClientException(_m('No question for this answer.'), 404); } $this->notice = Notice::getKV('uri', $this->answer->uri); if (empty($this->notice)) { // TRANS: Did we used to have it, and it got deleted? throw new ClientException(_m('No such answer.'), 404); } $this->user = User::getKV('id', $this->answer->profile_id); if (empty($this->user)) { // TRANS: Client exception thrown when requesting answer data for a non-existing user. throw new ClientException(_m('No such user.'), 404); } $this->profile = $this->user->getProfile(); if (empty($this->profile)) { // TRANS: Client exception thrown when requesting answer data for a user without a profile. throw new ServerException(_m('User without a profile.')); } try { $this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE); } catch (Exception $e) { $this->avatar = null; } return true; }
static function fromNotice($notice) { return QnA_Answer::getKV('uri', $notice->uri); }
/** * Output our CSS class for QnA notice list elements * * @param NoticeListItem $nli The item being shown * * @return boolean hook value */ function onStartOpenNoticeListItemElement(NoticeListItem $nli) { $type = $nli->notice->object_type; switch ($type) { case QnA_Question::OBJECT_TYPE: $id = empty($nli->repeat) ? $nli->notice->id : $nli->repeat->id; $class = 'h-entry notice question'; if ($nli->notice->scope != 0 && $nli->notice->scope != 1) { $class .= ' limited-scope'; } $question = QnA_Question::getKV('uri', $nli->notice->uri); if (!empty($question->closed)) { $class .= ' closed'; } $nli->out->elementStart('li', array('class' => $class, 'id' => 'notice-' . $id)); Event::handle('EndOpenNoticeListItemElement', array($nli)); return false; break; case QnA_Answer::OBJECT_TYPE: $id = empty($nli->repeat) ? $nli->notice->id : $nli->repeat->id; $cls = array('h-entry', 'notice', 'answer'); $answer = QnA_Answer::getKV('uri', $nli->notice->uri); if (!empty($answer) && !empty($answer->best)) { $cls[] = 'best'; } $nli->out->elementStart('li', array('class' => implode(' ', $cls), 'id' => 'notice-' . $id)); Event::handle('EndOpenNoticeListItemElement', array($nli)); return false; break; default: return true; } return true; }