Completed
Push — 1.10.x ( 9d8f25...0ad4ea )
by Angel Fernando Quiroz
80:30 queued 40:12
created
main/exercice/export/aiken/aiken_classes.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -11,12 +11,12 @@  discard block
 block discarded – undo
11 11
 
12 12
 if (!function_exists('mime_content_type')) {
13 13
 
14
-	/**
15
-	 * @param string $filename
16
-	 */
17
-	function mime_content_type($filename) {
18
-		return DocumentManager::file_get_mime_type((string)$filename);
19
-	}
14
+    /**
15
+     * @param string $filename
16
+     */
17
+    function mime_content_type($filename) {
18
+        return DocumentManager::file_get_mime_type((string)$filename);
19
+    }
20 20
 }
21 21
 
22 22
 /**
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
         {
34 34
             case MCUA :
35 35
                 $answer = new AikenAnswerMultipleChoice($this->id);
36
-            	return $answer;
36
+                return $answer;
37 37
             default :
38 38
                 $answer = null;
39 39
                 break;
@@ -42,11 +42,11 @@  discard block
 block discarded – undo
42 42
     }
43 43
     function createAnswersForm($form)
44 44
     {
45
-    	return true;
45
+        return true;
46 46
     }
47 47
     function processAnswersCreation($form)
48 48
     {
49
-    	return true;
49
+        return true;
50 50
     }
51 51
 }
52 52
 
Please login to merge, or discard this patch.
main/exercice/export/qti2/qti2_export.php 1 patch
Indentation   +159 added lines, -159 removed lines patch added patch discarded remove patch
@@ -34,21 +34,21 @@  discard block
 block discarded – undo
34 34
      *
35 35
      * @param Ims2Question $question Ims2Question object we want to export.
36 36
      */
37
-     function ImsAssessmentItem($question)
38
-     {
37
+        function ImsAssessmentItem($question)
38
+        {
39 39
         $this->question = $question;
40 40
         $this->answer = $this->question->setAnswer();
41 41
         $this->questionIdent = "QST_" . $question->id ;
42
-     }
43
-
44
-     /**
45
-      * Start the XML flow.
46
-      *
47
-      * This opens the <item> block, with correct attributes.
48
-      *
49
-      */
50
-      function start_item()
51
-      {
42
+        }
43
+
44
+        /**
45
+         * Start the XML flow.
46
+         *
47
+         * This opens the <item> block, with correct attributes.
48
+         *
49
+         */
50
+        function start_item()
51
+        {
52 52
         $string = '<assessmentItem xmlns="http://www.imsglobal.org/xsd/imsqti_v2p1"
53 53
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
54 54
                     xsi:schemaLocation="http://www.imsglobal.org/xsd/imsqti_v2p1 imsqti_v2p1.xsd"
@@ -56,55 +56,55 @@  discard block
 block discarded – undo
56 56
                     title="'.htmlspecialchars(formatExerciseQtiTitle($this->question->selectTitle())).'">'."\n";
57 57
 
58 58
         return $string;
59
-      }
60
-
61
-      /**
62
-       * End the XML flow, closing the </item> tag.
63
-       *
64
-       */
65
-      function end_item()
66
-      {
59
+        }
60
+
61
+        /**
62
+         * End the XML flow, closing the </item> tag.
63
+         *
64
+         */
65
+        function end_item()
66
+        {
67 67
         return "</assessmentItem>\n";
68
-      }
69
-
70
-     /**
71
-      * Start the itemBody
72
-      *
73
-      */
74
-     function start_item_body()
75
-     {
68
+        }
69
+
70
+        /**
71
+         * Start the itemBody
72
+         *
73
+         */
74
+        function start_item_body()
75
+        {
76 76
         return '  <itemBody>' . "\n";
77
-     }
78
-
79
-     /**
80
-      * End the itemBody part.
81
-      *
82
-      */
83
-     function end_item_body()
84
-     {
77
+        }
78
+
79
+        /**
80
+         * End the itemBody part.
81
+         *
82
+         */
83
+        function end_item_body()
84
+        {
85 85
         return "  </itemBody>\n";
86
-     }
87
-
88
-     /**
89
-      * add the response processing template used.
90
-      *
91
-      */
92
-
93
-      function add_response_processing()
94
-      {
95
-          return '  <responseProcessing template="http://www.imsglobal.org/question/qti_v2p1/rptemplates/map_correct"/>' . "\n";
96
-      }
97
-
98
-     /**
99
-      * Export the question as an IMS/QTI Item.
100
-      *
101
-      * This is a default behaviour, some classes may want to override this.
102
-      *
103
-      * @param $standalone: Boolean stating if it should be exported as a stand-alone question
104
-      * @return string string, the XML flow for an Item.
105
-      */
106
-     function export($standalone = false)
107
-     {
86
+        }
87
+
88
+        /**
89
+         * add the response processing template used.
90
+         *
91
+         */
92
+
93
+        function add_response_processing()
94
+        {
95
+            return '  <responseProcessing template="http://www.imsglobal.org/question/qti_v2p1/rptemplates/map_correct"/>' . "\n";
96
+        }
97
+
98
+        /**
99
+         * Export the question as an IMS/QTI Item.
100
+         *
101
+         * This is a default behaviour, some classes may want to override this.
102
+         *
103
+         * @param $standalone: Boolean stating if it should be exported as a stand-alone question
104
+         * @return string string, the XML flow for an Item.
105
+         */
106
+        function export($standalone = false)
107
+        {
108 108
         $head = $foot = "";
109 109
 
110 110
         if ($standalone) {
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
             .$foot;
132 132
 
133 133
         return $res;
134
-     }
134
+        }
135 135
 }
136 136
 
137 137
 /**
@@ -193,8 +193,8 @@  discard block
 block discarded – undo
193 193
     function export_presentation()
194 194
     {
195 195
         $out = "<presentation_material><flow_mat><material>\n"
196
-             . "  <mattext><![CDATA[" . formatExerciseQtiDescription($this->exercise->selectDescription()) . "]]></mattext>\n"
197
-             . "</material></flow_mat></presentation_material>\n";
196
+                . "  <mattext><![CDATA[" . formatExerciseQtiDescription($this->exercise->selectDescription()) . "]]></mattext>\n"
197
+                . "</material></flow_mat></presentation_material>\n";
198 198
         return $out;
199 199
     }
200 200
 
@@ -208,15 +208,15 @@  discard block
 block discarded – undo
208 208
         $out = '';
209 209
         if ($n = $this->exercise->getShuffle()) {
210 210
             $out.= "<selection_ordering>"
211
-                 . "  <selection>\n"
212
-                 . "    <selection_number>" . $n . "</selection_number>\n"
213
-                 . "  </selection>\n"
214
-                 . '  <order order_type="Random" />'
215
-                 . "\n</selection_ordering>\n";
211
+                    . "  <selection>\n"
212
+                    . "    <selection_number>" . $n . "</selection_number>\n"
213
+                    . "  </selection>\n"
214
+                    . '  <order order_type="Random" />'
215
+                    . "\n</selection_ordering>\n";
216 216
         } else {
217 217
             $out.= '<selection_ordering sequence_type="Normal">' . "\n"
218
-                 . "  <selection />\n"
219
-                 . "</selection_ordering>\n";
218
+                    . "  <selection />\n"
219
+                    . "</selection_ordering>\n";
220 220
         }
221 221
 
222 222
         return $out;
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
     {
231 231
         $out = "";
232 232
         foreach ($this->exercise->selectQuestionList() as $q) {
233
-        	$out .= export_question_qti($q, false);
233
+            $out .= export_question_qti($q, false);
234 234
         }
235 235
         return $out;
236 236
     }
@@ -247,18 +247,18 @@  discard block
 block discarded – undo
247 247
         $head = $foot = "";
248 248
         if ($standalone) {
249 249
             $head = '<?xml version = "1.0" encoding = "UTF-8" standalone = "no"?>' . "\n"
250
-                  . '<!DOCTYPE questestinterop SYSTEM "ims_qtiasiv2p1.dtd">' . "\n"
251
-                  . "<questestinterop>\n";
250
+                    . '<!DOCTYPE questestinterop SYSTEM "ims_qtiasiv2p1.dtd">' . "\n"
251
+                    . "<questestinterop>\n";
252 252
             $foot = "</questestinterop>\n";
253 253
         }
254 254
         $out = $head
255
-             . $this->start_section()
256
-             . $this->export_duration()
257
-             . $this->export_presentation()
258
-             . $this->export_ordering()
259
-             . $this->export_questions()
260
-             . $this->end_section()
261
-             . $foot;
255
+                . $this->start_section()
256
+                . $this->export_duration()
257
+                . $this->export_presentation()
258
+                . $this->export_ordering()
259
+                . $this->export_questions()
260
+                . $this->end_section()
261
+                . $foot;
262 262
 
263 263
         return $out;
264 264
     }
@@ -304,97 +304,97 @@  discard block
 block discarded – undo
304 304
      * @param $question The Question object we want to export.
305 305
      * @author Anamd Tihon
306 306
      */
307
-     function ImsItem($question)
308
-     {
307
+        function ImsItem($question)
308
+        {
309 309
         $this->question = $question;
310 310
         $this->answer = $question->answer;
311 311
         $this->questionIdent = "QST_" . $question->selectId() ;
312
-     }
313
-
314
-     /**
315
-      * Start the XML flow.
316
-      *
317
-      * This opens the <item> block, with correct attributes.
318
-      *
319
-      * @author Amand Tihon <[email protected]>
320
-      */
321
-      function start_item()
322
-      {
312
+        }
313
+
314
+        /**
315
+         * Start the XML flow.
316
+         *
317
+         * This opens the <item> block, with correct attributes.
318
+         *
319
+         * @author Amand Tihon <[email protected]>
320
+         */
321
+        function start_item()
322
+        {
323 323
         return '<item title="' . cleanAttribute(formatExerciseQtiDescription($this->question->selectTitle())) . '" ident="' . $this->questionIdent . '">' . "\n";
324
-      }
325
-
326
-      /**
327
-       * End the XML flow, closing the </item> tag.
328
-       *
329
-       * @author Amand Tihon <[email protected]>
330
-       */
331
-      function end_item()
332
-      {
324
+        }
325
+
326
+        /**
327
+         * End the XML flow, closing the </item> tag.
328
+         *
329
+         * @author Amand Tihon <[email protected]>
330
+         */
331
+        function end_item()
332
+        {
333 333
         return "</item>\n";
334
-      }
335
-
336
-     /**
337
-      * Create the opening, with the question itself.
338
-      *
339
-      * This means it opens the <presentation> but doesn't close it, as this is the role of end_presentation().
340
-      * In between, the export_responses from the subclass should have been called.
341
-      *
342
-      * @author Amand Tihon <[email protected]>
343
-      */
344
-     function start_presentation()
345
-     {
334
+        }
335
+
336
+        /**
337
+         * Create the opening, with the question itself.
338
+         *
339
+         * This means it opens the <presentation> but doesn't close it, as this is the role of end_presentation().
340
+         * In between, the export_responses from the subclass should have been called.
341
+         *
342
+         * @author Amand Tihon <[email protected]>
343
+         */
344
+        function start_presentation()
345
+        {
346 346
         return '<presentation label="' . $this->questionIdent . '"><flow>' . "\n"
347
-             . '<material><mattext>' . formatExerciseQtiDescription($this->question->selectDescription()) . "</mattext></material>\n";
348
-     }
349
-
350
-     /**
351
-      * End the </presentation> part, opened by export_header.
352
-      *
353
-      * @author Amand Tihon <[email protected]>
354
-      */
355
-     function end_presentation()
356
-     {
347
+                . '<material><mattext>' . formatExerciseQtiDescription($this->question->selectDescription()) . "</mattext></material>\n";
348
+        }
349
+
350
+        /**
351
+         * End the </presentation> part, opened by export_header.
352
+         *
353
+         * @author Amand Tihon <[email protected]>
354
+         */
355
+        function end_presentation()
356
+        {
357 357
         return "</flow></presentation>\n";
358
-     }
359
-
360
-     /**
361
-      * Start the response processing, and declare the default variable, SCORE, at 0 in the outcomes.
362
-      *
363
-      * @author Amand Tihon <[email protected]>
364
-      */
365
-     function start_processing()
366
-     {
358
+        }
359
+
360
+        /**
361
+         * Start the response processing, and declare the default variable, SCORE, at 0 in the outcomes.
362
+         *
363
+         * @author Amand Tihon <[email protected]>
364
+         */
365
+        function start_processing()
366
+        {
367 367
         return '<resprocessing><outcomes><decvar vartype="Integer" defaultval="0" /></outcomes>' . "\n";
368
-     }
369
-
370
-     /**
371
-      * End the response processing part.
372
-      *
373
-      * @author Amand Tihon <[email protected]>
374
-      */
375
-     function end_processing()
376
-     {
368
+        }
369
+
370
+        /**
371
+         * End the response processing part.
372
+         *
373
+         * @author Amand Tihon <[email protected]>
374
+         */
375
+        function end_processing()
376
+        {
377 377
         return "</resprocessing>\n";
378
-     }
379
-
380
-     /**
381
-      * Export the question as an IMS/QTI Item.
382
-      *
383
-      * This is a default behaviour, some classes may want to override this.
384
-      *
385
-      * @param $standalone: Boolean stating if it should be exported as a stand-alone question
386
-      * @return string string, the XML flow for an Item.
387
-      * @author Amand Tihon <[email protected]>
388
-      */
389
-     function export($standalone = False)
390
-     {
378
+        }
379
+
380
+        /**
381
+         * Export the question as an IMS/QTI Item.
382
+         *
383
+         * This is a default behaviour, some classes may want to override this.
384
+         *
385
+         * @param $standalone: Boolean stating if it should be exported as a stand-alone question
386
+         * @return string string, the XML flow for an Item.
387
+         * @author Amand Tihon <[email protected]>
388
+         */
389
+        function export($standalone = False)
390
+        {
391 391
         global $charset;
392 392
         $head = $foot = "";
393 393
 
394 394
         if ($standalone) {
395 395
             $head = '<?xml version = "1.0" encoding = "'.$charset.'" standalone = "no"?>' . "\n"
396
-                  . '<!DOCTYPE questestinterop SYSTEM "ims_qtiasiv2p1.dtd">' . "\n"
397
-                  . "<questestinterop>\n";
396
+                    . '<!DOCTYPE questestinterop SYSTEM "ims_qtiasiv2p1.dtd">' . "\n"
397
+                    . "<questestinterop>\n";
398 398
             $foot = "</questestinterop>\n";
399 399
         }
400 400
 
@@ -409,7 +409,7 @@  discard block
 block discarded – undo
409 409
             . $this->answer->imsExportFeedback($this->questionIdent)
410 410
             . $this->end_item()
411 411
             . $foot;
412
-     }
412
+        }
413 413
 }
414 414
 
415 415
 /**
@@ -447,9 +447,9 @@  discard block
 block discarded – undo
447 447
     $question->type = $qst->type;
448 448
     $question->question = $qst->question;
449 449
     $question->description = $qst->description;
450
-	$question->weighting=$qst->weighting;
451
-	$question->position=$qst->position;
452
-	$question->picture=$qst->picture;
450
+    $question->weighting=$qst->weighting;
451
+    $question->position=$qst->position;
452
+    $question->picture=$qst->picture;
453 453
     $ims = new ImsAssessmentItem($question);
454 454
 
455 455
     return $ims->export($standalone);
Please login to merge, or discard this patch.
main/exercice/hotpotatoes_exercise_result.class.php 1 patch
Indentation   +137 added lines, -137 removed lines patch added patch discarded remove patch
@@ -14,15 +14,15 @@  discard block
 block discarded – undo
14 14
     //stores the results
15 15
     private $results = array();
16 16
 
17
-	/**
18
-	 * Gets the results of all students (or just one student if access is limited)
19
-	 * @param	string		The document path (for HotPotatoes retrieval)
20
-	 * @param	integer		User ID. Optional. If no user ID is provided, we take all the results. Defauts to null
21
-	 * @param string $document_path
22
-	 */
23
-	public function getExercisesReporting($document_path, $hotpotato_name)
17
+    /**
18
+     * Gets the results of all students (or just one student if access is limited)
19
+     * @param	string		The document path (for HotPotatoes retrieval)
20
+     * @param	integer		User ID. Optional. If no user ID is provided, we take all the results. Defauts to null
21
+     * @param string $document_path
22
+     */
23
+    public function getExercisesReporting($document_path, $hotpotato_name)
24 24
     {
25
-		$return = array();
25
+        $return = array();
26 26
         $TBL_USER = Database::get_main_table(TABLE_MAIN_USER);
27 27
         $TBL_TRACK_HOTPOTATOES	= Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
28 28
 
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
         $hotpotato_name  = Database::escape_string($hotpotato_name);
35 35
 
36 36
         if (!empty($exercise_id)) {
37
-          $session_id_and .= " AND exe_exo_id = $exercise_id ";
37
+            $session_id_and .= " AND exe_exo_id = $exercise_id ";
38 38
         }
39 39
 
40 40
         if (empty($user_id)) {
@@ -111,25 +111,25 @@  discard block
 block discarded – undo
111 111
         $this->results = $return;
112 112
 
113 113
         return true;
114
-	}
114
+    }
115 115
 
116 116
 
117
-	/**
118
-	 * Exports the complete report as a CSV file
119
-	 * @param	string		Document path inside the document tool
120
-	 * @param	integer		Optional user ID
121
-	 * @param	boolean		Whether to include user fields or not
122
-	 * @return	boolean		False on error
123
-	 */
124
-	public function exportCompleteReportCSV($document_path='', $hotpotato_name)
117
+    /**
118
+     * Exports the complete report as a CSV file
119
+     * @param	string		Document path inside the document tool
120
+     * @param	integer		Optional user ID
121
+     * @param	boolean		Whether to include user fields or not
122
+     * @return	boolean		False on error
123
+     */
124
+    public function exportCompleteReportCSV($document_path='', $hotpotato_name)
125 125
     {
126
-		global $charset;
127
-		$this->getExercisesReporting($document_path, $hotpotato_name);
128
-		$filename = 'exercise_results_'.date('YmdGis').'.csv';
129
-		if (!empty($user_id)) {
130
-			$filename = 'exercise_results_user_'.$user_id.'_'.date('YmdGis').'.csv';
131
-		}
132
-		$data = '';
126
+        global $charset;
127
+        $this->getExercisesReporting($document_path, $hotpotato_name);
128
+        $filename = 'exercise_results_'.date('YmdGis').'.csv';
129
+        if (!empty($user_id)) {
130
+            $filename = 'exercise_results_user_'.$user_id.'_'.date('YmdGis').'.csv';
131
+        }
132
+        $data = '';
133 133
 
134 134
         if (api_is_western_name_order()) {
135 135
             if(!empty($this->results[0]['first_name'])) {
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
         }
149 149
         $data .= get_lang('Email').';';
150 150
 
151
-		/*if ($export_user_fields) {
151
+        /*if ($export_user_fields) {
152 152
 			//show user fields section with a big th colspan that spans over all fields
153 153
 			$extra_user_fields = UserManager::get_extra_fields(0,1000,5,'ASC',false, 1);
154 154
 			$num = count($extra_user_fields);
@@ -157,25 +157,25 @@  discard block
 block discarded – undo
157 157
 			}
158 158
 		}*/
159 159
 
160
-		$data .= get_lang('Title').';';
161
-		$data .= get_lang('StartDate').';';
162
-		$data .= get_lang('Score').';';
163
-		$data .= get_lang('Total').';';
164
-		$data .= "\n";
160
+        $data .= get_lang('Title').';';
161
+        $data .= get_lang('StartDate').';';
162
+        $data .= get_lang('Score').';';
163
+        $data .= get_lang('Total').';';
164
+        $data .= "\n";
165 165
 
166
-		//results
167
-		foreach($this->results as $row) {
166
+        //results
167
+        foreach($this->results as $row) {
168 168
             if (api_is_western_name_order()) {
169
-              $data .= str_replace("\r\n",'  ',api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset)).';';
170
-              $data .= str_replace("\r\n",'  ',api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset)).';';
169
+                $data .= str_replace("\r\n",'  ',api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset)).';';
170
+                $data .= str_replace("\r\n",'  ',api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset)).';';
171 171
             } else {
172
-              $data .= str_replace("\r\n",'  ',api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset)).';';
173
-              $data .= str_replace("\r\n",'  ',api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset)).';';
172
+                $data .= str_replace("\r\n",'  ',api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset)).';';
173
+                $data .= str_replace("\r\n",'  ',api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset)).';';
174 174
             }
175 175
 
176 176
             $data .= str_replace("\r\n",'  ',api_html_entity_decode(strip_tags($row['email']), ENT_QUOTES, $charset)).';';
177 177
 
178
-			/*if ($export_user_fields) {
178
+            /*if ($export_user_fields) {
179 179
 				//show user fields data, if any, for this user
180 180
 				$user_fields_values = UserManager::get_extra_user_data($row['user_id'],false,false, false, true);
181 181
 				foreach($user_fields_values as $value) {
@@ -183,40 +183,40 @@  discard block
 block discarded – undo
183 183
 				}
184 184
 			}*/
185 185
 
186
-			$data .= str_replace("\r\n",'  ',api_html_entity_decode(strip_tags($row['title']), ENT_QUOTES, $charset)).';';
187
-			$data .= str_replace("\r\n",'  ',$row['exe_date']).';';
188
-			$data .= str_replace("\r\n",'  ',$row['result']).';';
189
-			$data .= str_replace("\r\n",'  ',$row['max']).';';
190
-			$data .= "\n";
191
-		}
192
-
193
-		//output the results
194
-		$len = strlen($data);
195
-		header('Content-type: application/octet-stream');
196
-		header('Content-Type: application/force-download');
197
-		header('Content-length: '.$len);
198
-		if (preg_match("/MSIE 5.5/", $_SERVER['HTTP_USER_AGENT'])) {
199
-			header('Content-Disposition: filename= '.$filename);
200
-		} else {
201
-			header('Content-Disposition: attachment; filename= '.$filename);
202
-		}
203
-		if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
204
-			header('Pragma: ');
205
-			header('Cache-Control: ');
206
-			header('Cache-Control: public'); // IE cannot download from sessions without a cache
207
-		}
208
-		header('Content-Description: '.$filename);
209
-		header('Content-transfer-encoding: binary');
210
-		// @todo add this utf-8 header for all csv files
211
-		echo "\xEF\xBB\xBF";  // force utf-8 header of csv file
212
-		echo $data;
213
-		return true;
214
-	}
215
-
216
-	/**
217
-	 * Exports the complete report as an XLS file
218
-	 * @return	boolean		False on error
219
-	 */
186
+            $data .= str_replace("\r\n",'  ',api_html_entity_decode(strip_tags($row['title']), ENT_QUOTES, $charset)).';';
187
+            $data .= str_replace("\r\n",'  ',$row['exe_date']).';';
188
+            $data .= str_replace("\r\n",'  ',$row['result']).';';
189
+            $data .= str_replace("\r\n",'  ',$row['max']).';';
190
+            $data .= "\n";
191
+        }
192
+
193
+        //output the results
194
+        $len = strlen($data);
195
+        header('Content-type: application/octet-stream');
196
+        header('Content-Type: application/force-download');
197
+        header('Content-length: '.$len);
198
+        if (preg_match("/MSIE 5.5/", $_SERVER['HTTP_USER_AGENT'])) {
199
+            header('Content-Disposition: filename= '.$filename);
200
+        } else {
201
+            header('Content-Disposition: attachment; filename= '.$filename);
202
+        }
203
+        if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
204
+            header('Pragma: ');
205
+            header('Cache-Control: ');
206
+            header('Cache-Control: public'); // IE cannot download from sessions without a cache
207
+        }
208
+        header('Content-Description: '.$filename);
209
+        header('Content-transfer-encoding: binary');
210
+        // @todo add this utf-8 header for all csv files
211
+        echo "\xEF\xBB\xBF";  // force utf-8 header of csv file
212
+        echo $data;
213
+        return true;
214
+    }
215
+
216
+    /**
217
+     * Exports the complete report as an XLS file
218
+     * @return	boolean		False on error
219
+     */
220 220
     public function exportCompleteReportXLS(
221 221
         $document_path = '',
222 222
         $user_id = null,
@@ -225,37 +225,37 @@  discard block
 block discarded – undo
225 225
         $exercise_id = 0,
226 226
         $hotpotato_name = null
227 227
     ) {
228
-		global $charset;
229
-		$this->getExercisesReporting($document_path, $user_id, $export_filter, $exercise_id, $hotpotato_name);
230
-		$filename = 'exercise_results_'.api_get_local_time().'.xls';
231
-		if (!empty($user_id)) {
232
-			$filename = 'exercise_results_user_'.$user_id.'_'.api_get_local_time().'.xls';
233
-		}
228
+        global $charset;
229
+        $this->getExercisesReporting($document_path, $user_id, $export_filter, $exercise_id, $hotpotato_name);
230
+        $filename = 'exercise_results_'.api_get_local_time().'.xls';
231
+        if (!empty($user_id)) {
232
+            $filename = 'exercise_results_user_'.$user_id.'_'.api_get_local_time().'.xls';
233
+        }
234 234
 
235 235
         $spreadsheet = new PHPExcel();
236 236
         $spreadsheet->setActiveSheetIndex(0);
237 237
         $worksheet = $spreadsheet->getActiveSheet();
238 238
 
239 239
 
240
-		$line = 0;
241
-		$column = 0; //skip the first column (row titles)
240
+        $line = 0;
241
+        $column = 0; //skip the first column (row titles)
242 242
 
243
-		// check if exists column 'user'
244
-		$with_column_user = false;
245
-		foreach ($this->results as $result) {
246
-			if (!empty($result['last_name']) && !empty($result['first_name'])) {
247
-				$with_column_user = true;
248
-				break;
249
-			}
250
-		}
243
+        // check if exists column 'user'
244
+        $with_column_user = false;
245
+        foreach ($this->results as $result) {
246
+            if (!empty($result['last_name']) && !empty($result['first_name'])) {
247
+                $with_column_user = true;
248
+                break;
249
+            }
250
+        }
251 251
 
252
-		if ($with_column_user) {
253
-		    $worksheet->SetCellValueByColumnAndRow($line,$column,get_lang('Email'));
254
-		    $column++;
252
+        if ($with_column_user) {
253
+            $worksheet->SetCellValueByColumnAndRow($line,$column,get_lang('Email'));
254
+            $column++;
255 255
 
256 256
             if (api_is_western_name_order()) {
257
-    			$worksheet->SetCellValueByColumnAndRow($line,$column,get_lang('FirstName'));
258
-    			$column++;
257
+                $worksheet->SetCellValueByColumnAndRow($line,$column,get_lang('FirstName'));
258
+                $column++;
259 259
                 $worksheet->SetCellValueByColumnAndRow($line,$column,get_lang('LastName'));
260 260
                 $column++;
261 261
             } else {
@@ -264,36 +264,36 @@  discard block
 block discarded – undo
264 264
                 $worksheet->SetCellValueByColumnAndRow($line,$column,get_lang('FirstName'));
265 265
                 $column++;
266 266
             }
267
-		}
267
+        }
268 268
 
269
-		if ($export_user_fields) {
270
-			//show user fields section with a big th colspan that spans over all fields
271
-			$extra_user_fields = UserManager::get_extra_fields(0,1000,5,'ASC',false, 1);
269
+        if ($export_user_fields) {
270
+            //show user fields section with a big th colspan that spans over all fields
271
+            $extra_user_fields = UserManager::get_extra_fields(0,1000,5,'ASC',false, 1);
272 272
 
273
-			//show the fields names for user fields
274
-			foreach ($extra_user_fields as $field) {
275
-				$worksheet->SetCellValueByColumnAndRow($line, $column, api_html_entity_decode(strip_tags($field[3]), ENT_QUOTES, $charset));
276
-				$column++;
277
-			}
278
-		}
273
+            //show the fields names for user fields
274
+            foreach ($extra_user_fields as $field) {
275
+                $worksheet->SetCellValueByColumnAndRow($line, $column, api_html_entity_decode(strip_tags($field[3]), ENT_QUOTES, $charset));
276
+                $column++;
277
+            }
278
+        }
279 279
 
280
-		$worksheet->SetCellValueByColumnAndRow($line,$column, get_lang('Title'));
281
-		$column++;
282
-		$worksheet->SetCellValueByColumnAndRow($line,$column, get_lang('StartDate'));
280
+        $worksheet->SetCellValueByColumnAndRow($line,$column, get_lang('Title'));
281
+        $column++;
282
+        $worksheet->SetCellValueByColumnAndRow($line,$column, get_lang('StartDate'));
283 283
         $column++;
284 284
         $worksheet->SetCellValueByColumnAndRow($line,$column, get_lang('EndDate'));
285 285
         $column++;
286 286
         $worksheet->SetCellValueByColumnAndRow($line,$column, get_lang('Duration').' ('.get_lang('MinMinutes').')');
287
-		$column++;
288
-		$worksheet->SetCellValueByColumnAndRow($line,$column, get_lang('Score'));
289
-		$column++;
290
-		$worksheet->SetCellValueByColumnAndRow($line,$column, get_lang('Total'));
291
-		$column++;
287
+        $column++;
288
+        $worksheet->SetCellValueByColumnAndRow($line,$column, get_lang('Score'));
289
+        $column++;
290
+        $worksheet->SetCellValueByColumnAndRow($line,$column, get_lang('Total'));
291
+        $column++;
292 292
         $worksheet->SetCellValueByColumnAndRow($line,$column, get_lang('Status'));
293
-		$line++;
293
+        $line++;
294 294
 
295
-		foreach ($this->results as $row) {
296
-			$column = 0;
295
+        foreach ($this->results as $row) {
296
+            $column = 0;
297 297
 
298 298
             if ($with_column_user) {
299 299
                 $worksheet->SetCellValueByColumnAndRow($line,$column,api_html_entity_decode(strip_tags($row['email']), ENT_QUOTES, $charset));
@@ -310,38 +310,38 @@  discard block
 block discarded – undo
310 310
                     $worksheet->SetCellValueByColumnAndRow($line,$column,api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset));
311 311
                     $column++;
312 312
                 }
313
-			}
313
+            }
314 314
 
315
-			if ($export_user_fields) {
316
-				//show user fields data, if any, for this user
317
-				$user_fields_values = UserManager::get_extra_user_data($row['user_id'],false,false, false, true);
318
-				foreach($user_fields_values as $value) {
319
-					$worksheet->SetCellValueByColumnAndRow($line,$column, api_html_entity_decode(strip_tags($value), ENT_QUOTES, $charset));
320
-					$column++;
321
-				}
322
-			}
315
+            if ($export_user_fields) {
316
+                //show user fields data, if any, for this user
317
+                $user_fields_values = UserManager::get_extra_user_data($row['user_id'],false,false, false, true);
318
+                foreach($user_fields_values as $value) {
319
+                    $worksheet->SetCellValueByColumnAndRow($line,$column, api_html_entity_decode(strip_tags($value), ENT_QUOTES, $charset));
320
+                    $column++;
321
+                }
322
+            }
323 323
 
324
-			$worksheet->SetCellValueByColumnAndRow($line,$column,api_html_entity_decode(strip_tags($row['title']), ENT_QUOTES, $charset));
325
-			$column++;
326
-			$worksheet->SetCellValueByColumnAndRow($line,$column,$row['start_date']);
324
+            $worksheet->SetCellValueByColumnAndRow($line,$column,api_html_entity_decode(strip_tags($row['title']), ENT_QUOTES, $charset));
325
+            $column++;
326
+            $worksheet->SetCellValueByColumnAndRow($line,$column,$row['start_date']);
327 327
             $column++;
328
-			$worksheet->SetCellValueByColumnAndRow($line,$column,$row['end_date']);
328
+            $worksheet->SetCellValueByColumnAndRow($line,$column,$row['end_date']);
329
+            $column++;
330
+            $worksheet->SetCellValueByColumnAndRow($line,$column,$row['duration']);
331
+            $column++;
332
+            $worksheet->SetCellValueByColumnAndRow($line,$column,$row['result']);
333
+            $column++;
334
+            $worksheet->SetCellValueByColumnAndRow($line,$column,$row['max']);
329 335
             $column++;
330
-			$worksheet->SetCellValueByColumnAndRow($line,$column,$row['duration']);
331
-			$column++;
332
-			$worksheet->SetCellValueByColumnAndRow($line,$column,$row['result']);
333
-			$column++;
334
-			$worksheet->SetCellValueByColumnAndRow($line,$column,$row['max']);
335
-			$column++;
336 336
             $worksheet->SetCellValueByColumnAndRow($line,$column,$row['status']);
337
-			$line++;
338
-		}
337
+            $line++;
338
+        }
339 339
 
340 340
         $file = api_get_path(SYS_ARCHIVE_PATH).api_replace_dangerous_char($filename);
341 341
         $writer = new PHPExcel_Writer_Excel2007($spreadsheet);
342 342
         $writer->save($file);
343 343
         DocumentManager::file_send_for_download($file, true, $filename);
344 344
 
345
-		return true;
346
-	}
345
+        return true;
346
+    }
347 347
 }
Please login to merge, or discard this patch.
main/exercice/hotspot.class.php 1 patch
Indentation   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -12,78 +12,78 @@  discard block
 block discarded – undo
12 12
  **/
13 13
 class HotSpot extends Question
14 14
 {
15
-	static $typePicture = 'hotspot.png';
16
-	static $explanationLangVar = 'HotSpot';
17
-
18
-	public function __construct()
19
-	{
20
-		parent::__construct();
21
-		$this -> type = HOT_SPOT;
22
-	}
23
-
24
-	public function display()
25
-	{
26
-	}
27
-
28
-	/**
29
-	 * @param FormValidator $form
30
-	 * @param int $fck_config
31
-	 */
32
-	public function createForm (&$form, $fck_config=0)
33
-	{
34
-		parent::createForm($form, $fck_config);
35
-
36
-		if (!isset($_GET['editQuestion'])) {
37
-			$form->addElement('file','imageUpload',array('<img src="'.Display::return_icon('hotspot.png', null, null, ICON_SIZE_BIG, false, true).'" />', get_lang('UploadJpgPicture')) );
38
-
39
-			// setting the save button here and not in the question class.php
40
-			// Saving a question
41
-			$form->addButtonSave(get_lang('GoToQuestion'), 'submitQuestion');
42
-			//$form->addButtonSave(get_lang('GoToQuestion'), 'submitQuestion');
43
-			$form->addRule('imageUpload', get_lang('OnlyImagesAllowed'), 'filetype', array ('jpg', 'jpeg', 'png', 'gif'));
44
-			$form->addRule('imageUpload', get_lang('NoImage'), 'uploadedfile');
45
-		} else {
46
-			// setting the save button here and not in the question class.php
47
-			// Editing a question
48
-			$form->addButtonUpdate(get_lang('ModifyExercise'), 'submitQuestion');
49
-		}
50
-	}
51
-
52
-	/**
53
-	 * @param FormValidator $form
54
-	 * @param null $objExercise
55
-	 * @return null|false
56
-	 */
57
-	public function processCreation($form, $objExercise = null)
58
-	{
59
-		$file_info = $form->getSubmitValue('imageUpload');
60
-		$_course = api_get_course_info();
61
-		parent::processCreation($form, $objExercise);
62
-
63
-		if(!empty($file_info['tmp_name'])) {
64
-			$this->uploadPicture($file_info['tmp_name'], $file_info['name']);
65
-			$documentPath  = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
66
-			$picturePath   = $documentPath.'/images';
67
-
68
-			// fixed width ang height
69
-			if (file_exists($picturePath.'/'.$this->picture)) {
70
-				$this->resizePicture('width', 800);
71
-				$this->save();
72
-			} else {
73
-				return false;
74
-			}
75
-		}
76
-	}
77
-
78
-	function createAnswersForm ($form)
79
-	{
80
-		// nothing
81
-	}
82
-
83
-	function processAnswersCreation ($form)
84
-	{
85
-		// nothing
86
-	}
15
+    static $typePicture = 'hotspot.png';
16
+    static $explanationLangVar = 'HotSpot';
17
+
18
+    public function __construct()
19
+    {
20
+        parent::__construct();
21
+        $this -> type = HOT_SPOT;
22
+    }
23
+
24
+    public function display()
25
+    {
26
+    }
27
+
28
+    /**
29
+     * @param FormValidator $form
30
+     * @param int $fck_config
31
+     */
32
+    public function createForm (&$form, $fck_config=0)
33
+    {
34
+        parent::createForm($form, $fck_config);
35
+
36
+        if (!isset($_GET['editQuestion'])) {
37
+            $form->addElement('file','imageUpload',array('<img src="'.Display::return_icon('hotspot.png', null, null, ICON_SIZE_BIG, false, true).'" />', get_lang('UploadJpgPicture')) );
38
+
39
+            // setting the save button here and not in the question class.php
40
+            // Saving a question
41
+            $form->addButtonSave(get_lang('GoToQuestion'), 'submitQuestion');
42
+            //$form->addButtonSave(get_lang('GoToQuestion'), 'submitQuestion');
43
+            $form->addRule('imageUpload', get_lang('OnlyImagesAllowed'), 'filetype', array ('jpg', 'jpeg', 'png', 'gif'));
44
+            $form->addRule('imageUpload', get_lang('NoImage'), 'uploadedfile');
45
+        } else {
46
+            // setting the save button here and not in the question class.php
47
+            // Editing a question
48
+            $form->addButtonUpdate(get_lang('ModifyExercise'), 'submitQuestion');
49
+        }
50
+    }
51
+
52
+    /**
53
+     * @param FormValidator $form
54
+     * @param null $objExercise
55
+     * @return null|false
56
+     */
57
+    public function processCreation($form, $objExercise = null)
58
+    {
59
+        $file_info = $form->getSubmitValue('imageUpload');
60
+        $_course = api_get_course_info();
61
+        parent::processCreation($form, $objExercise);
62
+
63
+        if(!empty($file_info['tmp_name'])) {
64
+            $this->uploadPicture($file_info['tmp_name'], $file_info['name']);
65
+            $documentPath  = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
66
+            $picturePath   = $documentPath.'/images';
67
+
68
+            // fixed width ang height
69
+            if (file_exists($picturePath.'/'.$this->picture)) {
70
+                $this->resizePicture('width', 800);
71
+                $this->save();
72
+            } else {
73
+                return false;
74
+            }
75
+        }
76
+    }
77
+
78
+    function createAnswersForm ($form)
79
+    {
80
+        // nothing
81
+    }
82
+
83
+    function processAnswersCreation ($form)
84
+    {
85
+        // nothing
86
+    }
87 87
 }
88 88
 
89 89
 /**
@@ -91,35 +91,35 @@  discard block
 block discarded – undo
91 91
  */
92 92
 class HotSpotDelineation extends HotSpot
93 93
 {
94
-	static $typePicture = 'hotspot-delineation.png';
95
-	static $explanationLangVar = 'HotspotDelineation';
96
-
97
-	function __construct()
98
-	{
99
-		parent::__construct();
100
-		$this -> type = HOT_SPOT_DELINEATION;
101
-
102
-	}
103
-
104
-	function createForm (&$form, $fck_config=0)
105
-	{
106
-		parent::createForm ($form, $fck_config);
107
-	}
108
-
109
-	function processCreation ($form, $objExercise = null)
110
-	{
111
-		$file_info = $form -> getSubmitValue('imageUpload');
112
-		parent::processCreation ($form, $objExercise);
113
-	}
114
-
115
-	function createAnswersForm ($form)
116
-	{
117
-		parent::createAnswersForm ($form);
118
-	}
119
-
120
-	function processAnswersCreation ($form)
121
-	{
122
-		parent::processAnswersCreation ($form);
123
-	}
94
+    static $typePicture = 'hotspot-delineation.png';
95
+    static $explanationLangVar = 'HotspotDelineation';
96
+
97
+    function __construct()
98
+    {
99
+        parent::__construct();
100
+        $this -> type = HOT_SPOT_DELINEATION;
101
+
102
+    }
103
+
104
+    function createForm (&$form, $fck_config=0)
105
+    {
106
+        parent::createForm ($form, $fck_config);
107
+    }
108
+
109
+    function processCreation ($form, $objExercise = null)
110
+    {
111
+        $file_info = $form -> getSubmitValue('imageUpload');
112
+        parent::processCreation ($form, $objExercise);
113
+    }
114
+
115
+    function createAnswersForm ($form)
116
+    {
117
+        parent::createAnswersForm ($form);
118
+    }
119
+
120
+    function processAnswersCreation ($form)
121
+    {
122
+        parent::processAnswersCreation ($form);
123
+    }
124 124
 }
125 125
 
Please login to merge, or discard this patch.
main/exercice/answer.class.php 1 patch
Indentation   +301 added lines, -301 removed lines patch added patch discarded remove patch
@@ -157,12 +157,12 @@  discard block
 block discarded – undo
157 157
         return [];
158 158
     }
159 159
 
160
-     /**
161
-     * returns all answer ids from this question Id
162
-     *
163
-     * @author Yoselyn Castillo
164
-     * @return array - $id (answer ids)
165
-     */
160
+        /**
161
+         * returns all answer ids from this question Id
162
+         *
163
+         * @author Yoselyn Castillo
164
+         * @return array - $id (answer ids)
165
+         */
166 166
     public function selectAnswerId()
167 167
     {
168 168
         $TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER);
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
         }
183 183
 
184 184
         return $id;
185
-	}
185
+    }
186 186
 
187 187
     /**
188 188
      * Reads answer information from the data base ordered by parameter
@@ -193,23 +193,23 @@  discard block
 block discarded – undo
193 193
      */
194 194
     public function readOrderedBy($field, $order='ASC')
195 195
     {
196
-		$field = Database::escape_string($field);
197
-		if (empty($field)) {
198
-			$field = 'position';
199
-		}
196
+        $field = Database::escape_string($field);
197
+        if (empty($field)) {
198
+            $field = 'position';
199
+        }
200 200
 
201
-		if ($order != 'ASC' && $order!='DESC') {
202
-			$order = 'ASC';
203
-		}
201
+        if ($order != 'ASC' && $order!='DESC') {
202
+            $order = 'ASC';
203
+        }
204 204
 
205
-		$TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER);
206
-		$TBL_QUIZ = Database::get_course_table(TABLE_QUIZ_QUESTION);
207
-		$questionId = intval($this->questionId);
205
+        $TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER);
206
+        $TBL_QUIZ = Database::get_course_table(TABLE_QUIZ_QUESTION);
207
+        $questionId = intval($this->questionId);
208 208
 
209
-		$sql = "SELECT type FROM $TBL_QUIZ
209
+        $sql = "SELECT type FROM $TBL_QUIZ
210 210
 		        WHERE c_id = {$this->course_id} AND id = $questionId";
211
-		$result_question = Database::query($sql);
212
-		$questionType = Database::fetch_array($result_question);
211
+        $result_question = Database::query($sql);
212
+        $questionType = Database::fetch_array($result_question);
213 213
 
214 214
         if ($questionType['type'] == DRAGGABLE) {
215 215
             // Random is done by submit.js.tpl
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
             return true;
219 219
         }
220 220
 
221
-		$sql = "SELECT
221
+        $sql = "SELECT
222 222
 		            answer,
223 223
 		            correct,
224 224
 		            comment,
@@ -234,16 +234,16 @@  discard block
 block discarded – undo
234 234
                     c_id = {$this->course_id} AND
235 235
                     question_id='".$questionId."'
236 236
                 ORDER BY $field $order";
237
-		$result=Database::query($sql);
238
-
239
-		$i = 1;
240
-		// while a record is found
241
-		$doubt_data = null;
242
-		while ($object = Database::fetch_object($result)) {
243
-		    if ($questionType['type'] == UNIQUE_ANSWER_NO_OPTION && $object->position == 666) {
244
-		        $doubt_data = $object;
237
+        $result=Database::query($sql);
238
+
239
+        $i = 1;
240
+        // while a record is found
241
+        $doubt_data = null;
242
+        while ($object = Database::fetch_object($result)) {
243
+            if ($questionType['type'] == UNIQUE_ANSWER_NO_OPTION && $object->position == 666) {
244
+                $doubt_data = $object;
245 245
                 continue;
246
-		    }
246
+            }
247 247
             $this->answer[$i] = $object->answer;
248 248
             $this->correct[$i] = $object->correct;
249 249
             $this->comment[$i] = $object->comment;
@@ -255,9 +255,9 @@  discard block
 block discarded – undo
255 255
             $this->autoId[$i] = $object->id_auto;
256 256
             $this->iid[$i] = $object->iid;
257 257
             $i++;
258
-		}
258
+        }
259 259
 
260
-		if ($questionType['type'] == UNIQUE_ANSWER_NO_OPTION && !empty($doubt_data)) {
260
+        if ($questionType['type'] == UNIQUE_ANSWER_NO_OPTION && !empty($doubt_data)) {
261 261
             $this->answer[$i] = $doubt_data->answer;
262 262
             $this->correct[$i] = $doubt_data->correct;
263 263
             $this->comment[$i] = $doubt_data->comment;
@@ -269,88 +269,88 @@  discard block
 block discarded – undo
269 269
             $this->autoId[$i] = $doubt_data->id_auto;
270 270
             $this->iid[$i] = $doubt_data->iid;
271 271
             $i++;
272
-	    }
272
+        }
273 273
         $this->nbrAnswers = $i-1;
274
-	}
275
-
276
-	/**
277
-	 * returns the autoincrement id identificator
278
-	 *
279
-	 * @author Juan Carlos Ra�a
280
-	 * @return integer - answer num
281
-	 */
274
+    }
275
+
276
+    /**
277
+     * returns the autoincrement id identificator
278
+     *
279
+     * @author Juan Carlos Ra�a
280
+     * @return integer - answer num
281
+     */
282 282
     public function selectAutoId($id)
283 283
     {
284
-		return isset($this->autoId[$id]) ? $this->autoId[$id] : 0;
285
-	}
286
-
287
-	/**
288
-	 * returns the number of answers in this question
289
-	 *
290
-	 * @author Olivier Brouckaert
291
-	 * @return integer - number of answers
292
-	 */
293
-	public function selectNbrAnswers()
284
+        return isset($this->autoId[$id]) ? $this->autoId[$id] : 0;
285
+    }
286
+
287
+    /**
288
+     * returns the number of answers in this question
289
+     *
290
+     * @author Olivier Brouckaert
291
+     * @return integer - number of answers
292
+     */
293
+    public function selectNbrAnswers()
294 294
     {
295
-		return $this->nbrAnswers;
296
-	}
297
-
298
-	/**
299
-	 * returns the question ID which the answers belong to
300
-	 *
301
-	 * @author Olivier Brouckaert
302
-	 * @return integer - the question ID
303
-	 */
304
-	public function selectQuestionId()
295
+        return $this->nbrAnswers;
296
+    }
297
+
298
+    /**
299
+     * returns the question ID which the answers belong to
300
+     *
301
+     * @author Olivier Brouckaert
302
+     * @return integer - the question ID
303
+     */
304
+    public function selectQuestionId()
305 305
     {
306
-		return $this->questionId;
307
-	}
308
-
309
-	/**
310
-	 * returns the question ID of the destination question
311
-	 *
312
-	 * @author Julio Montoya
313
-	 * @param integer $id
314
-	 * @return integer - the question ID
315
-	 */
316
-	public function selectDestination($id)
306
+        return $this->questionId;
307
+    }
308
+
309
+    /**
310
+     * returns the question ID of the destination question
311
+     *
312
+     * @author Julio Montoya
313
+     * @param integer $id
314
+     * @return integer - the question ID
315
+     */
316
+    public function selectDestination($id)
317 317
     {
318
-		return isset($this->destination[$id]) ? $this->destination[$id] : null;
319
-	}
318
+        return isset($this->destination[$id]) ? $this->destination[$id] : null;
319
+    }
320 320
 
321 321
     /**
322
-	 * returns the answer title
323
-	 *
324
-	 * @author Olivier Brouckaert
325
-	 * @param - integer $id - answer ID
326
-	 * @return string - answer title
327
-	 */
328
-	public function selectAnswer($id)
329
-	{
330
-		return isset($this->answer[$id]) ? $this->answer[$id] : null;
331
-	}
332
-
333
-	/**
334
-	 * return array answer by id else return a bool
335
-	 * @param integer $auto_id
336
-	 */
337
-	public function selectAnswerByAutoId($auto_id)
338
-	{
339
-		$TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER);
340
-
341
-		$auto_id = intval($auto_id);
342
-		$sql = "SELECT id, answer, id_auto FROM $TBL_ANSWER
322
+     * returns the answer title
323
+     *
324
+     * @author Olivier Brouckaert
325
+     * @param - integer $id - answer ID
326
+     * @return string - answer title
327
+     */
328
+    public function selectAnswer($id)
329
+    {
330
+        return isset($this->answer[$id]) ? $this->answer[$id] : null;
331
+    }
332
+
333
+    /**
334
+     * return array answer by id else return a bool
335
+     * @param integer $auto_id
336
+     */
337
+    public function selectAnswerByAutoId($auto_id)
338
+    {
339
+        $TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER);
340
+
341
+        $auto_id = intval($auto_id);
342
+        $sql = "SELECT id, answer, id_auto FROM $TBL_ANSWER
343 343
 				WHERE c_id = {$this->course_id} AND id_auto='$auto_id'";
344
-		$rs = Database::query($sql);
344
+        $rs = Database::query($sql);
345 345
 
346
-		if (Database::num_rows($rs) > 0) {
347
-			$row = Database::fetch_array($rs, 'ASSOC');
346
+        if (Database::num_rows($rs) > 0) {
347
+            $row = Database::fetch_array($rs, 'ASSOC');
348 348
 
349
-			return $row;
350
-		}
349
+            return $row;
350
+        }
351 351
 
352
-		return false;
353
-	}
352
+        return false;
353
+    }
354 354
 
355 355
     /**
356 356
      * returns the answer title from an answer's position
@@ -359,18 +359,18 @@  discard block
 block discarded – undo
359 359
      * @param - integer $id - answer ID
360 360
      * @return bool - answer title
361 361
      */
362
-	public function selectAnswerIdByPosition($pos)
363
-	{
364
-		foreach ($this->position as $k => $v) {
365
-			if ($v != $pos) {
366
-				continue;
367
-			}
362
+    public function selectAnswerIdByPosition($pos)
363
+    {
364
+        foreach ($this->position as $k => $v) {
365
+            if ($v != $pos) {
366
+                continue;
367
+            }
368 368
 
369
-			return $k;
370
-		}
369
+            return $k;
370
+        }
371 371
 
372
-		return false;
373
-	}
372
+        return false;
373
+    }
374 374
 
375 375
     /**
376 376
      * Returns a list of answers
@@ -379,18 +379,18 @@  discard block
 block discarded – undo
379 379
      * of (id, answer, comment, grade) and grade=weighting
380 380
      */
381 381
     public function getAnswersList($decode = false)
382
-     {
383
-	 	$list = array();
384
-         for ($i = 1; $i <= $this->nbrAnswers; $i++) {
385
-             if (!empty($this->answer[$i])) {
386
-
387
-	 			//Avoid problems when parsing elements with accents
388
-	 			if ($decode) {
389
-	        		$this->answer[$i] 	= api_html_entity_decode($this->answer[$i], ENT_QUOTES, api_get_system_encoding());
390
-	        		$this->comment[$i]	= api_html_entity_decode($this->comment[$i], ENT_QUOTES, api_get_system_encoding());
391
-	 			}
392
-
393
-	 			$list[] = array(
382
+        {
383
+            $list = array();
384
+            for ($i = 1; $i <= $this->nbrAnswers; $i++) {
385
+                if (!empty($this->answer[$i])) {
386
+
387
+                    //Avoid problems when parsing elements with accents
388
+                    if ($decode) {
389
+                    $this->answer[$i] 	= api_html_entity_decode($this->answer[$i], ENT_QUOTES, api_get_system_encoding());
390
+                    $this->comment[$i]	= api_html_entity_decode($this->comment[$i], ENT_QUOTES, api_get_system_encoding());
391
+                    }
392
+
393
+                    $list[] = array(
394 394
                     'id' => $i,
395 395
                     'answer' => $this->answer[$i],
396 396
                     'comment' => $this->comment[$i],
@@ -399,137 +399,137 @@  discard block
 block discarded – undo
399 399
                     'hotspot_type' => $this->hotspot_type[$i],
400 400
                     'correct' => $this->correct[$i],
401 401
                     'destination' => $this->destination[$i]
402
-				);
402
+                );
403
+            }
403 404
             }
404
-	 	}
405 405
 
406
-	 	return $list;
407
-	 }
406
+            return $list;
407
+        }
408 408
 
409
-	/**
410
-	 * Returns a list of grades
411
-	 * @author Yannick Warnier <[email protected]>
412
-	 * @return array	List of grades where grade=weighting (?)
413
-	 */
409
+    /**
410
+     * Returns a list of grades
411
+     * @author Yannick Warnier <[email protected]>
412
+     * @return array	List of grades where grade=weighting (?)
413
+     */
414 414
     public function getGradesList()
415
-     {
416
-	 	$list = array();
417
-	 	for ($i = 0; $i<$this->nbrAnswers;$i++){
418
-	 		if(!empty($this->answer[$i])){
419
-	 			$list[$i] = $this->weighting[$i];
420
-	 		}
421
-	 	}
422
-	 	return $list;
423
-	 }
424
-
425
-	 /**
426
-	  * Returns the question type
427
-	  * @author	Yannick Warnier <[email protected]>
428
-	  * @return	integer	The type of the question this answer is bound to
429
-	  */
415
+        {
416
+            $list = array();
417
+            for ($i = 0; $i<$this->nbrAnswers;$i++){
418
+                if(!empty($this->answer[$i])){
419
+                    $list[$i] = $this->weighting[$i];
420
+                }
421
+            }
422
+            return $list;
423
+        }
424
+
425
+        /**
426
+         * Returns the question type
427
+         * @author	Yannick Warnier <[email protected]>
428
+         * @return	integer	The type of the question this answer is bound to
429
+         */
430 430
     public function getQuestionType()
431
-     {
432
-	 	$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
433
-	 	$sql = "SELECT type FROM $TBL_QUESTIONS
431
+        {
432
+            $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
433
+            $sql = "SELECT type FROM $TBL_QUESTIONS
434 434
 	 	        WHERE c_id = {$this->course_id} AND id = '".$this->questionId."'";
435
-	 	$res = Database::query($sql);
436
-	 	if (Database::num_rows($res)<=0){
437
-	 		return null;
438
-	 	}
439
-	 	$row = Database::fetch_array($res);
440
-
441
-	 	return $row['type'];
442
-	 }
443
-
444
-
445
-	/**
446
-	 * tells if answer is correct or not
447
-	 *
448
-	 * @author Olivier Brouckaert
449
-	 * @param - integer $id - answer ID
450
-	 * @return integer - 0 if bad answer, not 0 if good answer
451
-	 */
435
+            $res = Database::query($sql);
436
+            if (Database::num_rows($res)<=0){
437
+                return null;
438
+            }
439
+            $row = Database::fetch_array($res);
440
+
441
+            return $row['type'];
442
+        }
443
+
444
+
445
+    /**
446
+     * tells if answer is correct or not
447
+     *
448
+     * @author Olivier Brouckaert
449
+     * @param - integer $id - answer ID
450
+     * @return integer - 0 if bad answer, not 0 if good answer
451
+     */
452 452
     public function isCorrect($id)
453
-	{
454
-		return isset($this->correct[$id]) ? $this->correct[$id] : null;
455
-	}
456
-
457
-	/**
458
-	 * returns answer comment
459
-	 *
460
-	 * @author Olivier Brouckaert
461
-	 * @param - integer $id - answer ID
462
-	 * @return string - answer comment
463
-	 */
453
+    {
454
+        return isset($this->correct[$id]) ? $this->correct[$id] : null;
455
+    }
456
+
457
+    /**
458
+     * returns answer comment
459
+     *
460
+     * @author Olivier Brouckaert
461
+     * @param - integer $id - answer ID
462
+     * @return string - answer comment
463
+     */
464 464
     public function selectComment($id)
465
-	{
465
+    {
466 466
         return isset($this->comment[$id]) ? $this->comment[$id] : null;
467
-	}
468
-
469
-	/**
470
-	 * returns answer weighting
471
-	 *
472
-	 * @author Olivier Brouckaert
473
-	 * @param - integer $id - answer ID
474
-	 * @param integer $id
475
-	 * @return integer - answer weighting
476
-	 */
467
+    }
468
+
469
+    /**
470
+     * returns answer weighting
471
+     *
472
+     * @author Olivier Brouckaert
473
+     * @param - integer $id - answer ID
474
+     * @param integer $id
475
+     * @return integer - answer weighting
476
+     */
477 477
     public function selectWeighting($id)
478
-	{
479
-		return isset($this->weighting[$id]) ? $this->weighting[$id] : null;
480
-	}
481
-
482
-	/**
483
-	 * returns answer position
484
-	 *
485
-	 * @author Olivier Brouckaert
486
-	 * @param - integer $id - answer ID
487
-	 * @return integer - answer position
488
-	 */
489
-	function selectPosition($id)
490
-	{
491
-		return isset($this->position[$id]) ? $this->position[$id] : null;
492
-	}
493
-
494
-	/**
495
-	 * returns answer hotspot coordinates
496
-	 *
497
-	 * @author	Olivier Brouckaert
498
-	 * @param	integer	Answer ID
499
-	 * @param integer $id
500
-	 * @return	integer	Answer position
501
-	 */
478
+    {
479
+        return isset($this->weighting[$id]) ? $this->weighting[$id] : null;
480
+    }
481
+
482
+    /**
483
+     * returns answer position
484
+     *
485
+     * @author Olivier Brouckaert
486
+     * @param - integer $id - answer ID
487
+     * @return integer - answer position
488
+     */
489
+    function selectPosition($id)
490
+    {
491
+        return isset($this->position[$id]) ? $this->position[$id] : null;
492
+    }
493
+
494
+    /**
495
+     * returns answer hotspot coordinates
496
+     *
497
+     * @author	Olivier Brouckaert
498
+     * @param	integer	Answer ID
499
+     * @param integer $id
500
+     * @return	integer	Answer position
501
+     */
502 502
     public function selectHotspotCoordinates($id)
503
-	{
504
-		return isset($this->hotspot_coordinates[$id]) ? $this->hotspot_coordinates[$id] : null;
505
-	}
506
-
507
-	/**
508
-	 * returns answer hotspot type
509
-	 *
510
-	 * @author	Toon Keppens
511
-	 * @param	integer		Answer ID
512
-	 * @param integer $id
513
-	 * @return	integer		Answer position
514
-	 */
503
+    {
504
+        return isset($this->hotspot_coordinates[$id]) ? $this->hotspot_coordinates[$id] : null;
505
+    }
506
+
507
+    /**
508
+     * returns answer hotspot type
509
+     *
510
+     * @author	Toon Keppens
511
+     * @param	integer		Answer ID
512
+     * @param integer $id
513
+     * @return	integer		Answer position
514
+     */
515 515
     public function selectHotspotType($id)
516
-	{
517
-		return isset($this->hotspot_type[$id]) ? $this->hotspot_type[$id] : null;
518
-	}
519
-
520
-	/**
521
-	 * Creates a new answer
522
-	 *
523
-	 * @author Olivier Brouckaert
524
-	 * @param string 	$answer answer title
525
-	 * @param integer 	$correct 0 if bad answer, not 0 if good answer
526
-	 * @param string 	$comment answer comment
527
-	 * @param integer 	$weighting answer weighting
528
-	 * @param integer 	$position answer position
529
-	 * @param array    $new_hotspot_coordinates Coordinates for hotspot exercises (optional)
530
-	 * @param integer	$new_hotspot_type Type for hotspot exercises (optional)
516
+    {
517
+        return isset($this->hotspot_type[$id]) ? $this->hotspot_type[$id] : null;
518
+    }
519
+
520
+    /**
521
+     * Creates a new answer
522
+     *
523
+     * @author Olivier Brouckaert
524
+     * @param string 	$answer answer title
525
+     * @param integer 	$correct 0 if bad answer, not 0 if good answer
526
+     * @param string 	$comment answer comment
527
+     * @param integer 	$weighting answer weighting
528
+     * @param integer 	$position answer position
529
+     * @param array    $new_hotspot_coordinates Coordinates for hotspot exercises (optional)
530
+     * @param integer	$new_hotspot_type Type for hotspot exercises (optional)
531 531
      * @param string   $destination
532
-	 */
532
+     */
533 533
     public function createAnswer(
534 534
         $answer,
535 535
         $correct,
@@ -540,7 +540,7 @@  discard block
 block discarded – undo
540 540
         $new_hotspot_type = null,
541 541
         $destination = ''
542 542
     ) {
543
-		$this->new_nbrAnswers++;
543
+        $this->new_nbrAnswers++;
544 544
         $id = $this->new_nbrAnswers;
545 545
         $this->new_answer[$id] = $answer;
546 546
         $this->new_correct[$id] = $correct;
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
         $this->new_hotspot_coordinates[$id] = $new_hotspot_coordinates;
551 551
         $this->new_hotspot_type[$id] = $new_hotspot_type;
552 552
         $this->new_destination[$id] = $destination;
553
-	}
553
+    }
554 554
 
555 555
     /**
556 556
      * Updates an answer
@@ -591,31 +591,31 @@  discard block
 block discarded – undo
591 591
         ];
592 592
 
593 593
         Database::update($answerTable, $params, ['iid = ?' => intval($iid)]);
594
-	}
594
+    }
595 595
 
596
-	/**
597
-	 * Records answers into the data base
598
-	 *
599
-	 * @author Olivier Brouckaert
600
-	 */
596
+    /**
597
+     * Records answers into the data base
598
+     *
599
+     * @author Olivier Brouckaert
600
+     */
601 601
     public function save()
602 602
     {
603
-		$answerTable = Database::get_course_table(TABLE_QUIZ_ANSWER);
604
-		$questionId = intval($this->questionId);
603
+        $answerTable = Database::get_course_table(TABLE_QUIZ_ANSWER);
604
+        $questionId = intval($this->questionId);
605 605
 
606
-		$c_id = $this->course['real_id'];
606
+        $c_id = $this->course['real_id'];
607 607
         $correctList = [];
608 608
         $answerList = [];
609 609
 
610
-		for ($i=1; $i <= $this->new_nbrAnswers; $i++) {
611
-			$answer = $this->new_answer[$i];
612
-			$correct = $this->new_correct[$i];
613
-			$comment = $this->new_comment[$i];
614
-			$weighting = $this->new_weighting[$i];
615
-			$position = $this->new_position[$i];
616
-			$hotspot_coordinates = $this->new_hotspot_coordinates[$i];
617
-			$hotspot_type = $this->new_hotspot_type[$i];
618
-			$destination = $this->new_destination[$i];
610
+        for ($i=1; $i <= $this->new_nbrAnswers; $i++) {
611
+            $answer = $this->new_answer[$i];
612
+            $correct = $this->new_correct[$i];
613
+            $comment = $this->new_comment[$i];
614
+            $weighting = $this->new_weighting[$i];
615
+            $position = $this->new_position[$i];
616
+            $hotspot_coordinates = $this->new_hotspot_coordinates[$i];
617
+            $hotspot_type = $this->new_hotspot_type[$i];
618
+            $destination = $this->new_destination[$i];
619 619
             $autoId = $this->selectAutoId($i);
620 620
             $iid = isset($this->iid[$i]) ? $this->iid[$i] : 0;
621 621
 
@@ -714,37 +714,37 @@  discard block
 block discarded – undo
714 714
             }
715 715
         }
716 716
 
717
-		// moves $new_* arrays
718
-		$this->answer = $this->new_answer;
719
-		$this->correct = $this->new_correct;
720
-		$this->comment = $this->new_comment;
721
-		$this->weighting = $this->new_weighting;
722
-		$this->position = $this->new_position;
723
-		$this->hotspot_coordinates = $this->new_hotspot_coordinates;
724
-		$this->hotspot_type = $this->new_hotspot_type;
725
-
726
-		$this->nbrAnswers = $this->new_nbrAnswers;
727
-		$this->destination = $this->new_destination;
728
-		// clears $new_* arrays
729
-
730
-		$this->cancel();
731
-	}
732
-
733
-	/**
734
-	 * Duplicates answers by copying them into another question
735
-	 *
736
-	 * @author Olivier Brouckaert
737
-	 * @param  int question id
717
+        // moves $new_* arrays
718
+        $this->answer = $this->new_answer;
719
+        $this->correct = $this->new_correct;
720
+        $this->comment = $this->new_comment;
721
+        $this->weighting = $this->new_weighting;
722
+        $this->position = $this->new_position;
723
+        $this->hotspot_coordinates = $this->new_hotspot_coordinates;
724
+        $this->hotspot_type = $this->new_hotspot_type;
725
+
726
+        $this->nbrAnswers = $this->new_nbrAnswers;
727
+        $this->destination = $this->new_destination;
728
+        // clears $new_* arrays
729
+
730
+        $this->cancel();
731
+    }
732
+
733
+    /**
734
+     * Duplicates answers by copying them into another question
735
+     *
736
+     * @author Olivier Brouckaert
737
+     * @param  int question id
738 738
      * @param  array destination course info (result of the function api_get_course_info() )
739 739
      * @param string $newQuestionId
740
-	 */
740
+     */
741 741
     public function duplicate($newQuestionId, $course_info = null)
742 742
     {
743 743
         if (empty($course_info)) {
744 744
             $course_info = $this->course;
745 745
         }
746 746
 
747
-		$TBL_REPONSES = Database :: get_course_table(TABLE_QUIZ_ANSWER);
747
+        $TBL_REPONSES = Database :: get_course_table(TABLE_QUIZ_ANSWER);
748 748
         $fixed_list = array();
749 749
 
750 750
         if (self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE ||
@@ -758,7 +758,7 @@  discard block
 block discarded – undo
758 758
 
759 759
             if (!empty($origin_options)) {
760 760
                 foreach ($origin_options as $item) {
761
-            	   $new_option_list[] = $item['id'];
761
+                    $new_option_list[] = $item['id'];
762 762
                 }
763 763
             }
764 764
 
@@ -772,12 +772,12 @@  discard block
 block discarded – undo
772 772
             }
773 773
         }
774 774
 
775
-		// if at least one answer
776
-		if ($this->nbrAnswers) {
777
-			// inserts new answers into data base
778
-			$c_id = $course_info['real_id'];
775
+        // if at least one answer
776
+        if ($this->nbrAnswers) {
777
+            // inserts new answers into data base
778
+            $c_id = $course_info['real_id'];
779 779
 
780
-			for ($i=1;$i <= $this->nbrAnswers;$i++) {
780
+            for ($i=1;$i <= $this->nbrAnswers;$i++) {
781 781
                 if ($this->course['id'] != $course_info['id']) {
782 782
                     $this->answer[$i] = DocumentManager::replace_urls_inside_content_html_from_copy_course(
783 783
                         $this->answer[$i],
@@ -791,8 +791,8 @@  discard block
 block discarded – undo
791 791
                     );
792 792
                 }
793 793
 
794
-				$answer = $this->answer[$i];
795
-				$correct = $this->correct[$i];
794
+                $answer = $this->answer[$i];
795
+                $correct = $this->correct[$i];
796 796
 
797 797
                 if (self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE ||
798 798
                     self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE
@@ -800,12 +800,12 @@  discard block
 block discarded – undo
800 800
                     $correct = $fixed_list[intval($correct)];
801 801
                 }
802 802
 
803
-				$comment = $this->comment[$i];
804
-				$weighting = $this->weighting[$i];
805
-				$position = $this->position[$i];
806
-				$hotspot_coordinates = $this->hotspot_coordinates[$i];
807
-				$hotspot_type = $this->hotspot_type[$i];
808
-				$destination = $this->destination[$i];
803
+                $comment = $this->comment[$i];
804
+                $weighting = $this->weighting[$i];
805
+                $position = $this->position[$i];
806
+                $hotspot_coordinates = $this->hotspot_coordinates[$i];
807
+                $hotspot_type = $this->hotspot_type[$i];
808
+                $destination = $this->destination[$i];
809 809
 
810 810
                 $params = [
811 811
                     'c_id' => $c_id,
@@ -825,9 +825,9 @@  discard block
 block discarded – undo
825 825
                     $sql = "UPDATE $TBL_REPONSES SET id = iid, id_auto = iid WHERE iid = $id";
826 826
                     Database::query($sql);
827 827
                 }
828
-			}
828
+            }
829 829
         }
830
-	}
830
+    }
831 831
 
832 832
     /**
833 833
      * Get the necessary JavaScript for some answers
Please login to merge, or discard this patch.
main/exercice/fill_blanks.class.php 1 patch
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -728,43 +728,43 @@  discard block
 block discarded – undo
728 728
     }
729 729
 
730 730
     /**
731
-    * Return an array of student state answers for fill the blank questions
732
-    * for each students that answered the question
733
-    * -2  : didn't answer
734
-    * -1  : student answer is wrong
735
-    *  0  : student answer is correct
736
-    * >0  : for fill the blank question with choice menu, is the index of the student answer (right answer indice is 0)
737
-    *
738
-    * @param integer $testId
739
-    * @param integer $questionId
740
-    * @param $studentsIdList
741
-    * @param string $startDate
742
-    * @param string $endDate
743
-    * @param bool $useLastAnswerredAttempt
744
-    * @return array
745
-    * (
746
-    *     [student_id] => Array
747
-    *         (
748
-    *             [first fill the blank for question] => -1
749
-    *             [second fill the blank for question] => 2
750
-    *             [third fill the blank for question] => -1
751
-    *         )
752
-    * )
753
-    */
731
+     * Return an array of student state answers for fill the blank questions
732
+     * for each students that answered the question
733
+     * -2  : didn't answer
734
+     * -1  : student answer is wrong
735
+     *  0  : student answer is correct
736
+     * >0  : for fill the blank question with choice menu, is the index of the student answer (right answer indice is 0)
737
+     *
738
+     * @param integer $testId
739
+     * @param integer $questionId
740
+     * @param $studentsIdList
741
+     * @param string $startDate
742
+     * @param string $endDate
743
+     * @param bool $useLastAnswerredAttempt
744
+     * @return array
745
+     * (
746
+     *     [student_id] => Array
747
+     *         (
748
+     *             [first fill the blank for question] => -1
749
+     *             [second fill the blank for question] => 2
750
+     *             [third fill the blank for question] => -1
751
+     *         )
752
+     * )
753
+     */
754 754
     public static function getFillTheBlankTabResult($testId, $questionId, $studentsIdList, $startDate, $endDate, $useLastAnswerredAttempt = true) {
755 755
 
756
-       $tblTrackEAttempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
757
-       $tblTrackEExercise = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
758
-       $courseId = api_get_course_int_id();
756
+        $tblTrackEAttempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
757
+        $tblTrackEExercise = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
758
+        $courseId = api_get_course_int_id();
759 759
 
760
-       require_once api_get_path(SYS_PATH).'main/exercice/fill_blanks.class.php';
760
+        require_once api_get_path(SYS_PATH).'main/exercice/fill_blanks.class.php';
761 761
 
762
-       // request to have all the answers of student for this question
763
-       // student may have doing it several time
764
-       // student may have not answered the bracket id, in this case, is result of the answer is empty
762
+        // request to have all the answers of student for this question
763
+        // student may have doing it several time
764
+        // student may have not answered the bracket id, in this case, is result of the answer is empty
765 765
 
766
-       // we got the less recent attempt first
767
-       $sql = '
766
+        // we got the less recent attempt first
767
+        $sql = '
768 768
            SELECT * FROM '.$tblTrackEAttempt.' tea
769 769
 
770 770
            LEFT JOIN '.$tblTrackEExercise.' tee
@@ -780,49 +780,49 @@  discard block
 block discarded – undo
780 780
            ORDER BY user_id, tea.exe_id;
781 781
        ';
782 782
 
783
-       $res = Database::query($sql);
784
-       $tabUserResult = array();
785
-       $bracketNumber = 0;
786
-       // foreach attempts for all students starting with his older attempt
787
-       while ($data = Database::fetch_array($res)) {
788
-           $tabAnswer = FillBlanks::getAnswerInfo($data['answer'], true);
783
+        $res = Database::query($sql);
784
+        $tabUserResult = array();
785
+        $bracketNumber = 0;
786
+        // foreach attempts for all students starting with his older attempt
787
+        while ($data = Database::fetch_array($res)) {
788
+            $tabAnswer = FillBlanks::getAnswerInfo($data['answer'], true);
789 789
 
790
-           // for each bracket to find in this question
791
-           foreach ($tabAnswer['studentanswer'] as $bracketNumber => $studentAnswer) {
790
+            // for each bracket to find in this question
791
+            foreach ($tabAnswer['studentanswer'] as $bracketNumber => $studentAnswer) {
792 792
 
793
-               if ($tabAnswer['studentanswer'][$bracketNumber] != '') {
794
-                   // student has answered this bracket, cool
795
-                   switch (FillBlanks::getFillTheBlankAnswerType($tabAnswer['tabwords'][$bracketNumber])) {
796
-                       case self::FILL_THE_BLANK_MENU :
793
+                if ($tabAnswer['studentanswer'][$bracketNumber] != '') {
794
+                    // student has answered this bracket, cool
795
+                    switch (FillBlanks::getFillTheBlankAnswerType($tabAnswer['tabwords'][$bracketNumber])) {
796
+                        case self::FILL_THE_BLANK_MENU :
797 797
                            // get the indice of the choosen answer in the menu
798 798
                            // we know that the right answer is the first entry of the menu, ie 0
799 799
                            // (remember, menu entries are shuffled when taking the test)
800 800
                            $tabUserResult[$data['user_id']][$bracketNumber] = FillBlanks::getFillTheBlankMenuAnswerNum($tabAnswer['tabwords'][$bracketNumber], $tabAnswer['studentanswer'][$bracketNumber]);
801
-                           break;
802
-                       default :
801
+                            break;
802
+                        default :
803 803
                            if (FillBlanks::isGoodStudentAnswer($tabAnswer['studentanswer'][$bracketNumber], $tabAnswer['tabwords'][$bracketNumber])) {
804
-                               $tabUserResult[$data['user_id']][$bracketNumber] = 0;   //  right answer
805
-                           } else {
806
-                               $tabUserResult[$data['user_id']][$bracketNumber] = -1;  // wrong answer
807
-                           }
808
-                   }
809
-               } else {
810
-                   // student didn't answer this bracket
811
-                   if ($useLastAnswerredAttempt) {
812
-                       // if we take into account the last answered attempt
813
-                       if (!isset($tabUserResult[$data['user_id']][$bracketNumber])) {
814
-                           $tabUserResult[$data['user_id']][$bracketNumber] = -2;      // not answered
815
-                       }
816
-                   } else {
817
-                       // we take the last attempt, even if the student answer the question before
818
-                       $tabUserResult[$data['user_id']][$bracketNumber] = -2;      // not answered
819
-                   }
820
-               }
821
-           }
822
-
823
-
824
-       }
825
-       return $tabUserResult;
804
+                                $tabUserResult[$data['user_id']][$bracketNumber] = 0;   //  right answer
805
+                            } else {
806
+                                $tabUserResult[$data['user_id']][$bracketNumber] = -1;  // wrong answer
807
+                            }
808
+                    }
809
+                } else {
810
+                    // student didn't answer this bracket
811
+                    if ($useLastAnswerredAttempt) {
812
+                        // if we take into account the last answered attempt
813
+                        if (!isset($tabUserResult[$data['user_id']][$bracketNumber])) {
814
+                            $tabUserResult[$data['user_id']][$bracketNumber] = -2;      // not answered
815
+                        }
816
+                    } else {
817
+                        // we take the last attempt, even if the student answer the question before
818
+                        $tabUserResult[$data['user_id']][$bracketNumber] = -2;      // not answered
819
+                    }
820
+                }
821
+            }
822
+
823
+
824
+        }
825
+        return $tabUserResult;
826 826
     }
827 827
 
828 828
 
Please login to merge, or discard this patch.
main/exercice/TestCategory.php 1 patch
Indentation   +486 added lines, -486 removed lines patch added patch discarded remove patch
@@ -13,11 +13,11 @@  discard block
 block discarded – undo
13 13
     public $name;
14 14
     public $description;
15 15
 
16
-	/**
17
-	 * Constructor of the class Category
18
-	 * If you give an in_id and no in_name, you get info concerning the category of id=in_id
19
-	 * otherwise, you've got an category objet avec your in_id, in_name, in_descr
20
-	 *
16
+    /**
17
+     * Constructor of the class Category
18
+     * If you give an in_id and no in_name, you get info concerning the category of id=in_id
19
+     * otherwise, you've got an category objet avec your in_id, in_name, in_descr
20
+     *
21 21
      * @param int    $id
22 22
      * @param string $name
23 23
      * @param string $description
@@ -61,9 +61,9 @@  discard block
 block discarded – undo
61 61
         }
62 62
     }
63 63
 
64
-	/**
64
+    /**
65 65
      * add TestCategory in the database if name doesn't already exists
66
-	 */
66
+     */
67 67
     public function addCategoryInBDD()
68 68
     {
69 69
         $table = Database :: get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
@@ -108,12 +108,12 @@  discard block
 block discarded – undo
108 108
 
109 109
             return false;
110 110
         }
111
-	}
111
+    }
112 112
 
113
-	/**
113
+    /**
114 114
      * Removes the category from the database
115 115
      * if there were question in this category, the link between question and category is removed
116
-	 */
116
+     */
117 117
     public function removeCategory()
118 118
     {
119 119
         $table = Database :: get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
@@ -143,11 +143,11 @@  discard block
 block discarded – undo
143 143
 
144 144
             return true;
145 145
         }
146
-	}
146
+    }
147 147
 
148
-	/**
148
+    /**
149 149
      * Modify category name or description of category with id=in_id
150
-	 */
150
+     */
151 151
     public function modifyCategory()
152 152
     {
153 153
         $table = Database :: get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
@@ -175,40 +175,40 @@  discard block
 block discarded – undo
175 175
 
176 176
             return true;
177 177
         }
178
-	}
178
+    }
179 179
 
180
-	/**
180
+    /**
181 181
      * Gets the number of question of category id=in_id
182
-	 */
182
+     */
183 183
     public function getCategoryQuestionsNumber()
184 184
     {
185
-		$table = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
186
-		$in_id = intval($this->id);
187
-		$sql = "SELECT count(*) AS nb
185
+        $table = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
186
+        $in_id = intval($this->id);
187
+        $sql = "SELECT count(*) AS nb
188 188
 		        FROM $table
189 189
 		        WHERE category_id=$in_id AND c_id=".api_get_course_int_id();
190
-		$res = Database::query($sql);
191
-		$row = Database::fetch_array($res);
190
+        $res = Database::query($sql);
191
+        $row = Database::fetch_array($res);
192 192
 
193
-		return $row['nb'];
194
-	}
193
+        return $row['nb'];
194
+    }
195 195
 
196 196
     /**
197 197
      * @param string $in_color
198 198
      */
199 199
     public function display($in_color="#E0EBF5")
200 200
     {
201
-		echo "<textarea style='background-color:$in_color; width:60%; height:100px;'>";
202
-		print_r($this);
203
-		echo "</textarea>";
204
-	}
201
+        echo "<textarea style='background-color:$in_color; width:60%; height:100px;'>";
202
+        print_r($this);
203
+        echo "</textarea>";
204
+    }
205 205
 
206
-	/**
206
+    /**
207 207
      * Return an array of all Category objects in the database
208
-	 * If in_field=="" Return an array of all category objects in the database
209
-	 * Otherwise, return an array of all in_field value
210
-	 * in the database (in_field = id or name or description)
211
-	 */
208
+     * If in_field=="" Return an array of all category objects in the database
209
+     * Otherwise, return an array of all in_field value
210
+     * in the database (in_field = id or name or description)
211
+     */
212 212
     public static function getCategoryListInfo($in_field = "", $courseId = "")
213 213
     {
214 214
         if (empty($courseId) || $courseId=="") {
@@ -239,8 +239,8 @@  discard block
 block discarded – undo
239 239
             }
240 240
         }
241 241
 
242
-		return $tabres;
243
-	}
242
+        return $tabres;
243
+    }
244 244
 
245 245
     /**
246 246
      * Return the TestCategory id for question with question_id = $questionId
@@ -251,210 +251,210 @@  discard block
 block discarded – undo
251 251
      *
252 252
      * @return int
253 253
      */
254
-	public static function getCategoryForQuestion($questionId, $courseId ="")
254
+    public static function getCategoryForQuestion($questionId, $courseId ="")
255 255
     {
256
-		$result = 0;
256
+        $result = 0;
257 257
         if (empty($courseId) || $courseId == "") {
258 258
             $courseId = api_get_course_int_id();
259 259
         }
260
-		$table = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
260
+        $table = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
261 261
         $questionId = intval($questionId);
262
-		$sql = "SELECT category_id
262
+        $sql = "SELECT category_id
263 263
 		        FROM $table
264 264
 		        WHERE question_id = $questionId AND c_id = $courseId";
265
-		$res = Database::query($sql);
266
-		if (Database::num_rows($res) > 0) {
265
+        $res = Database::query($sql);
266
+        if (Database::num_rows($res) > 0) {
267 267
             $data = Database::fetch_array($res);
268
-			$result = $data['category_id'];
269
-		}
268
+            $result = $data['category_id'];
269
+        }
270 270
 
271
-		return $result;
272
-	}
271
+        return $result;
272
+    }
273 273
 
274
-	/**
275
-	 * true if question id has a category
276
-	 */
277
-	public static function isQuestionHasCategory($questionId)
274
+    /**
275
+     * true if question id has a category
276
+     */
277
+    public static function isQuestionHasCategory($questionId)
278 278
     {
279
-		if (TestCategory::getCategoryForQuestion($questionId) > 0) {
280
-			return true;
281
-		}
282
-		return false;
283
-	}
279
+        if (TestCategory::getCategoryForQuestion($questionId) > 0) {
280
+            return true;
281
+        }
282
+        return false;
283
+    }
284 284
 
285
-	/**
285
+    /**
286 286
 	 Return the category name for question with question_id = $questionId
287 287
 	 In this version, a question has only 1 category.
288 288
 	 Return the category id, "" if none
289
-	 */
289
+     */
290 290
     public static function getCategoryNameForQuestion(
291 291
         $questionId,
292 292
         $courseId = ""
293 293
     ) {
294
-		if (empty($courseId) || $courseId=="") {
295
-			$courseId = api_get_course_int_id();
296
-		}
297
-		$catid = TestCategory::getCategoryForQuestion($questionId, $courseId);
298
-		$result = "";	// result
299
-		$table = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
300
-		$catid = intval($catid);
301
-		$sql = "SELECT title FROM $table
294
+        if (empty($courseId) || $courseId=="") {
295
+            $courseId = api_get_course_int_id();
296
+        }
297
+        $catid = TestCategory::getCategoryForQuestion($questionId, $courseId);
298
+        $result = "";	// result
299
+        $table = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
300
+        $catid = intval($catid);
301
+        $sql = "SELECT title FROM $table
302 302
 		        WHERE id = $catid  AND c_id = $courseId";
303
-		$res = Database::query($sql);
304
-		$data = Database::fetch_array($res);
305
-		if (Database::num_rows($res) > 0) {
306
-			$result = $data['title'];
307
-		}
308
-
309
-		return $result;
310
-	}
311
-
312
-	/**
313
-	 * Return the list of differents categories ID for a test in the current course
314
-	 * input : test_id
315
-	 * return : array of category id (integer)
316
-	 * hubert.borderiou 07-04-2011
317
-	 * @param int $exerciseId
318
-	 */
319
-	public static function getListOfCategoriesIDForTest($exerciseId)
303
+        $res = Database::query($sql);
304
+        $data = Database::fetch_array($res);
305
+        if (Database::num_rows($res) > 0) {
306
+            $result = $data['title'];
307
+        }
308
+
309
+        return $result;
310
+    }
311
+
312
+    /**
313
+     * Return the list of differents categories ID for a test in the current course
314
+     * input : test_id
315
+     * return : array of category id (integer)
316
+     * hubert.borderiou 07-04-2011
317
+     * @param int $exerciseId
318
+     */
319
+    public static function getListOfCategoriesIDForTest($exerciseId)
320 320
     {
321
-		// parcourir les questions d'un test, recup les categories uniques dans un tableau
322
-		$exercise = new Exercise();
323
-		$exercise->read($exerciseId, false);
324
-		$categoriesInExercise = $exercise->getQuestionWithCategories();
325
-		// the array given by selectQuestionList start at indice 1 and not at indice 0 !!! ???
326
-		$categories = array();
321
+        // parcourir les questions d'un test, recup les categories uniques dans un tableau
322
+        $exercise = new Exercise();
323
+        $exercise->read($exerciseId, false);
324
+        $categoriesInExercise = $exercise->getQuestionWithCategories();
325
+        // the array given by selectQuestionList start at indice 1 and not at indice 0 !!! ???
326
+        $categories = array();
327 327
         if (!empty($categoriesInExercise)) {
328
-			foreach ($categoriesInExercise as $category) {
329
-				//$category['id'] = $category['iid'];
330
-				$categories[$category['id']] = $category;
331
-			}
332
-		}
333
-
334
-		return $categories;
335
-	}
336
-
337
-	/**
338
-	 * @param Exercise $exercise_obj
339
-	 * @return array
340
-	 */
341
-	public static function getListOfCategoriesIDForTestObject(Exercise $exercise_obj)
342
-	{
343
-		// parcourir les questions d'un test, recup les categories uniques dans un tableau
344
-		$categories_in_exercise = array();
345
-		// $question_list = $exercise_obj->getQuestionList();
346
-		$question_list = $exercise_obj->getQuestionOrderedListByName();
347
-
348
-		// the array given by selectQuestionList start at indice 1 and not at indice 0 !!! ???
349
-		foreach ($question_list as $questionInfo) {
350
-			$question_id = $questionInfo['question_id'];
351
-			$category_list = self::getCategoryForQuestion($question_id);
352
-			if (is_numeric($category_list)) {
353
-				$category_list = array($category_list);
354
-			}
355
-
356
-			if (!empty($category_list)) {
357
-				$categories_in_exercise = array_merge($categories_in_exercise, $category_list);
358
-			}
359
-		}
360
-		if (!empty($categories_in_exercise)) {
361
-			$categories_in_exercise = array_unique(array_filter($categories_in_exercise));
362
-		}
363
-		return $categories_in_exercise;
364
-	}
365
-
366
-	/**
367
-	 * Return the list of differents categories NAME for a test
368
-	 * @param int exercise id
369
-	 * @param bool
370
-	 * @return integer of string
371
-	 *
328
+            foreach ($categoriesInExercise as $category) {
329
+                //$category['id'] = $category['iid'];
330
+                $categories[$category['id']] = $category;
331
+            }
332
+        }
333
+
334
+        return $categories;
335
+    }
336
+
337
+    /**
338
+     * @param Exercise $exercise_obj
339
+     * @return array
340
+     */
341
+    public static function getListOfCategoriesIDForTestObject(Exercise $exercise_obj)
342
+    {
343
+        // parcourir les questions d'un test, recup les categories uniques dans un tableau
344
+        $categories_in_exercise = array();
345
+        // $question_list = $exercise_obj->getQuestionList();
346
+        $question_list = $exercise_obj->getQuestionOrderedListByName();
347
+
348
+        // the array given by selectQuestionList start at indice 1 and not at indice 0 !!! ???
349
+        foreach ($question_list as $questionInfo) {
350
+            $question_id = $questionInfo['question_id'];
351
+            $category_list = self::getCategoryForQuestion($question_id);
352
+            if (is_numeric($category_list)) {
353
+                $category_list = array($category_list);
354
+            }
355
+
356
+            if (!empty($category_list)) {
357
+                $categories_in_exercise = array_merge($categories_in_exercise, $category_list);
358
+            }
359
+        }
360
+        if (!empty($categories_in_exercise)) {
361
+            $categories_in_exercise = array_unique(array_filter($categories_in_exercise));
362
+        }
363
+        return $categories_in_exercise;
364
+    }
365
+
366
+    /**
367
+     * Return the list of differents categories NAME for a test
368
+     * @param int exercise id
369
+     * @param bool
370
+     * @return integer of string
371
+     *
372 372
      * @author function rewrote by jmontoya
373
-	 */
374
-	public static function getListOfCategoriesNameForTest($exercise_id, $grouped_by_category = true)
373
+     */
374
+    public static function getListOfCategoriesNameForTest($exercise_id, $grouped_by_category = true)
375 375
     {
376
-		$result = array();
377
-		$categories = self::getListOfCategoriesIDForTest($exercise_id, $grouped_by_category);
376
+        $result = array();
377
+        $categories = self::getListOfCategoriesIDForTest($exercise_id, $grouped_by_category);
378 378
 
379
-		foreach ($categories as $catInfo) {
380
-			$categoryId = $catInfo['id'];
381
-			if (!empty($categoryId)) {
382
-				$result[$categoryId] = array(
379
+        foreach ($categories as $catInfo) {
380
+            $categoryId = $catInfo['id'];
381
+            if (!empty($categoryId)) {
382
+                $result[$categoryId] = array(
383 383
                     'title' => $catInfo['title'],
384 384
                     //'parent_id' =>  $catInfo['parent_id'],
385
-					'parent_id' => '',
385
+                    'parent_id' => '',
386 386
                     'c_id' => $catInfo['c_id']
387 387
                 );
388
-		}
389
-		}
390
-
391
-		return $result;
392
-	}
393
-
394
-	/**
395
-	 * @param Exercise $exercise_obj
396
-	 * @return array
397
-	 */
398
-	public static function getListOfCategoriesForTest(Exercise $exercise_obj)
399
-	{
400
-		$result = array();
401
-		$categories = self::getListOfCategoriesIDForTestObject($exercise_obj);
402
-		foreach ($categories as $cat_id) {
403
-			$cat = new TestCategory($cat_id);
404
-			$cat = (array)$cat;
405
-			$cat['iid'] = $cat['id'];
406
-			$cat['title'] = $cat['name'];
407
-			$result[$cat['id']] = $cat;
408
-		}
409
-		return $result;
410
-	}
411
-
412
-	/**
413
-	 * return the number of differents categories for a test
414
-	 * input : test_id
415
-	 * return : integer
416
-	 * hubert.borderiou 07-04-2011
417
-	 */
418
-	public static function getNumberOfCategoriesForTest($id)
388
+        }
389
+        }
390
+
391
+        return $result;
392
+    }
393
+
394
+    /**
395
+     * @param Exercise $exercise_obj
396
+     * @return array
397
+     */
398
+    public static function getListOfCategoriesForTest(Exercise $exercise_obj)
399
+    {
400
+        $result = array();
401
+        $categories = self::getListOfCategoriesIDForTestObject($exercise_obj);
402
+        foreach ($categories as $cat_id) {
403
+            $cat = new TestCategory($cat_id);
404
+            $cat = (array)$cat;
405
+            $cat['iid'] = $cat['id'];
406
+            $cat['title'] = $cat['name'];
407
+            $result[$cat['id']] = $cat;
408
+        }
409
+        return $result;
410
+    }
411
+
412
+    /**
413
+     * return the number of differents categories for a test
414
+     * input : test_id
415
+     * return : integer
416
+     * hubert.borderiou 07-04-2011
417
+     */
418
+    public static function getNumberOfCategoriesForTest($id)
419 419
     {
420
-		return count(TestCategory::getListOfCategoriesIDForTest($id));
421
-	}
420
+        return count(TestCategory::getListOfCategoriesIDForTest($id));
421
+    }
422 422
 
423
-	/**
424
-	 * return the number of question of a category id in a test
425
-	 * @param int $exerciseId
423
+    /**
424
+     * return the number of question of a category id in a test
425
+     * @param int $exerciseId
426 426
      * @param int $categoryId
427 427
      *
428
-	 * @return integer
428
+     * @return integer
429 429
      *
430
-	 * @author hubert.borderiou 07-04-2011
431
-	 */
432
-	public static function getNumberOfQuestionsInCategoryForTest($exerciseId, $categoryId)
430
+     * @author hubert.borderiou 07-04-2011
431
+     */
432
+    public static function getNumberOfQuestionsInCategoryForTest($exerciseId, $categoryId)
433 433
     {
434
-		$nbCatResult = 0;
435
-		$quiz = new Exercise();
436
-		$quiz->read($exerciseId);
437
-		$tabQuestionList = $quiz->selectQuestionList();
438
-		// the array given by selectQuestionList start at indice 1 and not at indice 0 !!! ? ? ?
439
-		for ($i=1; $i <= count($tabQuestionList); $i++) {
440
-			if (TestCategory::getCategoryForQuestion($tabQuestionList[$i]) == $categoryId) {
441
-				$nbCatResult++;
442
-			}
443
-		}
444
-
445
-		return $nbCatResult;
446
-	}
447
-
448
-	/**
449
-	 * return the number of question for a test using random by category
450
-	 * input  : test_id, number of random question (min 1)
451
-	 * hubert.borderiou 07-04-2011
452
-	 * question without categories are not counted
453
-	 */
454
-	public static function getNumberOfQuestionRandomByCategory($exerciseId, $in_nbrandom)
434
+        $nbCatResult = 0;
435
+        $quiz = new Exercise();
436
+        $quiz->read($exerciseId);
437
+        $tabQuestionList = $quiz->selectQuestionList();
438
+        // the array given by selectQuestionList start at indice 1 and not at indice 0 !!! ? ? ?
439
+        for ($i=1; $i <= count($tabQuestionList); $i++) {
440
+            if (TestCategory::getCategoryForQuestion($tabQuestionList[$i]) == $categoryId) {
441
+                $nbCatResult++;
442
+            }
443
+        }
444
+
445
+        return $nbCatResult;
446
+    }
447
+
448
+    /**
449
+     * return the number of question for a test using random by category
450
+     * input  : test_id, number of random question (min 1)
451
+     * hubert.borderiou 07-04-2011
452
+     * question without categories are not counted
453
+     */
454
+    public static function getNumberOfQuestionRandomByCategory($exerciseId, $in_nbrandom)
455 455
     {
456
-		$nbquestionresult = 0;
457
-		$tabcatid = TestCategory::getListOfCategoriesIDForTest($exerciseId);
456
+        $nbquestionresult = 0;
457
+        $tabcatid = TestCategory::getListOfCategoriesIDForTest($exerciseId);
458 458
 
459 459
         foreach ($tabcatid as $category) {
460 460
             if (empty($category['id'])) {
@@ -470,30 +470,30 @@  discard block
 block discarded – undo
470 470
             }
471 471
         }
472 472
 
473
-		return $nbquestionresult;
474
-	}
473
+        return $nbquestionresult;
474
+    }
475 475
 
476
-	/**
477
-	 * Return an array (id=>name)
478
-	 * tabresult[0] = get_lang('NoCategory');
476
+    /**
477
+     * Return an array (id=>name)
478
+     * tabresult[0] = get_lang('NoCategory');
479 479
      *
480 480
      * @param int $courseId
481 481
      *
482 482
      * @return array
483
-	 *
484
-	 */
483
+     *
484
+     */
485 485
     public static function getCategoriesIdAndName($courseId = "")
486 486
     {
487
-		if (empty($courseId)) {
488
-			$courseId = api_get_course_int_id();
489
-		}
490
-	 	$tabcatobject = TestCategory::getCategoryListInfo("", $courseId);
491
-	 	$tabresult = array("0"=>get_lang('NoCategorySelected'));
492
-	 	for ($i=0; $i < count($tabcatobject); $i++) {
493
-	 		$tabresult[$tabcatobject[$i]->id] = $tabcatobject[$i]->name;
494
-	 	}
495
-	 	return $tabresult;
496
-	}
487
+        if (empty($courseId)) {
488
+            $courseId = api_get_course_int_id();
489
+        }
490
+            $tabcatobject = TestCategory::getCategoryListInfo("", $courseId);
491
+            $tabresult = array("0"=>get_lang('NoCategorySelected'));
492
+            for ($i=0; $i < count($tabcatobject); $i++) {
493
+                $tabresult[$tabcatobject[$i]->id] = $tabcatobject[$i]->name;
494
+            }
495
+            return $tabresult;
496
+    }
497 497
 
498 498
     /**
499 499
      * Returns an array of question ids for each category
@@ -502,10 +502,10 @@  discard block
 block discarded – undo
502 502
      * @param int exercise
503 503
      * @param array $check_in_question_list
504 504
      * @param array $categoriesAddedInExercise
505
-    *
506
-    * @param int $exerciseId
507
-    * @return array
508
-    */
505
+     *
506
+     * @param int $exerciseId
507
+     * @return array
508
+     */
509 509
     static function getQuestionsByCat(
510 510
         $exerciseId,
511 511
         $check_in_question_list = array(),
@@ -583,28 +583,28 @@  discard block
 block discarded – undo
583 583
         }
584 584
 
585 585
         return $categories;
586
-	}
586
+    }
587 587
 
588
-	/**
589
-	 * return a tab of $in_number random elements of $in_tab
590
-	 */
588
+    /**
589
+     * return a tab of $in_number random elements of $in_tab
590
+     */
591 591
     public static function getNElementsFromArray($in_tab, $in_number)
592 592
     {
593
-		$tabres = $in_tab;
594
-		shuffle($tabres);
595
-		if ($in_number < count($tabres)) {
596
-			$tabres = array_slice($tabres, 0, $in_number);
597
-		}
598
-		return $tabres;
599
-	}
600
-
601
-	/**
602
-	 * display the category
603
-	 */
604
-	public static function displayCategoryAndTitle($questionId, $in_display_category_name = 1)
593
+        $tabres = $in_tab;
594
+        shuffle($tabres);
595
+        if ($in_number < count($tabres)) {
596
+            $tabres = array_slice($tabres, 0, $in_number);
597
+        }
598
+        return $tabres;
599
+    }
600
+
601
+    /**
602
+     * display the category
603
+     */
604
+    public static function displayCategoryAndTitle($questionId, $in_display_category_name = 1)
605 605
     {
606 606
         echo self::returnCategoryAndTitle($questionId, $in_display_category_name);
607
-	}
607
+    }
608 608
 
609 609
     /**
610 610
      * @param int $questionId
@@ -620,90 +620,90 @@  discard block
 block discarded – undo
620 620
             $in_display_category_name = $objExercise->display_category_name;
621 621
         }
622 622
         $content = null;
623
-		if (TestCategory::getCategoryNameForQuestion($questionId) != "" && ($in_display_category_name == 1 || !$is_student)) {
623
+        if (TestCategory::getCategoryNameForQuestion($questionId) != "" && ($in_display_category_name == 1 || !$is_student)) {
624 624
             $content .= '<div class="page-header">';
625 625
             $content .= '<h4>'.get_lang('Category').": ".TestCategory::getCategoryNameForQuestion($questionId).'</h4>';
626 626
             $content .= "</div>";
627
-		}
627
+        }
628 628
         return $content;
629
-	}
629
+    }
630 630
 
631 631
     /**
632
-    * Display signs [+] and/or (>0) after question title if question has options
633
-    * scoreAlwaysPositive and/or uncheckedMayScore
634
-    */
632
+     * Display signs [+] and/or (>0) after question title if question has options
633
+     * scoreAlwaysPositive and/or uncheckedMayScore
634
+     */
635 635
     public function displayQuestionOption($in_objQuestion)
636 636
     {
637
-		if ($in_objQuestion->type == MULTIPLE_ANSWER && $in_objQuestion->scoreAlwaysPositive) {
638
-			echo "<span style='font-size:75%'> (>0)</span>";
639
-		}
640
-		if ($in_objQuestion->type == MULTIPLE_ANSWER && $in_objQuestion->uncheckedMayScore) {
641
-			echo "<span style='font-size:75%'> [+]</span>";
642
-		}
643
-	}
644
-
645
-	/**
646
-	 * sortTabByBracketLabel ($tabCategoryQuestions)
647
-	 * key of $tabCategoryQuestions are the category id (0 for not in a category)
648
-	 * value is the array of question id of this category
649
-	 * Sort question by Category
650
-	*/
637
+        if ($in_objQuestion->type == MULTIPLE_ANSWER && $in_objQuestion->scoreAlwaysPositive) {
638
+            echo "<span style='font-size:75%'> (>0)</span>";
639
+        }
640
+        if ($in_objQuestion->type == MULTIPLE_ANSWER && $in_objQuestion->uncheckedMayScore) {
641
+            echo "<span style='font-size:75%'> [+]</span>";
642
+        }
643
+    }
644
+
645
+    /**
646
+     * sortTabByBracketLabel ($tabCategoryQuestions)
647
+     * key of $tabCategoryQuestions are the category id (0 for not in a category)
648
+     * value is the array of question id of this category
649
+     * Sort question by Category
650
+     */
651 651
     public static function sortTabByBracketLabel($in_tab)
652 652
     {
653
-		$tabResult = array();
654
-		$tabCatName = array();	// tab of category name
655
-		while (list($cat_id, $tabquestion) = each($in_tab)) {
656
-			$catTitle = new TestCategory($cat_id);
657
-			$tabCatName[$cat_id] = $catTitle->name;
658
-		}
659
-		reset($in_tab);
660
-		// sort table by value, keeping keys as they are
661
-		asort($tabCatName);
662
-		// keys of $tabCatName are keys order for $in_tab
663
-		while (list($key, $val) = each($tabCatName)) {
664
-			$tabResult[$key] = $in_tab[$key];
665
-		}
666
-		return $tabResult;
667
-	}
653
+        $tabResult = array();
654
+        $tabCatName = array();	// tab of category name
655
+        while (list($cat_id, $tabquestion) = each($in_tab)) {
656
+            $catTitle = new TestCategory($cat_id);
657
+            $tabCatName[$cat_id] = $catTitle->name;
658
+        }
659
+        reset($in_tab);
660
+        // sort table by value, keeping keys as they are
661
+        asort($tabCatName);
662
+        // keys of $tabCatName are keys order for $in_tab
663
+        while (list($key, $val) = each($tabCatName)) {
664
+            $tabResult[$key] = $in_tab[$key];
665
+        }
666
+        return $tabResult;
667
+    }
668 668
 
669 669
     /**
670
-	 * return total score for test exe_id for all question in the category $in_cat_id for user
671
-	 * If no question for this category, return ""
672
-	 */
673
-	public static function getCatScoreForExeidForUserid($in_cat_id, $in_exe_id, $in_user_id)
674
-	{
675
-		$tbl_track_attempt		= Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
676
-		$tbl_question_rel_category = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
677
-		$in_cat_id = intval($in_cat_id);
678
-		$in_exe_id = intval($in_exe_id);
679
-		$in_user_id = intval($in_user_id);
680
-
681
-		$query = "SELECT DISTINCT
670
+     * return total score for test exe_id for all question in the category $in_cat_id for user
671
+     * If no question for this category, return ""
672
+     */
673
+    public static function getCatScoreForExeidForUserid($in_cat_id, $in_exe_id, $in_user_id)
674
+    {
675
+        $tbl_track_attempt		= Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
676
+        $tbl_question_rel_category = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
677
+        $in_cat_id = intval($in_cat_id);
678
+        $in_exe_id = intval($in_exe_id);
679
+        $in_user_id = intval($in_user_id);
680
+
681
+        $query = "SELECT DISTINCT
682 682
 		            marks, exe_id, user_id, ta.question_id, category_id
683 683
                   FROM $tbl_track_attempt ta , $tbl_question_rel_category qrc
684 684
                   WHERE
685 685
                     ta.question_id=qrc.question_id AND
686 686
                     qrc.category_id=$in_cat_id AND
687 687
                     exe_id=$in_exe_id AND user_id=$in_user_id";
688
-		$res = Database::query($query);
689
-		$totalcatscore = "";
690
-		while ($data = Database::fetch_array($res)) {
691
-			$totalcatscore += $data['marks'];
692
-		}
693
-		return $totalcatscore;
694
-	}
695
-
696
-	/**
688
+        $res = Database::query($query);
689
+        $totalcatscore = "";
690
+        while ($data = Database::fetch_array($res)) {
691
+            $totalcatscore += $data['marks'];
692
+        }
693
+        return $totalcatscore;
694
+    }
695
+
696
+    /**
697 697
      * return the number max of question in a category
698 698
      * count the number of questions in all categories, and return the max
699 699
      * @param int $exerciseId
700 700
      * @author - hubert borderiou
701
-    */
701
+     */
702 702
     public static function getNumberMaxQuestionByCat($exerciseId)
703 703
     {
704 704
         $res_num_max = 0;
705 705
         // foreach question
706
-		$tabcatid = TestCategory::getListOfCategoriesIDForTest($exerciseId);
706
+        $tabcatid = TestCategory::getListOfCategoriesIDForTest($exerciseId);
707 707
 
708 708
         foreach ($tabcatid as $category) {
709 709
             if (empty($category['id'])) {
@@ -775,34 +775,34 @@  discard block
 block discarded – undo
775 775
     }
776 776
 
777 777
     /**
778
-	 * @return array
779
-	 */
780
-	function get_all_categories()
781
-	{
782
-		$table = Database::get_course_table(TABLE_QUIZ_CATEGORY);
783
-		$sql = "SELECT * FROM $table ORDER BY title ASC";
784
-		$res = Database::query($sql);
785
-		while ($row = Database::fetch_array($res,'ASSOC')) {
786
-			$array[] = $row;
787
-		}
788
-		return $array;
789
-	}
790
-
791
-	/**
792
-	 * @param Exercise $exercise
793
-	 * @param int $course_id
794
-	 * @param string $order
795
-	 * @param bool $shuffle
796
-	 * @param bool $excludeCategoryWithNoQuestions
797
-	 * @return array|bool
798
-	 */
799
-	public function getCategoryExerciseTree(
800
-		$exercise,
801
-		$course_id,
802
-		$order = null,
803
-		$shuffle = false,
804
-		$excludeCategoryWithNoQuestions = true
805
-	) {
778
+     * @return array
779
+     */
780
+    function get_all_categories()
781
+    {
782
+        $table = Database::get_course_table(TABLE_QUIZ_CATEGORY);
783
+        $sql = "SELECT * FROM $table ORDER BY title ASC";
784
+        $res = Database::query($sql);
785
+        while ($row = Database::fetch_array($res,'ASSOC')) {
786
+            $array[] = $row;
787
+        }
788
+        return $array;
789
+    }
790
+
791
+    /**
792
+     * @param Exercise $exercise
793
+     * @param int $course_id
794
+     * @param string $order
795
+     * @param bool $shuffle
796
+     * @param bool $excludeCategoryWithNoQuestions
797
+     * @return array|bool
798
+     */
799
+    public function getCategoryExerciseTree(
800
+        $exercise,
801
+        $course_id,
802
+        $order = null,
803
+        $shuffle = false,
804
+        $excludeCategoryWithNoQuestions = true
805
+    ) {
806 806
         if (empty($exercise)) {
807 807
             return array();
808 808
         }
@@ -812,165 +812,165 @@  discard block
 block discarded – undo
812 812
         }
813 813
 
814 814
         $course_id = intval($course_id);
815
-		$table = Database::get_course_table(TABLE_QUIZ_REL_CATEGORY);
815
+        $table = Database::get_course_table(TABLE_QUIZ_REL_CATEGORY);
816 816
         $categoryTable = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
817
-		$sql = "SELECT * FROM $table qc
817
+        $sql = "SELECT * FROM $table qc
818 818
               	LEFT JOIN $categoryTable c
819 819
                 ON (qc.c_id = c.c_id AND c.id = qc.category_id)
820 820
                 WHERE qc.c_id = $course_id AND exercise_id = {$exercise->id} ";
821 821
 
822
-		if (!empty($order)) {
823
-			$sql .= "ORDER BY $order";
824
-		}
825
-
826
-		$categories = array();
827
-
828
-		$result = Database::query($sql);
829
-		if (Database::num_rows($result)) {
830
-			while ($row = Database::fetch_array($result, 'ASSOC')) {
831
-				if ($excludeCategoryWithNoQuestions) {
832
-					if ($row['count_questions'] == 0) {
833
-						continue;
834
-					}
835
-				}
836
-				if (empty($row['title']) && empty($row['category_id'])) {
837
-					$row['title'] = get_lang('NoCategory');
838
-				}
822
+        if (!empty($order)) {
823
+            $sql .= "ORDER BY $order";
824
+        }
825
+
826
+        $categories = array();
827
+
828
+        $result = Database::query($sql);
829
+        if (Database::num_rows($result)) {
830
+            while ($row = Database::fetch_array($result, 'ASSOC')) {
831
+                if ($excludeCategoryWithNoQuestions) {
832
+                    if ($row['count_questions'] == 0) {
833
+                        continue;
834
+                    }
835
+                }
836
+                if (empty($row['title']) && empty($row['category_id'])) {
837
+                    $row['title'] = get_lang('NoCategory');
838
+                }
839 839
                 $categories[$row['category_id']] = $row;
840
-			}
841
-		}
842
-
843
-		if ($shuffle) {
844
-			shuffle_assoc($categories);
845
-		}
846
-
847
-		return $categories;
848
-	}
849
-
850
-	public function getForm(& $form, $action = 'new')
851
-	{
852
-		switch($action) {
853
-			case 'new':
854
-				$header = get_lang('AddACategory');
855
-				$submit = get_lang('AddTestCategory');
856
-				break;
857
-			case 'edit':
858
-				$header = get_lang('EditCategory');
859
-				$submit = get_lang('ModifyCategory');
860
-				break;
861
-		}
862
-
863
-		// settting the form elements
864
-		$form->addElement('header', $header);
865
-		$form->addElement('hidden', 'category_id');
866
-		$form->addElement('text', 'category_name', get_lang('CategoryName'), array('class' => 'span6'));
867
-		$form->add_html_editor('category_description', get_lang('CategoryDescription'), false, false, array('ToolbarSet' => 'test_category', 'Width' => '90%', 'Height' => '200'));
868
-		$category_parent_list = array();
869
-
870
-		$options = array(
871
-				'1' => get_lang('Visible'),
872
-				'0' => get_lang('Hidden')
873
-		);
874
-		$form->addElement('select', 'visibility', get_lang('Visibility'), $options);
875
-		$script = null;
876
-		if (!empty($this->parent_id)) {
877
-			$parent_cat = new TestCategory($this->parent_id);
878
-			$category_parent_list = array($parent_cat->id => $parent_cat->name);
879
-			$script .= '<script>$(function() { $("#parent_id").trigger("addItem",[{"title": "'.$parent_cat->name.'", "value": "'.$parent_cat->id.'"}]); });</script>';
880
-		}
881
-		$form->addElement('html', $script);
882
-
883
-		$form->addElement('select', 'parent_id', get_lang('Parent'), $category_parent_list, array('id' => 'parent_id'));
884
-		$form->addElement('style_submit_button', 'SubmitNote', $submit, 'class="add"');
885
-
886
-		// setting the defaults
887
-		$defaults = array();
888
-		$defaults["category_id"] = $this->id;
889
-		$defaults["category_name"] = $this->name;
890
-		$defaults["category_description"] = $this->description;
891
-		$defaults["parent_id"] = $this->parent_id;
892
-		$defaults["visibility"] = $this->visibility;
893
-		$form->setDefaults($defaults);
894
-
895
-		// setting the rules
896
-		$form->addRule('category_name', get_lang('ThisFieldIsRequired'), 'required');
897
-	}
898
-
899
-	/**
900
-	 * Returns the category form.
901
-	 * @param Exercise $exercise_obj
902
-	 * @return string
903
-	 */
904
-	public function returnCategoryForm(Exercise $exercise_obj)
905
-	{
906
-		$categories = $this->getListOfCategoriesForTest($exercise_obj);
907
-
908
-		$saved_categories = $exercise_obj->get_categories_in_exercise();
909
-		$return = null;
910
-
911
-		if (!empty($categories)) {
912
-			$nbQuestionsTotal = $exercise_obj->getNumberQuestionExerciseCategory();
913
-			$exercise_obj->setCategoriesGrouping(true);
914
-			$real_question_count = count($exercise_obj->getQuestionList());
915
-
916
-			$warning = null;
917
-			if ($nbQuestionsTotal != $real_question_count) {
918
-				$warning = Display::return_message(get_lang('CheckThatYouHaveEnoughQuestionsInYourCategories'), 'warning');
919
-			}
920
-
921
-			$return .= $warning;
922
-			$return .= '<table class="data_table">';
923
-			$return .= '<tr>';
924
-			$return .= '<th height="24">' . get_lang('Categories') . '</th>';
925
-			$return .= '<th width="70" height="24">' . get_lang('Number') . '</th></tr>';
926
-
927
-			$emptyCategory = array(
928
-				'id' => '0',
929
-				'name' => get_lang('NoCategory'),
930
-				'description' => '',
931
-				'iid' => '0',
932
-				'title' => get_lang('NoCategory')
933
-			);
934
-
935
-			$categories[] = $emptyCategory;
936
-
937
-			foreach ($categories as $category) {
938
-				$cat_id = $category['iid'];
939
-				$return .= '<tr>';
940
-				$return .= '<td>';
941
-				//$return .= Display::div(isset($category['parent_path']) ? $category['parent_path'] : '');
942
-				$return .= Display::div($category['name']);
943
-				$return .= '</td>';
944
-				$return .= '<td>';
945
-				$value = isset($saved_categories) && isset($saved_categories[$cat_id]) ? $saved_categories[$cat_id]['count_questions'] : -1;
946
-				$return .= '<input name="category['.$cat_id.']" value="' .$value.'" />';
947
-				$return .= '</td>';
948
-				$return .= '</tr>';
949
-			}
950
-
951
-			$return .= '</table>';
952
-			$return .= get_lang('ZeroMeansNoQuestionWillBeSelectedMinusOneMeansThatAllQuestionsWillBeSelected');
953
-			return $return;
954
-		}
955
-	}
956
-
957
-	/**
958
-	 * Sorts an array
959
-	 * @param $array
960
-	 * @return mixed
961
-	 */
962
-	public function sort_tree_array($array)
963
-	{
964
-		foreach ($array as $key => $row) {
965
-			$parent[$key] = $row['parent_id'];
966
-		}
967
-		if (count($array) > 0) {
968
-			array_multisort($parent, SORT_ASC, $array);
969
-		}
970
-		return $array;
971
-	}
972
-
973
-	/**
840
+            }
841
+        }
842
+
843
+        if ($shuffle) {
844
+            shuffle_assoc($categories);
845
+        }
846
+
847
+        return $categories;
848
+    }
849
+
850
+    public function getForm(& $form, $action = 'new')
851
+    {
852
+        switch($action) {
853
+            case 'new':
854
+                $header = get_lang('AddACategory');
855
+                $submit = get_lang('AddTestCategory');
856
+                break;
857
+            case 'edit':
858
+                $header = get_lang('EditCategory');
859
+                $submit = get_lang('ModifyCategory');
860
+                break;
861
+        }
862
+
863
+        // settting the form elements
864
+        $form->addElement('header', $header);
865
+        $form->addElement('hidden', 'category_id');
866
+        $form->addElement('text', 'category_name', get_lang('CategoryName'), array('class' => 'span6'));
867
+        $form->add_html_editor('category_description', get_lang('CategoryDescription'), false, false, array('ToolbarSet' => 'test_category', 'Width' => '90%', 'Height' => '200'));
868
+        $category_parent_list = array();
869
+
870
+        $options = array(
871
+                '1' => get_lang('Visible'),
872
+                '0' => get_lang('Hidden')
873
+        );
874
+        $form->addElement('select', 'visibility', get_lang('Visibility'), $options);
875
+        $script = null;
876
+        if (!empty($this->parent_id)) {
877
+            $parent_cat = new TestCategory($this->parent_id);
878
+            $category_parent_list = array($parent_cat->id => $parent_cat->name);
879
+            $script .= '<script>$(function() { $("#parent_id").trigger("addItem",[{"title": "'.$parent_cat->name.'", "value": "'.$parent_cat->id.'"}]); });</script>';
880
+        }
881
+        $form->addElement('html', $script);
882
+
883
+        $form->addElement('select', 'parent_id', get_lang('Parent'), $category_parent_list, array('id' => 'parent_id'));
884
+        $form->addElement('style_submit_button', 'SubmitNote', $submit, 'class="add"');
885
+
886
+        // setting the defaults
887
+        $defaults = array();
888
+        $defaults["category_id"] = $this->id;
889
+        $defaults["category_name"] = $this->name;
890
+        $defaults["category_description"] = $this->description;
891
+        $defaults["parent_id"] = $this->parent_id;
892
+        $defaults["visibility"] = $this->visibility;
893
+        $form->setDefaults($defaults);
894
+
895
+        // setting the rules
896
+        $form->addRule('category_name', get_lang('ThisFieldIsRequired'), 'required');
897
+    }
898
+
899
+    /**
900
+     * Returns the category form.
901
+     * @param Exercise $exercise_obj
902
+     * @return string
903
+     */
904
+    public function returnCategoryForm(Exercise $exercise_obj)
905
+    {
906
+        $categories = $this->getListOfCategoriesForTest($exercise_obj);
907
+
908
+        $saved_categories = $exercise_obj->get_categories_in_exercise();
909
+        $return = null;
910
+
911
+        if (!empty($categories)) {
912
+            $nbQuestionsTotal = $exercise_obj->getNumberQuestionExerciseCategory();
913
+            $exercise_obj->setCategoriesGrouping(true);
914
+            $real_question_count = count($exercise_obj->getQuestionList());
915
+
916
+            $warning = null;
917
+            if ($nbQuestionsTotal != $real_question_count) {
918
+                $warning = Display::return_message(get_lang('CheckThatYouHaveEnoughQuestionsInYourCategories'), 'warning');
919
+            }
920
+
921
+            $return .= $warning;
922
+            $return .= '<table class="data_table">';
923
+            $return .= '<tr>';
924
+            $return .= '<th height="24">' . get_lang('Categories') . '</th>';
925
+            $return .= '<th width="70" height="24">' . get_lang('Number') . '</th></tr>';
926
+
927
+            $emptyCategory = array(
928
+                'id' => '0',
929
+                'name' => get_lang('NoCategory'),
930
+                'description' => '',
931
+                'iid' => '0',
932
+                'title' => get_lang('NoCategory')
933
+            );
934
+
935
+            $categories[] = $emptyCategory;
936
+
937
+            foreach ($categories as $category) {
938
+                $cat_id = $category['iid'];
939
+                $return .= '<tr>';
940
+                $return .= '<td>';
941
+                //$return .= Display::div(isset($category['parent_path']) ? $category['parent_path'] : '');
942
+                $return .= Display::div($category['name']);
943
+                $return .= '</td>';
944
+                $return .= '<td>';
945
+                $value = isset($saved_categories) && isset($saved_categories[$cat_id]) ? $saved_categories[$cat_id]['count_questions'] : -1;
946
+                $return .= '<input name="category['.$cat_id.']" value="' .$value.'" />';
947
+                $return .= '</td>';
948
+                $return .= '</tr>';
949
+            }
950
+
951
+            $return .= '</table>';
952
+            $return .= get_lang('ZeroMeansNoQuestionWillBeSelectedMinusOneMeansThatAllQuestionsWillBeSelected');
953
+            return $return;
954
+        }
955
+    }
956
+
957
+    /**
958
+     * Sorts an array
959
+     * @param $array
960
+     * @return mixed
961
+     */
962
+    public function sort_tree_array($array)
963
+    {
964
+        foreach ($array as $key => $row) {
965
+            $parent[$key] = $row['parent_id'];
966
+        }
967
+        if (count($array) > 0) {
968
+            array_multisort($parent, SORT_ASC, $array);
969
+        }
970
+        return $array;
971
+    }
972
+
973
+    /**
974 974
      * Return true if a category already exists with the same name
975 975
      * @param string $in_name
976 976
      *
@@ -1016,8 +1016,8 @@  discard block
 block discarded – undo
1016 1016
      * @param int $categoryId
1017 1017
      * @param int $questionId
1018 1018
      * @param int $courseId
1019
-	 *
1020
-	 * @return string|false
1019
+     *
1020
+     * @return string|false
1021 1021
      */
1022 1022
     public static function add_category_for_question_id($categoryId, $questionId, $courseId)
1023 1023
     {
@@ -1025,18 +1025,18 @@  discard block
 block discarded – undo
1025 1025
         // if question doesn't have a category
1026 1026
         // @todo change for 1.10 when a question can have several categories
1027 1027
         if (TestCategory::getCategoryForQuestion($questionId, $courseId) == 0 &&
1028
-			$questionId > 0 &&
1029
-			$courseId > 0
1028
+            $questionId > 0 &&
1029
+            $courseId > 0
1030 1030
         ) {
1031 1031
             $sql = "INSERT INTO $table (c_id, question_id, category_id)
1032 1032
                     VALUES (".intval($courseId).", ".intval($questionId).", ".intval($categoryId).")";
1033 1033
             Database::query($sql);
1034
-			$id = Database::insert_id();
1034
+            $id = Database::insert_id();
1035 1035
 
1036
-			return $id;
1036
+            return $id;
1037 1037
         }
1038 1038
 
1039
-		return false;
1039
+        return false;
1040 1040
     }
1041 1041
 
1042 1042
     /**
Please login to merge, or discard this patch.
main/dropbox/dropbox_class.inc.php 1 patch
Indentation   +423 added lines, -423 removed lines patch added patch discarded remove patch
@@ -77,20 +77,20 @@  discard block
 block discarded – undo
77 77
         }
78 78
     }
79 79
 
80
-	/**
81
-	 * private function creating a new work object
82
-	 *
83
-	 * @param int $uploader_id
84
-	 * @param string $title
85
-	 * @param string $description
86
-	 * @param string $author
87
-	 * @param string $filename
88
-	 * @param int $filesize
89
-	 *
90
-	 * @todo 	$author was originally a field but this has now been replaced by the first and lastname of the uploader (to prevent anonymous uploads)
91
-	 * 			As a consequence this parameter can be removed
92
-	 */
93
-	public function _createNewWork($uploader_id, $title, $description, $author, $filename, $filesize)
80
+    /**
81
+     * private function creating a new work object
82
+     *
83
+     * @param int $uploader_id
84
+     * @param string $title
85
+     * @param string $description
86
+     * @param string $author
87
+     * @param string $filename
88
+     * @param int $filesize
89
+     *
90
+     * @todo 	$author was originally a field but this has now been replaced by the first and lastname of the uploader (to prevent anonymous uploads)
91
+     * 			As a consequence this parameter can be removed
92
+     */
93
+    public function _createNewWork($uploader_id, $title, $description, $author, $filename, $filesize)
94 94
     {
95 95
         $dropbox_cnf = getDropboxConf();
96 96
 
@@ -108,17 +108,17 @@  discard block
 block discarded – undo
108 108
         // Check if object exists already. If it does, the old object is used
109 109
         // with updated information (authors, description, upload_date)
110 110
         $this->isOldWork = false;
111
-		$sql = "SELECT id, upload_date FROM ".$dropbox_cnf['tbl_file']."
111
+        $sql = "SELECT id, upload_date FROM ".$dropbox_cnf['tbl_file']."
112 112
 				WHERE c_id = $course_id AND filename = '".Database::escape_string($this->filename)."'";
113 113
         $result = Database::query($sql);
114
-		$res = Database::fetch_array($result);
115
-		if ($res) {
116
-			$this->isOldWork = true;
117
-		}
118
-		// Insert or update the dropbox_file table and set the id property
119
-		if ($this->isOldWork) {
120
-			$this->id = $res['id'];
121
-			$this->upload_date = $res['upload_date'];
114
+        $res = Database::fetch_array($result);
115
+        if ($res) {
116
+            $this->isOldWork = true;
117
+        }
118
+        // Insert or update the dropbox_file table and set the id property
119
+        if ($this->isOldWork) {
120
+            $this->id = $res['id'];
121
+            $this->upload_date = $res['upload_date'];
122 122
 
123 123
             $params = [
124 124
                 'filesize' => $this->filesize,
@@ -135,9 +135,9 @@  discard block
 block discarded – undo
135 135
                 ['c_id = ? AND id = ?' => [$course_id, $this->id]]
136 136
             );
137 137
 
138
-		} else {
139
-			$this->upload_date = $this->last_upload_date;
140
-			$params = [
138
+        } else {
139
+            $this->upload_date = $this->last_upload_date;
140
+            $params = [
141 141
                 'c_id' => $course_id,
142 142
                 'uploader_id' => $this->uploader_id,
143 143
                 'filename' => $this->filename,
@@ -149,14 +149,14 @@  discard block
 block discarded – undo
149 149
                 'last_upload_date' => $this->last_upload_date,
150 150
                 'session_id' => api_get_session_id(),
151 151
                 'cat_id' => 0
152
-			];
152
+            ];
153 153
 
154
-			$this->id = Database::insert($dropbox_cnf['tbl_file'], $params);
155
-			if ($this->id) {
156
-				$sql = "UPDATE ".$dropbox_cnf['tbl_file']." SET id = iid WHERE iid = {$this->id}";
157
-				Database::query($sql);
158
-			}
159
-		}
154
+            $this->id = Database::insert($dropbox_cnf['tbl_file'], $params);
155
+            if ($this->id) {
156
+                $sql = "UPDATE ".$dropbox_cnf['tbl_file']." SET id = iid WHERE iid = {$this->id}";
157
+                Database::query($sql);
158
+            }
159
+        }
160 160
 
161 161
         $sql = "SELECT count(file_id) as count
162 162
         		FROM ".$dropbox_cnf['tbl_person']."
@@ -170,16 +170,16 @@  discard block
 block discarded – undo
170 170
                     VALUES ($course_id, ".intval($this->id)." , ".intval($this->uploader_id).")";
171 171
             Database::query($sql);
172 172
         }
173
-	}
174
-
175
-	/**
176
-	 * private function creating existing object by retreiving info from db
177
-	 *
178
-	 * @param int $id
179
-	 */
180
-	public function _createExistingWork($id)
173
+    }
174
+
175
+    /**
176
+     * private function creating existing object by retreiving info from db
177
+     *
178
+     * @param int $id
179
+     */
180
+    public function _createExistingWork($id)
181 181
     {
182
-	    $course_id = api_get_course_int_id();
182
+        $course_id = api_get_course_int_id();
183 183
         $dropbox_cnf = getDropboxConf();
184 184
 
185 185
         $action = isset($_GET['action']) ? $_GET['action'] : null;
@@ -229,52 +229,52 @@  discard block
 block discarded – undo
229 229
             }
230 230
             $this->feedback2= $feedback2;
231 231
         }
232
-	}
232
+    }
233 233
 }
234 234
 
235 235
 class Dropbox_SentWork extends Dropbox_Work
236 236
 {
237
-	public $recipients;	//array of ['id']['name'] arrays
238
-
239
-	/**
240
-	 * Constructor calls private functions to create a new work or retreive an existing work from DB
241
-	 * depending on the number of parameters
242
-	 *
243
-	 * @param unknown_type $arg1
244
-	 * @param unknown_type $arg2
245
-	 * @param unknown_type $arg3
246
-	 * @param unknown_type $arg4
247
-	 * @param unknown_type $arg5
248
-	 * @param unknown_type $arg6
249
-	 * @param unknown_type $arg7
250
-	 * @return Dropbox_SentWork
251
-	 */
252
-	public function __construct($arg1, $arg2 = null, $arg3 = null, $arg4 = null, $arg5 = null, $arg6 = null, $arg7 = null)
237
+    public $recipients;	//array of ['id']['name'] arrays
238
+
239
+    /**
240
+     * Constructor calls private functions to create a new work or retreive an existing work from DB
241
+     * depending on the number of parameters
242
+     *
243
+     * @param unknown_type $arg1
244
+     * @param unknown_type $arg2
245
+     * @param unknown_type $arg3
246
+     * @param unknown_type $arg4
247
+     * @param unknown_type $arg5
248
+     * @param unknown_type $arg6
249
+     * @param unknown_type $arg7
250
+     * @return Dropbox_SentWork
251
+     */
252
+    public function __construct($arg1, $arg2 = null, $arg3 = null, $arg4 = null, $arg5 = null, $arg6 = null, $arg7 = null)
253 253
     {
254
-		if (func_num_args() > 1) {
255
-		    $this->_createNewSentWork($arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7);
256
-		} else {
257
-			$this->_createExistingSentWork($arg1);
258
-		}
259
-	}
260
-
261
-	/**
262
-	 * private function creating a new SentWork object
263
-	 *
264
-	 * @param int $uploader_id
265
-	 * @param string $title
266
-	 * @param string $description
267
-	 * @param string $author
268
-	 * @param string $filename
269
-	 * @param int $filesize
270
-	 * @param array $recipient_ids
271
-	 */
272
-	public function _createNewSentWork($uploader_id, $title, $description, $author, $filename, $filesize, $recipient_ids)
254
+        if (func_num_args() > 1) {
255
+            $this->_createNewSentWork($arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7);
256
+        } else {
257
+            $this->_createExistingSentWork($arg1);
258
+        }
259
+    }
260
+
261
+    /**
262
+     * private function creating a new SentWork object
263
+     *
264
+     * @param int $uploader_id
265
+     * @param string $title
266
+     * @param string $description
267
+     * @param string $author
268
+     * @param string $filename
269
+     * @param int $filesize
270
+     * @param array $recipient_ids
271
+     */
272
+    public function _createNewSentWork($uploader_id, $title, $description, $author, $filename, $filesize, $recipient_ids)
273 273
     {
274 274
         $dropbox_cnf = getDropboxConf();
275 275
         $_course = api_get_course_info();
276 276
 
277
-		// Call constructor of Dropbox_Work object
277
+        // Call constructor of Dropbox_Work object
278 278
         parent::__construct(
279 279
             $uploader_id,
280 280
             $title,
@@ -284,31 +284,31 @@  discard block
 block discarded – undo
284 284
             $filesize
285 285
         );
286 286
 
287
-		$course_id = api_get_course_int_id();
288
-
289
-		// Do sanity checks on recipient_ids array & property fillin
290
-		// The sanity check for ex-coursemembers is already done in base constructor
291
-		settype($uploader_id, 'integer') or die(get_lang('GeneralError').' (code 208)'); // Set $uploader_id to correct type
287
+        $course_id = api_get_course_int_id();
292 288
 
293
-		$justSubmit = false;
294
-		if ( is_int($recipient_ids)) {
295
-			$justSubmit = true;
296
-			$recipient_ids = array($recipient_ids + $this->id);
297
-		} elseif ( count($recipient_ids) == 0) {
298
-			$justSubmit = true;
299
-			$recipient_ids = array($uploader_id);
300
-		}
289
+        // Do sanity checks on recipient_ids array & property fillin
290
+        // The sanity check for ex-coursemembers is already done in base constructor
291
+        settype($uploader_id, 'integer') or die(get_lang('GeneralError').' (code 208)'); // Set $uploader_id to correct type
292
+
293
+        $justSubmit = false;
294
+        if ( is_int($recipient_ids)) {
295
+            $justSubmit = true;
296
+            $recipient_ids = array($recipient_ids + $this->id);
297
+        } elseif ( count($recipient_ids) == 0) {
298
+            $justSubmit = true;
299
+            $recipient_ids = array($uploader_id);
300
+        }
301 301
 
302
-		if (! is_array($recipient_ids) || count($recipient_ids) == 0) {
303
-			die(get_lang('GeneralError').' (code 209)');
304
-		}
302
+        if (! is_array($recipient_ids) || count($recipient_ids) == 0) {
303
+            die(get_lang('GeneralError').' (code 209)');
304
+        }
305 305
 
306
-		foreach ($recipient_ids as $rec) {
307
-			if (empty($rec)) die(get_lang('GeneralError').' (code 210)');
308
-			//if (!isCourseMember($rec)) die(); //cannot sent document to someone outside of course
309
-				//this check is done when validating submitted data
310
-			$this->recipients[] = array('id' => $rec, 'name' => getUserNameFromId($rec));
311
-		}
306
+        foreach ($recipient_ids as $rec) {
307
+            if (empty($rec)) die(get_lang('GeneralError').' (code 210)');
308
+            //if (!isCourseMember($rec)) die(); //cannot sent document to someone outside of course
309
+                //this check is done when validating submitted data
310
+            $this->recipients[] = array('id' => $rec, 'name' => getUserNameFromId($rec));
311
+        }
312 312
 
313 313
         $table_post = $dropbox_cnf['tbl_post'];
314 314
         $table_person = $dropbox_cnf['tbl_person'];
@@ -317,13 +317,13 @@  discard block
 block discarded – undo
317 317
         $user  = api_get_user_id();
318 318
         $now = api_get_utc_datetime();
319 319
 
320
-		// Insert data in dropbox_post and dropbox_person table for each recipient
321
-		foreach ($this->recipients as $rec) {
320
+        // Insert data in dropbox_post and dropbox_person table for each recipient
321
+        foreach ($this->recipients as $rec) {
322 322
             $file_id = (int)$this->id;
323 323
             $user_id = (int)$rec['id'];
324
-			$sql = "INSERT INTO $table_post (c_id, file_id, dest_user_id, session_id, feedback_date, cat_id)
324
+            $sql = "INSERT INTO $table_post (c_id, file_id, dest_user_id, session_id, feedback_date, cat_id)
325 325
                     VALUES ($course_id, $file_id, $user_id, $session_id, '$now', 0)";
326
-	        Database::query($sql);
326
+            Database::query($sql);
327 327
             // If work already exists no error is generated
328 328
 
329 329
             /**
@@ -340,13 +340,13 @@  discard block
 block discarded – undo
340 340
                 }
341 341
             }
342 342
 
343
-			// Update item_property table for each recipient
344
-			if (($ownerid = $this->uploader_id) > $dropbox_cnf['mailingIdBase']) {
345
-			    $ownerid = getUserOwningThisMailing($ownerid);
346
-			}
347
-			if (($recipid = $rec["id"]) > $dropbox_cnf['mailingIdBase']) {
348
-			    $recipid = $ownerid;  // mailing file recipient = mailing id, not a person
349
-			}
343
+            // Update item_property table for each recipient
344
+            if (($ownerid = $this->uploader_id) > $dropbox_cnf['mailingIdBase']) {
345
+                $ownerid = getUserOwningThisMailing($ownerid);
346
+            }
347
+            if (($recipid = $rec["id"]) > $dropbox_cnf['mailingIdBase']) {
348
+                $recipid = $ownerid;  // mailing file recipient = mailing id, not a person
349
+            }
350 350
             api_item_property_update(
351 351
                 $_course,
352 352
                 TOOL_DROPBOX,
@@ -356,92 +356,92 @@  discard block
 block discarded – undo
356 356
                 null,
357 357
                 $recipid
358 358
             );
359
-		}
360
-	}
361
-
362
-	/**
363
-	 * private function creating existing object by retreiving info from db
364
-	 *
365
-	 * @param unknown_type $id
366
-	 */
367
-	public function _createExistingSentWork($id)
359
+        }
360
+    }
361
+
362
+    /**
363
+     * private function creating existing object by retreiving info from db
364
+     *
365
+     * @param unknown_type $id
366
+     */
367
+    public function _createExistingSentWork($id)
368 368
     {
369 369
         $dropbox_cnf = getDropboxConf();
370 370
         $id = intval($id);
371 371
 
372
-		$course_id = api_get_course_int_id();
372
+        $course_id = api_get_course_int_id();
373 373
 
374
-		// Call constructor of Dropbox_Work object
375
-		parent::__construct($id);
374
+        // Call constructor of Dropbox_Work object
375
+        parent::__construct($id);
376 376
 
377
-		// Fill in recipients array
378
-		$this->recipients = array();
379
-		$sql = "SELECT dest_user_id, feedback_date, feedback
377
+        // Fill in recipients array
378
+        $this->recipients = array();
379
+        $sql = "SELECT dest_user_id, feedback_date, feedback
380 380
 				FROM ".$dropbox_cnf['tbl_post']."
381 381
 				WHERE c_id = $course_id AND file_id = ".intval($id)."";
382 382
         $result = Database::query($sql);
383
-		while ($res = Database::fetch_array($result, 'ASSOC')) {
384
-
385
-			// Check for deleted users
386
-			$dest_user_id = $res['dest_user_id'];
387
-			$user_info = api_get_user_info($dest_user_id);
388
-			//$this->category = $res['cat_id'];
389
-			if (!$user_info) {
390
-				$this->recipients[] = array('id' => -1, 'name' => get_lang('Unknown', ''));
391
-			} else {
392
-				$this->recipients[] = array(
383
+        while ($res = Database::fetch_array($result, 'ASSOC')) {
384
+
385
+            // Check for deleted users
386
+            $dest_user_id = $res['dest_user_id'];
387
+            $user_info = api_get_user_info($dest_user_id);
388
+            //$this->category = $res['cat_id'];
389
+            if (!$user_info) {
390
+                $this->recipients[] = array('id' => -1, 'name' => get_lang('Unknown', ''));
391
+            } else {
392
+                $this->recipients[] = array(
393 393
                     'id' => $dest_user_id,
394 394
                     'name' => $user_info['complete_name'],
395 395
                     'user_id' => $dest_user_id,
396
-				    'feedback_date' => $res['feedback_date'],
396
+                    'feedback_date' => $res['feedback_date'],
397 397
                     'feedback' => $res['feedback']
398 398
                 );
399
-			}
400
-		}
401
-	}
399
+            }
400
+        }
401
+    }
402 402
 }
403 403
 
404 404
 class Dropbox_Person
405 405
 {
406
-	// The receivedWork and the sentWork arrays are sorted.
407
-	public $receivedWork;	// an array of Dropbox_Work objects
408
-	public $sentWork;		// an array of Dropbox_SentWork objects
409
-
410
-	public $userId = 0;
411
-	public $isCourseAdmin = false;
412
-	public $isCourseTutor = false;
413
-	public $_orderBy = '';	// private property that determines by which field
414
-
415
-	/**
416
-	 * Constructor for recreating the Dropbox_Person object
417
-	 *
418
-	 * @param int $userId
419
-	 * @param bool $isCourseAdmin
420
-	 * @param bool $isCourseTutor
421
-	 * @return Dropbox_Person
422
-	 */
423
-	public function __construct($userId, $isCourseAdmin, $isCourseTutor)
406
+    // The receivedWork and the sentWork arrays are sorted.
407
+    public $receivedWork;	// an array of Dropbox_Work objects
408
+    public $sentWork;		// an array of Dropbox_SentWork objects
409
+
410
+    public $userId = 0;
411
+    public $isCourseAdmin = false;
412
+    public $isCourseTutor = false;
413
+    public $_orderBy = '';	// private property that determines by which field
414
+
415
+    /**
416
+     * Constructor for recreating the Dropbox_Person object
417
+     *
418
+     * @param int $userId
419
+     * @param bool $isCourseAdmin
420
+     * @param bool $isCourseTutor
421
+     * @return Dropbox_Person
422
+     */
423
+    public function __construct($userId, $isCourseAdmin, $isCourseTutor)
424 424
     {
425
-	    $course_id = api_get_course_int_id();
425
+        $course_id = api_get_course_int_id();
426 426
 
427
-		// Fill in properties
427
+        // Fill in properties
428 428
         $this->userId = $userId;
429 429
         $this->isCourseAdmin = $isCourseAdmin;
430 430
         $this->isCourseTutor = $isCourseTutor;
431 431
         $this->receivedWork = array();
432 432
         $this->sentWork = array();
433 433
 
434
-		// Note: perhaps include an ex coursemember check to delete old files
434
+        // Note: perhaps include an ex coursemember check to delete old files
435 435
 
436
-		$session_id = api_get_session_id();
437
-		$condition_session = api_get_session_condition($session_id);
436
+        $session_id = api_get_session_id();
437
+        $condition_session = api_get_session_condition($session_id);
438 438
 
439
-		$post_tbl = Database::get_course_table(TABLE_DROPBOX_POST);
440
-		$person_tbl = Database::get_course_table(TABLE_DROPBOX_PERSON);
441
-		$file_tbl = Database::get_course_table(TABLE_DROPBOX_FILE);
439
+        $post_tbl = Database::get_course_table(TABLE_DROPBOX_POST);
440
+        $person_tbl = Database::get_course_table(TABLE_DROPBOX_PERSON);
441
+        $file_tbl = Database::get_course_table(TABLE_DROPBOX_FILE);
442 442
 
443 443
         // Find all entries where this person is the recipient
444
-		$sql = "SELECT DISTINCT r.file_id, r.cat_id
444
+        $sql = "SELECT DISTINCT r.file_id, r.cat_id
445 445
                 FROM $post_tbl r
446 446
                 INNER JOIN $person_tbl p
447 447
                     ON (r.file_id = p.file_id AND r.c_id = $course_id AND p.c_id = $course_id )
@@ -450,12 +450,12 @@  discard block
 block discarded – undo
450 450
                      r.dest_user_id = ".intval($this->userId)." $condition_session ";
451 451
 
452 452
         $result = Database::query($sql);
453
-		while ($res = Database::fetch_array($result)) {
454
-			$temp = new Dropbox_Work($res['file_id']);
455
-			$temp->category = $res['cat_id'];
456
-			$this->receivedWork[] = $temp;
457
-		}
458
-		// Find all entries where this person is the sender/uploader
453
+        while ($res = Database::fetch_array($result)) {
454
+            $temp = new Dropbox_Work($res['file_id']);
455
+            $temp->category = $res['cat_id'];
456
+            $this->receivedWork[] = $temp;
457
+        }
458
+        // Find all entries where this person is the sender/uploader
459 459
         $sql = "SELECT DISTINCT f.id
460 460
 				FROM $file_tbl f
461 461
 				INNER JOIN $person_tbl p
@@ -466,261 +466,261 @@  discard block
 block discarded – undo
466 466
                     $condition_session
467 467
                 ";
468 468
         $result = Database::query($sql);
469
-		while ($res = Database::fetch_array($result)) {
470
-			$this->sentWork[] = new Dropbox_SentWork($res['id']);
471
-		}
472
-	}
473
-
474
-	/**
475
-	 * This private method is used by the usort function in  the
476
-	 * orderSentWork and orderReceivedWork methods.
477
-	 * It compares 2 work-objects by 1 of the properties of that object, dictated by the
478
-	 * private property _orderBy
479
-	 *
480
-	 * @param unknown_type $a
481
-	 * @param unknown_type $b
482
-	 * @return -1, 0 or 1 dependent of the result of the comparison.
483
-	 */
484
-	function _cmpWork($a, $b)
469
+        while ($res = Database::fetch_array($result)) {
470
+            $this->sentWork[] = new Dropbox_SentWork($res['id']);
471
+        }
472
+    }
473
+
474
+    /**
475
+     * This private method is used by the usort function in  the
476
+     * orderSentWork and orderReceivedWork methods.
477
+     * It compares 2 work-objects by 1 of the properties of that object, dictated by the
478
+     * private property _orderBy
479
+     *
480
+     * @param unknown_type $a
481
+     * @param unknown_type $b
482
+     * @return -1, 0 or 1 dependent of the result of the comparison.
483
+     */
484
+    function _cmpWork($a, $b)
485 485
     {
486
-		$sort = $this->_orderBy;
487
-		$aval = $a->$sort;
488
-		$bval = $b->$sort;
489
-		if ($sort == 'recipients') {
490
-		    // The recipients property is an array so we do the comparison based
491
-		    // on the first item of the recipients array
492
-		    $aval = $aval[0]['name'];
493
-			$bval = $bval[0]['name'];
494
-		}
495
-		if ($sort == 'filesize') {    // Filesize is not a string, so we use other comparison technique
496
-			return $aval < $bval ? -1 : 1;
497
-		} elseif ($sort == 'title') { // Natural order for sorting titles is more "human-friendly"
498
-			return api_strnatcmp($aval, $bval);
499
-		} else {
500
-		    return api_strcasecmp($aval, $bval);
501
-		}
502
-	}
503
-
504
-	/**
505
-	 * A method that sorts the objects in the sentWork array, dependent on the $sort parameter.
506
-	 * $sort can be lastDate, firstDate, title, size, ...
507
-	 *
508
-	 * @param unknown_type $sort
509
-	 */
510
-	function orderSentWork($sort)
486
+        $sort = $this->_orderBy;
487
+        $aval = $a->$sort;
488
+        $bval = $b->$sort;
489
+        if ($sort == 'recipients') {
490
+            // The recipients property is an array so we do the comparison based
491
+            // on the first item of the recipients array
492
+            $aval = $aval[0]['name'];
493
+            $bval = $bval[0]['name'];
494
+        }
495
+        if ($sort == 'filesize') {    // Filesize is not a string, so we use other comparison technique
496
+            return $aval < $bval ? -1 : 1;
497
+        } elseif ($sort == 'title') { // Natural order for sorting titles is more "human-friendly"
498
+            return api_strnatcmp($aval, $bval);
499
+        } else {
500
+            return api_strcasecmp($aval, $bval);
501
+        }
502
+    }
503
+
504
+    /**
505
+     * A method that sorts the objects in the sentWork array, dependent on the $sort parameter.
506
+     * $sort can be lastDate, firstDate, title, size, ...
507
+     *
508
+     * @param unknown_type $sort
509
+     */
510
+    function orderSentWork($sort)
511 511
     {
512
-		switch($sort) {
513
-			case 'lastDate':
514
-				$this->_orderBy = 'last_upload_date';
515
-				break;
516
-			case 'firstDate':
517
-				$this->_orderBy = 'upload_date';
518
-				break;
519
-			case 'title':
520
-				$this->_orderBy = 'title';
521
-				break;
522
-			case 'size':
523
-				$this->_orderBy = 'filesize';
524
-				break;
525
-			case 'author':
526
-				$this->_orderBy = 'author';
527
-				break;
528
-			case 'recipient':
529
-				$this->_orderBy = 'recipients';
530
-				break;
531
-			default:
532
-				$this->_orderBy = 'last_upload_date';
533
-		}
534
-
535
-		usort($this->sentWork, array($this, '_cmpWork'));
536
-	}
537
-
538
-	/**
539
-	 * method that sorts the objects in the receivedWork array, dependent on the $sort parameter.
540
-	 * $sort can be lastDate, firstDate, title, size, ...
541
-	 * @param unknown_type $sort
542
-	 */
543
-	function orderReceivedWork($sort)
512
+        switch($sort) {
513
+            case 'lastDate':
514
+                $this->_orderBy = 'last_upload_date';
515
+                break;
516
+            case 'firstDate':
517
+                $this->_orderBy = 'upload_date';
518
+                break;
519
+            case 'title':
520
+                $this->_orderBy = 'title';
521
+                break;
522
+            case 'size':
523
+                $this->_orderBy = 'filesize';
524
+                break;
525
+            case 'author':
526
+                $this->_orderBy = 'author';
527
+                break;
528
+            case 'recipient':
529
+                $this->_orderBy = 'recipients';
530
+                break;
531
+            default:
532
+                $this->_orderBy = 'last_upload_date';
533
+        }
534
+
535
+        usort($this->sentWork, array($this, '_cmpWork'));
536
+    }
537
+
538
+    /**
539
+     * method that sorts the objects in the receivedWork array, dependent on the $sort parameter.
540
+     * $sort can be lastDate, firstDate, title, size, ...
541
+     * @param unknown_type $sort
542
+     */
543
+    function orderReceivedWork($sort)
544 544
     {
545
-		switch($sort) {
546
-			case 'lastDate':
547
-				$this->_orderBy = 'last_upload_date';
548
-				break;
549
-			case 'firstDate':
550
-				$this->_orderBy = 'upload_date';
551
-				break;
552
-			case 'title':
553
-				$this->_orderBy = 'title';
554
-				break;
555
-			case 'size':
556
-				$this->_orderBy = 'filesize';
557
-				break;
558
-			case 'author':
559
-				$this->_orderBy = 'author';
560
-				break;
561
-			case 'sender':
562
-				$this->_orderBy = 'uploaderName';
563
-				break;
564
-			default:
565
-				$this->_orderBy = 'last_upload_date';
566
-		}
567
-
568
-		usort($this->receivedWork, array($this, '_cmpWork'));
569
-	}
570
-
571
-	/**
572
-	 * Deletes all the received work of this person
573
-	 */
574
-	function deleteAllReceivedWork()
545
+        switch($sort) {
546
+            case 'lastDate':
547
+                $this->_orderBy = 'last_upload_date';
548
+                break;
549
+            case 'firstDate':
550
+                $this->_orderBy = 'upload_date';
551
+                break;
552
+            case 'title':
553
+                $this->_orderBy = 'title';
554
+                break;
555
+            case 'size':
556
+                $this->_orderBy = 'filesize';
557
+                break;
558
+            case 'author':
559
+                $this->_orderBy = 'author';
560
+                break;
561
+            case 'sender':
562
+                $this->_orderBy = 'uploaderName';
563
+                break;
564
+            default:
565
+                $this->_orderBy = 'last_upload_date';
566
+        }
567
+
568
+        usort($this->receivedWork, array($this, '_cmpWork'));
569
+    }
570
+
571
+    /**
572
+     * Deletes all the received work of this person
573
+     */
574
+    function deleteAllReceivedWork()
575 575
     {
576
-	    $course_id = api_get_course_int_id();
576
+        $course_id = api_get_course_int_id();
577 577
         $dropbox_cnf = getDropboxConf();
578
-		// Delete entries in person table concerning received works
579
-		foreach ($this->receivedWork as $w) {
578
+        // Delete entries in person table concerning received works
579
+        foreach ($this->receivedWork as $w) {
580 580
             $sql = "DELETE FROM ".$dropbox_cnf['tbl_person']."
581 581
 			        WHERE c_id = $course_id AND user_id='".$this->userId."' AND file_id='".$w->id."'";
582
-			Database::query($sql);
583
-		}
582
+            Database::query($sql);
583
+        }
584 584
         // Check for unused files
585
-		removeUnusedFiles();
586
-	}
587
-
588
-	/**
589
-	 * Deletes all the received categories and work of this person
590
-	 * @param integer $id
591
-	 */
592
-	function deleteReceivedWorkFolder($id)
585
+        removeUnusedFiles();
586
+    }
587
+
588
+    /**
589
+     * Deletes all the received categories and work of this person
590
+     * @param integer $id
591
+     */
592
+    function deleteReceivedWorkFolder($id)
593 593
     {
594 594
         $dropbox_cnf = getDropboxConf();
595 595
         $course_id = api_get_course_int_id();
596 596
 
597
-		$id = intval($id);
598
-		$sql = "DELETE FROM ".$dropbox_cnf['tbl_file']."
597
+        $id = intval($id);
598
+        $sql = "DELETE FROM ".$dropbox_cnf['tbl_file']."
599 599
 		        WHERE c_id = $course_id AND cat_id = '".$id."' ";
600
-		if (!Database::query($sql)) return false;
601
-		$sql = "DELETE FROM ".$dropbox_cnf['tbl_category']."
600
+        if (!Database::query($sql)) return false;
601
+        $sql = "DELETE FROM ".$dropbox_cnf['tbl_category']."
602 602
 		        WHERE c_id = $course_id AND cat_id = '".$id."' ";
603
-		if (!Database::query($sql)) return false;
604
-		$sql = "DELETE FROM ".$dropbox_cnf['tbl_post']."
603
+        if (!Database::query($sql)) return false;
604
+        $sql = "DELETE FROM ".$dropbox_cnf['tbl_post']."
605 605
 		        WHERE c_id = $course_id AND cat_id = '".$id."' ";
606
-		if (!Database::query($sql)) return false;
607
-		return true;
608
-	}
609
-
610
-	/**
611
-	 * Deletes a received dropbox file of this person with id=$id
612
-	 *
613
-	 * @param integer $id
614
-	 */
615
-	function deleteReceivedWork($id)
606
+        if (!Database::query($sql)) return false;
607
+        return true;
608
+    }
609
+
610
+    /**
611
+     * Deletes a received dropbox file of this person with id=$id
612
+     *
613
+     * @param integer $id
614
+     */
615
+    function deleteReceivedWork($id)
616 616
     {
617
-	    $course_id = api_get_course_int_id();
617
+        $course_id = api_get_course_int_id();
618 618
         $dropbox_cnf = getDropboxConf();
619
-		$id = intval($id);
620
-
621
-		// index check
622
-		$found = false;
623
-		foreach ($this->receivedWork as $w) {
624
-			if ($w->id == $id) {
625
-			   $found = true;
626
-			   break;
627
-			}
628
-		}
629
-
630
-		if (!$found) {
631
-			if (!$this->deleteReceivedWorkFolder($id)) {
632
-				die(get_lang('GeneralError').' (code 216)');
633
-			}
634
-		}
635
-		// Delete entries in person table concerning received works
619
+        $id = intval($id);
620
+
621
+        // index check
622
+        $found = false;
623
+        foreach ($this->receivedWork as $w) {
624
+            if ($w->id == $id) {
625
+                $found = true;
626
+                break;
627
+            }
628
+        }
629
+
630
+        if (!$found) {
631
+            if (!$this->deleteReceivedWorkFolder($id)) {
632
+                die(get_lang('GeneralError').' (code 216)');
633
+            }
634
+        }
635
+        // Delete entries in person table concerning received works
636 636
         $sql = "DELETE FROM ".$dropbox_cnf['tbl_person']."
637 637
                 WHERE c_id = $course_id AND user_id = '".$this->userId."' AND file_id ='".$id."'";
638
-		Database::query($sql);
639
-		removeUnusedFiles();	// Check for unused files
640
-	}
641
-
642
-	/**
643
-	 * Deletes all the sent dropbox files of this person
644
-	 */
645
-	function deleteAllSentWork()
638
+        Database::query($sql);
639
+        removeUnusedFiles();	// Check for unused files
640
+    }
641
+
642
+    /**
643
+     * Deletes all the sent dropbox files of this person
644
+     */
645
+    function deleteAllSentWork()
646 646
     {
647
-	    $course_id = api_get_course_int_id();
647
+        $course_id = api_get_course_int_id();
648 648
         $dropbox_cnf = getDropboxConf();
649
-		//delete entries in person table concerning sent works
650
-		foreach ($this->sentWork as $w) {
649
+        //delete entries in person table concerning sent works
650
+        foreach ($this->sentWork as $w) {
651 651
             $sql = "DELETE FROM ".$dropbox_cnf['tbl_person']."
652 652
                     WHERE c_id = $course_id AND user_id='".$this->userId."' AND file_id='".$w->id."'";
653
-			Database::query($sql);
654
-			removeMoreIfMailing($w->id);
655
-		}
656
-		removeUnusedFiles();	// Check for unused files
657
-	}
658
-
659
-	/**
660
-	 * Deletes a sent dropbox file of this person with id=$id
661
-	 *
662
-	 * @param unknown_type $id
663
-	 */
664
-	function deleteSentWork($id)
653
+            Database::query($sql);
654
+            removeMoreIfMailing($w->id);
655
+        }
656
+        removeUnusedFiles();	// Check for unused files
657
+    }
658
+
659
+    /**
660
+     * Deletes a sent dropbox file of this person with id=$id
661
+     *
662
+     * @param unknown_type $id
663
+     */
664
+    function deleteSentWork($id)
665 665
     {
666
-	    $course_id = api_get_course_int_id();
666
+        $course_id = api_get_course_int_id();
667 667
         $dropbox_cnf = getDropboxConf();
668 668
 
669
-		$id = intval($id);
670
-
671
-		// index check
672
-		$found = false;
673
-		foreach ($this->sentWork as $w) {
674
-			if ($w->id == $id) {
675
-			   $found = true;
676
-			   break;
677
-			}
678
-		}
679
-		if (!$found) {
680
-			if (!$this->deleteReceivedWorkFolder($id)) {
681
-				die(get_lang('GeneralError').' (code 219)');
682
-			}
683
-		}
684
-		//$file_id = $this->sentWork[$index]->id;
685
-		// Delete entries in person table concerning sent works
669
+        $id = intval($id);
670
+
671
+        // index check
672
+        $found = false;
673
+        foreach ($this->sentWork as $w) {
674
+            if ($w->id == $id) {
675
+                $found = true;
676
+                break;
677
+            }
678
+        }
679
+        if (!$found) {
680
+            if (!$this->deleteReceivedWorkFolder($id)) {
681
+                die(get_lang('GeneralError').' (code 219)');
682
+            }
683
+        }
684
+        //$file_id = $this->sentWork[$index]->id;
685
+        // Delete entries in person table concerning sent works
686 686
         $sql = "DELETE FROM ".$dropbox_cnf['tbl_person']."
687 687
                 WHERE c_id = $course_id AND user_id='".$this->userId."' AND file_id='".$id."'";
688
-		Database::query($sql);
689
-		removeMoreIfMailing($id);
690
-		removeUnusedFiles();	// Check for unused files
691
-	}
692
-
693
-	/**
694
-	 * Updates feedback for received work of this person with id=$id
695
-	 *
696
-	 * @param string $id
697
-	 * @param string $text
698
-	 */
699
-	function updateFeedback($id, $text)
688
+        Database::query($sql);
689
+        removeMoreIfMailing($id);
690
+        removeUnusedFiles();	// Check for unused files
691
+    }
692
+
693
+    /**
694
+     * Updates feedback for received work of this person with id=$id
695
+     *
696
+     * @param string $id
697
+     * @param string $text
698
+     */
699
+    function updateFeedback($id, $text)
700 700
     {
701
-	    $course_id = api_get_course_int_id();
701
+        $course_id = api_get_course_int_id();
702 702
         $_course = api_get_course_info();
703 703
         $dropbox_cnf = getDropboxConf();
704 704
 
705
-		$id = intval($id);
706
-
707
-		// index check
708
-		$found = false;
709
-		$wi = -1;
710
-		foreach ($this->receivedWork as $w) {
711
-			$wi++;
712
-			if ($w->id == $id){
713
-			   $found = true;
714
-			   break;
715
-			}  // foreach (... as $wi -> $w) gives error 221! (no idea why...)
716
-		}
717
-		if (!$found) {
718
-			die(get_lang('GeneralError').' (code 221)');
719
-		}
720
-
721
-		$feedback_date = api_get_utc_datetime();
722
-		$this->receivedWork[$wi]->feedback_date = $feedback_date;
723
-		$this->receivedWork[$wi]->feedback = $text;
705
+        $id = intval($id);
706
+
707
+        // index check
708
+        $found = false;
709
+        $wi = -1;
710
+        foreach ($this->receivedWork as $w) {
711
+            $wi++;
712
+            if ($w->id == $id){
713
+                $found = true;
714
+                break;
715
+            }  // foreach (... as $wi -> $w) gives error 221! (no idea why...)
716
+        }
717
+        if (!$found) {
718
+            die(get_lang('GeneralError').' (code 221)');
719
+        }
720
+
721
+        $feedback_date = api_get_utc_datetime();
722
+        $this->receivedWork[$wi]->feedback_date = $feedback_date;
723
+        $this->receivedWork[$wi]->feedback = $text;
724 724
 
725 725
         $params = [
726 726
             'feedback_date' => $feedback_date,
@@ -738,11 +738,11 @@  discard block
 block discarded – undo
738 738
             ]
739 739
         );
740 740
 
741
-		// Update item_property table
741
+        // Update item_property table
742 742
 
743
-		if (($ownerid = $this->receivedWork[$wi]->uploader_id) > $dropbox_cnf['mailingIdBase']) {
744
-		    $ownerid = getUserOwningThisMailing($ownerid);
745
-		}
743
+        if (($ownerid = $this->receivedWork[$wi]->uploader_id) > $dropbox_cnf['mailingIdBase']) {
744
+            $ownerid = getUserOwningThisMailing($ownerid);
745
+        }
746 746
         api_item_property_update(
747 747
             $_course,
748 748
             TOOL_DROPBOX,
@@ -753,31 +753,31 @@  discard block
 block discarded – undo
753 753
             $ownerid
754 754
         );
755 755
 
756
-	}
756
+    }
757 757
 
758
-	/**
759
-	 * Filter the received work
760
-	 * @param string $type
761
-	 * @param string $value
762
-	 */
763
-	function filter_received_work($type, $value)
758
+    /**
759
+     * Filter the received work
760
+     * @param string $type
761
+     * @param string $value
762
+     */
763
+    function filter_received_work($type, $value)
764 764
     {
765 765
         $dropbox_cnf = getDropboxConf();
766
-    	$new_received_work = array();
767
-		foreach ($this->receivedWork as $work) {
768
-			switch ($type) {
769
-				case 'uploader_id':
770
-					if ($work->uploader_id == $value ||
771
-						($work->uploader_id > $dropbox_cnf['mailingIdBase'] &&
766
+        $new_received_work = array();
767
+        foreach ($this->receivedWork as $work) {
768
+            switch ($type) {
769
+                case 'uploader_id':
770
+                    if ($work->uploader_id == $value ||
771
+                        ($work->uploader_id > $dropbox_cnf['mailingIdBase'] &&
772 772
                         getUserOwningThisMailing($work->uploader_id) == $value)
773 773
                     ) {
774
-						$new_received_work[] = $work;
775
-					}
776
-					break;
777
-				default:
778
-					$new_received_work[] = $work;
779
-			}
780
-		}
781
-		$this->receivedWork = $new_received_work;
782
-	}
774
+                        $new_received_work[] = $work;
775
+                    }
776
+                    break;
777
+                default:
778
+                    $new_received_work[] = $work;
779
+            }
780
+        }
781
+        $this->receivedWork = $new_received_work;
782
+    }
783 783
 }
Please login to merge, or discard this patch.