public function fromIMS($ims_file, $deleteEntities = false) { if ($deleteEntities) { $this->initialize($deleteEntities); //Initialize the lesson aspects that the user specified } $timestamp = time(); $zip = new Archive_zip($ims_file); $extracted_files = $zip->extract(array('add_path' => G_LESSONSPATH . $this->lesson['id'] . "/IMS_" . $timestamp)); $total_fields = array(); $resources = array(); $tagArray = @eF_local_parseManifest(G_LESSONSPATH . $this->lesson['id'] . "/IMS_" . $timestamp); $questions = array(); $tests = array(); $content = array(); $inContent = false; $inTest = false; $inQuestion = false; $references = array(); $questionsKeys = array(); $testsKeys = array(); foreach ($tagArray as $key => $value) { $fields = array(); switch ($value['tag']) { case 'TITLE': $cur = $value['parent_index']; if ($inContent) { $content[$cur]['name'] = $value['value']; } if ($inTest) { $tests[$cur]['name'] = $value['value']; } break; case 'ITEM': $cur = $key; if ($value['attributes']['TYPE'] != 'question' && $value['attributes']['TYPE'] != 'test') { $inContent = true; $inTest = false; $inQuestion = false; $content[$key]['lessons_ID'] = $this->lesson['id']; $content[$key]['timestamp'] = time(); $content[$key]['ctg_type'] = 'theory'; $content[$key]['active'] = 1; $references[$key] = $value['attributes']['IDENTIFIERREF']; } else { if ($value['attributes']['TYPE'] == 'test') { $inTest = true; $inContent = false; $inQuestion = false; $tests[$key]['active'] = '1'; $testsKeys[$value['attributes']['IDENTIFIERREF']] = $key; $references[$key] = $value['attributes']['IDENTIFIERREF']; } else { if ($value['attributes']['TYPE'] == 'question') { $inQuestion = true; $inContent = false; $inTest = false; $questions[$key]['difficulty'] = 'medium'; //initial value $questions[$key]['type'] = 'true_false'; //initial value $questions[$key]['timestamp'] = time(); $questionsKeys[$value['attributes']['IDENTIFIERREF']] = $key; $references[$key] = $value['attributes']['IDENTIFIERREF']; } } } break; case 'RESOURCE': $resources[$key] = $value['attributes']['IDENTIFIER']; break; case 'FILE': $files[$key] = $value['attributes']['HREF']; break; case 'ADLCP:MAXTIMEALLOWED': $maxtimeallowed[$key] = $value['value']; break; case 'ADLCP:TIMELIMITACTION': $timelimitaction[$key] = $value['value']; break; case 'ADLCP:MASTERYSCORE': $masteryscore[$key] = $value['value']; break; case 'ADLCP:DATAFROMLMS': $datafromlms[$key] = $value['value']; break; case 'ADLCP:PREREQUISITES': $prerequisites[$key] = $value['value']; break; default: break; } } foreach ($references as $key => $value) { $ref = array_search($value, $resources); if ($ref !== false && !is_null($ref)) { $data = file_get_contents(G_LESSONSPATH . $this->lesson['id'] . "/IMS_" . $timestamp . "/" . $tagArray[$ref]['attributes']['HREF']); $primitive_hrefs[$ref] = $tagArray[$ref]['attributes']['HREF']; $path_part[$ref] = dirname($primitive_hrefs[$ref]); foreach ($tagArray[$ref]['children'] as $value2) { if ($tagArray[$value2]['tag'] == 'DEPENDENCY') { $idx = array_search($tagArray[$value2]['attributes']['IDENTIFIERREF'], $resources); foreach ($tagArray[$idx]['children'] as $value3) { if ($tagArray[$value3]['tag'] == 'FILE') { $data = preg_replace("#(\\.\\.\\/(\\w+\\/)*)?" . $tagArray[$value3]['attributes']['HREF'] . "#", G_LESSONSPATH . $this->lesson['id'] . "/" . $path_part[$ref] . "/\$1" . $tagArray[$value3]['attributes']['HREF'], $data); } } } } if ($content[$key]['active'] == 1) { $i1 = stripos($data, "<body"); $i2 = stripos($data, ">", $i1); $i3 = strripos($data, "<script"); $data = substr($data, $i2 + 1, $i3 - $i2 - 1); $content[$key]['data'] = $data; } else { if ($tests[$key]) { $data = $data; $tests[$key]['description'] = $data; } else { if ($questions[$key]) { $data = $data; $questions[$key]['text'] = $data; } } } } } $inStart = true; foreach ($content as $key => $value) { $cid = ef_insertTableData("content", $value); /* TODO INDEX */ if ($inStart) { $inStart = false; foreach ($questions as $keyq => $valueq) { $questions[$keyq]['content_ID'] = $cid; } } } foreach ($questions as $key => $value) { $qid = ef_insertTableData("questions", $value); $questions[$key]['id'] = $qid; } foreach ($tests as $key => $value) { $test_content['lessons_ID'] = $this->lesson['id']; $test_content['timestamp'] = time(); $test_content['ctg_type'] = 'tests'; $test_content['active'] = 1; $test_content['name'] = $value['name']; unset($value['name']); $cid = ef_insertTableData("content", $test_content); $value['content_id'] = $cid; $tid = ef_insertTableData("tests", $value); $tests[$key]['id'] = $tid; } eF_local_buildDirectories(G_LESSONSPATH . $this->lesson['id'] . "/", G_LESSONSPATH . $this->lesson['id'] . "/IMS_" . $timestamp); foreach ($files as $key => $value) { // if (!in_array($value, $primitive_hrefs)) // { $newhref = $tagArray[$tagArray[$key]['parent_index']]['attributes']['XML:BASE']; //copy(G_LESSONSPATH.$this->lesson['id']."/IMS_".$timestamp."/".trim($newhref,"/")."/".trim($value,"/"), G_LESSONSPATH.$this->lesson['id']."/".trim($newhref,"/")."/".trim($value,"/")); // } } $cur_dir = getcwd(); chdir(G_LESSONSPATH . $this->lesson['id'] . "/IMS_" . $timestamp); $filelist = eF_getDirContents(); foreach ($filelist as $value) { copy($value, G_LESSONSPATH . $this->lesson['id'] . "/" . $value); } chdir($cur_dir); foreach ($prerequisites as $key => $value) { foreach ($tagArray as $key2 => $value2) { if (isset($value2['attributes']['IDENTIFIER']) && $value2['attributes']['IDENTIFIER'] == $value) { unset($fields_insert); $fields_insert['users_LOGIN'] = "******"; $fields_insert['content_ID'] = $tagArray[$tagArray[$key]['parent_index']]['this_id']; $fields_insert['rule_type'] = "hasnot_seen"; $fields_insert['rule_content_ID'] = $value2['this_id']; $fields_insert['rule_option'] = 0; //eF_insertTableData("rules", $fields_insert); } } } //read the special EfrontLesson.xml $xmlfile = G_LESSONSPATH . $this->lesson['id'] . "/IMS_" . $timestamp . "/EfrontLesson.xml"; $xml = simplexml_load_file($xmlfile); for ($i = 0; $i < sizeof($xml->conditions->condition); $i++) { $condition = array(); $condition['type'] = (string) $xml->conditions->condition[$i]->type; $condition['options'] = (string) $xml->conditions->condition[$i]->options; $condition['relation'] = (string) $xml->conditions->condition[$i]->relation; $condition['lessons_ID'] = $this->lesson['id']; $cid = ef_insertTableData("lesson_conditions", $condition); } for ($i = 0; $i < sizeof($xml->glossary->word); $i++) { $glossary = array(); $glossary['name'] = (string) $xml->glossary->word[$i]->name; $glossary['type'] = (string) $xml->glossary->word[$i]->type; $glossary['info'] = (string) $xml->glossary->word[$i]->info; $glossary['active'] = (string) $xml->glossary->word[$i]->active; $glossary['lessons_ID'] = $this->lesson['id']; $cid = ef_insertTableData("glossary", $glossary); } for ($i = 0; $i < sizeof($xml->questions->question); $i++) { $update = array(); $refid = (string) $xml->questions->question[$i]->refid; $qk = $questionsKeys[$refid]; $qid = $questions[$qk]['id']; $update['type'] = (string) $xml->questions->question[$i]->type; $update['difficulty'] = (string) $xml->questions->question[$i]->difficulty; $update['options'] = (string) $xml->questions->question[$i]->options; $update['answer'] = (string) $xml->questions->question[$i]->answer; $update['explanation'] = (string) $xml->questions->question[$i]->explanation; ef_updateTableData("questions", $update, "id = {$qid}"); } for ($i = 0; $i < sizeof($xml->tests->test); $i++) { $update = array(); $refid = (string) $xml->tests->test[$i]->refid; $tk = $testsKeys[$refid]; $tid = $tests[$tk]['id']; $update['duration'] = (string) $xml->tests->test[$i]->duration; $update['redoable'] = (string) $xml->tests->test[$i]->redoable; $update['onebyone'] = (string) $xml->tests->test[$i]->onebyone; $update['answers'] = (string) $xml->tests->test[$i]->answers; $update['shuffle_questions'] = (string) $xml->tests->test[$i]->shuffle_questions; $update['shuffle_answers'] = (string) $xml->tests->test[$i]->shuffle_answers; $update['given_answers'] = (string) $xml->tests->test[$i]->given_answers; ef_updateTableData("tests", $update, "id=" . $tid); for ($j = 0; $j < sizeof($xml->tests->test[$i]->questions->question); $j++) { $testQuestions = array(); $refid = (string) $xml->tests->test[$i]->questions->question[$j]->refid; $qk = $questionsKeys[$refid]; $qid = $questions[$qk]['id']; $previd = (string) $xml->tests->test[$i]->questions->question[$j]->previous; if ($previd != "q0") { $pk = $questionsKeys[$previd]; $pid = $questions[$pk]['id']; } else { $pid = 0; } $testQuestions['tests_ID'] = $tid; $testQuestions['questions_ID'] = $qid; $testQuestions['previous_question_ID'] = $pid; $testQuestions['weight'] = (string) $xml->tests->test[$i]->questions->question[$j]->weight; ef_insertTableData("tests_to_questions", $testQuestions); } } }
private function setRefreshRate($rate) { ef_updateTableData('module_chat_config', array('refresh_rate' => $rate)); }