forked from GNUsocial/gnu-social
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;
|
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
|
* Custom HTML output for our notices
|
||||||
*
|
*
|
||||||
@ -323,23 +367,34 @@ class QnAPlugin extends MicroAppPlugin
|
|||||||
$nli = new NoticeListItem($notice, $out);
|
$nli = new NoticeListItem($notice, $out);
|
||||||
$nli->showNotice();
|
$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);
|
$question = QnA_Question::getByNotice($notice);
|
||||||
|
|
||||||
if ($question) {
|
if (!empty($question)) {
|
||||||
if ($user) {
|
|
||||||
$profile = $user->getProfile();
|
$short = $question->description;
|
||||||
$answer = $question->getAnswer($profile);
|
$out->raw($question->description);
|
||||||
if ($answer) {
|
|
||||||
// User has already answer; show the results.
|
// Don't prompt user for an answer if the question is closed or
|
||||||
$form = new QnareviseanswerForm($answer, $out);
|
// the current user posed the question in the first place
|
||||||
} else {
|
if (empty($question->closed)) {
|
||||||
$form = new QnaanswerForm($question, $out);
|
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 {
|
} else {
|
||||||
$out->text(_m('Question data is missing'));
|
$out->text(_m('Question data is missing.'));
|
||||||
}
|
}
|
||||||
$out->elementEnd('div');
|
$out->elementEnd('div');
|
||||||
|
|
||||||
@ -355,6 +410,19 @@ class QnAPlugin extends MicroAppPlugin
|
|||||||
$nli = new NoticeListItem($notice, $out);
|
$nli = new NoticeListItem($notice, $out);
|
||||||
$nli->showNotice();
|
$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
|
// @fixme
|
||||||
$out->elementStart('div', array('class' => 'entry-content'));
|
$out->elementStart('div', array('class' => 'entry-content'));
|
||||||
}
|
}
|
||||||
|
@ -137,9 +137,11 @@ class QnanewanswerAction extends Action
|
|||||||
*/
|
*/
|
||||||
function newAnswer()
|
function newAnswer()
|
||||||
{
|
{
|
||||||
|
$profile = $this->user->getProfile();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$notice = QnA_Answer::saveNew(
|
$notice = QnA_Answer::saveNew(
|
||||||
$this->user->getProfile(),
|
$profile,
|
||||||
$this->question,
|
$this->question,
|
||||||
$this->answerText
|
$this->answerText
|
||||||
);
|
);
|
||||||
@ -150,6 +152,7 @@ class QnanewanswerAction extends Action
|
|||||||
}
|
}
|
||||||
if ($this->boolean('ajax')) {
|
if ($this->boolean('ajax')) {
|
||||||
common_debug("ajaxy part");
|
common_debug("ajaxy part");
|
||||||
|
$answer = $this->question->getAnswer($profile);
|
||||||
header('Content-Type: text/xml;charset=utf-8');
|
header('Content-Type: text/xml;charset=utf-8');
|
||||||
$this->xw->startDocument('1.0', 'UTF-8');
|
$this->xw->startDocument('1.0', 'UTF-8');
|
||||||
$this->elementStart('html');
|
$this->elementStart('html');
|
||||||
@ -158,7 +161,7 @@ class QnanewanswerAction extends Action
|
|||||||
$this->element('title', null, _m('Answers'));
|
$this->element('title', null, _m('Answers'));
|
||||||
$this->elementEnd('head');
|
$this->elementEnd('head');
|
||||||
$this->elementStart('body');
|
$this->elementStart('body');
|
||||||
$this->raw($this->answer->asHTML());
|
$this->raw($answer->asHTML());
|
||||||
$this->elementEnd('body');
|
$this->elementEnd('body');
|
||||||
$this->elementEnd('html');
|
$this->elementEnd('html');
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user