]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/QnA/actions/qnashowquestion.php
Trying to debug some stuff regarding oEmbed
[quix0rs-gnu-social.git] / plugins / QnA / actions / qnashowquestion.php
index e563753a01402de2598f0033cedacef166454245..cc8f98448aa1e259f4d14bb96aba31ad43999cd3 100644 (file)
@@ -57,11 +57,11 @@ class QnashowquestionAction extends ShownoticeAction
      */
     function prepare($argarray)
     {
-        OwnerDesignAction::prepare($argarray);
+        Action::prepare($argarray);
 
         $this->id = $this->trimmed('id');
 
-        $this->question = Question::staticGet('id', $this->id);
+        $this->question = QnA_Question::getKV('id', $this->id);
 
         if (empty($this->question)) {
             // TRANS: Client exception thrown trying to view a non-existing question.
@@ -76,7 +76,7 @@ class QnashowquestionAction extends ShownoticeAction
             throw new ClientException(_m('No such question notice.'), 404);
         }
 
-        $this->user = User::staticGet('id', $this->question->profile_id);
+        $this->user = User::getKV('id', $this->question->profile_id);
 
         if (empty($this->user)) {
             // TRANS: Client exception thrown trying to view a question of a non-existing user.
@@ -90,11 +90,56 @@ class QnashowquestionAction extends ShownoticeAction
             throw new ServerException(_m('User without a profile.'));
         }
 
-        $this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
+        try {
+            $this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
+        } catch (Exception $e) {
+            $this->avatar = null;
+        }
 
         return true;
     }
 
+    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 = Notice::multiGet('id', $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');
+    }
+
     /**
      * Title of the page
      *
@@ -104,11 +149,13 @@ class QnashowquestionAction extends ShownoticeAction
      */
     function title()
     {
-        // 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->question);
+        return sprintf(
+            // TRANS: Page title for a question.
+            // TRANS: %1$s is the nickname of the user who asked the question, %2$s is the question.
+            _m('%1$s\'s question: %2$s'),
+            $this->user->nickname,
+            $this->question->title
+        );
     }
 
     /**
@@ -119,7 +166,6 @@ class QnashowquestionAction extends ShownoticeAction
         return Action::lastModified();
     }
 
-
     /**
      * @fixme combine the notice time with question update time
      */