]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
QnA - Better display of questions and answers in streams
authorZach Copley <zach@status.net>
Sun, 3 Apr 2011 23:57:59 +0000 (16:57 -0700)
committerZach Copley <zach@status.net>
Sun, 3 Apr 2011 23:57:59 +0000 (16:57 -0700)
plugins/QnA/QnAPlugin.php
plugins/QnA/actions/qnanewanswer.php

index 5740054a5f4a06d66ef87a3520d7f3b24325aa86..e53d56928cd72d9c4f6c7d14bbc778323c7d22ae 100644 (file)
@@ -290,6 +290,50 @@ class QnAPlugin extends MicroAppPlugin
         return true;
     }
 
+    /**
+     * Output our CSS class for QnA notice list elements
+     *
+     * @param NoticeListItem $nli The item being shown
+     *
+     * @return boolean hook value
+     */
+
+    function onStartOpenNoticeListItemElement($nli)
+    {
+
+        $type = $nli->notice->object_type;
+
+        switch($type)
+        {
+        case QnA_Question::OBJECT_TYPE:
+            $id = (empty($nli->repeat)) ? $nli->notice->id : $nli->repeat->id;
+            $nli->out->elementStart(
+                'li', array(
+                    'class' => 'hentry notice question',
+                    'id'    => 'notice-' . $id
+                )
+            );
+            Event::handle('EndOpenNoticeListItemElement', array($nli));
+            return false;
+            break;
+        case QnA_Answer::OBJECT_TYPE:
+            $id = (empty($nli->repeat)) ? $nli->notice->id : $nli->repeat->id;
+            $nli->out->elementStart(
+                'li', array(
+                    'class' => 'hentry notice answer',
+                    'id'    => 'notice-' . $id
+                )
+            );
+            Event::handle('EndOpenNoticeListItemElement', array($nli));
+            return false;
+            break;
+        default:
+            return true;
+        }
+
+        return true;
+    }
+
     /**
      * Custom HTML output for our notices
      *
@@ -323,23 +367,34 @@ class QnAPlugin extends MicroAppPlugin
         $nli = new NoticeListItem($notice, $out);
         $nli->showNotice();
 
-        $out->elementStart('div', array('class' => 'entry-content question-content'));
+
+
+        $out->elementStart('div', array('class' => 'entry-content question-desciption'));
+
         $question = QnA_Question::getByNotice($notice);
 
-        if ($question) {
-            if ($user) {
-                $profile = $user->getProfile();
-                $answer = $question->getAnswer($profile);
-                if ($answer) {
-                    // User has already answer; show the results.
-                    $form = new QnareviseanswerForm($answer, $out);
-                } else {
-                    $form = new QnaanswerForm($question, $out);
+        if (!empty($question)) {
+
+            $short = $question->description;
+            $out->raw($question->description);
+
+            // Don't prompt user for an answer if the question is closed or
+            // the current user posed the question in the first place
+            if (empty($question->closed)) {
+                if (!empty($user) && ($user->id != $question->profile_id)) {
+                    $profile = $user->getProfile();
+                    $answer = $question->getAnswer($profile);
+                    if ($answer) {
+                        // User has already answered; show the results.
+                        $form = new QnareviseanswerForm($answer, $out);
+                    } else {
+                        $form = new QnaanswerForm($question, $out);
+                    }
+                    $form->show();
                 }
-                $form->show();
             }
         } else {
-            $out->text(_m('Question data is missing'));
+            $out->text(_m('Question data is missing.'));
         }
         $out->elementEnd('div');
 
@@ -355,6 +410,19 @@ class QnAPlugin extends MicroAppPlugin
         $nli = new NoticeListItem($notice, $out);
         $nli->showNotice();
 
+        $out->elementStart('div', array('class' => 'entry-content answer-content'));
+
+        $answer = QnA_Answer::staticGet('uri', $notice->uri);
+
+        if (!empty($answer)) {
+            $short = $answer->content;
+            $out->raw($answer->content);
+        } else {
+            $out->text(_m('Answer data is missing.'));
+        }
+
+        $out->elementEnd('div');
+
         // @fixme
         $out->elementStart('div', array('class' => 'entry-content'));
     }
index a91ae9ad39535f7b088a702ce8fe5566ed659f6f..b4db9cadda8a8e9c0e6560227de73468c991ed4d 100644 (file)
@@ -137,9 +137,11 @@ class QnanewanswerAction extends Action
      */
     function newAnswer()
     {
+        $profile = $this->user->getProfile();
+
         try {
             $notice = QnA_Answer::saveNew(
-                $this->user->getProfile(),
+                $profile,
                 $this->question,
                 $this->answerText
             );
@@ -150,6 +152,7 @@ class QnanewanswerAction extends Action
         }
         if ($this->boolean('ajax')) {
             common_debug("ajaxy part");
+            $answer = $this->question->getAnswer($profile);
             header('Content-Type: text/xml;charset=utf-8');
             $this->xw->startDocument('1.0', 'UTF-8');
             $this->elementStart('html');
@@ -158,7 +161,7 @@ class QnanewanswerAction extends Action
             $this->element('title', null, _m('Answers'));
             $this->elementEnd('head');
             $this->elementStart('body');
-            $this->raw($this->answer->asHTML());
+            $this->raw($answer->asHTML());
             $this->elementEnd('body');
             $this->elementEnd('html');
         } else {