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


PHP workshop::invalid_file_extensions方法代码示例

本文整理汇总了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;
 }
开发者ID:sirromas,项目名称:lms,代码行数:66,代码来源:mod_form.php

示例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'));
 }
开发者ID:evltuma,项目名称:moodle,代码行数:21,代码来源:locallib_test.php


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