From eeff6285ae833a540552a35a83b709a9675d93f2 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Thu, 31 Mar 2011 09:58:26 -0700 Subject: [PATCH] Make new answers work --- plugins/QnA/QnAPlugin.php | 11 +++++------ plugins/QnA/actions/qnanewanswer.php | 24 +++++++++++++----------- plugins/QnA/actions/qnashowanswer.php | 23 ++++++++++++++++++----- plugins/QnA/classes/QnA_Answer.php | 4 ++-- plugins/QnA/lib/qnaansweredform.php | 2 +- plugins/QnA/lib/qnaanswerform.php | 3 ++- 6 files changed, 41 insertions(+), 26 deletions(-) diff --git a/plugins/QnA/QnAPlugin.php b/plugins/QnA/QnAPlugin.php index 992641b18e..228b571a6e 100644 --- a/plugins/QnA/QnAPlugin.php +++ b/plugins/QnA/QnAPlugin.php @@ -120,9 +120,8 @@ class QnAPlugin extends MicroAppPlugin array('action' => 'qnanewquestion') ); $m->connect( - 'main/qna/newanswer/:id', - array('action' => 'qnanewanswer'), - array('id' => $UUIDregex) + 'main/qna/newanswer', + array('action' => 'qnanewanswer') ); $m->connect( 'question/vote/:id', @@ -304,13 +303,13 @@ class QnAPlugin extends MicroAppPlugin // TRANS: %s is the unpexpected object type. throw new Exception( sprintf( - _m('Unexpected type for QnA plugin: %s.'), + _m('Unexpected type for QnA plugin: %s.'), $notice->object_type ) ); } } - + function showNoticeQuestion($notice, $out) { $user = common_current_user(); @@ -321,7 +320,7 @@ class QnAPlugin extends MicroAppPlugin $out->elementStart('div', array('class' => 'entry-content question-content')); $question = QnA_Question::getByNotice($notice); - + if ($question) { if ($user) { $profile = $user->getProfile(); diff --git a/plugins/QnA/actions/qnanewanswer.php b/plugins/QnA/actions/qnanewanswer.php index 781ded36e6..d2558380e9 100644 --- a/plugins/QnA/actions/qnanewanswer.php +++ b/plugins/QnA/actions/qnanewanswer.php @@ -45,12 +45,12 @@ if (!defined('STATUSNET')) { */ class QnanewanswerAction extends Action { - protected $user = null; - protected $error = null; - protected $complete = null; + protected $user = null; + protected $error = null; + protected $complete = null; - protected $question = null; - protected $content = null; + protected $question = null; + protected $content = null; /** * Returns the title of the action @@ -91,19 +91,22 @@ class QnanewanswerAction extends Action $this->checkSessionToken(); } - $id = $this->trimmed('id'); + $id = substr($this->trimmed('id'), 9); + + common_debug("XXXXXXXXXXXXXXXXXX id = " . $id); + $this->question = QnA_Question::staticGet('id', $id); - + if (empty($this->question)) { // TRANS: Client exception thrown trying to respond to a non-existing question. throw new ClientException( - _m('Invalid or missing question.'), + _m('Invalid or missing question.'), 404 ); } $this->answerText = $this->trimmed('answer'); - + return true; } @@ -145,8 +148,8 @@ class QnanewanswerAction extends Action $this->showPage(); return; } - if ($this->boolean('ajax')) { + common_debug("ajaxy part"); header('Content-Type: text/xml;charset=utf-8'); $this->xw->startDocument('1.0', 'UTF-8'); $this->elementStart('html'); @@ -176,7 +179,6 @@ class QnanewanswerAction extends Action } $form = new QnaanswerForm($this->question, $this); - $form->show(); return; diff --git a/plugins/QnA/actions/qnashowanswer.php b/plugins/QnA/actions/qnashowanswer.php index d90b5c7ac6..5f3bc2eed9 100644 --- a/plugins/QnA/actions/qnashowanswer.php +++ b/plugins/QnA/actions/qnashowanswer.php @@ -69,6 +69,12 @@ class QnashowanswerAction extends ShownoticeAction throw new ClientException(_('No such answer.'), 404); } + $this->question = $this->answer->getQuestion(); + + if (empty($this->question)) { + throw new ClientException(_('No question for this answer.'), 404); + } + $this->notice = Notice::staticGet('uri', $this->answer->uri); if (empty($this->notice)) { @@ -105,9 +111,11 @@ class QnashowanswerAction extends ShownoticeAction { $question = $this->answer->getQuestion(); - return sprintf(_('%s\'s answer to "%s"'), - $this->user->nickname, - $question->title); + return sprintf( + _('%s\'s answer to "%s"'), + $this->user->nickname, + $question->title + ); } /** @@ -121,9 +129,14 @@ class QnashowanswerAction extends ShownoticeAction $this->elementStart('h1'); $this->element( 'a', - array('href' => $this->answer->url), - $this->answer->title + array('href' => $this->answer->uri), + $this->question->title ); $this->elementEnd('h1'); } + + function showContent() + { + $this->raw($this->answer->asHTML()); + } } diff --git a/plugins/QnA/classes/QnA_Answer.php b/plugins/QnA/classes/QnA_Answer.php index 349bbb0196..06e88354c9 100644 --- a/plugins/QnA/classes/QnA_Answer.php +++ b/plugins/QnA/classes/QnA_Answer.php @@ -167,11 +167,11 @@ class QnA_Answer extends Managed_DataObject */ function getQuestion() { - $question = self::staticGet('id', $this->question_id); + $question = QnA_Question::staticGet('id', $this->question_id); if (empty($question)) { throw new Exception("No question with ID {$this->question_id}"); } - return question; + return $question; } function getProfile() diff --git a/plugins/QnA/lib/qnaansweredform.php b/plugins/QnA/lib/qnaansweredform.php index a229e7f870..b1500140f3 100644 --- a/plugins/QnA/lib/qnaansweredform.php +++ b/plugins/QnA/lib/qnaansweredform.php @@ -60,7 +60,7 @@ class QnaansweredForm extends Form function __construct(QnA_Answer $answer, HTMLOutputter $out) { parent::__construct($out); - $this->question = $answer->getQuestion(); + $this->question = $answer->getQuestion(); $this->answer = $answer; } diff --git a/plugins/QnA/lib/qnaanswerform.php b/plugins/QnA/lib/qnaanswerform.php index f89f6c7889..8d78213d7c 100644 --- a/plugins/QnA/lib/qnaanswerform.php +++ b/plugins/QnA/lib/qnaanswerform.php @@ -89,7 +89,7 @@ class QnaanswerForm extends Form */ function action() { - return common_local_url('qnanewanswer', array('id' => $this->question->id)); + return common_local_url('qnanewanswer'); } /** @@ -104,6 +104,7 @@ class QnaanswerForm extends Form $id = "question-" . $question->id; $out->element('p', 'answer', $question->title); + $out->hidden('id', $id); $out->element('input', array('type' => 'text', 'name' => 'answer')); } -- 2.39.5