Public Member Functions | |
ilObjAICCCourseInterchangeFiles () | |
findFiles ($dir) | |
readFiles () | |
getDescriptor ($system_id) | |
validate () | |
checkRequiredKeys () | |
checkCourseFile ($fileSuffix, $data, $requiredKeys, $group=0) | |
checkColumnCount ($fileSuffix, $data) | |
checkStructure () | |
readCRS ($filename) | |
readCSVFile ($filename) | |
getAllFiles ($dir, $arr=array()) | |
arraykeys_tolower ($arr) | |
writeToDatabase ($alm_id) | |
Data Fields | |
$coursefiles | |
$data | |
$errorText | |
$requiredFiles = array("crs", "au", "cst", "des") | |
$optionalFiles = array("cmp", "ort", "pre") |
Definition at line 3 of file class.ilObjAICCCourseInterchangeFiles.php.
ilObjAICCCourseInterchangeFiles::arraykeys_tolower | ( | $ | arr | ) |
Definition at line 206 of file class.ilObjAICCCourseInterchangeFiles.php.
Referenced by readFiles().
{ $arr=array_change_key_case($arr, CASE_LOWER); foreach ($arr as $k=>$v) { if (is_array($v)) $arr[$k]=$this->arraykeys_tolower($v); } return $arr; }
ilObjAICCCourseInterchangeFiles::checkColumnCount | ( | $ | fileSuffix, | |
$ | data | |||
) |
Definition at line 113 of file class.ilObjAICCCourseInterchangeFiles.php.
References $data.
Referenced by checkRequiredKeys().
{ if (count($data)>0) { $colcount=-1; for ($colnr=0;$colnr<count($data);$colnr++) { if ($colcount==-1) $colcount=count($data[$colnr]); else if ($colcount!=count($data[$colnr])) $this->errorText[]=strtoupper($fileSuffix)."-File: unexpected number of columns in line ".($colnr+2); } } }
ilObjAICCCourseInterchangeFiles::checkCourseFile | ( | $ | fileSuffix, | |
$ | data, | |||
$ | requiredKeys, | |||
$ | group = 0 | |||
) |
Definition at line 93 of file class.ilObjAICCCourseInterchangeFiles.php.
References $data.
Referenced by checkRequiredKeys().
{ if (count($data)>0 && is_array($data[$group])) { $keys=array_keys($data[$group]); $missingKeys = array_diff ($requiredKeys, $keys); $optionalKeys = array_diff ($keys, $requiredKeys); if (count($missingKeys)>0) $this->errorText[]="missing keys in ".strtoupper($fileSuffix)."-File: ".implode(",", $missingKeys); } else if (count($data)>0 && !is_array($data[$group])) { $this->errorText[]="missing Group in ".strtoupper($fileSuffix)."-File: $group"; } else { $this->errorText[]="empty ".strtoupper($fileSuffix)."-File"; } }
ilObjAICCCourseInterchangeFiles::checkRequiredKeys | ( | ) |
Definition at line 64 of file class.ilObjAICCCourseInterchangeFiles.php.
References $errorText, checkColumnCount(), and checkCourseFile().
Referenced by validate().
{ //AU $requiredKeys=array("system_id", "type", "command_line", "file_name", "max_score", "mastery_score", "max_time_allowed", "time_limit_action", "system_vendor", "core_vendor", "web_launch", "au_password"); $this->checkCourseFile("au", $this->data["au"], $requiredKeys); $this->checkColumnCount("au", $this->data["au"]); //DES $requiredKeys=array("system_id", "title", "description", "developer_id"); $this->checkCourseFile("des", $this->data["des"], $requiredKeys); $this->checkColumnCount("des", $this->data["des"]); //CRS $requiredKeys=array("course_creator", "course_id", "course_system", "course_title", "level", "max_fields_cst", "total_aus", "total_blocks", "version"); $this->checkCourseFile("crs", $this->data["crs"], $requiredKeys, "course"); $requiredKeys=array("max_normal"); $this->checkCourseFile("crs", $this->data["crs"], $requiredKeys, "course_behavior"); //CST $requiredKeys=array("block", "member"); $this->checkCourseFile("cst", $this->data["cst"], $requiredKeys,0); $this->checkColumnCount("cst", $this->data["cst"]); return $errorText; }
ilObjAICCCourseInterchangeFiles::checkStructure | ( | ) |
Definition at line 125 of file class.ilObjAICCCourseInterchangeFiles.php.
References $row.
Referenced by validate().
{ //max member fields in cst-file $max=$this->data[crs][course][max_fields_cst]; for ($row=0;$row<count($this->data[cst]);$row++) { $value=$this->data[cst][$row][member]; if ((is_array($value) && count($value)>$max) || (!is_array($value) && $max==1)) { $this->errorText[]="CRS-File: max_fields_cst does not match number of fields in the CST-File"; return; } } //additional validation statements // // }
ilObjAICCCourseInterchangeFiles::findFiles | ( | $ | dir | ) |
Definition at line 20 of file class.ilObjAICCCourseInterchangeFiles.php.
References $dir, $file, $files, and getAllFiles().
{ $suffixes=array_merge($this->requiredFiles,$this->optionalFiles); $files=$this->getAllFiles($dir); foreach ($files as $file) { foreach($suffixes as $suffix) { if (strcasecmp(substr($file, -(strlen($suffix)+1)), ".".$suffix)==0) $this->coursefiles[$suffix] = $file; } } //check for required files $missingFiles = array_diff ($this->requiredFiles, array_keys($this->coursefiles)); if (count($missingFiles)==4) $this->errorText[]="Missing all required files.<br>You want to check if your learning module is of a different type."; else if (count($missingFiles)>0) $this->errorText[]="Missing required file(s): ".implode("<bR>", $missingFiles); }
ilObjAICCCourseInterchangeFiles::getAllFiles | ( | $ | dir, | |
$ | arr = array() | |||
) |
Definition at line 189 of file class.ilObjAICCCourseInterchangeFiles.php.
Referenced by findFiles().
{ if (substr($dir, -1)!="/") $dir.="/"; $handle=opendir($dir); while ($file = readdir ($handle)) { if ($file != "." && $file != "..") { if (is_dir($dir.$file)) $arr=$this->getAllFiles($dir.$file, $arr); else $arr[]=$dir.$file; } } closedir($handle); return $arr; }
ilObjAICCCourseInterchangeFiles::getDescriptor | ( | $ | system_id | ) |
Definition at line 52 of file class.ilObjAICCCourseInterchangeFiles.php.
References $row.
Referenced by writeToDatabase().
{ foreach ($this->data["des"] as $row) { if (strcasecmp ($row["system_id"],$system_id)==0) return $row; } }
ilObjAICCCourseInterchangeFiles::ilObjAICCCourseInterchangeFiles | ( | ) |
Definition at line 11 of file class.ilObjAICCCourseInterchangeFiles.php.
{ $this->errorText=array(); $this->coursefiles=array(); }
ilObjAICCCourseInterchangeFiles::readCRS | ( | $ | filename | ) |
Definition at line 144 of file class.ilObjAICCCourseInterchangeFiles.php.
References $data.
Referenced by readFiles().
{ $data=@parse_ini_file($filename, TRUE); //crs-file is not a valid iniFile //thats why reading the file again to get course_description $lines=file($filename); for($i=0;$i<count($lines);$i++) { if (trim($lines[$i])=="[Course_Description]") { for ($i++;$i<count($lines);$i++) { if (strlen(trim($lines[$i]))>0) { $data["Course_Description"][description]=$lines[$i]; break; } } } } return $data; }
ilObjAICCCourseInterchangeFiles::readCSVFile | ( | $ | filename | ) |
Definition at line 164 of file class.ilObjAICCCourseInterchangeFiles.php.
Referenced by readFiles().
{ $row=1; $handle = fopen($filename, "r"); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { if ($row++==1) { $header=$data; } else if (count($data)>1) { $data2=array(); for ($col=0; $col<count($data); $col++) { if (array_key_exists($header[$col], $data2)) { $value=$data2[$header[$col]]; if (!is_array($value)) $data2[$header[$col]]=array($value, utf8_encode($data[$col])); else $data2[$header[$col]][]=utf8_encode($data[$col]); } else $data2[$header[$col]]=utf8_encode($data[$col]); } $rows[]=$data2; } } fclose($handle); return $rows; }
ilObjAICCCourseInterchangeFiles::readFiles | ( | ) |
Definition at line 38 of file class.ilObjAICCCourseInterchangeFiles.php.
References arraykeys_tolower(), readCRS(), and readCSVFile().
{ $this->data=array(); foreach ($this->coursefiles as $suffix=>$filename) { if ($suffix=="crs") $this->data[$suffix]=$this->readCRS($filename); else $this->data[$suffix]=$this->readCSVFile($filename); } //Prepare Data-Array: all keys to lower $this->data=$this->arraykeys_tolower($this->data); }
ilObjAICCCourseInterchangeFiles::validate | ( | ) |
Definition at line 59 of file class.ilObjAICCCourseInterchangeFiles.php.
References checkRequiredKeys(), and checkStructure().
{ $this->checkRequiredKeys(); $this->checkStructure(); }
ilObjAICCCourseInterchangeFiles::writeToDatabase | ( | $ | alm_id | ) |
Definition at line 215 of file class.ilObjAICCCourseInterchangeFiles.php.
References $row, $tree, and getDescriptor().
{ include_once("content/classes/AICC/class.ilAICCTree.php"); include_once("content/classes/AICC/class.ilAICCCourse.php"); include_once("content/classes/AICC/class.ilAICCUnit.php"); include_once("content/classes/AICC/class.ilAICCBlock.php"); //write course to database $course=new ilAICCCourse(); $course->setALMId($alm_id); $course->setSystemId("root"); $course->setTitle($this->data["crs"]["course"]["course_title"]); $course->setDescription($this->data["crs"]["course_description"]["description"]); $course->setCourseCreator($this->data["crs"]["course"]["course_creator"]); $course->setCourseId($this->data["crs"]["course"]["course_id"]); $course->setCourseSystem($this->data["crs"]["course"]["course_system"]); $course->setCourseTitle($this->data["crs"]["course"]["course_title"]); $course->setLevel($this->data["crs"]["course"]["level"]); $course->setMaxFieldsCst($this->data["crs"]["course"]["max_fields_cst"]); $course->setMaxFieldsOrt($this->data["crs"]["course"]["max_fields_ort"]); $course->setTotalAUs($this->data["crs"]["course"]["total_aus"]); $course->setTotalBlocks($this->data["crs"]["course"]["total_blocks"]); $course->setTotalComplexObj($this->data["crs"]["course"]["total_complex_obj"]); $course->setTotalObjectives($this->data["crs"]["course"]["total_objectives"]); $course->setVersion($this->data["crs"]["course"]["version"]); $course->setMaxNormal($this->data["crs"]["course_behavior"]["max_normal"]); $course->setDescription($this->data["crs"]["course_description"]["description"]); $course->create(); $identifier["root"]=$course->getId(); //all blocks foreach ($this->data["cst"] as $row) { $system_id=strtolower($row["block"]); if ($system_id!="root") { $unit=new ilAICCBlock(); $description=$this->getDescriptor($system_id); $unit->setALMId($alm_id); $unit->setType("sbl"); $unit->setTitle($description["title"]); $unit->setDescription($description["description"]); $unit->setDeveloperId($description["developer_id"]); $unit->setSystemId($description["system_id"]); $unit->create(); $identifier[$system_id]=$unit->getId(); } } //write assignable units to database foreach ($this->data["au"] as $row) { $sysid=strtolower($row["system_id"]); $unit=new ilAICCUnit(); $unit->setAUType($row["type"]); $unit->setCommand_line($row["command_line"]); $unit->setMaxTimeAllowed($row["max_time_allowed"]); $unit->setTimeLimitAction($row["time_limit_action"]); $unit->setMaxScore($row["max_score"]); $unit->setCoreVendor($row["core_vendor"]); $unit->setSystemVendor($row["system_vendor"]); $unit->setFilename($row["file_name"]); $unit->setMasteryScore($row["mastery_score"]); $unit->setWebLaunch($row["web_launch"]); $unit->setAUPassword($row["au_password"]); $description=$this->getDescriptor($sysid); $unit->setALMId($alm_id); $unit->setType("sau"); $unit->setTitle($description["title"]); $unit->setDescription($description["description"]); $unit->setDeveloperId($description["developer_id"]); $unit->setSystemId($description["system_id"]); $unit->create(); $identifier[$sysid]=$unit->getId(); } //write tree $tree =& new ilAICCTree($alm_id); $tree->addTree($alm_id, $identifier["root"]); //writing members foreach ($this->data["cst"] as $row) { $members=$row["member"]; if (!is_array($members)) $members=array($members); $parentid=$identifier[strtolower($row["block"])]; foreach($members as $member) { $memberid=$identifier[strtolower($member)]; $tree->insertNode($memberid, $parentid); } } }
ilObjAICCCourseInterchangeFiles::$coursefiles |
Definition at line 5 of file class.ilObjAICCCourseInterchangeFiles.php.
ilObjAICCCourseInterchangeFiles::$data |
Definition at line 6 of file class.ilObjAICCCourseInterchangeFiles.php.
Referenced by checkColumnCount(), checkCourseFile(), readCRS(), and readCSVFile().
ilObjAICCCourseInterchangeFiles::$errorText |
Definition at line 7 of file class.ilObjAICCCourseInterchangeFiles.php.
Referenced by checkRequiredKeys().
ilObjAICCCourseInterchangeFiles::$optionalFiles = array("cmp", "ort", "pre") |
Definition at line 9 of file class.ilObjAICCCourseInterchangeFiles.php.
ilObjAICCCourseInterchangeFiles::$requiredFiles = array("crs", "au", "cst", "des") |
Definition at line 8 of file class.ilObjAICCCourseInterchangeFiles.php.