2 require ('scormlib.php');
4 function scorm_seq_evaluate($scoid,$usertracks) {
8 function scorm_seq_overall ($scoid,$userid,$request,$attempt) {
9 $seq = scorm_seq_navigation($scoid,$userid,$request,$attempt);
10 if ($seq->navigation
) {
11 if ($seq->termination
!= null) {
12 $seq = scorm_seq_termination($scoid,$userid,$seq);
14 if ($seq->sequencing
!= null) {
15 $seq = scorm_seq_sequencing($scoid,$userid,$seq);
16 if($seq->sequencing
== 'exit'){//return the control to the LTS
20 if ($seq->delivery
!= null) {
21 $seq = scorm_sequencing_delivery($scoid,$userid,$seq);
22 $seq = scorm_content_delivery_environment ($seq,$userid);
25 if ($seq->exception
!= null) {
26 $seq = scorm_sequencing_exception($seq);
32 function scorm_seq_navigation ($scoid,$userid,$request,$attempt=0) {
33 /// Sequencing structure
34 $seq = new stdClass();
35 $seq->currentactivity
= scorm_get_sco($scoid);
36 $seq->traversaldir
= null;
37 $seq->nextactivity
= null;
38 $seq->deliveryvalid
= null;
39 $seq->attempt
= $attempt;
41 $seq->identifiedactivity
= null;
42 $seq->delivery
= null;
43 $seq->deliverable
= false;
44 $seq->active
= scorm_seq_is('active',$scoid,$userid);
45 $seq->suspended
= scorm_seq_is('suspended',$scoid,$userid);
46 $seq->navigation
= null;
47 $seq->termination
= null;
48 $seq->sequencing
= null;
50 $seq->endsession
= null;
51 $seq->exception
= null;
52 $seq->reachable
= true;
57 if (empty($seq->currentactivity
)) {
58 $seq->navigation
= true;
59 $seq->sequencing
= 'start';
61 $seq->exception
= 'NB.2.1-1'; /// Sequencing session already begun
65 if (empty($seq->currentactivity
)) {
66 if ($track = get_record('scorm_scoes_track','scoid',$scoid,'userid',$userid,'element','suspendedactivity')) {//I think it's suspend instead of suspendedactivity
67 $seq->navigation
= true;
68 $seq->sequencing
= 'resumeall';
70 $seq->exception
= 'NB.2.1-3'; /// No suspended activity found
73 $seq->exception
= 'NB.2.1-1'; /// Sequencing session already begun
78 if (!empty($seq->currentactivity
)) {
79 $sco = $seq->currentactivity
;
80 if ($sco->parent
!= '/') {
81 if ($parentsco = scorm_get_parent($sco)) {
83 if (isset($parentsco->flow
) && ($parentsco->flow
== true)) {//I think it's parentsco
84 // Current activity is active !
85 if (scorm_seq_is('active',$sco->id
,$userid)) {
86 if ($request == 'continue_') {
87 $seq->navigation
= true;
88 $seq->termination
= 'exit';
89 $seq->sequencing
= 'continue';
91 if (!isset($parentsco->forwardonly
) ||
($parentsco->forwardonly
== false)) {
92 $seq->navigation
= true;
93 $seq->termination
= 'exit';
94 $seq->sequencing
= 'previous';
96 $seq->exception
= 'NB.2.1-5'; /// Violates control mode
105 $seq->exception
= 'NB.2.1-2'; /// Current activity not defined
110 $seq->exception
= 'NB.2.1-7' ; /// None to be done, behavior not defined
114 if (!empty($seq->currentactivity
)) {
115 // Current activity is active !
116 $seq->navigation
= true;
117 $seq->termination
= substr($request,0,-1);
118 $seq->sequencing
= 'exit';
120 $seq->exception
= 'NB.2.1-2'; /// Current activity not defined
125 if (!empty($seq->currentactivity
)) {
126 $seq->navigation
= true;
127 $seq->termination
= substr($request,0,-1);
128 $seq->sequencing
= 'exit';
130 $seq->exception
= 'NB.2.1-2'; /// Current activity not defined
133 default: /// {target=<STRING>}choice
134 if ($targetsco = get_record('scorm_scoes','scorm',$sco->scorm
,'identifier',$request)) {
135 if ($targetsco->parent
!= '/') {
136 $seq->target
= $request;
138 if ($parentsco = scorm_get_parent($targetsco)) {
139 if (!isset($parentsco->choice
) ||
($parent->choice
== true)) {
140 $seq->target
= $request;
144 if ($seq->target
!= null) {
145 if (empty($seq->currentactivity
)) {
146 $seq->navigation
= true;
147 $seq->sequencing
= 'choice';
149 if (!$sco = scorm_get_sco($scoid)) {
152 if ($sco->parent
!= $target->parent
) {
153 $ancestors = scorm_get_ancestors($sco);
154 $commonpos = scorm_find_common_ancestor($ancestors,$targetsco);
155 if ($commonpos !== false) {
156 if ($activitypath = array_slice($ancestors,0,$commonpos)) {
157 foreach ($activitypath as $activity) {
158 if (scorm_seq_is('active',$activity->id
,$userid) && (isset($activity->choiceexit
) && ($activity->choiceexit
== false))) {
159 $seq->navigation
= false;
160 $seq->termination
= null;
161 $seq->sequencing
= null;
163 $seq->exception
= 'NB.2.1-8'; /// Violates control mode
168 $seq->navigation
= false;
169 $seq->termination
= null;
170 $seq->sequencing
= null;
172 $seq->exception
= 'NB.2.1-9';
176 // Current activity is active !
177 $seq->navigation
= true;
178 $seq->sequencing
= 'choice';
181 $seq->exception
= 'NB.2.1-10'; /// Violates control mode
184 $seq->exception
= 'NB.2.1-11'; /// Target activity does not exists
191 function scorm_seq_termination ($seq,$userid) {
192 if (empty($seq->currentactivity
)) {
193 $seq->termination
= false;
194 $seq->exception
= 'TB.2.3-1';
198 $sco = $seq->currentactivity
;
200 if ((($seq->termination
== 'exit') ||
($seq->termination
== 'abandon')) && !$seq->active
) {
201 $seq->termination
= false;
202 $seq->exception
= 'TB.2.3-2';
205 switch ($seq->termination
) {
207 scorm_seq_end_attempt($sco,$userid,$seq);
208 $seq = scorm_seq_exit_action_rules($seq,$userid);
210 $exit = false;// I think this is false. Originally this was true
211 $seq = scorm_seq_post_cond_rules($seq,$userid);
212 if ($seq->termination
== 'exitparent') {
213 if ($sco->parent
!= '/') {
214 $sco = scorm_get_parent($sco);
215 $seq->currentactivity
= $sco;
216 $seq->active
= scorm_seq_is('active',$sco->id
,$userid);
217 scorm_seq_end_attempt($sco,$userid,$seq);
218 $exit = true;//I think it's true. Originally this was false
220 $seq->termination
= false;
221 $seq->exception
= 'TB.2.3-4';
225 } while (($exit == false) && ($seq->termination
== 'exit'));
226 if ($seq->termination
== 'exit') {
227 $seq->termination
= true;
232 scorm_seq_end_attempt($sco,$userid,$seq);
234 /// Terminate Descendent Attempts Process
237 if ($ancestors = scorm_get_ancestors($sco)) {
238 foreach ($ancestors as $ancestor) {
239 scorm_seq_end_attempt($ancestor,$userid,$seq);
240 $seq->currentactivity
= $ancestor;
244 $seq->active
= scorm_seq_is('active',$seq->currentactivity
->id
,$userid);
245 $seq->termination
= true;
246 $seq->sequencing
= exit;
249 if (($seq->active
) ||
($seq->suspended
)) {
250 scorm_seq_set('suspended',$sco->id
,$userid);
252 if ($sco->parent
!= '/') {
253 $parentsco = scorm_get_parent($sco);
254 scorm_seq_set('suspended',$parentsco->id
,$userid);
256 $seq->termination
= false;
257 $seq->exception
= 'TB.2.3-3';
261 if ($ancestors = scorm_get_ancestors($sco)) {
262 foreach ($ancestors as $ancestor) {
263 scorm_seq_set('active',$ancestor->id
,$userid,false);
264 scorm_seq_set('suspended',$ancestor->id
,$userid);
265 $seq->currentactivity
= $ancestor;
267 $seq->termination
= true;
268 $seq->sequencing
= 'exit';
270 $seq->termination
= false;
271 $seq->exception
= 'TB.2.3-5';
275 scorm_seq_set('active',$sco->id
,$userid,false);
277 $seq->termination
= true;
280 if ($ancestors = scorm_get_ancestors($sco)) {
281 foreach ($ancestors as $ancestor) {
282 scorm_seq_set('active',$ancestor->id
,$userid,false);
283 $seq->currentactivity
= $ancestor;
285 $seq->termination
= true;
286 $seq->sequencing
= 'exit';
288 $seq->termination
= false;
289 $seq->exception
= 'TB.2.3-6';
293 $seq->termination
= false;
294 $seq->exception
= 'TB.2.3-7';
300 function scorm_seq_end_attempt($sco,$userid,$seq) {
301 if (scorm_is_leaf($sco)) {
302 if (!isset($sco->tracked
) ||
($sco->tracked
== 1)) {
303 if (!scorm_seq_is('suspended',$sco->id
,$userid)) {
304 if (!isset($sco->completionsetbycontent
) ||
($sco->completionsetbycontent
== 0)) {
305 if (!scorm_seq_is('attemptprogressstatus',$sco->id
,$userid,$seq->attempt
)) {
306 // if (!scorm_seq_is('attemptprogressstatus',$sco->id,$userid)) {
307 scorm_seq_set('attemptprogressstatus',$sco->id
,$userid);
308 scorm_seq_set('attemptcompletionstatus',$sco->id
,$userid);
311 if (!isset($sco->objectivesetbycontent
) ||
($sco->objectivesetbycontent
== 0)) {
312 if ($objectives = get_records('scorm_seq_objective','scoid',$sco->id
)) {
313 foreach ($objectives as $objective) {
314 if ($objective->primaryobj
) {
315 //if (!scorm_seq_objective_progress_status($sco,$userid,$objective)) {
316 if (!scorm_seq_is('objectiveprogressstatus',$sco->id
,$userid)) {
317 scorm_seq_set('objectiveprogressstatus',$sco->id
,$userid);
318 scorm_seq_set('objectivesatisfiedstatus',$sco->id
,$userid);
327 if ($children = scorm_get_children($sco)) {
329 foreach ($children as $child) {
330 if (scorm_seq_is('suspended',$child,$userid)) {
336 scorm_seq_set('suspended',$sco,$userid);
338 scorm_seq_set('suspended',$sco,$userid,false);
342 scorm_seq_set('active',$sco,$userid,0,false);
343 scorm_seq_overall_rollup($sco,$userid);
346 function scorm_seq_is($what, $scoid, $userid, $attempt=0) {
348 /// Check if passed activity $what is active
350 if ($track = get_record('scorm_scoes_track','scoid',$scoid,'userid',$userid,'attempt',$attempt,'element',$what)) {
356 function scorm_seq_set($what, $scoid, $userid, $attempt=0, $value='true') {
357 $sco = scorm_get_sco($scoid);
359 /// set passed activity to active or not
360 if ($value == false) {
361 delete_record('scorm_scoes_track','scoid',$scoid,'userid',$userid,'attempt',$attempt,'element',$what);
363 scorm_insert_track($userid, $sco->scorm
, $sco->id
, 0, $what, $value);
366 // update grades in gradebook
367 $scorm = get_record('scorm', 'id', $sco->scorm
);
368 scorm_update_grades($scorm, $userid, true);
371 function scorm_seq_exit_action_rules($seq,$userid) {
372 $sco = $seq->currentactivity
;
373 $ancestors = scorm_get_ancestors($sco);
375 foreach (array_reverse($ancestors) as $ancestor) {
376 if (scorm_seq_rules_check($ancestor,'exit') != null) {
377 $exittarget = $ancestor;
381 if ($exittarget != null) {
382 $commons = array_slice($ancestors,0,scorm_find_common_ancestor($ancestors,$exittarget));
384 /// Terminate Descendent Attempts Process
386 foreach ($commons as $ancestor) {
388 scorm_seq_end_attempt($ancestor,$userid,$seq->attempt
);
389 $seq->currentactivity
= $ancestor;
396 function scorm_seq_post_cond_rules($seq,$userid) {
397 $sco = $seq->currentactivity
;
398 if (!$seq->suspended
) {
399 if ($action = scorm_seq_rules_check($sco,'post') != null) {
404 $seq->sequencing
= $action;
408 $seq->termination
= $action;
411 $seq->termination
= 'exitall';
412 $seq->sequencing
= 'retry';
420 function scorm_seq_rules_check ($sco, $action){
422 if($rules = get_records('scorm_seq_ruleconds','scoid',$sco->id
,'action',$action)){
423 foreach ($rules as $rule){
424 if($act = scorm_seq_rule_check($sco,$rule)){
433 function scorm_seq_rule_check ($sco, $rule){
436 $ruleconds = get_records('scorm_seq_rulecond','scoid',$sco->id
,'ruleconditionsid',$rule->id
);
437 foreach ($ruleconds as $rulecond){
438 if ($rulecond->operator
= 'not') {
439 if ($rulecond->cond
!= 'unknown' ){
440 $rulecond->cond
= 'not'.$rulecond;
443 $bag [$rule->id
] = $rulecond->cond
;
454 if ($rule->conditioncombination
= 'all'){
455 foreach ($bag as $con){
456 $cond = $cond.' and '.$con;
461 foreach ($bag as $con){
462 $cond = $cond.' or '.$con;
469 function scorm_seq_overall_rollup($sco,$userid){//Carlos
471 if ($ancestors = scorm_get_ancestors($sco)) {
472 foreach ($ancestors as $ancestor) {
473 if(!scorm_is_leaf($ancestor)){
474 scorm_seq_measure_rollup($sco,$userid);
476 scorm_seq_objective_rollup($sco,$userid);
477 scorm_seq_activity_progress_rollup($sco,$userid);
484 /* For this next function I have defined measure weight and measure status as records with the attempt = 0 on the scorm_scoes_track table. According to the page 89 of the SeqNav.pdf those datas give us some information about the progress of the objective*/
486 function scorm_seq_measure_rollup($sco,$userid){
488 $totalmeasure = 0; //Check if there is something similar in the database
489 $valid = false;//Same as in the last line
490 $countedmeasures = 0;//Same too
491 $targetobjective = null;
492 $readable = true;//to check if status and measure weight are readable
493 $objectives = get_records('scorm_seq_objective','scoid',$sco->id
);
495 foreach ($objective as $objective){
497 if ($objective->primaryobj
== true){//Objective contributes to rollup I'm using primaryobj field, but not
498 $targetobjective = $objective;
504 if ($targetobjective != null){
505 $children = scorm_get_children($sco);
506 foreach ($children as $child){
507 $child = scorm_get_sco ($child);
508 if (!isset($child->tracked
) ||
($child->tracked
== 1)){
510 $rolledupobjective = null;// we set the rolled up activity to undefined
511 $objectives = get_records('scorm_seq_objective','scoid',$child->id
);
512 foreach ($objective as $objective){
513 if ($objective->primaryobj
== true){//Objective contributes to rollup I'm using primaryobj field, but not
514 $rolledupobjective = $objective;
518 if ($rolledupobjective != null){
519 $child = scorm_get_sco($child->id
);
521 $countedmeasures = $countedmeasures +
($child->measureweight
);
522 if (!scorm_seq_is('objectivemeasurestatus',$sco->id
,$userid)) {
523 $normalizedmeasure = get_record('scorm_scoes_track','scoid',$child->id
,'userid',$userid,'element','objectivenormalizedmeasure');
524 $totalmeasure = $totalmeasure +
(($normalizedmeasure->value
) * ($child->measureweight
));
537 scorm_seq_set('objectivemeasurestatus',$sco->id
,$userid,false);
541 if($countedmeasures>0){
542 scorm_seq_set('objectivemeasurestatus',$sco->id
,$userid);
543 $val=$totalmeasure/$countedmeasure;
544 scorm_seq_set('objectivenormalizedmeasure',$sco->id
,$userid,$val);
548 scorm_seq_set('objectivemeasurestatus',$sco->id
,$userid,false);
557 function scorm_seq_objective_rollup($sco,$userid){
559 scorm_seq_objective_rollup_measure($sco,$userid);
560 scorm_seq_objective_rollup_rules($sco,$userid);
561 scorm_seq_objective_rollup_default($sco,$userid);
564 if($targetobjective->satisfiedbymeasure){
565 scorm_seq_objective_rollup_measure($sco,$userid);
568 if ((scorm_seq_rollup_rule_check($sco,$userid,'incomplete'))|| (scorm_seq_rollup_rule_check($sco,$userid,'completed'))){
569 scorm_seq_objective_rollup_rules($sco,$userid);
573 $rolluprules = get_record('scorm_seq_rolluprule','scoid',$sco->id,'userid',$userid);
574 foreach($rolluprules as $rolluprule){
575 $rollupruleconds = get_records('scorm_seq_rolluprulecond','rollupruleid',$rolluprule->id);
576 foreach($rollupruleconds as $rolluprulecond){
578 switch ($rolluprulecond->cond!='satisfied' && $rolluprulecond->cond!='completed' && $rolluprulecond->cond!='attempted'){
580 scorm_seq_set('objectivesatisfiedstatus',$sco->id,$userid, false);
592 function scorm_seq_objective_rollup_measure($sco,$userid){
593 $targetobjective = null;
596 $objectives = get_records('scorm_seq_objective','scoid',$sco->id
);
597 foreach ($objectives as $objective){
598 if ($objective->primaryobj
== true){
599 $targetobjective = $objective;
603 if ($targetobjective != null){
605 if($targetobjective->satisfiedbymeasure
){
608 if (!scorm_seq_is('objectiveprogressstatus',$sco->id
,$userid)) {
610 scorm_seq_set('objectiveprogressstatus',$sco->id
,$userid,false);
615 if (scorm_seq_is('active',$sco->id
,$userid)) {
622 $normalizedmeasure = get_record('scorm_scoes_track','scoid',$sco->id
,'userid',$userid,'element','objectivenormalizedmeasure');
624 $sco = scorm_get_sco ($sco->id
);
626 if (!$isactive ||
($isactive && (!isset($sco->measuresatisfactionifactive
) ||
$sco->measuresatisfactionifactive
== true))){
627 if($normalizedmeasure->value
>= $targetobjective->minnormalizedmeasure
){
628 scorm_seq_set('objectiveprogressstatus',$sco->id
,$userid);
629 scorm_seq_set('objectivesatisfiedstatus',$sco->id
,$userid);
632 scorm_seq_set('objectiveprogressstatus',$sco->id
,$userid);
633 scorm_seq_set('objectivesatisfiedstatus',$sco->id
,$userid,false);
638 scorm_seq_set('objectiveprogressstatus',$sco->id
,$userid,false);
647 function scorm_seq_objective_rollup_default($sco,$userid){
648 if (!(scorm_seq_rollup_rule_check($sco,$userid,'incomplete')) && !(scorm_seq_rollup_rule_check($sco,$userid,'completed'))){
650 $rolluprules = get_record('scorm_seq_rolluprule','scoid',$sco->id
,'userid',$userid);
651 foreach($rolluprules as $rolluprule){
652 $rollupruleconds = get_records('scorm_seq_rolluprulecond','rollupruleid',$rolluprule->id
);
653 foreach($rollupruleconds as $rolluprulecond){
655 if ($rolluprulecond->cond
!='satisfied' && $rolluprulecond->cond
!='completed' && $rolluprulecond->cond
!='attempted'){
657 scorm_seq_set('objectivesatisfiedstatus',$sco->id
,$userid, false);
670 function scorm_seq_objective_rollup_rules($sco,$userid){
671 $targetobjective = null;
673 $objectives = get_records('scorm_seq_objective','scoid',$sco->id
);
674 foreach ($objective as $objective){
675 if ($objective->primaryobj
== true){//Objective contributes to rollup I'm using primaryobj field, but not
676 $targetobjective = $objective;
680 if ($targetobjective != null){
684 if(scorm_seq_rollup_rule_check($sco,$userid,'notsatisfied')){//with not satisfied rollup for the activity
687 scorm_seq_set('objectiveprogressstatus',$sco->id
,$userid);
688 scorm_seq_set('objectivesatisfiedstatus',$sco->id
,$userid,false);
690 if(scorm_seq_rollup_rule_check($sco,$userid,'satisfied')){//with satisfied rollup for the activity
691 scorm_seq_set('objectiveprogressstatus',$sco->id
,$userid);
692 scorm_seq_set('objectivesatisfiedstatus',$sco->id
,$userid);
699 function scorm_seq_activity_progress_rollup ($sco, $userid){
701 if(scorm_seq_rollup_rule_check($sco,$userid,'incomplete')){
702 //incomplete rollup action
703 scorm_seq_set('attemptcompletionstatus',$sco->id
,$userid,false,$seq->attempt
);
704 scorm_seq_set('attemptprogressstatus',$sco->id
,$userid,true,$seq->attempt
);
707 if(scorm_seq_rollup_rule_check($sco,$userid,'completed')){
708 //incomplete rollup action
709 scorm_seq_set('attemptcompletionstatus',$sco->id
,true,$userid);
710 scorm_seq_set('attemptprogressstatus',$sco->id
,true,$userid);
715 function scorm_seq_rollup_rule_check ($sco,$userid,$action){
717 if($rolluprules = get_record('scorm_seq_rolluprule','scoid',$sco->id
,'userid',$userid,'action',$action)){
719 $childrenbag = Array ();
720 $children = scorm_get_children ($sco);
722 foreach($rolluprules as $rolluprule){
724 foreach ($children as $child){
726 /*$tracked = get_records('scorm_scoes_track','scoid',$child->id,'userid',$userid);
727 if($tracked && $tracked->attemp != 0){*/
728 $child = scorm_get_sco ($child);
729 if (!isset($child->tracked
) ||
($child->tracked
== 1)){
731 if(scorm_seq_check_child ($child,$action,$userid)){
733 $rollupruleconds = get_records('scorm_seq_rolluprulecond','rollupruleid',$rolluprule->id
);
734 $evaluate = scorm_seq_evaluate_rollupcond($child,$rolluprule->conditioncombination
,$rollupruleconds,$userid);
735 if ($evaluate=='unknown'){
736 array_push($childrenbag,'unknown');
739 if($evaluate == true){
740 array_push($childrenbag,true);
743 array_push($childrenbag,false);
752 switch ($rolluprule->childactivityset
){
755 if((array_search(false,$childrenbag)===false)&&(array_search('unknown',$childrenbag)===false)){//I think I can use this condition instead equivalent to OR
761 if(array_search(true,$childrenbag)!==false){//I think I can use this condition instead equivalent to OR
767 if((array_search(true,$childrenbag)===false)&&(array_search('unknown',$childrenbag)===false)){//I think I can use this condition instead equivalent to OR
773 foreach ($childrenbag as $itm){//I think I can use this condition instead equivalent to OR
778 if($cont >= $roullprule->minimumcount
){
785 foreach ($childrenbag as $itm){//I think I can use this condition instead equivalent to OR
790 if($cont >= $roullprule->minimumcount
){
796 case 'atleastpercent':
797 foreach ($childrenbag as $itm){//I think I can use this condition instead equivalent to OR
802 if(($cont/sizeof($childrenbag)) >= $roullprule->minimumcount
){
817 function scorm_seq_evaluate_rollupcond($sco,$conditioncombination,$rollupruleconds,$userid){
822 foreach($rollupruleconds as $rolluprulecond){
824 $condit = scorm_evaluate_cond($rolluprulecond,$sco,$userid);
826 if($rule->operator
=='not'){// If operator is not, negate the condition
827 if ($rule->cond
!= 'unknown'){
838 array_push($childrenbag,$condit);
847 foreach ($bag as $b){
849 if ($rolluprule->conditioncombination
== 'all'){
882 function scorm_evaluate_condition ($rolluprulecond,$sco,$userid){
886 switch ($rolluprulecond->cond
){
889 if($r=get_record('scorm_scoes_track','scoid',$sco->id
,'userid',$userid,'element','objectivesatisfiedstatus')){
890 if($r->value
== true){
891 if ($r=get_record('scorm_scoes_track','scoid',$sco->id
,'userid',$userid,'element','objectiveprogressstatus')){
892 if($r->value
== true){
900 case 'objectiveStatusKnown':
901 if ($r=get_record('scorm_scoes_track','scoid',$sco->id
,'userid',$userid,'element','objectiveprogressstatus')){
902 if($r->value
== true){
908 case 'objectiveMeasureKnown':
909 if ($r = get_record('scorm_scoes_track','scoid',$sco->id
,'userid',$userid,'element','objectivemeasurestatus')){
910 if($r->value
== true){
919 if ($r = get_record('scorm_scoes_track','scoid',$sco->id
,'userid',$userid,'element','attemptcompletionstatus')){
921 if ($r = get_record('scorm_scoes_track','scoid',$sco->id
,'userid',$userid,'element','attemptprogressstatus')){
933 if ($r = get_record('scorm_scoes_track','scoid',$sco->id
,'userid',$userid,'element','activityprogressstatus')){
935 if ($r = get_record('scorm_scoes_track','scoid',$sco->id
,'userid',$userid,'element','activityattemptcount')){
947 case 'attemptLimitExceeded':
948 if ($r = get_record('scorm_scoes_track','scoid',$sco->id
,'userid',$userid,'element','activityprogressstatus')){
950 if ($r = get_record('scorm_scoes_track','scoid',$sco->id
,'userid',$userid,'element','limitconditionattemptlimitcontrol')){
952 if ($r = get_record('scorm_scoes_track','scoid',$sco->id
,'userid',$userid,'element','activityattemptcount') && $r2 = get_record('scorm_scoes_track','scoid',$sco->id
,'userid',$userid,'element','limitconditionattemptlimit') ){
953 if($r->value
>= $r2->value
){
969 case 'activityProgressKnown':
971 if ($r = get_record('scorm_scoes_track','scoid',$sco->id
,'userid',$userid,'element','activityprogressstatus')){
973 if ($r = get_record('scorm_scoes_track','scoid',$sco->id
,'userid',$userid,'element','attemptprogressstatus')){
990 function scorm_seq_check_child ($sco, $action, $userid){
992 $sco=scorm_get_sco($sco->id
);
993 $r = get_record('scorm_scoes_track','scoid',$sco->id
,'userid',$userid,'element','activityattemptcount');
994 if ($action == 'satisfied' ||
$action == 'notsatisfied'){
995 if (!$sco->rollupobjectivesatisfied
){
997 if (($action == 'satisfied' && $sco->requiredforsatisfied
== 'ifnotsuspended') ||
($action == 'notsatisfied' && $sco->requiredfornotsatisfied
== 'ifnotsuspended')){
999 if (!scorm_seq_is('activityprogressstatus',$sco->id
,$userid) ||
((($r->value
)>0)&& !scorm_seq_is('suspended',$sco->id
,$userid))){
1005 if (($action == 'satisfied' && $sco->requiredforsatisfied
== 'ifattempted') ||
($action == 'notsatisfied' && $sco->requiredfornotsatisfied
== 'ifattempted')){
1006 if (!scorm_seq_is('activityprogressstatus',$sco->id
,$userid) ||
(($r->value
) == 0)){
1011 if (($action == 'satisfied' && $sco->requiredforsatisfied
== 'ifnotskipped') ||
($action == 'notsatisfied' && $sco->requiredfornotsatisfied
== 'ifnotskipped')){
1012 $rulch = scorm_seq_rules_check($sco, 'skip');
1013 if ($rulch != null){
1021 if ($action == 'completed' ||
$action == 'incomplete'){
1022 if (!$sco->rollupprogresscompletion
){
1025 if (($action == 'completed' && $sco->requiredforcompleted
== 'ifnotsuspended') ||
($action == 'incomplete' && $sco->requiredforincomplete
== 'ifnotsuspended')){
1027 if (!scorm_seq_is('activityprogressstatus',$sco->id
,$userid) ||
( (($r->value
)>0)&& !scorm_seq_is('suspended',$sco->id
,$userid))){
1034 if (($action == 'completed' && $sco->requiredforcompleted
== 'ifattempted') ||
($action == 'incomplete' && $sco->requiredforincomplete
== 'ifattempted')){
1035 if (!scorm_seq_is('activityprogressstatus',$sco->id
,$userid) ||
(($r->value
)==0)){
1041 if (($action == 'completed' && $sco->requiredforsatisfied
== 'ifnotskipped') ||
($action == 'incomplete' && $sco->requiredfornotsatisfied
== 'ifnotskipped')){
1042 $rulch = scorm_seq_rules_check($sco, 'skip');
1043 if ($rulch != null){
1058 function scorm_seq_sequencing ($scoid,$userid,$seq) {
1060 switch ($seq->sequencing
) {
1063 $seq = scorm_seq_start_sequencing($sco,$userid,$seq); //We'll see the parameters we have to send, this should update delivery and end
1064 $seq->sequencing
= true;
1070 $seq = scorm_seq_resume_sequencing($sco,$userid,$seq); //We'll see the parameters we have to send, this should update delivery and end
1071 $seq->sequencing
= true;
1078 $seq = scorm_seq_exit_sequencing($sco,$userid,$seq); //We'll see the parameters we have to send, this should update delivery and end
1079 $seq->sequencing
= true;
1086 $seq = scorm_seq_retry_sequencing($sco,$userid,$seq); //We'll see the parameters we have to send, this should update delivery and end
1087 $seq->sequencing
= true;
1093 $seq = scorm_seq_previous_sequencing($sco,$userid,$seq);// We'll see the parameters we have to send, this should update delivery and end
1094 $seq->sequencing
= true;
1100 $seq = scorm_seq_choice_sequencing($sco,$userid,$seq);// We'll see the parameters we have to send, this should update delivery and end
1101 $seq->sequencing
= true;
1108 if ($seq->exception
!= null){
1109 $seq->sequencing
= false;
1113 $seq->sequencing
= true;
1118 function scorm_seq_start_sequencing($scoid,$userid,$seq){
1119 if (!empty($seq->currentactivity
)) {
1120 $seq->delivery
= null;
1121 $seq->exception
= 'SB.2.5-1';
1124 $sco = get_record('scorm_scoes','scoid',$scoid,'userid',$userid);
1125 if (($sco->parent
== '/') && scorm_is_leaf($sco)) {//if the activity is the root and is leaf
1126 $seq->delivery
= $sco;
1129 $ancestors = scorm_get_ancestors($sco);
1130 $ancestorsroot = array_reverse($ancestors);
1131 $res = scorm_seq_flow($ancestorsroot[0],'forward',$seq,true,$userid);
1136 //return end and exception
1141 function scorm_seq_resume_all_sequencing($scoid,$userid,$seq){
1142 if (!empty($seq->currentactivity
)){
1143 $seq->delivery
= null;
1144 $seq->exception
= 'SB.2.6-1';
1147 $track = get_record('scorm_scoes_track','scoid',$scoid,'userid',$userid,'element','suspendedactivity');
1149 $seq->delivery
= null;
1150 $seq->exception
= 'SB.2.6-2';
1153 $seq->delivery
= get_record('scorm_scoes','scoid',$scoid,'userid',$userid);//we assign the sco to the delivery
1157 function scorm_seq_continue_sequencing($scoid,$userid,$seq){
1158 if (empty($seq->currentactivity
)) {
1159 $seq->delivery
= null;
1160 $seq->exception
= 'SB.2.7-1';
1163 $currentact= $seq->currentactivity
;
1164 if ($currentact->parent
!= '/') {//if the activity is the root and is leaf
1165 $parent = scorm_get_parent ($currentact);
1167 if (!isset($parent->flow
) ||
($parent->flow
== false)) {
1168 $seq->delivery
= null;
1169 $seq->exception
= 'SB.2.7-2';
1173 $res = scorm_seq_flow($currentact,'forward',$seq,false,$userid);
1178 //return end and exception
1184 function scorm_seq_previous_sequencing($scoid,$userid,$seq){
1185 if (empty($seq->currentactivity
)) {
1186 $seq->delivery
= null;
1187 $seq->exception
= 'SB.2.8-1';
1191 $currentact= $seq->currentactivity
;
1192 if ($currentact->parent
!= '/') {//if the activity is the root and is leaf
1193 $parent = scorm_get_parent ($activity);
1194 if (!isset($parent->flow
) ||
($parent->flow
== false)) {
1195 $seq->delivery
= null;
1196 $seq->exception
= 'SB.2.8-2';
1200 $res = scorm_seq_flow($currentact,'backward',$seq,false,$userid);
1205 //return end and exception
1212 function scorm_seq_exit_sequencing($scoid,$userid,$seq){
1213 if (empty($seq->currentactivity
)) {
1214 $seq->delivery
= null;
1215 $seq->exception
= 'SB.2.11-1';
1220 $seq->endsession
= false;
1221 $seq->exception
= 'SB.2.11-2';
1224 $currentact= $seq->currentactivity
;
1225 if ($currentact->parent
== '/'){
1226 $seq->endsession
= true;
1230 $seq->endsession
= false;
1235 function scorm_seq_retry_sequencing($scoid,$userid,$seq){
1236 if (empty($seq->currentactivity
)) {
1237 $seq->delivery
= null;
1238 $seq->exception
= 'SB.2.10-1';
1241 if ($seq->active ||
$seq->suspended
){
1242 $seq->delivery
= null;
1243 $seq->exception
= 'SB.2.10-2';
1247 if (!scorm_is_leaf($seq->currentactivity
)){
1248 $res = scorm_seq_flow($seq->currentactivity
,'forward',$seq,true,$userid);
1254 $seq->delivery
= null;
1255 $seq->exception
= 'SB.2.10-3';
1260 $seq->delivery
= $seq->currentactivity
;
1266 function scorm_seq_flow ($candidate,$direction,$seq,$childrenflag,$userid){
1267 //$PREVDIRECTION NOT DEFINED YET
1269 $activity=$candidate;
1271 $previdirection = null;
1272 $seq = scorm_seq_flow_tree_traversal ($activity,$direction,$childrenflag,$prevdirection,$seq,$userid);
1273 if($seq->identifiedactivity
== null){//if identifies
1274 $seq->identifiedactivity
= $candidate;
1275 $seq->deliverable
= false;
1279 $activity = $seq->identifiedactivity
;
1280 $seq = scorm_seq_flow_activity_traversal($activity,$userid,$direction,$childrenflag,$prevdirection,$seq,$userid);//
1286 function scorm_seq_flow_activity_traversal ($activity, $userid, $direction, $childrenflag, $prevdirection, $seq,$userid){//returns the next activity on the tree, traversal direction, control returned to the LTS, (may) exception
1287 $activity = scorm_get_sco ($activity);
1288 $parent = scorm_get_parent ($activity);
1289 if (!isset($parent->flow
) ||
($parent->flow
== false)) {
1290 $seq->deliverable
= false;
1291 $seq->exception
= 'SB.2.2-1';
1292 $seq->nextactivity
= $activity;
1296 $rulch = scorm_seq_rules_check($sco, 'skipped');
1297 if ($rulch != null){
1298 $seq = scorm_seq_flow_tree_traversal ($activity, $direction, false, $prevdirection, $seq,$userid);//endsession and exception
1299 if ($seq->identifiedactivity
== null){
1300 $seq->deliverable
= false;
1301 $seq->nextactivity
= $activity;
1306 if ($prevdirection = 'backward' && $seq->traversaldir
== 'backward'){
1307 $seq = scorm_seq_flow_tree_traversal ($activity,$direction,false,null,$seq,$userid);
1308 $seq = scorm_seq_flow_activity($seq->identifiedactivity
, $userid, $direction, $childrenflag, $prevdirection, $seq,$userid);
1311 $seq = scorm_seq_flow_tree_traversal ($activity,$direction,false,null,$seq,$userid);
1312 $seq = scorm_seq_flow_activity($seq->identifiedactivity
, $userid, $direction, $childrenflag, $prevdirection, $seq,$userid);
1318 $ch=scorm_check_activity ($activity,$userid);
1322 $seq->deliverable
= false;
1323 $seq->exception
= 'SB.2.2-2';
1324 $seq->nextactivity
= $activity;
1329 if (!scorm_is_leaf($activity)){
1331 $seq = scorm_seq_flow_tree_traversal ($activity,$direction,true,null,$seq,$userid);
1333 if ($seq->identifiedactivity
== null){
1334 $seq->deliverable
= false;
1335 $seq->nextactivity
= $activity;
1340 if($direction == 'backward' && $seq->traversaldir
== 'forward'){
1341 $seq = scorm_seq_flow_activity($seq->identifiedactivity
, $userid, 'forward', $childrenflag, 'backward', $seq,$userid);
1344 scorm_seq_flow_activity($seq->identifiedactivity
, $userid, $direction, $childrenflag, null, $seq,$userid);
1351 $seq->deliverable
= true;
1352 $seq->nextactivity
= $activity;
1356 function scorm_seq_flow_tree_traversal ($activity,$direction,$childrenflag,$prevdirection,$seq,$userid){
1358 $revdirection = false;
1359 $parent = scorm_get_parent ($activity);
1360 $children = scorm_get_available_children ($parent);
1361 $siz = sizeof ($children);
1363 if (($prevdirection != null && $prevdirection == 'backward') && ($children[$siz-1]->id
== $activity->id
)){
1364 $direction = 'backward';
1365 $children[0] = $activity;
1366 $revdirection = true;
1369 if($direction = 'forward'){
1370 $ancestors = scorm_get_ancestors($activity);
1371 $ancestorsroot = array_reverse($ancestors);
1372 $preorder = scorm_get_preorder ($ancestorsroot);
1373 $siz= sizeof ($preorder);
1374 if (($activity->id
== $preorder[$siz-1]->id
) ||
(($activity->parent
== '/') && !($childrenflag))){
1375 scorm_seq_terminate_descent($ancestorsroot,$userid);
1376 $seq->endsession
= true;
1377 $seq->nextactivity
= null;
1380 if (scorm_is_leaf ($activity) ||
!$childrenflag){
1381 if ($children[$siz-1]->id
== $activity->id
){
1383 $seq = scorm_seq_flow_tree_traversal ($parent, $direction, false, null, $seq,$userid);
1384 // I think it's not necessary to do a return in here
1387 $parent = scorm_get_parent($activity);
1388 $children = scorm_get_available_children($parent);
1389 $seq->traversaldir
= $direction;
1390 $sib = scorm_get_siblings($activity);
1391 $pos = array_search($sib, $activity);
1392 if ($pos !== false) {
1393 if ($pos != sizeof ($sib)){
1394 $seq->nextactivity
= $sib [$pos+
1];
1398 $ch = scorm_get_children($sib[0]);
1399 $seq->nextactivity
= $ch[0];
1406 if (!empty ($children)){
1407 $seq->traversaldir
= $direction;
1408 $seq->nextactivity
= $children[0];
1412 $seq->traversaldir
= null;
1413 $seq->nextactivity
= $children[0];
1414 $seq->exception
= 'SB.2.1-2';
1420 if($direction = 'backward'){
1422 if ($activity->parent
== '/'){
1423 $seq->traversaldir
= null;
1424 $seq->nextactivity
= null;
1425 $seq->exception
= 'SB.2.1-3';
1428 if (scorm_is_leaf ($activity) ||
!$childrenflag){
1429 if (!$revdirection){
1430 if (isset($parent->forwardonly
) && ($parent->forwardonly
== true)) {
1431 $seq->traversaldir
= null;
1432 $seq->nextactivity
= null;
1433 $seq->exception
= 'SB.2.1-4';
1437 if ($children[0]->id
== $activity->id
){
1438 $seq = scorm_seq_flow_tree_traversal ($parent, 'backward', false, null, $seq);
1442 $ancestors = scorm_get_ancestors($activity);
1443 $ancestorsroot = array_reverse ($ancestors);
1444 $preorder = scorm_get_preorder ($ancestorsroot);
1445 $pos = array_search($preorder, $children[$siz]);
1446 $preord = array_slice($preorder, 0, $pos-1);
1447 $revpreorder = array_reverse($preord);
1448 $position = array_search($revpreorder, $activity);
1449 $seq->nextactivity
= $revpreorder[$pos+
1];
1450 $seq->traversaldir
= $direction;
1455 if (!empty($children)){
1456 $activity = scorm_get_sco($activity->id
);
1457 if (isset($parent->flow
) && ($parent->flow
== true)) {
1458 $children = scorm_get_children ($activity);
1459 $seq->traversaldir
= 'forward';
1460 $seq->nextactivity
= $children[0];
1465 $children = scorm_get_children ($activity);
1466 $seq->traversaldir
= 'backward';
1467 $seq->nextactivity
= $children[sizeof($children)-1];
1474 $seq->traversaldir
= null;
1475 $seq->nextactivity
= null;
1476 $seq->exception
= 'SB.2.1-2';
1485 function scorm_check_activity ($activity,$userid){
1486 $act = scorm_seq_rules_check($activity,'disabled');
1490 if(scorm_limit_cond_check ($activity,$userid)){
1498 function scorm_limit_cond_check ($activity,$userid){
1500 if (isset($activity->tracked
) && ($activity->tracked
== 0)){
1505 if (scorm_seq_is('active',$activity->id
,$userid) ||
scorm_seq_is('suspended',$activity->id
,$userid)){
1509 if (!isset($activity->limitcontrol
) ||
($activity->limitcontrol
== 1)){
1510 $r = get_record('scorm_scoes_track','scoid',$activity->id
,'userid',$userid,'element','activityattemptcount');
1511 if (scorm_seq_is('activityprogressstatus',$activity->id
,$userid) && ($r->value
>=$activity->limitattempt
)){
1516 if (!isset($activity->limitabsdurcontrol
) ||
($activity->limitabsdurcontrol
== 1)){
1517 $r = get_record('scorm_scoes_track','scoid',$activity->id
,'userid',$userid,'element','activityabsoluteduration');
1518 if (scorm_seq_is('activityprogressstatus',$activity->id
,$userid) && ($r->value
>=$activity->limitabsduration
)){
1523 if (!isset($activity->limitexpdurcontrol
) ||
($activity->limitexpdurcontrol
== 1)){
1524 $r = get_record('scorm_scoes_track','scoid',$activity->id
,'userid',$userid,'element','activityexperiencedduration');
1525 if (scorm_seq_is('activityprogressstatus',$activity->id
,$userid) && ($r->value
>=$activity->limitexpduration
)){
1530 if (!isset($activity->limitattabsdurcontrol
) ||
($activity->limitattabsdurcontrol
== 1)){
1531 $r = get_record('scorm_scoes_track','scoid',$activity->id
,'userid',$userid,'element','attemptabsoluteduration');
1532 if (scorm_seq_is('activityprogressstatus',$activity->id
,$userid) && ($r->value
>=$activity->limitattabsduration
)){
1537 if (!isset($activity->limitattexpdurcontrol
) ||
($activity->limitattexpdurcontrol
== 1)){
1538 $r = get_record('scorm_scoes_track','scoid',$activity->id
,'userid',$userid,'element','attemptexperiencedduration');
1539 if (scorm_seq_is('activityprogressstatus',$activity->id
,$userid) && ($r->value
>=$activity->limitattexpduration
)){
1544 if (!isset($activity->limitbegincontrol
) ||
($activity->limitbegincontrol
== 1)){
1545 $r = get_record('scorm_scoes_track','scoid',$activity->id
,'userid',$userid,'element','begintime');
1546 if (time()>=$activity->limitbegintime
){
1551 if (!isset($activity->limitbegincontrol
) ||
($activity->limitbegincontrol
== 1)){
1552 if (time()<$activity->limitbegintime
){
1557 if (!isset($activity->limitendcontrol
) ||
($activity->limitendcontrol
== 1)){
1559 if (time()>$activity->limitendtime
){
1569 function scorm_seq_choice_sequencing($sco,$userid,$seq){
1571 $avchildren = Array ();
1572 $comancestor = null;
1576 $seq->delivery
= null;
1577 $seq->exception
= 'SB.2.9-1';
1581 $ancestors = scorm_get_ancestors($sco);
1582 $arrpath = array_reverse($ancestors);
1583 array_push ($arrpath,$sco);//path from the root to the target
1585 foreach ($arrpath as $activity){
1587 if ($activity->parent
!= '/') {
1588 $avchildren = scorm_get_available_children (scorm_get_parent($activity));
1589 $position = array_search($avchildren, $activity);
1590 if ($position !== false){
1591 $seq->delivery
= null;
1592 $seq->exception
= 'SB.2.9-2';
1597 if (scorm_seq_rules_check($activity,'hidefromchoice' != null)){
1599 $seq->delivery
= null;
1600 $seq->exception
= 'SB.2.9-3';
1607 if ($sco->parent
!= '/') {
1608 $parent = scorm_sco_get_parent ($sco);
1609 if ( isset($parent->choice
) && ($parent->choice
== false)){
1610 $seq->delivery
= null;
1611 $seq->exception
= 'SB.2.9-4';
1616 if ($seq->currentactivity
!= null){
1617 $commonpos = scorm_find_common_ancestor($ancestors,$seq->currentactivity
);
1618 $comancestor = $arrpath [$commonpos];
1621 $comancestor = $arrpath [0];
1624 if($seq->currentactivity
=== $sco) {
1628 $sib = scorm_get_siblings($seq->currentactivity
);
1629 $pos = array_search($sib, $sco);
1633 $siblings = array_slice($sib, 0, $pos-1);
1635 if (empty($siblings)){
1637 $seq->delivery
= null;
1638 $seq->exception
= 'SB.2.9-5';
1643 $children = scorm_get_children (scorm_get_parent ($sco));
1644 $pos1 = array_search($children, $sco);
1645 $pos2 = array_search($seq->currentactivity
, $sco);
1647 $traverse = 'forward';
1650 $traverse = 'backward';
1653 foreach ($siblings as $sibling){
1654 $seq = scorm_seq_choice_activity_traversal($sibling,$userid,$seq,$traverse);
1655 if(!$seq->reachable
){
1656 $seq->delivery
= null;
1664 if($seq->currentactivity
== null ||
$seq->currentactivity
== $comancestor){
1665 $commonpos = scorm_find_common_ancestor($ancestors,$seq->currentactivity
);
1666 $comtarget = array_slice($ancestors, 1,$commonpos-1);//path from the common ancestor to the target activity
1667 $comtarget = array_reverse($comtarget);
1669 if (empty($comtarget)){
1670 $seq->delivery
= null;
1671 $seq->exception
= 'SB.2.9-5';
1674 foreach ($comtarget as $act){
1675 $seq = scorm_seq_choice_activity_traversal($act,$userid,$seq,'forward');
1676 if(!$seq->reachable
){
1677 $seq->delivery
= null;
1680 $act = scorm_get_sco ($acti->id
);
1681 if(scorm_seq_is('active',$act->id
,$userid) && ($act->id
!= $comancestor->id
&& $act->preventactivation
)){//adlseq:can i write it like another property for the $seq object?
1682 $seq->delivery
= null;
1683 $seq->exception
= 'SB.2.9-6';
1691 if ($comancestor->id
== $sco->id
){
1693 $ancestorscurrent = scorm_get_ancestors($seq->currentactivity
);
1694 $possco = array_search ($ancestorscurrent, $sco);
1695 $curtarget = array_slice($ancestorscurrent,0,$possco);//path from the current activity to the target
1697 if (empty($curtarget)){
1698 $seq->delivery
= null;
1699 $seq->exception
= 'SB.2.9-5';
1703 foreach ($curtarget as $activ){
1705 if ($i != sizeof($curtarget)){
1706 if ( isset($activ->choiceexit
) && ($activ->choiceexit
== false)){
1707 $seq->delivery
= null;
1708 $seq->exception
= 'SB.2.9-7';
1716 if (array_search ($ancestors, $comancestor)!== false){
1717 $ancestorscurrent = scorm_get_ancestors($seq->currentactivity
);
1718 $commonpos = scorm_find_common_ancestor($ancestors,$sco);
1719 $curcommon = array_slice($ancestorscurrent,0,$commonpos-1);
1720 if(empty($curcommon)){
1721 $seq->delivery
= null;
1722 $seq->exception
= 'SB.2.9-5';
1726 $constrained = null;
1727 foreach ($curcommon as $acti){
1728 $acti = scorm_get_sco($acti->id
);
1729 if ( isset($acti->choiceexit
) && ($acti->choiceexit
== false)){
1730 $seq->delivery
= null;
1731 $seq->exception
= 'SB.2.9-7';
1734 if ($constrained == null){
1735 if($acti->constrainchoice
== true){
1736 $constrained = $acti;
1740 if ($constrained != null){
1741 $fwdir = scorm_get_preorder($constrained);
1743 if(array_search ($fwdir, $sco)!== false){
1744 $traverse = 'forward';
1747 $traverse = 'backward';
1749 $seq = scorm_seq_choice_flow ($constrained, $traverse, $seq);
1750 $actconsider = $seq->identifiedactivity
;
1751 $avdescendents = Array();
1752 $avdescendents= scorm_get_available_descendents ($actconsider);
1753 if (array_search ($avdescendents, $sco) !== false && $sco->id
!= $actconsider->id
&& $constrained->id
!= $sco->id
){
1754 $seq->delivery
= null;
1755 $seq->exception
= 'SB.2.9-8';
1762 $commonpos = scorm_find_common_ancestor($ancestors,$seq->currentactivity
);
1763 $comtarget = array_slice($ancestors, 1,$commonpos-1);//path from the common ancestor to the target activity
1764 $comtarget = array_reverse($comtarget);
1766 if (empty($comtarget)){
1767 $seq->delivery
= null;
1768 $seq->exception
= 'SB.2.9-5';
1772 $fwdir = scorm_get_preorder($seq->currentactivity
);
1774 if(array_search ($fwdir, $sco)!== false){
1776 foreach ($comtarget as $act){
1777 $seq = scorm_seq_choice_activity_traversal($act,$userid,$seq,'forward');
1778 if(!$seq->reachable
){
1779 $seq->delivery
= null;
1782 $act = scorm_get_sco($act->id
);
1783 if(scorm_seq_is('active',$act->id
,$userid) && ($act->id
!= $comancestor->id
&& ($act->preventactivation
== true))){
1784 $seq->delivery
= null;
1785 $seq->exception
= 'SB.2.9-6';
1792 foreach ($comtarget as $act){
1793 $act = scorm_get_sco($act->id
);
1794 if(scorm_seq_is('active',$act->id
,$userid) && ($act->id
!= $comancestor->id
&& ($act->preventactivation
==true))){
1795 $seq->delivery
= null;
1796 $seq->exception
= 'SB.2.9-6';
1804 if(scorm_is_leaf ($sco)){
1805 $seq->delivery
= $sco;
1806 $seq->exception
= 'SB.2.9-6';
1810 $seq = scorm_seq_flow ($sco,'forward',$seq,true,$userid);
1811 if ($seq->deliverable
== false){
1812 scorm_terminate_descendent_attempts($comancestor,$userid,$seq);
1813 scorm_seq_end_attempt($comancestor,$userid,$seq->attempt
);
1814 $seq->currentactivity
= $sco;
1815 $seq->delivery
= null;
1816 $seq->exception
= 'SB.2.9-9';
1826 function scorm_seq_choice_flow ($constrained, $traverse, $seq){
1827 $seq = scorm_seq_choice_flow_tree ($constrained, $traverse, $seq);
1828 if ($seq->identifiedactivity
== null){
1829 $seq->identifiedactivity
= $constrained;
1837 function scorm_seq_choice_flow_tree ($constrained, $traverse, $seq){
1839 $parent = scorm_get_parent ($constrained);
1840 if ($traverse== 'forward'){
1841 $preord = scorm_get_preorder ($constrained);
1842 if (sizeof($preorder) == 0 ||
(sizeof($preorder) == 0 && $preorder[0]->id
= $constrained->id
)){
1843 $islast = true;//the function is the last activity available
1845 if ($constrained->parent
== '/' ||
$islast){
1846 $seq->nextactivity
= null;
1849 $avchildren = scorm_get_available_children ($parent);//available children
1850 if ($avchildren [sizeof($avchildren)-1]->id
== $constrained->id
){
1851 $seq = scorm_seq_choice_flow_tree ($parent, 'forward', $seq);
1856 while(i
< sizeof($avchildren)){
1857 if ($avchildren [i
]->id
== $constrained->id
){
1858 $seq->nextactivity
= $avchildren [i+
1];
1869 if ($traverse== 'backward'){
1870 if($constrained->parent
== '/' ){
1871 $seq->nextactivity
= null;
1875 $avchildren = scorm_get_available_children ($parent);//available children
1876 if ($avchildren [0]->id
== $constrained->id
){
1877 $seq = scorm_seq_choice_flow_tree ($parent, 'backward', $seq);
1881 $i=sizeof($avchildren)-1;
1883 if ($avchildren [i
]->id
== $constrained->id
){
1884 $seq->nextactivity
= $avchildren [i
-1];
1894 function scorm_seq_choice_activity_traversal($activity,$userid,$seq,$direction){
1896 if($direction == 'forward'){
1898 $act = scorm_seq_rules_check($activity,'stopforwardtraversal');
1901 $seq->reachable
= false;
1902 $seq->exception
= 'SB.2.4-1';
1905 $seq->reachable
= false;
1909 if($direction == 'backward'){
1910 $parentsco = scorm_get_parent($activity);
1911 if($parentsco!= null){
1912 if (isset($parentsco->forwardonly
) && ($parentsco->forwardonly
== true)){
1913 $seq->reachable
= false;
1914 $seq->exception
= 'SB.2.4-2';
1918 $seq->reachable
= false;
1919 $seq->exception
= 'SB.2.4-3';
1924 $seq->reachable
= true;
1929 //Delivery Request Process
1931 function scorm_sequencing_delivery($scoid,$userid,$seq){
1933 if(!scorm_is_leaf ($seq->delivery
)){
1934 $seq->deliveryvalid
= false;
1935 $seq->exception
= 'DB.1.1-1';
1938 $ancestors = scorm_get_ancestors($seq->delivery
);
1939 $arrpath = array_reverse($ancestors);
1940 array_push ($arrpath,$seq->delivery
);//path from the root to the target
1942 if (empty($arrpath)){
1943 $seq->deliveryvalid
= false;
1944 $seq->exception
= 'DB.1.1-2';
1948 foreach ($arrpath as $activity){
1949 if(scorm_check_activity ($activity,$userid)){
1950 $seq->deliveryvalid
= false;
1951 $seq->exception
= 'DB.1.1-3';
1956 $seq->deliveryvalid
= true;
1961 function scorm_content_delivery_environment ($seq,$userid){
1963 $act = $seq->currentactivity
;
1964 if(scorm_seq_is('active',$act->id
,$userid)){
1965 $seq->exception
= 'DB.2-1';
1968 $track = get_record('scorm_scoes_track','scoid',$act->id
,'userid',$userid,'element','suspendedactivity');
1969 if ($track != null){
1970 $seq = scorm_clear_suspended_activity($seq->delivery
, $seq);
1973 $seq = scorm_terminate_descendent_attempts ($seq->delivery
,$userid,$seq);
1974 $ancestors = scorm_get_ancestors($seq->delivery
);
1975 $arrpath = array_reverse($ancestors);
1976 array_push ($arrpath,$seq->delivery
);
1977 foreach ($arrpath as $activity){
1978 if(!scorm_seq_is('active',$activity->id
,$userid)){
1979 if(!isset($activity->tracked
) ||
($activity->tracked
== 1)){
1980 if(!scorm_seq_is('suspended',$activity->id
,$userid)){
1981 $r = get_record('scorm_scoes_track','scoid',$activity->id
,'userid',$userid,'element','activityattemptcount');
1982 $r->value
= ($r->value
)+
1;
1983 update_record ('scorm_scoes_track',$r);
1984 if ($r->value
== 1){
1985 scorm_seq_set('activityprogressstatus', $activity->id
, $userid, 'true');
1987 scorm_insert_track($userid, $activity->scorm
, $activity->id
, 0, 'objectiveprogressstatus', 'false');
1988 scorm_insert_track($userid, $activity->scorm
, $activity->id
, 0, 'objectivesatisfiedstatus', 'false');
1989 scorm_insert_track($userid, $activity->scorm
, $activity->id
, 0, 'objectivemeasurestatus', 'false');
1990 scorm_insert_track($userid, $activity->scorm
, $activity->id
, 0, 'objectivenormalizedmeasure', 0.0);
1992 scorm_insert_track($userid, $activity->scorm
, $activity->id
, 0, 'attemptprogressstatus', 'false');
1993 scorm_insert_track($userid, $activity->scorm
, $activity->id
, 0, 'attemptcompletionstatus', 'false');
1994 scorm_insert_track($userid, $activity->scorm
, $activity->id
, 0, 'attemptabsoluteduration', 0.0);
1995 scorm_insert_track($userid, $activity->scorm
, $activity->id
, 0, 'attemptexperiencedduration', 0.0);
1996 scorm_insert_track($userid, $activity->scorm
, $activity->id
, 0, 'attemptcompletionamount', 0.0);
1999 scorm_seq_set('active', $activity->id
, $userid, 'true');
2002 $seq->delivery
= $seq->currentactivity
;
2003 scorm_seq_set('suspendedactivity', $activity->id
, $userid, 'false');
2005 //ONCE THE DELIVERY BEGINS (How should I check that?)
2007 if(isset($activity->tracked
) ||
($activity->tracked
== 0)){
2008 //How should I track the info and what should I do to not record the information for the activity during delivery?
2009 $atabsdur = get_record('scorm_scoes_track','scoid',$activity->id
,'userid',$userid,'element','attemptabsoluteduration');
2010 $atexpdur = get_record('scorm_scoes_track','scoid',$activity->id
,'userid',$userid,'element','attemptexperiencedduration');
2016 function scorm_clear_suspended_activity($act,$seq){
2017 $currentact= $seq->currentactivity
;
2018 $track = get_record('scorm_scoes_track','scoid',$currentact->id
,'userid',$userid,'element','suspendedactivity');
2019 if ($track != null){
2020 $ancestors = scorm_get_ancestors($act);
2021 $commonpos = scorm_find_common_ancestor($ancestors,$currentact);
2022 if ($commonpos !== false) {
2023 if ($activitypath = array_slice($ancestors,0,$commonpos)) {
2024 if (!empty ($activitypath)){
2026 foreach ($activitypath as $activity) {
2027 if (scorm_is_leaf($activity)){
2028 scorm_seq_set('suspended',$activity->id
,$userid,false);
2031 $children = scorm_get_children($activity);
2033 foreach ($children as $child){
2034 if(scorm_seq_is('suspended',$child->id
,$userid)){
2039 scorm_seq_set('suspended',$activity->id
,$userid,false);
2046 scorm_seq_set('suspendedactivity',$act->id
,$userid,false);
2051 function scorm_select_children_process($scoid,$userid){
2053 $sco = scorm_get_sco($scoid);
2054 if (!scorm_is_leaf($sco)){
2055 if(!scorm_seq_is('suspended',$scoid,$userid) && !scorm_seq_is('active',$scoid,$userid)){
2056 $r = get_record('scorm_scoes_track','scoid',$scoid,'userid',$userid,'element','selectiontiming');
2060 case 'oneachnewattempt':
2065 if(!scorm_seq_is('activityprogressstatus',$scoid,$userid)){
2066 if(scorm_seq_is('selectioncountsstatus',$scoid,$userid)){
2068 $res = get_record('scorm_scoes_track','scoid',$scoid,'userid',$userid,'element','selectioncount');
2069 $i = ($res->value
)-1;
2070 $children = scorm_get_children ($sco);
2073 $pos = array_rand($children);
2074 array_push($childlist,$children [$pos]);
2075 array_splice($children,$pos,1);
2079 $clist = serialize ($childlist);
2080 scorm_seq_set('availablechildren', $scoid, $userid, false);
2081 scorm_seq_set('availablechildren', $scoid, $userid, $clist);
2094 function scorm_randomize_children_process($scoid,$userid){
2096 $sco = scorm_get_sco($scoid);
2097 if (!scorm_is_leaf($sco)){
2098 if(!scorm_seq_is('suspended',$scoid,$userid) && !scorm_seq_is('active',$scoid,$userid)){
2099 $r = get_record('scorm_scoes_track','scoid',$scoid,'userid',$userid,'element','randomizationtiming');
2107 case 'oneachnewattempt':
2109 if(!scorm_seq_is('activityprogressstatus',$scoid,$userid)){
2110 if(scorm_seq_is('randomizechildren',$scoid,$userid)){
2111 $childlist = array();
2112 $res = scorm_get_available_children($sco);
2113 $i = sizeof($res)-1;
2114 $children = $res->value
;
2117 $pos = array_rand($children);
2118 array_push($childlist,$children [$pos]);
2119 array_splice($children,$pos,1);
2123 $clist = serialize ($childlist);
2124 scorm_seq_set('availablechildren', $scoid, $userid, false);
2125 scorm_seq_set('availablechildren', $scoid, $userid, $clist);
2140 function scorm_terminate_descendent_attempts ($activity,$userid,$seq){
2141 $ancestors = scorm_get_ancestors($seq->currentactivity
);
2142 $commonpos = scorm_find_common_ancestor($ancestors,$activity);
2143 if ($commonpos !== false) {
2144 if ($activitypath = array_slice($ancestors,1,$commonpos-2)) {
2145 if (!empty ($activitypath)){
2147 foreach ($activitypath as $sco) {
2148 scorm_seq_end_attempt($sco,$userid,$seq->attempt
);
2156 function scorm_sequencing_exception($seq){
2157 if($seq->exception
!= null){
2158 switch($seq->exception
){
2161 notify("Sequencing session has already begun");
2164 notify("Sequencing session has not begun");
2167 notify("Suspended activity is not defined");
2170 notify("Flow Sequencing Control Model Violation");
2173 notify("Flow or Forward only Sequencing Control Model Violation");
2176 notify("No activity is previous to the root");
2179 notify("Unsupported Navigation Request");
2182 notify("Choice Exit Sequencing Control Model Violation");
2185 notify("No activities to consider");
2188 notify("Choice Sequencing Control Model Violation");
2191 notify("Target Activity does not exist");
2194 notify("Current Activity already terminated");
2197 notify("Undefined Navigation Request");
2201 notify("Current Activity already terminated");
2204 notify("Current Activity already terminated");
2207 notify("Current Activity already terminated");
2210 notify("Nothing to suspend; No active activities");
2213 notify("Nothing to abandon; No active activities");
2217 notify("Last activity in the tree");
2220 notify("Cluster has no available children");
2223 notify("No activity is previous to the root");
2226 notify("Forward Only Sequencing Control Model Violation");
2230 notify("Flow Sequencing Control Model Violation");
2233 notify("Activity unavailable");
2237 notify("Forward Traversal Blocked");
2240 notify("Forward Only Sequencing Control Model Violation");
2243 notify("No activity is previous to the root");
2247 notify("Sequencing session has already begun");
2251 notify("Sequencing session has already begun");
2254 notify("No Suspended activity is defined");
2258 notify("Sequencing session has not begun");
2261 notify("Flow Sequencing Control Model Violation");
2265 notify("Sequencing session has not begun");
2268 notify("Flow Sequencing Control Model Violation");
2272 notify("No target for Choice");
2275 notify("Target Activity does not exist or is unavailable");
2278 notify("Target Activity hidden from choice");
2281 notify("Choice Sequencing Control Model Violation");
2284 notify("No activities to consider");
2287 notify("Unable to activate target; target is not a child of the Current Activity");
2290 notify("Choice Exit Sequencing Control Model Violation");
2293 notify("Unable to choose target activity - constrained choice");
2296 notify("Choice Request Prevented by Flow-only Activity");
2300 notify("Sequencing session has not begun");
2303 notify("Current Activity is active or suspended");
2306 notify("Flow Sequencing Control Model Violation");
2310 notify("Sequencing session has not begun");
2313 notify("Current Activity has not been terminated");
2317 notify("Undefined Sequencing Request");
2321 notify("Cannot deliver a non-leaf activity");
2324 notify("Nothing to deliver");
2327 notify("Activity unavailable");
2331 notify("Identified activity is already active");