/** * 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; }