@@ -58,7 +58,8 @@ function save_item(
58
58
$ courseId = null ,
59
59
$ lmsFinish = 0 ,
60
60
$ userNavigatesAway = 0 ,
61
- $ statusSignalReceived = 0
61
+ $ statusSignalReceived = 0 ,
62
+ $ forceIframeSave = 0
62
63
) {
63
64
$ debug = 0 ;
64
65
$ return = null ;
@@ -107,6 +108,15 @@ function save_item(
107
108
108
109
// This functions sets the $this->db_item_view_id variable needed in get_status() see BT#5069
109
110
$ myLPI ->set_lp_view ($ view_id );
111
+ $ my_type = $ myLPI ->get_type ();
112
+
113
+ $ saveStatus = true ;
114
+ if ('document ' === $ my_type ) {
115
+ $ saveStatus = learnpathItem::isLpItemAutoComplete ($ myLPI ->getIid ());
116
+ if ($ forceIframeSave ) {
117
+ $ saveStatus = true ;
118
+ }
119
+ }
110
120
111
121
// Launch the prerequisites check and set error if needed
112
122
if (true !== $ prerequisitesCheck ) {
@@ -171,24 +181,29 @@ function save_item(
171
181
}
172
182
173
183
$ statusIsSet = false ;
174
- // Default behaviour.
175
- if (isset ($ status ) && $ status != '' && $ status != 'undefined ' ) {
176
- if ($ debug > 1 ) {
177
- error_log ('Calling set_status( ' .$ status .') ' );
178
- }
184
+ if ($ saveStatus ) {
185
+ // Default behaviour.
186
+ if (isset ($ status ) && $ status != '' && $ status != 'undefined ' ) {
187
+ if ($ debug > 1 ) {
188
+ error_log ('Calling set_status( ' .$ status .') ' );
189
+ }
179
190
180
- $ myLPI ->set_status ($ status );
181
- $ statusIsSet = true ;
182
- if ($ debug > 1 ) {
183
- error_log ('Done calling set_status: checking from memory: ' .$ myLPI ->get_status (false ));
191
+ $ myLPI ->set_status ($ status );
192
+ $ statusIsSet = true ;
193
+ if ($ debug > 1 ) {
194
+ error_log ('Done calling set_status: checking from memory: ' .$ myLPI ->get_status (false ));
195
+ }
196
+ } else {
197
+ if ($ debug > 1 ) {
198
+ error_log ('Status not updated ' );
199
+ }
184
200
}
185
201
} else {
186
202
if ($ debug > 1 ) {
187
203
error_log ('Status not updated ' );
188
204
}
189
205
}
190
206
191
- $ my_type = $ myLPI ->get_type ();
192
207
// Set status to completed for hotpotatoes if score > 80%.
193
208
if ($ my_type === 'hotpotatoes ' ) {
194
209
if ((empty ($ status ) || $ status == 'undefined ' || $ status == 'not attempted ' ) && $ max > 0 ) {
@@ -370,25 +385,30 @@ function save_item(
370
385
// End of type=='sco'
371
386
}
372
387
373
- // If no previous condition changed the SCO status, proceed with a
374
- // generic behaviour
375
- if (!$ statusIsSet && !$ statusSignalReceived ) {
376
- // Default behaviour
377
- if (isset ($ status ) && $ status != '' && $ status != 'undefined ' ) {
378
- if ($ debug > 1 ) {
379
- error_log ('Calling set_status( ' .$ status .') ' );
380
- }
388
+ // If no previous condition changed the SCO status, proceed with a generic behaviour
389
+ if ( $ saveStatus ) {
390
+ if (!$ statusIsSet && !$ statusSignalReceived ) {
391
+ // Default behaviour
392
+ if (isset ($ status ) && $ status != '' && $ status != 'undefined ' ) {
393
+ if ($ debug > 1 ) {
394
+ error_log ('Calling set_status( ' .$ status .') ' );
395
+ }
381
396
382
- $ myLPI ->set_status ($ status );
397
+ $ myLPI ->set_status ($ status );
383
398
384
- if ($ debug > 1 ) {
385
- error_log ('Done calling set_status: checking from memory: ' .$ myLPI ->get_status (false ));
386
- }
387
- } else {
388
- if ($ debug > 1 ) {
389
- error_log ("Status not updated " );
399
+ if ($ debug > 1 ) {
400
+ error_log ('Done calling set_status: checking from memory: ' .$ myLPI ->get_status (false ));
401
+ }
402
+ } else {
403
+ if ($ debug > 1 ) {
404
+ error_log ("Status not updated " );
405
+ }
390
406
}
391
407
}
408
+ } else {
409
+ if ($ debug > 1 ) {
410
+ error_log ("Status not updated " );
411
+ }
392
412
}
393
413
394
414
if (isset ($ time ) && $ time != '' && $ time != 'undefined ' ) {
@@ -440,7 +460,10 @@ function save_item(
440
460
if ($ core_exit != 'undefined ' ) {
441
461
$ myLPI ->set_core_exit ($ core_exit );
442
462
}
443
- $ myLP ->save_item ($ item_id , false );
463
+
464
+ if ($ saveStatus ) {
465
+ $ myLP ->save_item ($ item_id , false );
466
+ }
444
467
}
445
468
446
469
$ myStatusInDB = $ myLPI ->get_status (true );
@@ -478,37 +501,39 @@ function save_item(
478
501
error_log ("progress: $ myComplete / $ myTotal " );
479
502
}
480
503
481
- if ($ myLPI ->get_type () !== 'sco ' ) {
482
- // If this object's JS status has not been updated by the SCORM API, update now.
483
- $ return .= "olms.lesson_status=' " .$ myStatus ."'; " ;
484
- }
485
- $ return .= "update_toc(' " .$ myStatus ."',' " .$ item_id ."'); " ;
486
- $ update_list = $ myLP ->get_update_queue ();
487
-
488
- foreach ($ update_list as $ my_upd_id => $ my_upd_status ) {
489
- if ($ my_upd_id != $ item_id ) {
490
- /* Only update the status from other items (i.e. parents and brothers),
491
- do not update current as we just did it already. */
492
- $ return .= "update_toc(' " .$ my_upd_status ."',' " .$ my_upd_id ."'); " ;
504
+ if ($ saveStatus ) {
505
+ if ($ myLPI ->get_type () !== 'sco ' ) {
506
+ // If this object's JS status has not been updated by the SCORM API, update now.
507
+ $ return .= "olms.lesson_status=' " .$ myStatus ."'; " ;
493
508
}
494
- }
495
- $ progressBarSpecial = false ;
496
- $ scoreAsProgressSetting = api_get_configuration_value ('lp_score_as_progress_enable ' );
497
- if ($ scoreAsProgressSetting === true ) {
498
- $ scoreAsProgress = $ myLP ->getUseScoreAsProgress ();
499
- if ($ scoreAsProgress ) {
500
- // Only update score if it was set by scorm.
501
- if (isset ($ score ) && $ score != -1 ) {
502
- $ score = $ myLPI ->get_score ();
503
- $ maxScore = $ myLPI ->get_max ();
504
- $ return .= "update_progress_bar(' $ score', ' $ maxScore', ' $ myProgressMode'); " ;
509
+ $ return .= "update_toc(' " .$ myStatus ."',' " .$ item_id ."'); " ;
510
+ $ update_list = $ myLP ->get_update_queue ();
511
+ foreach ($ update_list as $ my_upd_id => $ my_upd_status ) {
512
+ if ($ my_upd_id != $ item_id ) {
513
+ /* Only update the status from other items (i.e. parents and brothers),
514
+ do not update current as we just did it already. */
515
+ $ return .= "update_toc(' " .$ my_upd_status ."',' " .$ my_upd_id ."'); " ;
505
516
}
506
- $ progressBarSpecial = true ;
507
517
}
508
- }
509
518
510
- if (!$ progressBarSpecial ) {
511
- $ return .= "update_progress_bar(' $ myComplete', ' $ myTotal', ' $ myProgressMode'); " ;
519
+ $ progressBarSpecial = false ;
520
+ $ scoreAsProgressSetting = api_get_configuration_value ('lp_score_as_progress_enable ' );
521
+ if ($ scoreAsProgressSetting === true ) {
522
+ $ scoreAsProgress = $ myLP ->getUseScoreAsProgress ();
523
+ if ($ scoreAsProgress ) {
524
+ // Only update score if it was set by scorm.
525
+ if (isset ($ score ) && $ score != -1 ) {
526
+ $ score = $ myLPI ->get_score ();
527
+ $ maxScore = $ myLPI ->get_max ();
528
+ $ return .= "update_progress_bar(' $ score', ' $ maxScore', ' $ myProgressMode'); " ;
529
+ }
530
+ $ progressBarSpecial = true ;
531
+ }
532
+ }
533
+
534
+ if (!$ progressBarSpecial ) {
535
+ $ return .= "update_progress_bar(' $ myComplete', ' $ myTotal', ' $ myProgressMode'); " ;
536
+ }
512
537
}
513
538
514
539
if (!Session::read ('login_as ' )) {
@@ -537,15 +562,17 @@ function save_item(
537
562
$ return .= 'update_stats(); ' ;
538
563
}
539
564
540
- // To be sure progress is updated.
541
- $ myLP ->save_last ($ score );
565
+ if ($ saveStatus ) {
566
+ // To be sure progress is updated.
567
+ $ myLP ->save_last ($ score );
568
+ HookLearningPathItemViewed::create ()
569
+ ->setEventData (['item_view_id ' => $ myLPI ->db_item_view_id ])
570
+ ->notifyLearningPathItemViewed ();
542
571
543
- HookLearningPathItemViewed:: create ()
544
- -> setEventData ([ ' item_view_id ' => $ myLPI -> db_item_view_id ])
545
- -> notifyLearningPathItemViewed ();
572
+ Session:: write ( ' lpobject ' , serialize ( $ myLP ));
573
+ Session:: write ( ' oLP ' , $ myLP );
574
+ }
546
575
547
- Session::write ('lpobject ' , serialize ($ myLP ));
548
- Session::write ('oLP ' , $ myLP );
549
576
if ($ debug > 0 ) {
550
577
error_log ("lp_view_session_id : " .$ myLP ->lp_view_session_id );
551
578
error_log ('---------------- lp_ajax_save_item.php : save_item end ----- ' );
@@ -593,5 +620,6 @@ function save_item(
593
620
(!empty ($ _REQUEST ['course_id ' ]) ? $ _REQUEST ['course_id ' ] : '' ),
594
621
(empty ($ _REQUEST ['finish ' ]) ? 0 : 1 ),
595
622
(empty ($ _REQUEST ['userNavigatesAway ' ]) ? 0 : 1 ),
596
- (empty ($ _REQUEST ['statusSignalReceived ' ]) ? 0 : 1 )
623
+ (empty ($ _REQUEST ['statusSignalReceived ' ]) ? 0 : 1 ),
624
+ isset ($ _REQUEST ['forceIframeSave ' ]) ? (int ) $ _REQUEST ['forceIframeSave ' ] : 0
597
625
);
0 commit comments