Updated the HEAD build version to 20080816
[moodle.git] / mod / scorm / lib.php
CommitLineData
e4aa175a 1<?php // $Id$
2
e4aa175a 3/**
4* Given an object containing all the necessary data,
7cac0c4b 5* (defined by the form in mod_form.php) this function
e4aa175a 6* will create a new instance and return the id number
7* of the new instance.
8*
9* @param mixed $scorm Form data
10* @return int
11*/
23ab8e8d 12//require_once('locallib.php');
e4aa175a 13function scorm_add_instance($scorm) {
c18269c7 14 global $CFG, $DB;
a679d64d 15
16 require_once('locallib.php');
17
18 if (($packagedata = scorm_check_package($scorm)) != null) {
19 $scorm->pkgtype = $packagedata->pkgtype;
20 $scorm->datadir = $packagedata->datadir;
21 $scorm->launch = $packagedata->launch;
76ea4fb4 22 $scorm->parse = 1;
76ea4fb4 23
a679d64d 24 $scorm->timemodified = time();
25 if (!scorm_external_link($scorm->reference)) {
26 $scorm->md5hash = md5_file($CFG->dataroot.'/'.$scorm->course.'/'.$scorm->reference);
76ea4fb4 27 } else {
a679d64d 28 $scorm->dir = $CFG->dataroot.'/'.$scorm->course.'/moddata/scorm';
29 $scorm->md5hash = md5_file($scorm->dir.$scorm->datadir.'/'.basename($scorm->reference));
76ea4fb4 30 }
a679d64d 31
e4aa175a 32 $scorm = scorm_option2text($scorm);
33 $scorm->width = str_replace('%','',$scorm->width);
34 $scorm->height = str_replace('%','',$scorm->height);
35
36 //sanitize submitted values a bit
37 $scorm->width = clean_param($scorm->width, PARAM_INT);
38 $scorm->height = clean_param($scorm->height, PARAM_INT);
b3659259 39
40 if (!isset($scorm->whatgrade)) {
41 $scorm->whatgrade = 0;
42 }
a30b6819 43 $scorm->grademethod = ($scorm->whatgrade * 10) + $scorm->grademethod;
e4aa175a 44
c18269c7 45 $id = $DB->insert_record('scorm', $scorm);
e4aa175a 46
8949f8df 47 if (scorm_external_link($scorm->reference) || ((basename($scorm->reference) != 'imsmanifest.xml') && ($scorm->reference[0] != '#'))) {
e4aa175a 48 // Rename temp scorm dir to scorm id
49 $scorm->dir = $CFG->dataroot.'/'.$scorm->course.'/moddata/scorm';
50 rename($scorm->dir.$scorm->datadir,$scorm->dir.'/'.$id);
51 }
52
53 // Parse scorm manifest
5c1ac70c 54 if ($scorm->parse == 1) {
e4aa175a 55 $scorm->id = $id;
56 $scorm->launch = scorm_parse($scorm);
c18269c7 57 $DB->set_field('scorm', 'launch', $scorm->launch, array('id'=>$scorm->id));
e4aa175a 58 }
59
c18269c7 60 scorm_grade_item_update($scorm);
531fa830 61
e4aa175a 62 return $id;
a679d64d 63 } else {
7cac0c4b 64 print_error('badpackage','scorm');
e4aa175a 65 }
66}
67
68/**
69* Given an object containing all the necessary data,
7cac0c4b 70* (defined by the form in mod_form.php) this function
e4aa175a 71* will update an existing instance with new data.
72*
73* @param mixed $scorm Form data
74* @return int
75*/
76function scorm_update_instance($scorm) {
c18269c7 77 global $CFG, $DB;
e4aa175a 78
a679d64d 79 require_once('locallib.php');
76ea4fb4 80
23ab8e8d 81 $scorm->parse = 0;
a679d64d 82 if (($packagedata = scorm_check_package($scorm)) != null) {
83 $scorm->pkgtype = $packagedata->pkgtype;
84 if ($packagedata->launch == 0) {
85 $scorm->launch = $packagedata->launch;
86 $scorm->datadir = $packagedata->datadir;
76ea4fb4 87 $scorm->parse = 1;
a679d64d 88 if (!scorm_external_link($scorm->reference)) {
89 $scorm->md5hash = md5_file($CFG->dataroot.'/'.$scorm->course.'/'.$scorm->reference);
90 } else {
91 $scorm->dir = $CFG->dataroot.'/'.$scorm->course.'/moddata/scorm';
92 $scorm->md5hash = md5_file($scorm->dir.$scorm->datadir.'/'.basename($scorm->reference));
93 }
76ea4fb4 94 }
95 }
96
e4aa175a 97 $scorm->timemodified = time();
98 $scorm->id = $scorm->instance;
bfe8c2f0 99
e4aa175a 100 $scorm = scorm_option2text($scorm);
101 $scorm->width = str_replace('%','',$scorm->width);
102 $scorm->height = str_replace('%','',$scorm->height);
103
b3659259 104 if (!isset($scorm->whatgrade)) {
105 $scorm->whatgrade = 0;
106 }
a30b6819 107 $scorm->grademethod = ($scorm->whatgrade * 10) + $scorm->grademethod;
108
e4aa175a 109 // Check if scorm manifest needs to be reparsed
5c1ac70c 110 if ($scorm->parse == 1) {
e4aa175a 111 $scorm->dir = $CFG->dataroot.'/'.$scorm->course.'/moddata/scorm';
5c1ac70c 112 if (is_dir($scorm->dir.'/'.$scorm->id)) {
e4aa175a 113 scorm_delete_files($scorm->dir.'/'.$scorm->id);
5c1ac70c 114 }
115 if (isset($scorm->datadir) && ($scorm->datadir != $scorm->id) &&
8949f8df 116 (scorm_external_link($scorm->reference) || ((basename($scorm->reference) != 'imsmanifest.xml') && ($scorm->reference[0] != '#')))) {
e4aa175a 117 rename($scorm->dir.$scorm->datadir,$scorm->dir.'/'.$scorm->id);
118 }
a30b6819 119
e4aa175a 120 $scorm->launch = scorm_parse($scorm);
a9d22c84 121 } else {
c18269c7 122 $oldscorm = $DB->get_record('scorm', array('id'=>$scorm->id));
a9d22c84 123 $scorm->reference = $oldscorm->reference; // This fix a problem with Firefox when the teacher choose Cancel on overwrite question
e4aa175a 124 }
a9d22c84 125
c18269c7 126 if ($result = $DB->update_record('scorm', $scorm)) {
127 scorm_grade_item_update($scorm);
531fa830 128 }
129
130 return $result;
e4aa175a 131}
132
133/**
134* Given an ID of an instance of this module,
135* this function will permanently delete the instance
136* and any data that depends on it.
137*
138* @param int $id Scorm instance id
139* @return boolean
140*/
141function scorm_delete_instance($id) {
c18269c7 142 global $CFG, $DB;
e4aa175a 143
c18269c7 144 if (! $scorm = $DB->get_record('scorm', array('id'=>$id))) {
e4aa175a 145 return false;
146 }
147
148 $result = true;
149
2b3447c3 150 $scorm->dir = $CFG->dataroot.'/'.$scorm->course.'/moddata/scorm';
151 if (is_dir($scorm->dir.'/'.$scorm->id)) {
152 // Delete any dependent files
153 require_once('locallib.php');
154 scorm_delete_files($scorm->dir.'/'.$scorm->id);
155 }
e4aa175a 156
157 // Delete any dependent records
c18269c7 158 if (! $DB->delete_records('scorm_scoes_track', array('scormid'=>$scorm->id))) {
e4aa175a 159 $result = false;
160 }
c18269c7 161 if ($scoes = $DB->get_records('scorm_scoes', array('scorm'=>$scorm->id))) {
b3659259 162 foreach ($scoes as $sco) {
c18269c7 163 if (! $DB->delete_records('scorm_scoes_data', array('scoid'=>$sco->id))) {
b3659259 164 $result = false;
165 }
166 }
c18269c7 167 $DB->delete_records('scorm_scoes', array('scorm'=>$scorm->id));
b3659259 168 } else {
e4aa175a 169 $result = false;
170 }
c18269c7 171 if (! $DB->delete_records('scorm', array('id'=>$scorm->id))) {
e4aa175a 172 $result = false;
173 }
a30b6819 174
c18269c7 175 /*if (! $DB->delete_records('scorm_sequencing_controlmode', array('scormid'=>$scorm->id))) {
e4aa175a 176 $result = false;
177 }
c18269c7 178 if (! $DB->delete_records('scorm_sequencing_rolluprules', array('scormid'=>$scorm->id))) {
e4aa175a 179 $result = false;
180 }
c18269c7 181 if (! $DB->delete_records('scorm_sequencing_rolluprule', array('scormid'=>$scorm->id))) {
e4aa175a 182 $result = false;
183 }
c18269c7 184 if (! $DB->delete_records('scorm_sequencing_rollupruleconditions', array('scormid'=>$scorm->id))) {
e4aa175a 185 $result = false;
186 }
c18269c7 187 if (! $DB->delete_records('scorm_sequencing_rolluprulecondition', array('scormid'=>$scorm->id))) {
e4aa175a 188 $result = false;
189 }
c18269c7 190 if (! $DB->delete_records('scorm_sequencing_rulecondition', array('scormid'=>$scorm->id))) {
e4aa175a 191 $result = false;
192 }
c18269c7 193 if (! $DB->delete_records('scorm_sequencing_ruleconditions', array('scormid'=>$scorm->id))) {
e4aa175a 194 $result = false;
531fa830 195 }*/
196
c18269c7 197 scorm_grade_item_delete($scorm);
531fa830 198
e4aa175a 199 return $result;
200}
201
202/**
203* Return a small object with summary information about what a
204* user has done with a given particular instance of this module
205* Used for user activity reports.
206*
207* @param int $course Course id
208* @param int $user User id
209* @param int $mod
210* @param int $scorm The scorm id
211* @return mixed
212*/
213function scorm_user_outline($course, $user, $mod, $scorm) {
531fa830 214 global $CFG;
a30b6819 215 require_once('locallib.php');
216
217 $return = scorm_grade_user($scorm, $user->id, true);
218
e4aa175a 219 return $return;
220}
221
222/**
223* Print a detailed representation of what a user has done with
224* a given particular instance of this module, for user activity reports.
225*
226* @param int $course Course id
227* @param int $user User id
228* @param int $mod
229* @param int $scorm The scorm id
230* @return boolean
231*/
232function scorm_user_complete($course, $user, $mod, $scorm) {
bf347041 233 global $CFG, $DB;
e4aa175a 234
235 $liststyle = 'structlist';
236 $scormpixdir = $CFG->modpixpath.'/scorm/pix';
237 $now = time();
238 $firstmodify = $now;
239 $lastmodify = 0;
240 $sometoreport = false;
241 $report = '';
242
bf347041 243 if ($orgs = $DB->get_records('scorm_scoes', array('scorm'=>$scorm->id, 'organization'=>'', 'launch'=>''),'id','id,identifier,title')) {
e4aa175a 244 if (count($orgs) <= 1) {
245 unset($orgs);
246 $orgs[]->identifier = '';
247 }
248 $report .= '<div class="mod-scorm">'."\n";
249 foreach ($orgs as $org) {
bf347041 250 $conditions = array();
e4aa175a 251 $currentorg = '';
252 if (!empty($org->identifier)) {
253 $report .= '<div class="orgtitle">'.$org->title.'</div>';
254 $currentorg = $org->identifier;
bf347041 255 $conditions['organization'] = $currentorg;
e4aa175a 256 }
257 $report .= "<ul id='0' class='$liststyle'>";
bf347041 258 $conditions['scorm'] = $scorm->id;
259 if ($scoes = $DB->get_records('scorm_scoes', $conditions, "id ASC")){
9fb2de4e 260 // drop keys so that we can access array sequentially
261 $scoes = array_values($scoes);
e4aa175a 262 $level=0;
263 $sublist=1;
264 $parents[$level]='/';
9fb2de4e 265 foreach ($scoes as $pos=>$sco) {
e4aa175a 266 if ($parents[$level]!=$sco->parent) {
267 if ($level>0 && $parents[$level-1]==$sco->parent) {
268 $report .= "\t\t</ul></li>\n";
269 $level--;
270 } else {
271 $i = $level;
272 $closelist = '';
273 while (($i > 0) && ($parents[$level] != $sco->parent)) {
274 $closelist .= "\t\t</ul></li>\n";
275 $i--;
276 }
277 if (($i == 0) && ($sco->parent != $currentorg)) {
278 $report .= "\t\t<li><ul id='$sublist' class='$liststyle'>\n";
279 $level++;
280 } else {
281 $report .= $closelist;
282 $level = $i;
283 }
284 $parents[$level]=$sco->parent;
285 }
286 }
287 $report .= "\t\t<li>";
9fb2de4e 288 if (isset($scoes[$pos+1])) {
289 $nextsco = $scoes[$pos+1];
290 } else {
291 $nextsco = false;
292 }
e4aa175a 293 if (($nextsco !== false) && ($sco->parent != $nextsco->parent) && (($level==0) || (($level>0) && ($nextsco->parent == $sco->identifier)))) {
294 $sublist++;
295 } else {
7150b8ae 296 $report .= '<img src="'.$scormpixdir.'/spacer.gif" alt="" />';
e4aa175a 297 }
298
299 if ($sco->launch) {
300 require_once('locallib.php');
301 $score = '';
302 $totaltime = '';
303 if ($usertrack=scorm_get_tracks($sco->id,$user->id)) {
304 if ($usertrack->status == '') {
305 $usertrack->status = 'notattempted';
306 }
307 $strstatus = get_string($usertrack->status,'scorm');
308 $report .= "<img src='".$scormpixdir.'/'.$usertrack->status.".gif' alt='$strstatus' title='$strstatus' />";
309 if ($usertrack->timemodified != 0) {
310 if ($usertrack->timemodified > $lastmodify) {
311 $lastmodify = $usertrack->timemodified;
312 }
313 if ($usertrack->timemodified < $firstmodify) {
314 $firstmodify = $usertrack->timemodified;
315 }
316 }
317 } else {
318 if ($sco->scormtype == 'sco') {
319 $report .= '<img src="'.$scormpixdir.'/'.'notattempted.gif" alt="'.get_string('notattempted','scorm').'" title="'.get_string('notattempted','scorm').'" />';
320 } else {
321 $report .= '<img src="'.$scormpixdir.'/'.'asset.gif" alt="'.get_string('asset','scorm').'" title="'.get_string('asset','scorm').'" />';
322 }
323 }
324 $report .= "&nbsp;$sco->title $score$totaltime</li>\n";
325 if ($usertrack !== false) {
326 $sometoreport = true;
327 $report .= "\t\t\t<li><ul class='$liststyle'>\n";
328 foreach($usertrack as $element => $value) {
329 if (substr($element,0,3) == 'cmi') {
330 $report .= '<li>'.$element.' => '.$value.'</li>';
331 }
332 }
333 $report .= "\t\t\t</ul></li>\n";
334 }
335 } else {
336 $report .= "&nbsp;$sco->title</li>\n";
337 }
338 }
339 for ($i=0;$i<$level;$i++) {
340 $report .= "\t\t</ul></li>\n";
341 }
342 }
343 $report .= "\t</ul><br />\n";
344 }
345 $report .= "</div>\n";
346 }
347 if ($sometoreport) {
348 if ($firstmodify < $now) {
349 $timeago = format_time($now - $firstmodify);
350 echo get_string('firstaccess','scorm').': '.userdate($firstmodify).' ('.$timeago.")<br />\n";
351 }
352 if ($lastmodify > 0) {
353 $timeago = format_time($now - $lastmodify);
354 echo get_string('lastaccess','scorm').': '.userdate($lastmodify).' ('.$timeago.")<br />\n";
355 }
356 echo get_string('report','scorm').":<br />\n";
357 echo $report;
358 } else {
dabfd0ed 359 print_string('noactivity','scorm');
e4aa175a 360 }
361
362 return true;
363}
364
e4aa175a 365/**
366* Function to be run periodically according to the moodle cron
367* This function searches for things that need to be done, such
368* as sending out mail, toggling flags etc ...
369*
370* @return boolean
371*/
372function scorm_cron () {
bf347041 373 global $CFG, $DB;
a679d64d 374
375 require_once('locallib.php');
376
377 $sitetimezone = $CFG->timezone;
378 /// Now see if there are any digest mails waiting to be sent, and if we should send them
bfe8c2f0 379 if (!isset($CFG->scorm_updatetimelast)) { // To catch the first time
380 set_config('scorm_updatetimelast', 0);
381 }
382
a679d64d 383 $timenow = time();
bfe8c2f0 384 $updatetime = usergetmidnight($timenow, $sitetimezone) + ($CFG->scorm_updatetime * 3600);
a679d64d 385
386 if ($CFG->scorm_updatetimelast < $updatetime and $timenow > $updatetime) {
387
bfe8c2f0 388 set_config('scorm_updatetimelast', $timenow);
e4aa175a 389
376c9c70 390 mtrace('Updating scorm packages which require daily update');//We are updating
bfe8c2f0 391
bf347041 392 $scormsupdate = $DB->get_records('scorm', array('updatefreq'=>UPDATE_EVERYDAY));
a679d64d 393 if (!empty($scormsupdate)) {
394 foreach($scormsupdate as $scormupdate) {
395 $scormupdate->instance = $scormupdate->id;
396 $id = scorm_update_instance($scormupdate);
397 }
398 }
399 }
400
e4aa175a 401 return true;
402}
403
404/**
531fa830 405 * Return grade for given user or all users.
406 *
407 * @param int $scormid id of scorm
408 * @param int $userid optional user id, 0 means all users
409 * @return array array of grades, false if none
410 */
411function scorm_get_user_grades($scorm, $userid=0) {
bf347041 412 global $CFG, $DB;
531fa830 413 require_once('locallib.php');
414
415 $grades = array();
416 if (empty($userid)) {
bf347041 417 if ($scousers = $DB->get_records_select('scorm_scoes_track', "scormid=? GROUP BY userid", array($scorm->id), "", "userid,null")) {
531fa830 418 foreach ($scousers as $scouser) {
419 $grades[$scouser->userid] = new object();
420 $grades[$scouser->userid]->id = $scouser->userid;
421 $grades[$scouser->userid]->userid = $scouser->userid;
422 $grades[$scouser->userid]->rawgrade = scorm_grade_user($scorm, $scouser->userid);
423 }
424 } else {
425 return false;
426 }
e4aa175a 427
531fa830 428 } else {
bf347041 429 if (!$DB->get_records_select('scorm_scoes_track', "scormid=? AND userid=? GROUP BY userid", array($scorm->id, $userid), "", "userid,null")) {
531fa830 430 return false; //no attempt yet
431 }
432 $grades[$userid] = new object();
433 $grades[$userid]->id = $userid;
434 $grades[$userid]->userid = $userid;
435 $grades[$userid]->rawgrade = scorm_grade_user($scorm, $userid);
e4aa175a 436 }
e4aa175a 437
531fa830 438 return $grades;
439}
440
441/**
442 * Update grades in central gradebook
443 *
444 * @param object $scorm null means all scormbases
445 * @param int $userid specific user only, 0 mean all
446 */
447function scorm_update_grades($scorm=null, $userid=0, $nullifnone=true) {
bf347041 448 global $CFG, $DB;
531fa830 449 if (!function_exists('grade_update')) { //workaround for buggy PHP versions
450 require_once($CFG->libdir.'/gradelib.php');
451 }
452
453 if ($scorm != null) {
454 if ($grades = scorm_get_user_grades($scorm, $userid)) {
50acc613 455 scorm_grade_item_update($scorm, $grades);
531fa830 456
457 } else if ($userid and $nullifnone) {
458 $grade = new object();
459 $grade->userid = $userid;
460 $grade->rawgrade = NULL;
eafb9d9e 461 scorm_grade_item_update($scorm, $grade);
462
463 } else {
464 scorm_grade_item_update($scorm);
e4aa175a 465 }
531fa830 466
e4aa175a 467 } else {
531fa830 468 $sql = "SELECT s.*, cm.idnumber as cmidnumber
bf347041 469 FROM {scorm} s, {course_modules} cm, {modules} m
531fa830 470 WHERE m.name='scorm' AND m.id=cm.module AND cm.instance=s.id";
bf347041 471 if ($rs = $DB->get_recordset_sql($sql)) {
472 foreach ($rs as $scorm) {
03cedd62 473 scorm_update_grades($scorm, 0, false);
531fa830 474 }
bf347041 475 $rs->close();
531fa830 476 }
e4aa175a 477 }
531fa830 478}
e4aa175a 479
531fa830 480/**
481 * Update/create grade item for given scorm
482 *
483 * @param object $scorm object with extra cmidnumber
0b5a80a1 484 * @param mixed optional array/object of grade(s); 'reset' means reset grades in gradebook
531fa830 485 * @return object grade_item
486 */
0b5a80a1 487function scorm_grade_item_update($scorm, $grades=NULL) {
bf347041 488 global $CFG, $DB;
531fa830 489 if (!function_exists('grade_update')) { //workaround for buggy PHP versions
490 require_once($CFG->libdir.'/gradelib.php');
491 }
492
493 $params = array('itemname'=>$scorm->name, 'idnumber'=>$scorm->cmidnumber);
494
495 if (($scorm->grademethod % 10) == 0) { // GRADESCOES
6280b17a 496 if ($maxgrade = $DB->count_records_select('scorm_scoes', 'scorm = ? AND launch <> ?', array($scorm->id, ''))) {
531fa830 497 $params['gradetype'] = GRADE_TYPE_VALUE;
498 $params['grademax'] = $maxgrade;
499 $params['grademin'] = 0;
500 } else {
501 $params['gradetype'] = GRADE_TYPE_NONE;
e4aa175a 502 }
531fa830 503 } else {
504 $params['gradetype'] = GRADE_TYPE_VALUE;
505 $params['grademax'] = $scorm->maxgrade;
506 $params['grademin'] = 0;
e4aa175a 507 }
531fa830 508
0b5a80a1 509 if ($grades === 'reset') {
510 $params['reset'] = true;
511 $grades = NULL;
512 }
513
514 return grade_update('mod/scorm', $scorm->course, 'mod', 'scorm', $scorm->id, 0, $grades, $params);
531fa830 515}
516
517/**
518 * Delete grade item for given scorm
519 *
520 * @param object $scorm object
521 * @return object grade_item
522 */
523function scorm_grade_item_delete($scorm) {
524 global $CFG;
525 require_once($CFG->libdir.'/gradelib.php');
526
527 return grade_update('mod/scorm', $scorm->course, 'mod', 'scorm', $scorm->id, 0, NULL, array('deleted'=>1));
e4aa175a 528}
529
530function scorm_get_view_actions() {
531 return array('pre-view','view','view all','report');
532}
533
534function scorm_get_post_actions() {
535 return array();
536}
537
e4aa175a 538function scorm_option2text($scorm) {
539 global $SCORM_POPUP_OPTIONS;
e4aa175a 540 if (isset($scorm->popup)) {
76ea4fb4 541 if ($scorm->popup == 1) {
e4aa175a 542 $optionlist = array();
543 foreach ($SCORM_POPUP_OPTIONS as $name => $option) {
544 if (isset($scorm->$name)) {
545 $optionlist[] = $name.'='.$scorm->$name;
546 } else {
547 $optionlist[] = $name.'=0';
548 }
549 }
550 $scorm->options = implode(',', $optionlist);
551 } else {
552 $scorm->options = '';
553 }
554 } else {
555 $scorm->popup = 0;
556 $scorm->options = '';
557 }
558 return $scorm;
559}
560
0b5a80a1 561/**
562 * Implementation of the function for printing the form elements that control
563 * whether the course reset functionality affects the scorm.
564 * @param $mform form passed by reference
565 */
566function scorm_reset_course_form_definition(&$mform) {
567 $mform->addElement('header', 'scormheader', get_string('modulenameplural', 'scorm'));
568 $mform->addElement('advcheckbox', 'reset_scorm', get_string('deleteallattempts','scorm'));
569}
570
571/**
572 * Course reset form defaults.
573 */
574function scorm_reset_course_form_defaults($course) {
575 return array('reset_scorm'=>1);
576}
577
578/**
579 * Removes all grades from gradebook
580 * @param int $courseid
581 * @param string optional type
582 */
583function scorm_reset_gradebook($courseid, $type='') {
bf347041 584 global $CFG, $DB;
0b5a80a1 585
586 $sql = "SELECT s.*, cm.idnumber as cmidnumber, s.course as courseid
bf347041 587 FROM {scorm} s, {course_modules} cm, {modules} m
588 WHERE m.name='scorm' AND m.id=cm.module AND cm.instance=s.id AND s.course=?";
0b5a80a1 589
bf347041 590 if ($scorms = $DB->get_records_sql($sql, array($courseid))) {
0b5a80a1 591 foreach ($scorms as $scorm) {
592 scorm_grade_item_update($scorm, 'reset');
593 }
594 }
595}
596
597/**
598 * Actual implementation of the rest coures functionality, delete all the
599 * scorm attempts for course $data->courseid.
600 * @param $data the data submitted from the reset course.
601 * @return array status array
602 */
603function scorm_reset_userdata($data) {
bf347041 604 global $CFG, $DB;
0b5a80a1 605
606 $componentstr = get_string('modulenameplural', 'scorm');
607 $status = array();
608
609 if (!empty($data->reset_scorm)) {
610 $scormssql = "SELECT s.id
bf347041 611 FROM {scorm} s
612 WHERE s.course=?";
0b5a80a1 613
bf347041 614 $DB->delete_records_select('scorm_scoes_track', "scormid IN ($scormssql)", array($data->courseid));
0b5a80a1 615
616 // remove all grades from gradebook
617 if (empty($data->reset_gradebook_grades)) {
618 scorm_reset_gradebook($data->courseid);
619 }
620
621 $status[] = array('component'=>$componentstr, 'item'=>get_string('deleteallattempts', 'scorm'), 'error'=>false);
622 }
623
624 // no dates to shift here
625
626 return $status;
627}
628
f432bebf 629/**
630 * Returns all other caps used in module
631 */
632function scorm_get_extra_capabilities() {
633 return array('moodle/site:accessallgroups');
634}
635
5c1ac70c 636?>