Completed
Push — 1.10.x ( fe0e5a...3a6f9c )
by Yannick
134:15 queued 86:39
created
main/gradebook/lib/be/attendancelink.class.php 1 patch
Indentation   +202 added lines, -202 removed lines patch added patch discarded remove patch
@@ -8,48 +8,48 @@  discard block
 block discarded – undo
8 8
  */
9 9
 class AttendanceLink extends AbstractLink
10 10
 {
11
-	private $attendance_table = null;
12
-	private $itemprop_table = null;
11
+    private $attendance_table = null;
12
+    private $itemprop_table = null;
13 13
 
14
-	/**
15
-	 * Constructor
16
-	 */
17
-	public function __construct()
18
-	{
19
-		parent::__construct();
20
-		$this->set_type(LINK_ATTENDANCE);
21
-	}
14
+    /**
15
+     * Constructor
16
+     */
17
+    public function __construct()
18
+    {
19
+        parent::__construct();
20
+        $this->set_type(LINK_ATTENDANCE);
21
+    }
22 22
 
23
-	/**
24
-	 * @return string
25
-	 */
26
-	public function get_type_name()
27
-	{
28
-		return get_lang('Attendance');
29
-	}
23
+    /**
24
+     * @return string
25
+     */
26
+    public function get_type_name()
27
+    {
28
+        return get_lang('Attendance');
29
+    }
30 30
 
31
-	/**
32
-	 * @return bool
33
-	 */
34
-	public function is_allowed_to_change_name()
35
-	{
36
-		return false;
37
-	}
31
+    /**
32
+     * @return bool
33
+     */
34
+    public function is_allowed_to_change_name()
35
+    {
36
+        return false;
37
+    }
38 38
 
39
-	/**
40
-	 * Generate an array of attendances that a teacher hasn't created a link for.
41
-	 * @return array 2-dimensional array - every element contains 2 subelements (id, name)
42
-	 * @todo seems to be depracated
43
-	 */
44
-	public function get_not_created_links()
45
-	{
46
-		return false;
47
-		if (empty($this->course_code)) {
48
-			die('Error in get_not_created_links() : course code not set');
49
-		}
50
-		$tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
39
+    /**
40
+     * Generate an array of attendances that a teacher hasn't created a link for.
41
+     * @return array 2-dimensional array - every element contains 2 subelements (id, name)
42
+     * @todo seems to be depracated
43
+     */
44
+    public function get_not_created_links()
45
+    {
46
+        return false;
47
+        if (empty($this->course_code)) {
48
+            die('Error in get_not_created_links() : course code not set');
49
+        }
50
+        $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
51 51
 
52
-		$sql = 'SELECT att.id, att.name, att.attendance_qualify_title
52
+        $sql = 'SELECT att.id, att.name, att.attendance_qualify_title
53 53
 				FROM '.$this->get_attendance_table().' att
54 54
 				WHERE
55 55
 					att.c_id = '.$this->course_id.' AND
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 							course_code = "'.Database::escape_string($this->get_course_code()).'"
61 61
 					)
62 62
 				AND att.session_id='.api_get_session_id().'';
63
-		$result = Database::query($sql);
63
+        $result = Database::query($sql);
64 64
 
65 65
         $cats = array();
66 66
         while ($data = Database::fetch_array($result)) {
@@ -71,13 +71,13 @@  discard block
 block discarded – undo
71 71
             }
72 72
         }
73 73
 
74
-		return $cats;
75
-	}
74
+        return $cats;
75
+    }
76 76
 
77
-	/**
78
-	 * Generate an array of all attendances available.
79
-	 * @return array 2-dimensional array - every element contains 2 subelements (id, name)
80
-	 */
77
+    /**
78
+     * Generate an array of all attendances available.
79
+     * @return array 2-dimensional array - every element contains 2 subelements (id, name)
80
+     */
81 81
     public function get_all_links()
82 82
     {
83 83
         if (empty($this->course_code)) {
@@ -104,55 +104,55 @@  discard block
 block discarded – undo
104 104
         $my_cats = isset($cats) ? $cats : null;
105 105
 
106 106
         return $my_cats;
107
-	}
107
+    }
108 108
 
109
-	/**
110
-	 * Has anyone done this exercise yet ?
111
-	 */
112
-	public function has_results()
113
-	{
114
-		$tbl_attendance_result = Database :: get_course_table(TABLE_ATTENDANCE_RESULT);
115
-		$session_id = api_get_session_id();
116
-		$sql = 'SELECT count(*) AS number FROM '.$tbl_attendance_result."
109
+    /**
110
+     * Has anyone done this exercise yet ?
111
+     */
112
+    public function has_results()
113
+    {
114
+        $tbl_attendance_result = Database :: get_course_table(TABLE_ATTENDANCE_RESULT);
115
+        $session_id = api_get_session_id();
116
+        $sql = 'SELECT count(*) AS number FROM '.$tbl_attendance_result."
117 117
 				WHERE
118 118
 					session_id = $session_id AND
119 119
 					c_id = '.$this->course_id.' AND
120 120
 					attendance_id = '".intval($this->get_ref_id())."'";
121
-		$result = Database::query($sql);
122
-		$number = Database::fetch_row($result);
121
+        $result = Database::query($sql);
122
+        $number = Database::fetch_row($result);
123 123
 
124
-		return $number[0] != 0;
125
-	}
124
+        return $number[0] != 0;
125
+    }
126 126
 
127
-	/**
128
-	 * @param int $stud_id
129
-	 * @return array|null
130
-	 */
131
-	public function calc_score($stud_id = null, $type = null)
132
-	{
133
-		$tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT);
134
-		$session_id = api_get_session_id();
127
+    /**
128
+     * @param int $stud_id
129
+     * @return array|null
130
+     */
131
+    public function calc_score($stud_id = null, $type = null)
132
+    {
133
+        $tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT);
134
+        $session_id = api_get_session_id();
135 135
 
136
-		// get attendance qualify max
137
-		$sql = 'SELECT att.attendance_qualify_max
136
+        // get attendance qualify max
137
+        $sql = 'SELECT att.attendance_qualify_max
138 138
 		        FROM '.$this->get_attendance_table().' att
139 139
   				WHERE
140 140
   					att.c_id = '.$this->course_id.' AND
141 141
   					att.id = '.intval($this->get_ref_id()).' AND
142 142
   					att.session_id='.intval($session_id).'';
143
-		$query = Database::query($sql);
144
-		$attendance = Database::fetch_array($query, 'ASSOC');
143
+        $query = Database::query($sql);
144
+        $attendance = Database::fetch_array($query, 'ASSOC');
145 145
 
146
-		// Get results
147
-		$sql = 'SELECT *
146
+        // Get results
147
+        $sql = 'SELECT *
148 148
 		        FROM '.$tbl_attendance_result.'
149 149
   	    		WHERE c_id = '.$this->course_id.' AND attendance_id = '.intval($this->get_ref_id());
150
-		if (isset($stud_id)) {
151
-			$sql .= ' AND user_id = '.intval($stud_id);
152
-		}
153
-		$scores = Database::query($sql);
154
-		// for 1 student
155
-		if (isset($stud_id)) {
150
+        if (isset($stud_id)) {
151
+            $sql .= ' AND user_id = '.intval($stud_id);
152
+        }
153
+        $scores = Database::query($sql);
154
+        // for 1 student
155
+        if (isset($stud_id)) {
156 156
             if ($data = Database::fetch_array($scores, 'ASSOC')) {
157 157
                 return array(
158 158
                     $data['score'],
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
                 //We sent the 0/attendance_qualify_max instead of null for correct calculations
163 163
                 return array(0, $attendance['attendance_qualify_max']);
164 164
             }
165
-		} else {
165
+        } else {
166 166
             // all students -> get average
167 167
             $students = array();  // user list, needed to make sure we only
168 168
             // take first attempts into account
@@ -171,144 +171,144 @@  discard block
 block discarded – undo
171 171
             $sumResult = 0;
172 172
             $bestResult = 0;
173 173
 
174
-			while ($data = Database::fetch_array($scores)) {
175
-				if (!(array_key_exists($data['user_id'], $students))) {
176
-					if ($attendance['attendance_qualify_max'] != 0) {
177
-						$students[$data['user_id']] = $data['score'];
178
-						$rescount++;
179
-						$sum += $data['score'] / $attendance['attendance_qualify_max'];
180
-						$sumResult += $data['score'];
181
-						if ($data['score'] > $bestResult) {
182
-							$bestResult = $data['score'];
183
-						}
184
-						$weight = $attendance['attendance_qualify_max'];
185
-					}
186
-				}
187
-			}
174
+            while ($data = Database::fetch_array($scores)) {
175
+                if (!(array_key_exists($data['user_id'], $students))) {
176
+                    if ($attendance['attendance_qualify_max'] != 0) {
177
+                        $students[$data['user_id']] = $data['score'];
178
+                        $rescount++;
179
+                        $sum += $data['score'] / $attendance['attendance_qualify_max'];
180
+                        $sumResult += $data['score'];
181
+                        if ($data['score'] > $bestResult) {
182
+                            $bestResult = $data['score'];
183
+                        }
184
+                        $weight = $attendance['attendance_qualify_max'];
185
+                    }
186
+                }
187
+            }
188 188
 
189
-			if ($rescount == 0) {
190
-				return null;
191
-			} else {
192
-				switch ($type) {
193
-					case 'best':
194
-						return array($bestResult, $weight);
195
-						break;
196
-					case 'average':
197
-						return array($sumResult / $rescount, $weight);
198
-						break;
199
-					case 'ranking':
200
-						return AbstractLink::getCurrentUserRanking($stud_id, $students);
201
-						break;
202
-					default:
203
-						return array($sum, $rescount);
204
-						break;
205
-				}
206
-			}
207
-		}
208
-	}
189
+            if ($rescount == 0) {
190
+                return null;
191
+            } else {
192
+                switch ($type) {
193
+                    case 'best':
194
+                        return array($bestResult, $weight);
195
+                        break;
196
+                    case 'average':
197
+                        return array($sumResult / $rescount, $weight);
198
+                        break;
199
+                    case 'ranking':
200
+                        return AbstractLink::getCurrentUserRanking($stud_id, $students);
201
+                        break;
202
+                    default:
203
+                        return array($sum, $rescount);
204
+                        break;
205
+                }
206
+            }
207
+        }
208
+    }
209 209
 
210
-	/**
211
-	 * Lazy load function to get the database table of the student publications
212
-	 */
213
-	private function get_attendance_table()
214
-	{
215
-		$this->attendance_table = Database::get_course_table(TABLE_ATTENDANCE);
216
-		return $this->attendance_table;
217
-	}
210
+    /**
211
+     * Lazy load function to get the database table of the student publications
212
+     */
213
+    private function get_attendance_table()
214
+    {
215
+        $this->attendance_table = Database::get_course_table(TABLE_ATTENDANCE);
216
+        return $this->attendance_table;
217
+    }
218 218
 
219
-	public function needs_name_and_description()
220
-	{
221
-		return false;
222
-	}
219
+    public function needs_name_and_description()
220
+    {
221
+        return false;
222
+    }
223 223
 
224
-	public function needs_max()
225
-	{
226
-		return false;
227
-	}
224
+    public function needs_max()
225
+    {
226
+        return false;
227
+    }
228 228
 
229
-	public function needs_results()
230
-	{
231
-		return false;
232
-	}
229
+    public function needs_results()
230
+    {
231
+        return false;
232
+    }
233 233
 
234
-	/**
235
-	 * @return string
236
-	 */
237
-	public function get_name()
238
-	{
239
-		$this->get_attendance_data();
240
-		$attendance_title = isset($this->attendance_data['name']) ? $this->attendance_data['name'] : '';
241
-		$attendance_qualify_title = isset($this->attendance_data['attendance_qualify_title']) ? $this->attendance_data['attendance_qualify_title'] : '';
242
-		if ( isset($attendance_qualify_title) && $attendance_qualify_title != '') {
243
-			return $this->attendance_data['attendance_qualify_title'];
244
-		} else {
245
-			return $attendance_title;
246
-		}
247
-	}
234
+    /**
235
+     * @return string
236
+     */
237
+    public function get_name()
238
+    {
239
+        $this->get_attendance_data();
240
+        $attendance_title = isset($this->attendance_data['name']) ? $this->attendance_data['name'] : '';
241
+        $attendance_qualify_title = isset($this->attendance_data['attendance_qualify_title']) ? $this->attendance_data['attendance_qualify_title'] : '';
242
+        if ( isset($attendance_qualify_title) && $attendance_qualify_title != '') {
243
+            return $this->attendance_data['attendance_qualify_title'];
244
+        } else {
245
+            return $attendance_title;
246
+        }
247
+    }
248 248
 
249
-	/**
250
-	 * @return string
251
-	 */
252
-	public function get_description()
253
-	{
254
-		return '';
255
-	}
249
+    /**
250
+     * @return string
251
+     */
252
+    public function get_description()
253
+    {
254
+        return '';
255
+    }
256 256
 
257
-	/**
258
-	 * Check if this still links to an exercise
259
-	 */
260
-	public function is_valid_link()
261
-	{
262
-		$session_id = api_get_session_id();
263
-		$sql = 'SELECT count(att.id) FROM '.$this->get_attendance_table().' att
257
+    /**
258
+     * Check if this still links to an exercise
259
+     */
260
+    public function is_valid_link()
261
+    {
262
+        $session_id = api_get_session_id();
263
+        $sql = 'SELECT count(att.id) FROM '.$this->get_attendance_table().' att
264 264
         		 WHERE att.c_id = '.$this->course_id.' AND att.id = '.intval($this->get_ref_id()).' ';
265
-		$result = Database::query($sql);
266
-		$number = Database::fetch_row($result);
267
-		return ($number[0] != 0);
268
-	}
265
+        $result = Database::query($sql);
266
+        $number = Database::fetch_row($result);
267
+        return ($number[0] != 0);
268
+    }
269 269
 
270
-	public function get_test_id()
271
-	{
272
-		return 'DEBUG:ID';
273
-	}
270
+    public function get_test_id()
271
+    {
272
+        return 'DEBUG:ID';
273
+    }
274 274
 
275
-	public function get_link()
276
-	{
277
-		//it was extracts the attendance id
278
-		$session_id = api_get_session_id();
279
-		$sql = 'SELECT * FROM '.$this->get_attendance_table().' att
275
+    public function get_link()
276
+    {
277
+        //it was extracts the attendance id
278
+        $session_id = api_get_session_id();
279
+        $sql = 'SELECT * FROM '.$this->get_attendance_table().' att
280 280
     			WHERE att.c_id = '.$this->course_id.' AND att.id = '.intval($this->get_ref_id()).' ';
281
-		$result = Database::query($sql);
282
-		$row = Database::fetch_array($result,'ASSOC');
283
-		$attendance_id = $row['id'];
284
-		$url = api_get_path(WEB_PATH).'main/attendance/index.php?action=attendance_sheet_list&gradebook=view&attendance_id='.$attendance_id.'&session_id='.$session_id.'&cidReq='.$this->get_course_code();
281
+        $result = Database::query($sql);
282
+        $row = Database::fetch_array($result,'ASSOC');
283
+        $attendance_id = $row['id'];
284
+        $url = api_get_path(WEB_PATH).'main/attendance/index.php?action=attendance_sheet_list&gradebook=view&attendance_id='.$attendance_id.'&session_id='.$session_id.'&cidReq='.$this->get_course_code();
285 285
 
286
-		return $url;
287
-	}
286
+        return $url;
287
+    }
288 288
 
289
-	/**
290
-	 * @return array|bool
291
-	 */
292
-	private function get_attendance_data()
293
-	{
294
-		$tbl_name = $this->get_attendance_table();
295
-		$session_id = api_get_session_id();
296
-		if ($tbl_name == '') {
297
-			return false;
298
-		} elseif (!isset($this->attendance_data)) {
299
-			$sql = 'SELECT * FROM '.$this->get_attendance_table().' att
289
+    /**
290
+     * @return array|bool
291
+     */
292
+    private function get_attendance_data()
293
+    {
294
+        $tbl_name = $this->get_attendance_table();
295
+        $session_id = api_get_session_id();
296
+        if ($tbl_name == '') {
297
+            return false;
298
+        } elseif (!isset($this->attendance_data)) {
299
+            $sql = 'SELECT * FROM '.$this->get_attendance_table().' att
300 300
 					WHERE att.c_id = '.$this->course_id.' AND att.id = '.intval($this->get_ref_id()).' ';
301
-			$query = Database::query($sql);
302
-			$this->attendance_data = Database::fetch_array($query);
303
-		}
304
-		return $this->attendance_data;
305
-	}
301
+            $query = Database::query($sql);
302
+            $this->attendance_data = Database::fetch_array($query);
303
+        }
304
+        return $this->attendance_data;
305
+    }
306 306
 
307
-	/**
308
-	 * @return string
309
-	 */
310
-	public function get_icon_name()
311
-	{
312
-		return 'attendance';
313
-	}
307
+    /**
308
+     * @return string
309
+     */
310
+    public function get_icon_name()
311
+    {
312
+        return 'attendance';
313
+    }
314 314
 }
Please login to merge, or discard this patch.
main/gradebook/lib/be/surveylink.class.php 1 patch
Indentation   +243 added lines, -243 removed lines patch added patch discarded remove patch
@@ -8,94 +8,94 @@  discard block
 block discarded – undo
8 8
  */
9 9
 class SurveyLink extends AbstractLink
10 10
 {
11
-	private $survey_table = null;
12
-
13
-	/**
14
-	 * Constructor
15
-	 */
16
-	public function __construct()
17
-	{
18
-		parent::__construct();
19
-		$this->set_type(LINK_SURVEY);
20
-	}
21
-
22
-	public function get_name()
23
-	{
24
-		$this->get_survey_data();
25
-		return $this->survey_data['code'].': '.self::html_to_text($this->survey_data['title']);
26
-	}
27
-
28
-	public function get_description()
29
-	{
30
-		$this->get_survey_data();
31
-		return $this->survey_data['subtitle'];
32
-	}
33
-
34
-	public function get_type_name()
35
-	{
36
-		return get_lang('Survey');
37
-	}
38
-
39
-	public function is_allowed_to_change_name()
40
-	{
41
-		return false;
42
-	}
43
-
44
-	public function needs_name_and_description()
45
-	{
46
-		return false;
47
-	}
48
-
49
-	public function needs_max()
50
-	{
51
-		return false;
52
-	}
53
-
54
-	public function needs_results()
55
-	{
56
-		return false;
57
-	}
58
-
59
-	/**
60
-	 * Generates an array of all surveys available.
61
-	 * @return array 2-dimensional array - every element contains 2 subelements (id, name)
62
-	 */
63
-	public function get_all_links()
64
-	{
65
-		if (empty($this->course_code)) {
66
-			die('Error in get_all_links() : course code not set');
67
-		}
68
-		$tbl_survey = $this->get_survey_table();
69
-		$session_id = api_get_session_id();
70
-		$course_id = api_get_course_int_id();
71
-		$sql = 'SELECT survey_id, title, code FROM '.$tbl_survey.'
11
+    private $survey_table = null;
12
+
13
+    /**
14
+     * Constructor
15
+     */
16
+    public function __construct()
17
+    {
18
+        parent::__construct();
19
+        $this->set_type(LINK_SURVEY);
20
+    }
21
+
22
+    public function get_name()
23
+    {
24
+        $this->get_survey_data();
25
+        return $this->survey_data['code'].': '.self::html_to_text($this->survey_data['title']);
26
+    }
27
+
28
+    public function get_description()
29
+    {
30
+        $this->get_survey_data();
31
+        return $this->survey_data['subtitle'];
32
+    }
33
+
34
+    public function get_type_name()
35
+    {
36
+        return get_lang('Survey');
37
+    }
38
+
39
+    public function is_allowed_to_change_name()
40
+    {
41
+        return false;
42
+    }
43
+
44
+    public function needs_name_and_description()
45
+    {
46
+        return false;
47
+    }
48
+
49
+    public function needs_max()
50
+    {
51
+        return false;
52
+    }
53
+
54
+    public function needs_results()
55
+    {
56
+        return false;
57
+    }
58
+
59
+    /**
60
+     * Generates an array of all surveys available.
61
+     * @return array 2-dimensional array - every element contains 2 subelements (id, name)
62
+     */
63
+    public function get_all_links()
64
+    {
65
+        if (empty($this->course_code)) {
66
+            die('Error in get_all_links() : course code not set');
67
+        }
68
+        $tbl_survey = $this->get_survey_table();
69
+        $session_id = api_get_session_id();
70
+        $course_id = api_get_course_int_id();
71
+        $sql = 'SELECT survey_id, title, code FROM '.$tbl_survey.'
72 72
 				WHERE c_id = '.$course_id.' AND session_id = '.intval($session_id).'';
73
-		$result = Database::query($sql);
74
-		while ($data = Database::fetch_array($result)) {
75
-			$links[] = array(
76
-				$data['survey_id'],
77
-				api_trunc_str(
78
-					$data['code'] . ': ' . self::html_to_text($data['title']),
79
-					80
80
-				)
81
-			);
82
-		}
83
-
84
-		return isset($links) ? $links : null;
85
-	}
86
-
87
-	/**
88
-	 * Generates an array of surveys that a teacher hasn't created a link for.
89
-	 * @return array 2-dimensional array - every element contains 2 subelements (id, name)
90
-	 */
91
-	public function get_not_created_links()
92
-	{
93
-		if (empty($this->course_code)) {
94
-			die('Error in get_not_created_links() : course code not set');
95
-		}
96
-		$tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
97
-
98
-		$sql = 'SELECT survey_id, title, code
73
+        $result = Database::query($sql);
74
+        while ($data = Database::fetch_array($result)) {
75
+            $links[] = array(
76
+                $data['survey_id'],
77
+                api_trunc_str(
78
+                    $data['code'] . ': ' . self::html_to_text($data['title']),
79
+                    80
80
+                )
81
+            );
82
+        }
83
+
84
+        return isset($links) ? $links : null;
85
+    }
86
+
87
+    /**
88
+     * Generates an array of surveys that a teacher hasn't created a link for.
89
+     * @return array 2-dimensional array - every element contains 2 subelements (id, name)
90
+     */
91
+    public function get_not_created_links()
92
+    {
93
+        if (empty($this->course_code)) {
94
+            die('Error in get_not_created_links() : course code not set');
95
+        }
96
+        $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
97
+
98
+        $sql = 'SELECT survey_id, title, code
99 99
     			FROM '.$this->get_survey_table().' AS srv
100 100
 				WHERE survey_id NOT IN
101 101
 					(
@@ -106,28 +106,28 @@  discard block
 block discarded – undo
106 106
 					)
107 107
 					AND srv.session_id = '.api_get_session_id();
108 108
 
109
-		$result = Database::query($sql);
110
-
111
-		$links = array();
112
-		while ($data = Database::fetch_array($result)) {
113
-			$links[] = array(
114
-				$data['survey_id'],
115
-				api_trunc_str($data['code'].': '.self::html_to_text($data['title']), 80)
116
-			);
117
-		}
118
-		return $links;
119
-	}
120
-
121
-	/**
122
-	 * Has anyone done this survey yet?
123
-	 */
124
-	public function has_results($stud_id=null)
125
-	{
126
-		$ref_id = intval($this->get_ref_id());
127
-		$session_id = api_get_session_id();
128
-		$tbl_survey = Database::get_course_table(TABLE_SURVEY);
129
-		$tbl_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION);
130
-		$sql = "SELECT
109
+        $result = Database::query($sql);
110
+
111
+        $links = array();
112
+        while ($data = Database::fetch_array($result)) {
113
+            $links[] = array(
114
+                $data['survey_id'],
115
+                api_trunc_str($data['code'].': '.self::html_to_text($data['title']), 80)
116
+            );
117
+        }
118
+        return $links;
119
+    }
120
+
121
+    /**
122
+     * Has anyone done this survey yet?
123
+     */
124
+    public function has_results($stud_id=null)
125
+    {
126
+        $ref_id = intval($this->get_ref_id());
127
+        $session_id = api_get_session_id();
128
+        $tbl_survey = Database::get_course_table(TABLE_SURVEY);
129
+        $tbl_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION);
130
+        $sql = "SELECT
131 131
 				COUNT(i.answered)
132 132
 				FROM $tbl_survey AS s
133 133
 				JOIN $tbl_survey_invitation AS i ON s.code = i.survey_code
@@ -137,30 +137,30 @@  discard block
 block discarded – undo
137 137
 					s.survey_id = $ref_id AND
138 138
 					i.session_id = $session_id";
139 139
 
140
-		$sql_result = Database::query($sql);
141
-		$data = Database::fetch_array($sql_result);
140
+        $sql_result = Database::query($sql);
141
+        $data = Database::fetch_array($sql_result);
142 142
 
143
-		return ($data[0] != 0);
144
-	}
143
+        return ($data[0] != 0);
144
+    }
145 145
 
146
-	/**
147
-	 * @param int $stud_id
148
-	 * @return array|null
149
-	 */
150
-	public function calc_score($stud_id = null, $type = null)
151
-	{
152
-		// Note: Max score is assumed to be always 1 for surveys,
153
-		// only student's participation is to be taken into account.
154
-		$max_score = 1;
146
+    /**
147
+     * @param int $stud_id
148
+     * @return array|null
149
+     */
150
+    public function calc_score($stud_id = null, $type = null)
151
+    {
152
+        // Note: Max score is assumed to be always 1 for surveys,
153
+        // only student's participation is to be taken into account.
154
+        $max_score = 1;
155 155
 
156
-		$ref_id = intval($this->get_ref_id());
157
-		$session_id = api_get_session_id();
158
-		$tbl_survey = Database::get_course_table(TABLE_SURVEY);
159
-		$tbl_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION);
156
+        $ref_id = intval($this->get_ref_id());
157
+        $session_id = api_get_session_id();
158
+        $tbl_survey = Database::get_course_table(TABLE_SURVEY);
159
+        $tbl_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION);
160 160
 
161
-		$get_individual_score = !is_null($stud_id);
161
+        $get_individual_score = !is_null($stud_id);
162 162
 
163
-		$sql = "SELECT i.answered
163
+        $sql = "SELECT i.answered
164 164
 				FROM $tbl_survey AS s
165 165
 				JOIN $tbl_survey_invitation AS i
166 166
 				ON s.code = i.survey_code
@@ -171,131 +171,131 @@  discard block
 block discarded – undo
171 171
 					i.session_id = $session_id
172 172
 				";
173 173
 
174
-		if ($get_individual_score) {
175
-			$sql .= ' AND i.user = '.intval($stud_id);
176
-		}
177
-
178
-		$sql_result = Database::query($sql);
179
-
180
-		if ($get_individual_score) {
181
-			// for 1 student
182
-			if ($data = Database::fetch_array($sql_result)) {
183
-				return array($data['answered'] ? $max_score : 0, $max_score);
184
-			}
185
-			return array(0, $max_score);
186
-		} else {
187
-			// for all the students -> get average
188
-			$rescount = 0;
189
-			$sum = 0;
190
-			$bestResult = 0;
191
-			$weight = 0;
192
-			while ($data = Database::fetch_array($sql_result)) {
193
-				$sum += $data['answered'] ? $max_score : 0;
194
-				$rescount++;
195
-				if ($data['answered'] > $bestResult) {
196
-					$bestResult = $data['answered'];
197
-					$weight = $assignment['qualification'];
198
-				}
199
-			}
200
-			$sum = $sum / $max_score;
201
-
202
-			if ($rescount == 0) {
203
-				return null;
204
-			}
205
-
206
-			switch ($type) {
207
-				case 'best':
208
-					return array($bestResult, $rescount);
209
-					break;
210
-				case 'average':
211
-					return array($sum, $rescount);
212
-					break;
213
-				case 'ranking':
214
-					return null;
215
-					break;
216
-				default:
217
-					return array($sum, $rescount);
218
-					break;
219
-			}
220
-		}
221
-	}
222
-
223
-	/**
224
-	 * Lazy load function to get the database table of the surveys
225
-	 */
226
-	private function get_survey_table()
227
-	{
228
-		$this->survey_table = Database :: get_course_table(TABLE_SURVEY);
229
-		return $this->survey_table;
230
-	}
231
-
232
-	/**
233
-	 * Check if this still links to a survey
234
-	 */
235
-	public function is_valid_link()
236
-	{
237
-		$session_id = api_get_session_id();
238
-		$sql = 'SELECT count(survey_id) FROM '.$this->get_survey_table().'
174
+        if ($get_individual_score) {
175
+            $sql .= ' AND i.user = '.intval($stud_id);
176
+        }
177
+
178
+        $sql_result = Database::query($sql);
179
+
180
+        if ($get_individual_score) {
181
+            // for 1 student
182
+            if ($data = Database::fetch_array($sql_result)) {
183
+                return array($data['answered'] ? $max_score : 0, $max_score);
184
+            }
185
+            return array(0, $max_score);
186
+        } else {
187
+            // for all the students -> get average
188
+            $rescount = 0;
189
+            $sum = 0;
190
+            $bestResult = 0;
191
+            $weight = 0;
192
+            while ($data = Database::fetch_array($sql_result)) {
193
+                $sum += $data['answered'] ? $max_score : 0;
194
+                $rescount++;
195
+                if ($data['answered'] > $bestResult) {
196
+                    $bestResult = $data['answered'];
197
+                    $weight = $assignment['qualification'];
198
+                }
199
+            }
200
+            $sum = $sum / $max_score;
201
+
202
+            if ($rescount == 0) {
203
+                return null;
204
+            }
205
+
206
+            switch ($type) {
207
+                case 'best':
208
+                    return array($bestResult, $rescount);
209
+                    break;
210
+                case 'average':
211
+                    return array($sum, $rescount);
212
+                    break;
213
+                case 'ranking':
214
+                    return null;
215
+                    break;
216
+                default:
217
+                    return array($sum, $rescount);
218
+                    break;
219
+            }
220
+        }
221
+    }
222
+
223
+    /**
224
+     * Lazy load function to get the database table of the surveys
225
+     */
226
+    private function get_survey_table()
227
+    {
228
+        $this->survey_table = Database :: get_course_table(TABLE_SURVEY);
229
+        return $this->survey_table;
230
+    }
231
+
232
+    /**
233
+     * Check if this still links to a survey
234
+     */
235
+    public function is_valid_link()
236
+    {
237
+        $session_id = api_get_session_id();
238
+        $sql = 'SELECT count(survey_id) FROM '.$this->get_survey_table().'
239 239
         		 WHERE
240 240
         		 	c_id = '.$this->course_id.' AND
241 241
         		 	survey_id = '.intval($this->get_ref_id()).' AND
242 242
         		 	session_id='.intval($session_id).'';
243
-		$result = Database::query($sql);
244
-		$number = Database::fetch_row($result);
245
-		return ($number[0] != 0);
246
-	}
247
-
248
-	public function get_test_id()
249
-	{
250
-		return 'DEBUG:ID';
251
-	}
252
-
253
-	public function get_link()
254
-	{
255
-		if (api_is_allowed_to_edit()) { // Let students make access only through "Surveys" tool.
256
-			$tbl_name = $this->get_survey_table();
257
-			$session_id = api_get_session_id();
258
-			if ($tbl_name != '') {
259
-				$sql = 'SELECT survey_id FROM '.$this->get_survey_table().'
243
+        $result = Database::query($sql);
244
+        $number = Database::fetch_row($result);
245
+        return ($number[0] != 0);
246
+    }
247
+
248
+    public function get_test_id()
249
+    {
250
+        return 'DEBUG:ID';
251
+    }
252
+
253
+    public function get_link()
254
+    {
255
+        if (api_is_allowed_to_edit()) { // Let students make access only through "Surveys" tool.
256
+            $tbl_name = $this->get_survey_table();
257
+            $session_id = api_get_session_id();
258
+            if ($tbl_name != '') {
259
+                $sql = 'SELECT survey_id FROM '.$this->get_survey_table().'
260 260
     					WHERE
261 261
     						c_id = '.$this->course_id.' AND
262 262
     						survey_id = '.intval($this->get_ref_id()).' AND
263 263
     						session_id = '.intval($session_id).' ';
264
-				$result = Database::query($sql);
265
-				$row = Database::fetch_array($result, 'ASSOC');
266
-				$survey_id = $row['survey_id'];
267
-				return api_get_path(WEB_PATH).'main/survey/reporting.php?cidReq='.$this->get_course_code().'&survey_id='.$survey_id;
268
-			}
269
-		}
270
-		return null;
271
-	}
272
-
273
-	private function get_survey_data()
274
-	{
275
-		$tbl_name = $this->get_survey_table();
276
-		$session_id = api_get_session_id();
277
-		if ($tbl_name == '') {
278
-			return false;
279
-		} elseif (!isset($this->survey_data)) {
280
-			$sql = 'SELECT * FROM '.$tbl_name.'
264
+                $result = Database::query($sql);
265
+                $row = Database::fetch_array($result, 'ASSOC');
266
+                $survey_id = $row['survey_id'];
267
+                return api_get_path(WEB_PATH).'main/survey/reporting.php?cidReq='.$this->get_course_code().'&survey_id='.$survey_id;
268
+            }
269
+        }
270
+        return null;
271
+    }
272
+
273
+    private function get_survey_data()
274
+    {
275
+        $tbl_name = $this->get_survey_table();
276
+        $session_id = api_get_session_id();
277
+        if ($tbl_name == '') {
278
+            return false;
279
+        } elseif (!isset($this->survey_data)) {
280
+            $sql = 'SELECT * FROM '.$tbl_name.'
281 281
 					WHERE
282 282
 						c_id = '.$this->course_id.' AND
283 283
 						survey_id = '.intval($this->get_ref_id()).' AND
284 284
 						session_id='.intval($session_id).'';
285
-			$query = Database::query($sql);
286
-			$this->survey_data = Database::fetch_array($query);
287
-		}
288
-		return $this->survey_data;
289
-	}
290
-
291
-	public function get_icon_name()
292
-	{
293
-		return 'survey';
294
-	}
295
-
296
-	private static function html_to_text($string)
297
-	{
298
-		return strip_tags($string);
299
-		//return trim(api_html_entity_decode(strip_tags(str_ireplace(array('<p>', '</p>', '<br />', '<br/>', '<br>'), array('', ' ', ' ', ' ', ' '), $string)), ENT_QUOTES));
300
-	}
285
+            $query = Database::query($sql);
286
+            $this->survey_data = Database::fetch_array($query);
287
+        }
288
+        return $this->survey_data;
289
+    }
290
+
291
+    public function get_icon_name()
292
+    {
293
+        return 'survey';
294
+    }
295
+
296
+    private static function html_to_text($string)
297
+    {
298
+        return strip_tags($string);
299
+        //return trim(api_html_entity_decode(strip_tags(str_ireplace(array('<p>', '</p>', '<br />', '<br/>', '<br>'), array('', ' ', ' ', ' ', ' '), $string)), ENT_QUOTES));
300
+    }
301 301
 }
Please login to merge, or discard this patch.
main/gradebook/lib/be/forumthreadlink.class.php 1 patch
Indentation   +259 added lines, -259 removed lines patch added patch discarded remove patch
@@ -10,54 +10,54 @@  discard block
 block discarded – undo
10 10
  */
11 11
 class ForumThreadLink extends AbstractLink
12 12
 {
13
-	private $forum_thread_table = null;
14
-	private $itemprop_table = null;
15
-
16
-	/**
17
-	 * Constructor
18
-	 */
19
-	public function __construct()
20
-	{
21
-		parent::__construct();
22
-		$this->set_type(LINK_FORUM_THREAD);
23
-	}
24
-
25
-	/**
26
-	 * @return string
27
-	 */
28
-	public function get_type_name()
29
-	{
30
-		return get_lang('ForumThreads');
31
-	}
32
-
33
-	/**
34
-	 * @return bool
35
-	 */
36
-	public function is_allowed_to_change_name()
37
-	{
38
-		return false;
39
-	}
40
-
41
-	/**
42
-	 * Generate an array of exercises that a teacher hasn't created a link for.
43
-	 * @return array 2-dimensional array - every element contains 2 subelements (id, name)
44
-	 */
45
-	public function get_not_created_links()
46
-	{
47
-		if (empty($this->course_code)) {
48
-			die('Error in get_not_created_links() : course code not set');
49
-		}
50
-
51
-		$tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
52
-
53
-		$sql = 'SELECT thread_id,thread_title,thread_title_qualify FROM '.$this->get_forum_thread_table()
54
-			.' forum_thread WHERE thread_id NOT IN'
55
-			.' (SELECT ref_id FROM '.$tbl_grade_links
56
-			.' WHERE type = '.LINK_FORUM_THREAD
57
-			." AND c_id = ".intval($this->course_id)
58
-			.') AND forum_thread.session_id='.api_get_session_id().'';
59
-
60
-		$result = Database::query($sql);
13
+    private $forum_thread_table = null;
14
+    private $itemprop_table = null;
15
+
16
+    /**
17
+     * Constructor
18
+     */
19
+    public function __construct()
20
+    {
21
+        parent::__construct();
22
+        $this->set_type(LINK_FORUM_THREAD);
23
+    }
24
+
25
+    /**
26
+     * @return string
27
+     */
28
+    public function get_type_name()
29
+    {
30
+        return get_lang('ForumThreads');
31
+    }
32
+
33
+    /**
34
+     * @return bool
35
+     */
36
+    public function is_allowed_to_change_name()
37
+    {
38
+        return false;
39
+    }
40
+
41
+    /**
42
+     * Generate an array of exercises that a teacher hasn't created a link for.
43
+     * @return array 2-dimensional array - every element contains 2 subelements (id, name)
44
+     */
45
+    public function get_not_created_links()
46
+    {
47
+        if (empty($this->course_code)) {
48
+            die('Error in get_not_created_links() : course code not set');
49
+        }
50
+
51
+        $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
52
+
53
+        $sql = 'SELECT thread_id,thread_title,thread_title_qualify FROM '.$this->get_forum_thread_table()
54
+            .' forum_thread WHERE thread_id NOT IN'
55
+            .' (SELECT ref_id FROM '.$tbl_grade_links
56
+            .' WHERE type = '.LINK_FORUM_THREAD
57
+            ." AND c_id = ".intval($this->course_id)
58
+            .') AND forum_thread.session_id='.api_get_session_id().'';
59
+
60
+        $result = Database::query($sql);
61 61
 
62 62
         $cats = array();
63 63
         while ($data = Database::fetch_array($result)) {
@@ -72,29 +72,29 @@  discard block
 block discarded – undo
72 72
         }
73 73
 
74 74
         return $cats;
75
-	}
76
-
77
-	/**
78
-	 * Generate an array of all exercises available.
79
-	 * @return array 2-dimensional array - every element contains 2 subelements (id, name)
80
-	 */
81
-	public function get_all_links()
82
-	{
83
-		if (empty($this->course_code)) {
84
-			die('Error in get_not_created_links() : course code not set');
85
-		}
86
-
87
-		$tbl_grade_links 	= Database :: get_course_table(TABLE_FORUM_THREAD);
88
-		$tbl_item_property	= Database :: get_course_table(TABLE_ITEM_PROPERTY);
89
-		$session_id = api_get_session_id();
90
-
91
-		if ($session_id) {
92
-			$session_condition = 'tl.session_id='.api_get_session_id();
93
-		} else {
94
-			$session_condition = '(tl.session_id = 0 OR tl.session_id IS NULL)';
95
-		}
96
-
97
-		$sql = 'SELECT tl.thread_id, tl.thread_title, tl.thread_title_qualify
75
+    }
76
+
77
+    /**
78
+     * Generate an array of all exercises available.
79
+     * @return array 2-dimensional array - every element contains 2 subelements (id, name)
80
+     */
81
+    public function get_all_links()
82
+    {
83
+        if (empty($this->course_code)) {
84
+            die('Error in get_not_created_links() : course code not set');
85
+        }
86
+
87
+        $tbl_grade_links 	= Database :: get_course_table(TABLE_FORUM_THREAD);
88
+        $tbl_item_property	= Database :: get_course_table(TABLE_ITEM_PROPERTY);
89
+        $session_id = api_get_session_id();
90
+
91
+        if ($session_id) {
92
+            $session_condition = 'tl.session_id='.api_get_session_id();
93
+        } else {
94
+            $session_condition = '(tl.session_id = 0 OR tl.session_id IS NULL)';
95
+        }
96
+
97
+        $sql = 'SELECT tl.thread_id, tl.thread_title, tl.thread_title_qualify
98 98
 				FROM '.$tbl_grade_links.' tl INNER JOIN '.$tbl_item_property.' ip
99 99
 				ON (tl.thread_id = ip.ref AND tl.c_id = ip.c_id )
100 100
 				WHERE
@@ -105,24 +105,24 @@  discard block
 block discarded – undo
105 105
                     '.$session_condition.'
106 106
                 ';
107 107
 
108
-		$result = Database::query($sql);
108
+        $result = Database::query($sql);
109 109
 
110
-		while ($data = Database::fetch_array($result)) {
111
-			if ( isset($data['thread_title_qualify']) and $data['thread_title_qualify']!=""){
112
-				$cats[] = array ($data['thread_id'], $data['thread_title_qualify']);
113
-			} else {
114
-				$cats[] = array ($data['thread_id'], $data['thread_title']);
115
-			}
116
-		}
117
-		$my_cats = isset($cats) ? $cats : null;
110
+        while ($data = Database::fetch_array($result)) {
111
+            if ( isset($data['thread_title_qualify']) and $data['thread_title_qualify']!=""){
112
+                $cats[] = array ($data['thread_id'], $data['thread_title_qualify']);
113
+            } else {
114
+                $cats[] = array ($data['thread_id'], $data['thread_title']);
115
+            }
116
+        }
117
+        $my_cats = isset($cats) ? $cats : null;
118 118
 
119
-		return $my_cats;
120
-	}
119
+        return $my_cats;
120
+    }
121 121
 
122 122
     /**
123
-    * Has anyone done this exercise yet ?
124
-    * @return int
125
-    */
123
+     * Has anyone done this exercise yet ?
124
+     * @return int
125
+     */
126 126
     public function has_results()
127 127
     {
128 128
         $table = Database :: get_course_table(TABLE_FORUM_POST);
@@ -134,40 +134,40 @@  discard block
 block discarded – undo
134 134
         $number = Database::fetch_row($result);
135 135
 
136 136
         return $number[0] != 0;
137
-	}
137
+    }
138 138
 
139
-	/**
140
-	 * @param int    $stud_id
139
+    /**
140
+     * @param int    $stud_id
141 141
      * @param string $type
142 142
      *
143
-	 * @return array|null
144
-	 */
145
-	public function calc_score($stud_id = null, $type = null)
146
-	{
143
+     * @return array|null
144
+     */
145
+    public function calc_score($stud_id = null, $type = null)
146
+    {
147 147
         require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php';
148 148
         $threadInfo = get_thread_information($this->get_ref_id());
149 149
 
150
-		$thread_qualify = Database :: get_course_table(TABLE_FORUM_THREAD_QUALIFY);
150
+        $thread_qualify = Database :: get_course_table(TABLE_FORUM_THREAD_QUALIFY);
151 151
 
152
-		$sql = 'SELECT thread_qualify_max
152
+        $sql = 'SELECT thread_qualify_max
153 153
 		        FROM '.Database :: get_course_table(TABLE_FORUM_THREAD)."
154 154
   				WHERE c_id = ".$this->course_id." AND thread_id = '".$this->get_ref_id()."'";
155
-		$query = Database::query($sql);
156
-		$assignment = Database::fetch_array($query);
155
+        $query = Database::query($sql);
156
+        $assignment = Database::fetch_array($query);
157 157
 
158
-		$sql = "SELECT * FROM $thread_qualify
158
+        $sql = "SELECT * FROM $thread_qualify
159 159
 				WHERE c_id = ".$this->course_id." AND thread_id = ".$this->get_ref_id();
160
-		if (isset($stud_id)) {
161
-			$sql .= ' AND user_id = '.intval($stud_id);
162
-		}
160
+        if (isset($stud_id)) {
161
+            $sql .= ' AND user_id = '.intval($stud_id);
162
+        }
163 163
 
164
-		// order by id, that way the student's first attempt is accessed first
165
-		$sql .= ' ORDER BY qualify_time DESC';
164
+        // order by id, that way the student's first attempt is accessed first
165
+        $sql .= ' ORDER BY qualify_time DESC';
166 166
 
167
-		$scores = Database::query($sql);
167
+        $scores = Database::query($sql);
168 168
 
169
-		// for 1 student
170
-		if (isset($stud_id)) {
169
+        // for 1 student
170
+        if (isset($stud_id)) {
171 171
             if ($threadInfo['thread_peer_qualify'] == 0) {
172 172
                 // Classic way of calculate score
173 173
                 if ($data = Database::fetch_array($scores)) {
@@ -195,174 +195,174 @@  discard block
 block discarded – undo
195 195
                 }
196 196
                 return [$score/$counter, $assignment['thread_qualify_max']];
197 197
             }
198
-		} else {
199
-			// All students -> get average
200
-			$students = array();  // user list, needed to make sure we only
201
-			// take first attempts into account
202
-			$counter = 0;
203
-			$sum = 0;
204
-			$bestResult = 0;
205
-			$weight = 0;
206
-			$sumResult = 0;
207
-
208
-			while ($data = Database::fetch_array($scores)) {
209
-				if (!(array_key_exists($data['user_id'], $students))) {
210
-					if ($assignment['thread_qualify_max'] != 0) {
211
-						$students[$data['user_id']] = $data['qualify'];
212
-						$counter++;
213
-						$sum += $data['qualify'] / $assignment['thread_qualify_max'];
214
-						$sumResult += $data['qualify'];
215
-						if ($data['qualify'] > $bestResult) {
216
-							$bestResult = $data['qualify'];
217
-						}
218
-						$weight = $assignment['thread_qualify_max'];
219
-					}
220
-				}
221
-			}
222
-
223
-			if ($counter == 0) {
224
-				return null;
225
-			} else {
226
-				switch ($type) {
227
-					case 'best':
228
-						return array($bestResult, $weight);
229
-						break;
230
-					case 'average':
231
-						return array($sumResult/$counter, $weight);
232
-						break;
233
-					case 'ranking':
234
-						return AbstractLink::getCurrentUserRanking($stud_id, $students);
235
-						break;
236
-					default:
237
-						return array($sum, $counter);
238
-						break;
239
-				}
240
-			}
241
-		}
242
-	}
243
-
244
-	/**
245
-	 * Lazy load function to get the database table of the student publications
246
-	 */
247
-	private function get_forum_thread_table()
248
-	{
249
-		return $this->forum_thread_table = Database :: get_course_table(TABLE_FORUM_THREAD);
250
-	}
251
-
252
-	public function needs_name_and_description()
253
-	{
254
-		return false;
255
-	}
256
-
257
-	public function needs_max()
258
-	{
259
-		return false;
260
-	}
261
-
262
-	public function needs_results()
263
-	{
264
-		return false;
265
-	}
198
+        } else {
199
+            // All students -> get average
200
+            $students = array();  // user list, needed to make sure we only
201
+            // take first attempts into account
202
+            $counter = 0;
203
+            $sum = 0;
204
+            $bestResult = 0;
205
+            $weight = 0;
206
+            $sumResult = 0;
207
+
208
+            while ($data = Database::fetch_array($scores)) {
209
+                if (!(array_key_exists($data['user_id'], $students))) {
210
+                    if ($assignment['thread_qualify_max'] != 0) {
211
+                        $students[$data['user_id']] = $data['qualify'];
212
+                        $counter++;
213
+                        $sum += $data['qualify'] / $assignment['thread_qualify_max'];
214
+                        $sumResult += $data['qualify'];
215
+                        if ($data['qualify'] > $bestResult) {
216
+                            $bestResult = $data['qualify'];
217
+                        }
218
+                        $weight = $assignment['thread_qualify_max'];
219
+                    }
220
+                }
221
+            }
222
+
223
+            if ($counter == 0) {
224
+                return null;
225
+            } else {
226
+                switch ($type) {
227
+                    case 'best':
228
+                        return array($bestResult, $weight);
229
+                        break;
230
+                    case 'average':
231
+                        return array($sumResult/$counter, $weight);
232
+                        break;
233
+                    case 'ranking':
234
+                        return AbstractLink::getCurrentUserRanking($stud_id, $students);
235
+                        break;
236
+                    default:
237
+                        return array($sum, $counter);
238
+                        break;
239
+                }
240
+            }
241
+        }
242
+    }
243
+
244
+    /**
245
+     * Lazy load function to get the database table of the student publications
246
+     */
247
+    private function get_forum_thread_table()
248
+    {
249
+        return $this->forum_thread_table = Database :: get_course_table(TABLE_FORUM_THREAD);
250
+    }
251
+
252
+    public function needs_name_and_description()
253
+    {
254
+        return false;
255
+    }
256
+
257
+    public function needs_max()
258
+    {
259
+        return false;
260
+    }
261
+
262
+    public function needs_results()
263
+    {
264
+        return false;
265
+    }
266 266
 
267 267
     /**
268 268
      * @return string
269 269
      */
270
-	public function get_name()
271
-	{
272
-		$this->get_exercise_data();
273
-		$thread_title=isset($this->exercise_data['thread_title']) ? $this->exercise_data['thread_title'] : '';
274
-		$thread_title_qualify=isset($this->exercise_data['thread_title_qualify']) ? $this->exercise_data['thread_title_qualify'] : '';
275
-		if ( isset($thread_title_qualify) && $thread_title_qualify!="") {
276
-			return $this->exercise_data['thread_title_qualify'];
277
-		} else {
278
-			return $thread_title;
279
-		}
280
-	}
270
+    public function get_name()
271
+    {
272
+        $this->get_exercise_data();
273
+        $thread_title=isset($this->exercise_data['thread_title']) ? $this->exercise_data['thread_title'] : '';
274
+        $thread_title_qualify=isset($this->exercise_data['thread_title_qualify']) ? $this->exercise_data['thread_title_qualify'] : '';
275
+        if ( isset($thread_title_qualify) && $thread_title_qualify!="") {
276
+            return $this->exercise_data['thread_title_qualify'];
277
+        } else {
278
+            return $thread_title;
279
+        }
280
+    }
281 281
 
282 282
     /**
283 283
      * @return string
284 284
      */
285
-	public function get_description()
286
-	{
287
-		return '';//$this->exercise_data['description'];
288
-	}
289
-
290
-	/**
291
-	 * Check if this still links to an exercise
292
-	 */
293
-	public function is_valid_link()
294
-	{
295
-		$sql = 'SELECT count(id) from '.$this->get_forum_thread_table().'
285
+    public function get_description()
286
+    {
287
+        return '';//$this->exercise_data['description'];
288
+    }
289
+
290
+    /**
291
+     * Check if this still links to an exercise
292
+     */
293
+    public function is_valid_link()
294
+    {
295
+        $sql = 'SELECT count(id) from '.$this->get_forum_thread_table().'
296 296
         		WHERE c_id = '.$this->course_id.' AND thread_id = '.$this->get_ref_id().' AND session_id='.api_get_session_id().'';
297
-		$result = Database::query($sql);
298
-		$number = Database::fetch_row($result);
299
-		return ($number[0] != 0);
300
-	}
301
-
302
-	public function get_test_id()
303
-	{
304
-		return 'DEBUG:ID';
305
-	}
306
-
307
-	public function get_link()
308
-	{
309
-		//it was extracts the forum id
310
-		$sql = 'SELECT * FROM '.$this->get_forum_thread_table()."
297
+        $result = Database::query($sql);
298
+        $number = Database::fetch_row($result);
299
+        return ($number[0] != 0);
300
+    }
301
+
302
+    public function get_test_id()
303
+    {
304
+        return 'DEBUG:ID';
305
+    }
306
+
307
+    public function get_link()
308
+    {
309
+        //it was extracts the forum id
310
+        $sql = 'SELECT * FROM '.$this->get_forum_thread_table()."
311 311
     			WHERE c_id = '.$this->course_id.' AND thread_id = '".$this->get_ref_id()."' AND session_id = ".api_get_session_id()."";
312
-		$result = Database::query($sql);
313
-		$row    = Database::fetch_array($result,'ASSOC');
314
-		$forum_id=$row['forum_id'];
315
-
316
-		$url = api_get_path(WEB_PATH).'main/forum/viewthread.php?cidReq='.$this->get_course_code().'&thread='.$this->get_ref_id().'&gradebook=view&forum='.$forum_id;
317
-		return $url;
318
-	}
319
-
320
-	private function get_exercise_data()
321
-	{
322
-		$session_id = api_get_session_id();
323
-		if ($session_id) {
324
-			$session_condition = 'session_id='.api_get_session_id();
325
-		} else {
326
-			$session_condition = '(session_id = 0 OR session_id IS NULL)';
327
-		}
328
-
329
-		if (!isset($this->exercise_data)) {
330
-			$sql = 'SELECT * FROM '.$this->get_forum_thread_table().'
312
+        $result = Database::query($sql);
313
+        $row    = Database::fetch_array($result,'ASSOC');
314
+        $forum_id=$row['forum_id'];
315
+
316
+        $url = api_get_path(WEB_PATH).'main/forum/viewthread.php?cidReq='.$this->get_course_code().'&thread='.$this->get_ref_id().'&gradebook=view&forum='.$forum_id;
317
+        return $url;
318
+    }
319
+
320
+    private function get_exercise_data()
321
+    {
322
+        $session_id = api_get_session_id();
323
+        if ($session_id) {
324
+            $session_condition = 'session_id='.api_get_session_id();
325
+        } else {
326
+            $session_condition = '(session_id = 0 OR session_id IS NULL)';
327
+        }
328
+
329
+        if (!isset($this->exercise_data)) {
330
+            $sql = 'SELECT * FROM '.$this->get_forum_thread_table().'
331 331
                     WHERE c_id = '.$this->course_id.' AND  thread_id = '.$this->get_ref_id().' AND '.$session_condition;
332
-			$query = Database::query($sql);
333
-			$this->exercise_data = Database::fetch_array($query);
334
-		}
335
-		return $this->exercise_data;
336
-	}
337
-
338
-	public function get_icon_name()
339
-	{
340
-		return 'forum';
341
-	}
342
-
343
-	function save_linked_data()
344
-	{
345
-		$weight = (float)$this->get_weight();
346
-		$ref_id = $this->get_ref_id();
347
-
348
-		if (!empty($ref_id)) {
349
-			$sql = 'UPDATE '.$this->get_forum_thread_table().' SET thread_weight='.$weight.'
332
+            $query = Database::query($sql);
333
+            $this->exercise_data = Database::fetch_array($query);
334
+        }
335
+        return $this->exercise_data;
336
+    }
337
+
338
+    public function get_icon_name()
339
+    {
340
+        return 'forum';
341
+    }
342
+
343
+    function save_linked_data()
344
+    {
345
+        $weight = (float)$this->get_weight();
346
+        $ref_id = $this->get_ref_id();
347
+
348
+        if (!empty($ref_id)) {
349
+            $sql = 'UPDATE '.$this->get_forum_thread_table().' SET thread_weight='.$weight.'
350 350
                     WHERE c_id = '.$this->course_id.' AND thread_id= '.$ref_id;
351
-			Database::query($sql);
352
-		}
353
-	}
354
-
355
-	function delete_linked_data()
356
-	{
357
-		$ref_id = $this->get_ref_id();
358
-		if (!empty($ref_id)) {
359
-			//Cleans forum
360
-			$sql = 'UPDATE '.$this->get_forum_thread_table().' SET
351
+            Database::query($sql);
352
+        }
353
+    }
354
+
355
+    function delete_linked_data()
356
+    {
357
+        $ref_id = $this->get_ref_id();
358
+        if (!empty($ref_id)) {
359
+            //Cleans forum
360
+            $sql = 'UPDATE '.$this->get_forum_thread_table().' SET
361 361
 			        thread_qualify_max = 0,
362 362
 			        thread_weight = 0,
363 363
 			        thread_title_qualify = ""
364 364
                     WHERE c_id = '.$this->course_id.' AND thread_id= '.$ref_id;
365
-			Database::query($sql);
366
-		}
367
-	}
365
+            Database::query($sql);
366
+        }
367
+    }
368 368
 }
Please login to merge, or discard this patch.
main/gradebook/lib/be/studentpublicationlink.class.php 1 patch
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.
main/gradebook/lib/be/evaluation.class.php 1 patch
Indentation   +744 added lines, -744 removed lines patch added patch discarded remove patch
@@ -9,364 +9,364 @@  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
-	public function get_description()
85
-	{
86
-		return $this->description;
87
-	}
88
-
89
-	public function get_user_id()
90
-	{
91
-		return $this->user_id;
92
-	}
93
-
94
-	public function get_course_code()
95
-	{
96
-		return $this->course_code;
97
-	}
98
-
99
-	/**
100
-	 * @return int
101
-	 */
102
-	public function getSessionId()
103
-	{
104
-		return $this->sessionId;
105
-	}
106
-
107
-	/**
108
-	 * @param int $sessionId
109
-	 */
110
-	public function setSessionId($sessionId)
111
-	{
112
-		$this->sessionId = intval($sessionId);
113
-	}
114
-
115
-	public function get_date()
116
-	{
117
-		return $this->created_at;
118
-	}
119
-
120
-	public function get_weight()
121
-	{
122
-		return $this->weight;
123
-	}
124
-
125
-	public function get_max()
126
-	{
127
-		return $this->eval_max;
128
-	}
129
-
130
-	public function get_type()
131
-	{
132
-		return $this->type;
133
-	}
134
-
135
-	public function is_visible()
136
-	{
137
-		return $this->visible;
138
-	}
139
-
140
-	public function get_locked()
141
-	{
142
-		return $this->locked;
143
-	}
144
-
145
-	public function is_locked()
146
-	{
147
-		return isset($this->locked) && $this->locked == 1 ? true : false;
148
-	}
149
-
150
-	public function set_id($id)
151
-	{
152
-		$this->id = $id;
153
-	}
154
-
155
-	public function set_name($name)
156
-	{
157
-		$this->name = $name;
158
-	}
159
-
160
-	public function set_description($description)
161
-	{
162
-		$this->description = $description;
163
-	}
164
-
165
-	public function set_user_id($user_id)
166
-	{
167
-		$this->user_id = $user_id;
168
-	}
169
-
170
-	public function set_course_code($course_code)
171
-	{
172
-		$this->course_code = $course_code;
173
-	}
174
-
175
-	public function set_date($date)
176
-	{
177
-		$this->created_at = $date;
178
-	}
179
-
180
-	public function set_weight($weight)
181
-	{
182
-		$this->weight = $weight;
183
-	}
184
-
185
-	public function set_max($max)
186
-	{
187
-		$this->eval_max = $max;
188
-	}
189
-
190
-	public function set_visible($visible)
191
-	{
192
-		$this->visible = $visible;
193
-	}
194
-
195
-	public function set_type($type)
196
-	{
197
-		$this->type = $type;
198
-	}
199
-
200
-	public function set_locked($locked)
201
-	{
202
-		$this->locked = $locked;
203
-	}
204
-
205
-	/**
206
-	 * Retrieve evaluations and return them as an array of Evaluation objects
207
-	 * @param int $id evaluation id
208
-	 * @param int $user_id user id (evaluation owner)
209
-	 * @param string $course_code course code
210
-	 * @param int $category_id parent category
211
-	 * @param $visible visible
212
-	 */
213
-	public static function load(
214
-		$id = null,
215
-		$user_id = null,
216
-		$course_code = null,
217
-		$category_id = null,
218
-		$visible = null,
219
-		$locked = null
220
-	) {
221
-		$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
222
-		$sql = 'SELECT * FROM '.$tbl_grade_evaluations;
223
-		$paramcount = 0;
224
-
225
-		if (isset ($id)) {
226
-			$sql.= ' WHERE id = '.intval($id);
227
-			$paramcount ++;
228
-		}
229
-
230
-		if (isset ($user_id)) {
231
-			if ($paramcount != 0) $sql .= ' AND';
232
-			else $sql .= ' WHERE';
233
-			$sql .= ' user_id = '.intval($user_id);
234
-			$paramcount ++;
235
-		}
236
-
237
-		if (isset ($course_code) && $course_code <> '-1') {
238
-			if ($paramcount != 0) $sql .= ' AND';
239
-			else $sql .= ' WHERE';
240
-			$sql .= " course_code = '".Database::escape_string($course_code)."'";
241
-			$paramcount ++;
242
-		}
243
-
244
-		if (isset ($category_id)) {
245
-			if ($paramcount != 0) $sql .= ' AND';
246
-			else $sql .= ' WHERE';
247
-			$sql .= ' category_id = '.intval($category_id);
248
-			$paramcount ++;
249
-		}
250
-
251
-		if (isset ($visible)) {
252
-			if ($paramcount != 0) $sql .= ' AND';
253
-			else $sql .= ' WHERE';
254
-			$sql .= ' visible = '.intval($visible);
255
-			$paramcount ++;
256
-		}
257
-
258
-		if (isset ($locked)) {
259
-			if ($paramcount != 0) $sql .= ' AND';
260
-			else $sql .= ' WHERE';
261
-			$sql .= ' locked = '.intval($locked);
262
-		}
263
-
264
-		$result = Database::query($sql);
265
-		$alleval = Evaluation::create_evaluation_objects_from_sql_result($result);
266
-
267
-		return $alleval;
268
-	}
269
-
270
-
271
-
272
-	/**
273
-	 * @param array $result
274
-	 * @return array
275
-	 */
276
-	private static function create_evaluation_objects_from_sql_result($result)
277
-	{
278
-		$alleval = array();
279
-		if (Database::num_rows($result)) {
280
-			while ($data = Database::fetch_array($result)) {
281
-				$eval= new Evaluation();
282
-				$eval->set_id($data['id']);
283
-				$eval->set_name($data['name']);
284
-				$eval->set_description($data['description']);
285
-				$eval->set_user_id($data['user_id']);
286
-				$eval->set_course_code($data['course_code']);
287
-				$eval->set_category_id($data['category_id']);
288
-				$eval->set_date(api_get_local_time($data['created_at']));
289
-				$eval->set_weight($data['weight']);
290
-				$eval->set_max($data['max']);
291
-				$eval->set_visible($data['visible']);
292
-				$eval->set_type($data['type']);
293
-				$eval->set_locked($data['locked']);
294
-				$eval->setSessionId(api_get_session_id());
295
-
296
-				$alleval[] = $eval;
297
-			}
298
-		}
299
-
300
-		return $alleval;
301
-	}
302
-
303
-	/**
304
-	 * Insert this evaluation into the database
305
-	 */
306
-	public function add()
307
-	{
308
-		if (isset($this->name) &&
309
-			isset($this->user_id) &&
310
-			isset($this->weight) &&
311
-			isset ($this->eval_max) &&
312
-			isset($this->visible)
313
-		) {
314
-			$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
315
-
316
-			$sql = 'INSERT INTO '.$tbl_grade_evaluations
317
-				.' (name, user_id, weight, max, visible';
318
-			if (isset($this->description)) {
319
-				$sql .= ',description';
320
-			}
321
-			if (isset($this->course_code)) {
322
-				$sql .= ', course_code';
323
-			}
324
-			if (isset($this->category)) {
325
-				$sql .= ', category_id';
326
-			}
327
-			$sql .= ', created_at';
328
-			$sql .= ',type';
329
-			$sql .= ") VALUES ('".Database::escape_string($this->get_name())."'"
330
-				.','.intval($this->get_user_id())
331
-				.','.floatval($this->get_weight())
332
-				.','.intval($this->get_max())
333
-				.','.intval($this->is_visible());
334
-			if (isset($this->description)) {
335
-				$sql .= ",'".Database::escape_string($this->get_description())."'";
336
-			}
337
-			if (isset($this->course_code)) {
338
-				$sql .= ",'".Database::escape_string($this->get_course_code())."'";
339
-			}
340
-			if (isset($this->category)) {
341
-				$sql .= ','.intval($this->get_category_id());
342
-			}
343
-			if (empty($this->type)) {
344
-				$this->type = 'evaluation';
345
-			}
346
-			$sql .= ", '".api_get_utc_datetime()."'";
347
-			$sql .= ',\''.Database::escape_string($this->type).'\'';
348
-			$sql .= ")";
349
-
350
-			Database::query($sql);
351
-			$this->set_id(Database::insert_id());
352
-		} else {
353
-			die('Error in Evaluation add: required field empty');
354
-		}
355
-	}
356
-
357
-	/**
358
-	 * @param int $idevaluation
359
-	 */
360
-	public function add_evaluation_log($idevaluation)
361
-	{
362
-		if (!empty($idevaluation)) {
363
-			$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
364
-			$tbl_grade_linkeval_log = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINKEVAL_LOG);
365
-			$eval = new Evaluation();
366
-			$dateobject = $eval->load($idevaluation,null,null,null,null);
367
-			$arreval = get_object_vars($dateobject[0]);
368
-			if (!empty($arreval['id'])) {
369
-				$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
+    public function get_description()
85
+    {
86
+        return $this->description;
87
+    }
88
+
89
+    public function get_user_id()
90
+    {
91
+        return $this->user_id;
92
+    }
93
+
94
+    public function get_course_code()
95
+    {
96
+        return $this->course_code;
97
+    }
98
+
99
+    /**
100
+     * @return int
101
+     */
102
+    public function getSessionId()
103
+    {
104
+        return $this->sessionId;
105
+    }
106
+
107
+    /**
108
+     * @param int $sessionId
109
+     */
110
+    public function setSessionId($sessionId)
111
+    {
112
+        $this->sessionId = intval($sessionId);
113
+    }
114
+
115
+    public function get_date()
116
+    {
117
+        return $this->created_at;
118
+    }
119
+
120
+    public function get_weight()
121
+    {
122
+        return $this->weight;
123
+    }
124
+
125
+    public function get_max()
126
+    {
127
+        return $this->eval_max;
128
+    }
129
+
130
+    public function get_type()
131
+    {
132
+        return $this->type;
133
+    }
134
+
135
+    public function is_visible()
136
+    {
137
+        return $this->visible;
138
+    }
139
+
140
+    public function get_locked()
141
+    {
142
+        return $this->locked;
143
+    }
144
+
145
+    public function is_locked()
146
+    {
147
+        return isset($this->locked) && $this->locked == 1 ? true : false;
148
+    }
149
+
150
+    public function set_id($id)
151
+    {
152
+        $this->id = $id;
153
+    }
154
+
155
+    public function set_name($name)
156
+    {
157
+        $this->name = $name;
158
+    }
159
+
160
+    public function set_description($description)
161
+    {
162
+        $this->description = $description;
163
+    }
164
+
165
+    public function set_user_id($user_id)
166
+    {
167
+        $this->user_id = $user_id;
168
+    }
169
+
170
+    public function set_course_code($course_code)
171
+    {
172
+        $this->course_code = $course_code;
173
+    }
174
+
175
+    public function set_date($date)
176
+    {
177
+        $this->created_at = $date;
178
+    }
179
+
180
+    public function set_weight($weight)
181
+    {
182
+        $this->weight = $weight;
183
+    }
184
+
185
+    public function set_max($max)
186
+    {
187
+        $this->eval_max = $max;
188
+    }
189
+
190
+    public function set_visible($visible)
191
+    {
192
+        $this->visible = $visible;
193
+    }
194
+
195
+    public function set_type($type)
196
+    {
197
+        $this->type = $type;
198
+    }
199
+
200
+    public function set_locked($locked)
201
+    {
202
+        $this->locked = $locked;
203
+    }
204
+
205
+    /**
206
+     * Retrieve evaluations and return them as an array of Evaluation objects
207
+     * @param int $id evaluation id
208
+     * @param int $user_id user id (evaluation owner)
209
+     * @param string $course_code course code
210
+     * @param int $category_id parent category
211
+     * @param $visible visible
212
+     */
213
+    public static function load(
214
+        $id = null,
215
+        $user_id = null,
216
+        $course_code = null,
217
+        $category_id = null,
218
+        $visible = null,
219
+        $locked = null
220
+    ) {
221
+        $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
222
+        $sql = 'SELECT * FROM '.$tbl_grade_evaluations;
223
+        $paramcount = 0;
224
+
225
+        if (isset ($id)) {
226
+            $sql.= ' WHERE id = '.intval($id);
227
+            $paramcount ++;
228
+        }
229
+
230
+        if (isset ($user_id)) {
231
+            if ($paramcount != 0) $sql .= ' AND';
232
+            else $sql .= ' WHERE';
233
+            $sql .= ' user_id = '.intval($user_id);
234
+            $paramcount ++;
235
+        }
236
+
237
+        if (isset ($course_code) && $course_code <> '-1') {
238
+            if ($paramcount != 0) $sql .= ' AND';
239
+            else $sql .= ' WHERE';
240
+            $sql .= " course_code = '".Database::escape_string($course_code)."'";
241
+            $paramcount ++;
242
+        }
243
+
244
+        if (isset ($category_id)) {
245
+            if ($paramcount != 0) $sql .= ' AND';
246
+            else $sql .= ' WHERE';
247
+            $sql .= ' category_id = '.intval($category_id);
248
+            $paramcount ++;
249
+        }
250
+
251
+        if (isset ($visible)) {
252
+            if ($paramcount != 0) $sql .= ' AND';
253
+            else $sql .= ' WHERE';
254
+            $sql .= ' visible = '.intval($visible);
255
+            $paramcount ++;
256
+        }
257
+
258
+        if (isset ($locked)) {
259
+            if ($paramcount != 0) $sql .= ' AND';
260
+            else $sql .= ' WHERE';
261
+            $sql .= ' locked = '.intval($locked);
262
+        }
263
+
264
+        $result = Database::query($sql);
265
+        $alleval = Evaluation::create_evaluation_objects_from_sql_result($result);
266
+
267
+        return $alleval;
268
+    }
269
+
270
+
271
+
272
+    /**
273
+     * @param array $result
274
+     * @return array
275
+     */
276
+    private static function create_evaluation_objects_from_sql_result($result)
277
+    {
278
+        $alleval = array();
279
+        if (Database::num_rows($result)) {
280
+            while ($data = Database::fetch_array($result)) {
281
+                $eval= new Evaluation();
282
+                $eval->set_id($data['id']);
283
+                $eval->set_name($data['name']);
284
+                $eval->set_description($data['description']);
285
+                $eval->set_user_id($data['user_id']);
286
+                $eval->set_course_code($data['course_code']);
287
+                $eval->set_category_id($data['category_id']);
288
+                $eval->set_date(api_get_local_time($data['created_at']));
289
+                $eval->set_weight($data['weight']);
290
+                $eval->set_max($data['max']);
291
+                $eval->set_visible($data['visible']);
292
+                $eval->set_type($data['type']);
293
+                $eval->set_locked($data['locked']);
294
+                $eval->setSessionId(api_get_session_id());
295
+
296
+                $alleval[] = $eval;
297
+            }
298
+        }
299
+
300
+        return $alleval;
301
+    }
302
+
303
+    /**
304
+     * Insert this evaluation into the database
305
+     */
306
+    public function add()
307
+    {
308
+        if (isset($this->name) &&
309
+            isset($this->user_id) &&
310
+            isset($this->weight) &&
311
+            isset ($this->eval_max) &&
312
+            isset($this->visible)
313
+        ) {
314
+            $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
315
+
316
+            $sql = 'INSERT INTO '.$tbl_grade_evaluations
317
+                .' (name, user_id, weight, max, visible';
318
+            if (isset($this->description)) {
319
+                $sql .= ',description';
320
+            }
321
+            if (isset($this->course_code)) {
322
+                $sql .= ', course_code';
323
+            }
324
+            if (isset($this->category)) {
325
+                $sql .= ', category_id';
326
+            }
327
+            $sql .= ', created_at';
328
+            $sql .= ',type';
329
+            $sql .= ") VALUES ('".Database::escape_string($this->get_name())."'"
330
+                .','.intval($this->get_user_id())
331
+                .','.floatval($this->get_weight())
332
+                .','.intval($this->get_max())
333
+                .','.intval($this->is_visible());
334
+            if (isset($this->description)) {
335
+                $sql .= ",'".Database::escape_string($this->get_description())."'";
336
+            }
337
+            if (isset($this->course_code)) {
338
+                $sql .= ",'".Database::escape_string($this->get_course_code())."'";
339
+            }
340
+            if (isset($this->category)) {
341
+                $sql .= ','.intval($this->get_category_id());
342
+            }
343
+            if (empty($this->type)) {
344
+                $this->type = 'evaluation';
345
+            }
346
+            $sql .= ", '".api_get_utc_datetime()."'";
347
+            $sql .= ',\''.Database::escape_string($this->type).'\'';
348
+            $sql .= ")";
349
+
350
+            Database::query($sql);
351
+            $this->set_id(Database::insert_id());
352
+        } else {
353
+            die('Error in Evaluation add: required field empty');
354
+        }
355
+    }
356
+
357
+    /**
358
+     * @param int $idevaluation
359
+     */
360
+    public function add_evaluation_log($idevaluation)
361
+    {
362
+        if (!empty($idevaluation)) {
363
+            $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
364
+            $tbl_grade_linkeval_log = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINKEVAL_LOG);
365
+            $eval = new Evaluation();
366
+            $dateobject = $eval->load($idevaluation,null,null,null,null);
367
+            $arreval = get_object_vars($dateobject[0]);
368
+            if (!empty($arreval['id'])) {
369
+                $sql = 'SELECT weight from '.$tbl_grade_evaluations.'
370 370
                         WHERE id='.$arreval['id'];
371 371
                 $rs = Database::query($sql);
372 372
                 $row_old_weight = Database::fetch_array($rs, 'ASSOC');
@@ -382,425 +382,425 @@  discard block
 block discarded – undo
382 382
                     'user_id_log' => api_get_user_id()
383 383
                 ];
384 384
                 Database::insert($tbl_grade_linkeval_log, $params);
385
-			}
386
-		}
387
-	}
388
-
389
-	/**
390
-	 * Update the properties of this evaluation in the database
391
-	 */
392
-	public function save()
393
-	{
394
-		$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
395
-		$sql = 'UPDATE '.$tbl_grade_evaluations
396
-			." SET name = '".Database::escape_string($this->get_name())."'"
397
-			.', description = ';
398
-		if (isset($this->description)) {
399
-			$sql .= "'".Database::escape_string($this->get_description())."'";
400
-		}else {
401
-			$sql .= 'null';
402
-		}
403
-		$sql .= ', user_id = '.intval($this->get_user_id())
404
-			.', course_code = ';
405
-		if (isset($this->course_code)) {
406
-			$sql .= "'".Database::escape_string($this->get_course_code())."'";
407
-		} else {
408
-			$sql .= 'null';
409
-		}
410
-		$sql .= ', category_id = ';
411
-		if (isset($this->category)) {
412
-			$sql .= intval($this->get_category_id());
413
-		} else {
414
-			$sql .= 'null';
415
-		}
416
-		$sql .= ', weight = "'.Database::escape_string($this->get_weight()).'" '
417
-			.', max = '.intval($this->get_max())
418
-			.', visible = '.intval($this->is_visible())
419
-			.' WHERE id = '.intval($this->id);
420
-		//recorded history
421
-
422
-		$eval_log = new Evaluation();
423
-		$eval_log->add_evaluation_log($this->id);
424
-		Database::query($sql);
425
-	}
426
-
427
-	/**
428
-	 * Delete this evaluation from the database
429
-	 */
430
-	public function delete()
431
-	{
432
-		$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
433
-		$sql = 'DELETE FROM '.$tbl_grade_evaluations.' WHERE id = '.intval($this->id);
434
-		Database::query($sql);
435
-	}
436
-
437
-	/**
438
-	 * Check if an evaluation name (with the same parent category) already exists
439
-	 * @param $name name to check (if not given, the name property of this object will be checked)
440
-	 * @param $parent parent category
441
-	 */
442
-	public function does_name_exist($name, $parent)
443
-	{
444
-		if (!isset ($name)) {
445
-			$name = $this->name;
446
-			$parent = $this->category;
447
-		}
448
-		$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
449
-		$sql = 'SELECT count(id) AS number'
450
-			.' FROM '.$tbl_grade_evaluations
451
-			." WHERE name = '".Database::escape_string($name)."'";
452
-
453
-		if (api_is_allowed_to_edit()) {
454
-			$parent = Category::load($parent);
455
-			$code = $parent[0]->get_course_code();
456
-			$courseInfo = api_get_course_info($code);
457
-			$courseId = $courseInfo['real_id'];
458
-
459
-			if (isset($code) && $code != '0') {
460
-				$main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
461
-				$sql .= ' AND user_id IN (
385
+            }
386
+        }
387
+    }
388
+
389
+    /**
390
+     * Update the properties of this evaluation in the database
391
+     */
392
+    public function save()
393
+    {
394
+        $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
395
+        $sql = 'UPDATE '.$tbl_grade_evaluations
396
+            ." SET name = '".Database::escape_string($this->get_name())."'"
397
+            .', description = ';
398
+        if (isset($this->description)) {
399
+            $sql .= "'".Database::escape_string($this->get_description())."'";
400
+        }else {
401
+            $sql .= 'null';
402
+        }
403
+        $sql .= ', user_id = '.intval($this->get_user_id())
404
+            .', course_code = ';
405
+        if (isset($this->course_code)) {
406
+            $sql .= "'".Database::escape_string($this->get_course_code())."'";
407
+        } else {
408
+            $sql .= 'null';
409
+        }
410
+        $sql .= ', category_id = ';
411
+        if (isset($this->category)) {
412
+            $sql .= intval($this->get_category_id());
413
+        } else {
414
+            $sql .= 'null';
415
+        }
416
+        $sql .= ', weight = "'.Database::escape_string($this->get_weight()).'" '
417
+            .', max = '.intval($this->get_max())
418
+            .', visible = '.intval($this->is_visible())
419
+            .' WHERE id = '.intval($this->id);
420
+        //recorded history
421
+
422
+        $eval_log = new Evaluation();
423
+        $eval_log->add_evaluation_log($this->id);
424
+        Database::query($sql);
425
+    }
426
+
427
+    /**
428
+     * Delete this evaluation from the database
429
+     */
430
+    public function delete()
431
+    {
432
+        $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
433
+        $sql = 'DELETE FROM '.$tbl_grade_evaluations.' WHERE id = '.intval($this->id);
434
+        Database::query($sql);
435
+    }
436
+
437
+    /**
438
+     * Check if an evaluation name (with the same parent category) already exists
439
+     * @param $name name to check (if not given, the name property of this object will be checked)
440
+     * @param $parent parent category
441
+     */
442
+    public function does_name_exist($name, $parent)
443
+    {
444
+        if (!isset ($name)) {
445
+            $name = $this->name;
446
+            $parent = $this->category;
447
+        }
448
+        $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
449
+        $sql = 'SELECT count(id) AS number'
450
+            .' FROM '.$tbl_grade_evaluations
451
+            ." WHERE name = '".Database::escape_string($name)."'";
452
+
453
+        if (api_is_allowed_to_edit()) {
454
+            $parent = Category::load($parent);
455
+            $code = $parent[0]->get_course_code();
456
+            $courseInfo = api_get_course_info($code);
457
+            $courseId = $courseInfo['real_id'];
458
+
459
+            if (isset($code) && $code != '0') {
460
+                $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
461
+                $sql .= ' AND user_id IN (
462 462
 					 SELECT user_id FROM '.$main_course_user_table.'
463 463
 					 WHERE
464 464
 						c_id = '.$courseId.' AND
465 465
 						status = '.COURSEMANAGER.'
466 466
 					)';
467
-			} else {
468
-				$sql .= ' AND user_id = '.api_get_user_id();
469
-			}
470
-
471
-		}else {
472
-			$sql .= ' AND user_id = '.api_get_user_id();
473
-		}
474
-
475
-		if (!isset ($parent)) {
476
-			$sql.= ' AND category_id is null';
477
-		} else {
478
-			$sql.= ' AND category_id = '.intval($parent);
479
-		}
480
-		$result = Database::query($sql);
481
-		$number=Database::fetch_row($result);
482
-
483
-		return $number[0] != 0;
484
-	}
485
-
486
-	/**
487
-	 * Are there any results for this evaluation yet ?
488
-	 * The 'max' property should not be changed then.
489
-	 */
490
-	public function has_results()
491
-	{
492
-		$tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
493
-		$sql = 'SELECT count(id) AS number
467
+            } else {
468
+                $sql .= ' AND user_id = '.api_get_user_id();
469
+            }
470
+
471
+        }else {
472
+            $sql .= ' AND user_id = '.api_get_user_id();
473
+        }
474
+
475
+        if (!isset ($parent)) {
476
+            $sql.= ' AND category_id is null';
477
+        } else {
478
+            $sql.= ' AND category_id = '.intval($parent);
479
+        }
480
+        $result = Database::query($sql);
481
+        $number=Database::fetch_row($result);
482
+
483
+        return $number[0] != 0;
484
+    }
485
+
486
+    /**
487
+     * Are there any results for this evaluation yet ?
488
+     * The 'max' property should not be changed then.
489
+     */
490
+    public function has_results()
491
+    {
492
+        $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
493
+        $sql = 'SELECT count(id) AS number
494 494
 				FROM '.$tbl_grade_results.'
495 495
 				WHERE evaluation_id = '.intval($this->id);
496
-		$result = Database::query($sql);
497
-		$number=Database::fetch_row($result);
498
-
499
-		return ($number[0] != 0);
500
-	}
501
-
502
-	/**
503
-	 * Delete all results for this evaluation
504
-	 */
505
-	public function delete_results()
506
-	{
507
-		$tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
508
-		$sql = 'DELETE FROM '.$tbl_grade_results.'
496
+        $result = Database::query($sql);
497
+        $number=Database::fetch_row($result);
498
+
499
+        return ($number[0] != 0);
500
+    }
501
+
502
+    /**
503
+     * Delete all results for this evaluation
504
+     */
505
+    public function delete_results()
506
+    {
507
+        $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
508
+        $sql = 'DELETE FROM '.$tbl_grade_results.'
509 509
 				WHERE evaluation_id = '.intval($this->id);
510
-		Database::query($sql);
511
-	}
512
-
513
-	/**
514
-	 * Delete this evaluation and all underlying results.
515
-	 */
516
-	public function delete_with_results()
517
-	{
518
-		$this->delete_results();
519
-		$this->delete();
520
-	}
521
-
522
-	/**
523
-	 * Check if the given score is possible for this evaluation
524
-	 */
525
-	public function is_valid_score($score)
526
-	{
527
-		return is_numeric($score) && $score >= 0 && $score <= $this->eval_max;
528
-	}
529
-
530
-	/**
531
-	 * Calculate the score of this evaluation
532
-	 * @param int $stud_id (default: all students who have results for this eval - then the average is returned)
533
-	 * @param string $type (best, average, ranking)
534
-	 * @return	array (score, max) if student is given
535
-	 * 			array (sum of scores, number of scores) otherwise
536
-	 * 			or null if no scores available
537
-	 */
538
-	public function calc_score($stud_id = null, $type = null)
539
-	{
510
+        Database::query($sql);
511
+    }
512
+
513
+    /**
514
+     * Delete this evaluation and all underlying results.
515
+     */
516
+    public function delete_with_results()
517
+    {
518
+        $this->delete_results();
519
+        $this->delete();
520
+    }
521
+
522
+    /**
523
+     * Check if the given score is possible for this evaluation
524
+     */
525
+    public function is_valid_score($score)
526
+    {
527
+        return is_numeric($score) && $score >= 0 && $score <= $this->eval_max;
528
+    }
529
+
530
+    /**
531
+     * Calculate the score of this evaluation
532
+     * @param int $stud_id (default: all students who have results for this eval - then the average is returned)
533
+     * @param string $type (best, average, ranking)
534
+     * @return	array (score, max) if student is given
535
+     * 			array (sum of scores, number of scores) otherwise
536
+     * 			or null if no scores available
537
+     */
538
+    public function calc_score($stud_id = null, $type = null)
539
+    {
540 540
         $useSession = true;
541
-		if (isset($stud_id) && empty($type)) {
542
-			$key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id.'_'.$stud_id;
543
-			$data = Session::read('calc_score');
541
+        if (isset($stud_id) && empty($type)) {
542
+            $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id.'_'.$stud_id;
543
+            $data = Session::read('calc_score');
544 544
             $results = isset($data[$key]) ? $data[$key] : null;
545 545
 
546 546
             if ($useSession == false) {
547 547
                 $results  = null;
548 548
             }
549
-			if (empty($results)) {
550
-				$results = Result::load(null, $stud_id, $this->id);
551
-				Session::write('calc_score', array($key => $results));
552
-			}
553
-
554
-			$score = 0;
555
-			/** @var Result $res */
556
-			foreach ($results as $res) {
557
-				$score = $res->get_score();
558
-			}
559
-
560
-			return array($score, $this->get_max());
561
-		} else {
562
-
563
-			$count = 0;
564
-			$sum = 0;
565
-			$bestResult = 0;
566
-			$weight = 0;
567
-			$sumResult = 0;
568
-
569
-			$key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id;
549
+            if (empty($results)) {
550
+                $results = Result::load(null, $stud_id, $this->id);
551
+                Session::write('calc_score', array($key => $results));
552
+            }
553
+
554
+            $score = 0;
555
+            /** @var Result $res */
556
+            foreach ($results as $res) {
557
+                $score = $res->get_score();
558
+            }
559
+
560
+            return array($score, $this->get_max());
561
+        } else {
562
+
563
+            $count = 0;
564
+            $sum = 0;
565
+            $bestResult = 0;
566
+            $weight = 0;
567
+            $sumResult = 0;
568
+
569
+            $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id;
570 570
             $data = Session::read('calc_score');
571 571
             $allResults = isset($data[$key]) ? $data[$key] : null;
572 572
             if ($useSession == false) {
573 573
                 $allResults  = null;
574 574
             }
575
-			if (empty($allResults)) {
576
-				$allResults = Result::load(null, null, $this->id);
577
-				Session::write($key, $allResults);
578
-			}
579
-
580
-			$students = array();
581
-			/** @var Result $res */
582
-			foreach ($allResults as $res) {
583
-				$score = $res->get_score();
584
-				if (!empty($score) || $score == '0') {
585
-					$count++;
586
-					$sum += $score / $this->get_max();
587
-					$sumResult += $score;
588
-					if ($score > $bestResult) {
589
-						$bestResult = $score;
590
-					}
591
-					$weight = $this->get_max();
592
-				}
593
-				$students[$res->get_user_id()] = $score;
594
-			}
595
-
596
-			if (empty($count)) {
597
-				return null;
598
-			}
599
-
600
-			switch ($type) {
601
-				case 'best':
602
-					return array($bestResult, $weight);
603
-					break;
604
-				case 'average':
605
-					return array($sumResult/$count, $weight);
606
-					break;
607
-				case 'ranking':
575
+            if (empty($allResults)) {
576
+                $allResults = Result::load(null, null, $this->id);
577
+                Session::write($key, $allResults);
578
+            }
579
+
580
+            $students = array();
581
+            /** @var Result $res */
582
+            foreach ($allResults as $res) {
583
+                $score = $res->get_score();
584
+                if (!empty($score) || $score == '0') {
585
+                    $count++;
586
+                    $sum += $score / $this->get_max();
587
+                    $sumResult += $score;
588
+                    if ($score > $bestResult) {
589
+                        $bestResult = $score;
590
+                    }
591
+                    $weight = $this->get_max();
592
+                }
593
+                $students[$res->get_user_id()] = $score;
594
+            }
595
+
596
+            if (empty($count)) {
597
+                return null;
598
+            }
599
+
600
+            switch ($type) {
601
+                case 'best':
602
+                    return array($bestResult, $weight);
603
+                    break;
604
+                case 'average':
605
+                    return array($sumResult/$count, $weight);
606
+                    break;
607
+                case 'ranking':
608 608
                     $students = array();
609 609
                     /** @var Result $res */
610 610
                     foreach ($allResults as $res) {
611 611
                         $score = $res->get_score();
612 612
                         $students[$res->get_user_id()] = $score;
613 613
                     }
614
-					return AbstractLink::getCurrentUserRanking($stud_id, $students);
615
-					break;
616
-				default:
617
-					return array($sum, $count);
618
-					break;
619
-			}
620
-		}
621
-	}
622
-
623
-	/**
624
-	 * Generate an array of possible categories where this evaluation can be moved to.
625
-	 * Notice: its own parent will be included in the list: it's up to the frontend
626
-	 * to disable this element.
627
-	 * @return array 2-dimensional array - every element contains 3 subelements (id, name, level)
628
-	 */
629
-	public function get_target_categories()
630
-	{
631
-		// - course independent evaluation
632
-		//   -> movable to root or other course independent categories
633
-		// - evaluation inside a course
634
-		//   -> movable to root, independent categories or categories inside the course
635
-		$user = (api_is_platform_admin() ? null : api_get_user_id());
636
-		$targets = array();
637
-		$level = 0;
638
-
639
-		$root = array(0, get_lang('RootCat'), $level);
640
-		$targets[] = $root;
641
-
642
-		if (isset($this->course_code) && !empty($this->course_code)) {
643
-			$crscats = Category::load(null,null,$this->course_code,0);
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());
647
-			}
648
-		}
649
-
650
-		$indcats = Category::load(null,$user,0,0);
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());
654
-		}
655
-
656
-		return $targets;
657
-	}
658
-
659
-	/**
660
-	 * Internal function used by get_target_categories()
661
-	 */
662
-	private function add_target_subcategories($targets, $level, $catid)
663
-	{
664
-		$subcats = Category::load(null,null,null,$catid);
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());
668
-		}
669
-		return $targets;
670
-	}
671
-
672
-	/**
673
-	 * Move this evaluation to the given category.
674
-	 * If this evaluation moves from inside a course to outside,
675
-	 * its course code is also changed.
676
-	 */
677
-	public function move_to_cat($cat)
678
-	{
679
-		$this->set_category_id($cat->get_id());
680
-		if ($this->get_course_code() != $cat->get_course_code()) {
681
-			$this->set_course_code($cat->get_course_code());
682
-		}
683
-		$this->save();
684
-	}
685
-
686
-	/**
687
-	 * Retrieve evaluations where a student has results for
688
-	 * and return them as an array of Evaluation objects
689
-	 * @param int $cat_id parent category (use 'null' to retrieve them in all categories)
690
-	 * @param int $stud_id student id
691
-	 */
692
-	public static function get_evaluations_with_result_for_student($cat_id = null, $stud_id)
693
-	{
694
-		$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
695
-		$tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
696
-
697
-		$sql = 'SELECT * FROM '.$tbl_grade_evaluations.'
614
+                    return AbstractLink::getCurrentUserRanking($stud_id, $students);
615
+                    break;
616
+                default:
617
+                    return array($sum, $count);
618
+                    break;
619
+            }
620
+        }
621
+    }
622
+
623
+    /**
624
+     * Generate an array of possible categories where this evaluation can be moved to.
625
+     * Notice: its own parent will be included in the list: it's up to the frontend
626
+     * to disable this element.
627
+     * @return array 2-dimensional array - every element contains 3 subelements (id, name, level)
628
+     */
629
+    public function get_target_categories()
630
+    {
631
+        // - course independent evaluation
632
+        //   -> movable to root or other course independent categories
633
+        // - evaluation inside a course
634
+        //   -> movable to root, independent categories or categories inside the course
635
+        $user = (api_is_platform_admin() ? null : api_get_user_id());
636
+        $targets = array();
637
+        $level = 0;
638
+
639
+        $root = array(0, get_lang('RootCat'), $level);
640
+        $targets[] = $root;
641
+
642
+        if (isset($this->course_code) && !empty($this->course_code)) {
643
+            $crscats = Category::load(null,null,$this->course_code,0);
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());
647
+            }
648
+        }
649
+
650
+        $indcats = Category::load(null,$user,0,0);
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());
654
+        }
655
+
656
+        return $targets;
657
+    }
658
+
659
+    /**
660
+     * Internal function used by get_target_categories()
661
+     */
662
+    private function add_target_subcategories($targets, $level, $catid)
663
+    {
664
+        $subcats = Category::load(null,null,null,$catid);
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());
668
+        }
669
+        return $targets;
670
+    }
671
+
672
+    /**
673
+     * Move this evaluation to the given category.
674
+     * If this evaluation moves from inside a course to outside,
675
+     * its course code is also changed.
676
+     */
677
+    public function move_to_cat($cat)
678
+    {
679
+        $this->set_category_id($cat->get_id());
680
+        if ($this->get_course_code() != $cat->get_course_code()) {
681
+            $this->set_course_code($cat->get_course_code());
682
+        }
683
+        $this->save();
684
+    }
685
+
686
+    /**
687
+     * Retrieve evaluations where a student has results for
688
+     * and return them as an array of Evaluation objects
689
+     * @param int $cat_id parent category (use 'null' to retrieve them in all categories)
690
+     * @param int $stud_id student id
691
+     */
692
+    public static function get_evaluations_with_result_for_student($cat_id = null, $stud_id)
693
+    {
694
+        $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
695
+        $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
696
+
697
+        $sql = 'SELECT * FROM '.$tbl_grade_evaluations.'
698 698
 				WHERE id IN (
699 699
 					SELECT evaluation_id FROM '.$tbl_grade_results.'
700 700
 					WHERE user_id = '.intval($stud_id).' AND score IS NOT NULL
701 701
 				)';
702
-		if (!api_is_allowed_to_edit()) {
703
-			$sql .= ' AND visible = 1';
704
-		}
705
-		if (isset($cat_id)) {
706
-			$sql .= ' AND category_id = '.intval($cat_id);
707
-		} else {
708
-			$sql .= ' AND category_id >= 0';
709
-		}
710
-
711
-		$result = Database::query($sql);
712
-		$alleval = Evaluation::create_evaluation_objects_from_sql_result($result);
713
-
714
-		return $alleval;
715
-	}
716
-
717
-	/**
718
-	 * Get a list of students that do not have a result record for this evaluation
719
-	 */
720
-	public function get_not_subscribed_students($first_letter_user = '')
721
-	{
722
-		$tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
723
-		$tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
724
-
725
-		$sql = 'SELECT user_id,lastname,firstname,username FROM '.$tbl_user
726
-			." WHERE lastname LIKE '".Database::escape_string($first_letter_user)."%'"
727
-			.' AND status = '.STUDENT
728
-			.' AND user_id NOT IN'
729
-			.' (SELECT user_id FROM '.$tbl_grade_results
730
-			.' WHERE evaluation_id = '.intval($this->id)
731
-			.' )'
732
-			.' ORDER BY lastname';
733
-
734
-		$result = Database::query($sql);
735
-		$users = Database::store_result($result);
736
-
737
-		return $users;
738
-	}
739
-
740
-	/**
741
-	 * Find evaluations by name
742
-	 * @param string $name_mask search string
743
-	 * @return array evaluation objects matching the search criterium
744
-	 * @todo can be written more efficiently using a new (but very complex) sql query
745
-	 */
746
-	public function find_evaluations($name_mask,$selectcat)
747
-	{
748
-		$rootcat = Category::load($selectcat);
749
-		$evals = $rootcat[0]->get_evaluations((api_is_allowed_to_create_course() ? null : api_get_user_id()), true);
750
-		$foundevals = array();
751
-		foreach ($evals as $eval) {
752
-			if (!(api_strpos(api_strtolower($eval->get_name()), api_strtolower($name_mask)) === false)) {
753
-				$foundevals[] = $eval;
754
-			}
755
-		}
756
-		return $foundevals;
757
-	}
758
-
759
-	public function get_item_type()
760
-	{
761
-		return 'E';
762
-	}
763
-
764
-	public function get_icon_name()
765
-	{
766
-		return $this->has_results() ? 'evalnotempty' : 'evalempty';
767
-	}
768
-
769
-	/**
770
-	 * Locks an evaluation, only one who can unlock it is the platform administrator.
771
-	 * @param int locked 1 or unlocked 0
772
-	 *
773
-	 **/
774
-	function lock($locked)
775
-	{
776
-		$table_evaluation = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
777
-		$sql = "UPDATE $table_evaluation SET locked = '".intval($locked)."' WHERE id='".intval($this->id)."'";
778
-		Database::query($sql);
779
-	}
780
-
781
-	function check_lock_permissions()
782
-	{
783
-		if (api_is_platform_admin()) {
784
-			return true;
785
-		} else {
786
-			if ($this->is_locked()) {
787
-				api_not_allowed();
788
-			}
789
-		}
790
-	}
791
-
792
-	function delete_linked_data()
793
-	{
794
-
795
-	}
702
+        if (!api_is_allowed_to_edit()) {
703
+            $sql .= ' AND visible = 1';
704
+        }
705
+        if (isset($cat_id)) {
706
+            $sql .= ' AND category_id = '.intval($cat_id);
707
+        } else {
708
+            $sql .= ' AND category_id >= 0';
709
+        }
710
+
711
+        $result = Database::query($sql);
712
+        $alleval = Evaluation::create_evaluation_objects_from_sql_result($result);
713
+
714
+        return $alleval;
715
+    }
716
+
717
+    /**
718
+     * Get a list of students that do not have a result record for this evaluation
719
+     */
720
+    public function get_not_subscribed_students($first_letter_user = '')
721
+    {
722
+        $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
723
+        $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
724
+
725
+        $sql = 'SELECT user_id,lastname,firstname,username FROM '.$tbl_user
726
+            ." WHERE lastname LIKE '".Database::escape_string($first_letter_user)."%'"
727
+            .' AND status = '.STUDENT
728
+            .' AND user_id NOT IN'
729
+            .' (SELECT user_id FROM '.$tbl_grade_results
730
+            .' WHERE evaluation_id = '.intval($this->id)
731
+            .' )'
732
+            .' ORDER BY lastname';
733
+
734
+        $result = Database::query($sql);
735
+        $users = Database::store_result($result);
736
+
737
+        return $users;
738
+    }
739
+
740
+    /**
741
+     * Find evaluations by name
742
+     * @param string $name_mask search string
743
+     * @return array evaluation objects matching the search criterium
744
+     * @todo can be written more efficiently using a new (but very complex) sql query
745
+     */
746
+    public function find_evaluations($name_mask,$selectcat)
747
+    {
748
+        $rootcat = Category::load($selectcat);
749
+        $evals = $rootcat[0]->get_evaluations((api_is_allowed_to_create_course() ? null : api_get_user_id()), true);
750
+        $foundevals = array();
751
+        foreach ($evals as $eval) {
752
+            if (!(api_strpos(api_strtolower($eval->get_name()), api_strtolower($name_mask)) === false)) {
753
+                $foundevals[] = $eval;
754
+            }
755
+        }
756
+        return $foundevals;
757
+    }
758
+
759
+    public function get_item_type()
760
+    {
761
+        return 'E';
762
+    }
763
+
764
+    public function get_icon_name()
765
+    {
766
+        return $this->has_results() ? 'evalnotempty' : 'evalempty';
767
+    }
768
+
769
+    /**
770
+     * Locks an evaluation, only one who can unlock it is the platform administrator.
771
+     * @param int locked 1 or unlocked 0
772
+     *
773
+     **/
774
+    function lock($locked)
775
+    {
776
+        $table_evaluation = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
777
+        $sql = "UPDATE $table_evaluation SET locked = '".intval($locked)."' WHERE id='".intval($this->id)."'";
778
+        Database::query($sql);
779
+    }
780
+
781
+    function check_lock_permissions()
782
+    {
783
+        if (api_is_platform_admin()) {
784
+            return true;
785
+        } else {
786
+            if ($this->is_locked()) {
787
+                api_not_allowed();
788
+            }
789
+        }
790
+    }
791
+
792
+    function delete_linked_data()
793
+    {
794
+
795
+    }
796 796
 
797 797
     public function getStudentList()
798 798
     {
799 799
         return $this->studentList;
800 800
     }
801 801
 
802
-	public function setStudentList($list)
803
-	{
804
-		$this->studentList = $list;
805
-	}
802
+    public function setStudentList($list)
803
+    {
804
+        $this->studentList = $list;
805
+    }
806 806
 }
Please login to merge, or discard this patch.
main/gradebook/lib/GradebookUtils.php 1 patch
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.
main/admin/grade_models.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
                         array('name'=>'name',           'index'=>'name',        'width'=>'80',   'align'=>'left'),
81 81
                         array('name'=>'description',    'index'=>'description', 'width'=>'500',  'align'=>'left','sortable'=>'false'),
82 82
                         array('name'=>'actions',        'index'=>'actions',     'width'=>'100',  'align'=>'left','formatter'=>'action_formatter','sortable'=>'false')
83
-                       );
83
+                        );
84 84
 //Autowidth
85 85
 $extra_params['autowidth'] = 'true';
86 86
 //height auto
@@ -89,8 +89,8 @@  discard block
 block discarded – undo
89 89
 //With this function we can add actions to the jgrid (edit, delete, etc)
90 90
 $action_links = 'function action_formatter(cellvalue, options, rowObject) {
91 91
                          return \'<a href="?action=edit&id=\'+options.rowId+\'">'.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>'.
92
-                         '&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;"  href="?sec_token='.$token.'&action=delete&id=\'+options.rowId+\'">'.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>'.
93
-                         '\';
92
+                            '&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;"  href="?sec_token='.$token.'&action=delete&id=\'+options.rowId+\'">'.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>'.
93
+                            '\';
94 94
                  }';
95 95
 ?>
96 96
 <script>
Please login to merge, or discard this patch.
main/admin/access_url_add_usergroup_to_url.php 1 patch
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.
main/admin/legal_add.php 1 patch
Indentation   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -18,93 +18,93 @@  discard block
 block discarded – undo
18 18
 
19 19
 $defaults = array();
20 20
 $term_preview = array(
21
-	'type' => 0,
22
-	'content' => '',
23
-	'changes' => '',
21
+    'type' => 0,
22
+    'content' => '',
23
+    'changes' => '',
24 24
 );
25 25
 if ($form->validate()) {
26
-	$check = Security::check_token('post');
27
-	if ($check) {
28
-		$values  = $form->getSubmitValues();
29
-		$lang 	 = $values['language'];
30
-		//language id
31
-		$lang = api_get_language_id($lang);
32
-
33
-		if (isset($values['type'])) {
34
-			$type 	 = $values['type'];
35
-		} else {
36
-			$type = 0;
37
-		}
38
-		if (isset($values['content'])) {
39
-			$content = $values['content'];
40
-		} else {
41
-			$content = '';
42
-		}
43
-		if (isset($values['changes'])) {
44
-			$changes = $values['changes'];
45
-		} else {
46
-			$changes = '';
47
-		}
48
-		$navigator_info = api_get_navigator();
49
-
50
-		if ($navigator_info['name']=='Internet Explorer' &&  $navigator_info['version']=='6') {
51
-			if (isset($values['preview'])) {
52
-				$submit	='preview';
53
-			} elseif (isset($values['save'])) {
54
-				$submit	='save';
55
-			} elseif (isset($values['back'])) {
56
-				$submit	='back';
57
-			}
58
-		} else {
59
-			$submit  = $values['send'];
60
-		}
61
-
62
-		$default['content'] = $content;
63
-		if (isset($values['language'])) {
64
-			if ($submit == 'back') {
65
-				header('Location: legal_add.php');
66
-				exit;
67
-			} elseif ($submit == 'save') {
68
-				$insert_result = LegalManager::add($lang, $content, $type, $changes);
69
-				if ($insert_result ) {
70
-					$message = get_lang('TermAndConditionSaved');
71
-				} else {
72
-					$message = get_lang('TermAndConditionNotSaved');
73
-				}
74
-				Security::clear_token();
75
-				$tok = Security::get_token();
76
-				header('Location: legal_list.php?action=show_message&message='.urlencode($message).'&sec_token='.$tok);
77
-				exit();
78
-			} elseif ($submit=='preview') {
79
-				$defaults['type'] = $type;
80
-				$defaults['content'] = $content;
81
-				$defaults['changes'] = $changes;
82
-				$term_preview = $defaults;
83
-				$term_preview['type'] = intval($_POST['type']);
84
-			} else {
85
-				$my_lang = $_POST['language'];
86
-				if (isset($_POST['language'])){
87
-					$all_langs = api_get_languages();
88
-					if (in_array($my_lang, $all_langs['folder'])){
89
-						$language = api_get_language_id($my_lang);
90
-						$term_preview = LegalManager::get_last_condition($language);
91
-						$defaults = $term_preview;
92
-						if (!$term_preview) {
93
-							// there are not terms and conditions
94
-							$term_preview['type']=-1;
95
-							$defaults['type']=0;
96
-						}
97
-					}
98
-				}
99
-			}
100
-		}
101
-	}
26
+    $check = Security::check_token('post');
27
+    if ($check) {
28
+        $values  = $form->getSubmitValues();
29
+        $lang 	 = $values['language'];
30
+        //language id
31
+        $lang = api_get_language_id($lang);
32
+
33
+        if (isset($values['type'])) {
34
+            $type 	 = $values['type'];
35
+        } else {
36
+            $type = 0;
37
+        }
38
+        if (isset($values['content'])) {
39
+            $content = $values['content'];
40
+        } else {
41
+            $content = '';
42
+        }
43
+        if (isset($values['changes'])) {
44
+            $changes = $values['changes'];
45
+        } else {
46
+            $changes = '';
47
+        }
48
+        $navigator_info = api_get_navigator();
49
+
50
+        if ($navigator_info['name']=='Internet Explorer' &&  $navigator_info['version']=='6') {
51
+            if (isset($values['preview'])) {
52
+                $submit	='preview';
53
+            } elseif (isset($values['save'])) {
54
+                $submit	='save';
55
+            } elseif (isset($values['back'])) {
56
+                $submit	='back';
57
+            }
58
+        } else {
59
+            $submit  = $values['send'];
60
+        }
61
+
62
+        $default['content'] = $content;
63
+        if (isset($values['language'])) {
64
+            if ($submit == 'back') {
65
+                header('Location: legal_add.php');
66
+                exit;
67
+            } elseif ($submit == 'save') {
68
+                $insert_result = LegalManager::add($lang, $content, $type, $changes);
69
+                if ($insert_result ) {
70
+                    $message = get_lang('TermAndConditionSaved');
71
+                } else {
72
+                    $message = get_lang('TermAndConditionNotSaved');
73
+                }
74
+                Security::clear_token();
75
+                $tok = Security::get_token();
76
+                header('Location: legal_list.php?action=show_message&message='.urlencode($message).'&sec_token='.$tok);
77
+                exit();
78
+            } elseif ($submit=='preview') {
79
+                $defaults['type'] = $type;
80
+                $defaults['content'] = $content;
81
+                $defaults['changes'] = $changes;
82
+                $term_preview = $defaults;
83
+                $term_preview['type'] = intval($_POST['type']);
84
+            } else {
85
+                $my_lang = $_POST['language'];
86
+                if (isset($_POST['language'])){
87
+                    $all_langs = api_get_languages();
88
+                    if (in_array($my_lang, $all_langs['folder'])){
89
+                        $language = api_get_language_id($my_lang);
90
+                        $term_preview = LegalManager::get_last_condition($language);
91
+                        $defaults = $term_preview;
92
+                        if (!$term_preview) {
93
+                            // there are not terms and conditions
94
+                            $term_preview['type']=-1;
95
+                            $defaults['type']=0;
96
+                        }
97
+                    }
98
+                }
99
+            }
100
+        }
101
+    }
102 102
 }
103 103
 
104 104
 $form->setDefaults($defaults);
105 105
 
106 106
 if (isset($_POST['send'])) {
107
-	Security::clear_token();
107
+    Security::clear_token();
108 108
 }
109 109
 $token = Security::get_token();
110 110
 
@@ -115,34 +115,34 @@  discard block
 block discarded – undo
115 115
 
116 116
 if (isset($_POST['language'])) {
117 117
 
118
-	$form->addElement('static', Security::remove_XSS($_POST['language']));
119
-	$form->addElement('hidden', 'language',Security::remove_XSS($_POST['language']));
120
-	$form->addHtmlEditor('content', get_lang('Content'), true, false, array('ToolbarSet' => 'terms_and_conditions', 'Width' => '100%', 'Height' => '250'));
118
+    $form->addElement('static', Security::remove_XSS($_POST['language']));
119
+    $form->addElement('hidden', 'language',Security::remove_XSS($_POST['language']));
120
+    $form->addHtmlEditor('content', get_lang('Content'), true, false, array('ToolbarSet' => 'terms_and_conditions', 'Width' => '100%', 'Height' => '250'));
121 121
 
122
-	$form->addElement('radio', 'type', '', get_lang('HTMLText') ,'0');
123
-	$form->addElement('radio', 'type', '', get_lang('PageLink') ,'1');
124
-	$form->addElement('textarea', 'changes', get_lang('ExplainChanges'),array('width'=>'20'));
122
+    $form->addElement('radio', 'type', '', get_lang('HTMLText') ,'0');
123
+    $form->addElement('radio', 'type', '', get_lang('PageLink') ,'1');
124
+    $form->addElement('textarea', 'changes', get_lang('ExplainChanges'),array('width'=>'20'));
125 125
 
126
-	$preview = LegalManager::show_last_condition($term_preview);
126
+    $preview = LegalManager::show_last_condition($term_preview);
127 127
 
128
-	if ($term_preview['type']!=-1) {
129
-		$form->addElement('label', get_lang('Preview'),  $preview);
130
-	}
128
+    if ($term_preview['type']!=-1) {
129
+        $form->addElement('label', get_lang('Preview'),  $preview);
130
+    }
131 131
 
132
-	// Submit & preview button
132
+    // Submit & preview button
133 133
     $navigator_info = api_get_navigator();
134 134
 
135 135
     //ie6 fix
136
-	if ($navigator_info['name']=='Internet Explorer' &&  $navigator_info['version']=='6') {
137
-		$buttons = '<div class="row" align="center">
136
+    if ($navigator_info['name']=='Internet Explorer' &&  $navigator_info['version']=='6') {
137
+        $buttons = '<div class="row" align="center">
138 138
 				<div class="formw">
139 139
 				<input type="submit" name="back"  value="'.get_lang('Back').'"/>
140 140
 				<input type="submit" name="preview"  value="'.get_lang('Preview').'"/>
141 141
 				<input type="submit" name="save"  value="'.get_lang('Save').'"/>
142 142
 				</div>
143 143
 			</div>';
144
-			$form->addElement('html',$buttons);
145
-	} else {
144
+            $form->addElement('html',$buttons);
145
+    } else {
146 146
         $buttons = '<div class="row" align="center">
147 147
 					<div class="formw">
148 148
 					<button type="submit" class="back" 	 name="send" value="back">'.get_lang('Back').'</button>
@@ -150,11 +150,11 @@  discard block
 block discarded – undo
150 150
 					<button type="submit" class="save" 	 name="send" value="save">'.get_lang('Save').'</button>
151 151
 					</div>
152 152
 				</div>';
153
-		$form->addElement('html',$buttons);
154
-	}
153
+        $form->addElement('html',$buttons);
154
+    }
155 155
 } else {
156
-	$form->addElement('select_language', 'language', get_lang('Language'),null,array());
157
-	$form->addElement('button', 'send', get_lang('Load'));
156
+    $form->addElement('select_language', 'language', get_lang('Language'),null,array());
157
+    $form->addElement('button', 'send', get_lang('Load'));
158 158
 
159 159
 }
160 160
 
@@ -176,11 +176,11 @@  discard block
 block discarded – undo
176 176
 echo '</div>';
177 177
 
178 178
 if (isset ($_GET['action'])) {
179
-	switch ($_GET['action']) {
180
-		case 'show_message' :
181
-			Display :: display_normal_message(stripslashes($_GET['message']));
182
-			break;
183
-	}
179
+    switch ($_GET['action']) {
180
+        case 'show_message' :
181
+            Display :: display_normal_message(stripslashes($_GET['message']));
182
+            break;
183
+    }
184 184
 }
185 185
 
186 186
 $form->setDefaults($defaults);
Please login to merge, or discard this patch.