| 
									
										
										
										
											2011-04-04 01:27:38 -07: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-04 23:58:35 -07:00
										 |  |  |      * The answer to show | 
					
						
							| 
									
										
										
										
											2011-04-04 01:27:38 -07:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2011-04-04 23:58:35 -07:00
										 |  |  |     protected $answer   = null; | 
					
						
							| 
									
										
										
										
											2011-04-04 01:27:38 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * The question this is an answer to | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2011-04-04 23:58:35 -07:00
										 |  |  |     protected $question = null; | 
					
						
							| 
									
										
										
										
											2011-04-04 01:27:38 -07: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-04 22:04:36 -07:00
										 |  |  |         $this->answer   = $answer; | 
					
						
							|  |  |  |         $this->question = $answer->getQuestion(); | 
					
						
							| 
									
										
										
										
											2011-04-04 01:27:38 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * ID of the form | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return int ID of the form | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     function id() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2011-04-04 23:58:35 -07:00
										 |  |  |         return 'show-' . $this->answer->id; | 
					
						
							| 
									
										
										
										
											2011-04-04 01:27:38 -07: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-04 23:58:35 -07:00
										 |  |  |         // TRANS: Form legend for showing the answer.
 | 
					
						
							|  |  |  |         $this->out->element('legend', null, _('Answer')); | 
					
						
							| 
									
										
										
										
											2011-04-04 01:27:38 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Data elements | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return void | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     function formData() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->out->hidden( | 
					
						
							| 
									
										
										
										
											2011-04-17 16:32:52 -07:00
										 |  |  |             'qna-answer-id', | 
					
						
							|  |  |  |             'answer-' . $this->answer->id, | 
					
						
							|  |  |  |             'id' | 
					
						
							| 
									
										
										
										
											2011-04-04 01:27:38 -07:00
										 |  |  |         ); | 
					
						
							| 
									
										
										
										
											2011-04-04 23:58:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-05 00:27:51 -07:00
										 |  |  |         $this->out->raw($this->answer->asHTML()); | 
					
						
							| 
									
										
										
										
											2011-04-04 01:27:38 -07: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-17 16:32:52 -07:00
										 |  |  |                         'qna-best-answer', | 
					
						
							| 
									
										
										
										
											2011-04-04 01:27:38 -07:00
										 |  |  |                         // TRANS: Button text for marking an answer as "best"
 | 
					
						
							|  |  |  |                         _m('BUTTON', 'Best'), | 
					
						
							|  |  |  |                         'submit', | 
					
						
							| 
									
										
										
										
											2011-04-18 15:31:48 -07:00
										 |  |  |                         'best', | 
					
						
							| 
									
										
										
										
											2011-04-04 01:27:38 -07:00
										 |  |  |                         // TRANS: Title for button text marking an answer as "best"
 | 
					
						
							|  |  |  |                         _('Mark as best answer') | 
					
						
							|  |  |  |                     ); | 
					
						
							|  |  |  |          | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2011-04-04 22:04:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |             /* | 
					
						
							|  |  |  |              * @fixme: Revise is disabled until we figure out the | 
					
						
							|  |  |  |              *         Ostatus bits This comment is just a reminder | 
					
						
							|  |  |  |              *         that the UI for this works. | 
					
						
							|  |  |  |              */ | 
					
						
							|  |  |  |             /* | 
					
						
							| 
									
										
										
										
											2011-04-04 01:27:38 -07:00
										 |  |  |             if ($user->id == $this->answer->profile_id) { | 
					
						
							|  |  |  |                 $this->out->submit( | 
					
						
							|  |  |  |                     'revise', | 
					
						
							|  |  |  |                     // TRANS: Button text for revising an answer
 | 
					
						
							|  |  |  |                     _m('BUTTON', 'Revise'), | 
					
						
							|  |  |  |                     'submit', | 
					
						
							|  |  |  |                     null, | 
					
						
							|  |  |  |                     // TRANS: Title for button text for revising an answer
 | 
					
						
							|  |  |  |                     _('Revise your answer') | 
					
						
							|  |  |  |                 ); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2011-04-04 22:04:36 -07:00
										 |  |  |              */ | 
					
						
							| 
									
										
										
										
											2011-04-04 01:27:38 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Class of the form. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return string the form's class | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     function formClass() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2011-04-18 02:27:56 -07:00
										 |  |  |         return 'form_answer_show ajax'; | 
					
						
							| 
									
										
										
										
											2011-04-04 01:27:38 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | } |