本文整理汇总了PHP中workshop::invalid_file_extensions方法的典型用法代码示例。如果您正苦于以下问题:PHP workshop::invalid_file_extensions方法的具体用法?PHP workshop::invalid_file_extensions怎么用?PHP workshop::invalid_file_extensions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类workshop
的用法示例。
在下文中一共展示了workshop::invalid_file_extensions方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validation
/**
* Validates the form input
*
* @param array $data submitted data
* @param array $files submitted files
* @return array eventual errors indexed by the field name
*/
public function validation($data, $files)
{
$errors = parent::validation($data, $files);
// Validate lists of allowed extensions.
foreach (array('submissionfiletypes', 'overallfeedbackfiletypes') as $fieldname) {
if (isset($data[$fieldname])) {
$invalidextensions = workshop::invalid_file_extensions($data[$fieldname], array_keys(core_filetypes::get_types()));
if ($invalidextensions) {
$errors[$fieldname] = get_string('err_unknownfileextension', 'mod_workshop', workshop::clean_file_extensions($invalidextensions));
}
}
}
// check the phases borders are valid
if ($data['submissionstart'] > 0 and $data['submissionend'] > 0 and $data['submissionstart'] >= $data['submissionend']) {
$errors['submissionend'] = get_string('submissionendbeforestart', 'mod_workshop');
}
if ($data['assessmentstart'] > 0 and $data['assessmentend'] > 0 and $data['assessmentstart'] >= $data['assessmentend']) {
$errors['assessmentend'] = get_string('assessmentendbeforestart', 'mod_workshop');
}
// check the phases do not overlap
if (max($data['submissionstart'], $data['submissionend']) > 0 and max($data['assessmentstart'], $data['assessmentend']) > 0) {
$phasesubmissionend = max($data['submissionstart'], $data['submissionend']);
$phaseassessmentstart = min($data['assessmentstart'], $data['assessmentend']);
if ($phaseassessmentstart == 0) {
$phaseassessmentstart = max($data['assessmentstart'], $data['assessmentend']);
}
if ($phasesubmissionend > 0 and $phaseassessmentstart > 0 and $phaseassessmentstart < $phasesubmissionend) {
foreach (array('submissionend', 'submissionstart', 'assessmentstart', 'assessmentend') as $f) {
if ($data[$f] > 0) {
$errors[$f] = get_string('phasesoverlap', 'mod_workshop');
break;
}
}
}
}
// Check that the submission grade pass is a valid number.
if (!empty($data['submissiongradepass'])) {
$submissiongradefloat = unformat_float($data['submissiongradepass'], true);
if ($submissiongradefloat === false) {
$errors['submissiongradepass'] = get_string('err_numeric', 'form');
} else {
if ($submissiongradefloat > $data['grade']) {
$errors['submissiongradepass'] = get_string('gradepassgreaterthangrade', 'grades', $data['grade']);
}
}
}
// Check that the grade pass is a valid number.
if (!empty($data['gradinggradepass'])) {
$gradepassfloat = unformat_float($data['gradinggradepass'], true);
if ($gradepassfloat === false) {
$errors['gradinggradepass'] = get_string('err_numeric', 'form');
} else {
if ($gradepassfloat > $data['gradinggrade']) {
$errors['gradinggradepass'] = get_string('gradepassgreaterthangrade', 'grades', $data['gradinggrade']);
}
}
}
return $errors;
}
示例2: test_invalid_file_extensions
/**
* Test validation of the list of file extensions.
*/
public function test_invalid_file_extensions()
{
$this->resetAfterTest(true);
$this->assertSame([], workshop::invalid_file_extensions('', ''));
$this->assertSame([], workshop::invalid_file_extensions('', '.doc'));
$this->assertSame([], workshop::invalid_file_extensions('odt', ''));
$this->assertSame([], workshop::invalid_file_extensions('odt', '*'));
$this->assertSame([], workshop::invalid_file_extensions('odt', 'odt'));
$this->assertSame([], workshop::invalid_file_extensions('doc, odt, pdf', ['pdf', 'doc', 'odt']));
$this->assertSame([], workshop::invalid_file_extensions(['doc', 'odt', 'PDF'], ['.doc', '.pdf', '.odt']));
$this->assertSame([], workshop::invalid_file_extensions('*~ .docx, Odt PDF :doc .pdf', '*.docx *.odt *.pdf *.doc'));
$this->assertSame(['.00001-wtf-is-this'], workshop::invalid_file_extensions('docx tgz .00001-wtf-is-this', 'tgz docx'));
$this->assertSame(['.foobar', '.wtfisthis'], workshop::invalid_file_extensions(['.pdf', '.foobar', 'wtfisthis'], 'pdf'));
$this->assertSame([], workshop::invalid_file_extensions('', ''));
$this->assertSame(['.odt'], workshop::invalid_file_extensions(['.PDF', 'PDF', '.ODT'], 'jpg pdf png gif'));
$this->assertSame(['.odt'], workshop::invalid_file_extensions(['.PDF', 'PDF', '.ODT'], '.jpg,.pdf, .png .gif'));
$this->assertSame(['.exe', '.bat'], workshop::invalid_file_extensions(['.exe', '.odt', '.bat', ''], 'odt'));
}