forked from GNUsocial/gnu-social
Make new answers work
This commit is contained in:
parent
7669bed9f3
commit
eeff6285ae
@ -120,9 +120,8 @@ class QnAPlugin extends MicroAppPlugin
|
|||||||
array('action' => 'qnanewquestion')
|
array('action' => 'qnanewquestion')
|
||||||
);
|
);
|
||||||
$m->connect(
|
$m->connect(
|
||||||
'main/qna/newanswer/:id',
|
'main/qna/newanswer',
|
||||||
array('action' => 'qnanewanswer'),
|
array('action' => 'qnanewanswer')
|
||||||
array('id' => $UUIDregex)
|
|
||||||
);
|
);
|
||||||
$m->connect(
|
$m->connect(
|
||||||
'question/vote/:id',
|
'question/vote/:id',
|
||||||
@ -304,13 +303,13 @@ class QnAPlugin extends MicroAppPlugin
|
|||||||
// TRANS: %s is the unpexpected object type.
|
// TRANS: %s is the unpexpected object type.
|
||||||
throw new Exception(
|
throw new Exception(
|
||||||
sprintf(
|
sprintf(
|
||||||
_m('Unexpected type for QnA plugin: %s.'),
|
_m('Unexpected type for QnA plugin: %s.'),
|
||||||
$notice->object_type
|
$notice->object_type
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function showNoticeQuestion($notice, $out)
|
function showNoticeQuestion($notice, $out)
|
||||||
{
|
{
|
||||||
$user = common_current_user();
|
$user = common_current_user();
|
||||||
@ -321,7 +320,7 @@ class QnAPlugin extends MicroAppPlugin
|
|||||||
|
|
||||||
$out->elementStart('div', array('class' => 'entry-content question-content'));
|
$out->elementStart('div', array('class' => 'entry-content question-content'));
|
||||||
$question = QnA_Question::getByNotice($notice);
|
$question = QnA_Question::getByNotice($notice);
|
||||||
|
|
||||||
if ($question) {
|
if ($question) {
|
||||||
if ($user) {
|
if ($user) {
|
||||||
$profile = $user->getProfile();
|
$profile = $user->getProfile();
|
||||||
|
@ -45,12 +45,12 @@ if (!defined('STATUSNET')) {
|
|||||||
*/
|
*/
|
||||||
class QnanewanswerAction extends Action
|
class QnanewanswerAction extends Action
|
||||||
{
|
{
|
||||||
protected $user = null;
|
protected $user = null;
|
||||||
protected $error = null;
|
protected $error = null;
|
||||||
protected $complete = null;
|
protected $complete = null;
|
||||||
|
|
||||||
protected $question = null;
|
protected $question = null;
|
||||||
protected $content = null;
|
protected $content = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the title of the action
|
* Returns the title of the action
|
||||||
@ -91,19 +91,22 @@ class QnanewanswerAction extends Action
|
|||||||
$this->checkSessionToken();
|
$this->checkSessionToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
$id = $this->trimmed('id');
|
$id = substr($this->trimmed('id'), 9);
|
||||||
|
|
||||||
|
common_debug("XXXXXXXXXXXXXXXXXX id = " . $id);
|
||||||
|
|
||||||
$this->question = QnA_Question::staticGet('id', $id);
|
$this->question = QnA_Question::staticGet('id', $id);
|
||||||
|
|
||||||
if (empty($this->question)) {
|
if (empty($this->question)) {
|
||||||
// TRANS: Client exception thrown trying to respond to a non-existing question.
|
// TRANS: Client exception thrown trying to respond to a non-existing question.
|
||||||
throw new ClientException(
|
throw new ClientException(
|
||||||
_m('Invalid or missing question.'),
|
_m('Invalid or missing question.'),
|
||||||
404
|
404
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->answerText = $this->trimmed('answer');
|
$this->answerText = $this->trimmed('answer');
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,8 +148,8 @@ class QnanewanswerAction extends Action
|
|||||||
$this->showPage();
|
$this->showPage();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->boolean('ajax')) {
|
if ($this->boolean('ajax')) {
|
||||||
|
common_debug("ajaxy part");
|
||||||
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');
|
||||||
@ -176,7 +179,6 @@ class QnanewanswerAction extends Action
|
|||||||
}
|
}
|
||||||
|
|
||||||
$form = new QnaanswerForm($this->question, $this);
|
$form = new QnaanswerForm($this->question, $this);
|
||||||
|
|
||||||
$form->show();
|
$form->show();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -69,6 +69,12 @@ class QnashowanswerAction extends ShownoticeAction
|
|||||||
throw new ClientException(_('No such answer.'), 404);
|
throw new ClientException(_('No such answer.'), 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->question = $this->answer->getQuestion();
|
||||||
|
|
||||||
|
if (empty($this->question)) {
|
||||||
|
throw new ClientException(_('No question for this answer.'), 404);
|
||||||
|
}
|
||||||
|
|
||||||
$this->notice = Notice::staticGet('uri', $this->answer->uri);
|
$this->notice = Notice::staticGet('uri', $this->answer->uri);
|
||||||
|
|
||||||
if (empty($this->notice)) {
|
if (empty($this->notice)) {
|
||||||
@ -105,9 +111,11 @@ class QnashowanswerAction extends ShownoticeAction
|
|||||||
{
|
{
|
||||||
$question = $this->answer->getQuestion();
|
$question = $this->answer->getQuestion();
|
||||||
|
|
||||||
return sprintf(_('%s\'s answer to "%s"'),
|
return sprintf(
|
||||||
$this->user->nickname,
|
_('%s\'s answer to "%s"'),
|
||||||
$question->title);
|
$this->user->nickname,
|
||||||
|
$question->title
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -121,9 +129,14 @@ class QnashowanswerAction extends ShownoticeAction
|
|||||||
$this->elementStart('h1');
|
$this->elementStart('h1');
|
||||||
$this->element(
|
$this->element(
|
||||||
'a',
|
'a',
|
||||||
array('href' => $this->answer->url),
|
array('href' => $this->answer->uri),
|
||||||
$this->answer->title
|
$this->question->title
|
||||||
);
|
);
|
||||||
$this->elementEnd('h1');
|
$this->elementEnd('h1');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function showContent()
|
||||||
|
{
|
||||||
|
$this->raw($this->answer->asHTML());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -167,11 +167,11 @@ class QnA_Answer extends Managed_DataObject
|
|||||||
*/
|
*/
|
||||||
function getQuestion()
|
function getQuestion()
|
||||||
{
|
{
|
||||||
$question = self::staticGet('id', $this->question_id);
|
$question = QnA_Question::staticGet('id', $this->question_id);
|
||||||
if (empty($question)) {
|
if (empty($question)) {
|
||||||
throw new Exception("No question with ID {$this->question_id}");
|
throw new Exception("No question with ID {$this->question_id}");
|
||||||
}
|
}
|
||||||
return question;
|
return $question;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getProfile()
|
function getProfile()
|
||||||
|
@ -60,7 +60,7 @@ class QnaansweredForm extends Form
|
|||||||
function __construct(QnA_Answer $answer, HTMLOutputter $out)
|
function __construct(QnA_Answer $answer, HTMLOutputter $out)
|
||||||
{
|
{
|
||||||
parent::__construct($out);
|
parent::__construct($out);
|
||||||
$this->question = $answer->getQuestion();
|
$this->question = $answer->getQuestion();
|
||||||
$this->answer = $answer;
|
$this->answer = $answer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ class QnaanswerForm extends Form
|
|||||||
*/
|
*/
|
||||||
function action()
|
function action()
|
||||||
{
|
{
|
||||||
return common_local_url('qnanewanswer', array('id' => $this->question->id));
|
return common_local_url('qnanewanswer');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -104,6 +104,7 @@ class QnaanswerForm extends Form
|
|||||||
$id = "question-" . $question->id;
|
$id = "question-" . $question->id;
|
||||||
|
|
||||||
$out->element('p', 'answer', $question->title);
|
$out->element('p', 'answer', $question->title);
|
||||||
|
$out->hidden('id', $id);
|
||||||
$out->element('input', array('type' => 'text', 'name' => 'answer'));
|
$out->element('input', array('type' => 'text', 'name' => 'answer'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user