MDL-29804 - Clean up Feedback modules coding style

This commit is contained in:
Andreas Grabs
2011-10-28 00:30:42 +02:00
parent 38e9a1cc79
commit 9c5bc7a580
67 changed files with 5875 additions and 4087 deletions
+79 -49
View File
@@ -1,31 +1,41 @@
<?php
/**
* prints the forms to choose an item-typ to create items and to choose a template to use
*
* @author Andreas Grabs
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package feedback
*/
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* prints the forms to choose an item-typ to create items and to choose a template to use
*
* @author Andreas Grabs
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package feedback
*/
//It must be included from a Moodle page
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
die('Direct access to this script is forbidden.');
}
require_once $CFG->libdir.'/formslib.php';
require_once($CFG->libdir.'/formslib.php');
class feedback_edit_add_question_form extends moodleform {
function definition() {
public function definition() {
$mform =& $this->_form;
//headline
$mform->addElement('header', 'general', get_string('add_items', 'feedback'));
// visible elements
// $feedback_names = feedback_load_feedback_items('mod/feedback/item');
// $feedback_names_options = array();
// $feedback_names_options[' '] = get_string('select');
// foreach($feedback_names as $fn) {
// $feedback_names_options[$fn] = get_string($fn,'feedback');
// }
$feedback_names_options = feedback_load_feedback_items_options();
$attributes = 'onChange="this.form.submit()"';
@@ -36,16 +46,16 @@ class feedback_edit_add_question_form extends moodleform {
$mform->setType('cmid', PARAM_INT);
$mform->addElement('hidden', 'position');
$mform->setType('position', PARAM_INT);
//-------------------------------------------------------------------------------
// buttons
$mform->addElement('submit', 'add_item', get_string('add_item', 'feedback'));
}
}
class feedback_edit_use_template_form extends moodleform {
var $feedbackdata;
private $feedbackdata;
function definition() {
public function definition() {
$this->feedbackdata = new stdClass();
//this function can not be called, because not all data are available at this time
//I use set_form_elements instead
@@ -54,9 +64,9 @@ class feedback_edit_use_template_form extends moodleform {
//this function set the data used in set_form_elements()
//in this form the only value have to set is course
//eg: array('course' => $course)
function set_feedbackdata($data) {
if(is_array($data)) {
foreach($data as $key => $val) {
public function set_feedbackdata($data) {
if (is_array($data)) {
foreach ($data as $key => $val) {
$this->feedbackdata->{$key} = $val;
}
}
@@ -65,7 +75,7 @@ class feedback_edit_use_template_form extends moodleform {
//here the elements will be set
//this function have to be called manually
//the advantage is that the data are already set
function set_form_elements(){
public function set_form_elements() {
$mform =& $this->_form;
$elementgroup = array();
@@ -81,58 +91,63 @@ class feedback_edit_use_template_form extends moodleform {
$publictemplates = feedback_get_template_list($this->feedbackdata->course, 'public');
$options = array();
if($owntemplates or $publictemplates) {
if ($owntemplates or $publictemplates) {
$options[''] = array('' => get_string('choose'));
if($owntemplates) {
if ($owntemplates) {
$courseoptions = array();
foreach($owntemplates as $template) {
foreach ($owntemplates as $template) {
$courseoptions[$template->id] = $template->name;
}
$options[get_string('course')] = $courseoptions;
}
if($publictemplates) {
if ($publictemplates) {
$publicoptions = array();
foreach($publictemplates as $template) {
foreach ($publictemplates as $template) {
$publicoptions[$template->id] = $template->name;
}
$options[get_string('public', 'feedback')] = $publicoptions;
}
$attributes = 'onChange="this.form.submit()"';
$elementgroup[] =& $mform->createElement('selectgroups', 'templateid', '', $options, $attributes);
$elementgroup[] =& $mform->createElement('submit', 'use_template', get_string('use_this_template', 'feedback'));
}else {
$elementgroup[] =& $mform->createElement('selectgroups',
'templateid',
'',
$options,
$attributes);
$elementgroup[] =& $mform->createElement('submit',
'use_template',
get_string('use_this_template', 'feedback'));
} else {
$mform->addElement('static', 'info', get_string('no_templates_available_yet', 'feedback'));
}
$mform->addGroup($elementgroup, 'elementgroup', '', array(' '), false);
//-------------------------------------------------------------------------------
}
}
class feedback_edit_create_template_form extends moodleform {
var $feedbackdata;
private $feedbackdata;
function definition() {
public function definition() {
}
function data_preprocessing(&$default_values){
public function data_preprocessing(&$default_values) {
$default_values['templatename'] = '';
}
function set_feedbackdata($data) {
if(is_array($data)) {
foreach($data as $key => $val) {
public function set_feedbackdata($data) {
if (is_array($data)) {
foreach ($data as $key => $val) {
$this->feedbackdata->{$key} = $val;
}
}
}
function set_form_elements(){
public function set_form_elements() {
$mform =& $this->_form;
// $capabilities = $this->feedbackdata->capabilities;
// hidden elements
$mform->addElement('hidden', 'id');
@@ -148,20 +163,35 @@ class feedback_edit_create_template_form extends moodleform {
// visible elements
$elementgroup = array();
$elementgroup[] =& $mform->createElement('static', 'templatenamelabel', get_string('name', 'feedback'));
$elementgroup[] =& $mform->createElement('text', 'templatename', get_string('name', 'feedback'), array('size'=>'40', 'maxlength'=>'200'));
$elementgroup[] =& $mform->createElement('static',
'templatenamelabel',
get_string('name', 'feedback'));
if(has_capability('mod/feedback:createpublictemplate', get_system_context())) {
$elementgroup[] =& $mform->createElement('checkbox', 'ispublic', get_string('public', 'feedback'), get_string('public', 'feedback'));
$elementgroup[] =& $mform->createElement('text',
'templatename',
get_string('name', 'feedback'),
array('size'=>'40', 'maxlength'=>'200'));
if (has_capability('mod/feedback:createpublictemplate', get_system_context())) {
$elementgroup[] =& $mform->createElement('checkbox',
'ispublic',
get_string('public', 'feedback'),
get_string('public', 'feedback'));
}
// buttons
$elementgroup[] =& $mform->createElement('submit', 'create_template', get_string('save_as_new_template', 'feedback'));
$mform->addGroup($elementgroup, 'elementgroup', get_string('name', 'feedback'), array(' '), false);
$elementgroup[] =& $mform->createElement('submit',
'create_template',
get_string('save_as_new_template', 'feedback'));
$mform->addGroup($elementgroup,
'elementgroup',
get_string('name', 'feedback'),
array(' '),
false);
$mform->setType('templatename', PARAM_TEXT);
//-------------------------------------------------------------------------------
}
}