]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/QnA/QnAPlugin.php
Merge branch '1.0.x' of gitorious.org:statusnet/mainline into 1.0.x
[quix0rs-gnu-social.git] / plugins / QnA / QnAPlugin.php
index cc70cb7aeb46ed59ebf974e22b0503907bcb3d85..ad0541a71cf1f08d34787261ba6e7e6e87ee9d8f 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.');
         }
 
@@ -279,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
      *
@@ -313,9 +295,20 @@ 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';
+            }
+
+            $question = QnA_Question::staticGet('uri', $nli->notice->uri);
+
+            if (!empty($question->closed)) {
+                $class .= ' closed';
+            }
+
             $nli->out->elementStart(
                 'li', array(
-                    'class' => 'hentry notice question',
+                    'class' => $class,
                     'id'    => 'notice-' . $id
                 )
             );
@@ -327,7 +320,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';
@@ -356,7 +349,7 @@ class QnAPlugin extends MicroAppPlugin
      * @param Notice $notice
      * @param HTMLOutputter $out
      */
-    
+
     function showNotice($notice, $out)
     {
         switch ($notice->object_type) {
@@ -384,25 +377,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)) {
-            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.'));
         }
@@ -412,10 +395,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();
 
@@ -496,7 +544,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)