當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。