Completed
Push — 1.10.x ( 8aeee0...ba9367 )
by Julito
233:57 queued 178:16
created
main/exercice/exercise_result.class.php 1 patch
Indentation   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 */
10 10
 class ExerciseResult
11 11
 {
12
-	private $results = array();
12
+    private $results = array();
13 13
     public $includeAllUsers = false;
14 14
     public $onlyBestAttempts = false;
15 15
 
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
         $exercise_id = 0,
47 47
         $hotpotato_name = null
48 48
     ) {
49
-		$return = array();
49
+        $return = array();
50 50
 
51 51
         $TBL_EXERCISES = Database::get_course_table(TABLE_QUIZ_TEST);
52 52
         $TBL_TABLE_LP_MAIN = Database::get_course_table(TABLE_LP_MAIN);
@@ -66,9 +66,9 @@  discard block
 block discarded – undo
66 66
             $session_id_and .= " AND exe_exo_id = $exercise_id ";
67 67
         }
68 68
 
69
-		if (empty($user_id)) {
69
+        if (empty($user_id)) {
70 70
             $user_id_and = null;
71
-			$sql = "SELECT ".(api_is_western_name_order() ? "firstname as userpart1, lastname userpart2" : "lastname as userpart1, firstname as userpart2").",
71
+            $sql = "SELECT ".(api_is_western_name_order() ? "firstname as userpart1, lastname userpart2" : "lastname as userpart1, firstname as userpart2").",
72 72
 			            official_code,
73 73
                         ce.title as extitle,
74 74
                         te.exe_result as exresult ,
@@ -91,9 +91,9 @@  discard block
 block discarded – undo
91 91
                     te.status != 'incomplete' AND
92 92
                     te.c_id = ce.c_id $user_id_and  $session_id_and AND
93 93
                     ce.active <>-1";
94
-		} else {
94
+        } else {
95 95
             $user_id_and = ' AND te.exe_user_id = ' . api_get_user_id() . ' ';
96
-			// get only this user's results
96
+            // get only this user's results
97 97
             $sql="SELECT ".(api_is_western_name_order() ? "firstname as userpart1, lastname userpart2" : "lastname as userpart1, firstname as userpart2").",
98 98
                     official_code,
99 99
                     ce.title as extitle,
@@ -119,12 +119,12 @@  discard block
 block discarded – undo
119 119
                         te.c_id = ce.c_id $user_id_and $session_id_and AND
120 120
                         ce.active <>-1 AND
121 121
                     ORDER BY userpart2, te.c_id ASC, ce.title ASC, te.exe_date DESC";
122
-		}
122
+        }
123 123
 
124
-		$results = array();
125
-		$resx = Database::query($sql);
124
+        $results = array();
125
+        $resx = Database::query($sql);
126 126
         $bestAttemptPerUser = array();
127
-		while ($rowx = Database::fetch_array($resx,'ASSOC')) {
127
+        while ($rowx = Database::fetch_array($resx,'ASSOC')) {
128 128
             if ($this->onlyBestAttempts) {
129 129
                 if (!isset($bestAttemptPerUser[$rowx['excruid']])) {
130 130
                     $bestAttemptPerUser[$rowx['excruid']] = $rowx;
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
             } else {
137 137
                 $results[] = $rowx;
138 138
             }
139
-		}
139
+        }
140 140
 
141 141
         if ($this->onlyBestAttempts) {
142 142
             $results = $bestAttemptPerUser;
@@ -190,8 +190,8 @@  discard block
 block discarded – undo
190 190
                     continue;
191 191
                 }
192 192
 
193
-				$return[$i] = array();
194
-				if (empty($user_id)) {
193
+                $return[$i] = array();
194
+                if (empty($user_id)) {
195 195
                     $return[$i]['official_code']   = $result['official_code'];
196 196
                     if (api_is_western_name_order()) {
197 197
                         $return[$i]['first_name']   = $results[$i]['userpart1'];
@@ -200,15 +200,15 @@  discard block
 block discarded – undo
200 200
                         $return[$i]['first_name']   = $results[$i]['userpart2'];
201 201
                         $return[$i]['last_name']    = $results[$i]['userpart1'];
202 202
                     }
203
-					$return[$i]['user_id']      = $results[$i]['excruid'];
204
-					$return[$i]['email']        = $results[$i]['exemail'];
205
-				}
206
-				$return[$i]['title'] = $result['extitle'];
207
-				$return[$i]['start_date'] = api_get_local_time($result['exstart']);
203
+                    $return[$i]['user_id']      = $results[$i]['excruid'];
204
+                    $return[$i]['email']        = $results[$i]['exemail'];
205
+                }
206
+                $return[$i]['title'] = $result['extitle'];
207
+                $return[$i]['start_date'] = api_get_local_time($result['exstart']);
208 208
                 $return[$i]['end_date'] = api_get_local_time($result['exdate']);
209 209
                 $return[$i]['duration'] = $result['duration'];
210
-				$return[$i]['result'] = $result['exresult'];
211
-				$return[$i]['max'] = $result['exweight'];
210
+                $return[$i]['result'] = $result['exresult'];
211
+                $return[$i]['max'] = $result['exweight'];
212 212
                 $return[$i]['status'] = $revised ? get_lang('Validated') : get_lang('NotValidated');
213 213
                 $return[$i]['lp_id'] = $result['orig_lp_id'];
214 214
                 $return[$i]['lp_name'] = $result['lp_name'];
@@ -221,8 +221,8 @@  discard block
 block discarded – undo
221 221
 
222 222
                 $userWithResults[$result['excruid']] = 1;
223 223
                 $i++;
224
-			}
225
-		}
224
+            }
225
+        }
226 226
 
227 227
         if ($this->includeAllUsers) {
228 228
             $latestId = count($return);
@@ -265,18 +265,18 @@  discard block
 block discarded – undo
265 265
             }
266 266
         }
267 267
 
268
-		$this->results = $return;
268
+        $this->results = $return;
269 269
 
270
-		return true;
271
-	}
270
+        return true;
271
+    }
272 272
 
273
-	/**
274
-	 * Exports the complete report as a CSV file
275
-	 * @param	string		Document path inside the document tool
276
-	 * @param	integer		Optional user ID
277
-	 * @param	boolean		Whether to include user fields or not
278
-	 * @return	boolean		False on error
279
-	 */
273
+    /**
274
+     * Exports the complete report as a CSV file
275
+     * @param	string		Document path inside the document tool
276
+     * @param	integer		Optional user ID
277
+     * @param	boolean		Whether to include user fields or not
278
+     * @return	boolean		False on error
279
+     */
280 280
     public function exportCompleteReportCSV(
281 281
         $document_path = '',
282 282
         $user_id = null,
@@ -285,14 +285,14 @@  discard block
 block discarded – undo
285 285
         $exercise_id = 0,
286 286
         $hotpotato_name = null
287 287
     ) {
288
-		global $charset;
289
-		$this->getExercisesReporting($document_path, $user_id, $export_filter, $exercise_id, $hotpotato_name);
290
-
291
-		$filename = 'exercise_results_'.date('YmdGis').'.csv';
292
-		if(!empty($user_id)) {
293
-			$filename = 'exercise_results_user_'.$user_id.'_'.date('YmdGis').'.csv';
294
-		}
295
-		$data = '';
288
+        global $charset;
289
+        $this->getExercisesReporting($document_path, $user_id, $export_filter, $exercise_id, $hotpotato_name);
290
+
291
+        $filename = 'exercise_results_'.date('YmdGis').'.csv';
292
+        if(!empty($user_id)) {
293
+            $filename = 'exercise_results_user_'.$user_id.'_'.date('YmdGis').'.csv';
294
+        }
295
+        $data = '';
296 296
         if (api_is_western_name_order()) {
297 297
             if(!empty($this->results[0]['first_name'])) {
298 298
                 $data .= get_lang('FirstName').';';
@@ -316,28 +316,28 @@  discard block
 block discarded – undo
316 316
         $data .= get_lang('Email').';';
317 317
         $data .= get_lang('Groups').';';
318 318
 
319
-		if ($export_user_fields) {
320
-			//show user fields section with a big th colspan that spans over all fields
321
-			$extra_user_fields = UserManager::get_extra_fields(0,1000,5,'ASC',false, 1);
322
-			$num = count($extra_user_fields);
323
-			foreach($extra_user_fields as $field) {
324
-				$data .= '"'.str_replace("\r\n",'  ',api_html_entity_decode(strip_tags($field[3]), ENT_QUOTES, $charset)).'";';
325
-			}
326
-		}
327
-
328
-		$data .= get_lang('Title').';';
329
-		$data .= get_lang('StartDate').';';
319
+        if ($export_user_fields) {
320
+            //show user fields section with a big th colspan that spans over all fields
321
+            $extra_user_fields = UserManager::get_extra_fields(0,1000,5,'ASC',false, 1);
322
+            $num = count($extra_user_fields);
323
+            foreach($extra_user_fields as $field) {
324
+                $data .= '"'.str_replace("\r\n",'  ',api_html_entity_decode(strip_tags($field[3]), ENT_QUOTES, $charset)).'";';
325
+            }
326
+        }
327
+
328
+        $data .= get_lang('Title').';';
329
+        $data .= get_lang('StartDate').';';
330 330
         $data .= get_lang('EndDate').';';
331 331
         $data .= get_lang('Duration'). ' ('.get_lang('MinMinutes').') ;';
332
-		$data .= get_lang('Score').';';
333
-		$data .= get_lang('Total').';';
332
+        $data .= get_lang('Score').';';
333
+        $data .= get_lang('Total').';';
334 334
         $data .= get_lang('Status').';';
335 335
         $data .= get_lang('ToolLearnpath').';';
336 336
         $data .= get_lang('UserIsCurrentlySubscribed').';';
337
-		$data .= "\n";
337
+        $data .= "\n";
338 338
 
339
-		//results
340
-		foreach ($this->results as $row) {
339
+        //results
340
+        foreach ($this->results as $row) {
341 341
 
342 342
             if (api_is_western_name_order()) {
343 343
                 $data .= str_replace("\r\n",'  ',api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset)).';';
@@ -354,51 +354,51 @@  discard block
 block discarded – undo
354 354
             $data .= str_replace("\r\n",'  ',api_html_entity_decode(strip_tags($row['email']), ENT_QUOTES, $charset)).';';
355 355
             $data .= str_replace("\r\n",'  ',implode(", ", GroupManager :: get_user_group_name($row['user_id']))).';';
356 356
 
357
-			if ($export_user_fields) {
358
-				//show user fields data, if any, for this user
359
-				$user_fields_values = UserManager::get_extra_user_data($row['user_id'],false,false, false, true);
360
-				foreach($user_fields_values as $value) {
361
-					$data .= '"'.str_replace('"','""',api_html_entity_decode(strip_tags($value), ENT_QUOTES, $charset)).'";';
362
-				}
363
-			}
357
+            if ($export_user_fields) {
358
+                //show user fields data, if any, for this user
359
+                $user_fields_values = UserManager::get_extra_user_data($row['user_id'],false,false, false, true);
360
+                foreach($user_fields_values as $value) {
361
+                    $data .= '"'.str_replace('"','""',api_html_entity_decode(strip_tags($value), ENT_QUOTES, $charset)).'";';
362
+                }
363
+            }
364 364
 
365
-			$data .= str_replace("\r\n",'  ',api_html_entity_decode(strip_tags($row['title']), ENT_QUOTES, $charset)).';';
366
-			$data .= str_replace("\r\n",'  ',$row['start_date']).';';
365
+            $data .= str_replace("\r\n",'  ',api_html_entity_decode(strip_tags($row['title']), ENT_QUOTES, $charset)).';';
366
+            $data .= str_replace("\r\n",'  ',$row['start_date']).';';
367 367
             $data .= str_replace("\r\n",'  ',$row['end_date']).';';
368 368
             $data .= str_replace("\r\n",'  ',$row['duration']).';';
369
-			$data .= str_replace("\r\n",'  ',$row['result']).';';
370
-			$data .= str_replace("\r\n",'  ',$row['max']).';';
369
+            $data .= str_replace("\r\n",'  ',$row['result']).';';
370
+            $data .= str_replace("\r\n",'  ',$row['max']).';';
371 371
             $data .= str_replace("\r\n",'  ',$row['status']).';';
372 372
             $data .= str_replace("\r\n",'  ',$row['lp_name']).';';
373 373
             $data .= str_replace("\r\n",'  ',$row['is_user_subscribed']).';';
374
-			$data .= "\n";
375
-		}
376
-
377
-		//output the results
378
-		$len = strlen($data);
379
-		header('Content-type: application/octet-stream');
380
-		header('Content-Type: application/force-download');
381
-		header('Content-length: '.$len);
382
-		if (preg_match("/MSIE 5.5/", $_SERVER['HTTP_USER_AGENT'])) {
383
-			header('Content-Disposition: filename= '.$filename);
384
-		} else {
385
-			header('Content-Disposition: attachment; filename= '.$filename);
386
-		}
387
-		if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
388
-			header('Pragma: ');
389
-			header('Cache-Control: ');
390
-			header('Cache-Control: public'); // IE cannot download from sessions without a cache
391
-		}
392
-		header('Content-Description: '.$filename);
393
-		header('Content-transfer-encoding: binary');
394
-		echo $data;
395
-		return true;
396
-	}
397
-
398
-	/**
399
-	 * Exports the complete report as an XLS file
400
-	 * @return	boolean		False on error
401
-	 */
374
+            $data .= "\n";
375
+        }
376
+
377
+        //output the results
378
+        $len = strlen($data);
379
+        header('Content-type: application/octet-stream');
380
+        header('Content-Type: application/force-download');
381
+        header('Content-length: '.$len);
382
+        if (preg_match("/MSIE 5.5/", $_SERVER['HTTP_USER_AGENT'])) {
383
+            header('Content-Disposition: filename= '.$filename);
384
+        } else {
385
+            header('Content-Disposition: attachment; filename= '.$filename);
386
+        }
387
+        if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
388
+            header('Pragma: ');
389
+            header('Cache-Control: ');
390
+            header('Cache-Control: public'); // IE cannot download from sessions without a cache
391
+        }
392
+        header('Content-Description: '.$filename);
393
+        header('Content-transfer-encoding: binary');
394
+        echo $data;
395
+        return true;
396
+    }
397
+
398
+    /**
399
+     * Exports the complete report as an XLS file
400
+     * @return	boolean		False on error
401
+     */
402 402
     public function exportCompleteReportXLS(
403 403
         $document_path = '',
404 404
         $user_id = null,
@@ -407,35 +407,35 @@  discard block
 block discarded – undo
407 407
         $exercise_id = 0,
408 408
         $hotpotato_name = null
409 409
     ) {
410
-		global $charset;
411
-		$this->getExercisesReporting($document_path, $user_id, $export_filter, $exercise_id, $hotpotato_name);
412
-		$filename = 'exercise_results_'.api_get_local_time().'.xlsx';
413
-		if (!empty($user_id)) {
414
-			$filename = 'exercise_results_user_'.$user_id.'_'.api_get_local_time().'.xlsx';
415
-		}
410
+        global $charset;
411
+        $this->getExercisesReporting($document_path, $user_id, $export_filter, $exercise_id, $hotpotato_name);
412
+        $filename = 'exercise_results_'.api_get_local_time().'.xlsx';
413
+        if (!empty($user_id)) {
414
+            $filename = 'exercise_results_user_'.$user_id.'_'.api_get_local_time().'.xlsx';
415
+        }
416 416
 
417 417
         $spreadsheet = new PHPExcel();
418 418
         $spreadsheet->setActiveSheetIndex(0);
419 419
         $worksheet = $spreadsheet->getActiveSheet();
420 420
 
421
-		$line = 0;
422
-		$column = 0; //skip the first column (row titles)
421
+        $line = 0;
422
+        $column = 0; //skip the first column (row titles)
423 423
 
424
-		// check if exists column 'user'
425
-		$with_column_user = false;
426
-		foreach ($this->results as $result) {
427
-			if (!empty($result['last_name']) && !empty($result['first_name'])) {
428
-				$with_column_user = true;
429
-				break;
430
-			}
431
-		}
424
+        // check if exists column 'user'
425
+        $with_column_user = false;
426
+        foreach ($this->results as $result) {
427
+            if (!empty($result['last_name']) && !empty($result['first_name'])) {
428
+                $with_column_user = true;
429
+                break;
430
+            }
431
+        }
432 432
 
433 433
         $officialCodeInList = api_get_setting('show_official_code_exercise_result_list');
434 434
 
435
-		if ($with_column_user) {
435
+        if ($with_column_user) {
436 436
             if (api_is_western_name_order()) {
437
-    			$worksheet->setCellValueByColumnAndRow($column, $line, get_lang('FirstName'));
438
-    			$column++;
437
+                $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('FirstName'));
438
+                $column++;
439 439
                 $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('LastName'));
440 440
                 $column++;
441 441
             } else {
@@ -451,17 +451,17 @@  discard block
 block discarded – undo
451 451
             }
452 452
 
453 453
             $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('Email'));
454
-		    $column++;
455
-		}
454
+            $column++;
455
+        }
456 456
         $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('Groups'));
457
-	    $column++;
457
+        $column++;
458 458
 
459
-		if ($export_user_fields) {
460
-			//show user fields section with a big th colspan that spans over all fields
461
-			$extra_user_fields = UserManager::get_extra_fields(0,1000,5,'ASC',false, 1);
459
+        if ($export_user_fields) {
460
+            //show user fields section with a big th colspan that spans over all fields
461
+            $extra_user_fields = UserManager::get_extra_fields(0,1000,5,'ASC',false, 1);
462 462
 
463
-			//show the fields names for user fields
464
-			foreach ($extra_user_fields as $field) {
463
+            //show the fields names for user fields
464
+            foreach ($extra_user_fields as $field) {
465 465
                 $worksheet->setCellValueByColumnAndRow(
466 466
                     $column,
467 467
                     $line,
@@ -471,31 +471,31 @@  discard block
 block discarded – undo
471 471
                         $charset
472 472
                     )
473 473
                 );
474
-				$column++;
475
-			}
476
-		}
474
+                $column++;
475
+            }
476
+        }
477 477
 
478
-		$worksheet->setCellValueByColumnAndRow($column, $line, get_lang('Title'));
479
-		$column++;
480
-		$worksheet->setCellValueByColumnAndRow($column, $line, get_lang('StartDate'));
478
+        $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('Title'));
479
+        $column++;
480
+        $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('StartDate'));
481 481
         $column++;
482 482
         $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('EndDate'));
483 483
         $column++;
484 484
         $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('Duration').' ('.get_lang('MinMinutes').')');
485
-		$column++;
486
-		$worksheet->setCellValueByColumnAndRow($column, $line, get_lang('Score'));
487
-		$column++;
488
-		$worksheet->setCellValueByColumnAndRow($column, $line, get_lang('Total'));
489
-		$column++;
485
+        $column++;
486
+        $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('Score'));
487
+        $column++;
488
+        $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('Total'));
489
+        $column++;
490 490
         $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('Status'));
491
-		$column++;
491
+        $column++;
492 492
         $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('ToolLearnpath'));
493 493
         $column++;
494 494
         $worksheet->setCellValueByColumnAndRow($column, $line, get_lang('UserIsCurrentlySubscribed'));
495
-		$line++;
495
+        $line++;
496 496
 
497
-		foreach ($this->results as $row) {
498
-			$column = 0;
497
+        foreach ($this->results as $row) {
498
+            $column = 0;
499 499
 
500 500
             if ($with_column_user) {
501 501
                 if (api_is_western_name_order()) {
@@ -517,15 +517,15 @@  discard block
 block discarded – undo
517 517
 
518 518
                 $worksheet->setCellValueByColumnAndRow($column, $line, api_html_entity_decode(strip_tags($row['email']), ENT_QUOTES, $charset));
519 519
                 $column++;
520
-			}
520
+            }
521 521
 
522 522
             $worksheet->setCellValueByColumnAndRow($column, $line, api_html_entity_decode(strip_tags(implode(", ", GroupManager :: get_user_group_name($row['user_id']))), ENT_QUOTES, $charset));
523 523
             $column++;
524 524
 
525
-			if ($export_user_fields) {
526
-				//show user fields data, if any, for this user
527
-				$user_fields_values = UserManager::get_extra_user_data($row['user_id'],false,false, false, true);
528
-				foreach($user_fields_values as $value) {
525
+            if ($export_user_fields) {
526
+                //show user fields data, if any, for this user
527
+                $user_fields_values = UserManager::get_extra_user_data($row['user_id'],false,false, false, true);
528
+                foreach($user_fields_values as $value) {
529 529
                     $worksheet->setCellValueByColumnAndRow(
530 530
                         $column,
531 531
                         $line,
@@ -535,12 +535,12 @@  discard block
 block discarded – undo
535 535
                             $charset
536 536
                         )
537 537
                     );
538
-					$column++;
539
-				}
540
-			}
538
+                    $column++;
539
+                }
540
+            }
541 541
 
542
-			$worksheet->setCellValueByColumnAndRow($column, $line, api_html_entity_decode(strip_tags($row['title']), ENT_QUOTES, $charset));
543
-			$column++;
542
+            $worksheet->setCellValueByColumnAndRow($column, $line, api_html_entity_decode(strip_tags($row['title']), ENT_QUOTES, $charset));
543
+            $column++;
544 544
             $worksheet->setCellValueByColumnAndRow($column, $line, $row['start_date']);
545 545
             $column++;
546 546
             $worksheet->setCellValueByColumnAndRow($column, $line, $row['end_date']);
@@ -556,14 +556,14 @@  discard block
 block discarded – undo
556 556
             $worksheet->setCellValueByColumnAndRow($column, $line, $row['lp_name']);
557 557
             $column++;
558 558
             $worksheet->setCellValueByColumnAndRow($column, $line, $row['is_user_subscribed']);
559
-			$line++;
560
-		}
559
+            $line++;
560
+        }
561 561
 
562 562
         $file = api_get_path(SYS_ARCHIVE_PATH).api_replace_dangerous_char($filename);
563 563
         $writer = new PHPExcel_Writer_Excel2007($spreadsheet);
564 564
         $writer->save($file);
565 565
         DocumentManager::file_send_for_download($file, true, $filename);
566 566
 
567
-		return true;
568
-	}
567
+        return true;
568
+    }
569 569
 }
Please login to merge, or discard this patch.