From 6c0bb0f35b7e457ea9ccdc2668b30df6e48cc267 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Mon, 4 Apr 2011 23:58:35 -0700 Subject: [PATCH] QnA * Some bug fixes * Better Question page --- plugins/QnA/actions/qnashowquestion.php | 50 +++++++++++++++++++++++-- plugins/QnA/classes/QnA_Answer.php | 5 +++ plugins/QnA/lib/qnanewanswerform.php | 9 +++-- plugins/QnA/lib/qnashowanswerform.php | 22 ++++++----- 4 files changed, 70 insertions(+), 16 deletions(-) diff --git a/plugins/QnA/actions/qnashowquestion.php b/plugins/QnA/actions/qnashowquestion.php index d128eeec2f..c30464bbf6 100644 --- a/plugins/QnA/actions/qnashowquestion.php +++ b/plugins/QnA/actions/qnashowquestion.php @@ -97,7 +97,49 @@ class QnashowquestionAction extends ShownoticeAction function showContent() { + $this->elementStart('div', 'qna-full-question'); $this->raw($this->question->asHTML()); + + $answer = $this->question->getAnswers(); + + $this->elementStart('div', 'qna-full-question-answers'); + + $answerIds = array(); + + // @fixme use a filtered stream! + + if (!empty($answer)) { + while ($answer->fetch()) { + $answerIds[] = $answer->getNotice()->id; + } + } + + if (count($answerIds) > 0) { + $notice = new Notice(); + $notice->query( + sprintf( + 'SELECT notice.* FROM notice WHERE notice.id IN (%s)', + implode(',', $answerIds) + ) + ); + + $nli = new NoticeList($notice, $this); + $nli->show(); + } + + $user = common_current_user(); + + if (!empty($user)) { + $profile = $user->getProfile(); + $answer = QnA_Question::getAnswer($profile); + if (empty($answer)) { + $form = new QnanewanswerForm($this, $this->question, false); + $form->show(); + } + } + + $this->elementEnd('div'); + $this->elementEnd('div'); } /** @@ -111,9 +153,11 @@ class QnashowquestionAction extends ShownoticeAction { // TRANS: Page title for a question. // TRANS: %1$s is the nickname of the user who asked the question, %2$s is the question. - return sprintf(_m('%1$s\'s question: %2$s'), - $this->user->nickname, - $this->question->title); + return sprintf( + _m('%1$s\'s question: %2$s'), + $this->user->nickname, + $this->question->title + ); } /** diff --git a/plugins/QnA/classes/QnA_Answer.php b/plugins/QnA/classes/QnA_Answer.php index c8dcd43162..d200c7b45a 100644 --- a/plugins/QnA/classes/QnA_Answer.php +++ b/plugins/QnA/classes/QnA_Answer.php @@ -155,6 +155,11 @@ class QnA_Answer extends Managed_DataObject return Notice::staticGet('uri', $this->uri); } + static function fromNotice($notice) + { + return QnA_Answer::staticGet('uri', $notice->uri); + } + function bestUrl() { return $this->getNotice()->bestUrl(); diff --git a/plugins/QnA/lib/qnanewanswerform.php b/plugins/QnA/lib/qnanewanswerform.php index a0f4cd4b22..2a81679ca3 100644 --- a/plugins/QnA/lib/qnanewanswerform.php +++ b/plugins/QnA/lib/qnanewanswerform.php @@ -47,6 +47,7 @@ if (!defined('STATUSNET')) { class QnanewanswerForm extends Form { protected $question; + protected $showQuestion; /** * Construct a new answer form @@ -56,10 +57,11 @@ class QnanewanswerForm extends Form * * @return void */ - function __construct(HTMLOutputter $out, QnA_Question $question) + function __construct(HTMLOutputter $out, QnA_Question $question, $showQuestion = true) { parent::__construct($out); $this->question = $question; + $this->showQuestion = $showQuestion; } /** @@ -103,9 +105,10 @@ class QnanewanswerForm extends Form $out = $this->out; $id = "question-" . $question->id; - $out->raw($this->question->asHTML()); + if ($this->showQuestion) { + $out->raw($this->question->asHTML()); + } - $out->element('p', 'answer', 'Your answer'); $out->hidden('id', $id); $out->textarea('answer', 'answer'); } diff --git a/plugins/QnA/lib/qnashowanswerform.php b/plugins/QnA/lib/qnashowanswerform.php index 890224ed69..665c40857f 100644 --- a/plugins/QnA/lib/qnashowanswerform.php +++ b/plugins/QnA/lib/qnashowanswerform.php @@ -46,14 +46,14 @@ require_once INSTALLDIR . '/lib/form.php'; class QnashowanswerForm extends Form { /** - * The answer to revise + * The answer to show */ - var $answer = null; + protected $answer = null; /** * The question this is an answer to */ - var $question = null; + protected $question = null; /** * Constructor @@ -76,7 +76,7 @@ class QnashowanswerForm extends Form */ function id() { - return 'revise-' . $this->answer->id; + return 'show-' . $this->answer->id; } /** @@ -109,8 +109,8 @@ class QnashowanswerForm extends Form */ function formLegend() { - // TRANS: Form legend for revising the answer. - $this->out->element('legend', null, _('Revise your answer')); + // TRANS: Form legend for showing the answer. + $this->out->element('legend', null, _('Answer')); } /** @@ -122,10 +122,12 @@ class QnashowanswerForm extends Form { $this->out->hidden( 'id', - 'revise-' . $this->answer->id + 'answer-' . $this->answer->id ); - - $this->out->raw($this->answer->asHTML()); + + + + // $this->out->raw($this->answer->asHTML()); } /** @@ -184,6 +186,6 @@ class QnashowanswerForm extends Form */ function formClass() { - return 'form_revise ajax'; + return 'form_show ajax'; } } -- 2.39.5