Skip to content

Commit

Permalink
Merge branch 'w16_MDL-32405_m23_estrict4' of git://github.com/skodak/…
Browse files Browse the repository at this point in the history
…moodle
  • Loading branch information
Sam Hemelryk committed Apr 16, 2012
2 parents 788c516 + c990e4b commit a02e2ea
Show file tree
Hide file tree
Showing 17 changed files with 83 additions and 69 deletions.
4 changes: 2 additions & 2 deletions lib/form/selectgroups.php
Expand Up @@ -210,7 +210,7 @@ function getMultiple()
function loadArrayOptGroups($arr, $values=null)
{
if (!is_array($arr)) {
return PEAR::raiseError('Argument 1 of HTML_Select::loadArrayOptGroups is not a valid array');
return self::raiseError('Argument 1 of HTML_Select::loadArrayOptGroups is not a valid array');
}
if (isset($values)) {
$this->setSelected($values);
Expand Down Expand Up @@ -255,7 +255,7 @@ function addOptGroup($text, $value, $attributes=null)
function loadArrayOptions($optgroup, $arr, $values=null)
{
if (!is_array($arr)) {
return PEAR::raiseError('Argument 1 of HTML_Select::loadArray is not a valid array');
return self::raiseError('Argument 1 of HTML_Select::loadArray is not a valid array');
}
if (isset($values)) {
$this->setSelected($values);
Expand Down
4 changes: 2 additions & 2 deletions lib/formslib.php
Expand Up @@ -61,7 +61,7 @@ function pear_handle_error($error){
print_object($error->backtrace);
}

if (!empty($CFG->debug) and $CFG->debug >= DEBUG_ALL){
if (!empty($CFG->debug) and ($CFG->debug >= DEBUG_ALL or $CFG->debug == -1)){
//TODO: this is a wrong place to init PEAR!
$GLOBALS['_PEAR_default_error_mode'] = PEAR_ERROR_CALLBACK;
$GLOBALS['_PEAR_default_error_options'] = 'pear_handle_error';
Expand Down Expand Up @@ -2117,7 +2117,7 @@ function hardFreeze($elementList=null)
}

if (!empty($elementList)) {
return PEAR::raiseError(null, QUICKFORM_NONEXIST_ELEMENT, null, E_USER_WARNING, "Nonexistant element(s): '" . implode("', '", array_keys($elementList)) . "' in HTML_QuickForm::freeze()", 'HTML_QuickForm_Error', true);
return self::raiseError(null, QUICKFORM_NONEXIST_ELEMENT, null, E_USER_WARNING, "Nonexistant element(s): '" . implode("', '", array_keys($elementList)) . "' in HTML_QuickForm::freeze()", 'HTML_QuickForm_Error', true);
}
return true;
}
Expand Down
11 changes: 11 additions & 0 deletions lib/pear/HTML/Common.php
Expand Up @@ -89,6 +89,17 @@ function HTML_Common($attributes = null, $tabOffset = 0)
$this->setTabOffset($tabOffset);
} // end constructor

public static function raiseError($message = null,
$code = null,
$mode = null,
$options = null,
$userinfo = null,
$error_class = null,
$skipmsg = false) {
$pear = new PEAR();
return $pear->raiseError($message, $code, $mode, $options, $userinfo, $error_class, $skipmsg);
}

/**
* Returns the current API version
* @access public
Expand Down
54 changes: 27 additions & 27 deletions lib/pear/HTML/QuickForm.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/pear/HTML/QuickForm/file.php
Expand Up @@ -165,7 +165,7 @@ function onQuickFormEvent($event, $arg, &$caller)
switch ($event) {
case 'updateValue':
if ($caller->getAttribute('method') == 'get') {
return PEAR::raiseError('Cannot add a file upload field to a GET method form');
return self::raiseError('Cannot add a file upload field to a GET method form');
}
$this->_value = $this->_findValue();
$caller->updateAttributes(array('enctype' => 'multipart/form-data'));
Expand Down
6 changes: 3 additions & 3 deletions lib/pear/HTML/QuickForm/select.php
Expand Up @@ -326,7 +326,7 @@ function addOption($text, $value, $attributes=null)
function loadArray($arr, $values=null)
{
if (!is_array($arr)) {
return PEAR::raiseError('Argument 1 of HTML_Select::loadArray is not a valid array');
return self::raiseError('Argument 1 of HTML_Select::loadArray is not a valid array');
}
if (isset($values)) {
$this->setSelected($values);
Expand Down Expand Up @@ -358,7 +358,7 @@ function loadArray($arr, $values=null)
function loadDbResult(&$result, $textCol=null, $valueCol=null, $values=null)
{
if (!is_object($result) || !is_a($result, 'db_result')) {
return PEAR::raiseError('Argument 1 of HTML_Select::loadDbResult is not a valid DB_result');
return self::raiseError('Argument 1 of HTML_Select::loadDbResult is not a valid DB_result');
}
if (isset($values)) {
$this->setValue($values);
Expand Down Expand Up @@ -401,7 +401,7 @@ function loadQuery(&$conn, $sql, $textCol=null, $valueCol=null, $values=null)
} elseif (is_subclass_of($conn, "db_common")) {
$dbConn = &$conn;
} else {
return PEAR::raiseError('Argument 1 of HTML_Select::loadQuery is not a valid type');
return self::raiseError('Argument 1 of HTML_Select::loadQuery is not a valid type');
}
$result = $dbConn->query($sql);
if (DB::isError($result)) {
Expand Down
3 changes: 2 additions & 1 deletion user/profile/definelib.php
Expand Up @@ -58,7 +58,7 @@ function define_form_common(&$form) {
* editing a profile field specific to the current data type
* @param object instance of the moodleform class
*/
function define_form_specific(&$form) {
function define_form_specific($form) {
/// do nothing - overwrite if necessary
}

Expand Down Expand Up @@ -115,6 +115,7 @@ function define_validate_common($data, $files) {
* Validate the data from the add/edit profile field form
* that is specific to the current data type
* @param object data from the add/edit profile field form
* @param array files
* @return array associative array of error messages
*/
function define_validate_specific($data, $files) {
Expand Down
2 changes: 1 addition & 1 deletion user/profile/field/checkbox/define.class.php
Expand Up @@ -2,7 +2,7 @@

class profile_define_checkbox extends profile_define_base {

function define_form_specific(&$form) {
function define_form_specific($form) {
/// select whether or not this should be checked by default
$form->addElement('selectyesno', 'defaultdata', get_string('profiledefaultchecked', 'admin'));
$form->setDefault('defaultdata', 0); // defaults to 'no'
Expand Down
4 changes: 2 additions & 2 deletions user/profile/field/checkbox/field.class.php
Expand Up @@ -22,9 +22,9 @@ function profile_field_checkbox($fieldid=0, $userid=0) {
}
}

function edit_field_add(&$mform) {
function edit_field_add($mform) {
/// Create the form field
$checkbox = &$mform->addElement('advcheckbox', $this->inputname, format_string($this->field->name));
$checkbox = $mform->addElement('advcheckbox', $this->inputname, format_string($this->field->name));
if ($this->data == '1') {
$checkbox->setChecked(true);
}
Expand Down
3 changes: 2 additions & 1 deletion user/profile/field/datetime/define.class.php
Expand Up @@ -47,9 +47,10 @@ function define_form_specific($form) {
* Validate the data from the profile field form
*
* @param object data from the add/edit profile field form
* @param array files
* @return array associative array of error messages
*/
function define_validate_specific($data) {
function define_validate_specific($data, $files) {
$errors = array();

// Make sure the start year is not greater than the end year
Expand Down
2 changes: 1 addition & 1 deletion user/profile/field/menu/define.class.php
Expand Up @@ -2,7 +2,7 @@

class profile_define_menu extends profile_define_base {

function define_form_specific(&$form) {
function define_form_specific($form) {
/// Param 1 for menu type contains the options
$form->addElement('textarea', 'param1', get_string('profilemenuoptions', 'admin'), array('rows' => 6, 'cols' => 40));
$form->setType('param1', PARAM_MULTILANG);
Expand Down
15 changes: 8 additions & 7 deletions user/profile/field/menu/field.class.php
Expand Up @@ -34,15 +34,15 @@ function profile_field_menu($fieldid=0, $userid=0) {
* Overwrites the base class method
* @param object moodleform instance
*/
function edit_field_add(&$mform) {
function edit_field_add($mform) {
$mform->addElement('select', $this->inputname, format_string($this->field->name), $this->options);
}

/**
* Set the default value for this field instance
* Overwrites the base class method
*/
function edit_field_set_default(&$mform) {
function edit_field_set_default($mform) {
if (FALSE !==array_search($this->field->defaultdata, $this->options)){
$defaultkey = (int)array_search($this->field->defaultdata, $this->options);
} else {
Expand All @@ -55,10 +55,11 @@ function edit_field_set_default(&$mform) {
* The data from the form returns the key. This should be converted to the
* respective option string to be saved in database
* Overwrites base class accessor method
* @param integer the key returned from the select input in the form
* @param mixed $data - the key returned from the select input in the form
* @param stdClass $datarecord The object that will be used to save the record
*/
function edit_save_data_preprocess($key) {
return isset($this->options[$key]) ? $this->options[$key] : NULL;
function edit_save_data_preprocess($data, $datarecord) {
return isset($this->options[$data]) ? $this->options[$data] : NULL;
}

/**
Expand All @@ -67,15 +68,15 @@ function edit_save_data_preprocess($key) {
* Overwrites the base class method
* @param object user object
*/
function edit_load_user_data(&$user) {
function edit_load_user_data($user) {
$user->{$this->inputname} = $this->datakey;
}

/**
* HardFreeze the field if locked.
* @param object instance of the moodleform class
*/
function edit_field_set_locked(&$mform) {
function edit_field_set_locked($mform) {
if (!$mform->elementExists($this->inputname)) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion user/profile/field/text/define.class.php
Expand Up @@ -2,7 +2,7 @@

class profile_define_text extends profile_define_base {

function define_form_specific(&$form) {
function define_form_specific($form) {
/// Default data
$form->addElement('text', 'defaultdata', get_string('profiledefaultdata', 'admin'), 'size="50"');
$form->setType('defaultdata', PARAM_MULTILANG);
Expand Down
2 changes: 1 addition & 1 deletion user/profile/field/text/field.class.php
Expand Up @@ -26,7 +26,7 @@ function display_data() {
return $data;
}

function edit_field_add(&$mform) {
function edit_field_add($mform) {
$size = $this->field->param1;
$maxlength = $this->field->param2;
$fieldtype = ($this->field->param3 == 1 ? 'password' : 'text');
Expand Down
2 changes: 1 addition & 1 deletion user/profile/field/textarea/define.class.php
Expand Up @@ -2,7 +2,7 @@

class profile_define_textarea extends profile_define_base {

function define_form_specific(&$form) {
function define_form_specific($form) {
/// Default data
$form->addElement('editor', 'defaultdata', get_string('profiledefaultdata', 'admin'));
$form->setType('defaultdata', PARAM_RAW); // we have to trust person with capability to edit this default description
Expand Down
6 changes: 3 additions & 3 deletions user/profile/field/textarea/field.class.php
Expand Up @@ -2,7 +2,7 @@

class profile_field_textarea extends profile_field_base {

function edit_field_add(&$mform) {
function edit_field_add($mform) {
$cols = $this->field->param1;
$rows = $this->field->param2;

Expand All @@ -17,15 +17,15 @@ function is_user_object_data() {
return false;
}

function edit_save_data_preprocess($data, &$datarecord) {
function edit_save_data_preprocess($data, $datarecord) {
if (is_array($data)) {
$datarecord->dataformat = $data['format'];
$data = $data['text'];
}
return $data;
}

function edit_load_user_data(&$user) {
function edit_load_user_data($user) {
if ($this->data !== NULL) {
$this->data = clean_text($this->data, $this->dataformat);
$user->{$this->inputname} = array('text'=>$this->data, 'format'=>$this->dataformat);
Expand Down
30 changes: 15 additions & 15 deletions user/profile/lib.php
Expand Up @@ -43,7 +43,7 @@ function profile_field_base($fieldid=0, $userid=0) {
* Abstract method: Adds the profile field to the moodle form class
* @param form instance of the moodleform class
*/
function edit_field_add(&$mform) {
function edit_field_add($mform) {
print_error('mustbeoveride', 'debug', '', 'edit_field_add');
}

Expand All @@ -64,7 +64,7 @@ function display_data() {
* @param object instance of the moodleform class
* $return boolean
*/
function edit_field(&$mform) {
function edit_field($mform) {

if ($this->field->visible != PROFILE_VISIBLE_NONE
or has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM))) {
Expand All @@ -82,7 +82,7 @@ function edit_field(&$mform) {
* @param object instance of the moodleform class
* $return boolean
*/
function edit_after_data(&$mform) {
function edit_after_data($mform) {

if ($this->field->visible != PROFILE_VISIBLE_NONE
or has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM))) {
Expand Down Expand Up @@ -158,7 +158,7 @@ function edit_validate_field($usernew) {
* Sets the default data for the field in the form object
* @param object instance of the moodleform class
*/
function edit_field_set_default(&$mform) {
function edit_field_set_default($mform) {
if (!empty($default)) {
$mform->setDefault($this->inputname, $this->field->defaultdata);
}
Expand All @@ -168,7 +168,7 @@ function edit_field_set_default(&$mform) {
* Sets the required flag for the field in the form object
* @param object instance of the moodleform class
*/
function edit_field_set_required(&$mform) {
function edit_field_set_required($mform) {
if ($this->is_required() and !has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM))) {
$mform->addRule($this->inputname, get_string('required'), 'required', null, 'client');
}
Expand All @@ -178,7 +178,7 @@ function edit_field_set_required(&$mform) {
* HardFreeze the field if locked.
* @param object instance of the moodleform class
*/
function edit_field_set_locked(&$mform) {
function edit_field_set_locked($mform) {
if (!$mform->elementExists($this->inputname)) {
return;
}
Expand All @@ -190,11 +190,11 @@ function edit_field_set_locked(&$mform) {

/**
* Hook for child classess to process the data before it gets saved in database
* @param mixed
* @param stdClass The object that will be used to save the record
* @param mixed $data
* @param stdClass $datarecord The object that will be used to save the record
* @return mixed
*/
function edit_save_data_preprocess($data, &$datarecord) {
function edit_save_data_preprocess($data, $datarecord) {
return $data;
}

Expand All @@ -203,7 +203,7 @@ function edit_save_data_preprocess($data, &$datarecord) {
* form
* @param object a user object
*/
function edit_load_user_data(&$user) {
function edit_load_user_data($user) {
if ($this->data !== NULL) {
$user->{$this->inputname} = $this->data;
}
Expand Down Expand Up @@ -336,7 +336,7 @@ function is_signup_field() {

/***** General purpose functions for customisable user profiles *****/

function profile_load_data(&$user) {
function profile_load_data($user) {
global $CFG, $DB;

if ($fields = $DB->get_records('user_info_field')) {
Expand All @@ -353,7 +353,7 @@ function profile_load_data(&$user) {
* Print out the customisable categories and fields for a users profile
* @param object instance of the moodleform class
*/
function profile_definition(&$mform) {
function profile_definition($mform) {
global $CFG, $DB;

// if user is "admin" fields are displayed regardless
Expand Down Expand Up @@ -386,7 +386,7 @@ function profile_definition(&$mform) {
}
}

function profile_definition_after_data(&$mform, $userid) {
function profile_definition_after_data($mform, $userid) {
global $CFG, $DB;

$userid = ($userid < 0) ? 0 : (int)$userid;
Expand Down Expand Up @@ -453,7 +453,7 @@ function profile_display_fields($userid) {
* should appear on the signup page
* @param object moodle form object
*/
function profile_signup_fields(&$mform) {
function profile_signup_fields($mform) {
global $CFG, $DB;

//only retrieve required custom fields (with category information)
Expand Down Expand Up @@ -513,7 +513,7 @@ function profile_user_record($userid) {
* @param object $user user object
* @return void $user object is modified
*/
function profile_load_custom_fields(&$user) {
function profile_load_custom_fields($user) {
$user->profile = (array)profile_user_record($user->id);
}

Expand Down

0 comments on commit a02e2ea

Please sign in to comment.