Completed
Pull Request — 1.10.x (#1170)
by Angel Fernando Quiroz
40:28
created
main/coursecopy/classes/CourseBuilder.class.php 1 patch
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -91,7 +91,7 @@
 block discarded – undo
91 91
     }
92 92
 
93 93
     /**
94
-     * @param array $array
94
+     * @param string[] $array
95 95
      */
96 96
     public function set_tools_to_build($array)
97 97
     {
Please login to merge, or discard this patch.
main/coursecopy/classes/CourseRestorer.class.php 2 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -1212,6 +1212,7 @@
 block discarded – undo
1212 1212
 	 * Restore a forum-post
1213 1213
 	 * @TODO Restore tree-structure of posts. For example: attachments to posts.
1214 1214
 	 * @param false|string $topic_id
1215
+	 * @param false|string $forum_id
1215 1216
 	 */
1216 1217
     public function restore_post($id, $topic_id, $forum_id, $sessionId = 0)
1217 1218
     {
Please login to merge, or discard this patch.
Indentation   +717 added lines, -717 removed lines patch added patch discarded remove patch
@@ -36,16 +36,16 @@  discard block
 block discarded – undo
36 36
  */
37 37
 class CourseRestorer
38 38
 {
39
-	/**
40
-	 * The course-object
41
-	 */
39
+    /**
40
+     * The course-object
41
+     */
42 42
     public $course;
43 43
     public $destination_course_info;
44 44
 
45
-	/**
46
-	 * What to do with files with same name (FILE_SKIP, FILE_RENAME or
47
-	 * FILE_OVERWRITE)
48
-	 */
45
+    /**
46
+     * What to do with files with same name (FILE_SKIP, FILE_RENAME or
47
+     * FILE_OVERWRITE)
48
+     */
49 49
     public $file_option;
50 50
     public $set_tools_invisible_by_default;
51 51
     public $skip_content;
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
         'events',
58 58
         'forum_category',
59 59
         'forums',
60
-       // 'forum_topics',
60
+        // 'forum_topics',
61 61
         'glossary',
62 62
         'quizzes',
63 63
         'test_category',
@@ -126,15 +126,15 @@  discard block
 block discarded – undo
126 126
         $this->tool_copy_settings = $array;
127 127
     }
128 128
 
129
-	/**
130
-	 * Restore a course.
129
+    /**
130
+     * Restore a course.
131 131
      *
132
-	 * @param string    $destination_course_code code of the Chamilo-course in
133
-	 * @param int	    $session_id
134
-	 * @param bool	    $update_course_settings Course settings are going to be restore?
132
+     * @param string    $destination_course_code code of the Chamilo-course in
133
+     * @param int	    $session_id
134
+     * @param bool	    $update_course_settings Course settings are going to be restore?
135 135
      * @param bool      $respect_base_content
136 136
      * @return false|null
137
-	 */
137
+     */
138 138
     public function restore(
139 139
         $destination_course_code = '',
140 140
         $session_id = 0,
@@ -277,17 +277,17 @@  discard block
 block discarded – undo
277 277
         }
278 278
     }
279 279
 
280
-	/**
281
-	 * Restore only harmless course settings:
280
+    /**
281
+     * Restore only harmless course settings:
282 282
      * course_language, visibility, department_name,department_url,
283 283
      * subscribe, unsubscribe ,category_code
284
-	 *
285
-	 * @param string $destination_course_code
286
-	 */
284
+     *
285
+     * @param string $destination_course_code
286
+     */
287 287
     public function restore_course_settings($destination_course_code)
288 288
     {
289
-	    $origin_course_info = api_get_course_info($destination_course_code);
290
-	    $course_info = $this->course->info;
289
+        $origin_course_info = api_get_course_info($destination_course_code);
290
+        $course_info = $this->course->info;
291 291
         $params['course_language'] = $course_info['language'];
292 292
         $params['visibility'] = $course_info['visibility'];
293 293
         $params['department_name'] = $course_info['department_name'];
@@ -296,8 +296,8 @@  discard block
 block discarded – undo
296 296
         $params['category_code'] = $course_info['categoryCode'];
297 297
         $params['subscribe'] = $course_info['subscribe_allowed'];
298 298
         $params['unsubscribe'] = $course_info['unsubscribe'];
299
-	    CourseManager::update_attributes($origin_course_info['real_id'], $params);
300
-	}
299
+        CourseManager::update_attributes($origin_course_info['real_id'], $params);
300
+    }
301 301
 
302 302
     /**
303 303
      * Restore documents
@@ -311,11 +311,11 @@  discard block
 block discarded – undo
311 311
         $course_info = api_get_course_info($destination_course_code);
312 312
 
313 313
         if ($this->course->has_resources(RESOURCE_DOCUMENT)) {
314
-			$table = Database :: get_course_table(TABLE_DOCUMENT);
315
-			$resources = $this->course->resources;
314
+            $table = Database :: get_course_table(TABLE_DOCUMENT);
315
+            $resources = $this->course->resources;
316 316
             $path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/';
317 317
 
318
-			foreach ($resources[RESOURCE_DOCUMENT] as $id => $document) {
318
+            foreach ($resources[RESOURCE_DOCUMENT] as $id => $document) {
319 319
 
320 320
                 if (empty($document->item_properties[0]['id_session'])) {
321 321
                     $my_session_id = 0;
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
                             }
386 386
                         }
387 387
                     }
388
-		    	} elseif ($document->file_type == DOCUMENT) {
388
+                } elseif ($document->file_type == DOCUMENT) {
389 389
                     //Checking if folder exists in the database otherwise we created it
390 390
                     $dir_to_create = dirname($document->path);
391 391
 
@@ -441,19 +441,19 @@  discard block
 block discarded – undo
441 441
                         }
442 442
                     }
443 443
 
444
-					if (file_exists($path.$document->path)) {
445
-						switch ($this->file_option) {
446
-							case FILE_OVERWRITE:
444
+                    if (file_exists($path.$document->path)) {
445
+                        switch ($this->file_option) {
446
+                            case FILE_OVERWRITE:
447 447
                                 $origin_path = $this->course->backup_path.'/'.$document->path;
448 448
 
449
-								if (file_exists($origin_path)) {
450
-        						    copy($origin_path, $path.$document->path);
449
+                                if (file_exists($origin_path)) {
450
+                                    copy($origin_path, $path.$document->path);
451 451
                                     $sql = "SELECT id FROM $table
452 452
                                             WHERE
453 453
                                                 c_id = ".$this->destination_course_id." AND
454 454
                                                 path = '/".self::DBUTF8escapestring(substr($document->path, 9))."'";
455 455
 
456
-        						    $res = Database::query($sql);
456
+                                    $res = Database::query($sql);
457 457
                                     $count = Database::num_rows($res);
458 458
 
459 459
                                     if ($count == 0) {
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
                                             'session_id' => $my_session_id,
468 468
                                         ];
469 469
 
470
-    									$document_id = Database::insert($table, $params);
470
+                                        $document_id = Database::insert($table, $params);
471 471
 
472 472
                                         if ($document_id) {
473 473
                                             $sql = "UPDATE $table SET id = iid WHERE iid = $document_id";
@@ -575,83 +575,83 @@  discard block
 block discarded – undo
575 575
                                             ],
576 576
                                         ]
577 577
                                     );
578
-								}
578
+                                }
579 579
 
580
-								break;
581
-							case FILE_SKIP:
582
-								$sql = "SELECT id FROM $table
580
+                                break;
581
+                            case FILE_SKIP:
582
+                                $sql = "SELECT id FROM $table
583 583
 								        WHERE
584 584
 								            c_id = ".$this->destination_course_id." AND
585 585
 								            path='/".self::DBUTF8escapestring(substr($document->path, 9))."'";
586
-								$res = Database::query($sql);
587
-								$obj = Database::fetch_object($res);
588
-								$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $obj->id;
589
-								break;
590
-							case FILE_RENAME:
591
-								$i = 1;
592
-								$ext = explode('.', basename($document->path));
593
-								if (count($ext) > 1) {
594
-									$ext = array_pop($ext);
595
-									$file_name_no_ext = substr($document->path, 0, - (strlen($ext) + 1));
596
-									$ext = '.'.$ext;
597
-								} else {
598
-									$ext = '';
599
-									$file_name_no_ext = $document->path;
600
-								}
601
-								$new_file_name = $file_name_no_ext.'_'.$i.$ext;
602
-								$file_exists = file_exists($path.$new_file_name);
603
-								while ($file_exists) {
604
-									$i ++;
605
-									$new_file_name = $file_name_no_ext.'_'.$i.$ext;
606
-									$file_exists = file_exists($path.$new_file_name);
607
-								}
608
-
609
-								if (!empty($session_id)) {
610
-
611
-									$document_path = explode('/',$document->path,3);
612
-									$course_path = $path;
613
-									$orig_base_folder = $document_path[1];
614
-									$orig_base_path   = $course_path.$document_path[0].'/'.$document_path[1];
615
-
616
-									if (is_dir($orig_base_path)) {
617
-
618
-										$new_base_foldername = $orig_base_folder;
619
-										$new_base_path = $orig_base_path;
620
-
621
-										if ($_SESSION['orig_base_foldername'] != $new_base_foldername) {
622
-											unset($_SESSION['new_base_foldername']);
623
-											unset($_SESSION['orig_base_foldername']);
624
-											unset($_SESSION['new_base_path']);
625
-										}
626
-
627
-										$folder_exists = file_exists($new_base_path);
628
-										if ($folder_exists) {
629
-											$_SESSION['orig_base_foldername'] = $new_base_foldername; 		// e.g: carpeta1 in session
630
-											$x = '';
631
-											while ($folder_exists) {
632
-												$x = $x + 1;
633
-												$new_base_foldername = $document_path[1].'_'.$x;
634
-												$new_base_path = $orig_base_path.'_'.$x;
586
+                                $res = Database::query($sql);
587
+                                $obj = Database::fetch_object($res);
588
+                                $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $obj->id;
589
+                                break;
590
+                            case FILE_RENAME:
591
+                                $i = 1;
592
+                                $ext = explode('.', basename($document->path));
593
+                                if (count($ext) > 1) {
594
+                                    $ext = array_pop($ext);
595
+                                    $file_name_no_ext = substr($document->path, 0, - (strlen($ext) + 1));
596
+                                    $ext = '.'.$ext;
597
+                                } else {
598
+                                    $ext = '';
599
+                                    $file_name_no_ext = $document->path;
600
+                                }
601
+                                $new_file_name = $file_name_no_ext.'_'.$i.$ext;
602
+                                $file_exists = file_exists($path.$new_file_name);
603
+                                while ($file_exists) {
604
+                                    $i ++;
605
+                                    $new_file_name = $file_name_no_ext.'_'.$i.$ext;
606
+                                    $file_exists = file_exists($path.$new_file_name);
607
+                                }
608
+
609
+                                if (!empty($session_id)) {
610
+
611
+                                    $document_path = explode('/',$document->path,3);
612
+                                    $course_path = $path;
613
+                                    $orig_base_folder = $document_path[1];
614
+                                    $orig_base_path   = $course_path.$document_path[0].'/'.$document_path[1];
615
+
616
+                                    if (is_dir($orig_base_path)) {
617
+
618
+                                        $new_base_foldername = $orig_base_folder;
619
+                                        $new_base_path = $orig_base_path;
620
+
621
+                                        if ($_SESSION['orig_base_foldername'] != $new_base_foldername) {
622
+                                            unset($_SESSION['new_base_foldername']);
623
+                                            unset($_SESSION['orig_base_foldername']);
624
+                                            unset($_SESSION['new_base_path']);
625
+                                        }
626
+
627
+                                        $folder_exists = file_exists($new_base_path);
628
+                                        if ($folder_exists) {
629
+                                            $_SESSION['orig_base_foldername'] = $new_base_foldername; 		// e.g: carpeta1 in session
630
+                                            $x = '';
631
+                                            while ($folder_exists) {
632
+                                                $x = $x + 1;
633
+                                                $new_base_foldername = $document_path[1].'_'.$x;
634
+                                                $new_base_path = $orig_base_path.'_'.$x;
635 635
                                                 if ($_SESSION['new_base_foldername'] == $new_base_foldername) {
636 636
                                                     break;
637 637
                                                 }
638
-												$folder_exists = file_exists($new_base_path);
639
-											}
640
-											$_SESSION['new_base_foldername'] = $new_base_foldername;
641
-											$_SESSION['new_base_path'] = $new_base_path;
642
-										}
643
-
644
-										if (isset($_SESSION['new_base_foldername']) && isset($_SESSION['new_base_path'])) {
645
-											$new_base_foldername = $_SESSION['new_base_foldername'];
646
-											$new_base_path = $_SESSION['new_base_path'];
647
-										}
648
-
649
-										$dest_document_path = $new_base_path.'/'.$document_path[2];		// e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1/collaborative.png"
650
-										$basedir_dest_path 	= dirname($dest_document_path);				// e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1"
651
-										$base_path_document = $course_path.$document_path[0];			// e.g: "/var/www/wiener/courses/CURSO4/document"
652
-										$path_title = '/'.$new_base_foldername.'/'.$document_path[2];
653
-
654
-										copy_folder_course_session(
638
+                                                $folder_exists = file_exists($new_base_path);
639
+                                            }
640
+                                            $_SESSION['new_base_foldername'] = $new_base_foldername;
641
+                                            $_SESSION['new_base_path'] = $new_base_path;
642
+                                        }
643
+
644
+                                        if (isset($_SESSION['new_base_foldername']) && isset($_SESSION['new_base_path'])) {
645
+                                            $new_base_foldername = $_SESSION['new_base_foldername'];
646
+                                            $new_base_path = $_SESSION['new_base_path'];
647
+                                        }
648
+
649
+                                        $dest_document_path = $new_base_path.'/'.$document_path[2];		// e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1/collaborative.png"
650
+                                        $basedir_dest_path 	= dirname($dest_document_path);				// e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1"
651
+                                        $base_path_document = $course_path.$document_path[0];			// e.g: "/var/www/wiener/courses/CURSO4/document"
652
+                                        $path_title = '/'.$new_base_foldername.'/'.$document_path[2];
653
+
654
+                                        copy_folder_course_session(
655 655
                                             $basedir_dest_path,
656 656
                                             $base_path_document,
657 657
                                             $session_id,
@@ -693,7 +693,7 @@  discard block
 block discarded – undo
693 693
                                             'session_id' => $my_session_id,
694 694
                                         ];
695 695
 
696
-										$document_id = Database::insert($table, $params);
696
+                                        $document_id = Database::insert($table, $params);
697 697
 
698 698
                                         if ($document_id) {
699 699
                                             $sql = "UPDATE $table SET id = iid WHERE iid = $document_id";
@@ -722,10 +722,10 @@  discard block
 block discarded – undo
722 722
                                             null,
723 723
                                             $my_session_id
724 724
                                         );
725
-									} else {
726
-									    if (file_exists($path.$document->path)) {
725
+                                    } else {
726
+                                        if (file_exists($path.$document->path)) {
727 727
                                             copy($path.$document->path, $path.$new_file_name);
728
-									    }
728
+                                        }
729 729
                                         //Replace old course code with the new destination code see BT#1985
730 730
                                         if (file_exists($path.$new_file_name)) {
731 731
                                             $file_info = pathinfo($path.$new_file_name);
@@ -784,10 +784,10 @@  discard block
 block discarded – undo
784 784
                                                 $my_session_id
785 785
                                             );
786 786
                                         }
787
-									}
788
-								} else {
787
+                                    }
788
+                                } else {
789 789
 
790
-									copy($this->course->backup_path.'/'.$document->path, $path.$new_file_name);
790
+                                    copy($this->course->backup_path.'/'.$document->path, $path.$new_file_name);
791 791
 
792 792
                                     //Replace old course code with the new destination code see BT#1985
793 793
                                     if (file_exists($path.$new_file_name)) {
@@ -847,20 +847,20 @@  discard block
 block discarded – undo
847 847
                                         null,
848 848
                                         $my_session_id
849 849
                                     );
850
-								}
851
-								break;
852
-
853
-						} // end switch
854
-					} else {
855
-					    // end if file exists
856
-						//make sure the source file actually exists
857
-						if (is_file($this->course->backup_path.'/'.$document->path) &&
850
+                                }
851
+                                break;
852
+
853
+                        } // end switch
854
+                    } else {
855
+                        // end if file exists
856
+                        //make sure the source file actually exists
857
+                        if (is_file($this->course->backup_path.'/'.$document->path) &&
858 858
                             is_readable($this->course->backup_path.'/'.$document->path) &&
859 859
                             is_dir(dirname($path.$document->path)) &&
860 860
                             is_writeable(dirname($path.$document->path))
861 861
                         ) {
862
-						    //echo 'Copying';
863
-							copy($this->course->backup_path.'/'.$document->path, $path.$document->path);
862
+                            //echo 'Copying';
863
+                            copy($this->course->backup_path.'/'.$document->path, $path.$document->path);
864 864
 
865 865
                             //Replace old course code with the new destination code see BT#1985
866 866
                             if (file_exists($path.$document->path)) {
@@ -898,7 +898,7 @@  discard block
 block discarded – undo
898 898
                                 Database::query($sql);
899 899
                             }
900 900
 
901
-							$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id;
901
+                            $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id;
902 902
 
903 903
                             $itemProperty = isset($document->item_properties[0]) ? $document->item_properties[0] : '';
904 904
                             $insertUserId = isset($itemProperty['insert_user_id']) ? $itemProperty['insert_user_id'] : api_get_user_id();
@@ -920,79 +920,79 @@  discard block
 block discarded – undo
920 920
                                 null,
921 921
                                 $my_session_id
922 922
                             );
923
-						} else {
924
-							if (is_file($this->course->backup_path.'/'.$document->path) &&
923
+                        } else {
924
+                            if (is_file($this->course->backup_path.'/'.$document->path) &&
925 925
                                 is_readable($this->course->backup_path.'/'.$document->path)
926 926
                             ) {
927
-								error_log('Course copy generated an ignoreable error while trying to copy '.$this->course->backup_path.'/'.$document->path.': file not found');
928
-							}
929
-							if (!is_dir(dirname($path.$document->path))) {
930
-								error_log('Course copy generated an ignoreable error while trying to copy to '.dirname($path.$document->path).': directory not found');
931
-							}
932
-							if (!is_writeable(dirname($path.$document->path))) {
933
-								error_log('Course copy generated an ignoreable error while trying to copy to '.dirname($path.$document->path).': directory not writeable');
934
-							}
935
-						}
936
-					} // end file doesn't exist
937
-				}
938
-			} // end for each
939
-
940
-    		// Delete sessions for the copy the new folder in session
941
-    		unset($_SESSION['new_base_foldername']);
942
-    		unset($_SESSION['orig_base_foldername']);
943
-    		unset($_SESSION['new_base_path']);
944
-		}
945
-	}
946
-
947
-	/**
948
-	 * Restore scorm documents
949
-	 * TODO @TODO check that the restore function with renaming doesn't break the scorm structure!
927
+                                error_log('Course copy generated an ignoreable error while trying to copy '.$this->course->backup_path.'/'.$document->path.': file not found');
928
+                            }
929
+                            if (!is_dir(dirname($path.$document->path))) {
930
+                                error_log('Course copy generated an ignoreable error while trying to copy to '.dirname($path.$document->path).': directory not found');
931
+                            }
932
+                            if (!is_writeable(dirname($path.$document->path))) {
933
+                                error_log('Course copy generated an ignoreable error while trying to copy to '.dirname($path.$document->path).': directory not writeable');
934
+                            }
935
+                        }
936
+                    } // end file doesn't exist
937
+                }
938
+            } // end for each
939
+
940
+            // Delete sessions for the copy the new folder in session
941
+            unset($_SESSION['new_base_foldername']);
942
+            unset($_SESSION['orig_base_foldername']);
943
+            unset($_SESSION['new_base_path']);
944
+        }
945
+    }
946
+
947
+    /**
948
+     * Restore scorm documents
949
+     * TODO @TODO check that the restore function with renaming doesn't break the scorm structure!
950 950
      * see #7029
951
-	 */
952
-	public function restore_scorm_documents()
951
+     */
952
+    public function restore_scorm_documents()
953 953
     {
954
-		$perm = api_get_permissions_for_new_directories();
954
+        $perm = api_get_permissions_for_new_directories();
955 955
 
956
-		if ($this->course->has_resources(RESOURCE_SCORM)) {
957
-			$resources = $this->course->resources;
956
+        if ($this->course->has_resources(RESOURCE_SCORM)) {
957
+            $resources = $this->course->resources;
958 958
 
959
-			foreach ($resources[RESOURCE_SCORM] as $document) {
960
-				$path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/';
959
+            foreach ($resources[RESOURCE_SCORM] as $document) {
960
+                $path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/';
961 961
 
962
-				@mkdir(dirname($path.$document->path), $perm, true);
962
+                @mkdir(dirname($path.$document->path), $perm, true);
963 963
 
964
-				if (file_exists($path.$document->path)) {
965
-					switch ($this->file_option) {
966
-						case FILE_OVERWRITE:
967
-							rmdirr($path.$document->path);
964
+                if (file_exists($path.$document->path)) {
965
+                    switch ($this->file_option) {
966
+                        case FILE_OVERWRITE:
967
+                            rmdirr($path.$document->path);
968 968
                             copyDirTo(
969 969
                                 $this->course->backup_path . '/' . $document->path,
970 970
                                 $path . dirname($document->path),
971 971
                                 false
972 972
                             );
973
-							break;
974
-						case FILE_SKIP:
975
-							break;
973
+                            break;
974
+                        case FILE_SKIP:
975
+                            break;
976 976
                         case FILE_RENAME:
977
-							$i = 1;
978
-							$ext = explode('.', basename($document->path));
979
-							if (count($ext) > 1) {
980
-								$ext = array_pop($ext);
981
-								$file_name_no_ext = substr($document->path, 0, - (strlen($ext) + 1));
982
-								$ext = '.'.$ext;
983
-							} else {
984
-								$ext = '';
985
-								$file_name_no_ext = $document->path;
986
-							}
987
-
988
-							$new_file_name = $file_name_no_ext.'_'.$i.$ext;
989
-							$file_exists = file_exists($path.$new_file_name);
990
-
991
-							while ($file_exists) {
992
-								$i ++;
993
-								$new_file_name = $file_name_no_ext.'_'.$i.$ext;
994
-								$file_exists = file_exists($path.$new_file_name);
995
-							}
977
+                            $i = 1;
978
+                            $ext = explode('.', basename($document->path));
979
+                            if (count($ext) > 1) {
980
+                                $ext = array_pop($ext);
981
+                                $file_name_no_ext = substr($document->path, 0, - (strlen($ext) + 1));
982
+                                $ext = '.'.$ext;
983
+                            } else {
984
+                                $ext = '';
985
+                                $file_name_no_ext = $document->path;
986
+                            }
987
+
988
+                            $new_file_name = $file_name_no_ext.'_'.$i.$ext;
989
+                            $file_exists = file_exists($path.$new_file_name);
990
+
991
+                            while ($file_exists) {
992
+                                $i ++;
993
+                                $new_file_name = $file_name_no_ext.'_'.$i.$ext;
994
+                                $file_exists = file_exists($path.$new_file_name);
995
+                            }
996 996
 
997 997
                             rename(
998 998
                                 $this->course->backup_path . '/' . $document->path,
@@ -1008,30 +1008,30 @@  discard block
 block discarded – undo
1008 1008
                                 $this->course->backup_path . '/' . $document->path
1009 1009
                             );
1010 1010
 
1011
-							break;
1012
-					} // end switch
1013
-				} else {
1011
+                            break;
1012
+                    } // end switch
1013
+                } else {
1014 1014
                     // end if file exists
1015 1015
                     copyDirTo(
1016 1016
                         $this->course->backup_path . '/' . $document->path,
1017 1017
                         $path . dirname($document->path),
1018 1018
                         false
1019 1019
                     );
1020
-				}
1021
-			} // end for each
1022
-		}
1023
-	}
1024
-
1025
-	/**
1026
-	 * Restore forums
1027
-	 */
1028
-	public function restore_forums($sessionId = 0)
1020
+                }
1021
+            } // end for each
1022
+        }
1023
+    }
1024
+
1025
+    /**
1026
+     * Restore forums
1027
+     */
1028
+    public function restore_forums($sessionId = 0)
1029 1029
     {
1030
-		if ($this->course->has_resources(RESOURCE_FORUM)) {
1030
+        if ($this->course->has_resources(RESOURCE_FORUM)) {
1031 1031
             $sessionId = intval($sessionId);
1032
-			$table_forum = Database::get_course_table(TABLE_FORUM);
1033
-			$resources = $this->course->resources;
1034
-			foreach ($resources[RESOURCE_FORUM] as $id => $forum) {
1032
+            $table_forum = Database::get_course_table(TABLE_FORUM);
1033
+            $resources = $this->course->resources;
1034
+            foreach ($resources[RESOURCE_FORUM] as $id => $forum) {
1035 1035
                 $params = (array)$forum->obj;
1036 1036
                 $cat_id = '';
1037 1037
                 if (isset($this->course->resources[RESOURCE_FORUMCATEGORY]) &&
@@ -1077,33 +1077,33 @@  discard block
 block discarded – undo
1077 1077
                     Database::query($sql);
1078 1078
                 }
1079 1079
 
1080
-				$this->course->resources[RESOURCE_FORUM][$id]->destination_id = $new_id;
1081
-
1082
-				$forum_topics = 0;
1083
-				if (is_array($this->course->resources[RESOURCE_FORUMTOPIC])) {
1084
-					foreach ($this->course->resources[RESOURCE_FORUMTOPIC] as $topic_id => $topic) {
1085
-						if ($topic->obj->forum_id == $id) {
1086
-							$this->restore_topic($topic_id, $new_id, $sessionId);
1087
-							$forum_topics ++;
1088
-						}
1089
-					}
1090
-				}
1091
-				if ($forum_topics > 0) {
1092
-					$sql = "UPDATE ".$table_forum." SET forum_threads = ".$forum_topics."
1080
+                $this->course->resources[RESOURCE_FORUM][$id]->destination_id = $new_id;
1081
+
1082
+                $forum_topics = 0;
1083
+                if (is_array($this->course->resources[RESOURCE_FORUMTOPIC])) {
1084
+                    foreach ($this->course->resources[RESOURCE_FORUMTOPIC] as $topic_id => $topic) {
1085
+                        if ($topic->obj->forum_id == $id) {
1086
+                            $this->restore_topic($topic_id, $new_id, $sessionId);
1087
+                            $forum_topics ++;
1088
+                        }
1089
+                    }
1090
+                }
1091
+                if ($forum_topics > 0) {
1092
+                    $sql = "UPDATE ".$table_forum." SET forum_threads = ".$forum_topics."
1093 1093
                             WHERE c_id = {$this->destination_course_id} AND forum_id = ".(int)$new_id;
1094
-					Database::query($sql);
1095
-				}
1096
-			}
1097
-		}
1098
-	}
1099
-
1100
-	/**
1101
-	 * Restore forum-categories
1102
-	 */
1094
+                    Database::query($sql);
1095
+                }
1096
+            }
1097
+        }
1098
+    }
1099
+
1100
+    /**
1101
+     * Restore forum-categories
1102
+     */
1103 1103
     public function restore_forum_category($my_id = null, $sessionId = 0)
1104 1104
     {
1105
-		$forum_cat_table = Database :: get_course_table(TABLE_FORUM_CATEGORY);
1106
-		$resources = $this->course->resources;
1105
+        $forum_cat_table = Database :: get_course_table(TABLE_FORUM_CATEGORY);
1106
+        $resources = $this->course->resources;
1107 1107
         if (!empty($resources[RESOURCE_FORUMCATEGORY])) {
1108 1108
             foreach ($resources[RESOURCE_FORUMCATEGORY] as $id => $forum_cat) {
1109 1109
                 if (!empty($my_id)) {
@@ -1150,16 +1150,16 @@  discard block
 block discarded – undo
1150 1150
                 }
1151 1151
             }
1152 1152
         }
1153
-	}
1153
+    }
1154 1154
 
1155
-	/**
1156
-	 * Restore a forum-topic
1157
-	 * @param false|string $forum_id
1158
-	 */
1155
+    /**
1156
+     * Restore a forum-topic
1157
+     * @param false|string $forum_id
1158
+     */
1159 1159
     public function restore_topic($thread_id, $forum_id, $sessionId = 0)
1160 1160
     {
1161
-		$table = Database :: get_course_table(TABLE_FORUM_THREAD);
1162
-		$topic = $this->course->resources[RESOURCE_FORUMTOPIC][$thread_id];
1161
+        $table = Database :: get_course_table(TABLE_FORUM_THREAD);
1162
+        $topic = $this->course->resources[RESOURCE_FORUMTOPIC][$thread_id];
1163 1163
 
1164 1164
         $params = (array)$topic->obj;
1165 1165
         $params = self::DBUTF8_array($params);
@@ -1195,28 +1195,28 @@  discard block
 block discarded – undo
1195 1195
             $sessionId
1196 1196
         );
1197 1197
 
1198
-		$this->course->resources[RESOURCE_FORUMTOPIC][$thread_id]->destination_id = $new_id;
1198
+        $this->course->resources[RESOURCE_FORUMTOPIC][$thread_id]->destination_id = $new_id;
1199 1199
 
1200
-		$topic_replies = -1;
1200
+        $topic_replies = -1;
1201 1201
 
1202
-		foreach ($this->course->resources[RESOURCE_FORUMPOST] as $post_id => $post) {
1203
-			if ($post->obj->thread_id == $thread_id) {
1204
-				$topic_replies++;
1205
-				$this->restore_post($post_id, $new_id, $forum_id, $sessionId);
1206
-			}
1207
-		}
1208
-		return $new_id;
1209
-	}
1202
+        foreach ($this->course->resources[RESOURCE_FORUMPOST] as $post_id => $post) {
1203
+            if ($post->obj->thread_id == $thread_id) {
1204
+                $topic_replies++;
1205
+                $this->restore_post($post_id, $new_id, $forum_id, $sessionId);
1206
+            }
1207
+        }
1208
+        return $new_id;
1209
+    }
1210 1210
 
1211
-	/**
1212
-	 * Restore a forum-post
1213
-	 * @TODO Restore tree-structure of posts. For example: attachments to posts.
1214
-	 * @param false|string $topic_id
1215
-	 */
1211
+    /**
1212
+     * Restore a forum-post
1213
+     * @TODO Restore tree-structure of posts. For example: attachments to posts.
1214
+     * @param false|string $topic_id
1215
+     */
1216 1216
     public function restore_post($id, $topic_id, $forum_id, $sessionId = 0)
1217 1217
     {
1218
-		$table_post = Database :: get_course_table(TABLE_FORUM_POST);
1219
-		$post = $this->course->resources[RESOURCE_FORUMPOST][$id];
1218
+        $table_post = Database :: get_course_table(TABLE_FORUM_POST);
1219
+        $post = $this->course->resources[RESOURCE_FORUMPOST][$id];
1220 1220
         $params = (array) $post->obj;
1221 1221
         $params['c_id'] = $this->destination_course_id;
1222 1222
         $params['forum_id'] = $forum_id;
@@ -1251,37 +1251,37 @@  discard block
 block discarded – undo
1251 1251
             null,
1252 1252
             $sessionId
1253 1253
         );
1254
-		$this->course->resources[RESOURCE_FORUMPOST][$id]->destination_id = $new_id;
1254
+        $this->course->resources[RESOURCE_FORUMPOST][$id]->destination_id = $new_id;
1255 1255
 
1256
-		return $new_id;
1257
-	}
1256
+        return $new_id;
1257
+    }
1258 1258
 
1259
-	/**
1260
-	 * Restore links
1261
-	 */
1259
+    /**
1260
+     * Restore links
1261
+     */
1262 1262
     public function restore_links($session_id = 0)
1263 1263
     {
1264
-		if ($this->course->has_resources(RESOURCE_LINK)) {
1265
-			$link_table = Database :: get_course_table(TABLE_LINK);
1266
-			$resources = $this->course->resources;
1264
+        if ($this->course->has_resources(RESOURCE_LINK)) {
1265
+            $link_table = Database :: get_course_table(TABLE_LINK);
1266
+            $resources = $this->course->resources;
1267 1267
 
1268
-			foreach ($resources[RESOURCE_LINK] as $id => $link) {
1268
+            foreach ($resources[RESOURCE_LINK] as $id => $link) {
1269 1269
                 $cat_id = $this->restore_link_category(
1270 1270
                     $link->category_id,
1271 1271
                     $session_id
1272 1272
                 );
1273
-				$sql = "SELECT MAX(display_order)
1273
+                $sql = "SELECT MAX(display_order)
1274 1274
 				        FROM $link_table
1275 1275
 				        WHERE
1276 1276
 				            c_id = ".$this->destination_course_id." AND
1277 1277
 				            category_id='" . intval($cat_id). "'";
1278
-				$result = Database::query($sql);
1279
-    			list($max_order) = Database::fetch_array($result);
1278
+                $result = Database::query($sql);
1279
+                list($max_order) = Database::fetch_array($result);
1280 1280
 
1281 1281
                 $params = [];
1282
-    			if (!empty($session_id)) {
1282
+                if (!empty($session_id)) {
1283 1283
                     $params['session_id'] = $session_id;
1284
-    			}
1284
+                }
1285 1285
 
1286 1286
                 $params['c_id'] = $this->destination_course_id;
1287 1287
                 $params['url'] = self::DBUTF8($link->url);
@@ -1310,9 +1310,9 @@  discard block
 block discarded – undo
1310 1310
                     }
1311 1311
                     $this->course->resources[RESOURCE_LINK][$id]->destination_id = $id;
1312 1312
                 }
1313
-			}
1314
-		}
1315
-	}
1313
+            }
1314
+        }
1315
+    }
1316 1316
 
1317 1317
     /**
1318 1318
      * Restore a link-category
@@ -1356,21 +1356,21 @@  discard block
 block discarded – undo
1356 1356
         return $this->course->resources[RESOURCE_LINKCATEGORY][$id]->destination_id;
1357 1357
     }
1358 1358
 
1359
-	/**
1360
-	 * Restore tool intro
1361
-	 */
1359
+    /**
1360
+     * Restore tool intro
1361
+     */
1362 1362
     public function restore_tool_intro($sessionId = 0)
1363 1363
     {
1364
-		if ($this->course->has_resources(RESOURCE_TOOL_INTRO)) {
1364
+        if ($this->course->has_resources(RESOURCE_TOOL_INTRO)) {
1365 1365
             $sessionId = intval($sessionId);
1366
-			$tool_intro_table = Database :: get_course_table(TABLE_TOOL_INTRO);
1367
-			$resources = $this->course->resources;
1368
-			foreach ($resources[RESOURCE_TOOL_INTRO] as $id => $tool_intro) {
1369
-				$sql = "DELETE FROM ".$tool_intro_table."
1366
+            $tool_intro_table = Database :: get_course_table(TABLE_TOOL_INTRO);
1367
+            $resources = $this->course->resources;
1368
+            foreach ($resources[RESOURCE_TOOL_INTRO] as $id => $tool_intro) {
1369
+                $sql = "DELETE FROM ".$tool_intro_table."
1370 1370
 				        WHERE
1371 1371
 				            c_id = ".$this->destination_course_id." AND
1372 1372
 				            id='".self::DBUTF8escapestring($tool_intro->id)."'";
1373
-				Database::query($sql);
1373
+                Database::query($sql);
1374 1374
 
1375 1375
                 $tool_intro->intro_text = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1376 1376
                     $tool_intro->intro_text,
@@ -1398,21 +1398,21 @@  discard block
 block discarded – undo
1398 1398
 
1399 1399
                     $this->course->resources[RESOURCE_TOOL_INTRO][$id]->destination_id = $id;
1400 1400
                 }
1401
-			}
1402
-		}
1403
-	}
1401
+            }
1402
+        }
1403
+    }
1404 1404
 
1405
-	/**
1406
-	 * Restore events
1407
-	 */
1405
+    /**
1406
+     * Restore events
1407
+     */
1408 1408
     public function restore_events($sessionId = 0)
1409 1409
     {
1410
-		if ($this->course->has_resources(RESOURCE_EVENT)) {
1410
+        if ($this->course->has_resources(RESOURCE_EVENT)) {
1411 1411
             $sessionId = intval($sessionId);
1412
-			$table = Database :: get_course_table(TABLE_AGENDA);
1413
-			$resources = $this->course->resources;
1414
-			foreach ($resources[RESOURCE_EVENT] as $id => $event) {
1415
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
1412
+            $table = Database :: get_course_table(TABLE_AGENDA);
1413
+            $resources = $this->course->resources;
1414
+            foreach ($resources[RESOURCE_EVENT] as $id => $event) {
1415
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
1416 1416
                 $event->content = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1417 1417
                     $event->content,
1418 1418
                     $this->course->code,
@@ -1430,7 +1430,7 @@  discard block
 block discarded – undo
1430 1430
                     'end_date' => $event->end_date,
1431 1431
                     'session_id' => $sessionId,
1432 1432
                 ];
1433
-				$new_event_id = Database::insert($table, $params);
1433
+                $new_event_id = Database::insert($table, $params);
1434 1434
 
1435 1435
                 if ($new_event_id) {
1436 1436
                     $sql = "UPDATE $table SET id = iid WHERE iid = $new_event_id";
@@ -1443,30 +1443,30 @@  discard block
 block discarded – undo
1443 1443
                     $this->course->resources[RESOURCE_EVENT][$id]->destination_id = $new_event_id;
1444 1444
                 }
1445 1445
 
1446
-				// Copy event attachment
1446
+                // Copy event attachment
1447 1447
 
1448
-				$origin_path = $this->course->backup_path.'/upload/calendar/';
1449
-				$destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/calendar/';
1448
+                $origin_path = $this->course->backup_path.'/upload/calendar/';
1449
+                $destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/calendar/';
1450 1450
 
1451
-				if (!empty($this->course->orig)) {
1451
+                if (!empty($this->course->orig)) {
1452 1452
 
1453
-					$table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
1454
-					$sql = 'SELECT path, comment, size, filename
1453
+                    $table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
1454
+                    $sql = 'SELECT path, comment, size, filename
1455 1455
 					        FROM '.$table_attachment.'
1456 1456
 					        WHERE c_id = '.$this->destination_course_id.' AND agenda_id = '.$id;
1457
-					$attachment_event = Database::query($sql);
1458
-					$attachment_event = Database::fetch_object($attachment_event);
1457
+                    $attachment_event = Database::query($sql);
1458
+                    $attachment_event = Database::fetch_object($attachment_event);
1459 1459
 
1460
-					if (file_exists($origin_path.$attachment_event->path) &&
1460
+                    if (file_exists($origin_path.$attachment_event->path) &&
1461 1461
                         !is_dir($origin_path.$attachment_event->path)
1462 1462
                     ) {
1463
-						$new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1464
-						$copy_result = copy($origin_path.$attachment_event->path, $destination_path.$new_filename);
1465
-						//$copy_result = true;
1466
-						if ($copy_result) {
1467
-							$table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
1463
+                        $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1464
+                        $copy_result = copy($origin_path.$attachment_event->path, $destination_path.$new_filename);
1465
+                        //$copy_result = true;
1466
+                        if ($copy_result) {
1467
+                            $table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
1468 1468
 
1469
-							$params = [
1469
+                            $params = [
1470 1470
                                 'c_id' => $this->destination_course_id,
1471 1471
                                 'path' => self::DBUTF8($new_filename),
1472 1472
                                 'comment' => self::DBUTF8($attachment_event->comment),
@@ -1480,17 +1480,17 @@  discard block
 block discarded – undo
1480 1480
                                 Database::query($sql);
1481 1481
                             }
1482 1482
                         }
1483
-					}
1484
-				} else {
1485
-					// get the info of the file
1486
-					if (!empty($event->attachment_path) &&
1483
+                    }
1484
+                } else {
1485
+                    // get the info of the file
1486
+                    if (!empty($event->attachment_path) &&
1487 1487
                         is_file($origin_path.$event->attachment_path) &&
1488 1488
                         is_readable($origin_path.$event->attachment_path)
1489 1489
                     ) {
1490
-						$new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1491
-						$copy_result = copy($origin_path.$event->attachment_path, $destination_path.$new_filename);
1492
-						if ($copy_result) {
1493
-							$table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
1490
+                        $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1491
+                        $copy_result = copy($origin_path.$event->attachment_path, $destination_path.$new_filename);
1492
+                        if ($copy_result) {
1493
+                            $table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
1494 1494
 
1495 1495
                             $params = [
1496 1496
                                 'c_id' => $this->destination_course_id,
@@ -1506,29 +1506,29 @@  discard block
 block discarded – undo
1506 1506
                                 $sql = "UPDATE $table_attachment SET id = iid WHERE iid = $id";
1507 1507
                                 Database::query($sql);
1508 1508
                             }
1509
-						}
1510
-					}
1511
-				}
1512
-			}
1513
-		}
1514
-	}
1515
-
1516
-	/**
1517
-	 * Restore course-description
1518
-	 */
1509
+                        }
1510
+                    }
1511
+                }
1512
+            }
1513
+        }
1514
+    }
1515
+
1516
+    /**
1517
+     * Restore course-description
1518
+     */
1519 1519
     public function restore_course_descriptions($session_id = 0)
1520 1520
     {
1521
-		if ($this->course->has_resources(RESOURCE_COURSEDESCRIPTION)) {
1522
-			$table = Database :: get_course_table(TABLE_COURSE_DESCRIPTION);
1523
-			$resources = $this->course->resources;
1524
-			foreach ($resources[RESOURCE_COURSEDESCRIPTION] as $id => $cd) {
1521
+        if ($this->course->has_resources(RESOURCE_COURSEDESCRIPTION)) {
1522
+            $table = Database :: get_course_table(TABLE_COURSE_DESCRIPTION);
1523
+            $resources = $this->course->resources;
1524
+            foreach ($resources[RESOURCE_COURSEDESCRIPTION] as $id => $cd) {
1525 1525
                 $courseDescription = (array) $cd;
1526 1526
 
1527 1527
                 $content = isset($courseDescription['content']) ? $courseDescription['content'] : '';
1528 1528
                 $descriptionType = isset($courseDescription['description_type']) ? $courseDescription['description_type'] : '';
1529 1529
                 $title = isset($courseDescription['title']) ? $courseDescription['title'] : '';
1530 1530
 
1531
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
1531
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
1532 1532
                 $description_content = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1533 1533
                     $content,
1534 1534
                     $this->course->code,
@@ -1556,22 +1556,22 @@  discard block
 block discarded – undo
1556 1556
                     }
1557 1557
                     $this->course->resources[RESOURCE_COURSEDESCRIPTION][$id]->destination_id = $id;
1558 1558
                 }
1559
-			}
1560
-		}
1561
-	}
1559
+            }
1560
+        }
1561
+    }
1562 1562
 
1563
-	/**
1564
-	 * Restore announcements
1565
-	 */
1563
+    /**
1564
+     * Restore announcements
1565
+     */
1566 1566
     public function restore_announcements($sessionId = 0)
1567 1567
     {
1568
-		if ($this->course->has_resources(RESOURCE_ANNOUNCEMENT)) {
1568
+        if ($this->course->has_resources(RESOURCE_ANNOUNCEMENT)) {
1569 1569
             $sessionId = intval($sessionId);
1570
-			$table = Database :: get_course_table(TABLE_ANNOUNCEMENT);
1571
-			$resources = $this->course->resources;
1572
-			foreach ($resources[RESOURCE_ANNOUNCEMENT] as $id => $announcement) {
1570
+            $table = Database :: get_course_table(TABLE_ANNOUNCEMENT);
1571
+            $resources = $this->course->resources;
1572
+            foreach ($resources[RESOURCE_ANNOUNCEMENT] as $id => $announcement) {
1573 1573
 
1574
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
1574
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
1575 1575
                 $announcement->content = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1576 1576
                     $announcement->content,
1577 1577
                     $this->course->code,
@@ -1590,7 +1590,7 @@  discard block
 block discarded – undo
1590 1590
                     'session_id' => $sessionId,
1591 1591
                 ];
1592 1592
 
1593
-				$new_announcement_id = Database::insert($table, $params);
1593
+                $new_announcement_id = Database::insert($table, $params);
1594 1594
 
1595 1595
                 if ($new_announcement_id) {
1596 1596
                     $sql = "UPDATE $table SET id = iid WHERE iid = $new_announcement_id";
@@ -1602,32 +1602,32 @@  discard block
 block discarded – undo
1602 1602
                     $this->course->resources[RESOURCE_ANNOUNCEMENT][$id]->destination_id = $new_announcement_id;
1603 1603
                 }
1604 1604
 
1605
-				$origin_path = $this->course->backup_path.'/upload/announcements/';
1606
-				$destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/announcements/';
1605
+                $origin_path = $this->course->backup_path.'/upload/announcements/';
1606
+                $destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/announcements/';
1607 1607
 
1608
-				// Copy announcement attachment file
1609
-				if (!empty($this->course->orig)) {
1608
+                // Copy announcement attachment file
1609
+                if (!empty($this->course->orig)) {
1610 1610
 
1611
-					$table_attachment = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
1612
-					$sql = 'SELECT path, comment, size, filename
1611
+                    $table_attachment = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
1612
+                    $sql = 'SELECT path, comment, size, filename
1613 1613
 					        FROM '.$table_attachment.'
1614 1614
 					        WHERE
1615 1615
 					            c_id = '.$this->destination_course_id.' AND
1616 1616
 					            announcement_id = '.$id;
1617
-					$attachment_event = Database::query($sql);
1618
-					$attachment_event = Database::fetch_object($attachment_event);
1617
+                    $attachment_event = Database::query($sql);
1618
+                    $attachment_event = Database::fetch_object($attachment_event);
1619 1619
 
1620
-					if (file_exists($origin_path.$attachment_event->path) &&
1620
+                    if (file_exists($origin_path.$attachment_event->path) &&
1621 1621
                         !is_dir($origin_path.$attachment_event->path)
1622 1622
                     ) {
1623
-						$new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1623
+                        $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1624 1624
                         $copy_result = copy(
1625 1625
                             $origin_path.$attachment_event->path,
1626 1626
                             $destination_path.$new_filename
1627 1627
                         );
1628 1628
 
1629
-						if ($copy_result) {
1630
-							$table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
1629
+                        if ($copy_result) {
1630
+                            $table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
1631 1631
 
1632 1632
                             $params = [
1633 1633
                                 'c_id' => $this->destination_course_id,
@@ -1644,20 +1644,20 @@  discard block
 block discarded – undo
1644 1644
                                 $sql = "UPDATE $table_attachment SET id = iid WHERE iid = $attachmentId";
1645 1645
                                 Database::query($sql);
1646 1646
                             }
1647
-						}
1648
-					}
1649
-				} else {
1650
-					// get the info of the file
1651
-					if (!empty($announcement->attachment_path) &&
1647
+                        }
1648
+                    }
1649
+                } else {
1650
+                    // get the info of the file
1651
+                    if (!empty($announcement->attachment_path) &&
1652 1652
                         is_file($origin_path.$announcement->attachment_path) &&
1653 1653
                         is_readable($origin_path.$announcement->attachment_path)
1654 1654
                     ) {
1655
-						$new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1656
-						$copy_result = copy($origin_path.$announcement->attachment_path, $destination_path.$new_filename);
1655
+                        $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1656
+                        $copy_result = copy($origin_path.$announcement->attachment_path, $destination_path.$new_filename);
1657 1657
 
1658
-						if ($copy_result) {
1659
-							$table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
1660
-							/*$sql = "INSERT INTO ".$table_attachment." SET
1658
+                        if ($copy_result) {
1659
+                            $table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
1660
+                            /*$sql = "INSERT INTO ".$table_attachment." SET
1661 1661
 							        c_id = ".$this->destination_course_id." ,
1662 1662
 							        path = '".self::DBUTF8escapestring($new_filename)."',
1663 1663
 							        comment = '".self::DBUTF8escapestring($announcement->attachment_comment)."',
@@ -1680,12 +1680,12 @@  discard block
 block discarded – undo
1680 1680
                                 $sql = "UPDATE $table_attachment SET id = iid WHERE iid = $attachmentId";
1681 1681
                                 Database::query($sql);
1682 1682
                             }
1683
-						}
1684
-					}
1685
-				}
1686
-			}
1687
-		}
1688
-	}
1683
+                        }
1684
+                    }
1685
+                }
1686
+            }
1687
+        }
1688
+    }
1689 1689
 
1690 1690
     /**
1691 1691
      * Restore Quiz
@@ -1696,13 +1696,13 @@  discard block
 block discarded – undo
1696 1696
         $session_id = 0,
1697 1697
         $respect_base_content = false
1698 1698
     ) {
1699
-		if ($this->course->has_resources(RESOURCE_QUIZ)) {
1700
-			$table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
1701
-			$table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
1702
-			$table_doc = Database :: get_course_table(TABLE_DOCUMENT);
1703
-			$resources = $this->course->resources;
1699
+        if ($this->course->has_resources(RESOURCE_QUIZ)) {
1700
+            $table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
1701
+            $table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
1702
+            $table_doc = Database :: get_course_table(TABLE_DOCUMENT);
1703
+            $resources = $this->course->resources;
1704 1704
 
1705
-			foreach ($resources[RESOURCE_QUIZ] as $id => $quiz) {
1705
+            foreach ($resources[RESOURCE_QUIZ] as $id => $quiz) {
1706 1706
 
1707 1707
                 if (isset($quiz->obj)) {
1708 1708
                     //For new imports
@@ -1712,7 +1712,7 @@  discard block
 block discarded – undo
1712 1712
                     $quiz->obj = $quiz;
1713 1713
                 }
1714 1714
 
1715
-				$doc = '';
1715
+                $doc = '';
1716 1716
                 if (!empty($quiz->sound)) {
1717 1717
                     if (isset($this->course->resources[RESOURCE_DOCUMENT][$quiz->sound]) &&
1718 1718
                         $this->course->resources[RESOURCE_DOCUMENT][$quiz->sound]->is_restored()) {
@@ -1720,14 +1720,14 @@  discard block
 block discarded – undo
1720 1720
                                 WHERE
1721 1721
                                     c_id = " . $this->destination_course_id . "  AND
1722 1722
                                     id = " . $resources[RESOURCE_DOCUMENT][$quiz->sound]->destination_id;
1723
-						$doc = Database::query($sql);
1724
-						$doc = Database::fetch_object($doc);
1725
-						$doc = str_replace('/audio/', '', $doc->path);
1726
-					}
1727
-				}
1728
-
1729
-				if ($id != -1) {
1730
-					// check resources inside html from ckeditor tool and copy correct urls into recipient course
1723
+                        $doc = Database::query($sql);
1724
+                        $doc = Database::fetch_object($doc);
1725
+                        $doc = str_replace('/audio/', '', $doc->path);
1726
+                    }
1727
+                }
1728
+
1729
+                if ($id != -1) {
1730
+                    // check resources inside html from ckeditor tool and copy correct urls into recipient course
1731 1731
                     $quiz->description = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1732 1732
                         $quiz->description,
1733 1733
                         $this->course->code,
@@ -1736,13 +1736,13 @@  discard block
 block discarded – undo
1736 1736
                         $this->course->info['path']
1737 1737
                     );
1738 1738
 
1739
-					global $_custom;
1740
-					if (isset($_custom['exercises_clean_dates_when_restoring']) &&
1739
+                    global $_custom;
1740
+                    if (isset($_custom['exercises_clean_dates_when_restoring']) &&
1741 1741
                         $_custom['exercises_clean_dates_when_restoring']
1742 1742
                     ) {
1743
-						$quiz->start_time = null;
1744
-						$quiz->end_time   = null;
1745
-					}
1743
+                        $quiz->start_time = null;
1744
+                        $quiz->end_time   = null;
1745
+                    }
1746 1746
 
1747 1747
                     $params = array(
1748 1748
                         'c_id' => $this->destination_course_id,
@@ -1774,10 +1774,10 @@  discard block
 block discarded – undo
1774 1774
                         }
1775 1775
                         $params['session_id'] = $my_session_id;
1776 1776
                     } else {
1777
-        				if (!empty($session_id)) {
1778
-        					$session_id = intval($session_id);
1777
+                        if (!empty($session_id)) {
1778
+                            $session_id = intval($session_id);
1779 1779
                             $params['session_id'] = $session_id;
1780
-    				    }
1780
+                        }
1781 1781
                     }
1782 1782
                     $new_id = Database::insert($table_qui, $params);
1783 1783
 
@@ -1786,15 +1786,15 @@  discard block
 block discarded – undo
1786 1786
                         Database::query($sql);
1787 1787
                     }
1788 1788
 
1789
-				} else {
1790
-					// $id = -1 identifies the fictionary test for collecting
1791
-					// orphan questions. We do not store it in the database.
1792
-					$new_id = -1;
1793
-				}
1789
+                } else {
1790
+                    // $id = -1 identifies the fictionary test for collecting
1791
+                    // orphan questions. We do not store it in the database.
1792
+                    $new_id = -1;
1793
+                }
1794 1794
 
1795
-				$this->course->resources[RESOURCE_QUIZ][$id]->destination_id = $new_id;
1795
+                $this->course->resources[RESOURCE_QUIZ][$id]->destination_id = $new_id;
1796 1796
 
1797
-				$order = 0;
1797
+                $order = 0;
1798 1798
                 if (!empty($quiz->question_ids)) {
1799 1799
                     foreach ($quiz->question_ids as $index => $question_id) {
1800 1800
                         $qid = $this->restore_quiz_question($question_id);
@@ -1807,30 +1807,30 @@  discard block
 block discarded – undo
1807 1807
                         Database::query($sql);
1808 1808
                     }
1809 1809
                 }
1810
-			}
1811
-		}
1812
-	}
1810
+            }
1811
+        }
1812
+    }
1813 1813
 
1814
-	/**
1815
-	 * Restore quiz-questions
1814
+    /**
1815
+     * Restore quiz-questions
1816 1816
      * @params int question id
1817
-	 */
1817
+     */
1818 1818
     public function restore_quiz_question($id)
1819 1819
     {
1820
-		$resources = $this->course->resources;
1820
+        $resources = $this->course->resources;
1821 1821
         $question = isset($resources[RESOURCE_QUIZQUESTION][$id]) ? $resources[RESOURCE_QUIZQUESTION][$id] : null;
1822 1822
 
1823
-		$new_id = 0;
1823
+        $new_id = 0;
1824 1824
 
1825
-		if (is_object($question)) {
1826
-			if ($question->is_restored()) {
1827
-				return $question->destination_id;
1828
-			}
1829
-			$table_que = Database::get_course_table(TABLE_QUIZ_QUESTION);
1830
-			$table_ans = Database::get_course_table(TABLE_QUIZ_ANSWER);
1825
+        if (is_object($question)) {
1826
+            if ($question->is_restored()) {
1827
+                return $question->destination_id;
1828
+            }
1829
+            $table_que = Database::get_course_table(TABLE_QUIZ_QUESTION);
1830
+            $table_ans = Database::get_course_table(TABLE_QUIZ_ANSWER);
1831 1831
             $table_options = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION);
1832 1832
 
1833
-			// check resources inside html from ckeditor tool and copy correct urls into recipient course
1833
+            // check resources inside html from ckeditor tool and copy correct urls into recipient course
1834 1834
             $question->description = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1835 1835
                 $question->description,
1836 1836
                 $this->course->code,
@@ -1851,7 +1851,7 @@  discard block
 block discarded – undo
1851 1851
                 'extra' => self::DBUTF8($question->extra),
1852 1852
             ];
1853 1853
 
1854
-			$new_id = Database::insert($table_que, $params);
1854
+            $new_id = Database::insert($table_que, $params);
1855 1855
 
1856 1856
             if ($new_id) {
1857 1857
 
@@ -1892,7 +1892,7 @@  discard block
 block discarded – undo
1892 1892
 
1893 1893
                 foreach ($temp as $index => $answer) {
1894 1894
                     //id = '".$index."',
1895
-					$params = [
1895
+                    $params = [
1896 1896
                         'c_id' => $this->destination_course_id,
1897 1897
                         'question_id' => $new_id,
1898 1898
                         'answer' => self::DBUTF8($answer['answer']),
@@ -1909,12 +1909,12 @@  discard block
 block discarded – undo
1909 1909
                         $sql = "UPDATE $table_ans SET id = iid, id_auto = iid WHERE iid = $answerId";
1910 1910
                         Database::query($sql);
1911 1911
                     }
1912
-				}
1913
-			} else {
1912
+                }
1913
+            } else {
1914 1914
                 $correct_answers = array();
1915
-				foreach ($question->answers as $index => $answer) {
1915
+                foreach ($question->answers as $index => $answer) {
1916 1916
 
1917
-					// check resources inside html from ckeditor tool and copy correct urls into recipient course
1917
+                    // check resources inside html from ckeditor tool and copy correct urls into recipient course
1918 1918
                     $answer['answer'] = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1919 1919
                         $answer['answer'],
1920 1920
                         $this->course->code,
@@ -1953,8 +1953,8 @@  discard block
 block discarded – undo
1953 1953
                     }
1954 1954
 
1955 1955
                     $correct_answers[$answerId] = $answer['correct'];
1956
-				}
1957
-			}
1956
+                }
1957
+            }
1958 1958
 
1959 1959
             //Current course id
1960 1960
             $course_id = api_get_course_int_id();
@@ -2051,12 +2051,12 @@  discard block
 block discarded – undo
2051 2051
                     }
2052 2052
                 }
2053 2053
             }
2054
-			$this->course->resources[RESOURCE_QUIZQUESTION][$id]->destination_id = $new_id;
2055
-		}
2056
-		return $new_id;
2057
-	}
2054
+            $this->course->resources[RESOURCE_QUIZQUESTION][$id]->destination_id = $new_id;
2055
+        }
2056
+        return $new_id;
2057
+    }
2058 2058
 
2059
-	/**
2059
+    /**
2060 2060
      * @todo : add session id when used for session
2061 2061
      */
2062 2062
     public function restore_test_category($session_id, $respect_base_content, $destination_course_code)
@@ -2136,21 +2136,21 @@  discard block
 block discarded – undo
2136 2136
         $sessionId = intval($sessionId);
2137 2137
 
2138 2138
         if ($this->course->has_resources(RESOURCE_SURVEY)) {
2139
-			$table_sur = Database :: get_course_table(TABLE_SURVEY);
2140
-			$table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION);
2141
-			$table_ans = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
2142
-			$resources = $this->course->resources;
2143
-			foreach ($resources[RESOURCE_SURVEY] as $id => $survey) {
2139
+            $table_sur = Database :: get_course_table(TABLE_SURVEY);
2140
+            $table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION);
2141
+            $table_ans = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
2142
+            $resources = $this->course->resources;
2143
+            foreach ($resources[RESOURCE_SURVEY] as $id => $survey) {
2144 2144
 
2145
-				$sql = 'SELECT survey_id FROM '.$table_sur.'
2145
+                $sql = 'SELECT survey_id FROM '.$table_sur.'
2146 2146
                         WHERE
2147 2147
                             c_id = '.$this->destination_course_id.' AND
2148 2148
                             code = "'.self::DBUTF8escapestring($survey->code).'" AND
2149 2149
                             lang = "'.self::DBUTF8escapestring($survey->lang).'" ';
2150 2150
 
2151
-				$result_check = Database::query($sql);
2151
+                $result_check = Database::query($sql);
2152 2152
 
2153
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
2153
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
2154 2154
                 $survey->title = DocumentManager::replace_urls_inside_content_html_from_copy_course(
2155 2155
                     $survey->title,
2156 2156
                     $this->course->code,
@@ -2204,20 +2204,20 @@  discard block
 block discarded – undo
2204 2204
                     'session_id' => $sessionId,
2205 2205
                 ];
2206 2206
 
2207
-				//An existing survey exists with the same code and the same language
2208
-				if (Database::num_rows($result_check) == 1) {
2209
-					switch ($this->file_option) {
2210
-						case FILE_SKIP:
2211
-							//Do nothing
2212
-							break;
2213
-						case FILE_RENAME:
2214
-							$survey_code = $survey->code.'_';
2215
-							$i=1;
2216
-							$temp_survey_code = $survey_code.$i;
2217
-							while (!$this->is_survey_code_available($temp_survey_code)) {
2218
-								$temp_survey_code = $survey_code.++$i;
2219
-							}
2220
-							$survey_code = $temp_survey_code;
2207
+                //An existing survey exists with the same code and the same language
2208
+                if (Database::num_rows($result_check) == 1) {
2209
+                    switch ($this->file_option) {
2210
+                        case FILE_SKIP:
2211
+                            //Do nothing
2212
+                            break;
2213
+                        case FILE_RENAME:
2214
+                            $survey_code = $survey->code.'_';
2215
+                            $i=1;
2216
+                            $temp_survey_code = $survey_code.$i;
2217
+                            while (!$this->is_survey_code_available($temp_survey_code)) {
2218
+                                $temp_survey_code = $survey_code.++$i;
2219
+                            }
2220
+                            $survey_code = $temp_survey_code;
2221 2221
 
2222 2222
                             $params['code'] = $survey_code;
2223 2223
                             $new_id = Database::insert($table_sur, $params);
@@ -2236,25 +2236,25 @@  discard block
 block discarded – undo
2236 2236
                                     Database::query($sql);
2237 2237
                                 }
2238 2238
                             }
2239
-							break;
2240
-						case FILE_OVERWRITE:
2241
-							// Delete the existing survey with the same code and language and import the one of the source course
2242
-							// getting the information of the survey (used for when the survey is shared)
2239
+                            break;
2240
+                        case FILE_OVERWRITE:
2241
+                            // Delete the existing survey with the same code and language and import the one of the source course
2242
+                            // getting the information of the survey (used for when the survey is shared)
2243 2243
 
2244
-							$sql = "SELECT * FROM $table_sur
2244
+                            $sql = "SELECT * FROM $table_sur
2245 2245
 							        WHERE
2246 2246
 							            c_id = ".$this->destination_course_id." AND
2247 2247
 							            survey_id='".self::DBUTF8escapestring(Database::result($result_check,0,0))."'";
2248
-							$result = Database::query($sql);
2249
-							$survey_data = Database::fetch_array($result,'ASSOC');
2248
+                            $result = Database::query($sql);
2249
+                            $survey_data = Database::fetch_array($result,'ASSOC');
2250 2250
 
2251
-							// if the survey is shared => also delete the shared content
2252
-							if (isset($survey_data['survey_share']) && is_numeric($survey_data['survey_share'])) {
2251
+                            // if the survey is shared => also delete the shared content
2252
+                            if (isset($survey_data['survey_share']) && is_numeric($survey_data['survey_share'])) {
2253 2253
                                 SurveyManager::delete_survey($survey_data['survey_share'], true,$this->destination_course_id);
2254
-							}
2255
-							SurveyManager :: delete_survey($survey_data['survey_id'],false,$this->destination_course_id);
2254
+                            }
2255
+                            SurveyManager :: delete_survey($survey_data['survey_id'],false,$this->destination_course_id);
2256 2256
 
2257
-							// Insert the new source survey
2257
+                            // Insert the new source survey
2258 2258
                             $new_id = Database::insert($table_sur, $params);
2259 2259
 
2260 2260
                             if ($new_id) {
@@ -2275,11 +2275,11 @@  discard block
 block discarded – undo
2275 2275
                                     Database::query($sql);
2276 2276
                                 }
2277 2277
                             }
2278
-							break;
2279
-						default:
2280
-							break;
2281
-					}
2282
-				} else {
2278
+                            break;
2279
+                        default:
2280
+                            break;
2281
+                    }
2282
+                } else {
2283 2283
                     // No existing survey with the same language and the same code, we just copy the survey
2284 2284
                     $new_id = Database::insert($table_sur, $params);
2285 2285
 
@@ -2301,45 +2301,45 @@  discard block
 block discarded – undo
2301 2301
                             Database::query($sql);
2302 2302
                         }
2303 2303
                     }
2304
-				}
2305
-			}
2306
-		}
2307
-	}
2308
-
2309
-	/**
2310
-	 * Check availability of a survey code
2311
-	 * @param string $survey_code
2312
-	 */
2304
+                }
2305
+            }
2306
+        }
2307
+    }
2308
+
2309
+    /**
2310
+     * Check availability of a survey code
2311
+     * @param string $survey_code
2312
+     */
2313 2313
     public function is_survey_code_available($survey_code)
2314 2314
     {
2315
-		$table_sur = Database :: get_course_table(TABLE_SURVEY);
2316
-		$sql = "SELECT * FROM $table_sur
2315
+        $table_sur = Database :: get_course_table(TABLE_SURVEY);
2316
+        $sql = "SELECT * FROM $table_sur
2317 2317
 		        WHERE
2318 2318
 		            c_id = ".$this->destination_course_id." AND
2319 2319
 		            code='".self::DBUTF8escapestring($survey_code)."'";
2320
-		$result = Database::query($sql);
2321
-		if (Database::num_rows($result) > 0) return false; else return true;
2322
-	}
2323
-
2324
-	/**
2325
-	 * Restore survey-questions
2326
-	 * @param string $survey_id
2327
-	 */
2320
+        $result = Database::query($sql);
2321
+        if (Database::num_rows($result) > 0) return false; else return true;
2322
+    }
2323
+
2324
+    /**
2325
+     * Restore survey-questions
2326
+     * @param string $survey_id
2327
+     */
2328 2328
     public function restore_survey_question($id, $survey_id)
2329 2329
     {
2330
-		$resources = $this->course->resources;
2331
-		$question = $resources[RESOURCE_SURVEYQUESTION][$id];
2330
+        $resources = $this->course->resources;
2331
+        $question = $resources[RESOURCE_SURVEYQUESTION][$id];
2332 2332
 
2333
-		$new_id=0;
2333
+        $new_id=0;
2334 2334
 
2335
-		if (is_object($question)) {
2336
-			if ($question->is_restored()) {
2337
-				return $question->destination_id;
2338
-			}
2339
-			$table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION);
2340
-			$table_ans = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
2335
+        if (is_object($question)) {
2336
+            if ($question->is_restored()) {
2337
+                return $question->destination_id;
2338
+            }
2339
+            $table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION);
2340
+            $table_ans = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
2341 2341
 
2342
-			// check resources inside html from ckeditor tool and copy correct urls into recipient course
2342
+            // check resources inside html from ckeditor tool and copy correct urls into recipient course
2343 2343
             $question->survey_question = DocumentManager::replace_urls_inside_content_html_from_copy_course(
2344 2344
                 $question->survey_question,
2345 2345
                 $this->course->code,
@@ -2393,10 +2393,10 @@  discard block
 block discarded – undo
2393 2393
                 }
2394 2394
                 $this->course->resources[RESOURCE_SURVEYQUESTION][$id]->destination_id = $new_id;
2395 2395
             }
2396
-		}
2396
+        }
2397 2397
 
2398
-		return $new_id;
2399
-	}
2398
+        return $new_id;
2399
+    }
2400 2400
 
2401 2401
     /**
2402 2402
      * Restoring learning paths
@@ -2407,20 +2407,20 @@  discard block
 block discarded – undo
2407 2407
     {
2408 2408
         $session_id = intval($session_id);
2409 2409
 
2410
-		if ($this->course->has_resources(RESOURCE_LEARNPATH)) {
2410
+        if ($this->course->has_resources(RESOURCE_LEARNPATH)) {
2411 2411
             $table_main = Database::get_course_table(TABLE_LP_MAIN);
2412 2412
             $table_item = Database::get_course_table(TABLE_LP_ITEM);
2413 2413
             $table_tool = Database::get_course_table(TABLE_TOOL_LIST);
2414 2414
 
2415
-			$resources = $this->course->resources;
2415
+            $resources = $this->course->resources;
2416 2416
 
2417
-			$origin_path = $this->course->backup_path.'/upload/learning_path/images/';
2418
-			$destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/learning_path/images/';
2417
+            $origin_path = $this->course->backup_path.'/upload/learning_path/images/';
2418
+            $destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/learning_path/images/';
2419 2419
 
2420
-			foreach ($resources[RESOURCE_LEARNPATH] as $id => $lp) {
2420
+            foreach ($resources[RESOURCE_LEARNPATH] as $id => $lp) {
2421 2421
 
2422
-				$condition_session = "";
2423
-				if (!empty($session_id)) {
2422
+                $condition_session = "";
2423
+                if (!empty($session_id)) {
2424 2424
                     if ($respect_base_content) {
2425 2425
                         $my_session_id = $lp->session_id;
2426 2426
                         if (!empty($lp->session_id)) {
@@ -2431,21 +2431,21 @@  discard block
 block discarded – undo
2431 2431
                         $session_id = intval($session_id);
2432 2432
                         $condition_session = $session_id;
2433 2433
                     }
2434
-				}
2435
-
2436
-				// Adding the author's image
2437
-				if (!empty($lp->preview_image)) {
2438
-					$new_filename = uniqid('').substr($lp->preview_image,strlen($lp->preview_image)-7, strlen($lp->preview_image));
2439
-					if (file_exists($origin_path.$lp->preview_image) && !is_dir($origin_path.$lp->preview_image)) {
2440
-						$copy_result = copy($origin_path.$lp->preview_image, $destination_path.$new_filename);
2441
-						//$copy_result = true;
2442
-						if ($copy_result) {
2443
-							$lp->preview_image = $new_filename;
2444
-						} else {
2445
-							$lp->preview_image ='';
2446
-						}
2447
-					}
2448
-				}
2434
+                }
2435
+
2436
+                // Adding the author's image
2437
+                if (!empty($lp->preview_image)) {
2438
+                    $new_filename = uniqid('').substr($lp->preview_image,strlen($lp->preview_image)-7, strlen($lp->preview_image));
2439
+                    if (file_exists($origin_path.$lp->preview_image) && !is_dir($origin_path.$lp->preview_image)) {
2440
+                        $copy_result = copy($origin_path.$lp->preview_image, $destination_path.$new_filename);
2441
+                        //$copy_result = true;
2442
+                        if ($copy_result) {
2443
+                            $lp->preview_image = $new_filename;
2444
+                        } else {
2445
+                            $lp->preview_image ='';
2446
+                        }
2447
+                    }
2448
+                }
2449 2449
 
2450 2450
                 if ($this->add_text_in_items) {
2451 2451
                     $lp->name = $lp->name.' '.get_lang('CopyLabelSuffix');
@@ -2492,7 +2492,7 @@  discard block
 block discarded – undo
2492 2492
                     $params['session_id'] = $condition_session;
2493 2493
                 }
2494 2494
 
2495
-				$new_lp_id = Database::insert($table_main, $params);
2495
+                $new_lp_id = Database::insert($table_main, $params);
2496 2496
 
2497 2497
                 if ($new_lp_id) {
2498 2498
 
@@ -2553,13 +2553,13 @@  discard block
 block discarded – undo
2553 2553
                 $old_refs = array();
2554 2554
                 $prerequisite_ids = array();
2555 2555
 
2556
-				foreach ($lp->get_items() as $index => $item) {
2557
-					// we set the ref code here and then we update in a for loop
2558
-					$ref = $item['ref'];
2556
+                foreach ($lp->get_items() as $index => $item) {
2557
+                    // we set the ref code here and then we update in a for loop
2558
+                    $ref = $item['ref'];
2559 2559
 
2560
-					// Dealing with path the same way as ref as some data has
2560
+                    // Dealing with path the same way as ref as some data has
2561 2561
                     // been put into path when it's a local resource
2562
-					// Only fix the path for no scos
2562
+                    // Only fix the path for no scos
2563 2563
                     if ($item['item_type'] == 'sco') {
2564 2564
                         $path = $item['path'];
2565 2565
                     } else {
@@ -2588,128 +2588,128 @@  discard block
 block discarded – undo
2588 2588
                         'launch_data' => self::DBUTF8($item['launch_data']),
2589 2589
                     ];
2590 2590
 
2591
-					$new_item_id = Database::insert($table_item, $params);
2591
+                    $new_item_id = Database::insert($table_item, $params);
2592 2592
 
2593 2593
                     $sql = "UPDATE $table_item SET id = iid WHERE iid = $new_item_id";
2594 2594
                     Database::query($sql);
2595 2595
 
2596
-					//save a link between old and new item IDs
2597
-					$new_item_ids[$item['id']] = $new_item_id;
2598
-					//save a reference of items that need a parent_item_id refresh
2599
-					$parent_item_ids[$new_item_id] = $item['parent_item_id'];
2600
-					//save a reference of items that need a previous_item_id refresh
2601
-					$previous_item_ids[$new_item_id] = $item['previous_item_id'];
2602
-					//save a reference of items that need a next_item_id refresh
2603
-					$next_item_ids[$new_item_id] = $item['next_item_id'];
2604
-
2605
-					if (!empty($item['prerequisite'])) {
2606
-						if ($lp->lp_type =='2') {
2607
-							// if is an sco
2608
-							$old_prerequisite[$new_item_id]= $item['prerequisite'];
2609
-						} else {
2610
-							$old_prerequisite[$new_item_id]= $new_item_ids[$item['prerequisite']];
2611
-						}
2612
-					}
2613
-
2614
-					if (!empty($ref)) {
2615
-						if ($lp->lp_type =='2') {
2616
-							// if is an sco
2617
-							$old_refs[$new_item_id]= $ref;
2618
-						} else {
2596
+                    //save a link between old and new item IDs
2597
+                    $new_item_ids[$item['id']] = $new_item_id;
2598
+                    //save a reference of items that need a parent_item_id refresh
2599
+                    $parent_item_ids[$new_item_id] = $item['parent_item_id'];
2600
+                    //save a reference of items that need a previous_item_id refresh
2601
+                    $previous_item_ids[$new_item_id] = $item['previous_item_id'];
2602
+                    //save a reference of items that need a next_item_id refresh
2603
+                    $next_item_ids[$new_item_id] = $item['next_item_id'];
2604
+
2605
+                    if (!empty($item['prerequisite'])) {
2606
+                        if ($lp->lp_type =='2') {
2607
+                            // if is an sco
2608
+                            $old_prerequisite[$new_item_id]= $item['prerequisite'];
2609
+                        } else {
2610
+                            $old_prerequisite[$new_item_id]= $new_item_ids[$item['prerequisite']];
2611
+                        }
2612
+                    }
2613
+
2614
+                    if (!empty($ref)) {
2615
+                        if ($lp->lp_type =='2') {
2616
+                            // if is an sco
2617
+                            $old_refs[$new_item_id]= $ref;
2618
+                        } else {
2619 2619
                             $old_refs[$new_item_id]= $new_item_ids[$ref];
2620
-						}
2621
-					}
2620
+                        }
2621
+                    }
2622 2622
 
2623
-					$prerequisite_ids[$new_item_id] = $item['prerequisite'];
2624
-				}
2623
+                    $prerequisite_ids[$new_item_id] = $item['prerequisite'];
2624
+                }
2625 2625
 
2626
-				// Updating prerequisites
2627
-				foreach ($old_prerequisite  as $key=>$my_old_prerequisite) {
2628
-					if($my_old_prerequisite != ''){
2629
-						$sql = "UPDATE ".$table_item." SET prerequisite = '".$my_old_prerequisite."'
2626
+                // Updating prerequisites
2627
+                foreach ($old_prerequisite  as $key=>$my_old_prerequisite) {
2628
+                    if($my_old_prerequisite != ''){
2629
+                        $sql = "UPDATE ".$table_item." SET prerequisite = '".$my_old_prerequisite."'
2630 2630
 						        WHERE c_id = ".$this->destination_course_id." AND id = '".$key."'  ";
2631
-						Database::query($sql);
2632
-					}
2633
-				}
2634
-
2635
-				// Updating refs
2636
-				foreach ($old_refs  as $key=>$my_old_ref) {
2637
-					if ($my_old_ref != '') {
2638
-						$sql = "UPDATE ".$table_item." SET ref = '".$my_old_ref."'
2631
+                        Database::query($sql);
2632
+                    }
2633
+                }
2634
+
2635
+                // Updating refs
2636
+                foreach ($old_refs  as $key=>$my_old_ref) {
2637
+                    if ($my_old_ref != '') {
2638
+                        $sql = "UPDATE ".$table_item." SET ref = '".$my_old_ref."'
2639 2639
 						        WHERE c_id = ".$this->destination_course_id." AND id = '".$key."'  ";
2640
-						Database::query($sql);
2641
-					}
2642
-				}
2643
-
2644
-				foreach ($parent_item_ids as $new_item_id => $parent_item_old_id) {
2645
-					$parent_new_id = 0;
2646
-					if($parent_item_old_id != 0){
2647
-						$parent_new_id = $new_item_ids[$parent_item_old_id];
2648
-					}
2649
-					$sql = "UPDATE ".$table_item." SET parent_item_id = '".$parent_new_id."'
2640
+                        Database::query($sql);
2641
+                    }
2642
+                }
2643
+
2644
+                foreach ($parent_item_ids as $new_item_id => $parent_item_old_id) {
2645
+                    $parent_new_id = 0;
2646
+                    if($parent_item_old_id != 0){
2647
+                        $parent_new_id = $new_item_ids[$parent_item_old_id];
2648
+                    }
2649
+                    $sql = "UPDATE ".$table_item." SET parent_item_id = '".$parent_new_id."'
2650 2650
 					        WHERE c_id = ".$this->destination_course_id." AND id = '".$new_item_id."'";
2651
-					Database::query($sql);
2652
-				}
2653
-				foreach ($previous_item_ids as $new_item_id => $previous_item_old_id) {
2654
-					$previous_new_id = 0;
2655
-					if($previous_item_old_id != 0){
2656
-						$previous_new_id = $new_item_ids[$previous_item_old_id];
2657
-					}
2658
-					$sql = "UPDATE ".$table_item." SET previous_item_id = '".$previous_new_id."'
2651
+                    Database::query($sql);
2652
+                }
2653
+                foreach ($previous_item_ids as $new_item_id => $previous_item_old_id) {
2654
+                    $previous_new_id = 0;
2655
+                    if($previous_item_old_id != 0){
2656
+                        $previous_new_id = $new_item_ids[$previous_item_old_id];
2657
+                    }
2658
+                    $sql = "UPDATE ".$table_item." SET previous_item_id = '".$previous_new_id."'
2659 2659
 					        WHERE  c_id = ".$this->destination_course_id." AND id = '".$new_item_id."'";
2660
-					Database::query($sql);
2661
-				}
2662
-
2663
-				foreach ($next_item_ids as $new_item_id => $next_item_old_id) {
2664
-					$next_new_id = 0;
2665
-					if($next_item_old_id != 0){
2666
-						$next_new_id = $new_item_ids[$next_item_old_id];
2667
-					}
2668
-					$sql = "UPDATE ".$table_item." SET next_item_id = '".$next_new_id."'
2660
+                    Database::query($sql);
2661
+                }
2662
+
2663
+                foreach ($next_item_ids as $new_item_id => $next_item_old_id) {
2664
+                    $next_new_id = 0;
2665
+                    if($next_item_old_id != 0){
2666
+                        $next_new_id = $new_item_ids[$next_item_old_id];
2667
+                    }
2668
+                    $sql = "UPDATE ".$table_item." SET next_item_id = '".$next_new_id."'
2669 2669
 					        WHERE c_id = ".$this->destination_course_id." AND id = '".$new_item_id."'";
2670
-					Database::query($sql);
2671
-				}
2672
-
2673
-				foreach ($prerequisite_ids as $new_item_id => $prerequisite_old_id) {
2674
-					$prerequisite_new_id = 0;
2675
-					if($prerequisite_old_id != 0){
2676
-						$prerequisite_new_id = $new_item_ids[$prerequisite_old_id];
2677
-					}
2678
-					$sql = "UPDATE ".$table_item." SET prerequisite = '".$prerequisite_new_id."'
2670
+                    Database::query($sql);
2671
+                }
2672
+
2673
+                foreach ($prerequisite_ids as $new_item_id => $prerequisite_old_id) {
2674
+                    $prerequisite_new_id = 0;
2675
+                    if($prerequisite_old_id != 0){
2676
+                        $prerequisite_new_id = $new_item_ids[$prerequisite_old_id];
2677
+                    }
2678
+                    $sql = "UPDATE ".$table_item." SET prerequisite = '".$prerequisite_new_id."'
2679 2679
 					        WHERE c_id = ".$this->destination_course_id." AND id = '".$new_item_id."'";
2680
-					Database::query($sql);
2681
-				}
2682
-				$this->course->resources[RESOURCE_LEARNPATH][$id]->destination_id = $new_lp_id;
2683
-			}
2684
-		}
2685
-	}
2686
-
2687
-	/**
2688
-	 * Restore works
2680
+                    Database::query($sql);
2681
+                }
2682
+                $this->course->resources[RESOURCE_LEARNPATH][$id]->destination_id = $new_lp_id;
2683
+            }
2684
+        }
2685
+    }
2686
+
2687
+    /**
2688
+     * Restore works
2689 2689
      * @deprecated use restore_works
2690 2690
      *
2691
-	 */
2692
-	public function restore_student_publication($sessionId = 0)
2691
+     */
2692
+    public function restore_student_publication($sessionId = 0)
2693 2693
     {
2694 2694
         $sessionId = intval($sessionId);
2695
-		$work_assignment_table  = Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
2696
-		$work_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
2697
-		$item_property_table  	= Database :: get_course_table(TABLE_ITEM_PROPERTY);
2695
+        $work_assignment_table  = Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
2696
+        $work_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
2697
+        $item_property_table  	= Database :: get_course_table(TABLE_ITEM_PROPERTY);
2698 2698
 
2699
-		// Query in student publication
2700
-		$sql = 'SELECT * FROM '.$work_table.'
2699
+        // Query in student publication
2700
+        $sql = 'SELECT * FROM '.$work_table.'
2701 2701
 		        WHERE c_id = '.$this->course_origin_id.' AND filetype = "folder" AND active IN (0, 1) ';
2702 2702
 
2703
-		$result = Database::query($sql);
2704
-		$folders = Database::store_result($result, 'ASSOC');
2703
+        $result = Database::query($sql);
2704
+        $folders = Database::store_result($result, 'ASSOC');
2705 2705
 
2706
-		foreach ($folders  as $folder) {
2707
-		    $old_id = $folder['id'];
2706
+        foreach ($folders  as $folder) {
2707
+            $old_id = $folder['id'];
2708 2708
             unset($folder['id']);
2709
-			$folder['c_id'] = $this->destination_course_id;
2709
+            $folder['c_id'] = $this->destination_course_id;
2710 2710
             $folder['parent_id'] = 0;
2711 2711
             $folder['session_id'] = $sessionId;
2712
-			$new_id = Database::insert($work_table, $folder);
2712
+            $new_id = Database::insert($work_table, $folder);
2713 2713
 
2714 2714
             if ($new_id) {
2715 2715
                 //query in item property
@@ -2768,23 +2768,23 @@  discard block
 block discarded – undo
2768 2768
                     }
2769 2769
                 }
2770 2770
             }
2771
-		}
2771
+        }
2772 2772
 
2773
-		$destination = '../../courses/'.$this->course->destination_path.'/work/';
2774
-		$origin = '../../courses/'.$this->course->info['path'].'/work/';
2775
-		self::allow_create_all_directory($origin,$destination,false);
2776
-	}
2773
+        $destination = '../../courses/'.$this->course->destination_path.'/work/';
2774
+        $origin = '../../courses/'.$this->course->info['path'].'/work/';
2775
+        self::allow_create_all_directory($origin,$destination,false);
2776
+    }
2777 2777
 
2778 2778
     /**
2779
-    * copy all directory and sub directory
2780
-    * @param string The path origin
2781
-    * @param string The path destination
2782
-    * @param boolean Option Overwrite
2783
-    * @param string $source
2784
-    * @param string $dest
2785
-    * @return void()
2786
-    * @deprecated
2787
-    */
2779
+     * copy all directory and sub directory
2780
+     * @param string The path origin
2781
+     * @param string The path destination
2782
+     * @param boolean Option Overwrite
2783
+     * @param string $source
2784
+     * @param string $dest
2785
+     * @return void()
2786
+     * @deprecated
2787
+     */
2788 2788
     public function allow_create_all_directory($source, $dest, $overwrite = false)
2789 2789
     {
2790 2790
         if (!is_dir($dest)) {
@@ -2795,14 +2795,14 @@  discard block
 block discarded – undo
2795 2795
                 if ($file != '.' && $file != '..') {
2796 2796
                     $path = $source . '/' . $file;
2797 2797
                     if (is_file($path)) {
2798
-                       /* if (!is_file($dest . '/' . $file) || $overwrite)
2798
+                        /* if (!is_file($dest . '/' . $file) || $overwrite)
2799 2799
                         if (!@copy($path, $dest . '/' . $file)) {
2800 2800
                             echo '<font color="red">File ('.$path.') '.get_lang('NotHavePermission').'</font>';
2801 2801
                         }*/
2802 2802
                     } elseif(is_dir($path)) {
2803 2803
                         if (!is_dir($dest . '/' . $file))
2804 2804
                         mkdir($dest . '/' . $file);
2805
-                       self:: allow_create_all_directory($path, $dest . '/' . $file, $overwrite);
2805
+                        self:: allow_create_all_directory($path, $dest . '/' . $file, $overwrite);
2806 2806
                     }
2807 2807
                 }
2808 2808
             }
@@ -2810,12 +2810,12 @@  discard block
 block discarded – undo
2810 2810
         }
2811 2811
     }
2812 2812
 
2813
-	/**
2814
-	 * Gets the new ID of one specific tool item from the tool name and the old ID
2815
-	 * @param	string	Tool name
2816
-	 * @param	integer	Old ID
2817
-	 * @return	integer	New ID
2818
-	 */
2813
+    /**
2814
+     * Gets the new ID of one specific tool item from the tool name and the old ID
2815
+     * @param	string	Tool name
2816
+     * @param	integer	Old ID
2817
+     * @return	integer	New ID
2818
+     */
2819 2819
     public function get_new_id($tool, $ref)
2820 2820
     {
2821 2821
         // Check if the value exist in the current array.
@@ -2837,25 +2837,25 @@  discard block
 block discarded – undo
2837 2837
         }
2838 2838
 
2839 2839
         return '';
2840
-	}
2840
+    }
2841 2841
 
2842
-	/**
2843
-	 * Restore glossary
2844
-	 */
2842
+    /**
2843
+     * Restore glossary
2844
+     */
2845 2845
     public function restore_glossary($session_id = 0)
2846 2846
     {
2847
-		if ($this->course->has_resources(RESOURCE_GLOSSARY)) {
2848
-			$table_glossary = Database :: get_course_table(TABLE_GLOSSARY);
2849
-			$resources = $this->course->resources;
2850
-			foreach ($resources[RESOURCE_GLOSSARY] as $id => $glossary) {
2847
+        if ($this->course->has_resources(RESOURCE_GLOSSARY)) {
2848
+            $table_glossary = Database :: get_course_table(TABLE_GLOSSARY);
2849
+            $resources = $this->course->resources;
2850
+            foreach ($resources[RESOURCE_GLOSSARY] as $id => $glossary) {
2851 2851
 
2852 2852
                 $params = [];
2853
-    			if (!empty($session_id)) {
2854
-    				$session_id = intval($session_id);
2853
+                if (!empty($session_id)) {
2854
+                    $session_id = intval($session_id);
2855 2855
                     $params['session_id'] = $session_id;
2856
-    			}
2856
+                }
2857 2857
 
2858
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
2858
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
2859 2859
                 $glossary->description = DocumentManager::replace_urls_inside_content_html_from_copy_course(
2860 2860
                     $glossary->description,
2861 2861
                     $this->course->code,
@@ -2889,27 +2889,27 @@  discard block
 block discarded – undo
2889 2889
 
2890 2890
                     $this->course->resources[RESOURCE_GLOSSARY][$id]->destination_id = $my_id;
2891 2891
                 }
2892
-			}
2893
-		}
2894
-	}
2892
+            }
2893
+        }
2894
+    }
2895 2895
 
2896 2896
     /**
2897 2897
      * @param int $session_id
2898 2898
      */
2899 2899
     public function restore_wiki($session_id = 0)
2900 2900
     {
2901
-		if ($this->course->has_resources(RESOURCE_WIKI)) {
2902
-			// wiki table of the target course
2903
-			$table_wiki = Database :: get_course_table(TABLE_WIKI);
2904
-			$table_wiki_conf = Database :: get_course_table(TABLE_WIKI_CONF);
2901
+        if ($this->course->has_resources(RESOURCE_WIKI)) {
2902
+            // wiki table of the target course
2903
+            $table_wiki = Database :: get_course_table(TABLE_WIKI);
2904
+            $table_wiki_conf = Database :: get_course_table(TABLE_WIKI_CONF);
2905 2905
 
2906
-			// storing all the resources that have to be copied in an array
2907
-			$resources = $this->course->resources;
2906
+            // storing all the resources that have to be copied in an array
2907
+            $resources = $this->course->resources;
2908 2908
 
2909
-			foreach ($resources[RESOURCE_WIKI] as $id => $wiki) {
2910
-				// the sql statement to insert the groups from the old course to the new course
2909
+            foreach ($resources[RESOURCE_WIKI] as $id => $wiki) {
2910
+                // the sql statement to insert the groups from the old course to the new course
2911 2911
 
2912
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
2912
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
2913 2913
                 $wiki->content = DocumentManager::replace_urls_inside_content_html_from_copy_course(
2914 2914
                     $wiki->content,
2915 2915
                     $this->course->code,
@@ -2932,7 +2932,7 @@  discard block
 block discarded – undo
2932 2932
                     'session_id' => !empty($session_id) ? intval($session_id) : 0,
2933 2933
                 ];
2934 2934
 
2935
-				$new_id = Database::insert($table_wiki, $params);
2935
+                $new_id = Database::insert($table_wiki, $params);
2936 2936
 
2937 2937
                 if ($new_id) {
2938 2938
 
@@ -2963,9 +2963,9 @@  discard block
 block discarded – undo
2963 2963
 
2964 2964
                     Database::insert($table_wiki_conf, $params);
2965 2965
                 }
2966
-			}
2967
-		}
2968
-	}
2966
+            }
2967
+        }
2968
+    }
2969 2969
 
2970 2970
     /**
2971 2971
      * Restore Thematics
@@ -2973,15 +2973,15 @@  discard block
 block discarded – undo
2973 2973
      */
2974 2974
     public function restore_thematic($session_id = 0)
2975 2975
     {
2976
-		if ($this->course->has_resources(RESOURCE_THEMATIC)) {
2976
+        if ($this->course->has_resources(RESOURCE_THEMATIC)) {
2977 2977
             $table_thematic = Database:: get_course_table(TABLE_THEMATIC);
2978 2978
             $table_thematic_advance = Database:: get_course_table(TABLE_THEMATIC_ADVANCE);
2979 2979
             $table_thematic_plan = Database:: get_course_table(TABLE_THEMATIC_PLAN);
2980 2980
 
2981
-			$resources = $this->course->resources;
2982
-			foreach ($resources[RESOURCE_THEMATIC] as $id => $thematic) {
2981
+            $resources = $this->course->resources;
2982
+            foreach ($resources[RESOURCE_THEMATIC] as $id => $thematic) {
2983 2983
 
2984
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
2984
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
2985 2985
                 $thematic->params['content'] = DocumentManager::replace_urls_inside_content_html_from_copy_course(
2986 2986
                     $thematic->params['content'],
2987 2987
                     $this->course->code,
@@ -2989,13 +2989,13 @@  discard block
 block discarded – undo
2989 2989
                     $this->course->backup_path,
2990 2990
                     $this->course->info['path']
2991 2991
                 );
2992
-				$thematic->params['c_id']  = $this->destination_course_id;
2993
-				unset($thematic->params['id']);
2992
+                $thematic->params['c_id']  = $this->destination_course_id;
2993
+                unset($thematic->params['id']);
2994 2994
                 unset($thematic->params['iid']);
2995 2995
 
2996
-				$last_id = Database::insert($table_thematic, $thematic->params, false);
2996
+                $last_id = Database::insert($table_thematic, $thematic->params, false);
2997 2997
 
2998
-				if ($last_id) {
2998
+                if ($last_id) {
2999 2999
 
3000 3000
                     $sql = "UPDATE $table_thematic SET id = iid WHERE iid = $last_id";
3001 3001
                     Database::query($sql);
@@ -3008,19 +3008,19 @@  discard block
 block discarded – undo
3008 3008
                         api_get_user_id()
3009 3009
                     );
3010 3010
 
3011
-					foreach ($thematic->thematic_advance_list as $thematic_advance) {
3012
-						unset($thematic_advance['id']);
3011
+                    foreach ($thematic->thematic_advance_list as $thematic_advance) {
3012
+                        unset($thematic_advance['id']);
3013 3013
                         unset($thematic_advance['iid']);
3014
-						$thematic_advance['attendance_id'] = 0;
3015
-						$thematic_advance['thematic_id'] = $last_id;
3016
-						$thematic_advance['c_id']  = $this->destination_course_id;
3014
+                        $thematic_advance['attendance_id'] = 0;
3015
+                        $thematic_advance['thematic_id'] = $last_id;
3016
+                        $thematic_advance['c_id']  = $this->destination_course_id;
3017 3017
                         $my_id = Database::insert(
3018 3018
                             $table_thematic_advance,
3019 3019
                             $thematic_advance,
3020 3020
                             false
3021 3021
                         );
3022 3022
 
3023
-						if ($my_id) {
3023
+                        if ($my_id) {
3024 3024
 
3025 3025
                             $sql = "UPDATE $table_thematic_advance SET id = iid WHERE iid = $my_id";
3026 3026
                             Database::query($sql);
@@ -3032,17 +3032,17 @@  discard block
 block discarded – undo
3032 3032
                                 "ThematicAdvanceAdded",
3033 3033
                                 api_get_user_id()
3034 3034
                             );
3035
-						}
3036
-					}
3035
+                        }
3036
+                    }
3037 3037
 
3038
-					foreach($thematic->thematic_plan_list as $thematic_plan) {
3039
-						unset($thematic_plan['id']);
3038
+                    foreach($thematic->thematic_plan_list as $thematic_plan) {
3039
+                        unset($thematic_plan['id']);
3040 3040
                         unset($thematic_plan['iid']);
3041
-						$thematic_plan['thematic_id'] = $last_id;
3042
-						$thematic_plan['c_id'] = $this->destination_course_id;
3043
-						$my_id = Database::insert($table_thematic_plan, $thematic_plan, false);
3041
+                        $thematic_plan['thematic_id'] = $last_id;
3042
+                        $thematic_plan['c_id'] = $this->destination_course_id;
3043
+                        $my_id = Database::insert($table_thematic_plan, $thematic_plan, false);
3044 3044
 
3045
-						if ($my_id) {
3045
+                        if ($my_id) {
3046 3046
 
3047 3047
                             $sql = "UPDATE $table_thematic_plan SET id = iid WHERE iid = $my_id";
3048 3048
                             Database::query($sql);
@@ -3054,12 +3054,12 @@  discard block
 block discarded – undo
3054 3054
                                 "ThematicPlanAdded",
3055 3055
                                 api_get_user_id()
3056 3056
                             );
3057
-						}
3058
-					}
3059
-				}
3060
-			}
3061
-		}
3062
-	}
3057
+                        }
3058
+                    }
3059
+                }
3060
+            }
3061
+        }
3062
+    }
3063 3063
 
3064 3064
     /**
3065 3065
      * Restore Attendance
@@ -3067,14 +3067,14 @@  discard block
 block discarded – undo
3067 3067
      */
3068 3068
     public function restore_attendance($session_id = 0)
3069 3069
     {
3070
-		if ($this->course->has_resources(RESOURCE_ATTENDANCE)) {
3071
-			$table_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
3072
-			$table_attendance_calendar = Database :: get_course_table(TABLE_ATTENDANCE_CALENDAR);
3070
+        if ($this->course->has_resources(RESOURCE_ATTENDANCE)) {
3071
+            $table_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
3072
+            $table_attendance_calendar = Database :: get_course_table(TABLE_ATTENDANCE_CALENDAR);
3073 3073
 
3074
-			$resources = $this->course->resources;
3075
-			foreach ($resources[RESOURCE_ATTENDANCE] as $id => $obj) {
3074
+            $resources = $this->course->resources;
3075
+            foreach ($resources[RESOURCE_ATTENDANCE] as $id => $obj) {
3076 3076
 
3077
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
3077
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
3078 3078
                 $obj->params['description'] = DocumentManager::replace_urls_inside_content_html_from_copy_course(
3079 3079
                     $obj->params['description'],
3080 3080
                     $this->course->code,
@@ -3086,11 +3086,11 @@  discard block
 block discarded – undo
3086 3086
                 unset($obj->params['id']);
3087 3087
                 unset($obj->params['iid']);
3088 3088
 
3089
-				$obj->params['c_id'] = $this->destination_course_id;
3089
+                $obj->params['c_id'] = $this->destination_course_id;
3090 3090
 
3091
-				$last_id = Database::insert($table_attendance, $obj->params);
3091
+                $last_id = Database::insert($table_attendance, $obj->params);
3092 3092
 
3093
-				if (is_numeric($last_id)) {
3093
+                if (is_numeric($last_id)) {
3094 3094
 
3095 3095
                     $sql = "UPDATE $table_attendance SET id = iid WHERE iid = $last_id";
3096 3096
                     Database::query($sql);
@@ -3104,11 +3104,11 @@  discard block
 block discarded – undo
3104 3104
                     );
3105 3105
 
3106 3106
                     foreach ($obj->attendance_calendar as $attendance_calendar) {
3107
-						unset($attendance_calendar['id']);
3107
+                        unset($attendance_calendar['id']);
3108 3108
                         unset($attendance_calendar['iid']);
3109 3109
 
3110
-						$attendance_calendar['attendance_id'] = $last_id;
3111
-						$attendance_calendar['c_id'] = $this->destination_course_id;
3110
+                        $attendance_calendar['attendance_id'] = $last_id;
3111
+                        $attendance_calendar['c_id'] = $this->destination_course_id;
3112 3112
                         $attendanceCalendarId = Database::insert(
3113 3113
                             $table_attendance_calendar,
3114 3114
                             $attendance_calendar
@@ -3116,11 +3116,11 @@  discard block
 block discarded – undo
3116 3116
 
3117 3117
                         $sql = "UPDATE $table_attendance_calendar SET id = iid WHERE iid = $attendanceCalendarId";
3118 3118
                         Database::query($sql);
3119
-					}
3120
-				}
3121
-			}
3122
-		}
3123
-	}
3119
+                    }
3120
+                }
3121
+            }
3122
+        }
3123
+    }
3124 3124
 
3125 3125
     /**
3126 3126
      * Restore Works
@@ -3262,11 +3262,11 @@  discard block
 block discarded – undo
3262 3262
      */
3263 3263
     public function DBUTF8($str)
3264 3264
     {
3265
-		if (UTF8_CONVERT) {
3265
+        if (UTF8_CONVERT) {
3266 3266
             $str = utf8_encode($str);
3267 3267
         }
3268
-		return $str;
3269
-	}
3268
+        return $str;
3269
+    }
3270 3270
 
3271 3271
     /**
3272 3272
      * @param string $str
@@ -3277,8 +3277,8 @@  discard block
 block discarded – undo
3277 3277
         if (UTF8_CONVERT) {
3278 3278
             $str = utf8_encode($str);
3279 3279
         }
3280
-		return Database::escape_string($str);
3281
-	}
3280
+        return Database::escape_string($str);
3281
+    }
3282 3282
 
3283 3283
     /**
3284 3284
      * @param array $array
Please login to merge, or discard this patch.
main/dropbox/dropbox_class.inc.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -267,7 +267,7 @@
 block discarded – undo
267 267
 	 * @param string $author
268 268
 	 * @param string $filename
269 269
 	 * @param int $filesize
270
-	 * @param array $recipient_ids
270
+	 * @param unknown_type|null $recipient_ids
271 271
 	 */
272 272
 	public function _createNewSentWork($uploader_id, $title, $description, $author, $filename, $filesize, $recipient_ids)
273 273
     {
Please login to merge, or discard this 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.
main/exercice/hotpotatoes.lib.php 1 patch
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
  * @param    reference    Reference to the array to search
260 260
  * @param    string       Node we are looking for in the array
261 261
  * @param string $node
262
- * @return   mixed        Node name or false if not found
262
+ * @return   false|string        Node name or false if not found
263 263
  */
264 264
 function myarraysearch(&$array, $node)
265 265
 {
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
  * Searches an image name into an array.
281 281
  * @param    reference        Reference to an array to search
282 282
  * @param    string           String to look for
283
- * @return   mixed            String given if found, false otherwise
283
+ * @return   false|string            String given if found, false otherwise
284 284
  * @uses     myarraysearch    This function is just an additional layer on the myarraysearch() function
285 285
  */
286 286
 function CheckImageName(&$imgparams, $string)
Please login to merge, or discard this patch.
main/gradebook/lib/be/category.class.php 1 patch
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1545,7 +1545,7 @@
 block discarded – undo
1545 1545
      * Retrieve all categories inside a course independent category
1546 1546
      * that should be visible to a student.
1547 1547
      * @param integer $cat_id parent category
1548
-     * @param $stud_id student id
1548
+     * @param integer $stud_id student id
1549 1549
      * @param $cats optional: if defined, the categories will be added to this array
1550 1550
      */
1551 1551
     public function get_independent_categories_with_result_for_student($cat_id, $stud_id, $cats = array())
Please login to merge, or discard this patch.
main/gradebook/lib/be/evaluation.class.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -273,7 +273,7 @@
 block discarded – undo
273 273
 
274 274
 
275 275
 	/**
276
-	 * @param array $result
276
+	 * @param Doctrine\DBAL\Driver\Statement|null $result
277 277
 	 * @return array
278 278
 	 */
279 279
 	private static function create_evaluation_objects_from_sql_result($result)
Please login to merge, or discard this patch.
Indentation   +748 added lines, -748 removed lines patch added patch discarded remove patch
@@ -9,367 +9,367 @@  discard block
 block discarded – undo
9 9
  */
10 10
 class Evaluation implements GradebookItem
11 11
 {
12
-	private $id;
13
-	private $name;
14
-	private $description;
15
-	private $user_id;
16
-	private $course_code;
17
-	/** @var Category */
18
-	private $category;
19
-	private $created_at;
20
-	private $weight;
21
-	private $eval_max;
22
-	private $visible;
23
-	private $sessionId;
24
-	public $studentList;
25
-
26
-	/**
27
-	 * Construct
28
-	 */
29
-	public function __construct()
30
-	{
31
-	}
32
-
33
-	/**
34
-	 * @return Category
35
-	 */
36
-	public function getCategory()
37
-	{
38
-		return $this->category;
39
-	}
40
-
41
-	/**
42
-	 * @param Category $category
43
-	 */
44
-	public function setCategory($category)
45
-	{
46
-		$this->category = $category;
47
-	}
48
-
49
-	/**
50
-	 * @return int
51
-	 */
52
-	public function get_category_id()
53
-	{
54
-		return $this->category->get_id();
55
-	}
56
-
57
-	/**
58
-	 * @param int $category_id
59
-	 */
60
-	public function set_category_id($category_id)
61
-	{
62
-		$categories = Category::load($category_id);
63
-		if (isset($categories[0])) {
64
-			$this->setCategory($categories[0]);
65
-		}
66
-	}
67
-
68
-	/**
69
-	 * @return int
70
-	 */
71
-	public function get_id()
72
-	{
73
-		return $this->id;
74
-	}
75
-
76
-	/**
77
-	 * @return string
78
-	 */
79
-	public function get_name()
80
-	{
81
-		return $this->name;
82
-	}
83
-
84
-	/**
85
-	 * @return string
86
-	 */
87
-	public function get_description()
88
-	{
89
-		return $this->description;
90
-	}
91
-
92
-	public function get_user_id()
93
-	{
94
-		return $this->user_id;
95
-	}
96
-
97
-	public function get_course_code()
98
-	{
99
-		return $this->course_code;
100
-	}
101
-
102
-	/**
103
-	 * @return int
104
-	 */
105
-	public function getSessionId()
106
-	{
107
-		return $this->sessionId;
108
-	}
109
-
110
-	/**
111
-	 * @param int $sessionId
112
-	 */
113
-	public function setSessionId($sessionId)
114
-	{
115
-		$this->sessionId = intval($sessionId);
116
-	}
117
-
118
-	public function get_date()
119
-	{
120
-		return $this->created_at;
121
-	}
122
-
123
-	public function get_weight()
124
-	{
125
-		return $this->weight;
126
-	}
127
-
128
-	public function get_max()
129
-	{
130
-		return $this->eval_max;
131
-	}
132
-
133
-	public function get_type()
134
-	{
135
-		return $this->type;
136
-	}
137
-
138
-	public function is_visible()
139
-	{
140
-		return $this->visible;
141
-	}
142
-
143
-	public function get_locked()
144
-	{
145
-		return $this->locked;
146
-	}
147
-
148
-	public function is_locked()
149
-	{
150
-		return isset($this->locked) && $this->locked == 1 ? true : false;
151
-	}
152
-
153
-	public function set_id($id)
154
-	{
155
-		$this->id = $id;
156
-	}
157
-
158
-	public function set_name($name)
159
-	{
160
-		$this->name = $name;
161
-	}
162
-
163
-	public function set_description($description)
164
-	{
165
-		$this->description = $description;
166
-	}
167
-
168
-	public function set_user_id($user_id)
169
-	{
170
-		$this->user_id = $user_id;
171
-	}
172
-
173
-	public function set_course_code($course_code)
174
-	{
175
-		$this->course_code = $course_code;
176
-	}
177
-
178
-	public function set_date($date)
179
-	{
180
-		$this->created_at = $date;
181
-	}
182
-
183
-	public function set_weight($weight)
184
-	{
185
-		$this->weight = $weight;
186
-	}
187
-
188
-	public function set_max($max)
189
-	{
190
-		$this->eval_max = $max;
191
-	}
192
-
193
-	public function set_visible($visible)
194
-	{
195
-		$this->visible = $visible;
196
-	}
197
-
198
-	public function set_type($type)
199
-	{
200
-		$this->type = $type;
201
-	}
202
-
203
-	public function set_locked($locked)
204
-	{
205
-		$this->locked = $locked;
206
-	}
207
-
208
-	/**
209
-	 * Retrieve evaluations and return them as an array of Evaluation objects
210
-	 * @param int $id evaluation id
211
-	 * @param int $user_id user id (evaluation owner)
212
-	 * @param string $course_code course code
213
-	 * @param int $category_id parent category
214
-	 * @param integer $visible visible
215
-	 */
216
-	public static function load(
217
-		$id = null,
218
-		$user_id = null,
219
-		$course_code = null,
220
-		$category_id = null,
221
-		$visible = null,
222
-		$locked = null
223
-	) {
224
-		$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
225
-		$sql = 'SELECT * FROM '.$tbl_grade_evaluations;
226
-		$paramcount = 0;
227
-
228
-		if (isset ($id)) {
229
-			$sql.= ' WHERE id = '.intval($id);
230
-			$paramcount ++;
231
-		}
232
-
233
-		if (isset ($user_id)) {
234
-			if ($paramcount != 0) $sql .= ' AND';
235
-			else $sql .= ' WHERE';
236
-			$sql .= ' user_id = '.intval($user_id);
237
-			$paramcount ++;
238
-		}
239
-
240
-		if (isset ($course_code) && $course_code <> '-1') {
241
-			if ($paramcount != 0) $sql .= ' AND';
242
-			else $sql .= ' WHERE';
243
-			$sql .= " course_code = '".Database::escape_string($course_code)."'";
244
-			$paramcount ++;
245
-		}
246
-
247
-		if (isset ($category_id)) {
248
-			if ($paramcount != 0) $sql .= ' AND';
249
-			else $sql .= ' WHERE';
250
-			$sql .= ' category_id = '.intval($category_id);
251
-			$paramcount ++;
252
-		}
253
-
254
-		if (isset ($visible)) {
255
-			if ($paramcount != 0) $sql .= ' AND';
256
-			else $sql .= ' WHERE';
257
-			$sql .= ' visible = '.intval($visible);
258
-			$paramcount ++;
259
-		}
260
-
261
-		if (isset ($locked)) {
262
-			if ($paramcount != 0) $sql .= ' AND';
263
-			else $sql .= ' WHERE';
264
-			$sql .= ' locked = '.intval($locked);
265
-		}
266
-
267
-		$result = Database::query($sql);
268
-		$alleval = Evaluation::create_evaluation_objects_from_sql_result($result);
269
-
270
-		return $alleval;
271
-	}
272
-
273
-
274
-
275
-	/**
276
-	 * @param array $result
277
-	 * @return array
278
-	 */
279
-	private static function create_evaluation_objects_from_sql_result($result)
280
-	{
281
-		$alleval = array();
282
-		if (Database::num_rows($result)) {
283
-			while ($data = Database::fetch_array($result)) {
284
-				$eval= new Evaluation();
285
-				$eval->set_id($data['id']);
286
-				$eval->set_name($data['name']);
287
-				$eval->set_description($data['description']);
288
-				$eval->set_user_id($data['user_id']);
289
-				$eval->set_course_code($data['course_code']);
290
-				$eval->set_category_id($data['category_id']);
291
-				$eval->set_date(api_get_local_time($data['created_at']));
292
-				$eval->set_weight($data['weight']);
293
-				$eval->set_max($data['max']);
294
-				$eval->set_visible($data['visible']);
295
-				$eval->set_type($data['type']);
296
-				$eval->set_locked($data['locked']);
297
-				$eval->setSessionId(api_get_session_id());
298
-
299
-				$alleval[] = $eval;
300
-			}
301
-		}
302
-
303
-		return $alleval;
304
-	}
305
-
306
-	/**
307
-	 * Insert this evaluation into the database
308
-	 */
309
-	public function add()
310
-	{
311
-		if (isset($this->name) &&
312
-			isset($this->user_id) &&
313
-			isset($this->weight) &&
314
-			isset ($this->eval_max) &&
315
-			isset($this->visible)
316
-		) {
317
-			$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
318
-
319
-			$sql = 'INSERT INTO '.$tbl_grade_evaluations
320
-				.' (name, user_id, weight, max, visible';
321
-			if (isset($this->description)) {
322
-				$sql .= ',description';
323
-			}
324
-			if (isset($this->course_code)) {
325
-				$sql .= ', course_code';
326
-			}
327
-			if (isset($this->category)) {
328
-				$sql .= ', category_id';
329
-			}
330
-			$sql .= ', created_at';
331
-			$sql .= ',type';
332
-			$sql .= ") VALUES ('".Database::escape_string($this->get_name())."'"
333
-				.','.intval($this->get_user_id())
334
-				.','.floatval($this->get_weight())
335
-				.','.intval($this->get_max())
336
-				.','.intval($this->is_visible());
337
-			if (isset($this->description)) {
338
-				$sql .= ",'".Database::escape_string($this->get_description())."'";
339
-			}
340
-			if (isset($this->course_code)) {
341
-				$sql .= ",'".Database::escape_string($this->get_course_code())."'";
342
-			}
343
-			if (isset($this->category)) {
344
-				$sql .= ','.intval($this->get_category_id());
345
-			}
346
-			if (empty($this->type)) {
347
-				$this->type = 'evaluation';
348
-			}
349
-			$sql .= ", '".api_get_utc_datetime()."'";
350
-			$sql .= ',\''.Database::escape_string($this->type).'\'';
351
-			$sql .= ")";
352
-
353
-			Database::query($sql);
354
-			$this->set_id(Database::insert_id());
355
-		} else {
356
-			die('Error in Evaluation add: required field empty');
357
-		}
358
-	}
359
-
360
-	/**
361
-	 * @param int $idevaluation
362
-	 */
363
-	public function add_evaluation_log($idevaluation)
364
-	{
365
-		if (!empty($idevaluation)) {
366
-			$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
367
-			$tbl_grade_linkeval_log = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINKEVAL_LOG);
368
-			$eval = new Evaluation();
369
-			$dateobject = $eval->load($idevaluation,null,null,null,null);
370
-			$arreval = get_object_vars($dateobject[0]);
371
-			if (!empty($arreval['id'])) {
372
-				$sql = 'SELECT weight from '.$tbl_grade_evaluations.'
12
+    private $id;
13
+    private $name;
14
+    private $description;
15
+    private $user_id;
16
+    private $course_code;
17
+    /** @var Category */
18
+    private $category;
19
+    private $created_at;
20
+    private $weight;
21
+    private $eval_max;
22
+    private $visible;
23
+    private $sessionId;
24
+    public $studentList;
25
+
26
+    /**
27
+     * Construct
28
+     */
29
+    public function __construct()
30
+    {
31
+    }
32
+
33
+    /**
34
+     * @return Category
35
+     */
36
+    public function getCategory()
37
+    {
38
+        return $this->category;
39
+    }
40
+
41
+    /**
42
+     * @param Category $category
43
+     */
44
+    public function setCategory($category)
45
+    {
46
+        $this->category = $category;
47
+    }
48
+
49
+    /**
50
+     * @return int
51
+     */
52
+    public function get_category_id()
53
+    {
54
+        return $this->category->get_id();
55
+    }
56
+
57
+    /**
58
+     * @param int $category_id
59
+     */
60
+    public function set_category_id($category_id)
61
+    {
62
+        $categories = Category::load($category_id);
63
+        if (isset($categories[0])) {
64
+            $this->setCategory($categories[0]);
65
+        }
66
+    }
67
+
68
+    /**
69
+     * @return int
70
+     */
71
+    public function get_id()
72
+    {
73
+        return $this->id;
74
+    }
75
+
76
+    /**
77
+     * @return string
78
+     */
79
+    public function get_name()
80
+    {
81
+        return $this->name;
82
+    }
83
+
84
+    /**
85
+     * @return string
86
+     */
87
+    public function get_description()
88
+    {
89
+        return $this->description;
90
+    }
91
+
92
+    public function get_user_id()
93
+    {
94
+        return $this->user_id;
95
+    }
96
+
97
+    public function get_course_code()
98
+    {
99
+        return $this->course_code;
100
+    }
101
+
102
+    /**
103
+     * @return int
104
+     */
105
+    public function getSessionId()
106
+    {
107
+        return $this->sessionId;
108
+    }
109
+
110
+    /**
111
+     * @param int $sessionId
112
+     */
113
+    public function setSessionId($sessionId)
114
+    {
115
+        $this->sessionId = intval($sessionId);
116
+    }
117
+
118
+    public function get_date()
119
+    {
120
+        return $this->created_at;
121
+    }
122
+
123
+    public function get_weight()
124
+    {
125
+        return $this->weight;
126
+    }
127
+
128
+    public function get_max()
129
+    {
130
+        return $this->eval_max;
131
+    }
132
+
133
+    public function get_type()
134
+    {
135
+        return $this->type;
136
+    }
137
+
138
+    public function is_visible()
139
+    {
140
+        return $this->visible;
141
+    }
142
+
143
+    public function get_locked()
144
+    {
145
+        return $this->locked;
146
+    }
147
+
148
+    public function is_locked()
149
+    {
150
+        return isset($this->locked) && $this->locked == 1 ? true : false;
151
+    }
152
+
153
+    public function set_id($id)
154
+    {
155
+        $this->id = $id;
156
+    }
157
+
158
+    public function set_name($name)
159
+    {
160
+        $this->name = $name;
161
+    }
162
+
163
+    public function set_description($description)
164
+    {
165
+        $this->description = $description;
166
+    }
167
+
168
+    public function set_user_id($user_id)
169
+    {
170
+        $this->user_id = $user_id;
171
+    }
172
+
173
+    public function set_course_code($course_code)
174
+    {
175
+        $this->course_code = $course_code;
176
+    }
177
+
178
+    public function set_date($date)
179
+    {
180
+        $this->created_at = $date;
181
+    }
182
+
183
+    public function set_weight($weight)
184
+    {
185
+        $this->weight = $weight;
186
+    }
187
+
188
+    public function set_max($max)
189
+    {
190
+        $this->eval_max = $max;
191
+    }
192
+
193
+    public function set_visible($visible)
194
+    {
195
+        $this->visible = $visible;
196
+    }
197
+
198
+    public function set_type($type)
199
+    {
200
+        $this->type = $type;
201
+    }
202
+
203
+    public function set_locked($locked)
204
+    {
205
+        $this->locked = $locked;
206
+    }
207
+
208
+    /**
209
+     * Retrieve evaluations and return them as an array of Evaluation objects
210
+     * @param int $id evaluation id
211
+     * @param int $user_id user id (evaluation owner)
212
+     * @param string $course_code course code
213
+     * @param int $category_id parent category
214
+     * @param integer $visible visible
215
+     */
216
+    public static function load(
217
+        $id = null,
218
+        $user_id = null,
219
+        $course_code = null,
220
+        $category_id = null,
221
+        $visible = null,
222
+        $locked = null
223
+    ) {
224
+        $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
225
+        $sql = 'SELECT * FROM '.$tbl_grade_evaluations;
226
+        $paramcount = 0;
227
+
228
+        if (isset ($id)) {
229
+            $sql.= ' WHERE id = '.intval($id);
230
+            $paramcount ++;
231
+        }
232
+
233
+        if (isset ($user_id)) {
234
+            if ($paramcount != 0) $sql .= ' AND';
235
+            else $sql .= ' WHERE';
236
+            $sql .= ' user_id = '.intval($user_id);
237
+            $paramcount ++;
238
+        }
239
+
240
+        if (isset ($course_code) && $course_code <> '-1') {
241
+            if ($paramcount != 0) $sql .= ' AND';
242
+            else $sql .= ' WHERE';
243
+            $sql .= " course_code = '".Database::escape_string($course_code)."'";
244
+            $paramcount ++;
245
+        }
246
+
247
+        if (isset ($category_id)) {
248
+            if ($paramcount != 0) $sql .= ' AND';
249
+            else $sql .= ' WHERE';
250
+            $sql .= ' category_id = '.intval($category_id);
251
+            $paramcount ++;
252
+        }
253
+
254
+        if (isset ($visible)) {
255
+            if ($paramcount != 0) $sql .= ' AND';
256
+            else $sql .= ' WHERE';
257
+            $sql .= ' visible = '.intval($visible);
258
+            $paramcount ++;
259
+        }
260
+
261
+        if (isset ($locked)) {
262
+            if ($paramcount != 0) $sql .= ' AND';
263
+            else $sql .= ' WHERE';
264
+            $sql .= ' locked = '.intval($locked);
265
+        }
266
+
267
+        $result = Database::query($sql);
268
+        $alleval = Evaluation::create_evaluation_objects_from_sql_result($result);
269
+
270
+        return $alleval;
271
+    }
272
+
273
+
274
+
275
+    /**
276
+     * @param array $result
277
+     * @return array
278
+     */
279
+    private static function create_evaluation_objects_from_sql_result($result)
280
+    {
281
+        $alleval = array();
282
+        if (Database::num_rows($result)) {
283
+            while ($data = Database::fetch_array($result)) {
284
+                $eval= new Evaluation();
285
+                $eval->set_id($data['id']);
286
+                $eval->set_name($data['name']);
287
+                $eval->set_description($data['description']);
288
+                $eval->set_user_id($data['user_id']);
289
+                $eval->set_course_code($data['course_code']);
290
+                $eval->set_category_id($data['category_id']);
291
+                $eval->set_date(api_get_local_time($data['created_at']));
292
+                $eval->set_weight($data['weight']);
293
+                $eval->set_max($data['max']);
294
+                $eval->set_visible($data['visible']);
295
+                $eval->set_type($data['type']);
296
+                $eval->set_locked($data['locked']);
297
+                $eval->setSessionId(api_get_session_id());
298
+
299
+                $alleval[] = $eval;
300
+            }
301
+        }
302
+
303
+        return $alleval;
304
+    }
305
+
306
+    /**
307
+     * Insert this evaluation into the database
308
+     */
309
+    public function add()
310
+    {
311
+        if (isset($this->name) &&
312
+            isset($this->user_id) &&
313
+            isset($this->weight) &&
314
+            isset ($this->eval_max) &&
315
+            isset($this->visible)
316
+        ) {
317
+            $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
318
+
319
+            $sql = 'INSERT INTO '.$tbl_grade_evaluations
320
+                .' (name, user_id, weight, max, visible';
321
+            if (isset($this->description)) {
322
+                $sql .= ',description';
323
+            }
324
+            if (isset($this->course_code)) {
325
+                $sql .= ', course_code';
326
+            }
327
+            if (isset($this->category)) {
328
+                $sql .= ', category_id';
329
+            }
330
+            $sql .= ', created_at';
331
+            $sql .= ',type';
332
+            $sql .= ") VALUES ('".Database::escape_string($this->get_name())."'"
333
+                .','.intval($this->get_user_id())
334
+                .','.floatval($this->get_weight())
335
+                .','.intval($this->get_max())
336
+                .','.intval($this->is_visible());
337
+            if (isset($this->description)) {
338
+                $sql .= ",'".Database::escape_string($this->get_description())."'";
339
+            }
340
+            if (isset($this->course_code)) {
341
+                $sql .= ",'".Database::escape_string($this->get_course_code())."'";
342
+            }
343
+            if (isset($this->category)) {
344
+                $sql .= ','.intval($this->get_category_id());
345
+            }
346
+            if (empty($this->type)) {
347
+                $this->type = 'evaluation';
348
+            }
349
+            $sql .= ", '".api_get_utc_datetime()."'";
350
+            $sql .= ',\''.Database::escape_string($this->type).'\'';
351
+            $sql .= ")";
352
+
353
+            Database::query($sql);
354
+            $this->set_id(Database::insert_id());
355
+        } else {
356
+            die('Error in Evaluation add: required field empty');
357
+        }
358
+    }
359
+
360
+    /**
361
+     * @param int $idevaluation
362
+     */
363
+    public function add_evaluation_log($idevaluation)
364
+    {
365
+        if (!empty($idevaluation)) {
366
+            $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
367
+            $tbl_grade_linkeval_log = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINKEVAL_LOG);
368
+            $eval = new Evaluation();
369
+            $dateobject = $eval->load($idevaluation,null,null,null,null);
370
+            $arreval = get_object_vars($dateobject[0]);
371
+            if (!empty($arreval['id'])) {
372
+                $sql = 'SELECT weight from '.$tbl_grade_evaluations.'
373 373
                         WHERE id='.$arreval['id'];
374 374
                 $rs = Database::query($sql);
375 375
                 $row_old_weight = Database::fetch_array($rs, 'ASSOC');
@@ -385,426 +385,426 @@  discard block
 block discarded – undo
385 385
                     'user_id_log' => api_get_user_id()
386 386
                 ];
387 387
                 Database::insert($tbl_grade_linkeval_log, $params);
388
-			}
389
-		}
390
-	}
391
-
392
-	/**
393
-	 * Update the properties of this evaluation in the database
394
-	 */
395
-	public function save()
396
-	{
397
-		$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
398
-		$sql = 'UPDATE '.$tbl_grade_evaluations
399
-			." SET name = '".Database::escape_string($this->get_name())."'"
400
-			.', description = ';
401
-		if (isset($this->description)) {
402
-			$sql .= "'".Database::escape_string($this->get_description())."'";
403
-		}else {
404
-			$sql .= 'null';
405
-		}
406
-		$sql .= ', user_id = '.intval($this->get_user_id())
407
-			.', course_code = ';
408
-		if (isset($this->course_code)) {
409
-			$sql .= "'".Database::escape_string($this->get_course_code())."'";
410
-		} else {
411
-			$sql .= 'null';
412
-		}
413
-		$sql .= ', category_id = ';
414
-		if (isset($this->category)) {
415
-			$sql .= intval($this->get_category_id());
416
-		} else {
417
-			$sql .= 'null';
418
-		}
419
-		$sql .= ', weight = "'.Database::escape_string($this->get_weight()).'" '
420
-			.', max = '.intval($this->get_max())
421
-			.', visible = '.intval($this->is_visible())
422
-			.' WHERE id = '.intval($this->id);
423
-		//recorded history
424
-
425
-		$eval_log = new Evaluation();
426
-		$eval_log->add_evaluation_log($this->id);
427
-		Database::query($sql);
428
-	}
429
-
430
-	/**
431
-	 * Delete this evaluation from the database
432
-	 */
433
-	public function delete()
434
-	{
435
-		$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
436
-		$sql = 'DELETE FROM '.$tbl_grade_evaluations.' WHERE id = '.intval($this->id);
437
-		Database::query($sql);
438
-	}
439
-
440
-	/**
441
-	 * Check if an evaluation name (with the same parent category) already exists
442
-	 * @param $name name to check (if not given, the name property of this object will be checked)
443
-	 * @param $parent parent category
444
-	 */
445
-	public function does_name_exist($name, $parent)
446
-	{
447
-		if (!isset ($name)) {
448
-			$name = $this->name;
449
-			$parent = $this->category;
450
-		}
451
-		$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
452
-		$sql = 'SELECT count(id) AS number'
453
-			.' FROM '.$tbl_grade_evaluations
454
-			." WHERE name = '".Database::escape_string($name)."'";
455
-
456
-		if (api_is_allowed_to_edit()) {
457
-			$parent = Category::load($parent);
458
-			$code = $parent[0]->get_course_code();
459
-			$courseInfo = api_get_course_info($code);
460
-			$courseId = $courseInfo['real_id'];
461
-
462
-			if (isset($code) && $code != '0') {
463
-				$main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
464
-				$sql .= ' AND user_id IN (
388
+            }
389
+        }
390
+    }
391
+
392
+    /**
393
+     * Update the properties of this evaluation in the database
394
+     */
395
+    public function save()
396
+    {
397
+        $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
398
+        $sql = 'UPDATE '.$tbl_grade_evaluations
399
+            ." SET name = '".Database::escape_string($this->get_name())."'"
400
+            .', description = ';
401
+        if (isset($this->description)) {
402
+            $sql .= "'".Database::escape_string($this->get_description())."'";
403
+        }else {
404
+            $sql .= 'null';
405
+        }
406
+        $sql .= ', user_id = '.intval($this->get_user_id())
407
+            .', course_code = ';
408
+        if (isset($this->course_code)) {
409
+            $sql .= "'".Database::escape_string($this->get_course_code())."'";
410
+        } else {
411
+            $sql .= 'null';
412
+        }
413
+        $sql .= ', category_id = ';
414
+        if (isset($this->category)) {
415
+            $sql .= intval($this->get_category_id());
416
+        } else {
417
+            $sql .= 'null';
418
+        }
419
+        $sql .= ', weight = "'.Database::escape_string($this->get_weight()).'" '
420
+            .', max = '.intval($this->get_max())
421
+            .', visible = '.intval($this->is_visible())
422
+            .' WHERE id = '.intval($this->id);
423
+        //recorded history
424
+
425
+        $eval_log = new Evaluation();
426
+        $eval_log->add_evaluation_log($this->id);
427
+        Database::query($sql);
428
+    }
429
+
430
+    /**
431
+     * Delete this evaluation from the database
432
+     */
433
+    public function delete()
434
+    {
435
+        $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
436
+        $sql = 'DELETE FROM '.$tbl_grade_evaluations.' WHERE id = '.intval($this->id);
437
+        Database::query($sql);
438
+    }
439
+
440
+    /**
441
+     * Check if an evaluation name (with the same parent category) already exists
442
+     * @param $name name to check (if not given, the name property of this object will be checked)
443
+     * @param $parent parent category
444
+     */
445
+    public function does_name_exist($name, $parent)
446
+    {
447
+        if (!isset ($name)) {
448
+            $name = $this->name;
449
+            $parent = $this->category;
450
+        }
451
+        $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
452
+        $sql = 'SELECT count(id) AS number'
453
+            .' FROM '.$tbl_grade_evaluations
454
+            ." WHERE name = '".Database::escape_string($name)."'";
455
+
456
+        if (api_is_allowed_to_edit()) {
457
+            $parent = Category::load($parent);
458
+            $code = $parent[0]->get_course_code();
459
+            $courseInfo = api_get_course_info($code);
460
+            $courseId = $courseInfo['real_id'];
461
+
462
+            if (isset($code) && $code != '0') {
463
+                $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
464
+                $sql .= ' AND user_id IN (
465 465
 					 SELECT user_id FROM '.$main_course_user_table.'
466 466
 					 WHERE
467 467
 						c_id = '.$courseId.' AND
468 468
 						status = '.COURSEMANAGER.'
469 469
 					)';
470
-			} else {
471
-				$sql .= ' AND user_id = '.api_get_user_id();
472
-			}
473
-
474
-		}else {
475
-			$sql .= ' AND user_id = '.api_get_user_id();
476
-		}
477
-
478
-		if (!isset ($parent)) {
479
-			$sql.= ' AND category_id is null';
480
-		} else {
481
-			$sql.= ' AND category_id = '.intval($parent);
482
-		}
483
-		$result = Database::query($sql);
484
-		$number=Database::fetch_row($result);
485
-
486
-		return $number[0] != 0;
487
-	}
488
-
489
-	/**
490
-	 * Are there any results for this evaluation yet ?
491
-	 * The 'max' property should not be changed then.
492
-	 */
493
-	public function has_results()
494
-	{
495
-		$tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
496
-		$sql = 'SELECT count(id) AS number
470
+            } else {
471
+                $sql .= ' AND user_id = '.api_get_user_id();
472
+            }
473
+
474
+        }else {
475
+            $sql .= ' AND user_id = '.api_get_user_id();
476
+        }
477
+
478
+        if (!isset ($parent)) {
479
+            $sql.= ' AND category_id is null';
480
+        } else {
481
+            $sql.= ' AND category_id = '.intval($parent);
482
+        }
483
+        $result = Database::query($sql);
484
+        $number=Database::fetch_row($result);
485
+
486
+        return $number[0] != 0;
487
+    }
488
+
489
+    /**
490
+     * Are there any results for this evaluation yet ?
491
+     * The 'max' property should not be changed then.
492
+     */
493
+    public function has_results()
494
+    {
495
+        $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
496
+        $sql = 'SELECT count(id) AS number
497 497
 				FROM '.$tbl_grade_results.'
498 498
 				WHERE evaluation_id = '.intval($this->id);
499
-		$result = Database::query($sql);
500
-		$number=Database::fetch_row($result);
501
-
502
-		return ($number[0] != 0);
503
-	}
504
-
505
-	/**
506
-	 * Delete all results for this evaluation
507
-	 */
508
-	public function delete_results()
509
-	{
510
-		$tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
511
-		$sql = 'DELETE FROM '.$tbl_grade_results.'
499
+        $result = Database::query($sql);
500
+        $number=Database::fetch_row($result);
501
+
502
+        return ($number[0] != 0);
503
+    }
504
+
505
+    /**
506
+     * Delete all results for this evaluation
507
+     */
508
+    public function delete_results()
509
+    {
510
+        $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
511
+        $sql = 'DELETE FROM '.$tbl_grade_results.'
512 512
 				WHERE evaluation_id = '.intval($this->id);
513
-		Database::query($sql);
514
-	}
515
-
516
-	/**
517
-	 * Delete this evaluation and all underlying results.
518
-	 */
519
-	public function delete_with_results()
520
-	{
521
-		$this->delete_results();
522
-		$this->delete();
523
-	}
524
-
525
-	/**
526
-	 * Check if the given score is possible for this evaluation
527
-	 */
528
-	public function is_valid_score($score)
529
-	{
530
-		return is_numeric($score) && $score >= 0 && $score <= $this->eval_max;
531
-	}
532
-
533
-	/**
534
-	 * Calculate the score of this evaluation
535
-	 * @param int $stud_id (default: all students who have results for this eval - then the average is returned)
536
-	 * @param string $type (best, average, ranking)
537
-	 * @return	array (score, max) if student is given
538
-	 * 			array (sum of scores, number of scores) otherwise
539
-	 * 			or null if no scores available
540
-	 */
541
-	public function calc_score($stud_id = null, $type = null)
542
-	{
513
+        Database::query($sql);
514
+    }
515
+
516
+    /**
517
+     * Delete this evaluation and all underlying results.
518
+     */
519
+    public function delete_with_results()
520
+    {
521
+        $this->delete_results();
522
+        $this->delete();
523
+    }
524
+
525
+    /**
526
+     * Check if the given score is possible for this evaluation
527
+     */
528
+    public function is_valid_score($score)
529
+    {
530
+        return is_numeric($score) && $score >= 0 && $score <= $this->eval_max;
531
+    }
532
+
533
+    /**
534
+     * Calculate the score of this evaluation
535
+     * @param int $stud_id (default: all students who have results for this eval - then the average is returned)
536
+     * @param string $type (best, average, ranking)
537
+     * @return	array (score, max) if student is given
538
+     * 			array (sum of scores, number of scores) otherwise
539
+     * 			or null if no scores available
540
+     */
541
+    public function calc_score($stud_id = null, $type = null)
542
+    {
543 543
         $useSession = true;
544
-		if (isset($stud_id) && empty($type)) {
545
-			$key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id.'_'.$stud_id;
546
-			$data = Session::read('calc_score');
544
+        if (isset($stud_id) && empty($type)) {
545
+            $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id.'_'.$stud_id;
546
+            $data = Session::read('calc_score');
547 547
             $results = isset($data[$key]) ? $data[$key] : null;
548 548
 
549 549
             if ($useSession == false) {
550 550
                 $results  = null;
551 551
             }
552
-			if (empty($results)) {
553
-				$results = Result::load(null, $stud_id, $this->id);
554
-				Session::write('calc_score', array($key => $results));
555
-			}
556
-
557
-			$score = 0;
558
-			/** @var Result $res */
559
-			foreach ($results as $res) {
560
-				$score = $res->get_score();
561
-			}
562
-
563
-			return array($score, $this->get_max());
564
-		} else {
565
-
566
-			$count = 0;
567
-			$sum = 0;
568
-			$bestResult = 0;
569
-			$weight = 0;
570
-			$sumResult = 0;
571
-
572
-			$key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id;
552
+            if (empty($results)) {
553
+                $results = Result::load(null, $stud_id, $this->id);
554
+                Session::write('calc_score', array($key => $results));
555
+            }
556
+
557
+            $score = 0;
558
+            /** @var Result $res */
559
+            foreach ($results as $res) {
560
+                $score = $res->get_score();
561
+            }
562
+
563
+            return array($score, $this->get_max());
564
+        } else {
565
+
566
+            $count = 0;
567
+            $sum = 0;
568
+            $bestResult = 0;
569
+            $weight = 0;
570
+            $sumResult = 0;
571
+
572
+            $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id;
573 573
             $data = Session::read('calc_score');
574 574
             $allResults = isset($data[$key]) ? $data[$key] : null;
575 575
             if ($useSession == false) {
576 576
                 $allResults  = null;
577 577
             }
578
-			if (empty($allResults)) {
579
-				$allResults = Result::load(null, null, $this->id);
580
-				Session::write($key, $allResults);
581
-			}
582
-
583
-			$students = array();
584
-			/** @var Result $res */
585
-			foreach ($allResults as $res) {
586
-				$score = $res->get_score();
587
-				if (!empty($score) || $score == '0') {
588
-					$count++;
589
-					$sum += $score / $this->get_max();
590
-					$sumResult += $score;
591
-					if ($score > $bestResult) {
592
-						$bestResult = $score;
593
-					}
594
-					$weight = $this->get_max();
595
-				}
596
-				$students[$res->get_user_id()] = $score;
597
-			}
598
-
599
-			if (empty($count)) {
600
-				return null;
601
-			}
602
-
603
-			switch ($type) {
604
-				case 'best':
605
-					return array($bestResult, $weight);
606
-					break;
607
-				case 'average':
608
-					return array($sumResult/$count, $weight);
609
-					break;
610
-				case 'ranking':
578
+            if (empty($allResults)) {
579
+                $allResults = Result::load(null, null, $this->id);
580
+                Session::write($key, $allResults);
581
+            }
582
+
583
+            $students = array();
584
+            /** @var Result $res */
585
+            foreach ($allResults as $res) {
586
+                $score = $res->get_score();
587
+                if (!empty($score) || $score == '0') {
588
+                    $count++;
589
+                    $sum += $score / $this->get_max();
590
+                    $sumResult += $score;
591
+                    if ($score > $bestResult) {
592
+                        $bestResult = $score;
593
+                    }
594
+                    $weight = $this->get_max();
595
+                }
596
+                $students[$res->get_user_id()] = $score;
597
+            }
598
+
599
+            if (empty($count)) {
600
+                return null;
601
+            }
602
+
603
+            switch ($type) {
604
+                case 'best':
605
+                    return array($bestResult, $weight);
606
+                    break;
607
+                case 'average':
608
+                    return array($sumResult/$count, $weight);
609
+                    break;
610
+                case 'ranking':
611 611
                     $students = array();
612 612
                     /** @var Result $res */
613 613
                     foreach ($allResults as $res) {
614 614
                         $score = $res->get_score();
615 615
                         $students[$res->get_user_id()] = $score;
616 616
                     }
617
-					return AbstractLink::getCurrentUserRanking($stud_id, $students);
618
-					break;
619
-				default:
620
-					return array($sum, $count);
621
-					break;
622
-			}
623
-		}
624
-	}
625
-
626
-	/**
627
-	 * Generate an array of possible categories where this evaluation can be moved to.
628
-	 * Notice: its own parent will be included in the list: it's up to the frontend
629
-	 * to disable this element.
630
-	 * @return array 2-dimensional array - every element contains 3 subelements (id, name, level)
631
-	 */
632
-	public function get_target_categories()
633
-	{
634
-		// - course independent evaluation
635
-		//   -> movable to root or other course independent categories
636
-		// - evaluation inside a course
637
-		//   -> movable to root, independent categories or categories inside the course
638
-		$user = (api_is_platform_admin() ? null : api_get_user_id());
639
-		$targets = array();
640
-		$level = 0;
641
-
642
-		$root = array(0, get_lang('RootCat'), $level);
643
-		$targets[] = $root;
644
-
645
-		if (isset($this->course_code) && !empty($this->course_code)) {
646
-			$crscats = Category::load(null,null,$this->course_code,0);
647
-			foreach ($crscats as $cat) {
648
-				$targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
649
-				$targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
650
-			}
651
-		}
652
-
653
-		$indcats = Category::load(null,$user,0,0);
654
-		foreach ($indcats as $cat) {
655
-			$targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
656
-			$targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
657
-		}
658
-
659
-		return $targets;
660
-	}
661
-
662
-	/**
663
-	 * Internal function used by get_target_categories()
664
-	 * @param integer $level
665
-	 */
666
-	private function add_target_subcategories($targets, $level, $catid)
667
-	{
668
-		$subcats = Category::load(null,null,null,$catid);
669
-		foreach ($subcats as $cat) {
670
-			$targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
671
-			$targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
672
-		}
673
-		return $targets;
674
-	}
675
-
676
-	/**
677
-	 * Move this evaluation to the given category.
678
-	 * If this evaluation moves from inside a course to outside,
679
-	 * its course code is also changed.
680
-	 */
681
-	public function move_to_cat($cat)
682
-	{
683
-		$this->set_category_id($cat->get_id());
684
-		if ($this->get_course_code() != $cat->get_course_code()) {
685
-			$this->set_course_code($cat->get_course_code());
686
-		}
687
-		$this->save();
688
-	}
689
-
690
-	/**
691
-	 * Retrieve evaluations where a student has results for
692
-	 * and return them as an array of Evaluation objects
693
-	 * @param int $cat_id parent category (use 'null' to retrieve them in all categories)
694
-	 * @param int $stud_id student id
695
-	 */
696
-	public static function get_evaluations_with_result_for_student($cat_id = null, $stud_id)
697
-	{
698
-		$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
699
-		$tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
700
-
701
-		$sql = 'SELECT * FROM '.$tbl_grade_evaluations.'
617
+                    return AbstractLink::getCurrentUserRanking($stud_id, $students);
618
+                    break;
619
+                default:
620
+                    return array($sum, $count);
621
+                    break;
622
+            }
623
+        }
624
+    }
625
+
626
+    /**
627
+     * Generate an array of possible categories where this evaluation can be moved to.
628
+     * Notice: its own parent will be included in the list: it's up to the frontend
629
+     * to disable this element.
630
+     * @return array 2-dimensional array - every element contains 3 subelements (id, name, level)
631
+     */
632
+    public function get_target_categories()
633
+    {
634
+        // - course independent evaluation
635
+        //   -> movable to root or other course independent categories
636
+        // - evaluation inside a course
637
+        //   -> movable to root, independent categories or categories inside the course
638
+        $user = (api_is_platform_admin() ? null : api_get_user_id());
639
+        $targets = array();
640
+        $level = 0;
641
+
642
+        $root = array(0, get_lang('RootCat'), $level);
643
+        $targets[] = $root;
644
+
645
+        if (isset($this->course_code) && !empty($this->course_code)) {
646
+            $crscats = Category::load(null,null,$this->course_code,0);
647
+            foreach ($crscats as $cat) {
648
+                $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
649
+                $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
650
+            }
651
+        }
652
+
653
+        $indcats = Category::load(null,$user,0,0);
654
+        foreach ($indcats as $cat) {
655
+            $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
656
+            $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
657
+        }
658
+
659
+        return $targets;
660
+    }
661
+
662
+    /**
663
+     * Internal function used by get_target_categories()
664
+     * @param integer $level
665
+     */
666
+    private function add_target_subcategories($targets, $level, $catid)
667
+    {
668
+        $subcats = Category::load(null,null,null,$catid);
669
+        foreach ($subcats as $cat) {
670
+            $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
671
+            $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
672
+        }
673
+        return $targets;
674
+    }
675
+
676
+    /**
677
+     * Move this evaluation to the given category.
678
+     * If this evaluation moves from inside a course to outside,
679
+     * its course code is also changed.
680
+     */
681
+    public function move_to_cat($cat)
682
+    {
683
+        $this->set_category_id($cat->get_id());
684
+        if ($this->get_course_code() != $cat->get_course_code()) {
685
+            $this->set_course_code($cat->get_course_code());
686
+        }
687
+        $this->save();
688
+    }
689
+
690
+    /**
691
+     * Retrieve evaluations where a student has results for
692
+     * and return them as an array of Evaluation objects
693
+     * @param int $cat_id parent category (use 'null' to retrieve them in all categories)
694
+     * @param int $stud_id student id
695
+     */
696
+    public static function get_evaluations_with_result_for_student($cat_id = null, $stud_id)
697
+    {
698
+        $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
699
+        $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
700
+
701
+        $sql = 'SELECT * FROM '.$tbl_grade_evaluations.'
702 702
 				WHERE id IN (
703 703
 					SELECT evaluation_id FROM '.$tbl_grade_results.'
704 704
 					WHERE user_id = '.intval($stud_id).' AND score IS NOT NULL
705 705
 				)';
706
-		if (!api_is_allowed_to_edit()) {
707
-			$sql .= ' AND visible = 1';
708
-		}
709
-		if (isset($cat_id)) {
710
-			$sql .= ' AND category_id = '.intval($cat_id);
711
-		} else {
712
-			$sql .= ' AND category_id >= 0';
713
-		}
714
-
715
-		$result = Database::query($sql);
716
-		$alleval = Evaluation::create_evaluation_objects_from_sql_result($result);
717
-
718
-		return $alleval;
719
-	}
720
-
721
-	/**
722
-	 * Get a list of students that do not have a result record for this evaluation
723
-	 */
724
-	public function get_not_subscribed_students($first_letter_user = '')
725
-	{
726
-		$tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
727
-		$tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
728
-
729
-		$sql = 'SELECT user_id,lastname,firstname,username FROM '.$tbl_user
730
-			." WHERE lastname LIKE '".Database::escape_string($first_letter_user)."%'"
731
-			.' AND status = '.STUDENT
732
-			.' AND user_id NOT IN'
733
-			.' (SELECT user_id FROM '.$tbl_grade_results
734
-			.' WHERE evaluation_id = '.intval($this->id)
735
-			.' )'
736
-			.' ORDER BY lastname';
737
-
738
-		$result = Database::query($sql);
739
-		$users = Database::store_result($result);
740
-
741
-		return $users;
742
-	}
743
-
744
-	/**
745
-	 * Find evaluations by name
746
-	 * @param string $name_mask search string
747
-	 * @return array evaluation objects matching the search criterium
748
-	 * @todo can be written more efficiently using a new (but very complex) sql query
749
-	 */
750
-	public function find_evaluations($name_mask,$selectcat)
751
-	{
752
-		$rootcat = Category::load($selectcat);
753
-		$evals = $rootcat[0]->get_evaluations((api_is_allowed_to_create_course() ? null : api_get_user_id()), true);
754
-		$foundevals = array();
755
-		foreach ($evals as $eval) {
756
-			if (!(api_strpos(api_strtolower($eval->get_name()), api_strtolower($name_mask)) === false)) {
757
-				$foundevals[] = $eval;
758
-			}
759
-		}
760
-		return $foundevals;
761
-	}
762
-
763
-	public function get_item_type()
764
-	{
765
-		return 'E';
766
-	}
767
-
768
-	public function get_icon_name()
769
-	{
770
-		return $this->has_results() ? 'evalnotempty' : 'evalempty';
771
-	}
772
-
773
-	/**
774
-	 * Locks an evaluation, only one who can unlock it is the platform administrator.
775
-	 * @param int locked 1 or unlocked 0
776
-	 *
777
-	 **/
778
-	function lock($locked)
779
-	{
780
-		$table_evaluation = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
781
-		$sql = "UPDATE $table_evaluation SET locked = '".intval($locked)."' WHERE id='".intval($this->id)."'";
782
-		Database::query($sql);
783
-	}
784
-
785
-	function check_lock_permissions()
786
-	{
787
-		if (api_is_platform_admin()) {
788
-			return true;
789
-		} else {
790
-			if ($this->is_locked()) {
791
-				api_not_allowed();
792
-			}
793
-		}
794
-	}
795
-
796
-	function delete_linked_data()
797
-	{
798
-
799
-	}
706
+        if (!api_is_allowed_to_edit()) {
707
+            $sql .= ' AND visible = 1';
708
+        }
709
+        if (isset($cat_id)) {
710
+            $sql .= ' AND category_id = '.intval($cat_id);
711
+        } else {
712
+            $sql .= ' AND category_id >= 0';
713
+        }
714
+
715
+        $result = Database::query($sql);
716
+        $alleval = Evaluation::create_evaluation_objects_from_sql_result($result);
717
+
718
+        return $alleval;
719
+    }
720
+
721
+    /**
722
+     * Get a list of students that do not have a result record for this evaluation
723
+     */
724
+    public function get_not_subscribed_students($first_letter_user = '')
725
+    {
726
+        $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
727
+        $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
728
+
729
+        $sql = 'SELECT user_id,lastname,firstname,username FROM '.$tbl_user
730
+            ." WHERE lastname LIKE '".Database::escape_string($first_letter_user)."%'"
731
+            .' AND status = '.STUDENT
732
+            .' AND user_id NOT IN'
733
+            .' (SELECT user_id FROM '.$tbl_grade_results
734
+            .' WHERE evaluation_id = '.intval($this->id)
735
+            .' )'
736
+            .' ORDER BY lastname';
737
+
738
+        $result = Database::query($sql);
739
+        $users = Database::store_result($result);
740
+
741
+        return $users;
742
+    }
743
+
744
+    /**
745
+     * Find evaluations by name
746
+     * @param string $name_mask search string
747
+     * @return array evaluation objects matching the search criterium
748
+     * @todo can be written more efficiently using a new (but very complex) sql query
749
+     */
750
+    public function find_evaluations($name_mask,$selectcat)
751
+    {
752
+        $rootcat = Category::load($selectcat);
753
+        $evals = $rootcat[0]->get_evaluations((api_is_allowed_to_create_course() ? null : api_get_user_id()), true);
754
+        $foundevals = array();
755
+        foreach ($evals as $eval) {
756
+            if (!(api_strpos(api_strtolower($eval->get_name()), api_strtolower($name_mask)) === false)) {
757
+                $foundevals[] = $eval;
758
+            }
759
+        }
760
+        return $foundevals;
761
+    }
762
+
763
+    public function get_item_type()
764
+    {
765
+        return 'E';
766
+    }
767
+
768
+    public function get_icon_name()
769
+    {
770
+        return $this->has_results() ? 'evalnotempty' : 'evalempty';
771
+    }
772
+
773
+    /**
774
+     * Locks an evaluation, only one who can unlock it is the platform administrator.
775
+     * @param int locked 1 or unlocked 0
776
+     *
777
+     **/
778
+    function lock($locked)
779
+    {
780
+        $table_evaluation = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
781
+        $sql = "UPDATE $table_evaluation SET locked = '".intval($locked)."' WHERE id='".intval($this->id)."'";
782
+        Database::query($sql);
783
+    }
784
+
785
+    function check_lock_permissions()
786
+    {
787
+        if (api_is_platform_admin()) {
788
+            return true;
789
+        } else {
790
+            if ($this->is_locked()) {
791
+                api_not_allowed();
792
+            }
793
+        }
794
+    }
795
+
796
+    function delete_linked_data()
797
+    {
798
+
799
+    }
800 800
 
801 801
     public function getStudentList()
802 802
     {
803 803
         return $this->studentList;
804 804
     }
805 805
 
806
-	public function setStudentList($list)
807
-	{
808
-		$this->studentList = $list;
809
-	}
806
+    public function setStudentList($list)
807
+    {
808
+        $this->studentList = $list;
809
+    }
810 810
 }
Please login to merge, or discard this patch.
main/inc/lib/api.lib.php 1 patch
Doc Comments   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1359,6 +1359,7 @@  discard block
 block discarded – undo
1359 1359
  * Gets the list of courses a specific user is subscribed to
1360 1360
  * @param int       User ID
1361 1361
  * @param boolean   $fetch_session Whether to get session courses or not - NOT YET IMPLEMENTED
1362
+ * @param integer $userid
1362 1363
  * @return array    Array of courses in the form [0]=>('code'=>xxx,'db'=>xxx,'dir'=>xxx,'status'=>d)
1363 1364
  */
1364 1365
 function api_get_user_courses($userid, $fetch_session = true)
@@ -6756,7 +6757,7 @@  discard block
 block discarded – undo
6756 6757
 /**
6757 6758
  * Returns an array of global configuration settings which should be ignored
6758 6759
  * when printing the configuration settings screens
6759
- * @return array Array of strings, each identifying one of the excluded settings
6760
+ * @return string[] Array of strings, each identifying one of the excluded settings
6760 6761
  */
6761 6762
 function api_get_locked_settings() {
6762 6763
     return array(
@@ -6799,6 +6800,7 @@  discard block
 block discarded – undo
6799 6800
  * false if he isn't. If the user ID is given and is an integer, then the same
6800 6801
  * ID is simply returned
6801 6802
  * @param  integer User ID
6803
+ * @param integer $user_id
6802 6804
  * @return boolean Integer User ID is logged in, or false otherwise
6803 6805
  */
6804 6806
 function api_user_is_login($user_id = null) {
@@ -7243,6 +7245,7 @@  discard block
 block discarded – undo
7243 7245
 /**
7244 7246
  * Gets memory limit in bytes
7245 7247
  * @param string The memory size (128M, 1G, 1000K, etc)
7248
+ * @param string $mem
7246 7249
  * @return int
7247 7250
  * @assert (null) === false
7248 7251
  * @assert ('1t')  === 1099511627776
Please login to merge, or discard this patch.
main/inc/lib/course.lib.php 1 patch
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -2240,7 +2240,7 @@
 block discarded – undo
2240 2240
 
2241 2241
     /**
2242 2242
      * Creates a file called mysql_dump.sql in the course folder
2243
-     * @param $course_code The code of the course
2243
+     * @param string $course_code The code of the course
2244 2244
      * @todo Implementation for single database
2245 2245
      */
2246 2246
     public static function create_database_dump($course_code)
Please login to merge, or discard this patch.
main/inc/lib/course_description.lib.php 1 patch
Doc Comments   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
 
360 360
     /**
361 361
      * Get description titles by default
362
-     * @return array
362
+     * @return string[]
363 363
      */
364 364
     public function get_default_description_title()
365 365
     {
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
 
379 379
     /**
380 380
      * Get description titles editable by default
381
-     * @return array
381
+     * @return boolean[]
382 382
      */
383 383
     public function get_default_description_title_editable()
384 384
     {
@@ -397,7 +397,7 @@  discard block
 block discarded – undo
397 397
 
398 398
     /**
399 399
      * Get description icons by default
400
-     * @return array
400
+     * @return string[]
401 401
      */
402 402
     public function get_default_description_icon()
403 403
     {
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
 
418 418
     /**
419 419
      * Get questions by default for help
420
-     * @return array
420
+     * @return string[]
421 421
      */
422 422
     public function get_default_question()
423 423
     {
@@ -436,7 +436,7 @@  discard block
 block discarded – undo
436 436
 
437 437
     /**
438 438
      * Get informations by default for help
439
-     * @return array
439
+     * @return string[]
440 440
      */
441 441
     public function get_default_information()
442 442
     {
Please login to merge, or discard this patch.