Last active
July 14, 2017 09:54
-
-
Save xyulex/92de9716c08de916068aad789162524e to your computer and use it in GitHub Desktop.
MOODLE: Importar SCORMS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// This file is part of Moodle - http://moodle.org/ | |
// | |
// Moodle is free software: you can redistribute it and/or modify | |
// it under the terms of the GNU General Public License as published by | |
// the Free Software Foundation, either version 3 of the License, or | |
// (at your option) any later version. | |
// | |
// Moodle is distributed in the hope that it will be useful, | |
// but WITHOUT ANY WARRANTY; without even the implied warranty of | |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
// GNU General Public License for more details. | |
// | |
// You should have received a copy of the GNU General Public License | |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | |
/** | |
* | |
* @package local_altamarimport | |
* @copyright 2017 Raúl Martínez <raul@tresipunt.com> | |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
*/ | |
require('../../config.php'); | |
require('lib.php'); | |
require('../../mod/scorm/lib.php'); | |
require('../../mod/scorm/locallib.php'); | |
require_once($CFG->dirroot . "/course/modlib.php"); | |
/** TO DO | |
Acabar de ocultar los TOC | |
Parametros de secciones, etc... | |
**/ | |
global $CFG, $USER, $DB; | |
$PAGE->set_url($CFG->wwwroot.'/local/altamarimport/index.php'); | |
require_login(); | |
require_capability('moodle/site:config', context_system::instance()); | |
// Get URL import and ZIP list. | |
$parameters = getDownloadParameters(); | |
$url = $parameters->downloadURL; | |
$scormFilenames = $parameters->contents; | |
$courseid = 3; // Hardcoded | |
$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST); | |
$courseid = $COURSE->id; | |
echo $OUTPUT->header(); | |
foreach($scormFilenames as $scormFilename) { | |
$fs = get_file_storage(); | |
$coursecontextid = context_course::instance($courseid)->id; | |
$scorm = new StdClass(); | |
$scorm->modulename = 'scorm'; | |
$scorm->module = $DB->get_field('modules', 'id', array('name' => $scorm->modulename)); | |
$scorm->name = $scormFilename; | |
$scorm->course = $courseid; | |
$scorm->intro = ""; | |
$scorm->introformat = FORMAT_MOODLE; | |
$scorm->cmidnumber = null; | |
$scorm->visible = 1; | |
$scorm->section = 4; | |
$scorm->width = '400'; | |
$scorm->height = '400'; | |
$scorm->version = 'SCORM_1.2'; | |
$scorm->hidetoc = 1; // Esconder TOC | |
$scorm->maxattempt = 0; // Intentos ilimitados | |
// Add file. | |
$draftitemid = 0; | |
file_prepare_draft_area($draftitemid, $coursecontextid, 'mod_scorm', 'package', 0, null); | |
$usercontextid = context_user::instance($USER->id)->id; | |
$record = new StdClass(); | |
$record->course = $courseid; | |
$record->contextid = $usercontextid; | |
$record->userid = $USER->id; | |
$record->component = 'user'; | |
$record->filearea = 'draft'; | |
$record->itemid = $draftitemid; | |
$record->filename = $scormFilename; | |
$record->filepath = '/'; | |
$file = $fs->create_file_from_pathname($record, '/var/www/html/altamar/local/altamarimport/zips/' .$scormFilename); | |
$scorm->packagefile = $draftitemid; | |
$modinfo = add_moduleinfo($scorm, $course); | |
} | |
echo $OUTPUT->footer(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment