More plumbing
This commit is contained in:
parent
c1a27922ba
commit
7669bed9f3
@ -50,7 +50,7 @@ class QnanewanswerAction extends Action
|
|||||||
protected $complete = null;
|
protected $complete = null;
|
||||||
|
|
||||||
protected $question = null;
|
protected $question = null;
|
||||||
protected $answerText = null;
|
protected $content = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the title of the action
|
* Returns the title of the action
|
||||||
@ -155,7 +155,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');
|
||||||
$form = new QnA_Answer($this->question, $this);
|
$form = new QnaanswerForm($this->question, $this);
|
||||||
$form->show();
|
$form->show();
|
||||||
$this->elementEnd('body');
|
$this->elementEnd('body');
|
||||||
$this->elementEnd('html');
|
$this->elementEnd('html');
|
||||||
|
@ -103,9 +103,11 @@ class QnashowanswerAction extends ShownoticeAction
|
|||||||
|
|
||||||
function title()
|
function title()
|
||||||
{
|
{
|
||||||
|
$question = $this->answer->getQuestion();
|
||||||
|
|
||||||
return sprintf(_('%s\'s answer to "%s"'),
|
return sprintf(_('%s\'s answer to "%s"'),
|
||||||
$this->user->nickname,
|
$this->user->nickname,
|
||||||
$this->answer->title);
|
$question->title);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -95,6 +95,11 @@ class QnashowquestionAction extends ShownoticeAction
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function showContent()
|
||||||
|
{
|
||||||
|
$this->raw($this->question->asHTML());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Title of the page
|
* Title of the page
|
||||||
*
|
*
|
||||||
|
@ -52,7 +52,7 @@ class QnA_Answer extends Managed_DataObject
|
|||||||
public $profile_id; // int -> question.id
|
public $profile_id; // int -> question.id
|
||||||
public $best; // (boolean) int -> whether the question asker has marked this as the best answer
|
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 $revisions; // int -> count of revisions to this answer
|
||||||
public $text; // text -> response text
|
public $content; // text -> response text
|
||||||
public $created; // datetime
|
public $created; // datetime
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -112,6 +112,7 @@ class QnA_Answer extends Managed_DataObject
|
|||||||
'not null' => true,
|
'not null' => true,
|
||||||
'description' => 'UUID of question being responded to'
|
'description' => 'UUID of question being responded to'
|
||||||
),
|
),
|
||||||
|
'content' => array('type' => 'text'), // got a better name?
|
||||||
'best' => array('type' => 'int', 'size' => 'tiny'),
|
'best' => array('type' => 'int', 'size' => 'tiny'),
|
||||||
'revisions' => array('type' => 'int'),
|
'revisions' => array('type' => 'int'),
|
||||||
'profile_id' => array('type' => 'int'),
|
'profile_id' => array('type' => 'int'),
|
||||||
@ -186,7 +187,8 @@ class QnA_Answer extends Managed_DataObject
|
|||||||
{
|
{
|
||||||
return self::toHTML(
|
return self::toHTML(
|
||||||
$this->getProfile(),
|
$this->getProfile(),
|
||||||
$this->getQuestion()
|
$this->getQuestion(),
|
||||||
|
$this
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,65 +196,43 @@ class QnA_Answer extends Managed_DataObject
|
|||||||
{
|
{
|
||||||
return self::toString(
|
return self::toString(
|
||||||
$this->getProfile(),
|
$this->getProfile(),
|
||||||
$this->getQuestion()
|
$this->getQuestion(),
|
||||||
|
$this
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function toHTML($profile, $event, $response)
|
static function toHTML($profile, $question, $answer)
|
||||||
{
|
{
|
||||||
$fmt = null;
|
$notice = $question->getNotice();
|
||||||
|
|
||||||
$notice = $event->getNotice();
|
$fmt = '<span class="answer_author"><a href="%1s">answer</a> by <a href="%2s">%3s</a></span>';
|
||||||
|
$fmt .= '<span class="answer_content">%4s</span>';
|
||||||
|
|
||||||
switch ($response) {
|
return sprintf(
|
||||||
case 'Y':
|
$fmt,
|
||||||
$fmt = _("<span class='automatic event-rsvp'><a href='%1s'>%2s</a> is attending <a href='%3s'>%4s</a>.</span>");
|
htmlspecialchars($notice->bestUrl()),
|
||||||
break;
|
|
||||||
case 'N':
|
|
||||||
$fmt = _("<span class='automatic event-rsvp'><a href='%1s'>%2s</a> is not attending <a href='%3s'>%4s</a>.</span>");
|
|
||||||
break;
|
|
||||||
case '?':
|
|
||||||
$fmt = _("<span class='automatic event-rsvp'><a href='%1s'>%2s</a> might attend <a href='%3s'>%4s</a>.</span>");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new Exception("Unknown response code {$response}");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return sprintf($fmt,
|
|
||||||
htmlspecialchars($profile->profileurl),
|
htmlspecialchars($profile->profileurl),
|
||||||
htmlspecialchars($profile->getBestName()),
|
htmlspecialchars($profile->getBestName()),
|
||||||
htmlspecialchars($notice->bestUrl()),
|
htmlspecialchars($answer->content)
|
||||||
htmlspecialchars($event->title));
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function toString($profile, $event, $response)
|
static function toString($profile, $question, $answer)
|
||||||
{
|
{
|
||||||
$fmt = null;
|
$notice = $question->getNotice();
|
||||||
|
|
||||||
$notice = $event->getNotice();
|
$fmt = _(
|
||||||
|
'%1s answered the question "%2s": %3s'
|
||||||
|
);
|
||||||
|
|
||||||
switch ($response) {
|
return sprintf(
|
||||||
case 'Y':
|
$fmt,
|
||||||
$fmt = _("%1s is attending %2s.");
|
htmlspecialchars($profile->getBestName()),
|
||||||
break;
|
htmlspecialchars($question->title),
|
||||||
case 'N':
|
htmlspecialchars($answer->content)
|
||||||
$fmt = _("%1s is not attending %2s.");
|
);
|
||||||
break;
|
|
||||||
case '?':
|
|
||||||
$fmt = _("%1s might attend %2s.>");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new Exception("Unknown response code {$response}");
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return sprintf($fmt,
|
|
||||||
$profile->getBestName(),
|
|
||||||
$event->title);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save a new answer notice
|
* Save a new answer notice
|
||||||
*
|
*
|
||||||
@ -274,7 +254,7 @@ class QnA_Answer extends Managed_DataObject
|
|||||||
$answer->question_id = $question->id;
|
$answer->question_id = $question->id;
|
||||||
$answer->revisions = 0;
|
$answer->revisions = 0;
|
||||||
$answer->best = 0;
|
$answer->best = 0;
|
||||||
$answer->text = $text;
|
$answer->content = $text;
|
||||||
$answer->created = common_sql_now();
|
$answer->created = common_sql_now();
|
||||||
$answer->uri = common_local_url(
|
$answer->uri = common_local_url(
|
||||||
'qnashowanswer',
|
'qnashowanswer',
|
||||||
|
@ -146,6 +146,15 @@ class QnA_Question extends Managed_DataObject
|
|||||||
return $this->getNotice()->bestUrl();
|
return $this->getNotice()->bestUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getProfile()
|
||||||
|
{
|
||||||
|
$profile = Profile::staticGet('id', $this->profile_id);
|
||||||
|
if (empty($profile)) {
|
||||||
|
throw new Exception("No profile with ID {$this->profile_id}");
|
||||||
|
}
|
||||||
|
return $profile;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the answer from a particular user to this question, if any.
|
* Get the answer from a particular user to this question, if any.
|
||||||
*
|
*
|
||||||
@ -166,6 +175,18 @@ class QnA_Question extends Managed_DataObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getAnswers()
|
||||||
|
{
|
||||||
|
$a = new QnA_Answer();
|
||||||
|
$a->question_id = $this->id;
|
||||||
|
$cnt = $a->find();
|
||||||
|
if (!empty($cnt)) {
|
||||||
|
return $a;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function countAnswers()
|
function countAnswers()
|
||||||
{
|
{
|
||||||
$a = new QnA_Answer();
|
$a = new QnA_Answer();
|
||||||
@ -178,6 +199,70 @@ class QnA_Question extends Managed_DataObject
|
|||||||
return QnA_Question::staticGet('uri', $notice->uri);
|
return QnA_Question::staticGet('uri', $notice->uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function asHTML()
|
||||||
|
{
|
||||||
|
return self::toHTML(
|
||||||
|
$this->getProfile(),
|
||||||
|
$this,
|
||||||
|
$this->getAnswers()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function asString()
|
||||||
|
{
|
||||||
|
return self::toString(
|
||||||
|
$this->getProfile(),
|
||||||
|
$this,
|
||||||
|
$this->getAnswers()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static function toHTML($profile, $question, $answer)
|
||||||
|
{
|
||||||
|
$notice = $question->getNotice();
|
||||||
|
|
||||||
|
$fmt = '<div class="qna_question">';
|
||||||
|
$fmt .= '<span class="question_title"><a href="%1s">%2s</a></span>';
|
||||||
|
$fmt .= '<span class="question_description">%3s</span>';
|
||||||
|
$fmt .= '<span class="question_author">asked by <a href="%4s">%5s</a></span>';
|
||||||
|
$fmt .= '</div>';
|
||||||
|
|
||||||
|
$q = sprintf(
|
||||||
|
$fmt,
|
||||||
|
htmlspecialchars($notice->bestUrl()),
|
||||||
|
htmlspecialchars($question->title),
|
||||||
|
htmlspecialchars($question->description),
|
||||||
|
htmlspecialchars($profile->profileurl),
|
||||||
|
htmlspecialchars($profile->getBestName())
|
||||||
|
);
|
||||||
|
|
||||||
|
$ans = array();
|
||||||
|
|
||||||
|
$ans[] = '<div class="qna_answers">';
|
||||||
|
|
||||||
|
while($answer->fetch()) {
|
||||||
|
$ans[] = $answer->asHTML();
|
||||||
|
}
|
||||||
|
|
||||||
|
$ans[] .= '</div>';
|
||||||
|
|
||||||
|
return $q . implode($ans);
|
||||||
|
}
|
||||||
|
|
||||||
|
static function toString($profile, $question, $answers)
|
||||||
|
{
|
||||||
|
$fmt = _(
|
||||||
|
'%1s asked the question "%2s": %3s'
|
||||||
|
);
|
||||||
|
|
||||||
|
return sprintf(
|
||||||
|
$fmt,
|
||||||
|
htmlspecialchars($profile->getBestName()),
|
||||||
|
htmlspecialchars($question->title),
|
||||||
|
htmlspecialchars($question->description)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save a new question notice
|
* Save a new question notice
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user