MDL-33053 AICC: Incorrect Table Of Content hierarchy using "structured" AICC
authorMatteo Scaramuccia <moodle@matteoscaramuccia.com>
Mon, 21 May 2012 22:47:01 +0000 (00:47 +0200)
committerMatteo Scaramuccia <moodle@matteoscaramuccia.com>
Mon, 21 May 2012 22:47:01 +0000 (00:47 +0200)
          courses
[Fix] 'scorm_scoes' doesn't contain all the entries described in the DES file
[Fix] HTMLizing the parent relationship, described in the CST file,
      fails: it considers 'index = 0' (found) equals to 'false' (not found)

mod/scorm/datamodels/aicclib.php
mod/scorm/locallib.php

index c926c12..9bf6628 100644 (file)
@@ -197,7 +197,10 @@ function scorm_parse_aicc($scorm) {
                 if (preg_match($regexp, $rows[$i], $matches)) {
                     for ($j=0; $j<count($columns->columns); $j++) {
                         if ($j != $columns->mastercol) {
-                            $courses[$courseid]->elements[substr(trim($matches[$j+1]), 1 , -1)]->parent = substr(trim($matches[$columns->mastercol+1]), 1, -1);
+                            $element = substr(trim($matches[$j+1]), 1 , -1);
+                            if (!empty($element)) {
+                                $courses[$courseid]->elements[$element]->parent = substr(trim($matches[$columns->mastercol+1]), 1, -1);
+                            }
                         }
                     }
                 }
@@ -275,58 +278,61 @@ function scorm_parse_aicc($scorm) {
                     } else {
                         $sco->parent = $element->parent;
                     }
+                    $sco->launch = '';
+                    $sco->scormtype = '';
+                    $sco->previous = 0;
+                    $sco->next = 0;
+                    $id = null;
+                    // Is it an Assignable Unit (AU)?
                     if (isset($element->file_name)) {
                         $sco->launch = $element->file_name;
                         $sco->scormtype = 'sco';
-                        $sco->previous = 0;
-                        $sco->next = 0;
-                        $id = null;
-                        if ($oldscoid = scorm_array_search('identifier', $sco->identifier, $oldscoes)) {
-                            $sco->id = $oldscoid;
-                            $DB->update_record('scorm_scoes', $sco);
-                            $id = $oldscoid;
-                            $DB->delete_records('scorm_scoes_data', array('scoid'=>$oldscoid));
-                            unset($oldscoes[$oldscoid]);
-                        } else {
-                            $id = $DB->insert_record('scorm_scoes', $sco);
+                    }
+                    if ($oldscoid = scorm_array_search('identifier', $sco->identifier, $oldscoes)) {
+                        $sco->id = $oldscoid;
+                        $DB->update_record('scorm_scoes', $sco);
+                        $id = $oldscoid;
+                        $DB->delete_records('scorm_scoes_data', array('scoid'=>$oldscoid));
+                        unset($oldscoes[$oldscoid]);
+                    } else {
+                        $id = $DB->insert_record('scorm_scoes', $sco);
+                    }
+                    if (!empty($id)) {
+                        $scodata = new stdClass();
+                        $scodata->scoid = $id;
+                        if (isset($element->web_launch)) {
+                            $scodata->name = 'parameters';
+                            $scodata->value = $element->web_launch;
+                            $dataid = $DB->insert_record('scorm_scoes_data', $scodata);
                         }
-                        if (!empty($id)) {
-                            $scodata = new stdClass();
-                            $scodata->scoid = $id;
-                            if (isset($element->web_launch)) {
-                                $scodata->name = 'parameters';
-                                $scodata->value = $element->web_launch;
-                                $dataid = $DB->insert_record('scorm_scoes_data', $scodata);
-                            }
-                            if (isset($element->prerequisites)) {
-                                $scodata->name = 'prerequisites';
-                                $scodata->value = $element->prerequisites;
-                                $dataid = $DB->insert_record('scorm_scoes_data', $scodata);
-                            }
-                            if (isset($element->max_time_allowed)) {
-                                $scodata->name = 'max_time_allowed';
-                                $scodata->value = $element->max_time_allowed;
-                                $dataid = $DB->insert_record('scorm_scoes_data', $scodata);
-                            }
-                            if (isset($element->time_limit_action)) {
-                                $scodata->name = 'time_limit_action';
-                                $scodata->value = $element->time_limit_action;
-                                $dataid = $DB->insert_record('scorm_scoes_data', $scodata);
-                            }
-                            if (isset($element->mastery_score)) {
-                                $scodata->name = 'mastery_score';
-                                $scodata->value = $element->mastery_score;
-                                $dataid = $DB->insert_record('scorm_scoes_data', $scodata);
-                            }
-                            if (isset($element->core_vendor)) {
-                                $scodata->name = 'datafromlms';
-                                $scodata->value = preg_replace('/<cr>/i', "\r\n", $element->core_vendor);
-                                $dataid = $DB->insert_record('scorm_scoes_data', $scodata);
-                            }
+                        if (isset($element->prerequisites)) {
+                            $scodata->name = 'prerequisites';
+                            $scodata->value = $element->prerequisites;
+                            $dataid = $DB->insert_record('scorm_scoes_data', $scodata);
+                        }
+                        if (isset($element->max_time_allowed)) {
+                            $scodata->name = 'max_time_allowed';
+                            $scodata->value = $element->max_time_allowed;
+                            $dataid = $DB->insert_record('scorm_scoes_data', $scodata);
                         }
-                        if ($launch==0) {
-                            $launch = $id;
+                        if (isset($element->time_limit_action)) {
+                            $scodata->name = 'time_limit_action';
+                            $scodata->value = $element->time_limit_action;
+                            $dataid = $DB->insert_record('scorm_scoes_data', $scodata);
                         }
+                        if (isset($element->mastery_score)) {
+                            $scodata->name = 'mastery_score';
+                            $scodata->value = $element->mastery_score;
+                            $dataid = $DB->insert_record('scorm_scoes_data', $scodata);
+                        }
+                        if (isset($element->core_vendor)) {
+                            $scodata->name = 'datafromlms';
+                            $scodata->value = preg_replace('/<cr>/i', "\r\n", $element->core_vendor);
+                            $dataid = $DB->insert_record('scorm_scoes_data', $scodata);
+                        }
+                    }
+                    if ($launch==0) {
+                        $launch = $id;
                     }
                 }
             }
index 7065221..c48c467 100644 (file)
@@ -1338,7 +1338,8 @@ function scorm_get_toc($user,$scorm,$cmid,$toclink=TOCJSLINK,$currentorg='',$sco
                 $isvisible = true;
             }
             if ($parents[$level] != $sco->parent) {
-                if ($newlevel = array_search($sco->parent,$parents)) {
+                $newlevel = array_search($sco->parent,$parents);
+                if ($newlevel !== false) {
                     for ($i=0; $i<($level-$newlevel); $i++) {
                         $result->toc .= "\t\t</li></ul></li>\n";
                     }