/** * Add a new answer * * @return void */ function newAnswer() { $profile = $this->user->getProfile(); try { $notice = QnA_Answer::saveNew($profile, $this->question, $this->answerText); } catch (ClientException $ce) { $this->error = $ce->getMessage(); $this->showForm($this->error); return; } if ($this->boolean('ajax')) { common_debug("ajaxy part"); $answer = $this->question->getAnswer($profile); header('Content-Type: text/xml;charset=utf-8'); $this->xw->startDocument('1.0', 'UTF-8'); $this->elementStart('html'); $this->elementStart('head'); // TRANS: Page title after sending an answer. $this->element('title', null, _m('Answers')); $this->elementEnd('head'); $this->elementStart('body'); $nli = new NoticeAnswerListItem($notice, $this, $this->question, $answer); $nli->show(); $this->elementEnd('body'); $this->elementEnd('html'); } else { common_debug("not ajax"); common_redirect($this->question->bestUrl(), 303); } }
/** * Given a parsed ActivityStreams activity, save it into a notice * and other data structures. * * @param Activity $activity * @param Profile $actor * @param array $options=array() * * @return Notice the resulting notice */ function saveNoticeFromActivity(Activity $activity, Profile $actor, array $options = array()) { if (count($activity->objects) != 1) { // TRANS: Exception thrown when there are too many activity objects. throw new Exception(_m('Too many activity objects.')); } $questionObj = $activity->objects[0]; if ($questionObj->type != QnA_Question::OBJECT_TYPE) { // TRANS: Exception thrown when an incorrect object type is encountered. throw new Exception(_m('Wrong type for object.')); } $notice = null; switch ($activity->verb) { case ActivityVerb::POST: $notice = QnA_Question::saveNew($actor, $questionObj->title, $questionObj->summary, $options); break; case Answer::ObjectType: $question = QnA_Question::getKV('uri', $questionObj->id); if (empty($question)) { // FIXME: save the question // TRANS: Exception thrown when answering a non-existing question. throw new Exception(_m('Answer to unknown question.')); } $notice = QnA_Answer::saveNew($actor, $question, $options); break; default: // TRANS: Exception thrown when an object type is encountered that cannot be handled. throw new Exception(_m('Unknown object type.')); } return $notice; }