当前位置: 首页>>代码示例>>PHP>>正文


PHP grade_verify_idnumber函数代码示例

本文整理汇总了PHP中grade_verify_idnumber函数的典型用法代码示例。如果您正苦于以下问题:PHP grade_verify_idnumber函数的具体用法?PHP grade_verify_idnumber怎么用?PHP grade_verify_idnumber使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了grade_verify_idnumber函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: validation

 function validation($data, $files)
 {
     global $COURSE, $DB, $CFG;
     $errors = parent::validation($data, $files);
     $mform =& $this->_form;
     $errors = array();
     if ($mform->elementExists('name')) {
         $name = trim($data['name']);
         if ($name == '') {
             $errors['name'] = get_string('required');
         }
     }
     $grade_item = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => $data['modulename'], 'iteminstance' => $data['instance'], 'itemnumber' => 0, 'courseid' => $COURSE->id));
     if ($data['coursemodule']) {
         $cm = $DB->get_record('course_modules', array('id' => $data['coursemodule']));
     } else {
         $cm = null;
     }
     if ($mform->elementExists('cmidnumber')) {
         // verify the idnumber
         if (!grade_verify_idnumber($data['cmidnumber'], $COURSE->id, $grade_item, $cm)) {
             $errors['cmidnumber'] = get_string('idnumbertaken');
         }
     }
     // Ratings: Don't let them select an aggregate type without selecting a scale.
     // If the user has selected to use ratings but has not chosen a scale or set max points then the form is
     // invalid. If ratings have been selected then the user must select either a scale or max points.
     // This matches (horrible) logic in data_preprocessing.
     if (isset($data['assessed']) && $data['assessed'] > 0 && empty($data['scale'])) {
         $errors['assessed'] = get_string('scaleselectionrequired', 'rating');
     }
     // Check that the grade pass is a valid number.
     $gradepassvalid = false;
     if (isset($data['gradepass'])) {
         if (unformat_float($data['gradepass'], true) === false) {
             $errors['gradepass'] = get_string('err_numeric', 'form');
         } else {
             $gradepassvalid = true;
         }
     }
     // Grade to pass: ensure that the grade to pass is valid for points and scales.
     // If we are working with a scale, convert into a positive number for validation.
     if ($gradepassvalid && isset($data['gradepass']) && (!empty($data['grade']) || !empty($data['scale']))) {
         $scale = !empty($data['grade']) ? $data['grade'] : $data['scale'];
         if ($scale < 0) {
             $scalevalues = $DB->get_record('scale', array('id' => -$scale));
             $grade = count(explode(',', $scalevalues->scale));
         } else {
             $grade = $scale;
         }
         if ($data['gradepass'] > $grade) {
             $errors['gradepass'] = get_string('gradepassgreaterthangrade', 'grades', $grade);
         }
     }
     // Completion: Don't let them choose automatic completion without turning
     // on some conditions. Ignore this check when completion settings are
     // locked, as the options are then disabled.
     if (array_key_exists('completion', $data) && $data['completion'] == COMPLETION_TRACKING_AUTOMATIC && !empty($data['completionunlocked'])) {
         if (empty($data['completionview']) && empty($data['completionusegrade']) && !$this->completion_rule_enabled($data)) {
             $errors['completion'] = get_string('badautocompletion', 'completion');
         }
     }
     // Availability: Check availability field does not have errors.
     if (!empty($CFG->enableavailability)) {
         \core_availability\frontend::report_validation_errors($data, $errors);
     }
     return $errors;
 }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:68,代码来源:moodleform_mod.php

示例2: process_module

    protected function process_module($data) {
        global $CFG, $DB;

        $data = (object)$data;
        $oldid = $data->id;

        $this->task->set_old_moduleversion($data->version);

        $data->course = $this->task->get_courseid();
        $data->module = $DB->get_field('modules', 'id', array('name' => $data->modulename));
        // Map section (first try by course_section mapping match. Useful in course and section restores)
        $data->section = $this->get_mappingid('course_section', $data->sectionid);
        if (!$data->section) { // mapping failed, try to get section by sectionnumber matching
            $params = array(
                'course' => $this->get_courseid(),
                'section' => $data->sectionnumber);
            $data->section = $DB->get_field('course_sections', 'id', $params);
        }
        if (!$data->section) { // sectionnumber failed, try to get first section in course
            $params = array(
                'course' => $this->get_courseid());
            $data->section = $DB->get_field('course_sections', 'MIN(id)', $params);
        }
        if (!$data->section) { // no sections in course, create section 0 and 1 and assign module to 1
            $sectionrec = array(
                'course' => $this->get_courseid(),
                'section' => 0);
            $DB->insert_record('course_sections', $sectionrec); // section 0
            $sectionrec = array(
                'course' => $this->get_courseid(),
                'section' => 1);
            $data->section = $DB->insert_record('course_sections', $sectionrec); // section 1
        }
        $data->groupingid= $this->get_mappingid('grouping', $data->groupingid);      // grouping
        if (!$CFG->enablegroupmembersonly) {                                         // observe groupsmemberonly
            $data->groupmembersonly = 0;
        }
        if (!grade_verify_idnumber($data->idnumber, $this->get_courseid())) {        // idnumber uniqueness
            $data->idnumber = '';
        }
        if (empty($CFG->enablecompletion)) { // completion
            $data->completion = 0;
            $data->completiongradeitemnumber = null;
            $data->completionview = 0;
            $data->completionexpected = 0;
        } else {
            $data->completionexpected = $this->apply_date_offset($data->completionexpected);
        }
        if (empty($CFG->enableavailability)) {
            $data->availablefrom = 0;
            $data->availableuntil = 0;
            $data->showavailability = 0;
        } else {
            $data->availablefrom = $this->apply_date_offset($data->availablefrom);
            $data->availableuntil= $this->apply_date_offset($data->availableuntil);
        }
        $data->instance = 0; // Set to 0 for now, going to create it soon (next step)

        // course_module record ready, insert it
        $newitemid = $DB->insert_record('course_modules', $data);
        // save mapping
        $this->set_mapping('course_module', $oldid, $newitemid);
        // set the new course_module id in the task
        $this->task->set_moduleid($newitemid);
        // we can now create the context safely
        $ctxid = get_context_instance(CONTEXT_MODULE, $newitemid)->id;
        // set the new context id in the task
        $this->task->set_contextid($ctxid);
        // update sequence field in course_section
        if ($sequence = $DB->get_field('course_sections', 'sequence', array('id' => $data->section))) {
            $sequence .= ',' . $newitemid;
        } else {
            $sequence = $newitemid;
        }
        $DB->set_field('course_sections', 'sequence', $sequence, array('id' => $data->section));
    }
开发者ID:nottmoo,项目名称:moodle,代码行数:76,代码来源:restore_stepslib.php

示例3: restore_create_gradebook


//.........这里部分代码省略.........
                            $course_category->aggregateoutcomes = backup_todb($cinfo['GRADE_CATEGORY']['#']['AGGREGATEOUTCOMES']['0']['#'], false);
                            $course_category->aggregatesubcats = backup_todb($cinfo['GRADE_CATEGORY']['#']['AGGREGATESUBCATS']['0']['#'], false);
                            $course_category->timecreated = backup_todb($cinfo['GRADE_CATEGORY']['#']['TIMECREATED']['0']['#'], false);
                            $course_category->update('restore');
                            $status = backup_putid($restore->backup_unique_code, 'grade_categories', $oldcat, $course_category->id) && $status;
                            $cached_categories[$oldcat] = $course_category;
                            $grade_item = $course_category->get_grade_item();
                        } else {
                            $oldparent = backup_todb($cinfo['GRADE_CATEGORY']['#']['PARENT']['0']['#'], false);
                            if (empty($cached_categories[$oldparent])) {
                                debugging('parent not found ' . $oldparent);
                                continue;
                                // parent not found, sorry
                            }
                            $grade_category = new grade_category();
                            $grade_category->courseid = $restore->course_id;
                            $grade_category->parent = $cached_categories[$oldparent]->id;
                            $grade_category->fullname = backup_todb($cinfo['GRADE_CATEGORY']['#']['FULLNAME']['0']['#'], false);
                            $grade_category->aggregation = backup_todb($cinfo['GRADE_CATEGORY']['#']['AGGREGATION']['0']['#'], false);
                            $grade_category->keephigh = backup_todb($cinfo['GRADE_CATEGORY']['#']['KEEPHIGH']['0']['#'], false);
                            $grade_category->droplow = backup_todb($cinfo['GRADE_CATEGORY']['#']['DROPLOW']['0']['#'], false);
                            $grade_category->aggregateonlygraded = backup_todb($cinfo['GRADE_CATEGORY']['#']['AGGREGATEONLYGRADED']['0']['#'], false);
                            $grade_category->aggregateoutcomes = backup_todb($cinfo['GRADE_CATEGORY']['#']['AGGREGATEOUTCOMES']['0']['#'], false);
                            $grade_category->aggregatesubcats = backup_todb($cinfo['GRADE_CATEGORY']['#']['AGGREGATESUBCATS']['0']['#'], false);
                            $grade_category->timecreated = backup_todb($cinfo['GRADE_CATEGORY']['#']['TIMECREATED']['0']['#'], false);
                            $grade_category->insert('restore');
                            $status = backup_putid($restore->backup_unique_code, 'grade_categories', $oldcat, $grade_category->id) && $status;
                            $cached_categories[$oldcat] = $grade_category;
                            $grade_item = $grade_category->get_grade_item();
                            // creates grade_item too
                        }
                        unset($cinfo);
                        $idnumber = backup_todb($info['GRADE_ITEM']['#']['IDNUMBER']['0']['#'], false);
                        if (grade_verify_idnumber($idnumber, $restore->course_id)) {
                            $grade_item->idnumber = $idnumber;
                        }
                        $grade_item->itemname = backup_todb($info['GRADE_ITEM']['#']['ITEMNAME']['0']['#'], false);
                        $grade_item->iteminfo = backup_todb($info['GRADE_ITEM']['#']['ITEMINFO']['0']['#'], false);
                        $grade_item->gradetype = backup_todb($info['GRADE_ITEM']['#']['GRADETYPE']['0']['#'], false);
                        $grade_item->calculation = backup_todb($info['GRADE_ITEM']['#']['CALCULATION']['0']['#'], false);
                        $grade_item->grademax = backup_todb($info['GRADE_ITEM']['#']['GRADEMAX']['0']['#'], false);
                        $grade_item->grademin = backup_todb($info['GRADE_ITEM']['#']['GRADEMIN']['0']['#'], false);
                        $grade_item->gradepass = backup_todb($info['GRADE_ITEM']['#']['GRADEPASS']['0']['#'], false);
                        $grade_item->multfactor = backup_todb($info['GRADE_ITEM']['#']['MULTFACTOR']['0']['#'], false);
                        $grade_item->plusfactor = backup_todb($info['GRADE_ITEM']['#']['PLUSFACTOR']['0']['#'], false);
                        $grade_item->aggregationcoef = backup_todb($info['GRADE_ITEM']['#']['AGGREGATIONCOEF']['0']['#'], false);
                        $grade_item->display = backup_todb($info['GRADE_ITEM']['#']['DISPLAY']['0']['#'], false);
                        $grade_item->decimals = backup_todb($info['GRADE_ITEM']['#']['DECIMALS']['0']['#'], false);
                        $grade_item->hidden = backup_todb($info['GRADE_ITEM']['#']['HIDDEN']['0']['#'], false);
                        $grade_item->locked = backup_todb($info['GRADE_ITEM']['#']['LOCKED']['0']['#'], false);
                        $grade_item->locktime = backup_todb($info['GRADE_ITEM']['#']['LOCKTIME']['0']['#'], false);
                        $grade_item->timecreated = backup_todb($info['GRADE_ITEM']['#']['TIMECREATED']['0']['#'], false);
                        if (backup_todb($info['GRADE_ITEM']['#']['SCALEID']['0']['#'], false)) {
                            $scale = backup_getid($restore->backup_unique_code, "scale", backup_todb($info['GRADE_ITEM']['#']['SCALEID']['0']['#'], false));
                            $grade_item->scaleid = $scale->new_id;
                        }
                        if (backup_todb($info['GRADE_ITEM']['#']['OUTCOMEID']['0']['#'], false)) {
                            $outcome = backup_getid($restore->backup_unique_code, "grade_outcomes", backup_todb($info['GRADE_ITEM']['#']['OUTCOMEID']['0']['#'], false));
                            $grade_item->outcomeid = $outcome->new_id;
                        }
                        $grade_item->update('restore');
                        $status = backup_putid($restore->backup_unique_code, "grade_items", $rec->old_id, $grade_item->id) && $status;
                    } else {
                        if ($itemtype != 'mod' and (!$restoreall or $importing)) {
                            // not extra gradebook stuff if restoring individual activities or something already there
                            continue;
开发者ID:kai707,项目名称:ITSA-backup,代码行数:67,代码来源:restorelib.php

示例4: array

$errors = array();
if ($data = $mform->get_data(false)) {
    $calculation = calc_formula::unlocalize($data->calculation);
    $grade_item->set_calculation($calculation);
    redirect($returnurl);
} elseif (!empty($section) and $section = 'idnumbers' and !empty($idnumbers)) {
    // Handle idnumbers separately (non-mform)
    //first validate and store the new idnumbers
    foreach ($idnumbers as $giid => $value) {
        if ($gi = grade_item::fetch(array('id' => $giid))) {
            if ($gi->itemtype == 'mod') {
                $cm = get_coursemodule_from_instance($gi->itemmodule, $gi->iteminstance, $gi->courseid);
            } else {
                $cm = null;
            }
            if (!grade_verify_idnumber($value, $COURSE->id, $gi, $cm)) {
                $errors[$giid] = get_string('idnumbertaken');
                continue;
            }
            if (empty($gi->idnumber) and !$gi->add_idnumber(stripslashes($idnumbers[$gi->id]))) {
                $errors[$giid] = get_string('error');
                continue;
            }
        } else {
            $errors[$giid] = 'Could not fetch the grade_item with id=' . $giid;
        }
    }
}
$gtree = new grade_tree($course->id, false, false);
$strgrades = get_string('grades');
$strgraderreport = get_string('graderreport', 'grades');
开发者ID:arshanam,项目名称:Moodle-ITScholars-LMS,代码行数:31,代码来源:calculation.php

示例5: validation

 function validation($data, $files)
 {
     global $COURSE, $DB;
     $errors = parent::validation($data, $files);
     $mform =& $this->_form;
     $errors = array();
     if ($mform->elementExists('name')) {
         $name = trim($data['name']);
         if ($name == '') {
             $errors['name'] = get_string('required');
         }
     }
     $grade_item = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => $data['modulename'], 'iteminstance' => $data['instance'], 'itemnumber' => 0, 'courseid' => $COURSE->id));
     if ($data['coursemodule']) {
         $cm = $DB->get_record('course_modules', array('id' => $data['coursemodule']));
     } else {
         $cm = null;
     }
     if ($mform->elementExists('cmidnumber')) {
         // verify the idnumber
         if (!grade_verify_idnumber($data['cmidnumber'], $COURSE->id, $grade_item, $cm)) {
             $errors['cmidnumber'] = get_string('idnumbertaken');
         }
     }
     // Completion: Don't let them choose automatic completion without turning
     // on some conditions
     if (array_key_exists('completion', $data) && $data['completion'] == COMPLETION_TRACKING_AUTOMATIC) {
         if (empty($data['completionview']) && empty($data['completionusegrade']) && !$this->completion_rule_enabled($data)) {
             $errors['completion'] = get_string('badautocompletion', 'completion');
         }
     }
     // Conditions: Don't let them set dates which make no sense
     if (array_key_exists('availablefrom', $data) && $data['availablefrom'] && $data['availableuntil'] && $data['availablefrom'] >= $data['availableuntil']) {
         $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(unformat_float($gradedata['conditiongrademin']))) {
                 $errors["conditiongradegroup[{$i}]"] = get_string('gradesmustbenumeric', 'condition');
                 continue;
             }
             if ($gradedata['conditiongrademax'] !== '' && !is_numeric(unformat_float($gradedata['conditiongrademax']))) {
                 $errors["conditiongradegroup[{$i}]"] = get_string('gradesmustbenumeric', 'condition');
                 continue;
             }
             if ($gradedata['conditiongrademin'] !== '' && $gradedata['conditiongrademax'] !== '' && unformat_float($gradedata['conditiongrademax']) <= unformat_float($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;
             }
         }
     }
     // Conditions: Verify that the user profile field has not been declared more than once
     if (array_key_exists('conditionfieldgroup', $data)) {
         // Array to store the existing fields
         $arrcurrentfields = array();
         // Error message displayed if any condition is declared more than once. We use lang string because
         // this way we don't actually generate the string unless there is an error.
         $stralreadydeclaredwarning = new lang_string('fielddeclaredmultipletimes', 'condition');
         foreach ($data['conditionfieldgroup'] as $i => $fielddata) {
             if ($fielddata['conditionfield'] == 0) {
                 // Don't need to bother if none is selected
                 continue;
             }
             if (in_array($fielddata['conditionfield'], $arrcurrentfields)) {
                 $errors["conditionfieldgroup[{$i}]"] = $stralreadydeclaredwarning->out();
             }
             // Add the field to the array
             $arrcurrentfields[] = $fielddata['conditionfield'];
         }
     }
     return $errors;
 }
开发者ID:Burick,项目名称:moodle,代码行数:81,代码来源:moodleform_mod.php

示例6: validation

 function validation($data, $files)
 {
     global $COURSE;
     $errors = parent::validation($data, $files);
     if (array_key_exists('idnumber', $data)) {
         if ($data['id']) {
             $grade_item = new grade_item(array('id' => $data['id'], 'courseid' => $data['courseid']));
             if ($grade_item->itemtype == 'mod') {
                 $cm = get_coursemodule_from_instance($grade_item->itemmodule, $grade_item->iteminstance, $grade_item->courseid);
             } else {
                 $cm = null;
             }
         } else {
             $grade_item = null;
             $cm = null;
         }
         if (!grade_verify_idnumber($data['idnumber'], $COURSE->id, $grade_item, $cm)) {
             $errors['idnumber'] = get_string('idnumbertaken');
         }
     }
     if (array_key_exists('gradetype', $data) and $data['gradetype'] == GRADE_TYPE_SCALE) {
         if (empty($data['scaleid'])) {
             $errors['scaleid'] = get_string('missingscale', 'grades');
         }
     }
     if (array_key_exists('grademin', $data) and array_key_exists('grademax', $data)) {
         if ($data['grademax'] == $data['grademin'] or $data['grademax'] < $data['grademin']) {
             $errors['grademin'] = get_string('incorrectminmax', 'grades');
             $errors['grademax'] = get_string('incorrectminmax', 'grades');
         }
     }
     return $errors;
 }
开发者ID:ajv,项目名称:Offline-Caching,代码行数:33,代码来源:item_form.php

示例7: array

$errors = array();
if ($data = $mform->get_data(false)) {
    $calculation = calc_formula::unlocalize($data->calculation);
    $grade_item->set_calculation($calculation);
    redirect($returnurl);
} elseif (!empty($section) and $section = 'idnumbers' and !empty($idnumbers)) {
    // Handle idnumbers separately (non-mform)
    //first validate and store the new idnumbers
    foreach ($idnumbers as $giid => $value) {
        if ($gi = grade_item::fetch(array('id' => $giid))) {
            if ($gi->itemtype == 'mod') {
                $cm = get_coursemodule_from_instance($gi->itemmodule, $gi->iteminstance, $gi->courseid);
            } else {
                $cm = null;
            }
            if (!grade_verify_idnumber($value, $gi, $cm)) {
                $errors[$giid] = get_string('idnumbertaken');
                continue;
            }
            if (empty($gi->idnumber) and !$gi->add_idnumber(stripslashes($idnumbers[$gi->id]))) {
                $errors[$giid] = get_string('error');
                continue;
            }
        } else {
            $errors[$giid] = 'Could not fetch the grade_item with id=' . $giid;
        }
    }
}
$gtree = new grade_tree($course->id, false, false);
$strgrades = get_string('grades');
$strgraderreport = get_string('graderreport', 'grades');
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:31,代码来源:calculation.php

示例8: process_module

 protected function process_module($data)
 {
     global $CFG, $DB;
     $data = (object) $data;
     $oldid = $data->id;
     $this->task->set_old_moduleversion($data->version);
     // Get the current course module data.
     $newitemid = $this->task->get_moduleid();
     $params = array('id' => $newitemid);
     $cmdata = $DB->get_record('course_modules', $params, '*', MUST_EXIST);
     // Group mode and Grouping.
     $cmdata->groupmode = $data->groupmode;
     $cmdata->groupingid = $this->get_mappingid('grouping', $data->groupingid);
     // Idnumber uniqueness.
     if (!grade_verify_idnumber($data->idnumber, $this->get_courseid())) {
         $data->idnumber = '';
     }
     $cmdata->idnumber = $data->idnumber;
     // Completion.
     if (!empty($CFG->enablecompletion)) {
         $cmdata->completion = $data->completion;
         $cmdata->completiongradeitemnumber = $data->completiongradeitemnumber;
         $cmdata->completionview = $data->completionview;
         $cmdata->completionexpected = $this->apply_date_offset($data->completionexpected);
     }
     // Availability.
     if (empty($CFG->enableavailability)) {
         $data->availability = null;
     }
     if (empty($data->availability)) {
         // If there are legacy availablility data fields (and no new format data),
         // convert the old fields.
         $data->availability = \core_availability\info::convert_legacy_fields($data, false);
     } else {
         if (!empty($data->groupmembersonly)) {
             // There is current availability data, but it still has groupmembersonly
             // as well (2.7 backups), convert just that part.
             require_once $CFG->dirroot . '/lib/db/upgradelib.php';
             $data->availability = upgrade_group_members_only($data->groupingid, $data->availability);
         }
     }
     $cmdata->availability = $data->availability;
     // Backups that did not include showdescription, set it to default 0
     // (this is not totally necessary as it has a db default, but just to
     // be explicit).
     if (!isset($data->showdescription)) {
         $data->showdescription = 0;
     }
     $cmdata->showdescription = $data->showdescription;
     // Course_module record ready, update it.
     $DB->update_record('course_modules', $cmdata);
     // Save mapping.
     $this->set_mapping('course_module', $oldid, $newitemid);
     // Set the new course_module id in the task.
     $this->task->set_moduleid($newitemid);
     // We can now create the context safely.
     $ctxid = context_module::instance($newitemid)->id;
     // Set the new context id in the task.
     $this->task->set_contextid($ctxid);
     // If there is the legacy showavailability data, store this for later use.
     // (This data is not present when restoring 'new' backups.)
     if (isset($cmdata->showavailability)) {
         // Cache the showavailability flag using the backup_ids data field.
         restore_dbops::set_backup_ids_record($this->get_restoreid(), 'module_showavailability', $newitemid, 0, null, (object) array('showavailability' => $cmdata->showavailability));
     }
 }
开发者ID:parksandwildlife,项目名称:learning,代码行数:66,代码来源:restore_dataform_activity_task.class.php

示例9: validation

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

        $mform =& $this->_form;

        $errors = array();

        if ($mform->elementExists('name')) {
            $name = trim($data['name']);
            if ($name == '') {
                $errors['name'] = get_string('required');
            }
        }

        $grade_item = grade_item::fetch(array('itemtype'=>'mod', 'itemmodule'=>$data['modulename'],
                     'iteminstance'=>$data['instance'], 'itemnumber'=>0, 'courseid'=>$COURSE->id));
        if ($data['coursemodule']) {
            $cm = $DB->get_record('course_modules', array('id'=>$data['coursemodule']));
        } else {
            $cm = null;
        }

        if ($mform->elementExists('cmidnumber')) {
            // verify the idnumber
            if (!grade_verify_idnumber($data['cmidnumber'], $COURSE->id, $grade_item, $cm)) {
                $errors['cmidnumber'] = get_string('idnumbertaken');
            }
        }

        // Completion: Don't let them choose automatic completion without turning
        // on some conditions. Ignore this check when completion settings are
        // locked, as the options are then disabled.
        if (array_key_exists('completion', $data) &&
                $data['completion'] == COMPLETION_TRACKING_AUTOMATIC &&
                !empty($data['completionunlocked'])) {
            if (empty($data['completionview']) && empty($data['completionusegrade']) &&
                !$this->completion_rule_enabled($data)) {
                $errors['completion'] = get_string('badautocompletion', 'completion');
            }
        }

        // Conditions: Don't let them set dates which make no sense
        if (array_key_exists('availablefrom', $data) &&
            $data['availablefrom'] && $data['availableuntil'] &&
            $data['availablefrom'] >= $data['availableuntil']) {
            $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(unformat_float($gradedata['conditiongrademin']))) {
                    $errors["conditiongradegroup[{$i}]"] = get_string('gradesmustbenumeric', 'condition');
                    continue;
                }
                if ($gradedata['conditiongrademax'] !== '' &&
                        !is_numeric(unformat_float($gradedata['conditiongrademax']))) {
                    $errors["conditiongradegroup[{$i}]"] = get_string('gradesmustbenumeric', 'condition');
                    continue;
                }
                if ($gradedata['conditiongrademin'] !== '' && $gradedata['conditiongrademax'] !== '' &&
                        unformat_float($gradedata['conditiongrademax']) <= unformat_float($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;
    }
开发者ID:ncsu-delta,项目名称:moodle,代码行数:82,代码来源:moodleform_mod.php

示例10: validation

 function validation($data, $files)
 {
     global $COURSE, $DB;
     $errors = parent::validation($data, $files);
     $mform =& $this->_form;
     $errors = array();
     if ($mform->elementExists('name')) {
         $name = trim($data['name']);
         if ($name == '') {
             $errors['name'] = get_string('required');
         }
     }
     $grade_item = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => $data['modulename'], 'iteminstance' => $data['instance'], 'itemnumber' => 0, 'courseid' => $COURSE->id));
     if ($data['coursemodule']) {
         $cm = $DB->get_record('course_modules', array('id' => $data['coursemodule']));
     } else {
         $cm = null;
     }
     if ($mform->elementExists('cmidnumber')) {
         // verify the idnumber
         if (!grade_verify_idnumber($data['cmidnumber'], $COURSE->id, $grade_item, $cm)) {
             $errors['cmidnumber'] = get_string('idnumbertaken');
         }
     }
     // Completion: Don't let them choose automatic completion without turning
     // on some conditions
     if (array_key_exists('completion', $data) && $data['completion'] == COMPLETION_TRACKING_AUTOMATIC) {
         if (empty($data['completionview']) && empty($data['completionusegrade']) && !$this->completion_rule_enabled($data)) {
             $errors['completion'] = get_string('badautocompletion', 'completion');
         }
     }
     // Conditions: Don't let them set dates which make no sense
     if (array_key_exists('availablefrom', $data) && $data['availablefrom'] && $data['availableuntil'] && $data['availablefrom'] > $data['availableuntil']) {
         $errors['availablefrom'] = get_string('badavailabledates', 'condition');
     }
     return $errors;
 }
开发者ID:ravivare,项目名称:moodle-1,代码行数:37,代码来源:moodleform_mod.php

示例11: validation

 function validation($data, $files)
 {
     global $COURSE, $DB, $CFG;
     $errors = parent::validation($data, $files);
     $mform =& $this->_form;
     $errors = array();
     if ($mform->elementExists('name')) {
         $name = trim($data['name']);
         if ($name == '') {
             $errors['name'] = get_string('required');
         }
     }
     $grade_item = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => $data['modulename'], 'iteminstance' => $data['instance'], 'itemnumber' => 0, 'courseid' => $COURSE->id));
     if ($data['coursemodule']) {
         $cm = $DB->get_record('course_modules', array('id' => $data['coursemodule']));
     } else {
         $cm = null;
     }
     if ($mform->elementExists('cmidnumber')) {
         // verify the idnumber
         if (!grade_verify_idnumber($data['cmidnumber'], $COURSE->id, $grade_item, $cm)) {
             $errors['cmidnumber'] = get_string('idnumbertaken');
         }
     }
     // Completion: Don't let them choose automatic completion without turning
     // on some conditions. Ignore this check when completion settings are
     // locked, as the options are then disabled.
     if (array_key_exists('completion', $data) && $data['completion'] == COMPLETION_TRACKING_AUTOMATIC && !empty($data['completionunlocked'])) {
         if (empty($data['completionview']) && empty($data['completionusegrade']) && !$this->completion_rule_enabled($data)) {
             $errors['completion'] = get_string('badautocompletion', 'completion');
         }
     }
     // Availability: Check availability field does not have errors.
     if (!empty($CFG->enableavailability)) {
         \core_availability\frontend::report_validation_errors($data, $errors);
     }
     return $errors;
 }
开发者ID:gwsd2015,项目名称:LogiClass,代码行数:38,代码来源:moodleform_mod.php

示例12: validation

 function validation($data, $files)
 {
     global $COURSE;
     $grade_item = false;
     if ($data['id']) {
         $grade_item = new grade_item(array('id' => $data['id'], 'courseid' => $data['courseid']));
     }
     $errors = parent::validation($data, $files);
     if (array_key_exists('idnumber', $data)) {
         if ($grade_item) {
             if ($grade_item->itemtype == 'mod') {
                 $cm = get_coursemodule_from_instance($grade_item->itemmodule, $grade_item->iteminstance, $grade_item->courseid);
             } else {
                 $cm = null;
             }
         } else {
             $grade_item = null;
             $cm = null;
         }
         if (!grade_verify_idnumber($data['idnumber'], $COURSE->id, $grade_item, $cm)) {
             $errors['idnumber'] = get_string('idnumbertaken');
         }
     }
     if (array_key_exists('gradetype', $data) and $data['gradetype'] == GRADE_TYPE_SCALE) {
         if (empty($data['scaleid'])) {
             $errors['scaleid'] = get_string('missingscale', 'grades');
         }
     }
     if (array_key_exists('grademin', $data) and array_key_exists('grademax', $data)) {
         if ($data['grademax'] == $data['grademin'] or $data['grademax'] < $data['grademin']) {
             $errors['grademin'] = get_string('incorrectminmax', 'grades');
             $errors['grademax'] = get_string('incorrectminmax', 'grades');
         }
     }
     // We do not want the user to be able to change the grade type or scale for this item if grades exist.
     if ($grade_item && $grade_item->has_grades()) {
         // Check that grade type is set - should never not be set unless form has been modified.
         if (!isset($data['gradetype'])) {
             $errors['gradetype'] = get_string('modgradecantchangegradetype', 'grades');
         } else {
             if ($data['gradetype'] !== $grade_item->gradetype) {
                 // Check if we are changing the grade type.
                 $errors['gradetype'] = get_string('modgradecantchangegradetype', 'grades');
             } else {
                 if ($data['gradetype'] == GRADE_TYPE_SCALE) {
                     // Check if we are changing the scale - can't do this when grades exist.
                     if (isset($data['scaleid']) && $data['scaleid'] !== $grade_item->scaleid) {
                         $errors['scaleid'] = get_string('modgradecantchangescale', 'grades');
                     }
                 }
             }
         }
     }
     if ($grade_item) {
         if ($grade_item->gradetype == GRADE_TYPE_VALUE) {
             if (grade_floats_different($data['grademin'], $grade_item->grademin) || grade_floats_different($data['grademax'], $grade_item->grademax)) {
                 if ($grade_item->has_grades() && empty($data['rescalegrades'])) {
                     $errors['rescalegrades'] = get_string('mustchooserescaleyesorno', 'grades');
                 }
             }
         }
     }
     return $errors;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:64,代码来源:item_form.php

示例13: validation

 function validation($data)
 {
     $errors = array();
     if (array_key_exists('idnumber', $data)) {
         if ($data['id']) {
             $grade_item = new grade_item(array('id' => $data['id'], 'courseid' => $data['courseid']));
             if ($grade_item->itemtype == 'mod') {
                 $cm = get_coursemodule_from_instance($grade_item->itemmodule, $grade_item->iteminstance, $grade_item->courseid);
             } else {
                 $cm = null;
             }
         } else {
             $grade_item = null;
             $cm = null;
         }
         if (!grade_verify_idnumber($data['idnumber'], $grade_item, $cm)) {
             $errors['idnumber'] = get_string('idnumbertaken');
         }
     }
     /*
     if (array_key_exists('calculation', $data) and $data['calculation'] != '') {
         $grade_item = new grade_item(array('id'=>$data['id'], 'itemtype'=>$data['itemtype'], 'courseid'=>$data['courseid']));
         $result = $grade_item->validate_formula($data['calculation']);
         if ($result !== true) {
             $errors['calculation'] = $result;
         }
     }
     */
     if (array_key_exists('grademin', $data) and array_key_exists('grademax', $data)) {
         if ($data['grademax'] == $data['grademin'] or $data['grademax'] < $data['grademin']) {
             $errors['grademin'] = get_String('incorrectminmax', 'grades');
             $errors['grademax'] = get_String('incorrectminmax', 'grades');
         }
     }
     if (0 == count($errors)) {
         return true;
     } else {
         return $errors;
     }
 }
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:40,代码来源:item_form.php

示例14: process_module

 protected function process_module($data)
 {
     global $CFG, $DB;
     $data = (object) $data;
     $oldid = $data->id;
     $this->task->set_old_moduleversion($data->version);
     $data->course = $this->task->get_courseid();
     $data->module = $DB->get_field('modules', 'id', array('name' => $data->modulename));
     // Map section (first try by course_section mapping match. Useful in course and section restores)
     $data->section = $this->get_mappingid('course_section', $data->sectionid);
     if (!$data->section) {
         // mapping failed, try to get section by sectionnumber matching
         $params = array('course' => $this->get_courseid(), 'section' => $data->sectionnumber);
         $data->section = $DB->get_field('course_sections', 'id', $params);
     }
     if (!$data->section) {
         // sectionnumber failed, try to get first section in course
         $params = array('course' => $this->get_courseid());
         $data->section = $DB->get_field('course_sections', 'MIN(id)', $params);
     }
     if (!$data->section) {
         // no sections in course, create section 0 and 1 and assign module to 1
         $sectionrec = array('course' => $this->get_courseid(), 'section' => 0);
         $DB->insert_record('course_sections', $sectionrec);
         // section 0
         $sectionrec = array('course' => $this->get_courseid(), 'section' => 1);
         $data->section = $DB->insert_record('course_sections', $sectionrec);
         // section 1
     }
     $data->groupingid = $this->get_mappingid('grouping', $data->groupingid);
     // grouping
     if (!grade_verify_idnumber($data->idnumber, $this->get_courseid())) {
         // idnumber uniqueness
         $data->idnumber = '';
     }
     if (empty($CFG->enablecompletion)) {
         // completion
         $data->completion = 0;
         $data->completiongradeitemnumber = null;
         $data->completionview = 0;
         $data->completionexpected = 0;
     } else {
         $data->completionexpected = $this->apply_date_offset($data->completionexpected);
     }
     if (empty($CFG->enableavailability)) {
         $data->availability = null;
     }
     // Backups that did not include showdescription, set it to default 0
     // (this is not totally necessary as it has a db default, but just to
     // be explicit).
     if (!isset($data->showdescription)) {
         $data->showdescription = 0;
     }
     $data->instance = 0;
     // Set to 0 for now, going to create it soon (next step)
     if (empty($data->availability)) {
         // If there are legacy availablility data fields (and no new format data),
         // convert the old fields.
         $data->availability = \core_availability\info::convert_legacy_fields($data, false);
     } else {
         if (!empty($data->groupmembersonly)) {
             // There is current availability data, but it still has groupmembersonly
             // as well (2.7 backups), convert just that part.
             require_once $CFG->dirroot . '/lib/db/upgradelib.php';
             $data->availability = upgrade_group_members_only($data->groupingid, $data->availability);
         }
     }
     // course_module record ready, insert it
     $newitemid = $DB->insert_record('course_modules', $data);
     // save mapping
     $this->set_mapping('course_module', $oldid, $newitemid);
     // set the new course_module id in the task
     $this->task->set_moduleid($newitemid);
     // we can now create the context safely
     $ctxid = context_module::instance($newitemid)->id;
     // set the new context id in the task
     $this->task->set_contextid($ctxid);
     // update sequence field in course_section
     if ($sequence = $DB->get_field('course_sections', 'sequence', array('id' => $data->section))) {
         $sequence .= ',' . $newitemid;
     } else {
         $sequence = $newitemid;
     }
     $DB->set_field('course_sections', 'sequence', $sequence, array('id' => $data->section));
     // If there is the legacy showavailability data, store this for later use.
     // (This data is not present when restoring 'new' backups.)
     if (isset($data->showavailability)) {
         // Cache the showavailability flag using the backup_ids data field.
         restore_dbops::set_backup_ids_record($this->get_restoreid(), 'module_showavailability', $newitemid, 0, null, (object) array('showavailability' => $data->showavailability));
     }
 }
开发者ID:Jinelle,项目名称:moodle,代码行数:91,代码来源:restore_stepslib.php

示例15: validation

 function validation($data, $files)
 {
     global $COURSE;
     $errors = parent::validation($data, $files);
     $mform =& $this->_form;
     $errors = array();
     if ($mform->elementExists('name')) {
         $name = trim($data['name']);
         if ($name == '') {
             $errors['name'] = get_string('required');
         }
     }
     $grade_item = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => $data['modulename'], 'iteminstance' => $data['instance'], 'itemnumber' => 0, 'courseid' => $COURSE->id));
     if ($data['coursemodule']) {
         $cm = get_record('course_modules', 'id', $data['coursemodule']);
     } else {
         $cm = null;
     }
     if ($mform->elementExists('cmidnumber')) {
         // verify the idnumber
         if (!grade_verify_idnumber($data['cmidnumber'], $COURSE->id, $grade_item, $cm)) {
             $errors['cmidnumber'] = get_string('idnumbertaken');
         }
     }
     return $errors;
 }
开发者ID:JackCanada,项目名称:moodle-hacks,代码行数:26,代码来源:moodleform_mod.php


注:本文中的grade_verify_idnumber函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。