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


PHP moodleform::validation方法代码示例

本文整理汇总了PHP中moodleform::validation方法的典型用法代码示例。如果您正苦于以下问题:PHP moodleform::validation方法的具体用法?PHP moodleform::validation怎么用?PHP moodleform::validation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在moodleform的用法示例。


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

示例1: validation

 /**
  * Form validation
  *
  * @param array $data
  * @param array $files
  * @return array $errors An array of errors
  */
 function validation($data, $files)
 {
     global $COURSE, $DB, $CFG;
     $errors = parent::validation($data, $files);
     $name = trim($data['name']);
     if ($data['id'] and $group = $DB->get_record('groups', array('id' => $data['id']))) {
         if (textlib::strtolower($group->name) != textlib::strtolower($name)) {
             if (groups_get_group_by_name($COURSE->id, $name)) {
                 $errors['name'] = get_string('groupnameexists', 'group', $name);
             }
         }
         if (!empty($CFG->groupenrolmentkeypolicy) and $data['enrolmentkey'] != '' and $group->enrolmentkey !== $data['enrolmentkey']) {
             // enforce password policy only if changing password
             $errmsg = '';
             if (!check_password_policy($data['enrolmentkey'], $errmsg)) {
                 $errors['enrolmentkey'] = $errmsg;
             }
         }
     } else {
         if (groups_get_group_by_name($COURSE->id, $name)) {
             $errors['name'] = get_string('groupnameexists', 'group', $name);
         }
     }
     return $errors;
 }
开发者ID:numbas,项目名称:moodle,代码行数:32,代码来源:group_form.php

示例2: validation

    /**
     * Perform minimal validation on the grade form
     * @param array $data
     * @param array $files
     */
    function validation($data, $files) {
        global $DB;
        $errors = parent::validation($data, $files);
        // advanced grading
        if (!array_key_exists('grade', $data)) {
            return $errors;
        }

        if ($this->assignment->get_instance()->grade > 0) {
            if (!is_numeric($data['grade']) and (!empty($data['grade']))) {
                $errors['grade'] = get_string('invalidfloatforgrade', 'assign', $data['grade']);
            } else if ($data['grade'] > $this->assignment->get_instance()->grade) {
                $errors['grade'] = get_string('gradeabovemaximum', 'assign', $this->assignment->get_instance()->grade);
            } else if ($data['grade'] < 0) {
                $errors['grade'] = get_string('gradebelowzero', 'assign');
            }
        } else {
            // this is a scale
            if ($scale = $DB->get_record('scale', array('id'=>-($this->assignment->get_instance()->grade)))) {
                $scaleoptions = make_menu_from_list($scale->scale);
                if (!array_key_exists((int)$data['grade'], $scaleoptions)) {
                    $errors['grade'] = get_string('invalidgradeforscale', 'assign');
                }
            }
        }
        return $errors;
    }
开发者ID:nicusX,项目名称:moodle,代码行数:32,代码来源:gradeform.php

示例3: validation

 /**
  * Perform minimal validation on the grade form
  * @param array $data
  * @param array $files
  */
 public function validation($data, $files)
 {
     global $DB;
     $errors = parent::validation($data, $files);
     $instance = $this->seplment->get_instance();
     if ($instance->markingworkflow && !empty($data['sendstudentnotifications']) && $data['workflowstate'] != ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) {
         $errors['sendstudentnotifications'] = get_string('studentnotificationworkflowstateerror', 'sepl');
     }
     // Advanced grading.
     if (!array_key_exists('grade', $data)) {
         return $errors;
     }
     if ($instance->grade > 0) {
         if (unformat_float($data['grade'], true) === false && !empty($data['grade'])) {
             $errors['grade'] = get_string('invalidfloatforgrade', 'sepl', $data['grade']);
         } else {
             if (unformat_float($data['grade']) > $instance->grade) {
                 $errors['grade'] = get_string('gradeabovemaximum', 'sepl', $instance->grade);
             } else {
                 if (unformat_float($data['grade']) < 0) {
                     $errors['grade'] = get_string('gradebelowzero', 'sepl');
                 }
             }
         }
     } else {
         // This is a scale.
         if ($scale = $DB->get_record('scale', array('id' => -$instance->grade))) {
             $scaleoptions = make_menu_from_list($scale->scale);
             if ((int) $data['grade'] !== -1 && !array_key_exists((int) $data['grade'], $scaleoptions)) {
                 $errors['grade'] = get_string('invalidgradeforscale', 'sepl');
             }
         }
     }
     return $errors;
 }
开发者ID:krzpassrl,项目名称:SRL_Moodle_Baseline,代码行数:40,代码来源:gradeform.php

示例4: validation

 public function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     // If this is a rate question.
     if ($data['type_id'] == QUESRATE) {
         if ($data['length'] < 2) {
             $errors["length"] = get_string('notenoughscaleitems', 'questionnaire');
         }
         // If this is a rate question with no duplicates option.
         if ($data['precise'] == 2) {
             $allchoices = $data['allchoices'];
             $allchoices = explode("\n", $allchoices);
             $nbvalues = 0;
             foreach ($allchoices as $choice) {
                 if ($choice && !preg_match("/^[0-9]{1,3}=/", $choice)) {
                     $nbvalues++;
                 }
             }
             if ($nbvalues < 2) {
                 $errors["allchoices"] = get_string('noduplicateschoiceserror', 'questionnaire');
             }
         }
     }
     return $errors;
 }
开发者ID:SysBind,项目名称:moodle-mod_questionnaire,代码行数:25,代码来源:edit_question_form.php

示例5: validation

 /**
  * Ensure that the data the user entered is valid
  *
  * @param object $data data object for validation
  * @param object $files file object for validation
  * 
  * @see lib/moodleform#validation()
  * 
  * @return $errors error message
  */
 function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     global $DB, $CFG, $USER;
     //Declare them if you need them
     return $errors;
 }
开发者ID:MoodleMetaData,项目名称:MoodleMetaData,代码行数:17,代码来源:syllabus_form.php

示例6: validation

 function validation($data, $files)
 {
     global $DB;
     $errors = parent::validation($data, $files);
     $tab_id = array();
     foreach ($data as $key => $value) {
         $pos = strstr($key, "voc_id");
         if ($pos) {
             // echo "found :$key /$value<=> $pos<br>";
             foreach ($value as $key2 => $value2) {
                 if ($value2 > 0) {
                     $tab_id[] = $value2;
                 }
             }
         } else {
             // echo " NOT found :$key /$value<br>";
         }
     }
     // var_dump($data);
     var_dump($tab_id);
     die('stop');
     if (empty($tab_id)) {
         $errors['shortname'] = 'please select at least one vocabulary';
         $errors[''] = 'please select at least one vocabulary';
         // todo repositionner l'erreur au bon endroit dans le formulaire
     }
     //        // Add field validation check for duplicate shortname.
     //        if ($term= $DB->get_record('taxonomy_term', array('shortname' => $data['shortname']), '*', IGNORE_MULTIPLE)) {
     //            if (empty($data['id']) || $term->id != $data['id']) {
     //                $errors['shortname'] = 'this shortmane is already used';
     //            }
     //        }
     return $errors;
 }
开发者ID:matlow,项目名称:taxonomy,代码行数:34,代码来源:AssocEditForm.php

示例7: validation

 function validation($data, $files)
 {
     global $db, $CFG;
     $errors = parent::validation($data, $files);
     if (!in_array($data['operator'], $this->allowedops)) {
         $errors['operator'] = get_string('error_operator', 'block_configurable_reports');
     }
     $columns = $db->MetaColumns($CFG->prefix . 'user');
     $usercolumns = array();
     foreach ($columns as $c) {
         $usercolumns[$c->name] = $c->name;
     }
     if ($profile = get_records('user_info_field')) {
         foreach ($profile as $p) {
             $usercolumns['profile_' . $p->shortname] = 'profile_' . $p->shortname;
         }
     }
     if (!in_array($data['field'], $usercolumns)) {
         $errors['field'] = get_string('error_field', 'block_configurable_reports');
     }
     if (!is_numeric($data['value']) && preg_match('/^(<|>)[^(<|>)]/i', $data['operator'])) {
         $errors['value'] = get_string('error_value_expected_integer', 'block_configurable_reports');
     }
     return $errors;
 }
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:25,代码来源:form.php

示例8: validation

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

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

        return $errors;
    }
开发者ID:narasimhaeabyas,项目名称:tataaiapro,代码行数:7,代码来源:form.php

示例9: validation

 /**
  * Validates the add instance form data
  *
  * @param array $data
  * @param array $files
  * @return array
  */
 public function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     if (!array_key_exists('name', $errors)) {
         if (!preg_match('#^[a-zA-Z0-9\\-_ ]+$#', $data['name'])) {
             $errors['name'] = get_string('storenameinvalid', 'cache');
         } else {
             if (empty($this->_customdata['store'])) {
                 $stores = cache_administration_helper::get_store_instance_summaries();
                 if (array_key_exists($data['name'], $stores)) {
                     $errors['name'] = get_string('storenamealreadyused', 'cache');
                 }
             }
         }
     }
     if (method_exists($this, 'configuration_validation')) {
         $newerrors = $this->configuration_validation($data, $files, $errors);
         // We need to selectiviliy merge here
         foreach ($newerrors as $element => $error) {
             if (!array_key_exists($element, $errors)) {
                 $errors[$element] = $error;
             }
         }
     }
     return $errors;
 }
开发者ID:Burick,项目名称:moodle,代码行数:33,代码来源:forms.php

示例10: validation

 function validation($data, $files)
 {
     global $USER;
     if ($errors = parent::validation($data, $files)) {
         return $errors;
     }
     $usercontext = context_user::instance($USER->id);
     $fs = get_file_storage();
     if (!($files = $fs->get_area_files($usercontext->id, 'user', 'draft', $data['importfile'], 'id', false))) {
         $errors['importfile'] = get_string('required');
         return $errors;
     } else {
         $file = reset($files);
         if ($file->get_mimetype() != 'application/zip') {
             $errors['importfile'] = get_string('invalidfiletype', 'error', $file->get_filename());
             // better delete current file, it is not usable anyway
             $fs->delete_area_files($usercontext->id, 'user', 'draft', $data['importfile']);
         } else {
             if (!($chpterfiles = toolbook_importhtml_get_chapter_files($file, $data['type']))) {
                 $errors['importfile'] = get_string('errornochapters', 'booktool_importhtml');
             }
         }
     }
     return $errors;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:25,代码来源:import_form.php

示例11: validation

    /**
     * Perform minimal validation on the grade form
     * @param array $data
     * @param array $files
     */
    public function validation($data, $files) {
        global $DB;
        $errors = parent::validation($data, $files);
        $instance = $this->assignment->get_instance();
        // Advanced grading.
        if (!array_key_exists('grade', $data)) {
            return $errors;
        }

        if ($instance->grade > 0) {
            if (unformat_float($data['grade']) === null && (!empty($data['grade']))) {
                $errors['grade'] = get_string('invalidfloatforgrade', 'assign', $data['grade']);
            } else if (unformat_float($data['grade']) > $instance->grade) {
                $errors['grade'] = get_string('gradeabovemaximum', 'assign', $instance->grade);
            } else if (unformat_float($data['grade']) < 0) {
                $errors['grade'] = get_string('gradebelowzero', 'assign');
            }
        } else {
            // This is a scale.
            if ($scale = $DB->get_record('scale', array('id'=>-($instance->grade)))) {
                $scaleoptions = make_menu_from_list($scale->scale);
                if (!array_key_exists((int)$data['grade'], $scaleoptions)) {
                    $errors['grade'] = get_string('invalidgradeforscale', 'assign');
                }
            }
        }
        return $errors;
    }
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:33,代码来源:gradeform.php

示例12: validation

 function validation($data, $files)
 {
     global $DB;
     $errors = parent::validation($data, $files);
     $foundcourses = null;
     $foundreqcourses = null;
     if (!empty($data['shortname'])) {
         $foundcourses = $DB->get_records('course', array('shortname' => $data['shortname']));
         $foundreqcourses = $DB->get_records('course_request', array('shortname' => $data['shortname']));
     }
     if (!empty($foundreqcourses)) {
         if (!empty($foundcourses)) {
             $foundcourses = array_merge($foundcourses, $foundreqcourses);
         } else {
             $foundcourses = $foundreqcourses;
         }
     }
     if (!empty($foundcourses)) {
         foreach ($foundcourses as $foundcourse) {
             if (!empty($foundcourse->requester)) {
                 $pending = 1;
                 $foundcoursenames[] = $foundcourse->fullname . ' [*]';
             } else {
                 $foundcoursenames[] = $foundcourse->fullname;
             }
         }
         $foundcoursenamestring = implode(',', $foundcoursenames);
         $errors['shortname'] = get_string('shortnametaken', '', $foundcoursenamestring);
         if (!empty($pending)) {
             $errors['shortname'] .= get_string('starpending');
         }
     }
     return $errors;
 }
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:34,代码来源:request_form.php

示例13: validation

    function validation($data, $files) {
        global $DB, $CFG;
        $id = optional_param('id', -1, PARAM_INT);
        $errors = array();
        $errors = parent::validation($data, $files);
        if ($data['schoolid'] == 0) {
            $errors['schoolid'] = get_string('schoolrequired', 'local_collegestructure');
        }
        if ($data['id'] < 0) {
            $examtypes1 = $DB->get_record('local_examtypes', array('schoolid' => $data['schoolid'], 'examtype' => $data['examtype']));
            $exam1 = core_text::strtolower($examtypes1->examtype);
            $exam2 = core_text::strtolower($data['examtype']);
            if ($exam1 == $exam2) {
                $errors['examtype'] = get_string('examexits', 'local_examtype');
            }
        }

        if ($data['id'] > 0) {
            $exists = $DB->get_field('local_examtypes', 'examtype', array('id' => $id));
            if (!($exists === $data['examtype'] )) {
                $examtypes1 = $DB->get_record('local_examtypes', array('schoolid' => $data['schoolid'], 'examtype' => $data['examtype']));
                $exam1 = core_text::strtolower($examtypes1->examtype);
                $exam2 = core_text::strtolower($data['examtype']);
                if ($exam1 == $exam2) {
                    $errors['examtype'] = get_string('examexits', 'local_examtype');
                }
            }
        }
        return $errors;
    }
开发者ID:anilch,项目名称:Personel,代码行数:30,代码来源:edit_form.php

示例14: validation

 /**
  * Form validation
  *
  * @param array $data
  * @param array $files
  * @return array $errors An array of validataion errors for the form.
  */
 function validation($data, $files)
 {
     global $COURSE, $DB;
     $errors = parent::validation($data, $files);
     $name = trim($data['name']);
     if (isset($data['idnumber'])) {
         $idnumber = trim($data['idnumber']);
     } else {
         $idnumber = '';
     }
     if ($data['id'] and $grouping = $DB->get_record('groupings', array('id' => $data['id']))) {
         if (core_text::strtolower($grouping->name) != core_text::strtolower($name)) {
             if (groups_get_grouping_by_name($COURSE->id, $name)) {
                 $errors['name'] = get_string('groupingnameexists', 'group', $name);
             }
         }
         if (!empty($idnumber) && $grouping->idnumber != $idnumber) {
             if (groups_get_grouping_by_idnumber($COURSE->id, $idnumber)) {
                 $errors['idnumber'] = get_string('idnumbertaken');
             }
         }
     } else {
         if (groups_get_grouping_by_name($COURSE->id, $name)) {
             $errors['name'] = get_string('groupingnameexists', 'group', $name);
         } else {
             if (!empty($idnumber) && groups_get_grouping_by_idnumber($COURSE->id, $idnumber)) {
                 $errors['idnumber'] = get_string('idnumbertaken');
             }
         }
     }
     return $errors;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:39,代码来源:grouping_form.php

示例15: validation

 function validation($data, $files)
 {
     global $CFG, $USER, $DB;
     $errors = parent::validation($data, $files);
     if (empty($data['id']) and empty($data['example'])) {
         // make sure there is no submission saved meanwhile from another browser window
         $sql = "SELECT COUNT(s.id)\n                      FROM {workshop_submissions} s\n                      JOIN {workshop} w ON (s.workshopid = w.id)\n                      JOIN {course_modules} cm ON (w.id = cm.instance)\n                      JOIN {modules} m ON (m.name = 'workshop' AND m.id = cm.module)\n                     WHERE cm.id = ? AND s.authorid = ? AND s.example = 0";
         if ($DB->count_records_sql($sql, array($data['cmid'], $USER->id))) {
             $errors['title'] = get_string('err_multiplesubmissions', 'mod_workshop');
         }
     }
     if (isset($data['attachment_filemanager']) and isset($this->_customdata['workshop']->submissionfiletypes)) {
         $whitelist = workshop::normalize_file_extensions($this->_customdata['workshop']->submissionfiletypes);
         if ($whitelist) {
             $draftfiles = file_get_drafarea_files($data['attachment_filemanager']);
             if ($draftfiles) {
                 $wrongfiles = array();
                 foreach ($draftfiles->list as $file) {
                     if (!workshop::is_allowed_file_type($file->filename, $whitelist)) {
                         $wrongfiles[] = $file->filename;
                     }
                 }
                 if ($wrongfiles) {
                     $a = array('whitelist' => workshop::clean_file_extensions($whitelist), 'wrongfiles' => implode(', ', $wrongfiles));
                     $errors['attachment_filemanager'] = get_string('err_wrongfileextension', 'mod_workshop', $a);
                 }
             }
         }
     }
     return $errors;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:31,代码来源:submission_form.php


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