Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 11
Línea 74... Línea 74...
74
            $record->grademethod = manager::GRADEHIGHESTATTEMPT;
74
            $record->grademethod = manager::GRADEHIGHESTATTEMPT;
75
        }
75
        }
76
        if (!isset($record->reviewmode)) {
76
        if (!isset($record->reviewmode)) {
77
            $record->reviewmode = manager::REVIEWCOMPLETION;
77
            $record->reviewmode = manager::REVIEWCOMPLETION;
78
        }
78
        }
-
 
79
        $globaluser = $USER;
-
 
80
        if (!empty($record->username)) {
-
 
81
            $user = core_user::get_user_by_username($record->username);
-
 
82
            $this->set_user($user);
79
 
83
        }
80
        // The 'packagefile' value corresponds to the draft file area ID. If not specified, create from packagefilepath.
84
        // The 'packagefile' value corresponds to the draft file area ID. If not specified, create from packagefilepath.
81
        if (empty($record->packagefile)) {
85
        if (empty($record->packagefile)) {
82
            if (!isloggedin() || isguestuser()) {
86
            if (!isloggedin() || isguestuser()) {
83
                throw new coding_exception('H5P activity generator requires a current user');
87
                throw new coding_exception('H5P activity generator requires a current user');
84
            }
88
            }
85
            if (!file_exists($record->packagefilepath)) {
89
            if (!file_exists($record->packagefilepath)) {
86
                throw new coding_exception("File {$record->packagefilepath} does not exist");
90
                throw new coding_exception("File {$record->packagefilepath} does not exist");
87
            }
91
            }
-
 
92
 
88
            $usercontext = context_user::instance($USER->id);
93
            $usercontext = context_user::instance($USER->id);
Línea 89... Línea 94...
89
 
94
 
90
            // Pick a random context id for specified user.
95
            // Pick a random context id for specified user.
Línea 91... Línea 96...
91
            $record->packagefile = file_get_unused_draft_itemid();
96
            $record->packagefile = file_get_unused_draft_itemid();
-
 
97
 
-
 
98
            // Add actual file there.
92
 
99
            $filerecord = [
-
 
100
                'component' => 'user',
93
            // Add actual file there.
101
                'filearea' => 'draft',
94
            $filerecord = ['component' => 'user', 'filearea' => 'draft',
102
                'contextid' => $usercontext->id,
-
 
103
                'itemid' => $record->packagefile,
-
 
104
                'filename' => basename($record->packagefilepath),
-
 
105
                'filepath' => '/',
95
                    'contextid' => $usercontext->id, 'itemid' => $record->packagefile,
106
                'userid' => $USER->id,
96
                    'filename' => basename($record->packagefilepath), 'filepath' => '/'];
107
            ];
97
            $fs = get_file_storage();
108
            $fs = get_file_storage();
98
            $fs->create_file_from_pathname($filerecord, $record->packagefilepath);
-
 
-
 
109
            $fs->create_file_from_pathname($filerecord, $record->packagefilepath);
99
        }
110
        }
100
 
111
        $instance = parent::create_instance($record, (array)$options);
101
        // Do work to actually add the instance.
112
        $this->set_user($globaluser);
Línea 102... Línea 113...
102
        return parent::create_instance($record, (array)$options);
113
        return $instance;
103
    }
114
    }
104
 
115