Skip to content

Commit

Permalink
Merge branch 'MDL-30559' of git://github.com/timhunt/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
Aparup Banerjee committed Dec 13, 2011
2 parents 099f23b + af4e440 commit 9b91efe
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
31 changes: 29 additions & 2 deletions course/moodleform_mod.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,35 @@ function validation($data, $files) {
$errors['availablefrom'] = get_string('badavailabledates', 'condition');
}

// Conditions: Verify that the grade conditions are numbers, and make sense.
if (array_key_exists('conditiongradegroup', $data)) {
foreach ($data['conditiongradegroup'] as $i => $gradedata) {
if ($gradedata['conditiongrademin'] !== '' && !is_numeric($gradedata['conditiongrademin'])) {
$errors["conditiongradegroup[{$i}]"] = get_string('gradesmustbenumeric', 'condition');
continue;
}
if ($gradedata['conditiongrademax'] !== '' && !is_numeric($gradedata['conditiongrademax'])) {
$errors["conditiongradegroup[{$i}]"] = get_string('gradesmustbenumeric', 'condition');
continue;
}
if ($gradedata['conditiongrademin'] !== '' && $gradedata['conditiongrademax'] !== '' &&
$gradedata['conditiongrademax'] < $gradedata['conditiongrademin']) {
$errors["conditiongradegroup[{$i}]"] = get_string('badgradelimits', 'condition');
continue;
}
if ($gradedata['conditiongrademin'] === '' && $gradedata['conditiongrademax'] === '' &&
$gradedata['conditiongradeitemid']) {
$errors["conditiongradegroup[{$i}]"] = get_string('gradeitembutnolimits', 'condition');
continue;
}
if (($gradedata['conditiongrademin'] !== '' || $gradedata['conditiongrademax'] !== '') &&
!$gradedata['conditiongradeitemid']) {
$errors["conditiongradegroup[{$i}]"] = get_string('gradelimitsbutnoitem', 'condition');
continue;
}
}
}

return $errors;
}

Expand Down Expand Up @@ -471,8 +500,6 @@ function standard_coursemodule_elements(){
$grouparray[] =& $mform->createElement('static', '', '','% '.get_string('grade_upto','condition').' ');
$grouparray[] =& $mform->createElement('text', 'conditiongrademax','',array('size'=>3));
$grouparray[] =& $mform->createElement('static', '', '','%');
$mform->setType('conditiongrademin',PARAM_FLOAT);
$mform->setType('conditiongrademax',PARAM_FLOAT);
$group = $mform->createElement('group','conditiongradegroup',
get_string('gradecondition', 'condition'),$grouparray);

Expand Down
4 changes: 4 additions & 0 deletions lang/en/condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
The difference between access from/to dates and availability settings for the activity is that outside the set dates the latter allows students to view the activity description, whereas access from/to dates prevent access completely.';
$string['availableuntil'] = 'Allow access until';
$string['badavailabledates'] = 'Invalid dates. If you set both dates, the \'Allow access from\' date should be before the \'until\' date.';
$string['badgradelimits'] = 'If you set both an upper and lower grade limit, the upper limit must be higher than the lower limit.';
$string['completion_complete'] = 'must be marked complete';
$string['completioncondition'] = 'Activity completion condition';
$string['completioncondition_help'] = 'This setting determines any activity completion conditions which must be met in order to access the activity. Note that completion tracking must first be set before an activity completion condition can be set.
Expand All @@ -48,6 +49,9 @@
Multiple grade conditions may be set if desired. If so, the activity will only allow access when ALL grade conditions are met.';
$string['grade_upto'] = 'and less than';
$string['gradeitembutnolimits'] = 'You must enter an upper or lower limit, or both.';
$string['gradelimitsbutnoitem'] = 'You must choose a grade item.';
$string['gradesmustbenumeric'] = 'The minimum and maximum grades must be numeric (or blank).';
$string['none'] = '(none)';
$string['notavailableyet'] = 'Not available yet';
$string['requires_completion_0'] = 'Not available unless the activity <strong>{$a}</strong> is incomplete.';
Expand Down

0 comments on commit 9b91efe

Please sign in to comment.