X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FQnA%2Fclasses%2FQnA_Answer.php;h=d200c7b45a0fcc24b853e2594bdcf1e3ef8f229f;hb=6c0bb0f35b7e457ea9ccdc2668b30df6e48cc267;hp=57c08afe4ed22c07a2e38e46ac26fdedc8ed54e8;hpb=c1a27922ba738f71b100a520e5db6f32985a307b;p=quix0rs-gnu-social.git diff --git a/plugins/QnA/classes/QnA_Answer.php b/plugins/QnA/classes/QnA_Answer.php index 57c08afe4e..d200c7b45a 100644 --- a/plugins/QnA/classes/QnA_Answer.php +++ b/plugins/QnA/classes/QnA_Answer.php @@ -52,7 +52,7 @@ class QnA_Answer extends Managed_DataObject public $profile_id; // int -> question.id public $best; // (boolean) int -> whether the question asker has marked this as the best answer public $revisions; // int -> count of revisions to this answer - public $text; // text -> response text + public $content; // text -> response text public $created; // datetime /** @@ -112,6 +112,7 @@ class QnA_Answer extends Managed_DataObject 'not null' => true, 'description' => 'UUID of question being responded to' ), + 'content' => array('type' => 'text'), // got a better name? 'best' => array('type' => 'int', 'size' => 'tiny'), 'revisions' => array('type' => 'int'), 'profile_id' => array('type' => 'int'), @@ -139,7 +140,7 @@ class QnA_Answer extends Managed_DataObject { $answer = self::staticGet('uri', $notice->uri); if (empty($answer)) { - throw new Exception("No answer with URI {$this->notice->uri}"); + throw new Exception("No answer with URI {$notice->uri}"); } return $answer; } @@ -154,6 +155,11 @@ class QnA_Answer extends Managed_DataObject return Notice::staticGet('uri', $this->uri); } + static function fromNotice($notice) + { + return QnA_Answer::staticGet('uri', $notice->uri); + } + function bestUrl() { return $this->getNotice()->bestUrl(); @@ -166,13 +172,13 @@ class QnA_Answer extends Managed_DataObject */ function getQuestion() { - $question = self::staticGet('id', $this->question_id); + $question = QnA_Question::staticGet('id', $this->question_id); if (empty($question)) { throw new Exception("No question with ID {$this->question_id}"); } - return question; + return $question; } - + function getProfile() { $profile = Profile::staticGet('id', $this->profile_id); @@ -186,7 +192,8 @@ class QnA_Answer extends Managed_DataObject { return self::toHTML( $this->getProfile(), - $this->getQuestion() + $this->getQuestion(), + $this ); } @@ -194,64 +201,57 @@ class QnA_Answer extends Managed_DataObject { return self::toString( $this->getProfile(), - $this->getQuestion() + $this->getQuestion(), + $this ); } - static function toHTML($profile, $event, $response) + static function toHTML($profile, $question, $answer) { - $fmt = null; - - $notice = $event->getNotice(); - - switch ($response) { - case 'Y': - $fmt = _("%2s is attending %4s."); - break; - case 'N': - $fmt = _("%2s is not attending %4s."); - break; - case '?': - $fmt = _("%2s might attend %4s."); - break; - default: - throw new Exception("Unknown response code {$response}"); - break; + $notice = $question->getNotice(); + + $out = new XMLStringer(); + + $cls = array('qna_answer'); + if (!empty($answer->best)) { + $cls[] = 'best'; } - return sprintf($fmt, - htmlspecialchars($profile->profileurl), - htmlspecialchars($profile->getBestName()), - htmlspecialchars($notice->bestUrl()), - htmlspecialchars($event->title)); - } + $out->elementStart('p', array('class' => implode(' ', $cls))); + $out->elementStart('span', 'answer-content'); + $out->raw(QnAPlugin::shorten($answer->content, $notice)); + $out->elementEnd('span'); - static function toString($profile, $event, $response) - { - $fmt = null; - - $notice = $event->getNotice(); - - switch ($response) { - case 'Y': - $fmt = _("%1s is attending %2s."); - break; - case 'N': - $fmt = _("%1s is not attending %2s."); - break; - case '?': - $fmt = _("%1s might attend %2s.>"); - break; - default: - throw new Exception("Unknown response code {$response}"); - break; + if (!empty($answer->revisions)) { + $out->elementstart('span', 'answer-revisions'); + $out->text( + htmlspecialchars( + sprintf(_m('%s revisions'), $answer->revisions) + ) + ); + $out->elementEnd('span'); } - return sprintf($fmt, - $profile->getBestName(), - $event->title); + $out->elementEnd('p'); + + return $out->getString(); } + static function toString($profile, $question, $answer) + { + $notice = $question->getNotice(); + + $fmt = _m( + '%1$s answered the question "%2$s": %3$s' + ); + + return sprintf( + $fmt, + htmlspecialchars($profile->getBestName()), + htmlspecialchars($question->title), + htmlspecialchars($answer->content) + ); + } /** * Save a new answer notice @@ -274,7 +274,7 @@ class QnA_Answer extends Managed_DataObject $answer->question_id = $question->id; $answer->revisions = 0; $answer->best = 0; - $answer->text = $text; + $answer->content = $text; $answer->created = common_sql_now(); $answer->uri = common_local_url( 'qnashowanswer',