case 'QnanewanswerAction':
case 'QnashowquestionAction':
case 'QnashowanswerAction':
+ case 'QnareviseanswerAction':
case 'QnavoteAction':
include_once $dir . '/actions/'
. strtolower(mb_substr($cls, 0, -6)) . '.php';
return false;
case 'QnaquestionForm':
case 'QnaanswerForm':
- case 'QnavoteForm';
+ case 'QnareviseanswerForm':
+ case 'QnavoteForm':
include_once $dir . '/lib/' . strtolower($cls).'.php';
break;
case 'QnA_Question':
array('action' => 'qnanewquestion')
);
$m->connect(
- 'main/qna/newanswer/:id',
- array('action' => 'qnanewanswer'),
- array('id' => $UUIDregex)
+ 'main/qna/newanswer',
+ array('action' => 'qnanewanswer')
);
$m->connect(
'question/vote/:id',
switch ($activity->verb) {
case ActivityVerb::POST:
- $notice = Question::saveNew(
+ $notice = QnA_Question::saveNew(
$actor,
- $questionObj->title
- // null,
- // $questionObj->summary,
- // $options
+ $questionObj->title,
+ $questionObj->summary,
+ $options
);
break;
- case Answer::NORMAL:
+ case Answer::ObjectType:
$question = QnA_Question::staticGet('uri', $questionObj->id);
if (empty($question)) {
// FIXME: save the question
throw new Exception("Answer to unknown question.");
}
- $notice = QnA_Answer::saveNew($actor, $question, $activity->verb, $options);
+ $notice = QnA_Answer::saveNew($actor, $question, $options);
break;
default:
- throw new Exception("Unknown verb for question");
+ throw new Exception("Unknown object type received by QnA Plugin");
}
return $notice;
* @param Notice $notice
* @param HTMLOutputter $out
*/
-
function showNotice($notice, $out)
{
switch ($notice->object_type) {
case QnA_Question::OBJECT_TYPE:
- $this->showQuestionNotice($notice, $out);
- break;
+ return $this->showNoticeQuestion($notice, $out);
case QnA_Answer::OBJECT_TYPE:
- $this->showAnswerNotice($notice, $out);
- break;
+ return $this->showNoticeAnswer($notice, $out);
+ default:
+ // TRANS: Exception thrown when performing an unexpected action on a question.
+ // TRANS: %s is the unpexpected object type.
+ throw new Exception(
+ sprintf(
+ _m('Unexpected type for QnA plugin: %s.'),
+ $notice->object_type
+ )
+ );
}
-
- // bad craziness
- $out->elementStart('div', array('class' => 'question'));
-
- $profile = $notice->getProfile();
- $avatar = $profile->getAvatar(AVATAR_MINI_SIZE);
-
- $out->element(
- 'img',
- array(
- 'src' => ($avatar)
- ? $avatar->displayUrl()
- : Avatar::defaultImage(AVATAR_MINI_SIZE),
- 'class' => 'avatar photo question-avatar',
- 'width' => AVATAR_MINI_SIZE,
- 'height' => AVATAR_MINI_SIZE,
- 'alt' => $profile->getBestName()
- )
- );
-
- $out->raw(' '); // avoid for AJAX XML compatibility
-
- // hack for belongsOnTimeline; JS needs to be able to find the author
- $out->elementStart('span', 'vcard author');
- $out->element(
- 'a',
- array(
- 'class' => 'url',
- 'href' => $profile->profileurl,
- 'title' => $profile->getBestName()
- ),
- $profile->nickname
- );
-
- $out->elementEnd('span');
}
- function showAnswerNotice($notice, $out)
+ function showNoticeQuestion($notice, $out)
{
- $answer = QnA_Answer::fromNotice($notice);
-
- assert(!empty($answer));
-
- $out->elementStart('div', 'answer');
- $out->raw($answer->asHTML());
- $out->elementEnd('div');
- }
-
- function showQuestionNotice($notice, $out)
- {
- $profile = $notice->getProfile();
- $question = QnA_Question::fromNotice($notice);
-
- assert(!empty($question));
- assert(!empty($profile));
-
- $out->elementStart('div', 'question-notice');
-
- $out->elementStart('h3');
+ $user = common_current_user();
- if (!empty($question->url)) {
- $out->element(
- 'a',
- array(
- 'href' => $question->url,
- 'class' => 'question-title'
- ),
- $question->title
- );
+ // @hack we want regular rendering, then just add stuff after that
+ $nli = new NoticeListItem($notice, $out);
+ $nli->showNotice();
+
+ $out->elementStart('div', array('class' => 'entry-content question-content'));
+ $question = QnA_Question::getByNotice($notice);
+
+ if ($question) {
+ if ($user) {
+ $profile = $user->getProfile();
+ $answer = $question->getAnswer($profile);
+ if ($answer) {
+ // User has already answer; show the results.
+ $form = new QnareviseanswerForm($answer, $out);
+ } else {
+ $form = new QnaanswerForm($question, $out);
+ }
+ $form->show();
+ }
} else {
- $out->text($question->title);
+ $out->text(_m('Question data is missing'));
}
-
- if (!empty($question->location)) {
- $out->elementStart('div', 'question-location');
- $out->element('strong', null, _('Location: '));
- $out->element('span', 'location', $question->location);
- $out->elementEnd('div');
- }
-
- if (!empty($question->description)) {
- $out->elementStart('div', 'question-description');
- $out->element('strong', null, _('Description: '));
- $out->element('span', 'description', $question->description);
- $out->elementEnd('div');
- }
-
- //$answers = $question->getAnswers();
-
- $out->elementStart('div', 'question-answers');
- $out->element('strong', null, _('Answer: '));
- $out->element('span', 'question-answer');
-
$out->elementEnd('div');
- $user = common_current_user();
-
- if (!empty($user)) {
-
- $answer = $question->getAnswer($user->getProfile());
-
- if (empty($answer)) {
- $form = new QnaanswerForm($question, $out);
- $form->show();
- }
+ // @fixme
+ $out->elementStart('div', array('class' => 'entry-content'));
+ }
+ function showNoticeAnswer($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->elementEnd('div');
+ // @fixme
+ $out->elementStart('div', array('class' => 'entry-content'));
}
/**