]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/QnA/QnAPlugin.php
OMG I think ajax works right now
[quix0rs-gnu-social.git] / plugins / QnA / QnAPlugin.php
index 375e87f615d2ad1eabff4f060c9ebd7fae0cc412..6841ec9873204e7d8e82001838ae9a20c19f3cf8 100644 (file)
@@ -205,7 +205,7 @@ class QnAPlugin extends MicroAppPlugin
 
         $questionObj = $activity->objects[0];
 
-        if ($questinoObj->type != QnA_Question::OBJECT_TYPE) {
+        if ($questionObj->type != QnA_Question::OBJECT_TYPE) {
             throw new Exception('Wrong type for object.');
         }
 
@@ -375,20 +375,10 @@ class QnAPlugin extends MicroAppPlugin
         $question = QnA_Question::getByNotice($notice);
 
         if (!empty($question)) {
-            if (empty($user)) {
-                $form = new QnashowquestionForm($out, $question);
-                $form->show();
-            } else {
-                $profile = $user->getProfile();
-                $answer = $question->getAnswer($profile);
-                if (empty($answer)) {
-                    $form = new QnanewanswerForm($out, $question);
-                    $form->show();
-                } else {
-                    $form = new QnashowquestionForm($out, $question);
-                    $form->show();
-                }
-            }
+
+            $form = new QnashowquestionForm($out, $question);
+            $form->show();
+
         } else {
             $out->text(_m('Question data is missing.'));
         }
@@ -398,6 +388,71 @@ class QnAPlugin extends MicroAppPlugin
         $out->elementStart('div', array('class' => 'entry-content'));
     }
 
+
+    /**
+     * Output the HTML for this kind of object in a list
+     *
+     * @param NoticeListItem $nli The list item being shown.
+     *
+     * @return boolean hook value
+     *
+     * @fixme WARNING WARNING WARNING this closes a 'div' that is implicitly opened in BookmarkPlugin's showNotice implementation
+     */
+    function onStartShowNoticeItem($nli)
+    {
+        if (!$this->isMyNotice($nli->notice)) {
+            return true;
+        }
+
+        $out = $nli->out;
+        $notice = $nli->notice;
+
+        $this->showNotice($notice, $out);
+
+        $nli->showNoticeLink();
+        $nli->showNoticeSource();
+        $nli->showNoticeLocation();
+        $nli->showContext();
+        $nli->showRepeat();
+
+        $out->elementEnd('div');
+
+        $nli->showNoticeOptions();
+
+        if ($notice->object_type == QnA_Question::OBJECT_TYPE) {
+
+            $user = common_current_user();
+            $question = QnA_Question::getByNotice($notice);
+
+            if (!empty($user)) {
+
+                $profile = $user->getProfile();
+                $answer = $question->getAnswer($profile);
+
+                // Output a placeholder input -- clicking on it will
+                // bring up a real answer form
+
+                // NOTE: this whole ul is just a placeholder
+                if (empty($question->closed) && empty($answer)) {
+                    $out->elementStart('ul', 'notices qna-dummy');
+                    $out->elementStart('li', 'qna-dummy-placeholder');
+                    $out->element(
+                        'input',
+                        array(
+                            'class' => 'placeholder',
+                            'value' => _m('Your answer...')
+                        )
+                    );
+                    $out->elementEnd('li');
+                    $out->elementEnd('ul');
+                }
+            }
+        }
+
+        return false;
+    }
+
+
     function showNoticeAnswer($notice, $out)
     {
         $user = common_current_user();