]> 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 a586d89b4094c274cab322978327268a3164279e..6841ec9873204e7d8e82001838ae9a20c19f3cf8 100644 (file)
@@ -81,18 +81,19 @@ class QnAPlugin extends MicroAppPlugin
         case 'QnanewquestionAction':
         case 'QnanewanswerAction':
         case 'QnashowquestionAction':
+        case 'QnaclosequestionAction':
         case 'QnashowanswerAction':
         case 'QnareviseanswerAction':
         case 'QnavoteAction':
             include_once $dir . '/actions/'
                 . strtolower(mb_substr($cls, 0, -6)) . '.php';
             return false;
-        case 'QnaquestionForm':
-        case 'QnashowanswerForm':
+        case 'QnanewquestionForm':
+        case 'QnashowquestionForm':
         case 'QnanewanswerForm':
+        case 'QnashowanswerForm':
         case 'QnareviseanswerForm':
         case 'QnavoteForm':
-        case 'AnswerNoticeListItem':
             include_once $dir . '/lib/' . strtolower($cls).'.php';
             break;
         case 'QnA_Question':
@@ -122,6 +123,10 @@ class QnAPlugin extends MicroAppPlugin
             'main/qna/newquestion',
             array('action' => 'qnanewquestion')
         );
+        $m->connect(
+            'answer/qna/closequestion',
+            array('action' => 'qnaclosequestion')
+        );
         $m->connect(
             'main/qna/newanswer',
             array('action' => 'qnanewanswer')
@@ -200,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.');
         }
 
@@ -274,24 +279,6 @@ class QnAPlugin extends MicroAppPlugin
         return $obj;
     }
 
-    /**
-     * Change the verb on Answer notices
-     *
-     * @param Notice $notice
-     *
-     * @return ActivityObject
-     */
-
-    function onEndNoticeAsActivity($notice, &$act) {
-        switch ($notice->object_type) {
-        case Answer::NORMAL:
-        case Answer::ANONYMOUS:
-            $act->verb = $notice->object_type;
-            break;
-        }
-        return true;
-    }
-
     /**
      * Output our CSS class for QnA notice list elements
      *
@@ -308,9 +295,13 @@ class QnAPlugin extends MicroAppPlugin
         {
         case QnA_Question::OBJECT_TYPE:
             $id = (empty($nli->repeat)) ? $nli->notice->id : $nli->repeat->id;
+            $class = 'hentry notice question';
+            if ($nli->notice->scope != 0 && $nli->notice->scope != 1) {
+                $class .= ' limited-scope';
+            }
             $nli->out->elementStart(
                 'li', array(
-                    'class' => 'hentry notice question',
+                    'class' => $class,
                     'id'    => 'notice-' . $id
                 )
             );
@@ -322,7 +313,7 @@ class QnAPlugin extends MicroAppPlugin
 
             $cls = array('hentry', 'notice', 'answer');
 
-            $answer = QnA_Answer::staticGet('uri', $notice->uri);
+            $answer = QnA_Answer::staticGet('uri', $nli->notice->uri);
 
             if (!empty($answer) && !empty($answer->best)) {
                 $cls[] = 'best';
@@ -351,7 +342,7 @@ class QnAPlugin extends MicroAppPlugin
      * @param Notice $notice
      * @param HTMLOutputter $out
      */
-    
+
     function showNotice($notice, $out)
     {
         switch ($notice->object_type) {
@@ -379,29 +370,15 @@ class QnAPlugin extends MicroAppPlugin
         $nli = new NoticeListItem($notice, $out);
         $nli->showNotice();
 
-        $out->elementStart('div', array('class' => 'entry-content question-desciption'));
+        $out->elementStart('div', array('class' => 'entry-content question-description'));
 
         $question = QnA_Question::getByNotice($notice);
 
         if (!empty($question)) {
 
-            $short = $this->shorten($question->description, $notice);
-            $out->raw($short);
-
-            // 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)) {
-                    $profile = $user->getProfile();
-                    $answer = $question->getAnswer($profile);
-                    if (!$answer) {
-                        $form = new QnanewanswerForm($question, $out);
-                        $form->show();
-                    }
-                }
-            } else {
-                $out->element('span', 'closed', _m('This question is closed.'));
-            }
+            $form = new QnashowquestionForm($out, $question);
+            $form->show();
+
         } else {
             $out->text(_m('Question data is missing.'));
         }
@@ -411,10 +388,75 @@ 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();
-        
+
         $answer   = QnA_Answer::getByNotice($notice);
         $question = $answer->getQuestion();
 
@@ -465,7 +507,7 @@ class QnAPlugin extends MicroAppPlugin
 
     function entryForm($out)
     {
-        return new QnaquestionForm($out);
+        return new QnanewquestionForm($out);
     }
 
     /**
@@ -495,7 +537,8 @@ class QnAPlugin extends MicroAppPlugin
 
     function onEndShowScripts($action)
     {
-        // XXX maybe some cool shiz here
+        $action->script($this->path('js/qna.js'));
+        return true;
     }
 
     function onEndShowStyles($action)