本文整理汇总了PHP中quiz_access_manager::validate_settings_form_fields方法的典型用法代码示例。如果您正苦于以下问题:PHP quiz_access_manager::validate_settings_form_fields方法的具体用法?PHP quiz_access_manager::validate_settings_form_fields怎么用?PHP quiz_access_manager::validate_settings_form_fields使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类quiz_access_manager
的用法示例。
在下文中一共展示了quiz_access_manager::validate_settings_form_fields方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validation
public function validation($data, $files)
{
$errors = parent::validation($data, $files);
// Check open and close times are consistent.
if ($data['timeopen'] != 0 && $data['timeclose'] != 0 && $data['timeclose'] < $data['timeopen']) {
$errors['timeclose'] = get_string('closebeforeopen', 'quiz');
}
// Check that the grace period is not too short.
if ($data['overduehandling'] == 'graceperiod') {
$graceperiodmin = get_config('quiz', 'graceperiodmin');
if ($data['graceperiod'] <= $graceperiodmin) {
$errors['graceperiod'] = get_string('graceperiodtoosmall', 'quiz', format_time($graceperiodmin));
}
}
// Check the boundary value is a number or a percentage, and in range.
$i = 0;
while (!empty($data['feedbackboundaries'][$i])) {
$boundary = trim($data['feedbackboundaries'][$i]);
if (strlen($boundary) > 0) {
if ($boundary[strlen($boundary) - 1] == '%') {
$boundary = trim(substr($boundary, 0, -1));
if (is_numeric($boundary)) {
$boundary = $boundary * $data['grade'] / 100.0;
} else {
$errors["feedbackboundaries[{$i}]"] = get_string('feedbackerrorboundaryformat', 'quiz', $i + 1);
}
} else {
if (!is_numeric($boundary)) {
$errors["feedbackboundaries[{$i}]"] = get_string('feedbackerrorboundaryformat', 'quiz', $i + 1);
}
}
}
if (is_numeric($boundary) && $boundary <= 0 || $boundary >= $data['grade']) {
$errors["feedbackboundaries[{$i}]"] = get_string('feedbackerrorboundaryoutofrange', 'quiz', $i + 1);
}
if (is_numeric($boundary) && $i > 0 && $boundary >= $data['feedbackboundaries'][$i - 1]) {
$errors["feedbackboundaries[{$i}]"] = get_string('feedbackerrororder', 'quiz', $i + 1);
}
$data['feedbackboundaries'][$i] = $boundary;
$i += 1;
}
$numboundaries = $i;
// Check there is nothing in the remaining unused fields.
if (!empty($data['feedbackboundaries'])) {
for ($i = $numboundaries; $i < count($data['feedbackboundaries']); $i += 1) {
if (!empty($data['feedbackboundaries'][$i]) && trim($data['feedbackboundaries'][$i]) != '') {
$errors["feedbackboundaries[{$i}]"] = get_string('feedbackerrorjunkinboundary', 'quiz', $i + 1);
}
}
}
for ($i = $numboundaries + 1; $i < count($data['feedbacktext']); $i += 1) {
if (!empty($data['feedbacktext'][$i]['text']) && trim($data['feedbacktext'][$i]['text']) != '') {
$errors["feedbacktext[{$i}]"] = get_string('feedbackerrorjunkinfeedback', 'quiz', $i + 1);
}
}
// Any other rule plugins.
$errors = quiz_access_manager::validate_settings_form_fields($errors, $data, $files, $this);
return $errors;
}
示例2: validation
public function validation($data, $files)
{
$errors = parent::validation($data, $files);
// Check open and close times are consistent.
if ($data['timeopen'] != 0 && $data['timeclose'] != 0 && $data['timeclose'] < $data['timeopen']) {
$errors['timeclose'] = get_string('closebeforeopen', 'quiz');
}
// Check that the grace period is not too short.
if ($data['overduehandling'] == 'graceperiod') {
$graceperiodmin = get_config('quiz', 'graceperiodmin');
if ($data['graceperiod'] <= $graceperiodmin) {
$errors['graceperiod'] = get_string('graceperiodtoosmall', 'quiz', format_time($graceperiodmin));
}
}
if (array_key_exists('completion', $data) && $data['completion'] == COMPLETION_TRACKING_AUTOMATIC) {
$completionpass = isset($data['completionpass']) ? $data['completionpass'] : $this->current->completionpass;
// Show an error if require passing grade was selected and the grade to pass was set to 0.
if ($completionpass && (empty($data['gradepass']) || grade_floatval($data['gradepass']) == 0)) {
if (isset($data['completionpass'])) {
$errors['completionpassgroup'] = get_string('gradetopassnotset', 'quiz');
} else {
$errors['gradepass'] = get_string('gradetopassmustbeset', 'quiz');
}
}
}
// Check the boundary value is a number or a percentage, and in range.
$i = 0;
while (!empty($data['feedbackboundaries'][$i])) {
$boundary = trim($data['feedbackboundaries'][$i]);
if (strlen($boundary) > 0) {
if ($boundary[strlen($boundary) - 1] == '%') {
$boundary = trim(substr($boundary, 0, -1));
if (is_numeric($boundary)) {
$boundary = $boundary * $data['grade'] / 100.0;
} else {
$errors["feedbackboundaries[{$i}]"] = get_string('feedbackerrorboundaryformat', 'quiz', $i + 1);
}
} else {
if (!is_numeric($boundary)) {
$errors["feedbackboundaries[{$i}]"] = get_string('feedbackerrorboundaryformat', 'quiz', $i + 1);
}
}
}
if (is_numeric($boundary) && $boundary <= 0 || $boundary >= $data['grade']) {
$errors["feedbackboundaries[{$i}]"] = get_string('feedbackerrorboundaryoutofrange', 'quiz', $i + 1);
}
if (is_numeric($boundary) && $i > 0 && $boundary >= $data['feedbackboundaries'][$i - 1]) {
$errors["feedbackboundaries[{$i}]"] = get_string('feedbackerrororder', 'quiz', $i + 1);
}
$data['feedbackboundaries'][$i] = $boundary;
$i += 1;
}
$numboundaries = $i;
// Check there is nothing in the remaining unused fields.
if (!empty($data['feedbackboundaries'])) {
for ($i = $numboundaries; $i < count($data['feedbackboundaries']); $i += 1) {
if (!empty($data['feedbackboundaries'][$i]) && trim($data['feedbackboundaries'][$i]) != '') {
$errors["feedbackboundaries[{$i}]"] = get_string('feedbackerrorjunkinboundary', 'quiz', $i + 1);
}
}
}
for ($i = $numboundaries + 1; $i < count($data['feedbacktext']); $i += 1) {
if (!empty($data['feedbacktext'][$i]['text']) && trim($data['feedbacktext'][$i]['text']) != '') {
$errors["feedbacktext[{$i}]"] = get_string('feedbackerrorjunkinfeedback', 'quiz', $i + 1);
}
}
// Any other rule plugins.
$errors = quiz_access_manager::validate_settings_form_fields($errors, $data, $files, $this);
return $errors;
}