/** * Add a new Question * * @return void */ function newQuestion() { if ($this->boolean('ajax')) { GNUsocial::setApi(true); } try { if (empty($this->title)) { // TRANS: Client exception thrown trying to create a question without a title. throw new ClientException(_m('Question must have a title.')); } // Notice options $options = array(); // Does the heavy-lifting for getting "To:" information ToSelector::fillOptions($this, $options); $saved = QnA_Question::saveNew($this->user->getProfile(), $this->title, $this->description, $options); } catch (ClientException $ce) { $this->error = $ce->getMessage(); $this->showPage(); return; } if ($this->boolean('ajax')) { $this->startHTML('text/xml;charset=utf-8'); $this->elementStart('head'); // TRANS: Page title after sending a notice. $this->element('title', null, _m('Question posted')); $this->elementEnd('head'); $this->elementStart('body'); $this->showNotice($saved); $this->elementEnd('body'); $this->endHTML(); } else { common_redirect($saved->getUrl(), 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; }