Completed
Push — 1.10.x ( f409b5...1f80a0 )
by Julito
112:29 queued 56:28
created
main/gradebook/lib/be/result.class.php 2 patches
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -90,23 +90,23 @@  discard block
 block discarded – undo
90 90
         if (is_null($id) && is_null($user_id) && !is_null($evaluation_id)) {
91 91
             // Verified_if_exist_evaluation
92 92
             $sql = 'SELECT COUNT(*) AS count
93
-                    FROM ' . $tbl_grade_results . '
94
-                    WHERE evaluation_id="' . Database::escape_string($evaluation_id) . '";';
93
+                    FROM ' . $tbl_grade_results.'
94
+                    WHERE evaluation_id="' . Database::escape_string($evaluation_id).'";';
95 95
             $result = Database::query($sql);
96 96
             $existEvaluation = Database::result($result, 0, 0);
97 97
 
98 98
             if ($existEvaluation != 0) {
99 99
                 if ($sessionId) {
100 100
                     $sql = 'SELECT c_id, user_id as user_id, status
101
-                            FROM ' . $tbl_session_rel_course_user . '
101
+                            FROM ' . $tbl_session_rel_course_user.'
102 102
 							WHERE
103 103
 							    status= 0 AND
104
-							    c_id = "' . api_get_course_int_id() . '" AND
104
+							    c_id = "' . api_get_course_int_id().'" AND
105 105
 							    session_id = ' . $sessionId;
106 106
                 } else {
107 107
                     $sql = 'SELECT c_id, user_id, status
108
-                            FROM ' . $tbl_course_rel_course . '
109
-                            WHERE status ="' . STUDENT . '" AND c_id = "' . api_get_course_int_id() . '" ';
108
+                            FROM ' . $tbl_course_rel_course.'
109
+                            WHERE status ="' . STUDENT.'" AND c_id = "'.api_get_course_int_id().'" ';
110 110
                 }
111 111
 
112 112
                 $res_course_rel_user = Database::query($sql);
@@ -116,15 +116,15 @@  discard block
 block discarded – undo
116 116
                 $current_date = api_get_utc_datetime();
117 117
                 for ($i = 0; $i < count($list_user_course_list); $i++) {
118 118
                     $sql_verified = 'SELECT COUNT(*) AS count
119
-                                    FROM ' . $tbl_grade_results . '
119
+                                    FROM ' . $tbl_grade_results.'
120 120
                                     WHERE
121
-                                        user_id="' . intval($list_user_course_list[$i]['user_id']) . '" AND
122
-                                        evaluation_id="' . intval($evaluation_id) . '";';
121
+                                        user_id="' . intval($list_user_course_list[$i]['user_id']).'" AND
122
+                                        evaluation_id="' . intval($evaluation_id).'";';
123 123
                     $res_verified = Database::query($sql_verified);
124 124
                     $info_verified = Database::result($res_verified, 0, 0);
125 125
                     if ($info_verified == 0) {
126
-                        $sql_insert = 'INSERT INTO ' . $tbl_grade_results . '(user_id,evaluation_id,created_at,score)
127
-									   VALUES ("' . intval($list_user_course_list[$i]['user_id']) . '","' . intval($evaluation_id) . '","' . $current_date . '",0);';
126
+                        $sql_insert = 'INSERT INTO '.$tbl_grade_results.'(user_id,evaluation_id,created_at,score)
127
+									   VALUES ("' . intval($list_user_course_list[$i]['user_id']).'","'.intval($evaluation_id).'","'.$current_date.'",0);';
128 128
                         Database::query($sql_insert);
129 129
                     }
130 130
                 }
@@ -148,16 +148,16 @@  discard block
 block discarded – undo
148 148
 
149 149
         $paramcount = 0;
150 150
         if (!empty($id)) {
151
-            $sql.= ' WHERE gr.id = ' . intval($id);
152
-            $paramcount ++;
151
+            $sql .= ' WHERE gr.id = '.intval($id);
152
+            $paramcount++;
153 153
         }
154 154
         if (!empty($user_id)) {
155 155
             if ($paramcount != 0)
156 156
                 $sql .= ' AND';
157 157
             else
158 158
                 $sql .= ' WHERE';
159
-            $sql .= ' gr.user_id = ' . intval($user_id);
160
-            $paramcount ++;
159
+            $sql .= ' gr.user_id = '.intval($user_id);
160
+            $paramcount++;
161 161
         }
162 162
         if (!empty($evaluation_id)) {
163 163
             if ($paramcount != 0) {
@@ -165,8 +165,8 @@  discard block
 block discarded – undo
165 165
             } else {
166 166
                 $sql .= ' WHERE';
167 167
             }
168
-            $sql .= ' gr.evaluation_id = ' . intval($evaluation_id);
169
-            $paramcount ++;
168
+            $sql .= ' gr.evaluation_id = '.intval($evaluation_id);
169
+            $paramcount++;
170 170
         }
171 171
         $sql .= ' ORDER BY u.lastname, u.firstname';
172 172
         $result = Database::query($sql);
@@ -191,17 +191,17 @@  discard block
 block discarded – undo
191 191
     {
192 192
         if (isset($this->user_id) && isset($this->evaluation)) {
193 193
             $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
194
-            $sql = "INSERT INTO " . $tbl_grade_results
194
+            $sql = "INSERT INTO ".$tbl_grade_results
195 195
                 . " (user_id, evaluation_id,
196 196
 					created_at";
197 197
             if (isset($this->score)) {
198 198
                 $sql .= ",score";
199 199
             }
200 200
             $sql .= ") VALUES
201
-					(" . (int) $this->get_user_id() . ", " . (int) $this->get_evaluation_id()
202
-                . ", '" . $this->get_date() . "' ";
201
+					(" . (int) $this->get_user_id().", ".(int) $this->get_evaluation_id()
202
+                . ", '".$this->get_date()."' ";
203 203
             if (isset($this->score)) {
204
-                $sql .= ", " . $this->get_score();
204
+                $sql .= ", ".$this->get_score();
205 205
             }
206 206
             $sql .= ")";
207 207
             Database::query($sql);
@@ -222,16 +222,16 @@  discard block
 block discarded – undo
222 222
             $arr_result = $result->load(null, $userid, $evaluationid);
223 223
             $arr = get_object_vars($arr_result[0]);
224 224
 
225
-            $sql = 'INSERT INTO ' . $tbl_grade_results_log
225
+            $sql = 'INSERT INTO '.$tbl_grade_results_log
226 226
                 . ' (id_result,user_id, evaluation_id,created_at';
227 227
             if (isset($arr['score'])) {
228 228
                 $sql .= ',score';
229 229
             }
230 230
             $sql .= ') VALUES
231
-					(' . (int) $arr['id'] . ',' . (int) $arr['user_id'] . ', ' . (int) $arr['evaluation']
232
-                . ", '" . api_get_utc_datetime() . "'";
231
+					(' . (int) $arr['id'].','.(int) $arr['user_id'].', '.(int) $arr['evaluation']
232
+                . ", '".api_get_utc_datetime()."'";
233 233
             if (isset($arr['score'])) {
234
-                $sql .= ', ' . $arr['score'];
234
+                $sql .= ', '.$arr['score'];
235 235
             }
236 236
             $sql .= ')';
237 237
 
@@ -247,16 +247,16 @@  discard block
 block discarded – undo
247 247
     public function save()
248 248
     {
249 249
         $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
250
-        $sql = 'UPDATE ' . $tbl_grade_results . '
250
+        $sql = 'UPDATE '.$tbl_grade_results.'
251 251
                 SET user_id = ' . $this->get_user_id()
252
-            . ', evaluation_id = ' . $this->get_evaluation_id()
252
+            . ', evaluation_id = '.$this->get_evaluation_id()
253 253
             . ', score = ';
254 254
         if (isset($this->score)) {
255 255
             $sql .= $this->get_score();
256 256
         } else {
257 257
             $sql .= 'null';
258 258
         }
259
-        $sql .= ' WHERE id = ' . $this->id;
259
+        $sql .= ' WHERE id = '.$this->id;
260 260
         // no need to update creation date
261 261
         Database::query($sql);
262 262
     }
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
     public function delete()
268 268
     {
269 269
         $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
270
-        $sql = 'DELETE FROM ' . $tbl_grade_results . ' WHERE id = ' . $this->id;
270
+        $sql = 'DELETE FROM '.$tbl_grade_results.' WHERE id = '.$this->id;
271 271
         Database::query($sql);
272 272
     }
273 273
 }
Please login to merge, or discard this patch.
Braces   +5 added lines, -4 removed lines patch added patch discarded remove patch
@@ -152,10 +152,11 @@
 block discarded – undo
152 152
             $paramcount ++;
153 153
         }
154 154
         if (!empty($user_id)) {
155
-            if ($paramcount != 0)
156
-                $sql .= ' AND';
157
-            else
158
-                $sql .= ' WHERE';
155
+            if ($paramcount != 0) {
156
+                            $sql .= ' AND';
157
+            } else {
158
+                            $sql .= ' WHERE';
159
+            }
159 160
             $sql .= ' gr.user_id = ' . intval($user_id);
160 161
             $paramcount ++;
161 162
         }
Please login to merge, or discard this patch.
main/gradebook/lib/be/studentpublicationlink.class.php 2 patches
Indentation   +317 added lines, -317 removed lines patch added patch discarded remove patch
@@ -8,102 +8,102 @@  discard block
 block discarded – undo
8 8
  */
9 9
 class StudentPublicationLink extends AbstractLink
10 10
 {
11
-	private $studpub_table = null;
12
-	private $itemprop_table = null;
13
-
14
-	/**
15
-	 * Constructor
16
-	 */
17
-	public function __construct()
18
-	{
19
-		parent::__construct();
20
-		$this->set_type(LINK_STUDENTPUBLICATION);
21
-	}
22
-
23
-	/**
24
-	 *
25
-	 * Returns the URL of a document
26
-	 * This function is loaded when using a gradebook as a tab (gradebook = -1)
27
-	 * see issue #2705
28
-	 *
29
-	 */
30
-	public function get_view_url($stud_id)
31
-	{
32
-		// find a file uploaded by the given student,
33
-		// with the same title as the evaluation name
34
-
35
-		$eval = $this->get_evaluation();
36
-		$stud_id = intval($stud_id);
37
-
38
-		$sql = 'SELECT pub.url
11
+    private $studpub_table = null;
12
+    private $itemprop_table = null;
13
+
14
+    /**
15
+     * Constructor
16
+     */
17
+    public function __construct()
18
+    {
19
+        parent::__construct();
20
+        $this->set_type(LINK_STUDENTPUBLICATION);
21
+    }
22
+
23
+    /**
24
+     *
25
+     * Returns the URL of a document
26
+     * This function is loaded when using a gradebook as a tab (gradebook = -1)
27
+     * see issue #2705
28
+     *
29
+     */
30
+    public function get_view_url($stud_id)
31
+    {
32
+        // find a file uploaded by the given student,
33
+        // with the same title as the evaluation name
34
+
35
+        $eval = $this->get_evaluation();
36
+        $stud_id = intval($stud_id);
37
+
38
+        $sql = 'SELECT pub.url
39 39
 				FROM '.$this->get_itemprop_table().' prop, '.$this->get_studpub_table().' pub'
40
-			." WHERE
40
+            ." WHERE
41 41
 					prop.c_id = ".$this->course_id." AND
42 42
 					pub.c_id = ".$this->course_id." AND
43 43
 					prop.tool = 'work'"
44
-			.' AND prop.insert_user_id = '.$stud_id
45
-			.' AND prop.ref = pub.id'
46
-			." AND pub.title = '".Database::escape_string($eval->get_name())."' AND pub.session_id=".api_get_session_id()."";
47
-
48
-		$result = Database::query($sql);
49
-		if ($fileurl = Database::fetch_row($result)) {
50
-			return null;
51
-		} else {
52
-			return null;
53
-		}
54
-	}
55
-
56
-	public function get_type_name()
57
-	{
58
-		return get_lang('Works');
59
-	}
60
-
61
-	public function is_allowed_to_change_name()
62
-	{
63
-		return false;
64
-	}
65
-
66
-	/**
67
-	 * Generate an array of exercises that a teacher hasn't created a link for.
68
-	 * @return array 2-dimensional array - every element contains 2 subelements (id, name)
69
-	 */
70
-	public function get_not_created_links()
71
-	{
72
-		return false;
73
-		if (empty($this->course_code)) {
74
-			die('Error in get_not_created_links() : course code not set');
75
-		}
76
-		$tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
77
-
78
-		$sql = 'SELECT id, url from '.$this->get_studpub_table()
79
-			.' pup WHERE c_id = '.$this->course_id.' AND has_properties != '."''".' AND id NOT IN'
80
-			.' (SELECT ref_id FROM '.$tbl_grade_links
81
-			.' WHERE type = '.LINK_STUDENTPUBLICATION
82
-			." AND course_code = '".Database::escape_string($this->get_course_code())."'"
83
-			.') AND pub.session_id='.api_get_session_id().'';
84
-
85
-		$result = Database::query($sql);
86
-
87
-		$cats=array();
88
-		while ($data=Database::fetch_array($result)) {
89
-			$cats[] = array ($data['id'], $data['url']);
90
-		}
91
-		return $cats;
92
-	}
93
-
94
-	/**
95
-	 * Generate an array of all exercises available.
96
-	 * @return array 2-dimensional array - every element contains 2 subelements (id, name)
97
-	 */
98
-	public function get_all_links()
99
-	{
100
-		if (empty($this->course_code)) {
101
-			die('Error in get_not_created_links() : course code not set');
102
-		}
103
-		$tbl_grade_links = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
104
-
105
-		$session_id = api_get_session_id();
106
-		/*
44
+            .' AND prop.insert_user_id = '.$stud_id
45
+            .' AND prop.ref = pub.id'
46
+            ." AND pub.title = '".Database::escape_string($eval->get_name())."' AND pub.session_id=".api_get_session_id()."";
47
+
48
+        $result = Database::query($sql);
49
+        if ($fileurl = Database::fetch_row($result)) {
50
+            return null;
51
+        } else {
52
+            return null;
53
+        }
54
+    }
55
+
56
+    public function get_type_name()
57
+    {
58
+        return get_lang('Works');
59
+    }
60
+
61
+    public function is_allowed_to_change_name()
62
+    {
63
+        return false;
64
+    }
65
+
66
+    /**
67
+     * Generate an array of exercises that a teacher hasn't created a link for.
68
+     * @return array 2-dimensional array - every element contains 2 subelements (id, name)
69
+     */
70
+    public function get_not_created_links()
71
+    {
72
+        return false;
73
+        if (empty($this->course_code)) {
74
+            die('Error in get_not_created_links() : course code not set');
75
+        }
76
+        $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
77
+
78
+        $sql = 'SELECT id, url from '.$this->get_studpub_table()
79
+            .' pup WHERE c_id = '.$this->course_id.' AND has_properties != '."''".' AND id NOT IN'
80
+            .' (SELECT ref_id FROM '.$tbl_grade_links
81
+            .' WHERE type = '.LINK_STUDENTPUBLICATION
82
+            ." AND course_code = '".Database::escape_string($this->get_course_code())."'"
83
+            .') AND pub.session_id='.api_get_session_id().'';
84
+
85
+        $result = Database::query($sql);
86
+
87
+        $cats=array();
88
+        while ($data=Database::fetch_array($result)) {
89
+            $cats[] = array ($data['id'], $data['url']);
90
+        }
91
+        return $cats;
92
+    }
93
+
94
+    /**
95
+     * Generate an array of all exercises available.
96
+     * @return array 2-dimensional array - every element contains 2 subelements (id, name)
97
+     */
98
+    public function get_all_links()
99
+    {
100
+        if (empty($this->course_code)) {
101
+            die('Error in get_not_created_links() : course code not set');
102
+        }
103
+        $tbl_grade_links = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
104
+
105
+        $session_id = api_get_session_id();
106
+        /*
107 107
         if (empty($session_id)) {
108 108
             $session_condition = api_get_session_condition(0, true);
109 109
         } else {
@@ -112,68 +112,68 @@  discard block
 block discarded – undo
112 112
         $sql = "SELECT id, url, title FROM $tbl_grade_links
113 113
                 WHERE c_id = {$this->course_id}  AND filetype='folder' AND active = 1 $session_condition ";*/
114 114
 
115
-		//Only show works from the session
116
-		//AND has_properties != ''
117
-		$sql = "SELECT id, url, title FROM $tbl_grade_links
115
+        //Only show works from the session
116
+        //AND has_properties != ''
117
+        $sql = "SELECT id, url, title FROM $tbl_grade_links
118 118
 				WHERE
119 119
 					c_id = {$this->course_id} AND
120 120
 					active = 1 AND
121 121
 					filetype='folder' AND
122 122
 					session_id = ".api_get_session_id()."";
123 123
 
124
-		$result = Database::query($sql);
125
-		while ($data = Database::fetch_array($result)) {
126
-			$work_name = $data['title'];
127
-			if (empty($work_name)) {
128
-				$work_name = basename($data['url']);
129
-			}
130
-			$cats[] = array ($data['id'], $work_name);
131
-		}
132
-		$cats=isset($cats) ? $cats : array();
133
-		return $cats;
134
-	}
135
-
136
-	/**
137
-	 * Has anyone done this exercise yet ?
138
-	 */
139
-	public function has_results()
140
-	{
141
-		$tbl_grade_links = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
142
-		$sql = 'SELECT count(*) AS number FROM '.$tbl_grade_links."
124
+        $result = Database::query($sql);
125
+        while ($data = Database::fetch_array($result)) {
126
+            $work_name = $data['title'];
127
+            if (empty($work_name)) {
128
+                $work_name = basename($data['url']);
129
+            }
130
+            $cats[] = array ($data['id'], $work_name);
131
+        }
132
+        $cats=isset($cats) ? $cats : array();
133
+        return $cats;
134
+    }
135
+
136
+    /**
137
+     * Has anyone done this exercise yet ?
138
+     */
139
+    public function has_results()
140
+    {
141
+        $tbl_grade_links = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
142
+        $sql = 'SELECT count(*) AS number FROM '.$tbl_grade_links."
143 143
 				WHERE 	c_id 		= {$this->course_id} AND
144 144
 						parent_id 	= '".intval($this->get_ref_id())."' AND
145 145
 						session_id	=".api_get_session_id()."";
146
-		$result = Database::query($sql);
147
-		$number = Database::fetch_row($result);
148
-		return ($number[0] != 0);
149
-	}
150
-
151
-	/**
152
-	 * @param null $stud_id
153
-	 * @return array|null
154
-	 */
155
-	public function calc_score($stud_id = null, $type = null)
156
-	{
157
-		$stud_id = intval($stud_id);
158
-		$table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
159
-		$sql = 'SELECT * FROM '.$table."
146
+        $result = Database::query($sql);
147
+        $number = Database::fetch_row($result);
148
+        return ($number[0] != 0);
149
+    }
150
+
151
+    /**
152
+     * @param null $stud_id
153
+     * @return array|null
154
+     */
155
+    public function calc_score($stud_id = null, $type = null)
156
+    {
157
+        $stud_id = intval($stud_id);
158
+        $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
159
+        $sql = 'SELECT * FROM '.$table."
160 160
     			WHERE
161 161
     				c_id = {$this->course_id} AND
162 162
     				id  = '".intval($this->get_ref_id())."' AND
163 163
     				session_id	= ".api_get_session_id()."
164 164
 				"
165
-		;
165
+        ;
166 166
 
167
-		$query = Database::query($sql);
168
-		$assignment = Database::fetch_array($query);
167
+        $query = Database::query($sql);
168
+        $assignment = Database::fetch_array($query);
169 169
 
170
-		if (count($assignment) == 0) {
171
-			$parentId = '0';
172
-		} else {
173
-			$parentId = $assignment['id'];
174
-		}
170
+        if (count($assignment) == 0) {
171
+            $parentId = '0';
172
+        } else {
173
+            $parentId = $assignment['id'];
174
+        }
175 175
 
176
-		$sql = 'SELECT * FROM '.$table.'
176
+        $sql = 'SELECT * FROM '.$table.'
177 177
     			WHERE
178 178
     				c_id = '.$this->course_id.' AND
179 179
     				active = 1 AND
@@ -181,190 +181,190 @@  discard block
 block discarded – undo
181 181
     				session_id = '.api_get_session_id() .' AND
182 182
     				qualificator_id <> 0
183 183
 				';
184
-		if (!empty($stud_id)) {
185
-			$sql .= " AND user_id = $stud_id ";
186
-		}
187
-
188
-		$order = api_get_setting('student_publication_to_take_in_gradebook');
189
-
190
-		switch ($order) {
191
-			case 'last':
192
-				// latest attempt
193
-				$sql .= ' ORDER BY sent_date DESC';
194
-				break;
195
-			case 'first':
196
-			default:
197
-				// first attempt
198
-				$sql .= ' ORDER BY id';
199
-				break;
200
-		}
201
-
202
-		$scores = Database::query($sql);
203
-
204
-		// for 1 student
205
-		if (!empty($stud_id)) {
206
-			if ($data = Database::fetch_array($scores)) {
207
-				return array(
208
-					$data['qualification'],
209
-					$assignment['qualification']
210
-				);
211
-			} else {
212
-				return '';
213
-			}
214
-		} else {
215
-			$students = array();  // user list, needed to make sure we only
216
-			// take first attempts into account
217
-			$rescount = 0;
218
-			$sum = 0;
219
-			$bestResult = 0;
220
-			$weight = 0;
221
-			$sumResult = 0;
222
-			$myResult = 0;
223
-
224
-			while ($data = Database::fetch_array($scores)) {
225
-				if (!(array_key_exists($data['user_id'], $students))) {
226
-					if ($assignment['qualification'] != 0) {
227
-						$students[$data['user_id']] = $data['qualification'];
228
-						$rescount++;
229
-						$sum += $data['qualification'] / $assignment['qualification'];
230
-						$sumResult += $data['qualification'];
231
-
232
-						if ($data['qualification'] > $bestResult) {
233
-							$bestResult = $data['qualification'];
234
-						}
235
-						$weight = $assignment['qualification'];
236
-					}
237
-				}
238
-			}
239
-
240
-			if ($rescount == 0) {
241
-				return null;
242
-			} else {
243
-				switch ($type) {
244
-					case 'best':
245
-						return array($bestResult, $weight);
246
-						break;
247
-					case 'average':
248
-						return array($sumResult/$rescount, $weight);
249
-						break;
250
-					case 'ranking':
251
-						return AbstractLink::getCurrentUserRanking($stud_id, $students);
252
-						break;
253
-					default:
254
-						return array($sum, $rescount);
255
-						break;
256
-				}
257
-			}
258
-		}
259
-	}
260
-
261
-	/**
262
-	 * Lazy load function to get the database table of the student publications
263
-	 */
264
-	private function get_studpub_table()
265
-	{
266
-		return $this->studpub_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
267
-	}
268
-
269
-	/**
270
-	 * Lazy load function to get the database table of the item properties
271
-	 */
272
-	private function get_itemprop_table()
273
-	{
274
-		return $this->itemprop_table = Database :: get_course_table(TABLE_ITEM_PROPERTY);
275
-	}
276
-
277
-	public function needs_name_and_description()
278
-	{
279
-		return false;
280
-	}
281
-
282
-	public function get_name()
283
-	{
284
-		$this->get_exercise_data();
285
-		return (isset($this->exercise_data['title']) && !empty($this->exercise_data['title'])) ? $this->exercise_data['title'] : get_lang('Untitled');
286
-	}
287
-
288
-	public function get_description()
289
-	{
290
-		$this->get_exercise_data();
291
-		return isset($this->exercise_data['description']) ? $this->exercise_data['description'] : null;
292
-	}
293
-
294
-	public function get_test_id()
295
-	{
296
-		return 'DEBUG:ID';
297
-	}
298
-
299
-	public function get_link()
300
-	{
301
-		$session_id = api_get_session_id();
302
-		$url = api_get_path(WEB_PATH).'main/work/work.php?session_id='.$session_id.'&cidReq='.$this->get_course_code().'&id='.$this->exercise_data['id'].'&gradebook=view';
303
-		return $url;
304
-	}
305
-
306
-	private function get_exercise_data()
307
-	{
308
-		$tbl_name = $this->get_studpub_table();
309
-		$course_info = api_get_course_info($this->get_course_code());
310
-		if ($tbl_name=='') {
311
-			return false;
312
-		} elseif (!isset($this->exercise_data)) {
313
-			$sql = 'SELECT * FROM '.$this->get_studpub_table()."
184
+        if (!empty($stud_id)) {
185
+            $sql .= " AND user_id = $stud_id ";
186
+        }
187
+
188
+        $order = api_get_setting('student_publication_to_take_in_gradebook');
189
+
190
+        switch ($order) {
191
+            case 'last':
192
+                // latest attempt
193
+                $sql .= ' ORDER BY sent_date DESC';
194
+                break;
195
+            case 'first':
196
+            default:
197
+                // first attempt
198
+                $sql .= ' ORDER BY id';
199
+                break;
200
+        }
201
+
202
+        $scores = Database::query($sql);
203
+
204
+        // for 1 student
205
+        if (!empty($stud_id)) {
206
+            if ($data = Database::fetch_array($scores)) {
207
+                return array(
208
+                    $data['qualification'],
209
+                    $assignment['qualification']
210
+                );
211
+            } else {
212
+                return '';
213
+            }
214
+        } else {
215
+            $students = array();  // user list, needed to make sure we only
216
+            // take first attempts into account
217
+            $rescount = 0;
218
+            $sum = 0;
219
+            $bestResult = 0;
220
+            $weight = 0;
221
+            $sumResult = 0;
222
+            $myResult = 0;
223
+
224
+            while ($data = Database::fetch_array($scores)) {
225
+                if (!(array_key_exists($data['user_id'], $students))) {
226
+                    if ($assignment['qualification'] != 0) {
227
+                        $students[$data['user_id']] = $data['qualification'];
228
+                        $rescount++;
229
+                        $sum += $data['qualification'] / $assignment['qualification'];
230
+                        $sumResult += $data['qualification'];
231
+
232
+                        if ($data['qualification'] > $bestResult) {
233
+                            $bestResult = $data['qualification'];
234
+                        }
235
+                        $weight = $assignment['qualification'];
236
+                    }
237
+                }
238
+            }
239
+
240
+            if ($rescount == 0) {
241
+                return null;
242
+            } else {
243
+                switch ($type) {
244
+                    case 'best':
245
+                        return array($bestResult, $weight);
246
+                        break;
247
+                    case 'average':
248
+                        return array($sumResult/$rescount, $weight);
249
+                        break;
250
+                    case 'ranking':
251
+                        return AbstractLink::getCurrentUserRanking($stud_id, $students);
252
+                        break;
253
+                    default:
254
+                        return array($sum, $rescount);
255
+                        break;
256
+                }
257
+            }
258
+        }
259
+    }
260
+
261
+    /**
262
+     * Lazy load function to get the database table of the student publications
263
+     */
264
+    private function get_studpub_table()
265
+    {
266
+        return $this->studpub_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
267
+    }
268
+
269
+    /**
270
+     * Lazy load function to get the database table of the item properties
271
+     */
272
+    private function get_itemprop_table()
273
+    {
274
+        return $this->itemprop_table = Database :: get_course_table(TABLE_ITEM_PROPERTY);
275
+    }
276
+
277
+    public function needs_name_and_description()
278
+    {
279
+        return false;
280
+    }
281
+
282
+    public function get_name()
283
+    {
284
+        $this->get_exercise_data();
285
+        return (isset($this->exercise_data['title']) && !empty($this->exercise_data['title'])) ? $this->exercise_data['title'] : get_lang('Untitled');
286
+    }
287
+
288
+    public function get_description()
289
+    {
290
+        $this->get_exercise_data();
291
+        return isset($this->exercise_data['description']) ? $this->exercise_data['description'] : null;
292
+    }
293
+
294
+    public function get_test_id()
295
+    {
296
+        return 'DEBUG:ID';
297
+    }
298
+
299
+    public function get_link()
300
+    {
301
+        $session_id = api_get_session_id();
302
+        $url = api_get_path(WEB_PATH).'main/work/work.php?session_id='.$session_id.'&cidReq='.$this->get_course_code().'&id='.$this->exercise_data['id'].'&gradebook=view';
303
+        return $url;
304
+    }
305
+
306
+    private function get_exercise_data()
307
+    {
308
+        $tbl_name = $this->get_studpub_table();
309
+        $course_info = api_get_course_info($this->get_course_code());
310
+        if ($tbl_name=='') {
311
+            return false;
312
+        } elseif (!isset($this->exercise_data)) {
313
+            $sql = 'SELECT * FROM '.$this->get_studpub_table()."
314 314
 					WHERE
315 315
 					 	c_id ='".$course_info['real_id']."' AND
316 316
 					 	id = '".intval($this->get_ref_id())."' ";
317
-			$query = Database::query($sql);
318
-			$this->exercise_data = Database::fetch_array($query);
319
-		}
320
-		return $this->exercise_data;
321
-	}
322
-
323
-	public function needs_max()
324
-	{
325
-		return false;
326
-	}
327
-
328
-	public function needs_results()
329
-	{
330
-		return false;
331
-	}
332
-
333
-	public function is_valid_link()
334
-	{
335
-		$sql = 'SELECT count(id) FROM '.$this->get_studpub_table().'
317
+            $query = Database::query($sql);
318
+            $this->exercise_data = Database::fetch_array($query);
319
+        }
320
+        return $this->exercise_data;
321
+    }
322
+
323
+    public function needs_max()
324
+    {
325
+        return false;
326
+    }
327
+
328
+    public function needs_results()
329
+    {
330
+        return false;
331
+    }
332
+
333
+    public function is_valid_link()
334
+    {
335
+        $sql = 'SELECT count(id) FROM '.$this->get_studpub_table().'
336 336
     			WHERE c_id = "'.$this->course_id.'" AND id = '.intval($this->get_ref_id()).'';
337
-		$result = Database::query($sql);
338
-		$number = Database::fetch_row($result);
339
-		return ($number[0] != 0);
340
-	}
341
-
342
-	public function get_icon_name()
343
-	{
344
-		return 'studentpublication';
345
-	}
346
-
347
-	public function save_linked_data()
348
-	{
349
-		$weight = (float)$this->get_weight();
350
-		$ref_id = $this->get_ref_id();
351
-
352
-		if (!empty($ref_id)) {
353
-			//Cleans works
354
-			$sql = 'UPDATE '.$this->get_studpub_table().' SET weight= '.$weight.'
337
+        $result = Database::query($sql);
338
+        $number = Database::fetch_row($result);
339
+        return ($number[0] != 0);
340
+    }
341
+
342
+    public function get_icon_name()
343
+    {
344
+        return 'studentpublication';
345
+    }
346
+
347
+    public function save_linked_data()
348
+    {
349
+        $weight = (float)$this->get_weight();
350
+        $ref_id = $this->get_ref_id();
351
+
352
+        if (!empty($ref_id)) {
353
+            //Cleans works
354
+            $sql = 'UPDATE '.$this->get_studpub_table().' SET weight= '.$weight.'
355 355
                     WHERE c_id = '.$this->course_id.' AND id ='.$ref_id;
356
-			Database::query($sql);
357
-		}
358
-	}
359
-
360
-	public function delete_linked_data()
361
-	{
362
-		$ref_id = $this->get_ref_id();
363
-		if (!empty($ref_id)) {
364
-			//Cleans works
365
-			$sql = 'UPDATE '.$this->get_studpub_table().' SET weight=0
356
+            Database::query($sql);
357
+        }
358
+    }
359
+
360
+    public function delete_linked_data()
361
+    {
362
+        $ref_id = $this->get_ref_id();
363
+        if (!empty($ref_id)) {
364
+            //Cleans works
365
+            $sql = 'UPDATE '.$this->get_studpub_table().' SET weight=0
366 366
                     WHERE c_id = '.$this->course_id.' AND id ='.$ref_id;
367
-			Database::query($sql);
368
-		}
369
-	}
367
+            Database::query($sql);
368
+        }
369
+    }
370 370
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -84,9 +84,9 @@  discard block
 block discarded – undo
84 84
 
85 85
 		$result = Database::query($sql);
86 86
 
87
-		$cats=array();
88
-		while ($data=Database::fetch_array($result)) {
89
-			$cats[] = array ($data['id'], $data['url']);
87
+		$cats = array();
88
+		while ($data = Database::fetch_array($result)) {
89
+			$cats[] = array($data['id'], $data['url']);
90 90
 		}
91 91
 		return $cats;
92 92
 	}
@@ -127,9 +127,9 @@  discard block
 block discarded – undo
127 127
 			if (empty($work_name)) {
128 128
 				$work_name = basename($data['url']);
129 129
 			}
130
-			$cats[] = array ($data['id'], $work_name);
130
+			$cats[] = array($data['id'], $work_name);
131 131
 		}
132
-		$cats=isset($cats) ? $cats : array();
132
+		$cats = isset($cats) ? $cats : array();
133 133
 		return $cats;
134 134
 	}
135 135
 
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
     				c_id = '.$this->course_id.' AND
179 179
     				active = 1 AND
180 180
     				parent_id = "'.$parentId.'" AND
181
-    				session_id = '.api_get_session_id() .' AND
181
+    				session_id = '.api_get_session_id().' AND
182 182
     				qualificator_id <> 0
183 183
 				';
184 184
 		if (!empty($stud_id)) {
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
 				return '';
213 213
 			}
214 214
 		} else {
215
-			$students = array();  // user list, needed to make sure we only
215
+			$students = array(); // user list, needed to make sure we only
216 216
 			// take first attempts into account
217 217
 			$rescount = 0;
218 218
 			$sum = 0;
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
 						return array($bestResult, $weight);
246 246
 						break;
247 247
 					case 'average':
248
-						return array($sumResult/$rescount, $weight);
248
+						return array($sumResult / $rescount, $weight);
249 249
 						break;
250 250
 					case 'ranking':
251 251
 						return AbstractLink::getCurrentUserRanking($stud_id, $students);
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
 	{
308 308
 		$tbl_name = $this->get_studpub_table();
309 309
 		$course_info = api_get_course_info($this->get_course_code());
310
-		if ($tbl_name=='') {
310
+		if ($tbl_name == '') {
311 311
 			return false;
312 312
 		} elseif (!isset($this->exercise_data)) {
313 313
 			$sql = 'SELECT * FROM '.$this->get_studpub_table()."
@@ -346,7 +346,7 @@  discard block
 block discarded – undo
346 346
 
347 347
 	public function save_linked_data()
348 348
 	{
349
-		$weight = (float)$this->get_weight();
349
+		$weight = (float) $this->get_weight();
350 350
 		$ref_id = $this->get_ref_id();
351 351
 
352 352
 		if (!empty($ref_id)) {
Please login to merge, or discard this patch.
main/gradebook/lib/be/evaluation.class.php 4 patches
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -223,36 +223,36 @@  discard block
 block discarded – undo
223 223
 		$paramcount = 0;
224 224
 
225 225
 		if (isset ($id)) {
226
-			$sql.= ' WHERE id = '.intval($id);
227
-			$paramcount ++;
226
+			$sql .= ' WHERE id = '.intval($id);
227
+			$paramcount++;
228 228
 		}
229 229
 
230 230
 		if (isset ($user_id)) {
231 231
 			if ($paramcount != 0) $sql .= ' AND';
232 232
 			else $sql .= ' WHERE';
233 233
 			$sql .= ' user_id = '.intval($user_id);
234
-			$paramcount ++;
234
+			$paramcount++;
235 235
 		}
236 236
 
237 237
 		if (isset ($course_code) && $course_code <> '-1') {
238 238
 			if ($paramcount != 0) $sql .= ' AND';
239 239
 			else $sql .= ' WHERE';
240 240
 			$sql .= " course_code = '".Database::escape_string($course_code)."'";
241
-			$paramcount ++;
241
+			$paramcount++;
242 242
 		}
243 243
 
244 244
 		if (isset ($category_id)) {
245 245
 			if ($paramcount != 0) $sql .= ' AND';
246 246
 			else $sql .= ' WHERE';
247 247
 			$sql .= ' category_id = '.intval($category_id);
248
-			$paramcount ++;
248
+			$paramcount++;
249 249
 		}
250 250
 
251 251
 		if (isset ($visible)) {
252 252
 			if ($paramcount != 0) $sql .= ' AND';
253 253
 			else $sql .= ' WHERE';
254 254
 			$sql .= ' visible = '.intval($visible);
255
-			$paramcount ++;
255
+			$paramcount++;
256 256
 		}
257 257
 
258 258
 		if (isset ($locked)) {
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
 		$alleval = array();
279 279
 		if (Database::num_rows($result)) {
280 280
 			while ($data = Database::fetch_array($result)) {
281
-				$eval= new Evaluation();
281
+				$eval = new Evaluation();
282 282
 				$eval->set_id($data['id']);
283 283
 				$eval->set_name($data['name']);
284 284
 				$eval->set_description($data['description']);
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
 			$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
364 364
 			$tbl_grade_linkeval_log = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINKEVAL_LOG);
365 365
 			$eval = new Evaluation();
366
-			$dateobject = $eval->load($idevaluation,null,null,null,null);
366
+			$dateobject = $eval->load($idevaluation, null, null, null, null);
367 367
 			$arreval = get_object_vars($dateobject[0]);
368 368
 			if (!empty($arreval['id'])) {
369 369
 				$sql = 'SELECT weight from '.$tbl_grade_evaluations.'
@@ -397,7 +397,7 @@  discard block
 block discarded – undo
397 397
 			.', description = ';
398 398
 		if (isset($this->description)) {
399 399
 			$sql .= "'".Database::escape_string($this->get_description())."'";
400
-		}else {
400
+		} else {
401 401
 			$sql .= 'null';
402 402
 		}
403 403
 		$sql .= ', user_id = '.intval($this->get_user_id())
@@ -468,17 +468,17 @@  discard block
 block discarded – undo
468 468
 				$sql .= ' AND user_id = '.api_get_user_id();
469 469
 			}
470 470
 
471
-		}else {
471
+		} else {
472 472
 			$sql .= ' AND user_id = '.api_get_user_id();
473 473
 		}
474 474
 
475 475
 		if (!isset ($parent)) {
476
-			$sql.= ' AND category_id is null';
476
+			$sql .= ' AND category_id is null';
477 477
 		} else {
478
-			$sql.= ' AND category_id = '.intval($parent);
478
+			$sql .= ' AND category_id = '.intval($parent);
479 479
 		}
480 480
 		$result = Database::query($sql);
481
-		$number=Database::fetch_row($result);
481
+		$number = Database::fetch_row($result);
482 482
 
483 483
 		return $number[0] != 0;
484 484
 	}
@@ -494,7 +494,7 @@  discard block
 block discarded – undo
494 494
 				FROM '.$tbl_grade_results.'
495 495
 				WHERE evaluation_id = '.intval($this->id);
496 496
 		$result = Database::query($sql);
497
-		$number=Database::fetch_row($result);
497
+		$number = Database::fetch_row($result);
498 498
 
499 499
 		return ($number[0] != 0);
500 500
 	}
@@ -544,7 +544,7 @@  discard block
 block discarded – undo
544 544
             $results = isset($data[$key]) ? $data[$key] : null;
545 545
 
546 546
             if ($useSession == false) {
547
-                $results  = null;
547
+                $results = null;
548 548
             }
549 549
 			if (empty($results)) {
550 550
 				$results = Result::load(null, $stud_id, $this->id);
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
             $data = Session::read('calc_score');
571 571
             $allResults = isset($data[$key]) ? $data[$key] : null;
572 572
             if ($useSession == false) {
573
-                $allResults  = null;
573
+                $allResults = null;
574 574
             }
575 575
 			if (empty($allResults)) {
576 576
 				$allResults = Result::load(null, null, $this->id);
@@ -602,7 +602,7 @@  discard block
 block discarded – undo
602 602
 					return array($bestResult, $weight);
603 603
 					break;
604 604
 				case 'average':
605
-					return array($sumResult/$count, $weight);
605
+					return array($sumResult / $count, $weight);
606 606
 					break;
607 607
 				case 'ranking':
608 608
                     $students = array();
@@ -640,17 +640,17 @@  discard block
 block discarded – undo
640 640
 		$targets[] = $root;
641 641
 
642 642
 		if (isset($this->course_code) && !empty($this->course_code)) {
643
-			$crscats = Category::load(null,null,$this->course_code,0);
643
+			$crscats = Category::load(null, null, $this->course_code, 0);
644 644
 			foreach ($crscats as $cat) {
645
-				$targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
646
-				$targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
645
+				$targets[] = array($cat->get_id(), $cat->get_name(), $level + 1);
646
+				$targets = $this->add_target_subcategories($targets, $level + 1, $cat->get_id());
647 647
 			}
648 648
 		}
649 649
 
650
-		$indcats = Category::load(null,$user,0,0);
650
+		$indcats = Category::load(null, $user, 0, 0);
651 651
 		foreach ($indcats as $cat) {
652
-			$targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
653
-			$targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
652
+			$targets[] = array($cat->get_id(), $cat->get_name(), $level + 1);
653
+			$targets = $this->add_target_subcategories($targets, $level + 1, $cat->get_id());
654 654
 		}
655 655
 
656 656
 		return $targets;
@@ -661,10 +661,10 @@  discard block
 block discarded – undo
661 661
 	 */
662 662
 	private function add_target_subcategories($targets, $level, $catid)
663 663
 	{
664
-		$subcats = Category::load(null,null,null,$catid);
664
+		$subcats = Category::load(null, null, null, $catid);
665 665
 		foreach ($subcats as $cat) {
666
-			$targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
667
-			$targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
666
+			$targets[] = array($cat->get_id(), $cat->get_name(), $level + 1);
667
+			$targets = $this->add_target_subcategories($targets, $level + 1, $cat->get_id());
668 668
 		}
669 669
 		return $targets;
670 670
 	}
@@ -743,7 +743,7 @@  discard block
 block discarded – undo
743 743
 	 * @return array evaluation objects matching the search criterium
744 744
 	 * @todo can be written more efficiently using a new (but very complex) sql query
745 745
 	 */
746
-	public function find_evaluations($name_mask,$selectcat)
746
+	public function find_evaluations($name_mask, $selectcat)
747 747
 	{
748 748
 		$rootcat = Category::load($selectcat);
749 749
 		$evals = $rootcat[0]->get_evaluations((api_is_allowed_to_create_course() ? null : api_get_user_id()), true);
Please login to merge, or discard this patch.
Braces   +27 added lines, -12 removed lines patch added patch discarded remove patch
@@ -228,36 +228,51 @@  discard block
 block discarded – undo
228 228
 		}
229 229
 
230 230
 		if (isset ($user_id)) {
231
-			if ($paramcount != 0) $sql .= ' AND';
232
-			else $sql .= ' WHERE';
231
+			if ($paramcount != 0) {
232
+			    $sql .= ' AND';
233
+			} else {
234
+			    $sql .= ' WHERE';
235
+			}
233 236
 			$sql .= ' user_id = '.intval($user_id);
234 237
 			$paramcount ++;
235 238
 		}
236 239
 
237 240
 		if (isset ($course_code) && $course_code <> '-1') {
238
-			if ($paramcount != 0) $sql .= ' AND';
239
-			else $sql .= ' WHERE';
241
+			if ($paramcount != 0) {
242
+			    $sql .= ' AND';
243
+			} else {
244
+			    $sql .= ' WHERE';
245
+			}
240 246
 			$sql .= " course_code = '".Database::escape_string($course_code)."'";
241 247
 			$paramcount ++;
242 248
 		}
243 249
 
244 250
 		if (isset ($category_id)) {
245
-			if ($paramcount != 0) $sql .= ' AND';
246
-			else $sql .= ' WHERE';
251
+			if ($paramcount != 0) {
252
+			    $sql .= ' AND';
253
+			} else {
254
+			    $sql .= ' WHERE';
255
+			}
247 256
 			$sql .= ' category_id = '.intval($category_id);
248 257
 			$paramcount ++;
249 258
 		}
250 259
 
251 260
 		if (isset ($visible)) {
252
-			if ($paramcount != 0) $sql .= ' AND';
253
-			else $sql .= ' WHERE';
261
+			if ($paramcount != 0) {
262
+			    $sql .= ' AND';
263
+			} else {
264
+			    $sql .= ' WHERE';
265
+			}
254 266
 			$sql .= ' visible = '.intval($visible);
255 267
 			$paramcount ++;
256 268
 		}
257 269
 
258 270
 		if (isset ($locked)) {
259
-			if ($paramcount != 0) $sql .= ' AND';
260
-			else $sql .= ' WHERE';
271
+			if ($paramcount != 0) {
272
+			    $sql .= ' AND';
273
+			} else {
274
+			    $sql .= ' WHERE';
275
+			}
261 276
 			$sql .= ' locked = '.intval($locked);
262 277
 		}
263 278
 
@@ -397,7 +412,7 @@  discard block
 block discarded – undo
397 412
 			.', description = ';
398 413
 		if (isset($this->description)) {
399 414
 			$sql .= "'".Database::escape_string($this->get_description())."'";
400
-		}else {
415
+		} else {
401 416
 			$sql .= 'null';
402 417
 		}
403 418
 		$sql .= ', user_id = '.intval($this->get_user_id())
@@ -468,7 +483,7 @@  discard block
 block discarded – undo
468 483
 				$sql .= ' AND user_id = '.api_get_user_id();
469 484
 			}
470 485
 
471
-		}else {
486
+		} else {
472 487
 			$sql .= ' AND user_id = '.api_get_user_id();
473 488
 		}
474 489
 
Please login to merge, or discard this patch.
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/gradebook/lib/GradebookUtils.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -249,7 +249,7 @@
 block discarded – undo
249 249
                     }
250 250
                 }
251 251
 
252
-               $modify_icons .= '<a href="gradebook_edit_all.php?selectcat=' .$cat->get_id() . '&cidReq=' . $cat->get_course_code() . '&id_session='.$cat->get_session_id().'">' .
252
+                $modify_icons .= '<a href="gradebook_edit_all.php?selectcat=' .$cat->get_id() . '&cidReq=' . $cat->get_course_code() . '&id_session='.$cat->get_session_id().'">' .
253 253
                     Display::return_icon(
254 254
                         'percentage.png',
255 255
                         get_lang('EditAllWeights'),
Please login to merge, or discard this patch.
Spacing   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -77,9 +77,9 @@  discard block
 block discarded – undo
77 77
         $course_code = Database::escape_string($course_code);
78 78
         if (!empty($link_id)) {
79 79
             $link_id = intval($link_id);
80
-            $sql = 'UPDATE ' . Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK) . '
81
-                    SET weight = ' . "'" . Database::escape_string((float) $weight) . "'" . '
82
-                    WHERE course_code = "' . $course_code . '" AND id = ' . $link_id;
80
+            $sql = 'UPDATE '.Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK).'
81
+                    SET weight = ' . "'".Database::escape_string((float) $weight)."'".'
82
+                    WHERE course_code = "' . $course_code.'" AND id = '.$link_id;
83 83
             Database::query($sql);
84 84
         }
85 85
 
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 
100 100
         // TODO find the corresponding category (the first one for this course, ordered by ID)
101 101
         $l = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
102
-        $sql = "DELETE FROM $l WHERE id = ".(int)$link_id;
102
+        $sql = "DELETE FROM $l WHERE id = ".(int) $link_id;
103 103
         Database::query($sql);
104 104
 
105 105
         return true;
@@ -195,8 +195,8 @@  discard block
 block discarded – undo
195 195
             $visibility_icon = ($cat->is_visible() == 0) ? 'invisible' : 'visible';
196 196
             $visibility_command = ($cat->is_visible() == 0) ? 'set_visible' : 'set_invisible';
197 197
 
198
-            $modify_icons .= '<a class="view_children" data-cat-id="' . $cat->get_id() . '" href="javascript:void(0);">' .
199
-                Display::return_icon('view_more_stats.gif', get_lang('Show'), '', ICON_SIZE_SMALL) . '</a>';
198
+            $modify_icons .= '<a class="view_children" data-cat-id="'.$cat->get_id().'" href="javascript:void(0);">'.
199
+                Display::return_icon('view_more_stats.gif', get_lang('Show'), '', ICON_SIZE_SMALL).'</a>';
200 200
 
201 201
             if (!api_is_allowed_to_edit(null, true)) {
202 202
                 $modify_icons .= Display::url(
@@ -206,9 +206,9 @@  discard block
 block discarded – undo
206 206
                         '',
207 207
                         ICON_SIZE_SMALL
208 208
                     ),
209
-                    'personal_stats.php?' . http_build_query([
209
+                    'personal_stats.php?'.http_build_query([
210 210
                         'selectcat' => $cat->get_id()
211
-                    ]) . '&' . api_get_cidreq(),
211
+                    ]).'&'.api_get_cidreq(),
212 212
                     [
213 213
                         'class' => 'ajax',
214 214
                         'data-title' => get_lang('FlatView')
@@ -222,16 +222,16 @@  discard block
 block discarded – undo
222 222
                 if (api_get_setting('gradebook_locking_enabled') == 'true') {
223 223
                     if ($cat->is_locked()) {
224 224
                         if (api_is_platform_admin()) {
225
-                            $modify_icons .= '&nbsp;<a onclick="javascript:if (!confirm(\'' . addslashes(get_lang('ConfirmToUnlockElement')) . '\')) return false;" href="' . api_get_self() . '?' . api_get_cidreq() . '&category_id=' . $cat->get_id() . '&action=unlock">' .
226
-                                Display::return_icon('lock.png', get_lang('UnLockEvaluation'), '', ICON_SIZE_SMALL) . '</a>';
225
+                            $modify_icons .= '&nbsp;<a onclick="javascript:if (!confirm(\''.addslashes(get_lang('ConfirmToUnlockElement')).'\')) return false;" href="'.api_get_self().'?'.api_get_cidreq().'&category_id='.$cat->get_id().'&action=unlock">'.
226
+                                Display::return_icon('lock.png', get_lang('UnLockEvaluation'), '', ICON_SIZE_SMALL).'</a>';
227 227
                         } else {
228
-                            $modify_icons .= '&nbsp;<a href="#">' . Display::return_icon('lock_na.png', get_lang('GradebookLockedAlert'), '', ICON_SIZE_SMALL) . '</a>';
228
+                            $modify_icons .= '&nbsp;<a href="#">'.Display::return_icon('lock_na.png', get_lang('GradebookLockedAlert'), '', ICON_SIZE_SMALL).'</a>';
229 229
                         }
230
-                        $modify_icons .= '&nbsp;<a href="gradebook_flatview.php?export_pdf=category&selectcat=' . $cat->get_id() . '" >' . Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_SMALL) . '</a>';
230
+                        $modify_icons .= '&nbsp;<a href="gradebook_flatview.php?export_pdf=category&selectcat='.$cat->get_id().'" >'.Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_SMALL).'</a>';
231 231
                     } else {
232
-                        $modify_icons .= '&nbsp;<a onclick="javascript:if (!confirm(\'' . addslashes(get_lang('ConfirmToLockElement')) . '\')) return false;" href="' . api_get_self() . '?' . api_get_cidreq() . '&category_id=' . $cat->get_id() . '&action=lock">' .
233
-                            Display::return_icon('unlock.png', get_lang('LockEvaluation'), '', ICON_SIZE_SMALL) . '</a>';
234
-                        $modify_icons .= '&nbsp;<a href="#" >' . Display::return_icon('pdf_na.png', get_lang('ExportToPDF'), '', ICON_SIZE_SMALL) . '</a>';
232
+                        $modify_icons .= '&nbsp;<a onclick="javascript:if (!confirm(\''.addslashes(get_lang('ConfirmToLockElement')).'\')) return false;" href="'.api_get_self().'?'.api_get_cidreq().'&category_id='.$cat->get_id().'&action=lock">'.
233
+                            Display::return_icon('unlock.png', get_lang('LockEvaluation'), '', ICON_SIZE_SMALL).'</a>';
234
+                        $modify_icons .= '&nbsp;<a href="#" >'.Display::return_icon('pdf_na.png', get_lang('ExportToPDF'), '', ICON_SIZE_SMALL).'</a>';
235 235
                     }
236 236
                 }
237 237
 
@@ -239,44 +239,44 @@  discard block
 block discarded – undo
239 239
                     if ($cat->is_locked() && !api_is_platform_admin()) {
240 240
                         $modify_icons .= Display::return_icon('edit_na.png', get_lang('Modify'), '', ICON_SIZE_SMALL);
241 241
                     } else {
242
-                        $modify_icons .= '<a href="gradebook_edit_cat.php?' .'editcat=' . $cat->get_id() . '&cidReq=' .$cat->get_course_code() . '&id_session='.$cat->get_session_id().'">' .
242
+                        $modify_icons .= '<a href="gradebook_edit_cat.php?'.'editcat='.$cat->get_id().'&cidReq='.$cat->get_course_code().'&id_session='.$cat->get_session_id().'">'.
243 243
                             Display::return_icon(
244 244
                                 'edit.png',
245 245
                                 get_lang('Modify'),
246 246
                                 '',
247 247
                                 ICON_SIZE_SMALL
248
-                            ) . '</a>';
248
+                            ).'</a>';
249 249
                     }
250 250
                 }
251 251
 
252
-               $modify_icons .= '<a href="gradebook_edit_all.php?selectcat=' .$cat->get_id() . '&cidReq=' . $cat->get_course_code() . '&id_session='.$cat->get_session_id().'">' .
252
+               $modify_icons .= '<a href="gradebook_edit_all.php?selectcat='.$cat->get_id().'&cidReq='.$cat->get_course_code().'&id_session='.$cat->get_session_id().'">'.
253 253
                     Display::return_icon(
254 254
                         'percentage.png',
255 255
                         get_lang('EditAllWeights'),
256 256
                         '',
257 257
                         ICON_SIZE_SMALL
258
-                    ) . '</a>';
258
+                    ).'</a>';
259 259
 
260
-                $modify_icons .= '<a href="gradebook_flatview.php?selectcat=' .$cat->get_id() . '&cidReq=' . $cat->get_course_code() . '&id_session='.$cat->get_session_id(). '">' .
260
+                $modify_icons .= '<a href="gradebook_flatview.php?selectcat='.$cat->get_id().'&cidReq='.$cat->get_course_code().'&id_session='.$cat->get_session_id().'">'.
261 261
                     Display::return_icon(
262 262
                         'stats.png',
263 263
                         get_lang('FlatView'),
264 264
                         '',
265 265
                         ICON_SIZE_SMALL
266
-                    ) . '</a>';
267
-                $modify_icons .= '&nbsp;<a href="' . api_get_self() .'?visiblecat=' . $cat->get_id() . '&' .$visibility_command . '=&selectcat=' . $selectcat .'&cidReq=' . $cat->get_course_code() . '&id_session='.$cat->get_session_id(). '">' .
266
+                    ).'</a>';
267
+                $modify_icons .= '&nbsp;<a href="'.api_get_self().'?visiblecat='.$cat->get_id().'&'.$visibility_command.'=&selectcat='.$selectcat.'&cidReq='.$cat->get_course_code().'&id_session='.$cat->get_session_id().'">'.
268 268
                     Display::return_icon(
269
-                        $visibility_icon . '.png',
269
+                        $visibility_icon.'.png',
270 270
                         get_lang('Visible'),
271 271
                         '',
272 272
                         ICON_SIZE_SMALL
273
-                    ) . '</a>';
273
+                    ).'</a>';
274 274
 
275 275
                 if ($cat->is_locked() && !api_is_platform_admin()) {
276 276
                     $modify_icons .= Display::return_icon('delete_na.png', get_lang('DeleteAll'), '', ICON_SIZE_SMALL);
277 277
                 } else {
278
-                    $modify_icons .= '&nbsp;<a href="' . api_get_self() . '?deletecat=' . $cat->get_id() . '&selectcat=' . $selectcat . '&cidReq=' . $cat->get_course_code() . '&id_session='.$cat->get_session_id(). '" onclick="return confirmation();">' .
279
-                        Display::return_icon('delete.png', get_lang('DeleteAll'), '', ICON_SIZE_SMALL) . '</a>';
278
+                    $modify_icons .= '&nbsp;<a href="'.api_get_self().'?deletecat='.$cat->get_id().'&selectcat='.$selectcat.'&cidReq='.$cat->get_course_code().'&id_session='.$cat->get_session_id().'" onclick="return confirmation();">'.
279
+                        Display::return_icon('delete.png', get_lang('DeleteAll'), '', ICON_SIZE_SMALL).'</a>';
280 280
                 }
281 281
             }
282 282
 
@@ -303,21 +303,21 @@  discard block
 block discarded – undo
303 303
             if ($is_locked && !api_is_platform_admin()) {
304 304
                 $modify_icons = Display::return_icon('edit_na.png', get_lang('Modify'), '', ICON_SIZE_SMALL);
305 305
             } else {
306
-                $modify_icons = '<a href="gradebook_edit_eval.php?editeval=' . $eval->get_id() . '&cidReq=' . $eval->get_course_code() . '&id_session='.$eval->getSessionId(). '">' .
307
-                    Display::return_icon('edit.png', get_lang('Modify'), '', ICON_SIZE_SMALL) . '</a>';
306
+                $modify_icons = '<a href="gradebook_edit_eval.php?editeval='.$eval->get_id().'&cidReq='.$eval->get_course_code().'&id_session='.$eval->getSessionId().'">'.
307
+                    Display::return_icon('edit.png', get_lang('Modify'), '', ICON_SIZE_SMALL).'</a>';
308 308
             }
309 309
 
310
-            $modify_icons .= '&nbsp;<a href="' . api_get_self() . '?visibleeval=' . $eval->get_id() . '&' . $visibility_command . '=&selectcat=' . $selectcat . '&id_session='.$eval->getSessionId(). ' ">' .
311
-                Display::return_icon($visibility_icon . '.png', get_lang('Visible'), '', ICON_SIZE_SMALL) . '</a>';
310
+            $modify_icons .= '&nbsp;<a href="'.api_get_self().'?visibleeval='.$eval->get_id().'&'.$visibility_command.'=&selectcat='.$selectcat.'&id_session='.$eval->getSessionId().' ">'.
311
+                Display::return_icon($visibility_icon.'.png', get_lang('Visible'), '', ICON_SIZE_SMALL).'</a>';
312 312
             if (api_is_allowed_to_edit(null, true)) {
313
-                $modify_icons .= '&nbsp;<a href="gradebook_showlog_eval.php?visiblelog=' . $eval->get_id() . '&selectcat=' . $selectcat . ' &cidReq=' . $eval->get_course_code() . '&id_session='.$eval->getSessionId(). '">' .
314
-                    Display::return_icon('history.png', get_lang('GradebookQualifyLog'), '', ICON_SIZE_SMALL) . '</a>';
313
+                $modify_icons .= '&nbsp;<a href="gradebook_showlog_eval.php?visiblelog='.$eval->get_id().'&selectcat='.$selectcat.' &cidReq='.$eval->get_course_code().'&id_session='.$eval->getSessionId().'">'.
314
+                    Display::return_icon('history.png', get_lang('GradebookQualifyLog'), '', ICON_SIZE_SMALL).'</a>';
315 315
             }
316 316
 
317 317
             if ($is_locked && !api_is_platform_admin()) {
318
-                $modify_icons .= '&nbsp;' . Display::return_icon('delete_na.png', get_lang('Delete'), '', ICON_SIZE_SMALL);
318
+                $modify_icons .= '&nbsp;'.Display::return_icon('delete_na.png', get_lang('Delete'), '', ICON_SIZE_SMALL);
319 319
             } else {
320
-                $modify_icons .= '&nbsp;<a href="' . api_get_self() . '?deleteeval=' . $eval->get_id() . '&selectcat=' . $selectcat . ' &cidReq=' . $eval->get_course_code() . '&id_session='.$eval->getSessionId(). '" onclick="return confirmation();">' . Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL) . '</a>';
320
+                $modify_icons .= '&nbsp;<a href="'.api_get_self().'?deleteeval='.$eval->get_id().'&selectcat='.$selectcat.' &cidReq='.$eval->get_course_code().'&id_session='.$eval->getSessionId().'" onclick="return confirmation();">'.Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a>';
321 321
             }
322 322
             return $modify_icons;
323 323
         }
@@ -347,21 +347,21 @@  discard block
 block discarded – undo
347 347
             if ($is_locked && !api_is_platform_admin()) {
348 348
                 $modify_icons = Display::return_icon('edit_na.png', get_lang('Modify'), '', ICON_SIZE_SMALL);
349 349
             } else {
350
-                $modify_icons = '<a href="gradebook_edit_link.php?editlink=' . $link->get_id() . '&cidReq=' . $link->get_course_code() . '&id_session='.$link->get_session_id().'">' .
351
-                    Display::return_icon('edit.png', get_lang('Modify'), '', ICON_SIZE_SMALL) . '</a>';
350
+                $modify_icons = '<a href="gradebook_edit_link.php?editlink='.$link->get_id().'&cidReq='.$link->get_course_code().'&id_session='.$link->get_session_id().'">'.
351
+                    Display::return_icon('edit.png', get_lang('Modify'), '', ICON_SIZE_SMALL).'</a>';
352 352
             }
353
-            $modify_icons .= '&nbsp;<a href="' . api_get_self() . '?visiblelink=' . $link->get_id() . '&' . $visibility_command . '=&selectcat=' . $selectcat . '&id_session='.$link->get_session_id(). ' ">' .
354
-                Display::return_icon($visibility_icon . '.png', get_lang('Visible'), '', ICON_SIZE_SMALL) . '</a>';
355
-            $modify_icons .= '&nbsp;<a href="gradebook_showlog_link.php?visiblelink=' . $link->get_id() . '&selectcat=' . $selectcat . '&cidReq=' . $link->get_course_code() . '&id_session='.$link->get_session_id(). '">' .
356
-                Display::return_icon('history.png', get_lang('GradebookQualifyLog'), '', ICON_SIZE_SMALL) . '</a>';
353
+            $modify_icons .= '&nbsp;<a href="'.api_get_self().'?visiblelink='.$link->get_id().'&'.$visibility_command.'=&selectcat='.$selectcat.'&id_session='.$link->get_session_id().' ">'.
354
+                Display::return_icon($visibility_icon.'.png', get_lang('Visible'), '', ICON_SIZE_SMALL).'</a>';
355
+            $modify_icons .= '&nbsp;<a href="gradebook_showlog_link.php?visiblelink='.$link->get_id().'&selectcat='.$selectcat.'&cidReq='.$link->get_course_code().'&id_session='.$link->get_session_id().'">'.
356
+                Display::return_icon('history.png', get_lang('GradebookQualifyLog'), '', ICON_SIZE_SMALL).'</a>';
357 357
 
358 358
             //If a work is added in a gradebook you can only delete the link in the work tool
359 359
 
360 360
             if ($is_locked && !api_is_platform_admin()) {
361
-                $modify_icons .= '&nbsp;' . Display::return_icon('delete_na.png', get_lang('Delete'), '', ICON_SIZE_SMALL);
361
+                $modify_icons .= '&nbsp;'.Display::return_icon('delete_na.png', get_lang('Delete'), '', ICON_SIZE_SMALL);
362 362
             } else {
363
-                $modify_icons .= '&nbsp;<a href="' . api_get_self() . '?deletelink=' . $link->get_id() . '&selectcat=' . $selectcat . ' &cidReq=' . $link->get_course_code() . '&id_session='.$link->get_session_id(). '" onclick="return confirmation();">' .
364
-                    Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL) . '</a>';
363
+                $modify_icons .= '&nbsp;<a href="'.api_get_self().'?deletelink='.$link->get_id().'&selectcat='.$selectcat.' &cidReq='.$link->get_course_code().'&id_session='.$link->get_session_id().'" onclick="return confirmation();">'.
364
+                    Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a>';
365 365
             }
366 366
             return $modify_icons;
367 367
         }
@@ -382,8 +382,8 @@  discard block
 block discarded – undo
382 382
         $sql = "SELECT * FROM $table l
383 383
                 WHERE
384 384
                     course_code = '$course_code' AND
385
-                    type = ".(int)$resource_type . " AND
386
-                    ref_id = " . (int)$resource_id;
385
+                    type = ".(int) $resource_type." AND
386
+                    ref_id = " . (int) $resource_id;
387 387
         $res = Database::query($sql);
388 388
 
389 389
         if (Database::num_rows($res) < 1) {
@@ -405,7 +405,7 @@  discard block
 block discarded – undo
405 405
         }
406 406
         // TODO find the corresponding category (the first one for this course, ordered by ID)
407 407
         $l = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
408
-        $sql = "SELECT * FROM $l WHERE id = " . (int) $link_id;
408
+        $sql = "SELECT * FROM $l WHERE id = ".(int) $link_id;
409 409
         $res = Database::query($sql);
410 410
         $row = array();
411 411
         if (Database::num_rows($res) > 0) {
@@ -423,10 +423,10 @@  discard block
 block discarded – undo
423 423
     {
424 424
         $course_table = Database::get_main_table(TABLE_MAIN_COURSE);
425 425
         $tbl_grade_links = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
426
-        $sql = 'SELECT c.id FROM ' . $course_table . ' c
427
-                INNER JOIN ' . $tbl_grade_links . ' l
426
+        $sql = 'SELECT c.id FROM '.$course_table.' c
427
+                INNER JOIN ' . $tbl_grade_links.' l
428 428
                 ON c.code = l.course_code
429
-                WHERE l.id=' . intval($id_link) . ' OR l.category_id=' . intval($id_link);
429
+                WHERE l.id=' . intval($id_link).' OR l.category_id='.intval($id_link);
430 430
         $res = Database::query($sql);
431 431
         $array = Database::fetch_array($res, 'ASSOC');
432 432
         return $array['id'];
@@ -535,7 +535,7 @@  discard block
 block discarded – undo
535 535
     {
536 536
         $result = Result :: load($resid);
537 537
         if ($importscore > $eval_max) {
538
-            header('Location: gradebook_view_result.php?selecteval=' . Security::remove_XSS($_GET['selecteval']) . '&overwritemax=');
538
+            header('Location: gradebook_view_result.php?selecteval='.Security::remove_XSS($_GET['selecteval']).'&overwritemax=');
539 539
             exit;
540 540
         }
541 541
         $result[0]->set_score($importscore);
@@ -576,8 +576,8 @@  discard block
 block discarded – undo
576 576
     {
577 577
         $table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
578 578
         $sql = 'SELECT COUNT(*) as count
579
-                FROM ' . $table . ' gc
580
-                WHERE gc.cat_id="' . intval($cat_id) . '" AND user_id="' . intval($user_id) . '" ';
579
+                FROM ' . $table.' gc
580
+                WHERE gc.cat_id="' . intval($cat_id).'" AND user_id="'.intval($user_id).'" ';
581 581
         $rs_exist = Database::query($sql);
582 582
         $row = Database::fetch_array($rs_exist);
583 583
         if ($row['count'] == 0) {
@@ -600,8 +600,8 @@  discard block
 block discarded – undo
600 600
     public static function get_certificate_by_user_id($cat_id, $user_id)
601 601
     {
602 602
         $table_certificate = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
603
-        $sql = 'SELECT * FROM ' . $table_certificate . '
604
-                WHERE cat_id="' . intval($cat_id) . '" AND user_id="' . intval($user_id) . '"';
603
+        $sql = 'SELECT * FROM '.$table_certificate.'
604
+                WHERE cat_id="' . intval($cat_id).'" AND user_id="'.intval($user_id).'"';
605 605
 
606 606
         $result = Database::query($sql);
607 607
         $row = Database::fetch_array($result, 'ASSOC');
@@ -620,18 +620,18 @@  discard block
 block discarded – undo
620 620
         $table_certificate = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
621 621
         $table_user = Database::get_main_table(TABLE_MAIN_USER);
622 622
         $sql = 'SELECT DISTINCT u.user_id, u.lastname, u.firstname, u.username
623
-                FROM ' . $table_user . ' u
624
-                INNER JOIN ' . $table_certificate . ' gc
623
+                FROM ' . $table_user.' u
624
+                INNER JOIN ' . $table_certificate.' gc
625 625
                 ON u.user_id=gc.user_id ';
626 626
         if (!is_null($cat_id) && $cat_id > 0) {
627
-            $sql.=' WHERE cat_id=' . intval($cat_id);
627
+            $sql .= ' WHERE cat_id='.intval($cat_id);
628 628
         }
629 629
         if (!empty($userList)) {
630 630
             $userList = array_map('intval', $userList);
631 631
             $userListCondition = implode("','", $userList);
632 632
             $sql .= " AND u.user_id IN ('$userListCondition')";
633 633
         }
634
-        $sql.=' ORDER BY u.firstname';
634
+        $sql .= ' ORDER BY u.firstname';
635 635
         $rs = Database::query($sql);
636 636
 
637 637
         $list_users = array();
@@ -652,10 +652,10 @@  discard block
 block discarded – undo
652 652
     {
653 653
         $table_certificate = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
654 654
         $sql = 'SELECT gc.score_certificate, gc.created_at, gc.path_certificate, gc.cat_id, gc.user_id, gc.id
655
-                FROM  ' . $table_certificate . ' gc
656
-                WHERE gc.user_id="' . intval($user_id) . '" ';
655
+                FROM  ' . $table_certificate.' gc
656
+                WHERE gc.user_id="' . intval($user_id).'" ';
657 657
         if (!is_null($cat_id) && $cat_id > 0) {
658
-            $sql.=' AND cat_id=' . intval($cat_id);
658
+            $sql .= ' AND cat_id='.intval($cat_id);
659 659
         }
660 660
 
661 661
         $rs = Database::query($sql);
@@ -693,12 +693,12 @@  discard block
 block discarded – undo
693 693
             $variables = $content_html['variables'];
694 694
         }
695 695
 
696
-        $path_image = api_get_path(WEB_COURSE_PATH) . api_get_course_path($course_code) . '/document/images/gallery';
696
+        $path_image = api_get_path(WEB_COURSE_PATH).api_get_course_path($course_code).'/document/images/gallery';
697 697
         $new_content_html = str_replace('../images/gallery', $path_image, $new_content_html);
698 698
 
699
-        $path_image_in_default_course = api_get_path(WEB_CODE_PATH) . 'default_course_document';
699
+        $path_image_in_default_course = api_get_path(WEB_CODE_PATH).'default_course_document';
700 700
         $new_content_html = str_replace('/main/default_course_document', $path_image_in_default_course, $new_content_html);
701
-        $new_content_html = str_replace(SYS_CODE_PATH . 'img/', api_get_path(WEB_IMG_PATH), $new_content_html);
701
+        $new_content_html = str_replace(SYS_CODE_PATH.'img/', api_get_path(WEB_IMG_PATH), $new_content_html);
702 702
 
703 703
         //add print header
704 704
         if ($hide_print_button == false) {
@@ -709,7 +709,7 @@  discard block
 block discarded – undo
709 709
         }
710 710
 
711 711
         // Add header
712
-        $new_content_html =  $contentHead. $print . '</head>' . $new_content_html;
712
+        $new_content_html = $contentHead.$print.'</head>'.$new_content_html;
713 713
 
714 714
         return array(
715 715
             'content' => $new_content_html,
@@ -731,9 +731,9 @@  discard block
 block discarded – undo
731 731
             $session_id = api_get_session_id();
732 732
 
733 733
             $t = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
734
-            $sql = "SELECT * FROM $t WHERE course_code = '" . Database::escape_string($course_code) . "' ";
734
+            $sql = "SELECT * FROM $t WHERE course_code = '".Database::escape_string($course_code)."' ";
735 735
             if (!empty($session_id)) {
736
-                $sql .= " AND session_id = " . (int) $session_id;
736
+                $sql .= " AND session_id = ".(int) $session_id;
737 737
             } else {
738 738
                 $sql .= " AND (session_id IS NULL OR session_id = 0) ";
739 739
             }
@@ -745,7 +745,7 @@  discard block
 block discarded – undo
745 745
                 if (!empty($session_id)) {
746 746
                     $my_session_id = api_get_session_id();
747 747
                     $s_name = api_get_session_name($my_session_id);
748
-                    $cat->set_name($course_code . ' - ' . get_lang('Session') . ' ' . $s_name);
748
+                    $cat->set_name($course_code.' - '.get_lang('Session').' '.$s_name);
749 749
                     $cat->set_session_id($session_id);
750 750
                 } else {
751 751
                     $cat->set_name($course_code);
@@ -867,13 +867,13 @@  discard block
 block discarded – undo
867 867
 
868 868
         if ($use_grade_model) {
869 869
             if ($parent_id == 0) {
870
-                $title = api_strtoupper(get_lang('Average')) . '<br />' . get_lang('Detailed');
870
+                $title = api_strtoupper(get_lang('Average')).'<br />'.get_lang('Detailed');
871 871
             } else {
872
-                $title = api_strtoupper(get_lang('Average')) . '<br />' . $cat[0]->get_description() . ' - (' . $cat[0]->get_name() . ')';
872
+                $title = api_strtoupper(get_lang('Average')).'<br />'.$cat[0]->get_description().' - ('.$cat[0]->get_name().')';
873 873
             }
874 874
         } else {
875 875
             if ($parent_id == 0) {
876
-                $title = api_strtoupper(get_lang('Average')) . '<br />' . get_lang('Detailed');
876
+                $title = api_strtoupper(get_lang('Average')).'<br />'.get_lang('Detailed');
877 877
             } else {
878 878
                 $title = api_strtoupper(get_lang('Average'));
879 879
             }
@@ -927,11 +927,11 @@  discard block
 block discarded – undo
927 927
         } else {
928 928
             $column = 0;
929 929
             $table->setCellContents($row, $column, get_lang('NoResults'));
930
-            $table->updateCellAttributes($row, $column, 'colspan="' . $columns . '" align="center" class="row_odd"');
930
+            $table->updateCellAttributes($row, $column, 'colspan="'.$columns.'" align="center" class="row_odd"');
931 931
         }
932 932
 
933 933
         $pdfParams = array(
934
-            'filename' => get_lang('FlatView') . '_' . api_get_utc_datetime(),
934
+            'filename' => get_lang('FlatView').'_'.api_get_utc_datetime(),
935 935
             'pdf_title' => $title,
936 936
             'course_code' => $course_code,
937 937
             'add_signatures' => true
@@ -1016,7 +1016,7 @@  discard block
 block discarded – undo
1016 1016
         $a_students = array();
1017 1017
         while ($user = Database::fetch_array($result)) {
1018 1018
             if (!array_key_exists($user['user_id'], $a_students)) {
1019
-                $a_current_student = array ();
1019
+                $a_current_student = array();
1020 1020
                 $a_current_student[] = $user['user_id'];
1021 1021
                 $a_current_student[] = $user['username'];
1022 1022
                 $a_current_student[] = $user['lastname'];
@@ -1074,7 +1074,7 @@  discard block
 block discarded – undo
1074 1074
         foreach ($links as $link) {
1075 1075
             // links are always in a course
1076 1076
             $coursecode = $link->get_course_code();
1077
-            if (!array_key_exists($coursecode,$coursecodes)) {
1077
+            if (!array_key_exists($coursecode, $coursecodes)) {
1078 1078
                 $coursecodes[$coursecode] = '1';
1079 1079
                 $users = array_merge($users, GradebookUtils::get_users_in_course($coursecode));
1080 1080
             }
@@ -1087,7 +1087,7 @@  discard block
 block discarded – undo
1087 1087
      * Search students matching a given last name and/or first name
1088 1088
      * @author Bert Steppé
1089 1089
      */
1090
-    public static function find_students($mask= '')
1090
+    public static function find_students($mask = '')
1091 1091
     {
1092 1092
         // students shouldn't be here // don't search if mask empty
1093 1093
         if (!api_is_allowed_to_edit() || empty ($mask)) {
@@ -1098,23 +1098,23 @@  discard block
 block discarded – undo
1098 1098
         $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
1099 1099
         $tbl_cru = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
1100 1100
         $sql = 'SELECT DISTINCT user.user_id, user.lastname, user.firstname, user.email, user.official_code
1101
-                FROM ' . $tbl_user . ' user';
1101
+                FROM ' . $tbl_user.' user';
1102 1102
         if (!api_is_platform_admin()) {
1103
-            $sql .= ', ' . $tbl_cru . ' cru';
1103
+            $sql .= ', '.$tbl_cru.' cru';
1104 1104
         }
1105 1105
 
1106
-        $sql .= ' WHERE user.status = ' . STUDENT;
1107
-        $sql .= ' AND (user.lastname LIKE '."'%" . $mask . "%'";
1108
-        $sql .= ' OR user.firstname LIKE '."'%" . $mask . "%')";
1106
+        $sql .= ' WHERE user.status = '.STUDENT;
1107
+        $sql .= ' AND (user.lastname LIKE '."'%".$mask."%'";
1108
+        $sql .= ' OR user.firstname LIKE '."'%".$mask."%')";
1109 1109
 
1110 1110
         if (!api_is_platform_admin()) {
1111 1111
             $sql .= ' AND user.user_id = cru.user_id AND
1112 1112
                       cru.relation_type <> '.COURSE_RELATION_TYPE_RRHH.' AND
1113 1113
                       cru.c_id in (
1114
-                            SELECT c_id FROM '.$tbl_cru . '
1114
+                            SELECT c_id FROM '.$tbl_cru.'
1115 1115
                             WHERE
1116
-                                user_id = ' . api_get_user_id() . ' AND
1117
-                                status = ' . COURSEMANAGER . '
1116
+                                user_id = ' . api_get_user_id().' AND
1117
+                                status = ' . COURSEMANAGER.'
1118 1118
                         )
1119 1119
                     ';
1120 1120
         }
@@ -1157,7 +1157,7 @@  discard block
 block discarded – undo
1157 1157
         $sql = 'SELECT ref_id FROM '.$table_link.'
1158 1158
                 WHERE id = '.$linkId.' AND type='.LINK_ATTENDANCE;
1159 1159
 
1160
-        $rs_attendance  = Database::query($sql);
1160
+        $rs_attendance = Database::query($sql);
1161 1161
         if (Database::num_rows($rs_attendance) > 0) {
1162 1162
             $row_attendance = Database::fetch_array($rs_attendance);
1163 1163
             $sql = 'UPDATE '.$tbl_attendance.' SET attendance_weight ='.$weight.'
@@ -1243,7 +1243,7 @@  discard block
 block discarded – undo
1243 1243
                 'course' => $courseInfo['title'],
1244 1244
                 'score' => $certificateInfo['score_certificate'],
1245 1245
                 'date' => api_format_date($certificateInfo['created_at'], DATE_FORMAT_SHORT),
1246
-                'link' => api_get_path(WEB_PATH) . "certificates/index.php?id={$certificateInfo['id']}"
1246
+                'link' => api_get_path(WEB_PATH)."certificates/index.php?id={$certificateInfo['id']}"
1247 1247
             ];
1248 1248
         }
1249 1249
 
@@ -1307,7 +1307,7 @@  discard block
 block discarded – undo
1307 1307
                     'course' => $course['title'],
1308 1308
                     'score' => $certificateInfo['score_certificate'],
1309 1309
                     'date' => api_format_date($certificateInfo['created_at'], DATE_FORMAT_SHORT),
1310
-                    'link' => api_get_path(WEB_PATH) . "certificates/index.php?id={$certificateInfo['id']}"
1310
+                    'link' => api_get_path(WEB_PATH)."certificates/index.php?id={$certificateInfo['id']}"
1311 1311
                 ];
1312 1312
             }
1313 1313
         }
Please login to merge, or discard this patch.
main/gradebook/lib/results_data_generator.class.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
     /**
39 39
      * Get total number of results (rows)
40 40
      */
41
-    public function get_total_results_count ()
41
+    public function get_total_results_count()
42 42
     {
43 43
         return count($this->results);
44 44
     }
@@ -53,12 +53,12 @@  discard block
 block discarded – undo
53 53
      * 4 ['score']     : student's score
54 54
      * 5 ['display']   : custom score display (only if custom scoring enabled)
55 55
      */
56
-    public function get_data ($sorting = 0, $start = 0, $count = null, $ignore_score_color = false, $pdf=false)
56
+    public function get_data($sorting = 0, $start = 0, $count = null, $ignore_score_color = false, $pdf = false)
57 57
     {
58 58
         // do some checks on count, redefine if invalid value
59 59
         $number_decimals = api_get_setting('gradebook_number_decimals');
60 60
         if (!isset($count)) {
61
-            $count = count ($this->results) - $start;
61
+            $count = count($this->results) - $start;
62 62
         }
63 63
         if ($count < 0) {
64 64
             $count = 0;
@@ -66,11 +66,11 @@  discard block
 block discarded – undo
66 66
         $scoredisplay = ScoreDisplay :: instance();
67 67
         // generate actual data array
68 68
         $table = array();
69
-        foreach($this->results as $result) {
69
+        foreach ($this->results as $result) {
70 70
             $user = array();
71 71
             $info = api_get_user_info($result->get_user_id());
72 72
             $user['id'] = $result->get_user_id();
73
-            if ($pdf){
73
+            if ($pdf) {
74 74
                 $user['username'] = $info['username'];
75 75
             }
76 76
             $user['result_id'] = $result->get_id();
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
                 true
93 93
             )
94 94
             );
95
-            if ($pdf && $number_decimals == null){
95
+            if ($pdf && $number_decimals == null) {
96 96
                 $user['scoreletter'] = $result->get_score();
97 97
             }
98 98
             if ($scoredisplay->is_custom()) {
@@ -132,13 +132,13 @@  discard block
 block discarded – undo
132 132
      * @param bool  Whether we want to ignore the score color
133 133
      * @result string The score as we want to show it
134 134
      */
135
-    private function get_score_display ($score, $realscore, $ignore_score_color = false)
135
+    private function get_score_display($score, $realscore, $ignore_score_color = false)
136 136
     {
137 137
         if ($score != null) {
138 138
             $scoredisplay = ScoreDisplay :: instance();
139 139
             $type = SCORE_CUSTOM;
140 140
             if ($realscore === true) {
141
-                $type = SCORE_DIV_PERCENT ;
141
+                $type = SCORE_DIV_PERCENT;
142 142
             }
143 143
 
144 144
             return $scoredisplay->display_score(
@@ -172,10 +172,10 @@  discard block
 block discarded – undo
172 172
         }
173 173
     }
174 174
 
175
-    function sort_by_mask ($item1, $item2)
175
+    function sort_by_mask($item1, $item2)
176 176
     {
177
-        $score1 = (isset($item1['score']) ? array($item1['score'],$this->evaluation->get_max()) : null);
178
-        $score2 = (isset($item2['score']) ? array($item2['score'],$this->evaluation->get_max()) : null);
177
+        $score1 = (isset($item1['score']) ? array($item1['score'], $this->evaluation->get_max()) : null);
178
+        $score2 = (isset($item2['score']) ? array($item2['score'], $this->evaluation->get_max()) : null);
179 179
         return ScoreDisplay :: compare_scores_by_custom_display($score1, $score2);
180 180
     }
181 181
 }
Please login to merge, or discard this patch.
main/gradebook/lib/flatview_data_generator.class.php 1 patch
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -114,10 +114,10 @@  discard block
 block discarded – undo
114 114
             isset($this->params['only_subcat']) &&
115 115
             $this->params['only_subcat'] == $this->category->get_id()
116 116
         ) {
117
-            $main_weight  = $this->category->get_weight();
117
+            $main_weight = $this->category->get_weight();
118 118
             $grade_model_id = $this->category->get_grade_model_id();
119 119
         } else {
120
-            $main_cat  = Category::load($parent_id, null, null);
120
+            $main_cat = Category::load($parent_id, null, null);
121 121
             $main_weight = $main_cat[0]->get_weight();
122 122
             $grade_model_id = $main_cat[0]->get_grade_model_id();
123 123
         }
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
                     $list = [];
200 200
                     $list['items'] = $finalList;
201 201
                     $list['header'] = '<center>'.$mainHeader.'</center>';
202
-                    $headers[]= $list;
202
+                    $headers[] = $list;
203 203
                 } else {
204 204
                     $headers[] = '<center>'.$mainHeader.'</center>';
205 205
                 }
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
                 (isset($this->params['only_total_category']) &&
210 210
                     $this->params['only_total_category'] == false)
211 211
             ) {
212
-                for ($count=0; ($count < $items_count ) && ($items_start + $count < count($this->evals_links)); $count++) {
212
+                for ($count = 0; ($count < $items_count) && ($items_start + $count < count($this->evals_links)); $count++) {
213 213
                     /** @var AbstractLink $item */
214 214
                     $item = $this->evals_links[$count + $items_start];
215 215
                     $weight = round(100 * $item->get_weight() / $main_weight, 1);
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
                     !in_array($item->get_id(), $evaluationsAdded)
228 228
                 ) {
229 229
                     $weight = round(100 * $item->get_weight() / $main_weight, 1);
230
-                    $headers[] = $item->get_name() . ' ' . $weight . ' % ';
230
+                    $headers[] = $item->get_name().' '.$weight.' % ';
231 231
                 }
232 232
             }
233 233
         }
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
         if (!isset($items_count)) {
267 267
             $items_count = count($this->evals_links) - $items_start;
268 268
         }
269
-        for ($count=0; ($count < $items_count ) && ($items_start + $count < count($this->evals_links)); $count++) {
269
+        for ($count = 0; ($count < $items_count) && ($items_start + $count < count($this->evals_links)); $count++) {
270 270
             $item = $this->evals_links [$count + $items_start];
271 271
             $headers[] = $item->get_name();
272 272
         }
@@ -293,13 +293,13 @@  discard block
 block discarded – undo
293 293
     ) {
294 294
         // Do some checks on users/items counts, redefine if invalid values
295 295
         if (!isset($users_count)) {
296
-            $users_count = count ($this->users) - $users_start;
296
+            $users_count = count($this->users) - $users_start;
297 297
         }
298 298
         if ($users_count < 0) {
299 299
             $users_count = 0;
300 300
         }
301 301
         if (!isset($items_count)) {
302
-            $items_count = count ($this->evals) + count ($this->links) - $items_start;
302
+            $items_count = count($this->evals) + count($this->links) - $items_start;
303 303
         }
304 304
         if ($items_count < 0) {
305 305
             $items_count = 0;
@@ -312,10 +312,10 @@  discard block
 block discarded – undo
312 312
 
313 313
         // sort users array
314 314
         if ($users_sorting & self :: FVDG_SORT_LASTNAME) {
315
-            usort($userTable, array('FlatViewDataGenerator','sort_by_last_name'));
315
+            usort($userTable, array('FlatViewDataGenerator', 'sort_by_last_name'));
316 316
 
317 317
         } elseif ($users_sorting & self :: FVDG_SORT_FIRSTNAME) {
318
-            usort($userTable, array('FlatViewDataGenerator','sort_by_first_name'));
318
+            usort($userTable, array('FlatViewDataGenerator', 'sort_by_first_name'));
319 319
         }
320 320
 
321 321
         if ($users_sorting & self :: FVDG_SORT_DESC) {
@@ -356,10 +356,10 @@  discard block
 block discarded – undo
356 356
         $parent_id = $this->category->get_parent_id();
357 357
 
358 358
         if ($parent_id == 0 or $this->params['only_subcat'] == $this->category->get_id()) {
359
-            $main_weight  = $this->category->get_weight();
359
+            $main_weight = $this->category->get_weight();
360 360
             $grade_model_id = $this->category->get_grade_model_id();
361 361
         } else {
362
-            $main_cat  = Category::load($parent_id, null, null);
362
+            $main_cat = Category::load($parent_id, null, null);
363 363
             $main_weight = $main_cat[0]->get_weight();
364 364
             $grade_model_id = $main_cat[0]->get_grade_model_id();
365 365
         }
@@ -471,11 +471,11 @@  discard block
 block discarded – undo
471 471
                     $divide = $score[1] == 0 ? 1 : $score[1];
472 472
 
473 473
                     $sub_cat_percentage = $sum_categories_weight_array[$sub_cat->get_id()];
474
-                    $item_value  = $score[0]/$divide*$main_weight;
474
+                    $item_value = $score[0] / $divide * $main_weight;
475 475
 
476 476
                     // Fixing total when using one or multiple gradebooks
477
-                    $percentage = $sub_cat->get_weight()/($sub_cat_percentage) * $sub_cat_percentage/$this->category->get_weight();
478
-                    $item_value = $percentage*$item_value;
477
+                    $percentage = $sub_cat->get_weight() / ($sub_cat_percentage) * $sub_cat_percentage / $this->category->get_weight();
478
+                    $item_value = $percentage * $item_value;
479 479
                     $item_total += $sub_cat->get_weight();
480 480
                     /*
481 481
                         if ($convert_using_the_global_weight) {
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
                 if ($convert_using_the_global_weight) {
522 522
                     //$item_total = $main_weight;
523 523
                 }
524
-            } else  {
524
+            } else {
525 525
                 // All evaluations
526 526
                 $result = $this->parseEvaluations(
527 527
                     $user_id,
@@ -628,7 +628,7 @@  discard block
 block discarded – undo
628 628
             // Sub cat weight
629 629
             //$sub_cat_percentage = $sum_categories_weight_array[$item->get_category_id()];
630 630
 
631
-            $item_value = isset($score[0]) ? $score[0]/$divide : 0;
631
+            $item_value = isset($score[0]) ? $score[0] / $divide : 0;
632 632
 
633 633
             // Fixing total when using one or multiple gradebooks.
634 634
             if (empty($parentCategoryIdFilter)) {
@@ -710,11 +710,11 @@  discard block
 block discarded – undo
710 710
         $data = array();
711 711
 
712 712
         foreach ($selected_users as $user) {
713
-            $row = array ();
714
-            for ($count=0;$count < count($this->evals_links); $count++) {
713
+            $row = array();
714
+            for ($count = 0; $count < count($this->evals_links); $count++) {
715 715
                 $item = $this->evals_links [$count];
716 716
                 $score = $item->calc_score($user[0]);
717
-                $porcent_score = isset($score[1]) &&  $score[1] > 0 ? ($score[0]*100)/$score[1] :0;
717
+                $porcent_score = isset($score[1]) && $score[1] > 0 ? ($score[0] * 100) / $score[1] : 0;
718 718
                 $row[$item->get_name()] = $porcent_score;
719 719
             }
720 720
             $data[$user[0]] = $row;
@@ -726,7 +726,7 @@  discard block
 block discarded – undo
726 726
             $tmp = array();
727 727
             foreach ($items as $item => $value) {
728 728
                 $tmp[] = $item;
729
-                if (in_array($item,$tmp)) {
729
+                if (in_array($item, $tmp)) {
730 730
                     $data_by_item[$item][$uid] = $value;
731 731
                 }
732 732
             }
@@ -737,7 +737,7 @@  discard block
 block discarded – undo
737 737
         */
738 738
         $result = array();
739 739
         foreach ($data_by_item as $k => $v) {
740
-            $average = round(array_sum($v)/count($v));
740
+            $average = round(array_sum($v) / count($v));
741 741
             arsort($v);
742 742
             $maximum = array_shift($v);
743 743
             $minimum = array_pop($v);
@@ -746,7 +746,7 @@  discard block
 block discarded – undo
746 746
                 $minimum = 0;
747 747
             }
748 748
 
749
-            $summary= array(
749
+            $summary = array(
750 750
                 'max' => $maximum,
751 751
                 'min' => $minimum,
752 752
                 'avg' => $average
@@ -763,32 +763,32 @@  discard block
 block discarded – undo
763 763
     public function get_data_to_graph()
764 764
     {
765 765
         // do some checks on users/items counts, redefine if invalid values
766
-        $usertable = array ();
766
+        $usertable = array();
767 767
         foreach ($this->users as $user) {
768 768
             $usertable[] = $user;
769 769
         }
770 770
         // sort users array
771
-        usort($usertable, array ('FlatViewDataGenerator','sort_by_first_name'));
771
+        usort($usertable, array('FlatViewDataGenerator', 'sort_by_first_name'));
772 772
 
773
-        $data = array ();
773
+        $data = array();
774 774
 
775 775
         $selected_users = $usertable;
776 776
         foreach ($selected_users as $user) {
777
-            $row = array ();
778
-            $row[] = $user[0];    // user id
777
+            $row = array();
778
+            $row[] = $user[0]; // user id
779 779
             $item_value = 0;
780 780
             $item_total = 0;
781 781
 
782
-            for ($count=0;$count < count($this->evals_links); $count++) {
782
+            for ($count = 0; $count < count($this->evals_links); $count++) {
783 783
                 $item = $this->evals_links[$count];
784 784
                 $score = $item->calc_score($user[0]);
785 785
 
786
-                $divide =( ($score[1])==0 ) ? 1 : $score[1];
787
-                $item_value += $score[0]/$divide*$item->get_weight();
786
+                $divide = (($score[1]) == 0) ? 1 : $score[1];
787
+                $item_value += $score[0] / $divide * $item->get_weight();
788 788
                 $item_total += $item->get_weight();
789 789
 
790 790
 
791
-                $score_denom = ($score[1]==0) ? 1 : $score[1];
791
+                $score_denom = ($score[1] == 0) ? 1 : $score[1];
792 792
                 $score_final = ($score[0] / $score_denom) * 100;
793 793
                 $row[] = $score_final;
794 794
             }
@@ -814,15 +814,15 @@  discard block
 block discarded – undo
814 814
             $usertable[] = $user;
815 815
         }
816 816
         // sort users array
817
-        usort($usertable, array ('FlatViewDataGenerator','sort_by_first_name'));
817
+        usort($usertable, array('FlatViewDataGenerator', 'sort_by_first_name'));
818 818
 
819 819
         // generate actual data array
820 820
         $scoredisplay = ScoreDisplay :: instance();
821 821
         $data = array();
822 822
         $selected_users = $usertable;
823 823
         foreach ($selected_users as $user) {
824
-            $row = array ();
825
-            $row[] = $user[0];    // user id
824
+            $row = array();
825
+            $row[] = $user[0]; // user id
826 826
             $item_value = 0;
827 827
             $item_total = 0;
828 828
             $final_score = 0;
@@ -843,8 +843,8 @@  discard block
 block discarded – undo
843 843
                     $divide = $score[1] == 0 ? 1 : $score[1];
844 844
 
845 845
                     //$sub_cat_percentage = $sum_categories_weight_array[$sub_cat->get_id()];
846
-                    $item_value     = $score[0]/$divide*$main_weight;
847
-                    $item_total        += $sub_cat->get_weight();
846
+                    $item_value = $score[0] / $divide * $main_weight;
847
+                    $item_total += $sub_cat->get_weight();
848 848
 
849 849
                     $row[] = array(
850 850
                         $item_value,
@@ -861,23 +861,23 @@  discard block
 block discarded – undo
861 861
                     trim($scoredisplay->display_score($total_score, SCORE_CUSTOM, null, true))
862 862
                 );
863 863
             } else {
864
-                for ($count=0;$count < count($this->evals_links); $count++) {
864
+                for ($count = 0; $count < count($this->evals_links); $count++) {
865 865
                     $item = $this->evals_links [$count];
866 866
                     $score = $item->calc_score($user[0]);
867 867
                     $divide = ($score[1]) == 0 ? 1 : $score[1];
868 868
                     $item_value += $score[0] / $divide * $item->get_weight();
869
-                    $item_total+=$item->get_weight();
870
-                    $score_denom=($score[1]==0) ? 1 : $score[1];
869
+                    $item_total += $item->get_weight();
870
+                    $score_denom = ($score[1] == 0) ? 1 : $score[1];
871 871
                     $score_final = ($score[0] / $score_denom) * 100;
872
-                    $row[] = array ($score_final, trim($scoredisplay->display_score($score, SCORE_CUSTOM,null, true)));
872
+                    $row[] = array($score_final, trim($scoredisplay->display_score($score, SCORE_CUSTOM, null, true)));
873 873
 
874 874
                 }
875
-                $total_score=array($item_value,$item_total);
875
+                $total_score = array($item_value, $item_total);
876 876
                 $score_final = ($item_value / $item_total) * 100;
877 877
                 if ($displayWarning) {
878
-                    Display::display_warning_message( Display::display_warning_message($total_score[1]));
878
+                    Display::display_warning_message(Display::display_warning_message($total_score[1]));
879 879
                 }
880
-                $row[] =array ($score_final, trim($scoredisplay->display_score($total_score, SCORE_CUSTOM, null, true)));
880
+                $row[] = array($score_final, trim($scoredisplay->display_score($total_score, SCORE_CUSTOM, null, true)));
881 881
             }
882 882
 
883 883
             $data[] = $row;
Please login to merge, or discard this patch.
main/admin/class_edit.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -19,8 +19,8 @@  discard block
 block discarded – undo
19 19
 api_protect_admin_script();
20 20
 
21 21
 // Setting breadcrumbs.
22
-$interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
23
-$interbreadcrumb[] = array ('url' => 'class_list.php', 'name' => get_lang('AdminClasses'));
22
+$interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
23
+$interbreadcrumb[] = array('url' => 'class_list.php', 'name' => get_lang('AdminClasses'));
24 24
 
25 25
 
26 26
 // Setting the name of the tool.
@@ -30,10 +30,10 @@  discard block
 block discarded – undo
30 30
 $class_id = intval($_GET['idclass']);
31 31
 $class = ClassManager :: get_class_info($class_id);
32 32
 $form = new FormValidator('edit_class', 'post', 'class_edit.php?idclass='.$class_id);
33
-$form->addText('name',get_lang('ClassName'));
33
+$form->addText('name', get_lang('ClassName'));
34 34
 $form->addButtonUpdate(get_lang('Ok'));
35 35
 $form->setDefaults(array('name'=>$class['name']));
36
-if($form->validate())
36
+if ($form->validate())
37 37
 {
38 38
     $values = $form->exportValues();
39 39
     ClassManager :: set_name($values['name'], $class_id);
Please login to merge, or discard this patch.
main/admin/ldap_import_students.php 3 patches
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
  * Code
10 10
  */
11 11
 // resetting the course id
12
-$cidReset=true;
12
+$cidReset = true;
13 13
 require_once('../inc/global.inc.php');
14 14
 // setting the section (for the tabs)
15 15
 $this_section = SECTION_PLATFORM_ADMIN;
@@ -18,11 +18,11 @@  discard block
 block discarded – undo
18 18
 api_protect_admin_script();
19 19
 require('../auth/ldap/authldap.php');
20 20
 
21
-$annee_base=date('Y');
21
+$annee_base = date('Y');
22 22
 
23 23
 $tool_name = get_lang('LDAPImport');
24 24
 // setting breadcrumbs
25
-$interbreadcrumb[]=array('url' => 'index.php','name' => get_lang('PlatformAdmin'));
25
+$interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
26 26
 
27 27
 $htmlHeadXtra[] = '<script language="JavaScript" type="text/javascript">
28 28
 var buttoncheck = 1;
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 
49 49
 $annee = $_GET['annee'];
50 50
 $composante = $_GET['composante'];
51
-$etape =  $_GET['etape'];
51
+$etape = $_GET['etape'];
52 52
 $course = $_POST['course'];
53 53
 
54 54
 
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
 	echo '</div>';
199 199
 }
200 200
 */
201
-elseif(!empty($annee) && empty($course))
201
+elseif (!empty($annee) && empty($course))
202 202
 {
203 203
 	Display::display_header($tool_name);
204 204
 	echo '<div style="align:center">';
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
 	echo '<form method="post" action="'.api_get_self().'?annee='.Security::remove_XSS($annee).'"><br />';
207 207
 	echo '<select name="course">';
208 208
 	$courses = CourseManager::get_courses_list();
209
-	foreach($courses as $row)
209
+	foreach ($courses as $row)
210 210
 	{
211 211
 		echo '<option value="'.$row['code'].'">'.api_htmlentities($row['title']).'</option>';
212 212
 	}
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
 
240 240
 		$info = ldap_get_entries($ds, $sr);
241 241
 
242
-		for ($key = 0; $key < $info["count"]; $key ++) {
242
+		for ($key = 0; $key < $info["count"]; $key++) {
243 243
 			$nom_form[] = $info[$key]["sn"][0];
244 244
 			$prenom_form[] = $info[$key]["givenname"][0];
245 245
 			$email_form[] = $info[$key]["mail"][0];
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 		asort($nom_form);
260 260
 		reset($nom_form);
261 261
 
262
-		$statut=5;
262
+		$statut = 5;
263 263
 		include ('ldap_form_add_users_group.php');
264 264
 	} else {
265 265
 		echo '<h4>'.get_lang('UnableToConnectTo').' '.$host.'</h4>';
@@ -270,25 +270,25 @@  discard block
 block discarded – undo
270 270
     echo '</div>';
271 271
 
272 272
 }
273
-elseif (!empty($annee) && !empty($course) && ($_POST['confirmed']=='yes'))
273
+elseif (!empty($annee) && !empty($course) && ($_POST['confirmed'] == 'yes'))
274 274
 {
275
-	$id=$_POST['username_form'];
276
-	$UserList=array();
275
+	$id = $_POST['username_form'];
276
+	$UserList = array();
277 277
 	$userid_match_login = array();
278 278
 	foreach ($id as $form_index=>$user_id)
279 279
 	{
280
-		if(is_array($_POST['checkboxes']) && in_array($form_index,array_values($_POST['checkboxes'])))
280
+		if (is_array($_POST['checkboxes']) && in_array($form_index, array_values($_POST['checkboxes'])))
281 281
 		{
282 282
 			$tmp = ldap_add_user($user_id);
283
-			$UserList[]= $tmp;
283
+			$UserList[] = $tmp;
284 284
 			$userid_match_login[$tmp] = $user_id;
285 285
 		}
286 286
 	}
287 287
 	if (!empty($_POST['course']))
288 288
 	{
289
-		foreach($UserList as $user_id)
289
+		foreach ($UserList as $user_id)
290 290
 		{
291
-			CourseManager::add_user_to_course($user_id,$_POST['course']);
291
+			CourseManager::add_user_to_course($user_id, $_POST['course']);
292 292
 		}
293 293
 		header('Location: course_information.php?code='.Security::remove_XSS($_POST['course']));
294 294
 	}
@@ -314,8 +314,8 @@  discard block
 block discarded – undo
314 314
 	else
315 315
 	{
316 316
 		Display::display_header($tool_name);
317
-		$message=get_lang('NoUserAdded');
318
-		Display :: display_normal_message($message,false);
317
+		$message = get_lang('NoUserAdded');
318
+		Display :: display_normal_message($message, false);
319 319
 	}
320 320
 	echo '<br /><br />';
321 321
     echo '<a href="ldap_import_students.php?annee=&composante=&etape=">'.get_lang('BackToNewSearch').'</a>';
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -269,8 +269,7 @@
 block discarded – undo
269 269
     echo '<br /><br />';
270 270
     echo '</div>';
271 271
 
272
-}
273
-elseif (!empty($annee) && !empty($course) && ($_POST['confirmed']=='yes'))
272
+} elseif (!empty($annee) && !empty($course) && ($_POST['confirmed']=='yes'))
274 273
 {
275 274
 	$id=$_POST['username_form'];
276 275
 	$UserList=array();
Please login to merge, or discard this patch.
Indentation   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -56,19 +56,19 @@  discard block
 block discarded – undo
56 56
 //if ($annee == "" && $composante == "" && $etape == "") {
57 57
 if (empty($annee) && empty($course))
58 58
 {
59
-		Display::display_header($tool_name);
60
-		echo '<div style="align:center">';
61
-		Display::display_icon('group.gif', get_lang('LDAPSelectFilterOnUsersOU'));
62
-		echo get_lang('LDAPSelectFilterOnUsersOU');
63
-		//echo '<em>'.get_lang('ToDoThisYouMustEnterYearComponentAndComponentStep').'</em><br />';
64
-		///echo get_lang('FollowEachOfTheseStepsStepByStep').'<br />';
65
-
66
-		echo '<form method="get" action="'.api_get_self().'"><br />';
67
-		echo '<em>'.get_lang('LDAPOUAttributeFilter').' :</em> ';
68
-		echo '<input  type="text" name="annee" size="4" maxlength="30" value="'.$annee_base.'"><br />';
69
-		echo '<input type="submit" value="'.get_lang('Submit').'">';
70
-		echo '</form>';
71
-		echo '</div>';
59
+        Display::display_header($tool_name);
60
+        echo '<div style="align:center">';
61
+        Display::display_icon('group.gif', get_lang('LDAPSelectFilterOnUsersOU'));
62
+        echo get_lang('LDAPSelectFilterOnUsersOU');
63
+        //echo '<em>'.get_lang('ToDoThisYouMustEnterYearComponentAndComponentStep').'</em><br />';
64
+        ///echo get_lang('FollowEachOfTheseStepsStepByStep').'<br />';
65
+
66
+        echo '<form method="get" action="'.api_get_self().'"><br />';
67
+        echo '<em>'.get_lang('LDAPOUAttributeFilter').' :</em> ';
68
+        echo '<input  type="text" name="annee" size="4" maxlength="30" value="'.$annee_base.'"><br />';
69
+        echo '<input type="submit" value="'.get_lang('Submit').'">';
70
+        echo '</form>';
71
+        echo '</div>';
72 72
 
73 73
 }
74 74
 /*
@@ -200,71 +200,71 @@  discard block
 block discarded – undo
200 200
 */
201 201
 elseif(!empty($annee) && empty($course))
202 202
 {
203
-	Display::display_header($tool_name);
204
-	echo '<div style="align:center">';
205
-	echo Display::return_icon('course.png', get_lang('SelectCourseToImportUsersTo')).' '.get_lang('SelectCourseToImportUsersTo').'<br />';
206
-	echo '<form method="post" action="'.api_get_self().'?annee='.Security::remove_XSS($annee).'"><br />';
207
-	echo '<select name="course">';
208
-	$courses = CourseManager::get_courses_list();
209
-	foreach($courses as $row)
210
-	{
211
-		echo '<option value="'.$row['code'].'">'.api_htmlentities($row['title']).'</option>';
212
-	}
213
-	echo '</select>';
214
-	echo '<input type="submit" value="'.get_lang('Submit').'">';
215
-	echo '</form>';
216
-	echo '</div>';
203
+    Display::display_header($tool_name);
204
+    echo '<div style="align:center">';
205
+    echo Display::return_icon('course.png', get_lang('SelectCourseToImportUsersTo')).' '.get_lang('SelectCourseToImportUsersTo').'<br />';
206
+    echo '<form method="post" action="'.api_get_self().'?annee='.Security::remove_XSS($annee).'"><br />';
207
+    echo '<select name="course">';
208
+    $courses = CourseManager::get_courses_list();
209
+    foreach($courses as $row)
210
+    {
211
+        echo '<option value="'.$row['code'].'">'.api_htmlentities($row['title']).'</option>';
212
+    }
213
+    echo '</select>';
214
+    echo '<input type="submit" value="'.get_lang('Submit').'">';
215
+    echo '</form>';
216
+    echo '</div>';
217 217
 }
218 218
 // form4  annee != 0; composante != 0 etape != 0
219 219
 //elseif ($annee <> "" && $composante <> "" && $etape <> "" && $listeok != 'yes') {
220 220
 elseif (!empty($annee) && !empty($course) && empty($_POST['confirmed']))
221 221
 {
222
-	Display::display_header($tool_name);
223
-	echo '<div style="align: center;">';
224
-	echo '<br />';
225
-	echo '<br />';
226
-	echo '<h3>'.Display::return_icon('group.gif', get_lang('SelectStudents')).' '.get_lang('SelectStudents').'</h3>';
227
-	//echo "Connection ...";
228
-	$ds = ldap_connect($ldap_host, $ldap_port) or die(get_lang('LDAPConnectionError'));
229
-	ldap_set_version($ds);
230
-
231
-	if ($ds) {
232
-
233
-		$r = false;
234
-		$res = ldap_handle_bind($ds, $r);
235
-
236
-		//$sr = @ ldap_search($ds, "ou=people,$LDAPbasedn", "(|(edupersonprimaryorgunitdn=ou=$etape,ou=$annee,ou=diploma,o=Paris1,$LDAPbasedn)(edupersonprimaryorgunitdn=ou=02PEL,ou=$annee,ou=diploma,o=Paris1,$LDAPbasedn))");
237
-		//echo "(ou=*$annee,ou=$composante)";
238
-		$sr = @ ldap_search($ds, $ldap_basedn, "(ou=*$annee)");
239
-
240
-		$info = ldap_get_entries($ds, $sr);
241
-
242
-		for ($key = 0; $key < $info["count"]; $key ++) {
243
-			$nom_form[] = $info[$key]["sn"][0];
244
-			$prenom_form[] = $info[$key]["givenname"][0];
245
-			$email_form[] = $info[$key]["mail"][0];
246
-			// Get uid from dn
247
-			//$dn_array=ldap_explode_dn($info[$key]["dn"],1);
248
-			//$username_form[] = $dn_array[0]; // uid is first key
249
-			$username_form[] = $info[$key]['uid'][0];
250
-			$outab[] = $info[$key]["eduPersonPrimaryAffiliation"][0]; // Ici "student"
251
-			//$val = ldap_get_values_len($ds, $entry, "userPassword");
252
-			//$password_form[] = $val[0];
253
-			$password_form[] = $info[$key]['userPassword'][0];
254
-		}
255
-		ldap_unbind($ds);
256
-
257
-		/*-----------------------------------------------*/
258
-
259
-		asort($nom_form);
260
-		reset($nom_form);
261
-
262
-		$statut=5;
263
-		include ('ldap_form_add_users_group.php');
264
-	} else {
265
-		echo '<h4>'.get_lang('UnableToConnectTo').' '.$host.'</h4>';
266
-	}
267
-	echo '<br /><br />';
222
+    Display::display_header($tool_name);
223
+    echo '<div style="align: center;">';
224
+    echo '<br />';
225
+    echo '<br />';
226
+    echo '<h3>'.Display::return_icon('group.gif', get_lang('SelectStudents')).' '.get_lang('SelectStudents').'</h3>';
227
+    //echo "Connection ...";
228
+    $ds = ldap_connect($ldap_host, $ldap_port) or die(get_lang('LDAPConnectionError'));
229
+    ldap_set_version($ds);
230
+
231
+    if ($ds) {
232
+
233
+        $r = false;
234
+        $res = ldap_handle_bind($ds, $r);
235
+
236
+        //$sr = @ ldap_search($ds, "ou=people,$LDAPbasedn", "(|(edupersonprimaryorgunitdn=ou=$etape,ou=$annee,ou=diploma,o=Paris1,$LDAPbasedn)(edupersonprimaryorgunitdn=ou=02PEL,ou=$annee,ou=diploma,o=Paris1,$LDAPbasedn))");
237
+        //echo "(ou=*$annee,ou=$composante)";
238
+        $sr = @ ldap_search($ds, $ldap_basedn, "(ou=*$annee)");
239
+
240
+        $info = ldap_get_entries($ds, $sr);
241
+
242
+        for ($key = 0; $key < $info["count"]; $key ++) {
243
+            $nom_form[] = $info[$key]["sn"][0];
244
+            $prenom_form[] = $info[$key]["givenname"][0];
245
+            $email_form[] = $info[$key]["mail"][0];
246
+            // Get uid from dn
247
+            //$dn_array=ldap_explode_dn($info[$key]["dn"],1);
248
+            //$username_form[] = $dn_array[0]; // uid is first key
249
+            $username_form[] = $info[$key]['uid'][0];
250
+            $outab[] = $info[$key]["eduPersonPrimaryAffiliation"][0]; // Ici "student"
251
+            //$val = ldap_get_values_len($ds, $entry, "userPassword");
252
+            //$password_form[] = $val[0];
253
+            $password_form[] = $info[$key]['userPassword'][0];
254
+        }
255
+        ldap_unbind($ds);
256
+
257
+        /*-----------------------------------------------*/
258
+
259
+        asort($nom_form);
260
+        reset($nom_form);
261
+
262
+        $statut=5;
263
+        include ('ldap_form_add_users_group.php');
264
+    } else {
265
+        echo '<h4>'.get_lang('UnableToConnectTo').' '.$host.'</h4>';
266
+    }
267
+    echo '<br /><br />';
268 268
     echo '<a href="ldap_import_students.php?annee=&composante=&etape=">'.get_lang('BackToNewSearch').'</a>';
269 269
     echo '<br /><br />';
270 270
     echo '</div>';
@@ -272,27 +272,27 @@  discard block
 block discarded – undo
272 272
 }
273 273
 elseif (!empty($annee) && !empty($course) && ($_POST['confirmed']=='yes'))
274 274
 {
275
-	$id=$_POST['username_form'];
276
-	$UserList=array();
277
-	$userid_match_login = array();
278
-	foreach ($id as $form_index=>$user_id)
279
-	{
280
-		if(is_array($_POST['checkboxes']) && in_array($form_index,array_values($_POST['checkboxes'])))
281
-		{
282
-			$tmp = ldap_add_user($user_id);
283
-			$UserList[]= $tmp;
284
-			$userid_match_login[$tmp] = $user_id;
285
-		}
286
-	}
287
-	if (!empty($_POST['course']))
288
-	{
289
-		foreach($UserList as $user_id)
290
-		{
291
-			CourseManager::add_user_to_course($user_id,$_POST['course']);
292
-		}
293
-		header('Location: course_information.php?code='.Security::remove_XSS($_POST['course']));
294
-	}
295
-	/*
275
+    $id=$_POST['username_form'];
276
+    $UserList=array();
277
+    $userid_match_login = array();
278
+    foreach ($id as $form_index=>$user_id)
279
+    {
280
+        if(is_array($_POST['checkboxes']) && in_array($form_index,array_values($_POST['checkboxes'])))
281
+        {
282
+            $tmp = ldap_add_user($user_id);
283
+            $UserList[]= $tmp;
284
+            $userid_match_login[$tmp] = $user_id;
285
+        }
286
+    }
287
+    if (!empty($_POST['course']))
288
+    {
289
+        foreach($UserList as $user_id)
290
+        {
291
+            CourseManager::add_user_to_course($user_id,$_POST['course']);
292
+        }
293
+        header('Location: course_information.php?code='.Security::remove_XSS($_POST['course']));
294
+    }
295
+    /*
296 296
 	else
297 297
 	{
298 298
 		Display :: display_header($tool_name);
@@ -311,13 +311,13 @@  discard block
 block discarded – undo
311 311
 		Display :: display_normal_message($message,false);
312 312
 	}
313 313
 	*/
314
-	else
315
-	{
316
-		Display::display_header($tool_name);
317
-		$message=get_lang('NoUserAdded');
318
-		Display :: display_normal_message($message,false);
319
-	}
320
-	echo '<br /><br />';
314
+    else
315
+    {
316
+        Display::display_header($tool_name);
317
+        $message=get_lang('NoUserAdded');
318
+        Display :: display_normal_message($message,false);
319
+    }
320
+    echo '<br /><br />';
321 321
     echo '<a href="ldap_import_students.php?annee=&composante=&etape=">'.get_lang('BackToNewSearch').'</a>';
322 322
     echo '<br /><br />';
323 323
 }
Please login to merge, or discard this patch.
main/admin/access_url_add_usergroup_to_url.php 3 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -87,7 +87,7 @@
 block discarded – undo
87 87
                   <?php
88 88
                     echo Display::get_alphabet_options($firstLetterUserGroup);
89 89
                     echo Display::get_numeric_options(0, 9, $firstLetterUserGroup);
90
-                  ?>
90
+                    ?>
91 91
             </select>
92 92
         </td>
93 93
         <td width="20%">&nbsp;</td>
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -30,8 +30,8 @@  discard block
 block discarded – undo
30 30
 $tbl_course = Database:: get_main_table(TABLE_MAIN_COURSE);
31 31
 
32 32
 $tool_name = get_lang('AddUserGroupToURL');
33
-$interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
34
-$interbreadcrumb[] = array ('url' => 'access_urls.php', 'name' => get_lang('MultipleAccessURLs'));
33
+$interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
34
+$interbreadcrumb[] = array('url' => 'access_urls.php', 'name' => get_lang('MultipleAccessURLs'));
35 35
 
36 36
 Display::display_header($tool_name);
37 37
 
@@ -46,8 +46,8 @@  discard block
 block discarded – undo
46 46
 
47 47
 if (isset($_POST['form_sent']) && $_POST['form_sent']) {
48 48
     $form_sent = $_POST['form_sent'];
49
-    $userGroups = is_array($_POST['user_group_list']) ? $_POST['user_group_list'] : array() ;
50
-    $urlList = is_array($_POST['url_list']) ? $_POST['url_list'] : array() ;
49
+    $userGroups = is_array($_POST['user_group_list']) ? $_POST['user_group_list'] : array();
50
+    $urlList = is_array($_POST['url_list']) ? $_POST['url_list'] : array();
51 51
     $firstLetterUserGroup = $_POST['first_letter_user_group'];
52 52
 
53 53
     if ($form_sent == 1) {
Please login to merge, or discard this patch.
Braces   +8 added lines, -2 removed lines patch added patch discarded remove patch
@@ -99,7 +99,10 @@  discard block
 block discarded – undo
99 99
         <td width="40%" align="center">
100 100
         <select name="user_group_list[]" multiple="multiple" size="20" style="width:400px;">
101 101
 		<?php foreach ($dbUserGroups as $item) { ?>
102
-			<option value="<?php echo $item['id']; ?>" <?php if (in_array($item['id'], $courses)) echo 'selected="selected"'; ?>><?php echo $item['name']; ?>
102
+			<option value="<?php echo $item['id']; ?>" <?php if (in_array($item['id'], $courses)) {
103
+    echo 'selected="selected"';
104
+}
105
+?>><?php echo $item['name']; ?>
103 106
             </option>
104 107
         <?php } ?>
105 108
     </select>
@@ -110,7 +113,10 @@  discard block
 block discarded – undo
110 113
    <td width="40%" align="center">
111 114
     <select name="url_list[]" multiple="multiple" size="20" style="width:300px;">
112 115
 		<?php foreach ($db_urls as $url_obj) { ?>
113
-        <option value="<?php echo $url_obj['id']; ?>" <?php if (in_array($url_obj['id'], $url_list)) echo 'selected="selected"'; ?>><?php echo $url_obj['url']; ?>
116
+        <option value="<?php echo $url_obj['id']; ?>" <?php if (in_array($url_obj['id'], $url_list)) {
117
+    echo 'selected="selected"';
118
+}
119
+?>><?php echo $url_obj['url']; ?>
114 120
         </option>
115 121
 		<?php } ?>
116 122
     </select>
Please login to merge, or discard this patch.