Completed
Push — 1.10.x ( 039d05...2fbd07 )
by Yannick
45:46
created
main/exercice/export/exercise_import.inc.php 2 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -949,7 +949,6 @@
 block discarded – undo
949 949
 /**
950 950
  * Processes an IMS/QTI manifest file: store links to new files to be able to transform them into questions text
951 951
  * @param string $filePath The absolute filepath
952
- * @param array $links List of filepaths changes
953 952
  * @return bool
954 953
  */
955 954
 function qtiProcessManifest($filePath)
Please login to merge, or discard this patch.
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
     global $questionTempDir;
60 60
     global $resourcesLinks;
61 61
 
62
-    $baseWorkDir = api_get_path(SYS_ARCHIVE_PATH) . 'qti2';
62
+    $baseWorkDir = api_get_path(SYS_ARCHIVE_PATH).'qti2';
63 63
 
64 64
     if (!is_dir($baseWorkDir)) {
65 65
         mkdir($baseWorkDir, api_get_permissions_for_new_directories(), true);
@@ -101,35 +101,35 @@  discard block
 block discarded – undo
101 101
 
102 102
     // parse every subdirectory to search xml question files
103 103
     while (false !== ($file = readdir($exerciseHandle))) {
104
-        if (is_dir($baseWorkDir . '/' . $file) && $file != "." && $file != "..") {
104
+        if (is_dir($baseWorkDir.'/'.$file) && $file != "." && $file != "..") {
105 105
             // Find each manifest for each question repository found
106
-            $questionHandle = opendir($baseWorkDir . '/' . $file);
106
+            $questionHandle = opendir($baseWorkDir.'/'.$file);
107 107
             // Only analyse one level of subdirectory - no recursivity here
108 108
             while (false !== ($questionFile = readdir($questionHandle))) {
109 109
                 if (preg_match('/.xml$/i', $questionFile)) {
110
-                    $isQti = isQtiQuestionBank($baseWorkDir . '/' . $file . '/' . $questionFile);
110
+                    $isQti = isQtiQuestionBank($baseWorkDir.'/'.$file.'/'.$questionFile);
111 111
                     if ($isQti) {
112 112
                         $result = qti_parse_file($baseWorkDir, $file, $questionFile);
113
-                        $filePath = $baseWorkDir . $file;
113
+                        $filePath = $baseWorkDir.$file;
114 114
                         $file_found = true;
115 115
                     } else {
116
-                        $isManifest = isQtiManifest($baseWorkDir . '/' . $file . '/' . $questionFile);
116
+                        $isManifest = isQtiManifest($baseWorkDir.'/'.$file.'/'.$questionFile);
117 117
                         if ($isManifest) {
118
-                            $resourcesLinks = qtiProcessManifest($baseWorkDir . '/' . $file . '/' . $questionFile);
118
+                            $resourcesLinks = qtiProcessManifest($baseWorkDir.'/'.$file.'/'.$questionFile);
119 119
                         }
120 120
                     }
121 121
                 }
122 122
             }
123 123
         } elseif (preg_match('/.xml$/i', $file)) {
124
-            $isQti = isQtiQuestionBank($baseWorkDir . '/' . $file);
124
+            $isQti = isQtiQuestionBank($baseWorkDir.'/'.$file);
125 125
             if ($isQti) {
126 126
                 $result = qti_parse_file($baseWorkDir, '', $file);
127
-                $filePath = $baseWorkDir . '/' . $file;
127
+                $filePath = $baseWorkDir.'/'.$file;
128 128
                 $file_found = true;
129 129
             } else {
130
-                $isManifest = isQtiManifest($baseWorkDir . '/' . $file);
130
+                $isManifest = isQtiManifest($baseWorkDir.'/'.$file);
131 131
                 if ($isManifest) {
132
-                    $resourcesLinks = qtiProcessManifest($baseWorkDir . '/' . $file);
132
+                    $resourcesLinks = qtiProcessManifest($baseWorkDir.'/'.$file);
133 133
                 }
134 134
             }
135 135
 
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
             $question->type = $question_array['type'];
164 164
             $question->setAnswer();
165 165
             if (strlen($question_array['title']) < 50) {
166
-                $question->updateTitle(formatText(strip_tags($question_array['title'])) . '...');
166
+                $question->updateTitle(formatText(strip_tags($question_array['title'])).'...');
167 167
             } else {
168 168
                 $question->updateTitle(formatText(substr(strip_tags($question_array['title']), 0, 50)));
169 169
                 $question->updateDescription($question_array['title']);
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
         }
210 210
 
211 211
         // delete the temp dir where the exercise was unzipped
212
-        my_delete($baseWorkDir . $uploadPath);
212
+        my_delete($baseWorkDir.$uploadPath);
213 213
         return $last_exercise_id;
214 214
     }
215 215
 
@@ -237,8 +237,8 @@  discard block
 block discarded – undo
237 237
     global $record_item_body;
238 238
     global $questionTempDir;
239 239
 
240
-    $questionTempDir = $exercisePath . '/' . $file . '/';
241
-    $questionFilePath = $questionTempDir . $questionFile;
240
+    $questionTempDir = $exercisePath.'/'.$file.'/';
241
+    $questionFilePath = $questionTempDir.$questionFile;
242 242
 
243 243
     if (!($fp = fopen($questionFilePath, 'r'))) {
244 244
         Display::addFlash(Display::return_message(get_lang('Error opening question\'s XML file'), 'error'));
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
         $error = xml_get_error_code();
294 294
         Display::addFlash(
295 295
             Display::return_message(
296
-                get_lang('Error reading XML file') . sprintf('[%d:%d]', xml_get_current_line_number($xml_parser), xml_get_current_column_number($xml_parser)),
296
+                get_lang('Error reading XML file').sprintf('[%d:%d]', xml_get_current_line_number($xml_parser), xml_get_current_column_number($xml_parser)),
297 297
                 'error'
298 298
             )
299 299
         );
@@ -359,9 +359,9 @@  discard block
 block discarded – undo
359 359
     if ($record_item_body) {
360 360
 
361 361
         if ((!in_array($current_element, $non_HTML_tag_to_avoid))) {
362
-            $current_question_item_body .= "<" . $name;
362
+            $current_question_item_body .= "<".$name;
363 363
             foreach ($attributes as $attribute_name => $attribute_value) {
364
-                $current_question_item_body .= " " . $attribute_name . "=\"" . $attribute_value . "\"";
364
+                $current_question_item_body .= " ".$attribute_name."=\"".$attribute_value."\"";
365 365
             }
366 366
             $current_question_item_body .= ">";
367 367
         } else {
@@ -369,11 +369,11 @@  discard block
 block discarded – undo
369 369
             //we first save with claroline tags ,then when the answer will be parsed, the claroline tags will be replaced
370 370
 
371 371
             if ($current_element == 'INLINECHOICEINTERACTION') {
372
-                $current_question_item_body .= "**claroline_start**" . $attributes['RESPONSEIDENTIFIER'] . "**claroline_end**";
372
+                $current_question_item_body .= "**claroline_start**".$attributes['RESPONSEIDENTIFIER']."**claroline_end**";
373 373
             }
374 374
             if ($current_element == 'TEXTENTRYINTERACTION') {
375 375
                 $correct_answer_value = $exercise_info['question'][$current_question_ident]['correct_answers'][$current_answer_id];
376
-                $current_question_item_body .= "[" . $correct_answer_value . "]";
376
+                $current_question_item_body .= "[".$correct_answer_value."]";
377 377
 
378 378
             }
379 379
             if ($current_element == 'BR') {
@@ -490,7 +490,7 @@  discard block
 block discarded – undo
490 490
     //treat the record of the full content of itembody tag :
491 491
 
492 492
     if ($record_item_body && (!in_array($current_element, $non_HTML_tag_to_avoid))) {
493
-        $current_question_item_body .= "</" . $name . ">";
493
+        $current_question_item_body .= "</".$name.">";
494 494
     }
495 495
 
496 496
     switch ($name) {
@@ -548,14 +548,14 @@  discard block
 block discarded – undo
548 548
             if (!isset ($exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['value'])) {
549 549
                 $exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['value'] = trim($data);
550 550
             } else {
551
-                $exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['value'] .= '' . trim($data);
551
+                $exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['value'] .= ''.trim($data);
552 552
             }
553 553
             break;
554 554
         case 'FEEDBACKINLINE':
555 555
             if (!isset ($exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['feedback'])) {
556 556
                 $exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['feedback'] = trim($data);
557 557
             } else {
558
-                $exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['feedback'] .= ' ' . trim($data);
558
+                $exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['feedback'] .= ' '.trim($data);
559 559
             }
560 560
             break;
561 561
         case 'SIMPLEASSOCIABLECHOICE':
@@ -572,7 +572,7 @@  discard block
 block discarded – undo
572 572
             break;
573 573
         case 'ITEMBODY':
574 574
             foreach ($resourcesLinks['manifest'] as $key=>$value) {
575
-                $data = preg_replace('|' . $value . '|', $resourcesLinks['web'][$key], $data);
575
+                $data = preg_replace('|'.$value.'|', $resourcesLinks['web'][$key], $data);
576 576
             }
577 577
             $current_question_item_body .= $data;
578 578
             break;
@@ -581,8 +581,8 @@  discard block
 block discarded – undo
581 581
             $answer_identifier = $exercise_info['question'][$current_question_ident]['correct_answers'][$current_answer_id];
582 582
             if ($current_inlinechoice_id == $answer_identifier) {
583 583
                 $current_question_item_body = str_replace(
584
-                    "**claroline_start**" . $current_answer_id . "**claroline_end**",
585
-                    "[" . $data . "]",
584
+                    "**claroline_start**".$current_answer_id."**claroline_end**",
585
+                    "[".$data."]",
586 586
                     $current_question_item_body
587 587
                 );
588 588
             } else {
@@ -641,9 +641,9 @@  discard block
 block discarded – undo
641 641
     if ($record_item_body) {
642 642
 
643 643
         if ((!in_array($current_element, $non_HTML_tag_to_avoid))) {
644
-            $current_question_item_body .= "<" . $name;
644
+            $current_question_item_body .= "<".$name;
645 645
             foreach ($attributes as $attribute_name => $attribute_value) {
646
-                $current_question_item_body .= " " . $attribute_name . "=\"" . $attribute_value . "\"";
646
+                $current_question_item_body .= " ".$attribute_name."=\"".$attribute_value."\"";
647 647
             }
648 648
             $current_question_item_body .= ">";
649 649
         } else {
@@ -651,11 +651,11 @@  discard block
 block discarded – undo
651 651
             //we first save with claroline tags ,then when the answer will be parsed, the claroline tags will be replaced
652 652
 
653 653
             if ($current_element == 'INLINECHOICEINTERACTION') {
654
-                $current_question_item_body .= "**claroline_start**" . $attributes['RESPONSEIDENTIFIER'] . "**claroline_end**";
654
+                $current_question_item_body .= "**claroline_start**".$attributes['RESPONSEIDENTIFIER']."**claroline_end**";
655 655
             }
656 656
             if ($current_element == 'TEXTENTRYINTERACTION') {
657 657
                 $correct_answer_value = $exercise_info['question'][$current_question_ident]['correct_answers'][$current_answer_id];
658
-                $current_question_item_body .= "[" . $correct_answer_value . "]";
658
+                $current_question_item_body .= "[".$correct_answer_value."]";
659 659
 
660 660
             }
661 661
             if ($current_element == 'BR') {
@@ -774,7 +774,7 @@  discard block
 block discarded – undo
774 774
     //treat the record of the full content of itembody tag :
775 775
 
776 776
     if ($record_item_body && (!in_array($current_element, $non_HTML_tag_to_avoid))) {
777
-        $current_question_item_body .= "</" . $name . ">";
777
+        $current_question_item_body .= "</".$name.">";
778 778
     }
779 779
 
780 780
     switch ($name) {
@@ -886,7 +886,7 @@  discard block
 block discarded – undo
886 886
             break;
887 887
         case 'MATTEXT':
888 888
             foreach ($resourcesLinks['manifest'] as $key=>$value) {
889
-                $data = preg_replace('|' . $value . '|', $resourcesLinks['web'][$key], $data);
889
+                $data = preg_replace('|'.$value.'|', $resourcesLinks['web'][$key], $data);
890 890
             }
891 891
             if (!empty($current_question_item_body)) {
892 892
                 $current_question_item_body .= $data;
@@ -959,9 +959,9 @@  discard block
 block discarded – undo
959 959
     $sessionId = api_get_session_id();
960 960
     $courseDir = $course['path'];
961 961
     $sysPath = api_get_path(SYS_COURSE_PATH);
962
-    $exercisesSysPath = $sysPath . $courseDir . '/document/';
962
+    $exercisesSysPath = $sysPath.$courseDir.'/document/';
963 963
     $webPath = api_get_path(WEB_CODE_PATH);
964
-    $exercisesWebPath = $webPath . 'document/document.php?' . api_get_cidreq() . '&action=download&id=';
964
+    $exercisesWebPath = $webPath.'document/document.php?'.api_get_cidreq().'&action=download&id=';
965 965
     $links = array(
966 966
         'manifest' => array(),
967 967
         'system' => array(),
@@ -969,7 +969,7 @@  discard block
 block discarded – undo
969 969
     );
970 970
     $tableDocuments = Database::get_course_table(TABLE_DOCUMENT);
971 971
     $countResources = count($xml->resources->resource->file);
972
-    for ($i=0; $i < $countResources; $i++) {
972
+    for ($i = 0; $i < $countResources; $i++) {
973 973
         $file = $xml->resources->resource->file[$i];
974 974
         $href = '';
975 975
         foreach ($file->attributes() as $key => $value) {
@@ -981,17 +981,17 @@  discard block
 block discarded – undo
981 981
         }
982 982
         if (!empty($href)) {
983 983
             $links['manifest'][] = (string) $href;
984
-            $links['system'][] = $exercisesSysPath . strtolower($href);
984
+            $links['system'][] = $exercisesSysPath.strtolower($href);
985 985
             $specialHref = Database::escape_string(preg_replace('/_/', '-', strtolower($href)));
986 986
             $specialHref = preg_replace('/(-){2,8}/', '-', $specialHref);
987 987
 
988
-            $sql = "SELECT iid FROM " . $tableDocuments . " WHERE c_id = " . $course['real_id'] . " AND session_id = $sessionId AND path = '/" . $specialHref . "'";
988
+            $sql = "SELECT iid FROM ".$tableDocuments." WHERE c_id = ".$course['real_id']." AND session_id = $sessionId AND path = '/".$specialHref."'";
989 989
             $result = Database::query($sql);
990 990
             $documentId = 0;
991 991
             while ($row = Database::fetch_assoc($result)) {
992 992
                 $documentId = $row['iid'];
993 993
             }
994
-            $links['web'][] = $exercisesWebPath . $documentId;
994
+            $links['web'][] = $exercisesWebPath.$documentId;
995 995
         }
996 996
     }
997 997
     return $links;
Please login to merge, or discard this patch.