2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 function scorm_seq_exit_action_rules($seq, $userid) {
18 $sco = $seq->currentactivity
;
19 $ancestors = scorm_get_ancestors($sco);
21 foreach (array_reverse($ancestors) as $ancestor) {
22 if (scorm_seq_rules_check($ancestor, 'exit') != null) {
23 $exittarget = $ancestor;
27 if ($exittarget != null) {
28 $commons = array_slice($ancestors, 0, scorm_find_common_ancestor($ancestors, $exittarget));
30 // Terminate Descendent Attempts Process.
32 foreach ($commons as $ancestor) {
33 scorm_seq_end_attempt($ancestor, $userid, $seq->attempt
);
34 $seq->currentactivity
= $ancestor;
41 function scorm_seq_post_cond_rules($seq, $userid) {
42 $sco = $seq->currentactivity
;
43 if (!$seq->suspended
) {
44 if ($action = scorm_seq_rules_check($sco, 'post') != null) {
49 $seq->sequencing
= $action;
53 $seq->termination
= $action;
56 $seq->termination
= 'exitall';
57 $seq->sequencing
= 'retry';
66 function scorm_seq_evaluate_rollupcond($sco, $conditioncombination, $rollupruleconds, $userid) {
71 foreach ($rollupruleconds as $rolluprulecond) {
72 $condit = scorm_evaluate_condition($rolluprulecond, $sco, $userid);
73 if ($rolluprulecond->operator
== 'not') { // If operator is not, negate the condition.
74 if ($rolluprulecond->cond
!= 'unknown') {
83 array_push($childrenbag, $condit);
90 foreach ($bag as $b) {
91 if ($rolluprulecond->conditioncombination
== 'all') {
93 if ($b == 'unknown') {
102 if ($b == 'unknown') {
117 function scorm_seq_check_child ($sco, $action, $userid) {
121 $sco = scorm_get_sco($sco->id
);
122 $r = scorm_get_sco_value($sco->id
, $userid, 'activityattemptcount');
123 if ($action == 'satisfied' ||
$action == 'notsatisfied') {
124 if (!$sco->rollupobjectivesatisfied
) {
126 if (($action == 'satisfied' && $sco->requiredforsatisfied
== 'ifnotsuspended') ||
127 ($action == 'notsatisfied' && $sco->requiredfornotsatisfied
== 'ifnotsuspended')) {
129 if (!scorm_seq_is('activityprogressstatus', $sco->id
, $userid) ||
130 ((($r->value
) > 0) && !scorm_seq_is('suspended', $sco->id
, $userid))) {
135 if (($action == 'satisfied' && $sco->requiredforsatisfied
== 'ifattempted') ||
136 ($action == 'notsatisfied' && $sco->requiredfornotsatisfied
== 'ifattempted')) {
137 if (!scorm_seq_is('activityprogressstatus', $sco->id
, $userid) ||
(($r->value
) == 0)) {
141 if (($action == 'satisfied' && $sco->requiredforsatisfied
== 'ifnotskipped') ||
142 ($action == 'notsatisfied' && $sco->requiredfornotsatisfied
== 'ifnotskipped')) {
143 $rulch = scorm_seq_rules_check($sco, 'skip');
144 if ($rulch != null) {
152 if ($action == 'completed' ||
$action == 'incomplete') {
153 if (!$sco->rollupprogresscompletion
) {
156 if (($action == 'completed' && $sco->requiredforcompleted
== 'ifnotsuspended') ||
157 ($action == 'incomplete' && $sco->requiredforincomplete
== 'ifnotsuspended')) {
159 if (!scorm_seq_is('activityprogressstatus', $sco->id
, $userid) ||
160 ((($r->value
) > 0)&& !scorm_seq_is('suspended', $sco->id
, $userid))) {
166 if (($action == 'completed' && $sco->requiredforcompleted
== 'ifattempted') ||
167 ($action == 'incomplete' && $sco->requiredforincomplete
== 'ifattempted')) {
168 if (!scorm_seq_is('activityprogressstatus', $sco->id
, $userid) ||
(($r->value
) == 0)) {
173 if (($action == 'completed' && $sco->requiredforsatisfied
== 'ifnotskipped') ||
174 ($action == 'incomplete' && $sco->requiredfornotsatisfied
== 'ifnotskipped')) {
175 $rulch = scorm_seq_rules_check($sco, 'skip');
176 if ($rulch != null) {
187 function scorm_seq_sequencing ($scoid, $userid, $seq) {
189 switch ($seq->sequencing
) {
191 // We'll see the parameters we have to send, this should update delivery and end.
192 $seq = scorm_seq_start_sequencing($scoid, $userid, $seq);
193 $seq->sequencing
= true;
197 // We'll see the parameters we have to send, this should update delivery and end.
198 $seq = scorm_seq_resume_all_sequencing($scoid, $userid, $seq);
199 $seq->sequencing
= true;
203 // We'll see the parameters we have to send, this should update delivery and end.
204 $seq = scorm_seq_exit_sequencing($scoid, $userid, $seq);
205 $seq->sequencing
= true;
209 // We'll see the parameters we have to send, this should update delivery and end.
210 $seq = scorm_seq_retry_sequencing($scoid, $userid, $seq);
211 $seq->sequencing
= true;
215 // We'll see the parameters we have to send, this should update delivery and end.
216 $seq = scorm_seq_previous_sequencing($scoid, $userid, $seq);
217 $seq->sequencing
= true;
221 // We'll see the parameters we have to send, this should update delivery and end.
222 $seq = scorm_seq_choice_sequencing($scoid, $userid, $seq);
223 $seq->sequencing
= true;
227 if ($seq->exception
!= null) {
228 $seq->sequencing
= false;
232 $seq->sequencing
= true;
236 function scorm_seq_start_sequencing($scoid, $userid, $seq) {
239 if (!empty($seq->currentactivity
)) {
240 $seq->delivery
= null;
241 $seq->exception
= 'SB.2.5-1';
244 $sco = $DB->get_record('scorm_scoes', array('scoid' => $scoid, 'userid' => $userid));
245 if (($sco->parent
== '/') && scorm_is_leaf($sco)) { // If the activity is the root and is leaf.
246 $seq->delivery
= $sco;
248 $ancestors = scorm_get_ancestors($sco);
249 $ancestorsroot = array_reverse($ancestors);
250 $res = scorm_seq_flow($ancestorsroot[0], 'forward', $seq, true, $userid);
257 function scorm_seq_resume_all_sequencing($scoid, $userid, $seq) {
260 if (!empty($seq->currentactivity
)) {
261 $seq->delivery
= null;
262 $seq->exception
= 'SB.2.6-1';
265 $track = scorm_get_sco_value($scoid, $userid, 'suspendedactivity');
267 $seq->delivery
= null;
268 $seq->exception
= 'SB.2.6-2';
271 // We assign the sco to the delivery.
272 $seq->delivery
= $DB->get_record('scorm_scoes', array('scoid' => $scoid, 'userid' => $userid));
275 function scorm_seq_continue_sequencing($scoid, $userid, $seq) {
276 if (empty($seq->currentactivity
)) {
277 $seq->delivery
= null;
278 $seq->exception
= 'SB.2.7-1';
281 $currentact = $seq->currentactivity
;
282 if ($currentact->parent
!= '/') {
283 // If the activity is the root and is leaf.
284 $parent = scorm_get_parent ($currentact);
286 if (!isset($parent->flow
) ||
($parent->flow
== false)) {
287 $seq->delivery
= null;
288 $seq->exception
= 'SB.2.7-2';
292 $res = scorm_seq_flow($currentact, 'forward', $seq, false, $userid);
299 function scorm_seq_previous_sequencing($scoid, $userid, $seq) {
300 if (empty($seq->currentactivity
)) {
301 $seq->delivery
= null;
302 $seq->exception
= 'SB.2.8-1';
306 $currentact = $seq->currentactivity
;
307 if ($currentact->parent
!= '/') { // If the activity is the root and is leaf.
308 $parent = scorm_get_parent ($currentact);
309 if (!isset($parent->flow
) ||
($parent->flow
== false)) {
310 $seq->delivery
= null;
311 $seq->exception
= 'SB.2.8-2';
315 $res = scorm_seq_flow($currentact, 'backward', $seq, false, $userid);
322 function scorm_seq_exit_sequencing($scoid, $userid, $seq) {
323 if (empty($seq->currentactivity
)) {
324 $seq->delivery
= null;
325 $seq->exception
= 'SB.2.11-1';
330 $seq->endsession
= false;
331 $seq->exception
= 'SB.2.11-2';
334 $currentact = $seq->currentactivity
;
335 if ($currentact->parent
== '/') {
336 $seq->endsession
= true;
340 $seq->endsession
= false;
344 function scorm_seq_retry_sequencing($scoid, $userid, $seq) {
345 if (empty($seq->currentactivity
)) {
346 $seq->delivery
= null;
347 $seq->exception
= 'SB.2.10-1';
350 if ($seq->active ||
$seq->suspended
) {
351 $seq->delivery
= null;
352 $seq->exception
= 'SB.2.10-2';
356 if (!scorm_is_leaf($seq->currentactivity
)) {
357 $res = scorm_seq_flow($seq->currentactivity
, 'forward', $seq, true, $userid);
362 $seq->delivery
= null;
363 $seq->exception
= 'SB.2.10-3';
367 $seq->delivery
= $seq->currentactivity
;
373 function scorm_seq_choice_sequencing($sco, $userid, $seq) {
375 $avchildren = Array ();
380 $seq->delivery
= null;
381 $seq->exception
= 'SB.2.9-1';
385 $ancestors = scorm_get_ancestors($sco);
386 $arrpath = array_reverse($ancestors);
387 array_push ($arrpath, $sco); // Path from the root to the target.
389 foreach ($arrpath as $activity) {
390 if ($activity->parent
!= '/') {
391 $avchildren = scorm_get_available_children (scorm_get_parent($activity));
392 $position = array_search($avchildren, $activity);
393 if ($position !== false) {
394 $seq->delivery
= null;
395 $seq->exception
= 'SB.2.9-2';
400 if (scorm_seq_rules_check($activity, 'hidefromchoice' != null)) {
401 $seq->delivery
= null;
402 $seq->exception
= 'SB.2.9-3';
407 if ($sco->parent
!= '/') {
408 $parent = scorm_sco_get_parent ($sco);
409 if ( isset($parent->choice
) && ($parent->choice
== false)) {
410 $seq->delivery
= null;
411 $seq->exception
= 'SB.2.9-4';
416 if ($seq->currentactivity
!= null) {
417 $commonpos = scorm_find_common_ancestor($ancestors, $seq->currentactivity
);
418 $comancestor = $arrpath [$commonpos];
420 $comancestor = $arrpath [0];
423 if ($seq->currentactivity
=== $sco) {
424 // MDL-51757 - this part of the SCORM 2004 sequencing and navigation was not completed.
425 throw new \
coding_exception('Unexpected state encountered');
428 $sib = scorm_get_siblings($seq->currentactivity
);
429 $pos = array_search($sib, $sco);
431 if ($pos !== false) {
432 $siblings = array_slice($sib, 0, $pos - 1);
433 if (empty($siblings)) {
434 $seq->delivery
= null;
435 $seq->exception
= 'SB.2.9-5';
439 $children = scorm_get_children (scorm_get_parent ($sco));
440 $pos1 = array_search($children, $sco);
441 $pos2 = array_search($seq->currentactivity
, $sco);
443 $traverse = 'forward';
445 $traverse = 'backward';
448 foreach ($siblings as $sibling) {
449 $seq = scorm_seq_choice_activity_traversal($sibling, $userid, $seq, $traverse);
450 if (!$seq->reachable
) {
451 $seq->delivery
= null;
455 // MDL-51757 - this part of the SCORM 2004 sequencing and navigation was not completed.
456 throw new \
coding_exception('Unexpected state encountered');
459 if ($seq->currentactivity
== null ||
$seq->currentactivity
== $comancestor) {
460 $commonpos = scorm_find_common_ancestor($ancestors, $seq->currentactivity
);
461 // Path from the common ancestor to the target activity.
462 $comtarget = array_slice($ancestors, 1, $commonpos - 1);
463 $comtarget = array_reverse($comtarget);
465 if (empty($comtarget)) {
466 $seq->delivery
= null;
467 $seq->exception
= 'SB.2.9-5';
470 foreach ($comtarget as $act) {
471 $seq = scorm_seq_choice_activity_traversal($act, $userid, $seq, 'forward');
472 if (!$seq->reachable
) {
473 $seq->delivery
= null;
476 $act = scorm_get_sco ($acti->id
);
477 if (scorm_seq_is('active', $act->id
, $userid) && ($act->id
!= $comancestor->id
&& $act->preventactivation
)) {
478 $seq->delivery
= null;
479 $seq->exception
= 'SB.2.9-6';
483 // MDL-51757 - this part of the SCORM 2004 sequencing and navigation was not completed.
484 throw new \
coding_exception('Unexpected state encountered');
487 if ($comancestor->id
== $sco->id
) {
489 $ancestorscurrent = scorm_get_ancestors($seq->currentactivity
);
490 $possco = array_search($ancestorscurrent, $sco);
491 // Path from the current activity to the target.
492 $curtarget = array_slice($ancestorscurrent, 0, $possco);
494 if (empty($curtarget)) {
495 $seq->delivery
= null;
496 $seq->exception
= 'SB.2.9-5';
500 foreach ($curtarget as $activ) {
502 if ($i != count($curtarget)) {
503 if (isset($activ->choiceexit
) && ($activ->choiceexit
== false)) {
504 $seq->delivery
= null;
505 $seq->exception
= 'SB.2.9-7';
510 // MDL-51757 - this part of the SCORM 2004 sequencing and navigation was not completed.
511 throw new \
coding_exception('Unexpected state encountered');
514 if (array_search($ancestors, $comancestor) !== false) {
515 $ancestorscurrent = scorm_get_ancestors($seq->currentactivity
);
516 $commonpos = scorm_find_common_ancestor($ancestors, $sco);
517 $curcommon = array_slice($ancestorscurrent, 0, $commonpos - 1);
518 if (empty($curcommon)) {
519 $seq->delivery
= null;
520 $seq->exception
= 'SB.2.9-5';
525 foreach ($curcommon as $acti) {
526 $acti = scorm_get_sco($acti->id
);
527 if (isset($acti->choiceexit
) && ($acti->choiceexit
== false)) {
528 $seq->delivery
= null;
529 $seq->exception
= 'SB.2.9-7';
532 if ($constrained == null) {
533 if ($acti->constrainchoice
== true) {
534 $constrained = $acti;
538 if ($constrained != null) {
539 $fwdir = scorm_get_preorder($constrained);
541 if (array_search($fwdir, $sco) !== false) {
542 $traverse = 'forward';
544 $traverse = 'backward';
546 $seq = scorm_seq_choice_flow($constrained, $traverse, $seq);
547 $actconsider = $seq->identifiedactivity
;
548 $avdescendents = Array();
549 $avdescendents = scorm_get_available_descendents($actconsider);
550 if (array_search ($avdescendents, $sco) !== false && $sco->id
!= $actconsider->id
&& $constrained->id
!= $sco->id
) {
551 $seq->delivery
= null;
552 $seq->exception
= 'SB.2.9-8';
558 $commonpos = scorm_find_common_ancestor($ancestors, $seq->currentactivity
);
559 $comtarget = array_slice($ancestors, 1, $commonpos - 1);// Path from the common ancestor to the target activity.
560 $comtarget = array_reverse($comtarget);
562 if (empty($comtarget)) {
563 $seq->delivery
= null;
564 $seq->exception
= 'SB.2.9-5';
568 $fwdir = scorm_get_preorder($seq->currentactivity
);
570 if (array_search($fwdir, $sco) !== false) {
571 foreach ($comtarget as $act) {
572 $seq = scorm_seq_choice_activity_traversal($act, $userid, $seq, 'forward');
573 if (!$seq->reachable
) {
574 $seq->delivery
= null;
577 $act = scorm_get_sco($act->id
);
578 if (scorm_seq_is('active', $act->id
, $userid) && ($act->id
!= $comancestor->id
&&
579 ($act->preventactivation
== true))) {
580 $seq->delivery
= null;
581 $seq->exception
= 'SB.2.9-6';
587 foreach ($comtarget as $act) {
588 $act = scorm_get_sco($act->id
);
589 if (scorm_seq_is('active', $act->id
, $userid) && $act->id
!= $comancestor->id
&& $act->preventactivation
== true) {
590 $seq->delivery
= null;
591 $seq->exception
= 'SB.2.9-6';
596 // MDL-51757 - this part of the SCORM 2004 sequencing and navigation was not completed.
597 throw new \
coding_exception('Unexpected state encountered');
600 if (scorm_is_leaf ($sco)) {
601 $seq->delivery
= $sco;
602 $seq->exception
= 'SB.2.9-6';
606 $seq = scorm_seq_flow($sco, 'forward', $seq, true, $userid);
607 if ($seq->deliverable
== false) {
608 scorm_terminate_descendent_attempts($comancestor, $userid, $seq);
609 scorm_seq_end_attempt($comancestor, $userid, $seq->attempt
);
610 $seq->currentactivity
= $sco;
611 $seq->delivery
= null;
612 $seq->exception
= 'SB.2.9-9';
620 function scorm_seq_choice_flow ($constrained, $traverse, $seq) {
621 $seq = scorm_seq_choice_flow_tree ($constrained, $traverse, $seq);
622 if ($seq->identifiedactivity
== null) {
623 $seq->identifiedactivity
= $constrained;
630 function scorm_seq_choice_flow_tree ($constrained, $traverse, $seq) {
632 $parent = scorm_get_parent ($constrained);
633 if ($traverse == 'forward') {
634 $preord = scorm_get_preorder($constrained);
635 if (count($preorder) == 0 ||
(count($preorder) == 0 && $preorder[0]->id
= $constrained->id
)) {
637 $islast = true; // The function is the last activity available.
639 if ($constrained->parent
== '/' ||
$islast) {
640 $seq->nextactivity
= null;
643 $avchildren = scorm_get_available_children($parent); // Available children.
644 if ($avchildren[count($avchildren) - 1]->id
== $constrained->id
) {
645 $seq = scorm_seq_choice_flow_tree ($parent, 'forward', $seq);
649 while ($i < count($avchildren)) {
650 if ($avchildren [$i]->id
== $constrained->id
) {
651 $seq->nextactivity
= $avchildren [$i +
1];
660 if ($traverse == 'backward') {
661 if ($constrained->parent
== '/' ) {
662 $seq->nextactivity
= null;
666 $avchildren = scorm_get_available_children($parent); // Available children.
667 if ($avchildren [0]->id
== $constrained->id
) {
668 $seq = scorm_seq_choice_flow_tree ($parent, 'backward', $seq);
671 $i = count($avchildren) - 1;
673 if ($avchildren [$i]->id
== $constrained->id
) {
674 $seq->nextactivity
= $avchildren [$i - 1];
684 function scorm_seq_choice_activity_traversal($activity, $userid, $seq, $direction) {
685 if ($direction == 'forward') {
686 $act = scorm_seq_rules_check($activity, 'stopforwardtraversal');
689 $seq->reachable
= false;
690 $seq->exception
= 'SB.2.4-1';
693 $seq->reachable
= false;
697 if ($direction == 'backward') {
698 $parentsco = scorm_get_parent($activity);
699 if ($parentsco != null) {
700 if (isset($parentsco->forwardonly
) && ($parentsco->forwardonly
== true)) {
701 $seq->reachable
= false;
702 $seq->exception
= 'SB.2.4-2';
705 $seq->reachable
= false;
706 $seq->exception
= 'SB.2.4-3';
711 $seq->reachable
= true;
715 // Delivery Request Process.
717 function scorm_sequencing_delivery($scoid, $userid, $seq) {
719 if (!scorm_is_leaf($seq->delivery
)) {
720 $seq->deliveryvalid
= false;
721 $seq->exception
= 'DB.1.1-1';
724 $ancestors = scorm_get_ancestors($seq->delivery
);
725 $arrpath = array_reverse($ancestors);
726 array_push ($arrpath, $seq->delivery
); // Path from the root to the target.
728 if (empty($arrpath)) {
729 $seq->deliveryvalid
= false;
730 $seq->exception
= 'DB.1.1-2';
734 foreach ($arrpath as $activity) {
735 if (scorm_check_activity($activity, $userid)) {
736 $seq->deliveryvalid
= false;
737 $seq->exception
= 'DB.1.1-3';
742 $seq->deliveryvalid
= true;
747 function scorm_content_delivery_environment($seq, $userid) {
750 $act = $seq->currentactivity
;
751 if (scorm_seq_is('active', $act->id
, $userid)) {
752 $seq->exception
= 'DB.2-1';
755 $track = scorm_get_sco_value($act->id
, $userid, 'suspendedactivity');
756 if ($track != null) {
757 $seq = scorm_clear_suspended_activity($seq->delivery
, $seq, $userid);
760 $attemptobject = scorm_get_attempt($userid, $track->scormid
, 0);
761 $seq = scorm_terminate_descendent_attempts ($seq->delivery
, $userid, $seq);
762 $ancestors = scorm_get_ancestors($seq->delivery
);
763 $arrpath = array_reverse($ancestors);
764 array_push ($arrpath, $seq->delivery
);
765 foreach ($arrpath as $activity) {
766 if (!scorm_seq_is('active', $activity->id
, $userid)) {
767 if (!isset($activity->tracked
) ||
($activity->tracked
== 1)) {
768 if (!scorm_seq_is('suspended', $activity->id
, $userid)) {
769 $r = scorm_get_sco_value($activity->id
, $userid, 'activityattemptcount');
770 $value = new stdClass();
771 $value->id
= $r->valueid
;
772 $value->value
= ($r->value
) +
1;
773 $DB->update_record('scorm_scoes_value', $value);
774 if ($r->value
== 1) {
775 scorm_seq_set('activityprogressstatus', $activity->id
, $userid, 'true');
777 scorm_insert_track($userid, $activity->scorm
, $activity->id
, $attemptobject,
778 'objectiveprogressstatus', 'false');
779 scorm_insert_track($userid, $activity->scorm
, $activity->id
, $attemptobject,
780 'objectivesatisfiedstatus', 'false');
781 scorm_insert_track($userid, $activity->scorm
, $activity->id
, $attemptobject,
782 'objectivemeasurestatus', 'false');
783 scorm_insert_track($userid, $activity->scorm
, $activity->id
, $attemptobject,
784 'objectivenormalizedmeasure', 0.0);
785 scorm_insert_track($userid, $activity->scorm
, $activity->id
, $attemptobject,
786 'attemptprogressstatus', 'false');
787 scorm_insert_track($userid, $activity->scorm
, $activity->id
, $attemptobject,
788 'attemptcompletionstatus', 'false');
789 scorm_insert_track($userid, $activity->scorm
, $activity->id
, $attemptobject,
790 'attemptabsoluteduration', 0.0);
791 scorm_insert_track($userid, $activity->scorm
, $activity->id
, $attemptobject,
792 'attemptexperiencedduration', 0.0);
793 scorm_insert_track($userid, $activity->scorm
, $activity->id
, $attemptobject,
794 'attemptcompletionamount', 0.0);
797 scorm_seq_set('active', $activity->id
, $userid, 'true');
800 $seq->delivery
= $seq->currentactivity
;
801 scorm_seq_set('suspendedactivity', $activity->id
, $userid, 'false');
806 function scorm_clear_suspended_activity($act, $seq, $userid) {
808 $currentact = $seq->currentactivity
;
809 $track = scorm_get_sco_value($currentact->id
, $userid, 'suspendedactivity');
810 if ($track != null) {
811 $ancestors = scorm_get_ancestors($act);
812 $commonpos = scorm_find_common_ancestor($ancestors, $currentact);
813 if ($commonpos !== false) {
814 if ($activitypath = array_slice($ancestors, 0, $commonpos)) {
815 if (!empty($activitypath)) {
817 foreach ($activitypath as $activity) {
818 if (scorm_is_leaf($activity)) {
819 scorm_seq_set('suspended', $activity->id
, $userid, false);
821 $children = scorm_get_children($activity);
823 foreach ($children as $child) {
824 if (scorm_seq_is('suspended', $child->id
, $userid)) {
829 scorm_seq_set('suspended', $activity->id
, $userid, false);
836 scorm_seq_set('suspendedactivity', $act->id
, $userid, false);
840 function scorm_select_children_process($scoid, $userid) {
843 $sco = scorm_get_sco($scoid);
844 if (!scorm_is_leaf($sco)) {
845 if (!scorm_seq_is('suspended', $scoid, $userid) && !scorm_seq_is('active', $scoid, $userid)) {
846 $r = scorm_get_sco_value($scoid, $userid, 'selectiontiming');
849 case 'oneachnewattempt':
854 if (!scorm_seq_is('activityprogressstatus', $scoid, $userid)) {
855 if (scorm_seq_is('selectioncountsstatus', $scoid, $userid)) {
857 $res = scorm_get_sco_value($scoid, $userid, 'selectioncount');
858 $i = ($res->value
) - 1;
859 $children = scorm_get_children($sco);
862 $pos = array_rand($children);
863 array_push($childlist, $children[$pos]);
864 array_splice($children, $pos, 1);
868 $clist = serialize($childlist);
869 scorm_seq_set('availablechildren', $scoid, $userid, false);
870 scorm_seq_set('availablechildren', $scoid, $userid, $clist);
879 function scorm_randomize_children_process($scoid, $userid) {
882 $sco = scorm_get_sco($scoid);
883 if (!scorm_is_leaf($sco)) {
884 if (!scorm_seq_is('suspended', $scoid, $userid) && !scorm_seq_is('active', $scoid, $userid)) {
885 $r = scorm_get_sco_value($scoid, $userid, 'randomizationtiming');
891 case 'oneachnewattempt':
893 if (!scorm_seq_is('activityprogressstatus', $scoid, $userid)) {
894 if (scorm_seq_is('randomizechildren', $scoid, $userid)) {
895 $childlist = array();
896 $res = scorm_get_available_children($sco);
897 $i = count($res) - 1;
898 $children = $res->value
;
901 $pos = array_rand($children);
902 array_push($childlist, $children[$pos]);
903 array_splice($children, $pos, 1);
907 $clist = serialize ($childlist);
908 scorm_seq_set('availablechildren', $scoid, $userid, false);
909 scorm_seq_set('availablechildren', $scoid, $userid, $clist);
918 function scorm_terminate_descendent_attempts($activity, $userid, $seq) {
919 $ancestors = scorm_get_ancestors($seq->currentactivity
);
920 $commonpos = scorm_find_common_ancestor($ancestors, $activity);
921 if ($commonpos !== false) {
922 if ($activitypath = array_slice($ancestors, 1, $commonpos - 2)) {
923 if (!empty($activitypath)) {
924 foreach ($activitypath as $sco) {
925 scorm_seq_end_attempt($sco, $userid, $seq->attempt
);
932 function scorm_sequencing_exception($seq) {
934 if ($seq->exception
!= null) {
935 switch ($seq->exception
) {
937 echo $OUTPUT->notification("Sequencing session has already begun");
940 echo $OUTPUT->notification("Sequencing session has not begun");
943 echo $OUTPUT->notification("Suspended activity is not defined");
946 echo $OUTPUT->notification("Flow Sequencing Control Model Violation");
949 echo $OUTPUT->notification("Flow or Forward only Sequencing Control Model Violation");
952 echo $OUTPUT->notification("No activity is previous to the root");
955 echo $OUTPUT->notification("Unsupported Navigation Request");
958 echo $OUTPUT->notification("Choice Exit Sequencing Control Model Violation");
961 echo $OUTPUT->notification("No activities to consider");
964 echo $OUTPUT->notification("Choice Sequencing Control Model Violation");
967 echo $OUTPUT->notification("Target Activity does not exist");
970 echo $OUTPUT->notification("Current Activity already terminated");
973 echo $OUTPUT->notification("Undefined Navigation Request");
977 echo $OUTPUT->notification("Current Activity already terminated");
980 echo $OUTPUT->notification("Current Activity already terminated");
983 echo $OUTPUT->notification("Current Activity already terminated");
986 echo $OUTPUT->notification("Nothing to suspend; No active activities");
989 echo $OUTPUT->notification("Nothing to abandon; No active activities");
993 echo $OUTPUT->notification("Last activity in the tree");
996 echo $OUTPUT->notification("Cluster has no available children");
999 echo $OUTPUT->notification("No activity is previous to the root");
1002 echo $OUTPUT->notification("Forward Only Sequencing Control Model Violation");
1006 echo $OUTPUT->notification("Flow Sequencing Control Model Violation");
1009 echo $OUTPUT->notification("Activity unavailable");
1013 echo $OUTPUT->notification("Forward Traversal Blocked");
1016 echo $OUTPUT->notification("Forward Only Sequencing Control Model Violation");
1019 echo $OUTPUT->notification("No activity is previous to the root");
1023 echo $OUTPUT->notification("Sequencing session has already begun");
1027 echo $OUTPUT->notification("Sequencing session has already begun");
1030 echo $OUTPUT->notification("No Suspended activity is defined");
1034 echo $OUTPUT->notification("Sequencing session has not begun");
1037 echo $OUTPUT->notification("Flow Sequencing Control Model Violation");
1041 echo $OUTPUT->notification("Sequencing session has not begun");
1044 echo $OUTPUT->notification("Flow Sequencing Control Model Violation");
1048 echo $OUTPUT->notification("No target for Choice");
1051 echo $OUTPUT->notification("Target Activity does not exist or is unavailable");
1054 echo $OUTPUT->notification("Target Activity hidden from choice");
1057 echo $OUTPUT->notification("Choice Sequencing Control Model Violation");
1060 echo $OUTPUT->notification("No activities to consider");
1063 echo $OUTPUT->notification("Unable to activate target; target is not a child of the Current Activity");
1066 echo $OUTPUT->notification("Choice Exit Sequencing Control Model Violation");
1069 echo $OUTPUT->notification("Unable to choose target activity - constrained choice");
1072 echo $OUTPUT->notification("Choice Request Prevented by Flow-only Activity");
1076 echo $OUTPUT->notification("Sequencing session has not begun");
1079 echo $OUTPUT->notification("Current Activity is active or suspended");
1082 echo $OUTPUT->notification("Flow Sequencing Control Model Violation");
1086 echo $OUTPUT->notification("Sequencing session has not begun");
1089 echo $OUTPUT->notification("Current Activity has not been terminated");
1093 echo $OUTPUT->notification("Undefined Sequencing Request");
1097 echo $OUTPUT->notification("Cannot deliver a non-leaf activity");
1100 echo $OUTPUT->notification("Nothing to deliver");
1103 echo $OUTPUT->notification("Activity unavailable");
1107 echo $OUTPUT->notification("Identified activity is already active");