Esempio n. 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;
 }
Esempio 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 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;
 }
 /**
  * Construct a new answer form
  *
  * @param QnA_Answer $answer
  * @param HTMLOutputter $out output channel
  *
  * @return void
  */
 function __construct(QnA_Answer $answer, HTMLOutputter $out)
 {
     parent::__construct($out);
     $this->question = $answer->getQuestion();
     $this->answer = $answer;
 }
Esempio n. 4
0
 /**
  * Add a new answer
  *
  * @return void
  */
 function newAnswer()
 {
     $profile = $this->user->getProfile();
     try {
         $notice = QnA_Answer::saveNew($profile, $this->question, $this->answerText);
     } catch (ClientException $ce) {
         $this->error = $ce->getMessage();
         $this->showForm($this->error);
         return;
     }
     if ($this->boolean('ajax')) {
         common_debug("ajaxy part");
         $answer = $this->question->getAnswer($profile);
         header('Content-Type: text/xml;charset=utf-8');
         $this->xw->startDocument('1.0', 'UTF-8');
         $this->elementStart('html');
         $this->elementStart('head');
         // TRANS: Page title after sending an answer.
         $this->element('title', null, _m('Answers'));
         $this->elementEnd('head');
         $this->elementStart('body');
         $nli = new NoticeAnswerListItem($notice, $this, $this->question, $answer);
         $nli->show();
         $this->elementEnd('body');
         $this->elementEnd('html');
     } else {
         common_debug("not ajax");
         common_redirect($this->question->bestUrl(), 303);
     }
 }
Esempio n. 5
0
 /**
  * Save a new answer notice
  *
  * @param Profile  $profile
  * @param Question $Question the question being answered
  * @param array
  *
  * @return Notice saved notice
  */
 static function saveNew($profile, $question, $text, $options = null)
 {
     if (empty($options)) {
         $options = array();
     }
     $answer = new QnA_Answer();
     $answer->id = UUID::gen();
     $answer->profile_id = $profile->id;
     $answer->question_id = $question->id;
     $answer->revisions = 0;
     $answer->best = 0;
     $answer->content = $text;
     $answer->created = common_sql_now();
     $answer->uri = common_local_url('qnashowanswer', array('id' => $answer->id));
     common_log(LOG_DEBUG, "Saving answer: {$answer->id}, {$answer->uri}");
     $answer->insert();
     $content = sprintf(_m('answered "%s"'), $question->title);
     $link = '<a href="' . htmlspecialchars($answer->uri) . '">' . htmlspecialchars($question->title) . '</a>';
     // TRANS: Rendered version of the notice content answering a question.
     // TRANS: %s a link to the question with question title as the link content.
     $rendered = sprintf(_m('answered "%s"'), $link);
     $tags = array();
     $replies = array();
     $options = array_merge(array('urls' => array(), 'content' => $content, 'rendered' => $rendered, 'tags' => $tags, 'replies' => $replies, 'reply_to' => $question->getNotice()->id, 'object_type' => self::OBJECT_TYPE), $options);
     if (!array_key_exists('uri', $options)) {
         $options['uri'] = $answer->uri;
     }
     $saved = Notice::saveNew($profile->id, $content, array_key_exists('source', $options) ? $options['source'] : 'web', $options);
     return $saved;
 }
Esempio n. 6
0
 /**
  * Add a new answer
  *
  * @return void
  */
 function answer()
 {
     try {
         $notice = Answer::saveNew($this->user->getProfile(), $this->question, $this->answer);
     } catch (ClientException $ce) {
         $this->error = $ce->getMessage();
         $this->showPage();
         return;
     }
     if ($this->boolean('ajax')) {
         header('Content-Type: text/xml;charset=utf-8');
         $this->xw->startDocument('1.0', 'UTF-8');
         $this->elementStart('html');
         $this->elementStart('head');
         // TRANS: Page title after sending in a vote for a question or answer.
         $this->element('title', null, _m('Answers'));
         $this->elementEnd('head');
         $this->elementStart('body');
         $form = new QnA_Answer($this->question, $this);
         $form->show();
         $this->elementEnd('body');
         $this->elementEnd('html');
     } else {
         common_redirect($this->question->bestUrl(), 303);
     }
 }
Esempio n. 7
0
 function countAnswers()
 {
     $a = new QnA_Answer();
     $a->question_id = $this->id;
     return $a->count();
 }
Esempio n. 8
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...");
     }
 }
Esempio n. 9
0
 /**
  * Constructor
  *
  * @param HTMLOutputter $out    output channel
  * @param QnA_Answer    $answer answer to revise
  */
 function __construct($out = null, $answer = null)
 {
     parent::__construct($out);
     $this->answer = $answer;
     $this->question = $answer->getQuestion();
 }
Esempio n. 10
0
 function showNoticeAnswer(Notice $notice, $out)
 {
     $user = common_current_user();
     $answer = QnA_Answer::getByNotice($notice);
     $question = $answer->getQuestion();
     $nli = new NoticeListItem($notice, $out);
     $nli->showNotice();
     $out->elementStart('div', array('class' => 'e-content answer-content'));
     if (!empty($answer)) {
         $form = new QnashowanswerForm($out, $answer);
         $form->show();
     } else {
         // TRANS: Error message displayed when answer data is not present.
         $out->text(_m('Answer data is missing.'));
     }
     $out->elementEnd('div');
     // @todo FIXME
     $out->elementStart('div', array('class' => 'e-content'));
 }