本文整理汇总了PHP中moodleform_mod::validation方法的典型用法代码示例。如果您正苦于以下问题:PHP moodleform_mod::validation方法的具体用法?PHP moodleform_mod::validation怎么用?PHP moodleform_mod::validation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类moodleform_mod
的用法示例。
在下文中一共展示了moodleform_mod::validation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validation
function validation($data, $files) {
global $USER;
if ($errors = parent::validation($data, $files)) {
return $errors;
}
$usercontext = get_context_instance(CONTEXT_USER, $USER->id);
$fs = get_file_storage();
if (!$files = $fs->get_area_files($usercontext->id, 'user', 'draft', $data['package'], 'id', false)) {
if (!$this->current->instance) {
$errors['package'] = get_string('required');
return $errors;
}
} else {
$file = reset($files);
if ($file->get_mimetype() != 'application/zip') {
$errors['package'] = get_string('invalidfiletype', 'error', '', $file);
// better delete current file, it is not usable anyway
$fs->delete_area_files($usercontext->id, 'user', 'draft', $data['package']);
}
}
return $errors;
}
示例2: validation
public function validation($data, $files)
{
global $DB;
$errors = parent::validation($data, $files);
// If you enable sharing, you must enter an idnumber.
if (!empty($data['enablesharing']) && empty($data['cmidnumber'])) {
$errors['cmidnumber'] = get_string('error_noidnumber', 'subpage');
}
// If you turn off sharing, there must be no shared pages using it.
if (empty($data['enablesharing']) && !empty($this->_instance)) {
if ($DB->get_field('modules', 'id', array('name' => 'sharedsubpage'))) {
// Check if there is a shared subpage...
if ($DB->record_exists('sharedsubpage', array('subpageid' => $this->_instance))) {
$errors['enablesharing'] = get_string('error_sharingused', 'subpage');
}
}
}
// ID numbers must be unique, systemwide.
if (!empty($data['cmidnumber'])) {
// Except obviously on this existing course-module (if it does exist).
$except = -1;
if (!empty($data['coursemodule'])) {
$except = $data['coursemodule'];
}
if ($DB->record_exists_sql('SELECT 1 FROM {course_modules} WHERE idnumber = ? AND id <> ?', array($data['cmidnumber'], $except))) {
$errors['cmidnumber'] = get_string('error_duplicateidnumber', 'subpage');
}
}
return $errors;
}
示例3: validation
function validation($data, $files)
{
global $CFG;
$errors = parent::validation($data, $files);
if (empty($data['h5pfile'])) {
$errors['h5pfile'] = get_string('required');
return $errors;
}
$files = $this->get_draft_files('h5pfile');
if (count($files) < 1) {
$errors['h5pfile'] = get_string('required');
return $errors;
}
$file = reset($files);
$interface = hvp_get_instance('interface');
$path = $CFG->dirroot . '/mod/hvp/files/tmp/' . uniqid('hvp-');
$interface->getUploadedH5pFolderPath($path);
$path .= '.h5p';
$interface->getUploadedH5pPath($path);
$file->copy_content_to($path);
$h5pValidator = hvp_get_instance('validator');
if (!$h5pValidator->isValidPackage()) {
$errors['h5pfile'] = get_string('noth5pfile', 'hvp');
}
return $errors;
}
示例4: validation
public function validation($data, $files)
{
$errors = parent::validation($data, $files);
if (count($errors) == 0) {
return true;
} else {
return $errors;
}
}
示例5: validation
function validation($data, $files)
{
$errors = parent::validation($data, $files);
// Completion: Automatic on-view completion can not work together with
// "display inline" option
if (empty($errors['completion']) && array_key_exists('completion', $data) && $data['completion'] == COMPLETION_TRACKING_AUTOMATIC && !empty($data['completionview']) && $data['display'] == FOLDER_DISPLAY_INLINE) {
$errors['completion'] = get_string('noautocompletioninline', 'mod_folder');
}
return $errors;
}
示例6: validation
function validation($data, $files)
{
global $COURSE;
$errors = parent::validation($data, $files);
$mform =& $this->_form;
$maxmembers = $data['maxmembers'];
if ($maxmembers < 0) {
$errors['maxmembers'] = get_string('error');
}
return $errors;
}
示例7: validation
function validation($data, $files)
{
$errors = parent::validation($data, $files);
// Disabled this feature because client wants to be able to paste
// URLs with spaces and only have them trimed just before the page
// is redirected.
// if(!ezproxy_has_protocol($data['serverurl'])) {
// $errors['serverurl'] = get_string('missingprotocol', 'ezproxy');
// }
return $errors;
}
示例8: validation
/**
* Enforce validation rules here
*
* @param array $data array of ("fieldname"=>value) of submitted data
* @param array $files array of uploaded files "element_name"=>tmp_file_path
* @return array
**/
public function validation($data, $files)
{
$errors = parent::validation($data, $files);
// Check open and close times are consistent.
if ($data['timeavailablefrom'] && $data['timeavailableto'] && $data['timeavailableto'] < $data['timeavailablefrom']) {
$errors['timeavailableto'] = get_string('availabletodatevalidation', 'data');
}
if ($data['timeviewfrom'] && $data['timeviewto'] && $data['timeviewto'] < $data['timeviewfrom']) {
$errors['timeviewto'] = get_string('viewtodatevalidation', 'data');
}
return $errors;
}
示例9: validation
function validation($data, $files)
{
$errors = parent::validation($data, $files);
// Validating entered NeuroK course url.
if (!empty($data['url'])) {
$testurl = $data['url'];
if (preg_match('|^https:|i', $testurl)) {
if (!preg_match('|' . NEUROKBASEURL . '|i', $testurl)) {
$errors['url'] = get_string('invalidurl', 'neurok');
}
} else {
$errors['url'] = get_string('invalidurl', 'neurok');
}
}
return $errors;
}
示例10: validation
/**
* Perform minimal validation on the settings form
* @param array $data
* @param array $files
*/
public function validation($data, $files)
{
$errors = parent::validation($data, $files);
if ($data['allowsubmissionsfromdate'] && $data['duedate']) {
if ($data['allowsubmissionsfromdate'] > $data['duedate']) {
$errors['duedate'] = get_string('duedatevalidation', 'publication');
}
}
if ($data['duedate'] && $data['cutoffdate']) {
if ($data['duedate'] > $data['cutoffdate']) {
$errors['cutoffdate'] = get_string('cutoffdatevalidation', 'publication');
}
}
if ($data['allowsubmissionsfromdate'] && $data['cutoffdate']) {
if ($data['allowsubmissionsfromdate'] > $data['cutoffdate']) {
$errors['cutoffdate'] = get_string('cutoffdatefromdatevalidation', 'publication');
}
}
if ($data['mode'] == PUBLICATION_MODE_IMPORT) {
if ($data['importfrom'] == "0") {
$errors['importfrom'] = get_string('importfrom_err', 'publication');
}
}
return $errors;
}
示例11: validation
function validation($data, $files)
{
global $USER;
$errors = parent::validation($data, $files);
$usercontext = context_user::instance($USER->id);
$fs = get_file_storage();
if (!($files = $fs->get_area_files($usercontext->id, 'user', 'draft', $data['files'], 'sortorder, id', false))) {
$errors['files'] = get_string('required');
return $errors;
}
if (count($files) == 1) {
// no need to select main file if only one picked
return $errors;
} else {
if (count($files) > 1) {
$mainfile = false;
foreach ($files as $file) {
if ($file->get_sortorder() == 1) {
$mainfile = true;
break;
}
}
// set a default main file
if (!$mainfile) {
$file = reset($files);
file_set_sortorder($file->get_contextid(), $file->get_component(), $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename(), 1);
}
}
}
return $errors;
}
示例12: validation
public function validation($data, $files)
{
$current_activity =& $this->current;
$errors = parent::validation($data, $files);
if ($data['timeavailable'] != 0 && $data['timedue'] != 0 && $data['timedue'] < $data['timeavailable']) {
$errors['timedue'] = get_string('bbbduetimeoverstartingtime', 'bigbluebuttonbn');
}
return $errors;
}
示例13: validation
function validation($data, $files)
{
$errors = parent::validation($data, $files);
// Validating Entered url, we are looking for obvious problems only,
// teachers are responsible for testing if it actually works.
// This is not a security validation!! Teachers are allowed to enter "javascript:alert(666)" for example.
// NOTE: do not try to explain the difference between URL and URI, people would be only confused...
if (empty($data['externalurl'])) {
$errors['externalurl'] = get_string('required');
} else {
$url = trim($data['externalurl']);
if (empty($url)) {
$errors['externalurl'] = get_string('required');
} else {
if (preg_match('|^/|', $url)) {
// links relative to server root are ok - no validation necessary
} else {
if (preg_match('|^[a-z]+://|i', $url) or preg_match('|^https?:|i', $url) or preg_match('|^ftp:|i', $url)) {
// normal URL
if (!url_appears_valid_url($url)) {
$errors['externalurl'] = get_string('invalidurl', 'url');
}
} else {
if (preg_match('|^[a-z]+:|i', $url)) {
// general URI such as teamspeak, mailto, etc. - it may or may not work in all browsers,
// we do not validate these at all, sorry
} else {
// invalid URI, we try to fix it by adding 'http://' prefix,
// relative links are NOT allowed because we display the link on different pages!
if (!url_appears_valid_url('http://' . $url)) {
$errors['externalurl'] = get_string('invalidurl', 'url');
}
}
}
}
}
}
return $errors;
}
示例14: validation
function validation($data, $files) {
global $CFG;
$errors = parent::validation($data, $files);
$type = $data['scormtype'];
if ($type === SCORM_TYPE_LOCAL) {
if (!empty($data['update'])) {
//ok, not required
} else if (empty($data['packagefile'])) {
$errors['packagefile'] = get_string('required');
} else {
$files = $this->get_draft_files('packagefile');
if (count($files)<1) {
$errors['packagefile'] = get_string('required');
return $errors;
}
$file = reset($files);
$filename = $CFG->tempdir.'/scormimport/scrom_'.time();
make_temp_directory('scormimport');
$file->copy_content_to($filename);
$packer = get_file_packer('application/zip');
$filelist = $packer->list_files($filename);
if (!is_array($filelist)) {
$errors['packagefile'] = 'Incorrect file package - not an archive'; //TODO: localise
} else {
$manifestpresent = false;
$aiccfound = false;
foreach ($filelist as $info) {
if ($info->pathname == 'imsmanifest.xml') {
$manifestpresent = true;
break;
}
if (preg_match('/\.cst$/', $info->pathname)) {
$aiccfound = true;
break;
}
}
if (!$manifestpresent and !$aiccfound) {
$errors['packagefile'] = 'Incorrect file package - missing imsmanifest.xml or AICC structure'; //TODO: localise
}
}
unlink($filename);
}
} else if ($type === SCORM_TYPE_EXTERNAL) {
$reference = $data['packageurl'];
// Syntax check.
if (!preg_match('/(http:\/\/|https:\/\/|www).*\/imsmanifest.xml$/i', $reference)) {
$errors['packageurl'] = get_string('invalidurl', 'scorm');
} else {
// Availability check.
$result = scorm_check_url($reference);
if (is_string($result)) {
$errors['packageurl'] = $result;
}
}
} else if ($type === 'packageurl') {
$reference = $data['reference'];
// Syntax check.
if (!preg_match('/(http:\/\/|https:\/\/|www).*(\.zip|\.pif)$/i', $reference)) {
$errors['packageurl'] = get_string('invalidurl', 'scorm');
} else {
// Availability check.
$result = scorm_check_url($reference);
if (is_string($result)) {
$errors['packageurl'] = $result;
}
}
} else if ($type === SCORM_TYPE_IMSREPOSITORY) {
$reference = $data['packageurl'];
if (stripos($reference, '#') !== 0) {
$errors['packageurl'] = get_string('invalidurl', 'scorm');
}
} else if ($type === SCORM_TYPE_AICCURL) {
$reference = $data['packageurl'];
// Syntax check.
if (!preg_match('/(http:\/\/|https:\/\/|www).*/', $reference)) {
$errors['packageurl'] = get_string('invalidurl', 'scorm');
} else {
// Availability check.
$result = scorm_check_url($reference);
if (is_string($result)) {
$errors['packageurl'] = $result;
}
}
}
return $errors;
}
示例15: validation
function validation($data, $files)
{
$errors = parent::validation($data, $files);
$groupIDs = explode(';', $data['serializedselectedgroups']);
$groupIDs = array_diff($groupIDs, array(''));
if (array_key_exists('multipleenrollmentspossible', $data) && $data['multipleenrollmentspossible'] === '1') {
if (count($groupIDs) < 1) {
$errors['serializedselectedgroups'] = get_string('fillinatleastoneoption', 'choicegroup');
}
} else {
if (count($groupIDs) < 2) {
$errors['serializedselectedgroups'] = get_string('fillinatleasttwooptions', 'choicegroup');
}
}
return $errors;
}