Exemplo n.º 1
0
 /**
  * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/JCLIC
  * data available
  */
 public function process_jclic($data)
 {
     // get the course module id and context id
     $instanceid = $data['id'];
     $cminfo = $this->get_cminfo($instanceid);
     $this->moduleid = $cminfo['id'];
     $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid);
     // get a fresh new file manager for this instance
     $this->fileman = $this->converter->get_file_manager($contextid, 'mod_jclic');
     // convert course files embedded into the intro
     $this->fileman->filearea = 'intro';
     $this->fileman->itemid = 0;
     $data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman);
     // migrate jclic package file
     $this->fileman->filearea = 'content';
     $this->fileman->itemid = 0;
     if (!jclic_is_valid_external_url($data['url'])) {
         // Migrate file
         try {
             $this->fileman->migrate_file('course_files/' . $data['url']);
         } catch (Exception $e) {
             echo 'Caught exception: ', $e->getMessage(), ' File: \'', $data['url'], '\' on JClic activity \'' . $data['name'] . '\' <br>';
         }
     }
     // To avoid problems if maxgrade is null
     if ($data['maxgrade'] === NULL) {
         $data['maxgrade'] = 100;
     }
     // get grade value from maxgrade
     $data['grade'] = $data['maxgrade'];
     // start writing jclic.xml
     $this->open_xml_writer("activities/jclic_{$this->moduleid}/jclic.xml");
     $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 'modulename' => 'jclic', 'contextid' => $contextid));
     $this->xmlwriter->begin_tag('jclic', array('id' => $instanceid));
     foreach ($data as $field => $value) {
         if ($field != 'id') {
             $this->xmlwriter->full_tag($field, $value);
         }
     }
     return $data;
 }
Exemplo n.º 2
0
/**
 * Migrate jclic package to new area if found
 *
 * @return
 */
function jclic_migrate_files()
{
    global $CFG, $DB;
    $fs = get_file_storage();
    $sqlfrom = "FROM {jclic} j\n                JOIN {modules} m ON m.name = 'jclic'\n                JOIN {course_modules} cm ON (cm.module = m.id AND cm.instance = j.id)";
    $count = $DB->count_records_sql("SELECT COUNT('x') {$sqlfrom}");
    $rs = $DB->get_recordset_sql("SELECT j.id, j.url, j.course, cm.id AS cmid {$sqlfrom} ORDER BY j.course, j.id");
    if ($rs->valid()) {
        $pbar = new progress_bar('migratejclicfiles', 500, true);
        $i = 0;
        foreach ($rs as $jclic) {
            $i++;
            upgrade_set_timeout(180);
            // set up timeout, may also abort execution
            $pbar->update($i, $count, "Migrating jclic files - {$i}/{$count}.");
            $context = context_module::instance($jclic->cmid);
            $coursecontext = context_course::instance($jclic->course);
            if (!jclic_is_valid_external_url($jclic->url)) {
                // first copy local files if found - do not delete in case they are shared ;-)
                $jclicfile = clean_param($jclic->url, PARAM_PATH);
                $pathnamehash = sha1("/{$coursecontext->id}/course/legacy/0/{$jclicfile}");
                if ($file = $fs->get_file_by_hash($pathnamehash)) {
                    $file_record = array('contextid' => $context->id, 'component' => 'mod_jclic', 'filearea' => 'content', 'itemid' => 0, 'filepath' => '/');
                    try {
                        $fs->create_file_from_storedfile($file_record, $file);
                    } catch (Exception $x) {
                        // ignore any errors, we can not do much anyway
                    }
                    $jclic->url = $pathnamehash;
                } else {
                    $jclic->url = '';
                }
                $DB->update_record('jclic', $jclic);
            }
        }
    }
    $rs->close();
}
Exemplo n.º 3
0
 function set_data($default_values)
 {
     $default_values = (array) $default_values;
     if (isset($default_values['url'])) {
         if (jclic_is_valid_external_url($default_values['url'])) {
             $default_values['filetype'] = JCLIC_FILE_TYPE_EXTERNAL;
             $default_values['url'] = $default_values['url'];
         } else {
             $default_values['filetype'] = JCLIC_FILE_TYPE_LOCAL;
             $default_values['jclicfile'] = $default_values['url'];
             unset($default_values['url']);
         }
     }
     $this->data_preprocessing($default_values);
     parent::set_data($default_values);
 }
Exemplo n.º 4
0
function jclic_get_url($jclic, $context)
{
    global $CFG;
    $url = '';
    if (jclic_is_valid_external_url($jclic->url)) {
        $url = $jclic->url;
    } else {
        $fs = get_file_storage();
        $files = $fs->get_area_files($context->id, 'mod_jclic', 'content', 0, 'sortorder DESC, id ASC', false);
        if (count($files) < 1) {
            //resource_print_filenotfound($resource, $cm, $course);
            die;
        } else {
            $file = reset($files);
            unset($files);
        }
        $path = '/' . $context->id . '/mod_jclic/content/0' . $file->get_filepath() . $file->get_filename();
        $url = file_encode_url($CFG->wwwroot . '/pluginfile.php', $path, false);
    }
    return $url;
}