Example #1
0
 /**
  * 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->answer = QnA_Answer::staticGet('id', $this->id);
     if (empty($this->answer)) {
         // TRANS: Client exception thrown when requesting a non-existing answer.
         throw new ClientException(_m('No such answer.'), 404);
     }
     $this->question = $this->answer->getQuestion();
     if (empty($this->question)) {
         // TRANS: Client exception thrown when requesting an answer that has no connected question.
         throw new ClientException(_m('No question for this answer.'), 404);
     }
     $this->notice = Notice::staticGet('uri', $this->answer->uri);
     if (empty($this->notice)) {
         // TRANS: Did we used to have it, and it got deleted?
         throw new ClientException(_m('No such answer.'), 404);
     }
     $this->user = User::staticGet('id', $this->answer->profile_id);
     if (empty($this->user)) {
         // TRANS: Client exception thrown when requesting answer data for a non-existing user.
         throw new ClientException(_m('No such user.'), 404);
     }
     $this->profile = $this->user->getProfile();
     if (empty($this->profile)) {
         // TRANS: Client exception thrown when requesting answer data for a user without a profile.
         throw new ServerException(_m('User without a profile.'));
     }
     $this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
     return true;
 }
Example #2
0
 /**
  * For initializing members of the class.
  *
  * @param array $argarray misc. arguments
  *
  * @return boolean true
  */
 function prepare($argarray)
 {
     parent::prepare($argarray);
     if ($this->boolean('ajax')) {
         StatusNet::setApi(true);
     }
     $this->user = common_current_user();
     if (empty($this->user)) {
         throw new ClientException(_m("You must be logged in to answer to a question."), 403);
     }
     $id = substr($this->trimmed('id'), 7);
     $this->answer = QnA_Answer::staticGet('id', $id);
     $this->question = $this->answer->getQuestion();
     if (empty($this->answer) || empty($this->question)) {
         throw new ClientException(_m('Invalid or missing answer.'), 404);
     }
     $this->answerText = $this->trimmed('answer');
     return true;
 }
Example #3
0
 /**
  * Output our CSS class for QnA notice list elements
  *
  * @param NoticeListItem $nli The item being shown
  *
  * @return boolean hook value
  */
 function onStartOpenNoticeListItemElement($nli)
 {
     $type = $nli->notice->object_type;
     switch ($type) {
         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' => $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('hentry', 'notice', 'answer');
             $answer = QnA_Answer::staticGet('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;
 }
Example #4
0
 static function fromNotice($notice)
 {
     return QnA_Answer::staticGet('uri', $notice->uri);
 }