]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
QnA
authorZach Copley <zach@status.net>
Tue, 5 Apr 2011 06:58:35 +0000 (23:58 -0700)
committerZach Copley <zach@status.net>
Tue, 5 Apr 2011 06:58:35 +0000 (23:58 -0700)
* Some bug fixes
* Better Question page

plugins/QnA/actions/qnashowquestion.php
plugins/QnA/classes/QnA_Answer.php
plugins/QnA/lib/qnanewanswerform.php
plugins/QnA/lib/qnashowanswerform.php

index d128eeec2fcdef171fc144db3dbcff3c11df8ba8..c30464bbf61aed2efb03f27f17892512910ebf1c 100644 (file)
@@ -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
+        );
     }
 
     /**
index c8dcd43162fd9d8c6c9ec6117ed03d811fa93500..d200c7b45a0fcc24b853e2594bdcf1e3ef8f229f 100644 (file)
@@ -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();
index a0f4cd4b2288fd8b73a1ee2fe764b535a44b5d63..2a81679ca3307cd02aa0cd1fbe6960db18994a25 100644 (file)
@@ -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');
     }
index 890224ed69178410bc085852e6d2a88660949e5b..665c40857f1c96bea3a47e89c31a6497062fe9cc 100644 (file)
@@ -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';
     }
 }