Skip to content

Commit

Permalink
MDL-12133 validate() method tidying up; merged from MOODLE_19_STABLE
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Nov 23, 2007
1 parent 010aa4d commit a78890d
Show file tree
Hide file tree
Showing 44 changed files with 128 additions and 229 deletions.
10 changes: 3 additions & 7 deletions admin/uploaduser_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ function definition_after_data() {
/**
* Server side validation.
*/
function validation($data) {
$errors = array();
function validation($data, $files) {
$errors = parent::validation($data, $files);
$columns =& $this->_customdata;
$optype = $data['uutype'];

Expand Down Expand Up @@ -325,11 +325,7 @@ function validation($data) {
}
}

if (0 == count($errors)){
return true;
} else {
return $errors;
}
return $errors;
}
}
?>
10 changes: 3 additions & 7 deletions course/edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,8 @@ function definition_after_data() {


/// perform some extra moodle validation
function validation($data){
$errors= array();
function validation($data, $files) {
$errors = parent::validation($data, $files);
if ($foundcourses = get_records('course', 'shortname', $data['shortname'])) {
if (!empty($data['id'])) {
unset($foundcourses[$data['id']]);
Expand All @@ -426,11 +426,7 @@ function validation($data){
}
}

if (0 == count($errors)){
return true;
} else {
return $errors;
}
return $errors;
}
}
?>
6 changes: 3 additions & 3 deletions course/import/activities/import_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ function definition() {

}

function validation($data) {
return true;
function validation($data, $files) {
return parent::validation($data, $files);
}

}
Expand All @@ -52,7 +52,7 @@ function definition() {

}

function validation($data) {
function validation($data, $files) {
return true;
}

Expand Down
21 changes: 11 additions & 10 deletions course/moodleform_mod.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ function definition_after_data() {
}
}

if ($mform->elementExists('groupmode')) {
if ($COURSE->groupmodeforce) {
if ($COURSE->groupmodeforce) {
if ($mform->elementExists('groupmode')) {
$mform->hardFreeze('groupmode'); // groupmode can not be changed if forced from course settings
}
}
Expand All @@ -86,8 +86,9 @@ function definition_after_data() {
}

// form verification
function validation($data) {
function validation($data, $files) {
global $COURSE;
$errors = parent::validation($data, $files);

$mform =& $this->_form;

Expand Down Expand Up @@ -115,11 +116,7 @@ function validation($data) {
}
}

if (count($errors) == 0) {
return true;
} else {
return $errors;
}
return $errors;
}

/**
Expand Down Expand Up @@ -181,8 +178,12 @@ function standard_coursemodule_elements($features=null){
}

$mform->addElement('header', 'modstandardelshdr', get_string('modstandardels', 'form'));
if ($features->groups){
$mform->addElement('modgroupmode', 'groupmode', get_string('groupmode'));
if ($features->groups) {
$options = array(NOGROUPS => get_string('groupsnone'),
SEPARATEGROUPS => get_string('groupsseparate'),
VISIBLEGROUPS => get_string('groupsvisible'));
$mform->addElement('select', 'groupmode', get_string('groupmode'), $options, NOGROUPS);
$mform->setHelpButton('groupmode', array('groupmode', get_string('groupmode')));
}

if (!empty($CFG->enablegroupings)) {
Expand Down
10 changes: 3 additions & 7 deletions course/request_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ function definition() {
$this->add_action_buttons();
}

function validation($data) {
$errors = array();
function validation($data, $files) {
$errors = parent::validation($data, $files);
$foundcourses = null;
$foundreqcourses = null;

Expand Down Expand Up @@ -67,12 +67,8 @@ function validation($data) {
}
}
}
if (0 == count($errors)){
return true;
} else {
return $errors;
}

return $errors;
}

}
Expand Down
7 changes: 3 additions & 4 deletions enrol/authorize/enrol_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,10 @@ function definition()
$this->add_action_buttons(false, get_string('sendpaymentbutton', 'enrol_authorize'));
}

function validation($data)
function validation($data, $files)
{
global $CFG;

$errors = array();
$errors = parent::validation($data, $files);

if (AN_METHOD_CC == $data['paymentmethod'])
{
Expand Down Expand Up @@ -209,7 +208,7 @@ function validation($data)
}
}

return (empty($errors) ? true : $errors);
return $errors;
}

private function other_method_available($currentmethod)
Expand Down
10 changes: 3 additions & 7 deletions grade/edit/outcome/edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ function definition_after_data() {
}

/// perform extra validation before submission
function validation($data){
$errors = array();
function validation($data, $files) {
$errors = parent::validation($data, $files);

if ($data['scaleid'] < 1) {
$errors['scaleid'] = get_string('required');
Expand All @@ -149,11 +149,7 @@ function validation($data){
}
}

if (0 == count($errors)){
return true;
} else {
return $errors;
}
return $errors;
}


Expand Down
10 changes: 3 additions & 7 deletions grade/edit/scale/edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ function definition_after_data() {
}

/// perform extra validation before submission
function validation($data){
function validation($data, $files) {
global $CFG, $COURSE;

$errors = array();
$errors = parent::validation($data, $files);

// we can not allow 2 scales with the same exact scale as this creates
// problems for backup/restore
Expand Down Expand Up @@ -148,11 +148,7 @@ function validation($data){
}
}

if (0 == count($errors)){
return true;
} else {
return $errors;
}
return $errors;
}
}

Expand Down
10 changes: 3 additions & 7 deletions grade/edit/tree/calculation_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ function definition_after_data() {
}

/// perform extra validation before submission
function validation($data){
$errors = array();
function validation($data, $files) {
$errors = parent::validation($data, $files);

$mform =& $this->_form;

Expand All @@ -97,11 +97,7 @@ function validation($data){
}
}

if (0 == count($errors)){
return true;
} else {
return $errors;
}
return $errors;
}

}
Expand Down
10 changes: 3 additions & 7 deletions grade/edit/tree/item_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@ function definition_after_data() {


/// perform extra validation before submission
function validation($data){
$errors = array();
function validation($data, $files) {
$errors = parent::validation($data, $files);

if (array_key_exists('idnumber', $data)) {
if ($data['id']) {
Expand Down Expand Up @@ -351,11 +351,7 @@ function validation($data){
}
}

if (0 == count($errors)){
return true;
} else {
return $errors;
}
return $errors;
}

}
Expand Down
10 changes: 3 additions & 7 deletions grade/edit/tree/outcomeitem_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ function definition_after_data() {


/// perform extra validation before submission
function validation($data){
$errors= array();
function validation($data, $files) {
$errors = parent::validation($data, $files);

if (array_key_exists('idnumber', $data)) {
if ($data['id']) {
Expand All @@ -230,11 +230,7 @@ function validation($data){
}
}

if (0 == count($errors)){
return true;
} else {
return $errors;
}
return $errors;
}

}
Expand Down
8 changes: 2 additions & 6 deletions grade/import/xml/grade_import_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function definition () {
}

function validation($data, $files) {
$err = array();
$err = parent::validation($data, $files);
if (empty($data['url']) and empty($files['userfile'])) {
if (array_key_exists('url', $data)) {
$err['url'] = get_string('required');
Expand All @@ -97,11 +97,7 @@ function validation($data, $files) {
$err['url'] = get_string('error');
}

if (count($err) == 0){
return true;
} else {
return $err;
}
return $err;
}
}
?>
9 changes: 2 additions & 7 deletions grade/report/grader/preferences_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,8 @@ function definition() {
}

/// perform some extra moodle validation
function validation($data){
$errors= array();
if (0 == count($errors)){
return true;
} else {
return $errors;
}
function validation($data, $files) {
return parent::validation($data, $files);
}
}
?>
2 changes: 1 addition & 1 deletion group/autogroup_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function definition() {

function validation($data, $files) {
global $CFG, $COURSE;
$errors = array();
$errors = parent::validation($data, $files);

if ($data['allocateby'] != 'no') {
if (!$users = groups_get_potential_members($data['courseid'], $data['roleid'])) {
Expand Down
10 changes: 3 additions & 7 deletions group/group_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ function definition () {
$this->add_action_buttons();
}

function validation($data) {
function validation($data, $files) {
global $COURSE;

$errors = array();
$errors = parent::validation($data, $files);

$name = trim(stripslashes($data['name']));
if ($data['id'] and $group = get_record('groups', 'id', $data['id'])) {
Expand All @@ -59,11 +59,7 @@ function validation($data) {
$errors['name'] = get_string('groupnameexists', 'group', $name);
}

if (count($errors) > 0) {
return $errors;
} else {
return true;
}
return $errors;
}

function get_um() {
Expand Down
10 changes: 3 additions & 7 deletions group/grouping_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ function definition () {
$this->add_action_buttons();
}

function validation($data) {
function validation($data, $files) {
global $COURSE;

$errors = array();
$errors = parent::validation($data, $files);

$name = trim(stripslashes($data['name']));
if ($data['id'] and $grouping = get_record('groupings', 'id', $data['id'])) {
Expand All @@ -44,11 +44,7 @@ function validation($data) {
$errors['name'] = get_string('groupingnameexists', 'group', $name);
}

if (count($errors) > 0) {
return $errors;
} else {
return true;
}
return $errors;
}

}
Expand Down
Loading

0 comments on commit a78890d

Please sign in to comment.