MDL-30974 form: Checked and updated docblock for form library

This commit is contained in:
Rajesh Taneja 2012-01-06 16:38:06 +08:00 committed by Rajesh Taneja
parent 5fc420e2ed
commit 6c1fd30484
39 changed files with 2567 additions and 1156 deletions

View file

@ -1,27 +1,29 @@
<?php
// 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/>.
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.org //
// //
// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
// //
// This program 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 2 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 General Public License for more details: //
// //
// http://www.gnu.org/copyleft/gpl.html //
// //
///////////////////////////////////////////////////////////////////////////
/**
* Duration form element
*
* Contains class to create length of time for element.
*
* @package core_form
* @copyright 2009 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
global $CFG;
require_once($CFG->libdir . '/form/group.php');
@ -29,30 +31,37 @@ require_once($CFG->libdir . '/formslib.php');
require_once($CFG->libdir . '/form/text.php');
/**
* Duration element
*
* HTML class for a length of time. For example, 30 minutes of 4 days. The
* values returned to PHP is the duration in seconds.
*
* @package formslib
* @package core_form
* @category form
* @copyright 2009 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class MoodleQuickForm_duration extends MoodleQuickForm_group {
/**
* Control the fieldnames for form elements
* optional => if true, show a checkbox beside the element to turn it on (or off)
* @var array
*/
protected $_options = array('optional' => false, 'defaultunit' => 60);
/** @var array associative array of time units (days, hours, minutes, seconds) */
private $_units = null;
/**
* Class constructor
* constructor
*
* @access public
* @param string $elementName Element's name
* @param mixed $elementLabel Label(s) for an element
* @param array $options Options to control the element's display. Recognised values are
* 'optional' => true/false - whether to display an 'enabled' checkbox next to the element.
* 'defaultunit' => 1|60|3600|86400 - the default unit to display when the time is blank. If not specified, minutes is used.
* @param mixed $attributes Either a typical HTML attribute string or an associative array
* @param string $elementName Element's name
* @param mixed $elementLabel Label(s) for an element
* @param array $options Options to control the element's display. Recognised values are
'optional' => true/false - whether to display an 'enabled' checkbox next to the element.
'defaultunit' => 1|60|3600|86400 - the default unit to display when the time is blank.
* If not specified, minutes is used.
* @param mixed $attributes Either a typical HTML attribute string or an associative array
*/
function MoodleQuickForm_duration($elementName = null, $elementLabel = null, $options = array(), $attributes = null) {
$this->HTML_QuickForm_element($elementName, $elementLabel, $attributes);
@ -75,6 +84,8 @@ class MoodleQuickForm_duration extends MoodleQuickForm_group {
}
/**
* Returns time associative array of unit length.
*
* @return array unit length in seconds => string unit name.
*/
public function get_units() {
@ -90,9 +101,11 @@ class MoodleQuickForm_duration extends MoodleQuickForm_group {
}
/**
* @param $seconds an amout of time in seconds.
* @return array($number, $unit) Conver an interval to the best possible unit.
* for example 1800 -> array(30, 60) = 30 minutes.
* Converts seconds to the best possible time unit. for example
* 1800 -> array(30, 60) = 30 minutes.
*
* @param int $seconds an amout of time in seconds.
* @return array associative array ($number => $unit)
*/
public function seconds_to_unit($seconds) {
if ($seconds == 0) {
@ -106,7 +119,9 @@ class MoodleQuickForm_duration extends MoodleQuickForm_group {
return array($seconds, 1);
}
// Override of standard quickforms method.
/**
* Override of standard quickforms method to create this element.
*/
function _createElements() {
$attributes = $this->getAttributes();
if (is_null($attributes)) {
@ -130,7 +145,14 @@ class MoodleQuickForm_duration extends MoodleQuickForm_group {
}
}
// Override of standard quickforms method.
/**
* Called by HTML_QuickForm whenever form event is made on this element
*
* @param string $event Name of event
* @param mixed $arg event arguments
* @param object $caller calling object
* @return bool
*/
function onQuickFormEvent($event, $arg, $caller) {
switch ($event) {
case 'updateValue':
@ -174,7 +196,11 @@ class MoodleQuickForm_duration extends MoodleQuickForm_group {
}
}
// Override of standard quickforms method.
/**
* Returns HTML for advchecbox form element.
*
* @return string
*/
function toHtml() {
include_once('HTML/QuickForm/Renderer/Default.php');
$renderer = new HTML_QuickForm_Renderer_Default();
@ -183,7 +209,13 @@ class MoodleQuickForm_duration extends MoodleQuickForm_group {
return $renderer->toHtml();
}
// Override of standard quickforms method.
/**
* Accepts a renderer
*
* @param HTML_QuickForm_Renderer $renderer An HTML_QuickForm_Renderer object
* @param bool $required Whether a group is required
* @param string $error An error message associated with a group
*/
function accept($renderer, $required = false, $error = null) {
$renderer->renderElement($this, $required, $error);
}
@ -192,8 +224,8 @@ class MoodleQuickForm_duration extends MoodleQuickForm_group {
* Output a timestamp. Give it the name of the group.
* Override of standard quickforms method.
*
* @param array $submitValues
* @param bool $notused Not used.
* @param array $submitValues
* @param bool $notused Not used.
* @return array field name => value. The value is the time interval in seconds.
*/
function exportValue($submitValues, $notused = false) {