2011-04-04 09:27:38 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* StatusNet, the distributed open-source microblogging tool
|
|
|
|
*
|
|
|
|
* Form for showing / revising an answer
|
|
|
|
*
|
|
|
|
* PHP version 5
|
|
|
|
*
|
|
|
|
* LICENCE: This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* @category Form
|
|
|
|
* @package StatusNet
|
|
|
|
* @author Zach Copley <zach@status.net>
|
|
|
|
* @copyright 2011 StatusNet, Inc.
|
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
|
|
|
* @link http://status.net/
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!defined('STATUSNET')) {
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
require_once INSTALLDIR . '/lib/form.php';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Form for showing / revising an answer
|
|
|
|
*
|
|
|
|
* @category Form
|
|
|
|
* @package StatusNet
|
|
|
|
* @author Zach Copley <zach@status.net>
|
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
|
|
|
* @link http://status.net/
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class QnashowanswerForm extends Form
|
|
|
|
{
|
|
|
|
/**
|
2011-04-05 07:58:35 +01:00
|
|
|
* The answer to show
|
2011-04-04 09:27:38 +01:00
|
|
|
*/
|
2011-04-05 07:58:35 +01:00
|
|
|
protected $answer = null;
|
2011-04-04 09:27:38 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The question this is an answer to
|
|
|
|
*/
|
2011-04-05 07:58:35 +01:00
|
|
|
protected $question = null;
|
2011-04-04 09:27:38 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @param HTMLOutputter $out output channel
|
|
|
|
* @param QnA_Answer $answer answer to revise
|
|
|
|
*/
|
|
|
|
function __construct($out = null, $answer = null)
|
|
|
|
{
|
|
|
|
parent::__construct($out);
|
|
|
|
|
2011-04-05 06:04:36 +01:00
|
|
|
$this->answer = $answer;
|
|
|
|
$this->question = $answer->getQuestion();
|
2011-04-04 09:27:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ID of the form
|
|
|
|
*
|
|
|
|
* @return int ID of the form
|
|
|
|
*/
|
|
|
|
function id()
|
|
|
|
{
|
2011-04-05 07:58:35 +01:00
|
|
|
return 'show-' . $this->answer->id;
|
2011-04-04 09:27:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Action of the form
|
|
|
|
*
|
|
|
|
* @return string URL of the action
|
|
|
|
*/
|
|
|
|
function action()
|
|
|
|
{
|
|
|
|
return common_local_url('qnareviseanswer');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Include a session token for CSRF protection
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function sessionToken()
|
|
|
|
{
|
|
|
|
$this->out->hidden(
|
|
|
|
'token',
|
|
|
|
common_session_token()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Legend of the Form
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function formLegend()
|
|
|
|
{
|
2011-04-05 07:58:35 +01:00
|
|
|
// TRANS: Form legend for showing the answer.
|
2011-04-19 20:54:56 +01:00
|
|
|
$this->out->element('legend', null, _m('Answer'));
|
2011-04-04 09:27:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Data elements
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function formData()
|
|
|
|
{
|
|
|
|
$this->out->hidden(
|
2011-04-18 00:32:52 +01:00
|
|
|
'qna-answer-id',
|
|
|
|
'answer-' . $this->answer->id,
|
|
|
|
'id'
|
2011-04-04 09:27:38 +01:00
|
|
|
);
|
2011-04-05 07:58:35 +01:00
|
|
|
|
2011-04-05 08:27:51 +01:00
|
|
|
$this->out->raw($this->answer->asHTML());
|
2011-04-04 09:27:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Action elements
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function formActions()
|
|
|
|
{
|
|
|
|
$user = common_current_user();
|
|
|
|
if (empty($user)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($this->question->closed)) {
|
|
|
|
if ($user->id == $this->question->profile_id) {
|
|
|
|
if (empty($this->answer->best)) {
|
|
|
|
$this->out->submit(
|
2011-04-18 00:32:52 +01:00
|
|
|
'qna-best-answer',
|
2011-06-05 10:06:08 +01:00
|
|
|
// TRANS: Button text for marking an answer as "best".
|
2011-04-04 09:27:38 +01:00
|
|
|
_m('BUTTON', 'Best'),
|
|
|
|
'submit',
|
2011-04-18 23:31:48 +01:00
|
|
|
'best',
|
2011-06-05 10:06:08 +01:00
|
|
|
// TRANS: Title for button text marking an answer as "best".
|
|
|
|
_m('Mark this answer as the best answer.')
|
2011-04-04 09:27:38 +01:00
|
|
|
);
|
2011-04-19 20:54:56 +01:00
|
|
|
|
2011-04-04 09:27:38 +01:00
|
|
|
}
|
|
|
|
}
|
2011-04-05 06:04:36 +01:00
|
|
|
|
|
|
|
/*
|
2011-06-05 10:06:08 +01:00
|
|
|
* @todo FIXME: Revise is disabled until we figure out the
|
2011-04-05 06:04:36 +01:00
|
|
|
* Ostatus bits This comment is just a reminder
|
|
|
|
* that the UI for this works.
|
|
|
|
*/
|
|
|
|
/*
|
2011-04-04 09:27:38 +01:00
|
|
|
if ($user->id == $this->answer->profile_id) {
|
|
|
|
$this->out->submit(
|
|
|
|
'revise',
|
2011-06-05 10:06:08 +01:00
|
|
|
// TRANS: Button text for revising an answer.
|
2011-04-04 09:27:38 +01:00
|
|
|
_m('BUTTON', 'Revise'),
|
|
|
|
'submit',
|
|
|
|
null,
|
2011-06-05 10:06:08 +01:00
|
|
|
// TRANS: Title for button text for revising an answer.
|
|
|
|
_m('Revise your answer.')
|
2011-04-04 09:27:38 +01:00
|
|
|
);
|
|
|
|
}
|
2011-04-05 06:04:36 +01:00
|
|
|
*/
|
2011-04-04 09:27:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class of the form.
|
|
|
|
*
|
|
|
|
* @return string the form's class
|
|
|
|
*/
|
|
|
|
function formClass()
|
|
|
|
{
|
2011-04-18 10:27:56 +01:00
|
|
|
return 'form_answer_show ajax';
|
2011-04-04 09:27:38 +01:00
|
|
|
}
|
|
|
|
}
|