/**
  * For initializing members of the class.
  *
  * @param array $argarray misc. arguments
  *
  * @return boolean true
  */
 function prepare($argarray)
 {
     Action::prepare($argarray);
     $this->id = $this->trimmed('id');
     $this->question = QnA_Question::getKV('id', $this->id);
     if (empty($this->question)) {
         // TRANS: Client exception thrown trying to view a non-existing question.
         throw new ClientException(_m('No such question.'), 404);
     }
     $this->notice = $this->question->getNotice();
     if (empty($this->notice)) {
         // Did we used to have it, and it got deleted?
         // TRANS: Client exception thrown trying to view a non-existing question notice.
         throw new ClientException(_m('No such question notice.'), 404);
     }
     $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.
         throw new ClientException(_m('No such user.'), 404);
     }
     $this->profile = $this->user->getProfile();
     if (empty($this->profile)) {
         // TRANS: Server exception thrown trying to view a question for a user for which the profile could not be loaded.
         throw new ServerException(_m('User without a profile.'));
     }
     try {
         $this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
     } catch (Exception $e) {
         $this->avatar = null;
     }
     return true;
 }
 /**
  * For initializing members of the class.
  *
  * @param array $argarray misc. arguments
  *
  * @return boolean true
  */
 function prepare($argarray)
 {
     parent::prepare($argarray);
     if ($this->boolean('ajax')) {
         GNUsocial::setApi(true);
     }
     $this->user = common_current_user();
     if (empty($this->user)) {
         throw new ClientException(_m("You must be logged in to close a question."), 403);
     }
     if ($this->isPost()) {
         $this->checkSessionToken();
     }
     $id = substr($this->trimmed('id'), 9);
     $this->question = QnA_Question::getKV('id', $id);
     if (empty($this->question)) {
         // TRANS: Client exception thrown trying to respond to a non-existing question.
         throw new ClientException(_m('Invalid or missing question.'), 404);
     }
     return true;
 }
 /**
  * For initializing members of the class.
  *
  * @param array $argarray misc. arguments
  *
  * @return boolean true
  */
 function prepare($argarray)
 {
     parent::prepare($argarray);
     if ($this->boolean('ajax')) {
         GNUsocial::setApi(true);
     }
     common_debug("in qnanewanswer");
     $this->user = common_current_user();
     if (empty($this->user)) {
         throw new ClientException(_m("You must be logged in to answer to a question."), 403);
     }
     if ($this->isPost()) {
         $this->checkSessionToken();
     }
     $id = substr($this->trimmed('id'), 9);
     $this->question = QnA_Question::getKV('id', $id);
     if (empty($this->question)) {
         throw new ClientException(_m('Invalid or missing question.'), 404);
     }
     $this->answerText = $this->trimmed('answer');
     return true;
 }
 /**
  * Get the Question this is an answer to
  *
  * @return QnA_Question
  */
 function getQuestion()
 {
     $question = QnA_Question::getKV('id', $this->question_id);
     if (empty($question)) {
         // TRANS: Exception thown when getting a question with a non-existing ID.
         // TRANS: %s is the non-existing question ID.
         throw new Exception(sprintf(_m('No question with ID %s'), $this->question_id));
     }
     return $question;
 }
 static function fromNotice($notice)
 {
     return QnA_Question::getKV('uri', $notice->uri);
 }
 /**
  * Output our CSS class for QnA notice list elements
  *
  * @param NoticeListItem $nli The item being shown
  *
  * @return boolean hook value
  */
 function onStartOpenNoticeListItemElement(NoticeListItem $nli)
 {
     $type = $nli->notice->object_type;
     switch ($type) {
         case QnA_Question::OBJECT_TYPE:
             $id = empty($nli->repeat) ? $nli->notice->id : $nli->repeat->id;
             $class = 'h-entry notice question';
             if ($nli->notice->scope != 0 && $nli->notice->scope != 1) {
                 $class .= ' limited-scope';
             }
             $question = QnA_Question::getKV('uri', $nli->notice->uri);
             if (!empty($question->closed)) {
                 $class .= ' closed';
             }
             $nli->out->elementStart('li', array('class' => $class, '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;
             $cls = array('h-entry', 'notice', 'answer');
             $answer = QnA_Answer::getKV('uri', $nli->notice->uri);
             if (!empty($answer) && !empty($answer->best)) {
                 $cls[] = 'best';
             }
             $nli->out->elementStart('li', array('class' => implode(' ', $cls), 'id' => 'notice-' . $id));
             Event::handle('EndOpenNoticeListItemElement', array($nli));
             return false;
             break;
         default:
             return true;
     }
     return true;
 }