+ $question = QnA_Question::getKV('id', $this->question_id);
+ if (empty($question)) {
+ // TRANS: Exception thown when getting a question with a non-existing ID.
+ // TRANS: %s is the non-existing question ID.
+ throw new Exception(sprintf(_m('No question with ID %s'),$this->question_id));
+ }
+ return $question;
+ }
+
+ function getProfile()
+ {
+ $profile = Profile::getKV('id', $this->profile_id);
+ if (empty($profile)) {
+ // TRANS: Exception thown when getting a profile with a non-existing ID.
+ // TRANS: %s is the non-existing profile ID.
+ throw new Exception(sprintf(_m('No profile with ID %s'),$this->profile_id));
+ }
+ return $profile;
+ }
+
+ function asHTML()
+ {
+ return self::toHTML(
+ $this->getProfile(),
+ $this->getQuestion(),
+ $this
+ );
+ }
+
+ function asString()
+ {
+ return self::toString(
+ $this->getProfile(),
+ $this->getQuestion(),
+ $this
+ );
+ }
+
+ static function toHTML(Profile $profile, $question, $answer)
+ {
+ $notice = $question->getNotice();
+
+ $out = new XMLStringer();
+
+ $cls = array('qna_answer');
+ if (!empty($answer->best)) {
+ $cls[] = 'best';
+ }
+
+ $out->elementStart('p', array('class' => implode(' ', $cls)));
+ $out->elementStart('span', 'answer-content');
+ $out->raw(common_render_text($answer->content));
+ $out->elementEnd('span');
+
+ if (!empty($answer->revisions)) {
+ $out->elementstart('span', 'answer-revisions');
+ $out->text(
+ htmlspecialchars(
+ // Notification of how often an answer was revised.
+ // TRANS: %s is the number of answer revisions.
+ sprintf(_m('%s revision','%s revisions',$answer->revisions), $answer->revisions)
+ )
+ );
+ $out->elementEnd('span');
+ }
+
+ $out->elementEnd('p');
+
+ return $out->getString();
+ }
+
+ static function toString($profile, $question, $answer)
+ {
+ // @todo FIXME: unused variable?
+ $notice = $question->getNotice();
+
+ return sprintf(
+ // TRANS: Text for a question that was answered.
+ // TRANS: %1$s is the user that answered, %2$s is the question title,
+ // TRANS: %2$s is the answer content.
+ _m('%1$s answered the question "%2$s": %3$s'),
+ htmlspecialchars($profile->getBestName()),
+ htmlspecialchars($question->title),
+ htmlspecialchars($answer->content)
+ );