From 0a95cdfa88af6d86ae455c9cf83a26c288439ebf Mon Sep 17 00:00:00 2001 From: chimo Date: Sun, 17 Aug 2014 13:37:43 -0400 Subject: [PATCH] Added adaptNoticeListItem and QnAListItem --- plugins/QnA/QnAPlugin.php | 79 +------------------- plugins/QnA/lib/qnalistitem.php | 126 ++++++++++++++++++++++++++++++++ 2 files changed, 129 insertions(+), 76 deletions(-) create mode 100644 plugins/QnA/lib/qnalistitem.php diff --git a/plugins/QnA/QnAPlugin.php b/plugins/QnA/QnAPlugin.php index ec1b16b872..77c4abf320 100644 --- a/plugins/QnA/QnAPlugin.php +++ b/plugins/QnA/QnAPlugin.php @@ -316,57 +316,6 @@ class QnAPlugin extends MicroAppPlugin return true; } - /** - * Custom HTML output for our notices - * - * @param Notice $notice - * @param HTMLOutputter $out - */ - function showNoticeContent(Notice $notice, $out) - { - switch ($notice->object_type) { - case QnA_Question::OBJECT_TYPE: - return $this->showNoticeQuestion($notice, $out); - case QnA_Answer::OBJECT_TYPE: - return $this->showNoticeAnswer($notice, $out); - default: - throw new Exception( - // TRANS: Exception thrown when performing an unexpected action on a question. - // TRANS: %s is the unpexpected object type. - sprintf(_m('Unexpected type for QnA plugin: %s.'), - $notice->object_type - ) - ); - } - } - - function showNoticeQuestion(Notice $notice, $out) - { - $user = common_current_user(); - - // @hack we want regular rendering, then just add stuff after that - $nli = new NoticeListItem($notice, $out); - $nli->showNotice(); - - $out->elementStart('div', array('class' => 'e-content question-description')); - - $question = QnA_Question::getByNotice($notice); - - if (!empty($question)) { - - $form = new QnashowquestionForm($out, $question); - $form->show(); - - } else { - // TRANS: Error message displayed when question data is not present. - $out->text(_m('Question data is missing.')); - } - $out->elementEnd('div'); - - // @fixme - $out->elementStart('div', array('class' => 'e-content')); - } - /** * Output the HTML for this kind of object in a list * @@ -385,7 +334,7 @@ class QnAPlugin extends MicroAppPlugin $out = $nli->out; $notice = $nli->notice; - $this->showNotice($notice, $out); + $nli->showNotice($notice, $out); $nli->showNoticeLink(); $nli->showNoticeSource(); @@ -430,30 +379,8 @@ class QnAPlugin extends MicroAppPlugin return false; } - function showNoticeAnswer(Notice $notice, $out) - { - $user = common_current_user(); - - $answer = QnA_Answer::getByNotice($notice); - $question = $answer->getQuestion(); - - $nli = new NoticeListItem($notice, $out); - $nli->showNotice(); - - $out->elementStart('div', array('class' => 'e-content answer-content')); - - if (!empty($answer)) { - $form = new QnashowanswerForm($out, $answer); - $form->show(); - } else { - // TRANS: Error message displayed when answer data is not present. - $out->text(_m('Answer data is missing.')); - } - - $out->elementEnd('div'); - - // @todo FIXME - $out->elementStart('div', array('class' => 'e-content')); + function adaptNoticeListItem($nli) { + return new QnAListItem($nli); } static function shorten($content, $notice) diff --git a/plugins/QnA/lib/qnalistitem.php b/plugins/QnA/lib/qnalistitem.php new file mode 100644 index 0000000000..125c64fcdb --- /dev/null +++ b/plugins/QnA/lib/qnalistitem.php @@ -0,0 +1,126 @@ +. + * + * @category QnA + * @package StatusNet + * @author Evan Prodromou + * @copyright 2011 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 + * @link http://status.net/ + */ + +if (!defined('STATUSNET')) { + // This check helps protect against security problems; + // your code file can't be executed directly from the web. + exit(1); +} + +/** + * An adapter to show QnA in a nicer way + * + * @category QnA + * @package StatusNet + * @author Evan Prodromou + * @copyright 2011 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 + * @link http://status.net/ + */ + +class QnAListItem extends NoticeListItemAdapter +{ + /** + * Custom HTML output for our notices + * + * @param Notice $notice + * @param HTMLOutputter $out + */ + function showNotice(Notice $notice, $out) + { + switch ($notice->object_type) { + case QnA_Question::OBJECT_TYPE: + return $this->showNoticeQuestion($notice, $out); + case QnA_Answer::OBJECT_TYPE: + return $this->showNoticeAnswer($notice, $out); + default: + throw new Exception( + // TRANS: Exception thrown when performing an unexpected action on a question. + // TRANS: %s is the unpexpected object type. + sprintf(_m('Unexpected type for QnA plugin: %s.'), + $notice->object_type + ) + ); + } + } + + function showNoticeQuestion(Notice $notice, $out) + { + $user = common_current_user(); + + // @hack we want regular rendering, then just add stuff after that + $nli = new NoticeListItem($notice, $out); + $nli->showNotice(); + + $out->elementStart('div', array('class' => 'e-content question-description')); + + $question = QnA_Question::getByNotice($notice); + + if (!empty($question)) { + + $form = new QnashowquestionForm($out, $question); + $form->show(); + + } else { + // TRANS: Error message displayed when question data is not present. + $out->text(_m('Question data is missing.')); + } + $out->elementEnd('div'); + + // @fixme + $out->elementStart('div', array('class' => 'e-content')); + } + + function showNoticeAnswer(Notice $notice, $out) + { + $user = common_current_user(); + + $answer = QnA_Answer::getByNotice($notice); + $question = $answer->getQuestion(); + + $nli = new NoticeListItem($notice, $out); + $nli->showNotice(); + + $out->elementStart('div', array('class' => 'e-content answer-content')); + + if (!empty($answer)) { + $form = new QnashowanswerForm($out, $answer); + $form->show(); + } else { + // TRANS: Error message displayed when answer data is not present. + $out->text(_m('Answer data is missing.')); + } + + $out->elementEnd('div'); + + // @todo FIXME + $out->elementStart('div', array('class' => 'e-content')); + } +} -- 2.39.5