Ejemplo n.º 1
0
 function showNoticeQuestion(Notice $notice, $out)
 {
     $user = common_current_user();
     // @hack we want regular rendering, then just add stuff after that
     $nli = new NoticeListItem($notice, $out);
     $nli->showNotice();
     $out->elementStart('div', array('class' => 'e-content question-description'));
     $question = QnA_Question::getByNotice($notice);
     if (!empty($question)) {
         $form = new QnashowquestionForm($out, $question);
         $form->show();
     } else {
         // TRANS: Error message displayed when question data is not present.
         $out->text(_m('Question data is missing.'));
     }
     $out->elementEnd('div');
     // @fixme
     $out->elementStart('div', array('class' => 'e-content'));
 }
Ejemplo n.º 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 close a question."), 403);
     }
     if ($this->isPost()) {
         $this->checkSessionToken();
     }
     $id = substr($this->trimmed('id'), 9);
     $this->question = QnA_Question::staticGet('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;
 }
Ejemplo n.º 3
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);
     }
     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::staticGet('id', $id);
     if (empty($this->question)) {
         throw new ClientException(_m('Invalid or missing question.'), 404);
     }
     $this->answerText = $this->trimmed('answer');
     return true;
 }
Ejemplo n.º 4
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')) {
         GNUsocial::setApi(true);
     }
     $this->user = common_current_user();
     if (empty($this->user)) {
         // TRANS: Client exception thrown trying to answer a question while not logged in.
         throw new ClientException(_m('You must be logged in to answer to a question.'), 403);
     }
     if ($this->isPost()) {
         $this->checkSessionToken();
     }
     $id = $this->trimmed('id');
     $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);
     }
     $answer = $this->trimmed('answer');
     return true;
 }
Ejemplo n.º 5
0
 /**
  * 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;
 }
 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 = new Notice();
         $notice->query(sprintf('SELECT notice.* FROM notice WHERE notice.id IN (%s)', implode(',', $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');
 }
Ejemplo n.º 7
0
 /**
  * Save a new question notice
  *
  * @param Profile $profile
  * @param string  $question
  * @param string  $title
  * @param string  $description
  * @param array   $option // and whatnot
  *
  * @return Notice saved notice
  */
 static function saveNew($profile, $title, $description, $options = array())
 {
     $q = new QnA_Question();
     $q->id = UUID::gen();
     $q->profile_id = $profile->id;
     $q->title = $title;
     $q->description = $description;
     if (array_key_exists('created', $options)) {
         $q->created = $options['created'];
     } else {
         $q->created = common_sql_now();
     }
     if (array_key_exists('uri', $options)) {
         $q->uri = $options['uri'];
     } else {
         $q->uri = common_local_url('qnashowquestion', array('id' => $q->id));
     }
     common_log(LOG_DEBUG, "Saving question: {$q->id} {$q->uri}");
     $q->insert();
     if (Notice::contentTooLong($q->title . ' ' . $q->uri)) {
         $max = Notice::maxContent();
         $uriLen = mb_strlen($q->uri);
         $targetLen = $max - ($uriLen + 15);
         $title = mb_substr($q->title, 0, $targetLen) . '…';
     }
     $content = $title . ' ' . $q->uri;
     $link = '<a href="' . htmlspecialchars($q->uri) . '">' . htmlspecialchars($q->title) . '</a>';
     // TRANS: Rendered version of the notice content creating a question.
     // TRANS: %s a link to the question as link description.
     $rendered = sprintf(_m('Question: %s'), $link);
     $tags = array('question');
     $replies = array();
     $options = array_merge(array('urls' => array(), 'rendered' => $rendered, 'tags' => $tags, 'replies' => $replies, 'object_type' => self::OBJECT_TYPE), $options);
     if (!array_key_exists('uri', $options)) {
         $options['uri'] = $q->uri;
     }
     $saved = Notice::saveNew($profile->id, $content, array_key_exists('source', $options) ? $options['source'] : 'web', $options);
     return $saved;
 }
Ejemplo n.º 8
0
 /**
  * Add a new Question
  *
  * @return void
  */
 function newQuestion()
 {
     if ($this->boolean('ajax')) {
         GNUsocial::setApi(true);
     }
     try {
         if (empty($this->title)) {
             // TRANS: Client exception thrown trying to create a question without a title.
             throw new ClientException(_m('Question must have a title.'));
         }
         // Notice options
         $options = array();
         // Does the heavy-lifting for getting "To:" information
         ToSelector::fillOptions($this, $options);
         $saved = QnA_Question::saveNew($this->user->getProfile(), $this->title, $this->description, $options);
     } catch (ClientException $ce) {
         $this->error = $ce->getMessage();
         $this->showPage();
         return;
     }
     if ($this->boolean('ajax')) {
         $this->startHTML('text/xml;charset=utf-8');
         $this->elementStart('head');
         // TRANS: Page title after sending a notice.
         $this->element('title', null, _m('Question posted'));
         $this->elementEnd('head');
         $this->elementStart('body');
         $this->showNotice($saved);
         $this->elementEnd('body');
         $this->endHTML();
     } else {
         common_redirect($saved->getUrl(), 303);
     }
 }
Ejemplo n.º 9
0
 /**
  * When a notice is deleted, clean up related tables.
  *
  * @param Notice $notice
  */
 function deleteRelated(Notice $notice)
 {
     switch ($notice->object_type) {
         case QnA_Question::OBJECT_TYPE:
             common_log(LOG_DEBUG, "Deleting question from notice...");
             $question = QnA_Question::fromNotice($notice);
             $question->delete();
             break;
         case QnA_Answer::OBJECT_TYPE:
             common_log(LOG_DEBUG, "Deleting answer from notice...");
             $answer = QnA_Answer::fromNotice($notice);
             common_log(LOG_DEBUG, "to delete: {$answer->id}");
             $answer->delete();
             break;
         default:
             common_log(LOG_DEBUG, "Not deleting related, wtf...");
     }
 }