Example #1
0
/**
 * Returns a list of information about file types based on extensions.
 *
 * The following elements expected in value array for each extension:
 * 'type' - mimetype
 * 'icon' - location of the icon file. If value is FILENAME, then either pix/f/FILENAME.gif
 *     or pix/f/FILENAME.png must be present in moodle and contain 16x16 filetype icon;
 *     also files with bigger sizes under names
 *     FILENAME-24, FILENAME-32, FILENAME-64, FILENAME-128, FILENAME-256 are recommended.
 * 'groups' (optional) - array of filetype groups this filetype extension is part of;
 *     commonly used in moodle the following groups:
 *       - web_image - image that can be included as <img> in HTML
 *       - image - image that we can parse using GD to find it's dimensions, also used for portfolio format
 *       - video - file that can be imported as video in text editor
 *       - audio - file that can be imported as audio in text editor
 *       - archive - we can extract files from this archive
 *       - spreadsheet - used for portfolio format
 *       - document - used for portfolio format
 *       - presentation - used for portfolio format
 * 'string' (optional) - the name of the string from lang/en/mimetypes.php that displays
 *     human-readable description for this filetype;
 *     Function {@link get_mimetype_description()} first looks at the presence of string for
 *     particular mimetype (value of 'type'), if not found looks for string specified in 'string'
 *     attribute, if not found returns the value of 'type';
 * 'defaulticon' (boolean, optional) - used by function {@link file_mimetype_icon()} to find
 *     an icon for mimetype. If an entry with 'defaulticon' is not found for a particular mimetype,
 *     this function will return first found icon; Especially usefull for types such as 'text/plain'
 *
 * @category files
 * @return array List of information about file types based on extensions.
 *   Associative array of extension (lower-case) to associative array
 *   from 'element name' to data. Current element names are 'type' and 'icon'.
 *   Unknown types should use the 'xxx' entry which includes defaults.
 */
function &get_mimetypes_array()
{
    // Get types from the core_filetypes function, which includes caching.
    return core_filetypes::get_types();
}
Example #2
0
 /**
  * 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;
 }