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; }
function hvp_get_file_paths($hvp) { global $CFG, $DB; $filepaths = array('preloadedJs' => array(), 'preloadedCss' => array()); $libraries = $DB->get_records_sql('SELECT hl.id, hl.machine_name, hl.major_version, hl.minor_version, hl.preloaded_css, hl.preloaded_js, hcl.drop_css FROM {hvp_contents_libraries} hcl JOIN {hvp_libraries} hl ON hcl.library_id = hl.id WHERE hcl.id = ? AND hcl.preloaded = 1', array($hvp->id)); $path = '/mod/hvp/files'; $h5pcore = hvp_get_instance('core'); foreach ($libraries as $library) { // core only supports assoc. arrays. $librarydata = array('machineName' => $library->machine_name, 'majorVersion' => $library->major_version, 'minorVersion' => $library->minor_version); if (!empty($library->preloaded_js)) { foreach (explode(',', $library->preloaded_js) as $scriptpath) { $filepaths['preloadedJs'][] = $path . '/libraries/' . $h5pcore->libraryToString($librarydata, TRUE) . '/' . trim($scriptpath); } } if (!empty($library->preloaded_css) && !$library->drop_css) { foreach (explode(',', $library->preloaded_css) as $stylepath) { $filepaths['preloadedCss'][] = $path . '/libraries/' . $h5pcore->libraryToString($librarydata, TRUE) . '/' . trim($stylepath); } } } return $filepaths; }