QnA - Better display of questions and answers in streams
This commit is contained in:
parent
8e086d5a90
commit
bac112c244
|
@ -290,6 +290,50 @@ class QnAPlugin extends MicroAppPlugin
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output our CSS class for QnA notice list elements
|
||||
*
|
||||
* @param NoticeListItem $nli The item being shown
|
||||
*
|
||||
* @return boolean hook value
|
||||
*/
|
||||
|
||||
function onStartOpenNoticeListItemElement($nli)
|
||||
{
|
||||
|
||||
$type = $nli->notice->object_type;
|
||||
|
||||
switch($type)
|
||||
{
|
||||
case QnA_Question::OBJECT_TYPE:
|
||||
$id = (empty($nli->repeat)) ? $nli->notice->id : $nli->repeat->id;
|
||||
$nli->out->elementStart(
|
||||
'li', array(
|
||||
'class' => 'hentry notice question',
|
||||
'id' => 'notice-' . $id
|
||||
)
|
||||
);
|
||||
Event::handle('EndOpenNoticeListItemElement', array($nli));
|
||||
return false;
|
||||
break;
|
||||
case QnA_Answer::OBJECT_TYPE:
|
||||
$id = (empty($nli->repeat)) ? $nli->notice->id : $nli->repeat->id;
|
||||
$nli->out->elementStart(
|
||||
'li', array(
|
||||
'class' => 'hentry notice answer',
|
||||
'id' => 'notice-' . $id
|
||||
)
|
||||
);
|
||||
Event::handle('EndOpenNoticeListItemElement', array($nli));
|
||||
return false;
|
||||
break;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom HTML output for our notices
|
||||
*
|
||||
|
@ -323,23 +367,34 @@ class QnAPlugin extends MicroAppPlugin
|
|||
$nli = new NoticeListItem($notice, $out);
|
||||
$nli->showNotice();
|
||||
|
||||
$out->elementStart('div', array('class' => 'entry-content question-content'));
|
||||
|
||||
|
||||
$out->elementStart('div', array('class' => 'entry-content question-desciption'));
|
||||
|
||||
$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);
|
||||
if (!empty($question)) {
|
||||
|
||||
$short = $question->description;
|
||||
$out->raw($question->description);
|
||||
|
||||
// Don't prompt user for an answer if the question is closed or
|
||||
// the current user posed the question in the first place
|
||||
if (empty($question->closed)) {
|
||||
if (!empty($user) && ($user->id != $question->profile_id)) {
|
||||
$profile = $user->getProfile();
|
||||
$answer = $question->getAnswer($profile);
|
||||
if ($answer) {
|
||||
// User has already answered; show the results.
|
||||
$form = new QnareviseanswerForm($answer, $out);
|
||||
} else {
|
||||
$form = new QnaanswerForm($question, $out);
|
||||
}
|
||||
$form->show();
|
||||
}
|
||||
$form->show();
|
||||
}
|
||||
} else {
|
||||
$out->text(_m('Question data is missing'));
|
||||
$out->text(_m('Question data is missing.'));
|
||||
}
|
||||
$out->elementEnd('div');
|
||||
|
||||
|
@ -355,6 +410,19 @@ class QnAPlugin extends MicroAppPlugin
|
|||
$nli = new NoticeListItem($notice, $out);
|
||||
$nli->showNotice();
|
||||
|
||||
$out->elementStart('div', array('class' => 'entry-content answer-content'));
|
||||
|
||||
$answer = QnA_Answer::staticGet('uri', $notice->uri);
|
||||
|
||||
if (!empty($answer)) {
|
||||
$short = $answer->content;
|
||||
$out->raw($answer->content);
|
||||
} else {
|
||||
$out->text(_m('Answer data is missing.'));
|
||||
}
|
||||
|
||||
$out->elementEnd('div');
|
||||
|
||||
// @fixme
|
||||
$out->elementStart('div', array('class' => 'entry-content'));
|
||||
}
|
||||
|
|
|
@ -137,9 +137,11 @@ class QnanewanswerAction extends Action
|
|||
*/
|
||||
function newAnswer()
|
||||
{
|
||||
$profile = $this->user->getProfile();
|
||||
|
||||
try {
|
||||
$notice = QnA_Answer::saveNew(
|
||||
$this->user->getProfile(),
|
||||
$profile,
|
||||
$this->question,
|
||||
$this->answerText
|
||||
);
|
||||
|
@ -150,6 +152,7 @@ class QnanewanswerAction extends Action
|
|||
}
|
||||
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');
|
||||
|
@ -158,7 +161,7 @@ class QnanewanswerAction extends Action
|
|||
$this->element('title', null, _m('Answers'));
|
||||
$this->elementEnd('head');
|
||||
$this->elementStart('body');
|
||||
$this->raw($this->answer->asHTML());
|
||||
$this->raw($answer->asHTML());
|
||||
$this->elementEnd('body');
|
||||
$this->elementEnd('html');
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue
Block a user