Completed
Push — master ( e4ee84...996ef7 )
by Julito
48:07 queued 18:14
created
main/gradebook/gradebook_add_eval.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
     null,
31 31
     'add_eval_form',
32 32
     null,
33
-    api_get_self() . '?selectcat=' . $select_cat.'&'.api_get_cidreq()
33
+    api_get_self().'?selectcat='.$select_cat.'&'.api_get_cidreq()
34 34
 );
35 35
 
36 36
 if ($form->validate()) {
@@ -69,23 +69,23 @@  discard block
 block discarded – undo
69 69
             //header('Location: gradebook_add_user.php?selecteval=' . $eval->get_id());
70 70
             exit;
71 71
         } else {
72
-            header('Location: ' . Security::remove_XSS($_SESSION['gradebook_dest']) . '?selectcat=' . $eval->get_category_id().'&'.api_get_cidreq());
72
+            header('Location: '.Security::remove_XSS($_SESSION['gradebook_dest']).'?selectcat='.$eval->get_category_id().'&'.api_get_cidreq());
73 73
             exit;
74 74
         }
75 75
     } else {
76 76
         $val_addresult = isset($values['addresult']) ? $values['addresult'] : null;
77 77
         if ($val_addresult == 1) {
78
-            header('Location: gradebook_add_result.php?selecteval=' . $eval->get_id().'&'.api_get_cidreq());
78
+            header('Location: gradebook_add_result.php?selecteval='.$eval->get_id().'&'.api_get_cidreq());
79 79
             exit;
80 80
         } else {
81
-            header('Location: ' . Security::remove_XSS($_SESSION['gradebook_dest']) . '?selectcat=' . $eval->get_category_id().'&'.api_get_cidreq());
81
+            header('Location: '.Security::remove_XSS($_SESSION['gradebook_dest']).'?selectcat='.$eval->get_category_id().'&'.api_get_cidreq());
82 82
             exit;
83 83
         }
84 84
     }
85 85
 }
86 86
 
87 87
 $interbreadcrumb[] = array(
88
-    'url' => Security::remove_XSS($_SESSION['gradebook_dest']) . '?selectcat=' . $select_cat.'&'.api_get_cidreq(),
88
+    'url' => Security::remove_XSS($_SESSION['gradebook_dest']).'?selectcat='.$select_cat.'&'.api_get_cidreq(),
89 89
     'name' => get_lang('Gradebook'))
90 90
 ;
91 91
 $this_section = SECTION_COURSES;
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
        $("#hid_category_id option:selected").each(function () {
99 99
            var cat_id = $(this).val();
100 100
             $.ajax({
101
-                url: "' . $url. '",
101
+                url: "' . $url.'",
102 102
                 data: "cat_id="+cat_id,
103 103
                 success: function(return_value) {
104 104
                     if (return_value != 0 ) {
Please login to merge, or discard this patch.
main/gradebook/lib/be/abstractlink.class.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -138,22 +138,22 @@  discard block
 block discarded – undo
138 138
         return $this->visible;
139 139
     }
140 140
 
141
-    public function set_id ($id)
141
+    public function set_id($id)
142 142
     {
143 143
         $this->id = $id;
144 144
     }
145 145
 
146
-    public function set_type ($type)
146
+    public function set_type($type)
147 147
     {
148 148
         $this->type = $type;
149 149
     }
150 150
 
151
-    public function set_ref_id ($ref_id)
151
+    public function set_ref_id($ref_id)
152 152
     {
153 153
         $this->ref_id = $ref_id;
154 154
     }
155 155
 
156
-    public function set_user_id ($user_id)
156
+    public function set_user_id($user_id)
157 157
     {
158 158
         $this->user_id = $user_id;
159 159
     }
@@ -240,20 +240,20 @@  discard block
 block discarded – undo
240 240
         $sql = 'SELECT * FROM '.$tbl_grade_links;
241 241
         $paramcount = 0;
242 242
         if (isset($id)) {
243
-            $sql.= ' WHERE id = '.intval($id);
244
-            $paramcount ++;
243
+            $sql .= ' WHERE id = '.intval($id);
244
+            $paramcount++;
245 245
         }
246 246
         if (isset($type)) {
247 247
             if ($paramcount != 0) $sql .= ' AND';
248 248
             else $sql .= ' WHERE';
249 249
             $sql .= ' type = '.intval($type);
250
-            $paramcount ++;
250
+            $paramcount++;
251 251
         }
252 252
         if (isset($ref_id)) {
253 253
             if ($paramcount != 0) $sql .= ' AND';
254 254
             else $sql .= ' WHERE';
255 255
             $sql .= ' ref_id = '.intval($ref_id);
256
-            $paramcount ++;
256
+            $paramcount++;
257 257
         }
258 258
         if (isset($user_id)) {
259 259
             if ($paramcount != 0) {
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
                 $sql .= ' WHERE';
263 263
             }
264 264
             $sql .= ' user_id = '.intval($user_id);
265
-            $paramcount ++;
265
+            $paramcount++;
266 266
         }
267 267
         if (isset($course_code)) {
268 268
             if ($paramcount != 0) {
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
                 $sql .= ' WHERE';
284 284
             }
285 285
             $sql .= ' category_id = '.intval($category_id);
286
-            $paramcount ++;
286
+            $paramcount++;
287 287
         }
288 288
         if (isset($visible)) {
289 289
             if ($paramcount != 0) {
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
             $session_id = api_get_session_id();
325 325
 
326 326
             $link->set_session_id($session_id);
327
-            $links[]=$link;
327
+            $links[] = $link;
328 328
         }
329 329
         return $links;
330 330
     }
@@ -417,12 +417,12 @@  discard block
 block discarded – undo
417 417
         $dateobject = AbstractLink::load($idevaluation, null, null, null, null);
418 418
         $current_date_server = api_get_utc_datetime();
419 419
         $arreval = get_object_vars($dateobject[0]);
420
-        $description_log = isset($arreval['description']) ? $arreval['description']:'';
420
+        $description_log = isset($arreval['description']) ? $arreval['description'] : '';
421 421
         if (empty($nameLog)) {
422 422
             if (isset($_POST['name_link'])) {
423 423
                 $name_log = isset($_POST['name_link']) ? $_POST['name_link'] : $arreval['course_code'];
424
-            } elseif (isset($_POST['link_' . $idevaluation]) && $_POST['link_' . $idevaluation]) {
425
-                $name_log = $_POST['link_' . $idevaluation];
424
+            } elseif (isset($_POST['link_'.$idevaluation]) && $_POST['link_'.$idevaluation]) {
425
+                $name_log = $_POST['link_'.$idevaluation];
426 426
             } else {
427 427
                 $name_log = $arreval['course_code'];
428 428
             }
@@ -467,10 +467,10 @@  discard block
 block discarded – undo
467 467
         $targets = array();
468 468
         $level = 0;
469 469
 
470
-        $crscats = Category::load(null,null,$this->get_course_code(),0);
470
+        $crscats = Category::load(null, null, $this->get_course_code(), 0);
471 471
         foreach ($crscats as $cat) {
472
-            $targets[] = array($cat->get_id(), $cat->get_name(), $level+1);
473
-            $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
472
+            $targets[] = array($cat->get_id(), $cat->get_name(), $level + 1);
473
+            $targets = $this->add_target_subcategories($targets, $level + 1, $cat->get_id());
474 474
         }
475 475
 
476 476
         return $targets;
@@ -482,10 +482,10 @@  discard block
 block discarded – undo
482 482
      */
483 483
     private function add_target_subcategories($targets, $level, $catid)
484 484
     {
485
-        $subcats = Category::load(null,null,null,$catid);
485
+        $subcats = Category::load(null, null, null, $catid);
486 486
         foreach ($subcats as $cat) {
487
-            $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
488
-            $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
487
+            $targets[] = array($cat->get_id(), $cat->get_name(), $level + 1);
488
+            $targets = $this->add_target_subcategories($targets, $level + 1, $cat->get_id());
489 489
         }
490 490
         return $targets;
491 491
     }
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
      * @todo can be written more efficiently using a new (but very complex) sql query
511 511
      * @param string $name_mask
512 512
      */
513
-    public function find_links ($name_mask,$selectcat)
513
+    public function find_links($name_mask, $selectcat)
514 514
     {
515 515
         $rootcat = Category::load($selectcat);
516 516
         $links = $rootcat[0]->get_links((api_is_allowed_to_edit() ? null : api_get_user_id()), true);
Please login to merge, or discard this patch.
main/gradebook/lib/be/evaluation.class.php 1 patch
Indentation   +741 added lines, -741 removed lines patch added patch discarded remove patch
@@ -9,236 +9,236 @@  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;
12
+    private $id;
13
+    private $name;
14
+    private $description;
15
+    private $user_id;
16
+    private $course_code;
17 17
     private $courseId;
18
-	/** @var Category */
19
-	private $category;
20
-	private $created_at;
21
-	private $weight;
22
-	private $eval_max;
23
-	private $visible;
24
-	private $sessionId;
25
-	public $studentList;
26
-
27
-	/**
28
-	 * Construct
29
-	 */
30
-	public function __construct()
31
-	{
32
-	}
33
-
34
-	/**
35
-	 * @return Category
36
-	 */
37
-	public function getCategory()
38
-	{
39
-		return $this->category;
40
-	}
41
-
42
-	/**
43
-	 * @param Category $category
44
-	 */
45
-	public function setCategory($category)
46
-	{
47
-		$this->category = $category;
48
-	}
49
-
50
-	/**
51
-	 * @return int
52
-	 */
53
-	public function get_category_id()
54
-	{
55
-		return $this->category->get_id();
56
-	}
57
-
58
-	/**
59
-	 * @param int $category_id
60
-	 */
61
-	public function set_category_id($category_id)
62
-	{
63
-		$categories = Category::load($category_id);
64
-		if (isset($categories[0])) {
65
-			$this->setCategory($categories[0]);
66
-		}
67
-	}
68
-
69
-	/**
70
-	 * @return int
71
-	 */
72
-	public function get_id()
73
-	{
74
-		return $this->id;
75
-	}
76
-
77
-	/**
78
-	 * @return string
79
-	 */
80
-	public function get_name()
81
-	{
82
-		return $this->name;
83
-	}
84
-
85
-	/**
86
-	 * @return string
87
-	 */
88
-	public function get_description()
89
-	{
90
-		return $this->description;
91
-	}
92
-
93
-	public function get_user_id()
94
-	{
95
-		return $this->user_id;
96
-	}
97
-
98
-	public function get_course_code()
99
-	{
100
-		return $this->course_code;
101
-	}
102
-
103
-	/**
104
-	 * @return int
105
-	 */
106
-	public function getSessionId()
107
-	{
108
-		return $this->sessionId;
109
-	}
110
-
111
-	/**
112
-	 * @param int $sessionId
113
-	 */
114
-	public function setSessionId($sessionId)
115
-	{
116
-		$this->sessionId = intval($sessionId);
117
-	}
118
-
119
-	public function get_date()
120
-	{
121
-		return $this->created_at;
122
-	}
123
-
124
-	public function get_weight()
125
-	{
126
-		return $this->weight;
127
-	}
128
-
129
-	public function get_max()
130
-	{
131
-		return $this->eval_max;
132
-	}
133
-
134
-	public function get_type()
135
-	{
136
-		return $this->type;
137
-	}
138
-
139
-	public function is_visible()
140
-	{
141
-		return $this->visible;
142
-	}
143
-
144
-	public function get_locked()
145
-	{
146
-		return $this->locked;
147
-	}
148
-
149
-	public function is_locked()
150
-	{
151
-		return isset($this->locked) && $this->locked == 1 ? true : false;
152
-	}
153
-
154
-	public function set_id($id)
155
-	{
156
-		$this->id = $id;
157
-	}
158
-
159
-	public function set_name($name)
160
-	{
161
-		$this->name = $name;
162
-	}
163
-
164
-	public function set_description($description)
165
-	{
166
-		$this->description = $description;
167
-	}
168
-
169
-	public function set_user_id($user_id)
170
-	{
171
-		$this->user_id = $user_id;
172
-	}
173
-
174
-	public function set_course_code($course_code)
175
-	{
176
-		$this->course_code = $course_code;
177
-	}
178
-
179
-	public function set_date($date)
180
-	{
181
-		$this->created_at = $date;
182
-	}
183
-
184
-	public function set_weight($weight)
185
-	{
186
-		$this->weight = $weight;
187
-	}
188
-
189
-	public function set_max($max)
190
-	{
191
-		$this->eval_max = $max;
192
-	}
193
-
194
-	public function set_visible($visible)
195
-	{
196
-		$this->visible = $visible;
197
-	}
198
-
199
-	public function set_type($type)
200
-	{
201
-		$this->type = $type;
202
-	}
203
-
204
-	public function set_locked($locked)
205
-	{
206
-		$this->locked = $locked;
207
-	}
208
-
209
-	/**
210
-	 * Retrieve evaluations and return them as an array of Evaluation objects
211
-	 * @param int $id evaluation id
212
-	 * @param int $user_id user id (evaluation owner)
213
-	 * @param string $course_code course code
214
-	 * @param int $category_id parent category
215
-	 * @param integer $visible visible
216
-	 */
217
-	public static function load(
218
-		$id = null,
219
-		$user_id = null,
220
-		$course_code = null,
221
-		$category_id = null,
222
-		$visible = null,
223
-		$locked = null
224
-	) {
225
-		$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
226
-		$sql = 'SELECT * FROM '.$tbl_grade_evaluations;
227
-		$paramcount = 0;
228
-
229
-		if (isset ($id)) {
230
-			$sql.= ' WHERE id = '.intval($id);
231
-			$paramcount ++;
232
-		}
233
-
234
-		if (isset($user_id)) {
235
-			if ($paramcount != 0) $sql .= ' AND';
236
-			else $sql .= ' WHERE';
237
-			$sql .= ' user_id = '.intval($user_id);
238
-			$paramcount ++;
239
-		}
240
-
241
-		if (isset($course_code) && $course_code <> '-1') {
18
+    /** @var Category */
19
+    private $category;
20
+    private $created_at;
21
+    private $weight;
22
+    private $eval_max;
23
+    private $visible;
24
+    private $sessionId;
25
+    public $studentList;
26
+
27
+    /**
28
+     * Construct
29
+     */
30
+    public function __construct()
31
+    {
32
+    }
33
+
34
+    /**
35
+     * @return Category
36
+     */
37
+    public function getCategory()
38
+    {
39
+        return $this->category;
40
+    }
41
+
42
+    /**
43
+     * @param Category $category
44
+     */
45
+    public function setCategory($category)
46
+    {
47
+        $this->category = $category;
48
+    }
49
+
50
+    /**
51
+     * @return int
52
+     */
53
+    public function get_category_id()
54
+    {
55
+        return $this->category->get_id();
56
+    }
57
+
58
+    /**
59
+     * @param int $category_id
60
+     */
61
+    public function set_category_id($category_id)
62
+    {
63
+        $categories = Category::load($category_id);
64
+        if (isset($categories[0])) {
65
+            $this->setCategory($categories[0]);
66
+        }
67
+    }
68
+
69
+    /**
70
+     * @return int
71
+     */
72
+    public function get_id()
73
+    {
74
+        return $this->id;
75
+    }
76
+
77
+    /**
78
+     * @return string
79
+     */
80
+    public function get_name()
81
+    {
82
+        return $this->name;
83
+    }
84
+
85
+    /**
86
+     * @return string
87
+     */
88
+    public function get_description()
89
+    {
90
+        return $this->description;
91
+    }
92
+
93
+    public function get_user_id()
94
+    {
95
+        return $this->user_id;
96
+    }
97
+
98
+    public function get_course_code()
99
+    {
100
+        return $this->course_code;
101
+    }
102
+
103
+    /**
104
+     * @return int
105
+     */
106
+    public function getSessionId()
107
+    {
108
+        return $this->sessionId;
109
+    }
110
+
111
+    /**
112
+     * @param int $sessionId
113
+     */
114
+    public function setSessionId($sessionId)
115
+    {
116
+        $this->sessionId = intval($sessionId);
117
+    }
118
+
119
+    public function get_date()
120
+    {
121
+        return $this->created_at;
122
+    }
123
+
124
+    public function get_weight()
125
+    {
126
+        return $this->weight;
127
+    }
128
+
129
+    public function get_max()
130
+    {
131
+        return $this->eval_max;
132
+    }
133
+
134
+    public function get_type()
135
+    {
136
+        return $this->type;
137
+    }
138
+
139
+    public function is_visible()
140
+    {
141
+        return $this->visible;
142
+    }
143
+
144
+    public function get_locked()
145
+    {
146
+        return $this->locked;
147
+    }
148
+
149
+    public function is_locked()
150
+    {
151
+        return isset($this->locked) && $this->locked == 1 ? true : false;
152
+    }
153
+
154
+    public function set_id($id)
155
+    {
156
+        $this->id = $id;
157
+    }
158
+
159
+    public function set_name($name)
160
+    {
161
+        $this->name = $name;
162
+    }
163
+
164
+    public function set_description($description)
165
+    {
166
+        $this->description = $description;
167
+    }
168
+
169
+    public function set_user_id($user_id)
170
+    {
171
+        $this->user_id = $user_id;
172
+    }
173
+
174
+    public function set_course_code($course_code)
175
+    {
176
+        $this->course_code = $course_code;
177
+    }
178
+
179
+    public function set_date($date)
180
+    {
181
+        $this->created_at = $date;
182
+    }
183
+
184
+    public function set_weight($weight)
185
+    {
186
+        $this->weight = $weight;
187
+    }
188
+
189
+    public function set_max($max)
190
+    {
191
+        $this->eval_max = $max;
192
+    }
193
+
194
+    public function set_visible($visible)
195
+    {
196
+        $this->visible = $visible;
197
+    }
198
+
199
+    public function set_type($type)
200
+    {
201
+        $this->type = $type;
202
+    }
203
+
204
+    public function set_locked($locked)
205
+    {
206
+        $this->locked = $locked;
207
+    }
208
+
209
+    /**
210
+     * Retrieve evaluations and return them as an array of Evaluation objects
211
+     * @param int $id evaluation id
212
+     * @param int $user_id user id (evaluation owner)
213
+     * @param string $course_code course code
214
+     * @param int $category_id parent category
215
+     * @param integer $visible visible
216
+     */
217
+    public static function load(
218
+        $id = null,
219
+        $user_id = null,
220
+        $course_code = null,
221
+        $category_id = null,
222
+        $visible = null,
223
+        $locked = null
224
+    ) {
225
+        $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
226
+        $sql = 'SELECT * FROM '.$tbl_grade_evaluations;
227
+        $paramcount = 0;
228
+
229
+        if (isset ($id)) {
230
+            $sql.= ' WHERE id = '.intval($id);
231
+            $paramcount ++;
232
+        }
233
+
234
+        if (isset($user_id)) {
235
+            if ($paramcount != 0) $sql .= ' AND';
236
+            else $sql .= ' WHERE';
237
+            $sql .= ' user_id = '.intval($user_id);
238
+            $paramcount ++;
239
+        }
240
+
241
+        if (isset($course_code) && $course_code <> '-1') {
242 242
             $courseInfo = api_get_course_info($course_code);
243 243
             if ($courseInfo) {
244 244
                 if ($paramcount != 0) {
@@ -249,137 +249,137 @@  discard block
 block discarded – undo
249 249
                 $sql .= " c_id = '".$courseInfo['real_id']."'";
250 250
                 $paramcount++;
251 251
             }
252
-		}
253
-
254
-		if (isset($category_id)) {
255
-			if ($paramcount != 0) $sql .= ' AND';
256
-			else $sql .= ' WHERE';
257
-			$sql .= ' category_id = '.intval($category_id);
258
-			$paramcount ++;
259
-		}
260
-
261
-		if (isset($visible)) {
262
-			if ($paramcount != 0) $sql .= ' AND';
263
-			else $sql .= ' WHERE';
264
-			$sql .= ' visible = '.intval($visible);
265
-			$paramcount ++;
266
-		}
267
-
268
-		if (isset($locked)) {
269
-			if ($paramcount != 0) $sql .= ' AND';
270
-			else $sql .= ' WHERE';
271
-			$sql .= ' locked = '.intval($locked);
272
-		}
273
-
274
-		$result = Database::query($sql);
275
-		$allEval = Evaluation::create_evaluation_objects_from_sql_result($result);
276
-
277
-		return $allEval;
278
-	}
279
-
280
-	/**
281
-	 * @param array $result
282
-	 * @return array
283
-	 */
284
-	private static function create_evaluation_objects_from_sql_result($result)
285
-	{
286
-		$alleval = array();
287
-		if (Database::num_rows($result)) {
288
-			while ($data = Database::fetch_array($result)) {
289
-				$eval= new Evaluation();
290
-				$eval->set_id($data['id']);
291
-				$eval->set_name($data['name']);
292
-				$eval->set_description($data['description']);
293
-				$eval->set_user_id($data['user_id']);
252
+        }
253
+
254
+        if (isset($category_id)) {
255
+            if ($paramcount != 0) $sql .= ' AND';
256
+            else $sql .= ' WHERE';
257
+            $sql .= ' category_id = '.intval($category_id);
258
+            $paramcount ++;
259
+        }
260
+
261
+        if (isset($visible)) {
262
+            if ($paramcount != 0) $sql .= ' AND';
263
+            else $sql .= ' WHERE';
264
+            $sql .= ' visible = '.intval($visible);
265
+            $paramcount ++;
266
+        }
267
+
268
+        if (isset($locked)) {
269
+            if ($paramcount != 0) $sql .= ' AND';
270
+            else $sql .= ' WHERE';
271
+            $sql .= ' locked = '.intval($locked);
272
+        }
273
+
274
+        $result = Database::query($sql);
275
+        $allEval = Evaluation::create_evaluation_objects_from_sql_result($result);
276
+
277
+        return $allEval;
278
+    }
279
+
280
+    /**
281
+     * @param array $result
282
+     * @return array
283
+     */
284
+    private static function create_evaluation_objects_from_sql_result($result)
285
+    {
286
+        $alleval = array();
287
+        if (Database::num_rows($result)) {
288
+            while ($data = Database::fetch_array($result)) {
289
+                $eval= new Evaluation();
290
+                $eval->set_id($data['id']);
291
+                $eval->set_name($data['name']);
292
+                $eval->set_description($data['description']);
293
+                $eval->set_user_id($data['user_id']);
294 294
                 $eval->setCourseId($data['c_id']);
295 295
                 $courseInfo = api_get_course_info_by_id($data['c_id']);
296
-				$eval->set_course_code($courseInfo['course_code']);
297
-				$eval->set_category_id($data['category_id']);
298
-				$eval->set_date(api_get_local_time($data['created_at']));
299
-				$eval->set_weight($data['weight']);
300
-				$eval->set_max($data['max']);
301
-				$eval->set_visible($data['visible']);
302
-				$eval->set_type($data['type']);
303
-				$eval->set_locked($data['locked']);
304
-				$eval->setSessionId(api_get_session_id());
305
-
306
-				$alleval[] = $eval;
307
-			}
308
-		}
309
-
310
-		return $alleval;
311
-	}
312
-
313
-	/**
314
-	 * Insert this evaluation into the database
315
-	 */
296
+                $eval->set_course_code($courseInfo['course_code']);
297
+                $eval->set_category_id($data['category_id']);
298
+                $eval->set_date(api_get_local_time($data['created_at']));
299
+                $eval->set_weight($data['weight']);
300
+                $eval->set_max($data['max']);
301
+                $eval->set_visible($data['visible']);
302
+                $eval->set_type($data['type']);
303
+                $eval->set_locked($data['locked']);
304
+                $eval->setSessionId(api_get_session_id());
305
+
306
+                $alleval[] = $eval;
307
+            }
308
+        }
309
+
310
+        return $alleval;
311
+    }
312
+
313
+    /**
314
+     * Insert this evaluation into the database
315
+     */
316 316
     public function add()
317
-	{
318
-		if (isset($this->name) &&
319
-			isset($this->user_id) &&
320
-			isset($this->weight) &&
321
-			isset ($this->eval_max) &&
322
-			isset($this->visible)
323
-		) {
324
-			$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
325
-
326
-			$sql = 'INSERT INTO '.$tbl_grade_evaluations
327
-				.' (name, user_id, weight, max, visible, locked';
328
-			if (isset($this->description)) {
329
-				$sql .= ',description';
330
-			}
331
-			if (isset($this->courseId)) {
332
-				$sql .= ', c_id';
333
-			}
334
-			if (isset($this->category)) {
335
-				$sql .= ', category_id';
336
-			}
337
-			$sql .= ', created_at';
338
-			$sql .= ',type';
339
-			$sql .= ") VALUES ('".Database::escape_string(
340
-			    $this->get_name())."'"
341
-				.','.intval($this->get_user_id())
342
-				.','.floatval($this->get_weight())
343
-				.','.intval($this->get_max())
344
-				.','.intval($this->is_visible())
317
+    {
318
+        if (isset($this->name) &&
319
+            isset($this->user_id) &&
320
+            isset($this->weight) &&
321
+            isset ($this->eval_max) &&
322
+            isset($this->visible)
323
+        ) {
324
+            $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
325
+
326
+            $sql = 'INSERT INTO '.$tbl_grade_evaluations
327
+                .' (name, user_id, weight, max, visible, locked';
328
+            if (isset($this->description)) {
329
+                $sql .= ',description';
330
+            }
331
+            if (isset($this->courseId)) {
332
+                $sql .= ', c_id';
333
+            }
334
+            if (isset($this->category)) {
335
+                $sql .= ', category_id';
336
+            }
337
+            $sql .= ', created_at';
338
+            $sql .= ',type';
339
+            $sql .= ") VALUES ('".Database::escape_string(
340
+                $this->get_name())."'"
341
+                .','.intval($this->get_user_id())
342
+                .','.floatval($this->get_weight())
343
+                .','.intval($this->get_max())
344
+                .','.intval($this->is_visible())
345 345
                 .','.intval(0)
346 346
             ;
347
-			if (isset($this->description)) {
348
-				$sql .= ",'".Database::escape_string($this->get_description())."'";
349
-			}
350
-			if (isset($this->courseId)) {
351
-				$sql .= ",'".Database::escape_string($this->getCourseId())."'";
352
-			}
353
-			if (isset($this->category)) {
354
-				$sql .= ','.intval($this->get_category_id());
355
-			}
356
-			if (empty($this->type)) {
357
-				$this->type = 'evaluation';
358
-			}
359
-			$sql .= ", '".api_get_utc_datetime()."'";
360
-			$sql .= ',\''.Database::escape_string($this->type).'\'';
361
-			$sql .= ")";
362
-
363
-			Database::query($sql);
364
-			$this->set_id(Database::insert_id());
365
-		} else {
366
-			die('Error in Evaluation add: required field empty');
367
-		}
368
-	}
369
-
370
-	/**
371
-	 * @param int $idevaluation
372
-	 */
373
-	public function add_evaluation_log($idevaluation)
374
-	{
375
-		if (!empty($idevaluation)) {
376
-			$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
377
-			$tbl_grade_linkeval_log = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINKEVAL_LOG);
378
-			$eval = new Evaluation();
379
-			$dateobject = $eval->load($idevaluation,null,null,null,null);
380
-			$arreval = get_object_vars($dateobject[0]);
381
-			if (!empty($arreval['id'])) {
382
-				$sql = 'SELECT weight from '.$tbl_grade_evaluations.'
347
+            if (isset($this->description)) {
348
+                $sql .= ",'".Database::escape_string($this->get_description())."'";
349
+            }
350
+            if (isset($this->courseId)) {
351
+                $sql .= ",'".Database::escape_string($this->getCourseId())."'";
352
+            }
353
+            if (isset($this->category)) {
354
+                $sql .= ','.intval($this->get_category_id());
355
+            }
356
+            if (empty($this->type)) {
357
+                $this->type = 'evaluation';
358
+            }
359
+            $sql .= ", '".api_get_utc_datetime()."'";
360
+            $sql .= ',\''.Database::escape_string($this->type).'\'';
361
+            $sql .= ")";
362
+
363
+            Database::query($sql);
364
+            $this->set_id(Database::insert_id());
365
+        } else {
366
+            die('Error in Evaluation add: required field empty');
367
+        }
368
+    }
369
+
370
+    /**
371
+     * @param int $idevaluation
372
+     */
373
+    public function add_evaluation_log($idevaluation)
374
+    {
375
+        if (!empty($idevaluation)) {
376
+            $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
377
+            $tbl_grade_linkeval_log = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINKEVAL_LOG);
378
+            $eval = new Evaluation();
379
+            $dateobject = $eval->load($idevaluation,null,null,null,null);
380
+            $arreval = get_object_vars($dateobject[0]);
381
+            if (!empty($arreval['id'])) {
382
+                $sql = 'SELECT weight from '.$tbl_grade_evaluations.'
383 383
                         WHERE id='.$arreval['id'];
384 384
                 $rs = Database::query($sql);
385 385
                 $row_old_weight = Database::fetch_array($rs, 'ASSOC');
@@ -395,430 +395,430 @@  discard block
 block discarded – undo
395 395
                     'user_id_log' => api_get_user_id()
396 396
                 ];
397 397
                 Database::insert($tbl_grade_linkeval_log, $params);
398
-			}
399
-		}
400
-	}
401
-
402
-	/**
403
-	 * Update the properties of this evaluation in the database
404
-	 */
405
-	public function save()
406
-	{
407
-		$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
408
-		$sql = 'UPDATE '.$tbl_grade_evaluations
409
-			." SET name = '".Database::escape_string($this->get_name())."'"
410
-			.', description = ';
411
-		if (isset($this->description)) {
412
-			$sql .= "'".Database::escape_string($this->get_description())."'";
413
-		}else {
414
-			$sql .= 'null';
415
-		}
416
-		$sql .= ', user_id = '.intval($this->get_user_id())
417
-			.', c_id = ';
418
-		if (isset($this->courseId)) {
419
-			$sql .= "'".Database::escape_string($this->getCourseId())."'";
420
-		} else {
421
-			$sql .= 'null';
422
-		}
423
-		$sql .= ', category_id = ';
424
-		if (isset($this->category)) {
425
-			$sql .= intval($this->get_category_id());
426
-		} else {
427
-			$sql .= 'null';
428
-		}
429
-		$sql .= ', weight = "'.Database::escape_string($this->get_weight()).'" '
430
-			.', max = '.intval($this->get_max())
431
-			.', visible = '.intval($this->is_visible())
432
-			.' WHERE id = '.intval($this->id);
433
-		//recorded history
434
-
435
-		$eval_log = new Evaluation();
436
-		$eval_log->add_evaluation_log($this->id);
437
-		Database::query($sql);
438
-	}
439
-
440
-	/**
441
-	 * Delete this evaluation from the database
442
-	 */
443
-	public function delete()
444
-	{
445
-		$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
446
-		$sql = 'DELETE FROM '.$tbl_grade_evaluations.' WHERE id = '.intval($this->id);
447
-		Database::query($sql);
448
-	}
449
-
450
-	/**
451
-	 * Check if an evaluation name (with the same parent category) already exists
452
-	 * @param $name name to check (if not given, the name property of this object will be checked)
453
-	 * @param $parent parent category
454
-	 */
455
-	public function does_name_exist($name, $parent)
456
-	{
457
-		if (!isset ($name)) {
458
-			$name = $this->name;
459
-			$parent = $this->category;
460
-		}
461
-		$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
462
-		$sql = 'SELECT count(id) AS number'
463
-			.' FROM '.$tbl_grade_evaluations
464
-			." WHERE name = '".Database::escape_string($name)."'";
465
-
466
-		if (api_is_allowed_to_edit()) {
467
-			$parent = Category::load($parent);
468
-			$courseId = $parent[0]->getCourseId();
469
-			if (isset($courseId) && !empty($courseId)) {
470
-				$table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
471
-				$sql .= ' AND user_id IN (
398
+            }
399
+        }
400
+    }
401
+
402
+    /**
403
+     * Update the properties of this evaluation in the database
404
+     */
405
+    public function save()
406
+    {
407
+        $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
408
+        $sql = 'UPDATE '.$tbl_grade_evaluations
409
+            ." SET name = '".Database::escape_string($this->get_name())."'"
410
+            .', description = ';
411
+        if (isset($this->description)) {
412
+            $sql .= "'".Database::escape_string($this->get_description())."'";
413
+        }else {
414
+            $sql .= 'null';
415
+        }
416
+        $sql .= ', user_id = '.intval($this->get_user_id())
417
+            .', c_id = ';
418
+        if (isset($this->courseId)) {
419
+            $sql .= "'".Database::escape_string($this->getCourseId())."'";
420
+        } else {
421
+            $sql .= 'null';
422
+        }
423
+        $sql .= ', category_id = ';
424
+        if (isset($this->category)) {
425
+            $sql .= intval($this->get_category_id());
426
+        } else {
427
+            $sql .= 'null';
428
+        }
429
+        $sql .= ', weight = "'.Database::escape_string($this->get_weight()).'" '
430
+            .', max = '.intval($this->get_max())
431
+            .', visible = '.intval($this->is_visible())
432
+            .' WHERE id = '.intval($this->id);
433
+        //recorded history
434
+
435
+        $eval_log = new Evaluation();
436
+        $eval_log->add_evaluation_log($this->id);
437
+        Database::query($sql);
438
+    }
439
+
440
+    /**
441
+     * Delete this evaluation from the database
442
+     */
443
+    public function delete()
444
+    {
445
+        $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
446
+        $sql = 'DELETE FROM '.$tbl_grade_evaluations.' WHERE id = '.intval($this->id);
447
+        Database::query($sql);
448
+    }
449
+
450
+    /**
451
+     * Check if an evaluation name (with the same parent category) already exists
452
+     * @param $name name to check (if not given, the name property of this object will be checked)
453
+     * @param $parent parent category
454
+     */
455
+    public function does_name_exist($name, $parent)
456
+    {
457
+        if (!isset ($name)) {
458
+            $name = $this->name;
459
+            $parent = $this->category;
460
+        }
461
+        $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
462
+        $sql = 'SELECT count(id) AS number'
463
+            .' FROM '.$tbl_grade_evaluations
464
+            ." WHERE name = '".Database::escape_string($name)."'";
465
+
466
+        if (api_is_allowed_to_edit()) {
467
+            $parent = Category::load($parent);
468
+            $courseId = $parent[0]->getCourseId();
469
+            if (isset($courseId) && !empty($courseId)) {
470
+                $table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
471
+                $sql .= ' AND user_id IN (
472 472
 					 SELECT user_id FROM '.$table.'
473 473
 					 WHERE
474 474
 						c_id = '.$courseId.' AND
475 475
 						status = '.COURSEMANAGER.'
476 476
 					)';
477
-			} else {
478
-				$sql .= ' AND user_id = '.api_get_user_id();
479
-			}
480
-
481
-		}else {
482
-			$sql .= ' AND user_id = '.api_get_user_id();
483
-		}
484
-
485
-		if (!isset ($parent)) {
486
-			$sql.= ' AND category_id is null';
487
-		} else {
488
-			$sql.= ' AND category_id = '.intval($parent);
489
-		}
490
-		$result = Database::query($sql);
491
-		$number=Database::fetch_row($result);
492
-
493
-		return $number[0] != 0;
494
-	}
495
-
496
-	/**
497
-	 * Are there any results for this evaluation yet ?
498
-	 * The 'max' property should not be changed then.
499
-	 */
500
-	public function has_results()
501
-	{
502
-		$tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
503
-		$sql = 'SELECT count(id) AS number
477
+            } else {
478
+                $sql .= ' AND user_id = '.api_get_user_id();
479
+            }
480
+
481
+        }else {
482
+            $sql .= ' AND user_id = '.api_get_user_id();
483
+        }
484
+
485
+        if (!isset ($parent)) {
486
+            $sql.= ' AND category_id is null';
487
+        } else {
488
+            $sql.= ' AND category_id = '.intval($parent);
489
+        }
490
+        $result = Database::query($sql);
491
+        $number=Database::fetch_row($result);
492
+
493
+        return $number[0] != 0;
494
+    }
495
+
496
+    /**
497
+     * Are there any results for this evaluation yet ?
498
+     * The 'max' property should not be changed then.
499
+     */
500
+    public function has_results()
501
+    {
502
+        $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
503
+        $sql = 'SELECT count(id) AS number
504 504
 				FROM '.$tbl_grade_results.'
505 505
 				WHERE evaluation_id = '.intval($this->id);
506
-		$result = Database::query($sql);
507
-		$number=Database::fetch_row($result);
508
-
509
-		return ($number[0] != 0);
510
-	}
511
-
512
-	/**
513
-	 * Delete all results for this evaluation
514
-	 */
515
-	public function delete_results()
516
-	{
517
-		$tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
518
-		$sql = 'DELETE FROM '.$tbl_grade_results.'
506
+        $result = Database::query($sql);
507
+        $number=Database::fetch_row($result);
508
+
509
+        return ($number[0] != 0);
510
+    }
511
+
512
+    /**
513
+     * Delete all results for this evaluation
514
+     */
515
+    public function delete_results()
516
+    {
517
+        $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
518
+        $sql = 'DELETE FROM '.$tbl_grade_results.'
519 519
 				WHERE evaluation_id = '.intval($this->id);
520
-		Database::query($sql);
521
-	}
522
-
523
-	/**
524
-	 * Delete this evaluation and all underlying results.
525
-	 */
526
-	public function delete_with_results()
527
-	{
528
-		$this->delete_results();
529
-		$this->delete();
530
-	}
531
-
532
-	/**
533
-	 * Check if the given score is possible for this evaluation
534
-	 */
535
-	public function is_valid_score($score)
536
-	{
537
-		return is_numeric($score) && $score >= 0 && $score <= $this->eval_max;
538
-	}
539
-
540
-	/**
541
-	 * Calculate the score of this evaluation
542
-	 * @param int $stud_id (default: all students who have results for this eval - then the average is returned)
543
-	 * @param string $type (best, average, ranking)
544
-	 * @return	array (score, max) if student is given
545
-	 * 			array (sum of scores, number of scores) otherwise
546
-	 * 			or null if no scores available
547
-	 */
548
-	public function calc_score($stud_id = null, $type = null)
549
-	{
520
+        Database::query($sql);
521
+    }
522
+
523
+    /**
524
+     * Delete this evaluation and all underlying results.
525
+     */
526
+    public function delete_with_results()
527
+    {
528
+        $this->delete_results();
529
+        $this->delete();
530
+    }
531
+
532
+    /**
533
+     * Check if the given score is possible for this evaluation
534
+     */
535
+    public function is_valid_score($score)
536
+    {
537
+        return is_numeric($score) && $score >= 0 && $score <= $this->eval_max;
538
+    }
539
+
540
+    /**
541
+     * Calculate the score of this evaluation
542
+     * @param int $stud_id (default: all students who have results for this eval - then the average is returned)
543
+     * @param string $type (best, average, ranking)
544
+     * @return	array (score, max) if student is given
545
+     * 			array (sum of scores, number of scores) otherwise
546
+     * 			or null if no scores available
547
+     */
548
+    public function calc_score($stud_id = null, $type = null)
549
+    {
550 550
         $useSession = true;
551
-		if (isset($stud_id) && empty($type)) {
552
-			$key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id.'_'.$stud_id;
553
-			$data = Session::read('calc_score');
551
+        if (isset($stud_id) && empty($type)) {
552
+            $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id.'_'.$stud_id;
553
+            $data = Session::read('calc_score');
554 554
             $results = isset($data[$key]) ? $data[$key] : null;
555 555
 
556 556
             if ($useSession == false) {
557 557
                 $results  = null;
558 558
             }
559
-			if (empty($results)) {
560
-				$results = Result::load(null, $stud_id, $this->id);
561
-				Session::write('calc_score', array($key => $results));
562
-			}
563
-
564
-			$score = 0;
565
-			/** @var Result $res */
566
-			foreach ($results as $res) {
567
-				$score = $res->get_score();
568
-			}
569
-
570
-			return array($score, $this->get_max());
571
-		} else {
572
-
573
-			$count = 0;
574
-			$sum = 0;
575
-			$bestResult = 0;
576
-			$weight = 0;
577
-			$sumResult = 0;
578
-
579
-			$key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id;
559
+            if (empty($results)) {
560
+                $results = Result::load(null, $stud_id, $this->id);
561
+                Session::write('calc_score', array($key => $results));
562
+            }
563
+
564
+            $score = 0;
565
+            /** @var Result $res */
566
+            foreach ($results as $res) {
567
+                $score = $res->get_score();
568
+            }
569
+
570
+            return array($score, $this->get_max());
571
+        } else {
572
+
573
+            $count = 0;
574
+            $sum = 0;
575
+            $bestResult = 0;
576
+            $weight = 0;
577
+            $sumResult = 0;
578
+
579
+            $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id;
580 580
             $data = Session::read('calc_score');
581 581
             $allResults = isset($data[$key]) ? $data[$key] : null;
582 582
             if ($useSession == false) {
583 583
                 $allResults  = null;
584 584
             }
585
-			if (empty($allResults)) {
586
-				$allResults = Result::load(null, null, $this->id);
587
-				Session::write($key, $allResults);
588
-			}
589
-
590
-			$students = array();
591
-			/** @var Result $res */
592
-			foreach ($allResults as $res) {
593
-				$score = $res->get_score();
594
-				if (!empty($score) || $score == '0') {
595
-					$count++;
596
-					$sum += $score / $this->get_max();
597
-					$sumResult += $score;
598
-					if ($score > $bestResult) {
599
-						$bestResult = $score;
600
-					}
601
-					$weight = $this->get_max();
602
-				}
603
-				$students[$res->get_user_id()] = $score;
604
-			}
605
-
606
-			if (empty($count)) {
607
-				return null;
608
-			}
609
-
610
-			switch ($type) {
611
-				case 'best':
612
-					return array($bestResult, $weight);
613
-					break;
614
-				case 'average':
615
-					return array($sumResult/$count, $weight);
616
-					break;
617
-				case 'ranking':
585
+            if (empty($allResults)) {
586
+                $allResults = Result::load(null, null, $this->id);
587
+                Session::write($key, $allResults);
588
+            }
589
+
590
+            $students = array();
591
+            /** @var Result $res */
592
+            foreach ($allResults as $res) {
593
+                $score = $res->get_score();
594
+                if (!empty($score) || $score == '0') {
595
+                    $count++;
596
+                    $sum += $score / $this->get_max();
597
+                    $sumResult += $score;
598
+                    if ($score > $bestResult) {
599
+                        $bestResult = $score;
600
+                    }
601
+                    $weight = $this->get_max();
602
+                }
603
+                $students[$res->get_user_id()] = $score;
604
+            }
605
+
606
+            if (empty($count)) {
607
+                return null;
608
+            }
609
+
610
+            switch ($type) {
611
+                case 'best':
612
+                    return array($bestResult, $weight);
613
+                    break;
614
+                case 'average':
615
+                    return array($sumResult/$count, $weight);
616
+                    break;
617
+                case 'ranking':
618 618
                     $students = array();
619 619
                     /** @var Result $res */
620 620
                     foreach ($allResults as $res) {
621 621
                         $score = $res->get_score();
622 622
                         $students[$res->get_user_id()] = $score;
623 623
                     }
624
-					return AbstractLink::getCurrentUserRanking($stud_id, $students);
625
-					break;
626
-				default:
627
-					return array($sum, $count);
628
-					break;
629
-			}
630
-		}
631
-	}
632
-
633
-	/**
634
-	 * Generate an array of possible categories where this evaluation can be moved to.
635
-	 * Notice: its own parent will be included in the list: it's up to the frontend
636
-	 * to disable this element.
637
-	 * @return array 2-dimensional array - every element contains 3 subelements (id, name, level)
638
-	 */
639
-	public function get_target_categories()
640
-	{
641
-		// - course independent evaluation
642
-		//   -> movable to root or other course independent categories
643
-		// - evaluation inside a course
644
-		//   -> movable to root, independent categories or categories inside the course
645
-		$user = (api_is_platform_admin() ? null : api_get_user_id());
646
-		$targets = array();
647
-		$level = 0;
648
-
649
-		$root = array(0, get_lang('RootCat'), $level);
650
-		$targets[] = $root;
651
-
652
-		if (isset($this->courseId) && !empty($this->courseId)) {
653
-			$crscats = Category::load(null,null,$this->course_code,0);
654
-			foreach ($crscats as $cat) {
655
-				$targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
656
-				$targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
657
-			}
658
-		}
659
-
660
-		$indcats = Category::load(null,$user,0,0);
661
-		foreach ($indcats as $cat) {
662
-			$targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
663
-			$targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
664
-		}
665
-
666
-		return $targets;
667
-	}
668
-
669
-	/**
670
-	 * Internal function used by get_target_categories()
671
-	 * @param integer $level
672
-	 */
673
-	private function add_target_subcategories($targets, $level, $catid)
674
-	{
675
-		$subcats = Category::load(null,null,null,$catid);
676
-		foreach ($subcats as $cat) {
677
-			$targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
678
-			$targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
679
-		}
680
-		return $targets;
681
-	}
682
-
683
-	/**
684
-	 * Move this evaluation to the given category.
685
-	 * If this evaluation moves from inside a course to outside,
686
-	 * its course code is also changed.
687
-	 */
688
-	public function move_to_cat($cat)
689
-	{
690
-		$this->set_category_id($cat->get_id());
691
-		if ($this->get_course_code() != $cat->get_course_code()) {
692
-			$this->set_course_code($cat->get_course_code());
693
-		}
694
-		$this->save();
695
-	}
696
-
697
-	/**
698
-	 * Retrieve evaluations where a student has results for
699
-	 * and return them as an array of Evaluation objects
700
-	 * @param int $cat_id parent category (use 'null' to retrieve them in all categories)
701
-	 * @param int $stud_id student id
702
-	 */
703
-	public static function get_evaluations_with_result_for_student($cat_id = null, $stud_id)
704
-	{
705
-		$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
706
-		$tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
707
-
708
-		$sql = 'SELECT * FROM '.$tbl_grade_evaluations.'
624
+                    return AbstractLink::getCurrentUserRanking($stud_id, $students);
625
+                    break;
626
+                default:
627
+                    return array($sum, $count);
628
+                    break;
629
+            }
630
+        }
631
+    }
632
+
633
+    /**
634
+     * Generate an array of possible categories where this evaluation can be moved to.
635
+     * Notice: its own parent will be included in the list: it's up to the frontend
636
+     * to disable this element.
637
+     * @return array 2-dimensional array - every element contains 3 subelements (id, name, level)
638
+     */
639
+    public function get_target_categories()
640
+    {
641
+        // - course independent evaluation
642
+        //   -> movable to root or other course independent categories
643
+        // - evaluation inside a course
644
+        //   -> movable to root, independent categories or categories inside the course
645
+        $user = (api_is_platform_admin() ? null : api_get_user_id());
646
+        $targets = array();
647
+        $level = 0;
648
+
649
+        $root = array(0, get_lang('RootCat'), $level);
650
+        $targets[] = $root;
651
+
652
+        if (isset($this->courseId) && !empty($this->courseId)) {
653
+            $crscats = Category::load(null,null,$this->course_code,0);
654
+            foreach ($crscats as $cat) {
655
+                $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
656
+                $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
657
+            }
658
+        }
659
+
660
+        $indcats = Category::load(null,$user,0,0);
661
+        foreach ($indcats as $cat) {
662
+            $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
663
+            $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
664
+        }
665
+
666
+        return $targets;
667
+    }
668
+
669
+    /**
670
+     * Internal function used by get_target_categories()
671
+     * @param integer $level
672
+     */
673
+    private function add_target_subcategories($targets, $level, $catid)
674
+    {
675
+        $subcats = Category::load(null,null,null,$catid);
676
+        foreach ($subcats as $cat) {
677
+            $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
678
+            $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
679
+        }
680
+        return $targets;
681
+    }
682
+
683
+    /**
684
+     * Move this evaluation to the given category.
685
+     * If this evaluation moves from inside a course to outside,
686
+     * its course code is also changed.
687
+     */
688
+    public function move_to_cat($cat)
689
+    {
690
+        $this->set_category_id($cat->get_id());
691
+        if ($this->get_course_code() != $cat->get_course_code()) {
692
+            $this->set_course_code($cat->get_course_code());
693
+        }
694
+        $this->save();
695
+    }
696
+
697
+    /**
698
+     * Retrieve evaluations where a student has results for
699
+     * and return them as an array of Evaluation objects
700
+     * @param int $cat_id parent category (use 'null' to retrieve them in all categories)
701
+     * @param int $stud_id student id
702
+     */
703
+    public static function get_evaluations_with_result_for_student($cat_id = null, $stud_id)
704
+    {
705
+        $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
706
+        $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
707
+
708
+        $sql = 'SELECT * FROM '.$tbl_grade_evaluations.'
709 709
 				WHERE id IN (
710 710
 					SELECT evaluation_id FROM '.$tbl_grade_results.'
711 711
 					WHERE user_id = '.intval($stud_id).' AND score IS NOT NULL
712 712
 				)';
713
-		if (!api_is_allowed_to_edit()) {
714
-			$sql .= ' AND visible = 1';
715
-		}
716
-		if (isset($cat_id)) {
717
-			$sql .= ' AND category_id = '.intval($cat_id);
718
-		} else {
719
-			$sql .= ' AND category_id >= 0';
720
-		}
721
-
722
-		$result = Database::query($sql);
723
-		$alleval = Evaluation::create_evaluation_objects_from_sql_result($result);
724
-
725
-		return $alleval;
726
-	}
727
-
728
-	/**
729
-	 * Get a list of students that do not have a result record for this evaluation
730
-	 */
731
-	public function get_not_subscribed_students($first_letter_user = '')
732
-	{
733
-		$tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
734
-		$tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
735
-
736
-		$sql = 'SELECT user_id,lastname,firstname,username FROM '.$tbl_user
737
-			." WHERE lastname LIKE '".Database::escape_string($first_letter_user)."%'"
738
-			.' AND status = '.STUDENT
739
-			.' AND user_id NOT IN'
740
-			.' (SELECT user_id FROM '.$tbl_grade_results
741
-			.' WHERE evaluation_id = '.intval($this->id)
742
-			.' )'
743
-			.' ORDER BY lastname';
744
-
745
-		$result = Database::query($sql);
746
-		$users = Database::store_result($result);
747
-
748
-		return $users;
749
-	}
750
-
751
-	/**
752
-	 * Find evaluations by name
753
-	 * @param string $name_mask search string
754
-	 * @return array evaluation objects matching the search criterium
755
-	 * @todo can be written more efficiently using a new (but very complex) sql query
756
-	 */
757
-	public function find_evaluations($name_mask,$selectcat)
758
-	{
759
-		$rootcat = Category::load($selectcat);
760
-		$evals = $rootcat[0]->get_evaluations((api_is_allowed_to_create_course() ? null : api_get_user_id()), true);
761
-		$foundevals = array();
762
-		foreach ($evals as $eval) {
763
-			if (!(api_strpos(api_strtolower($eval->get_name()), api_strtolower($name_mask)) === false)) {
764
-				$foundevals[] = $eval;
765
-			}
766
-		}
767
-		return $foundevals;
768
-	}
769
-
770
-	public function get_item_type()
771
-	{
772
-		return 'E';
773
-	}
774
-
775
-	public function get_icon_name()
776
-	{
777
-		return $this->has_results() ? 'evalnotempty' : 'evalempty';
778
-	}
779
-
780
-	/**
781
-	 * Locks an evaluation, only one who can unlock it is the platform administrator.
782
-	 * @param int locked 1 or unlocked 0
783
-	 *
784
-	 **/
785
-	function lock($locked)
786
-	{
787
-		$table_evaluation = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
788
-		$sql = "UPDATE $table_evaluation SET locked = '".intval($locked)."' WHERE id='".intval($this->id)."'";
789
-		Database::query($sql);
790
-	}
791
-
792
-	function check_lock_permissions()
793
-	{
794
-		if (api_is_platform_admin()) {
795
-			return true;
796
-		} else {
797
-			if ($this->is_locked()) {
798
-				api_not_allowed();
799
-			}
800
-		}
801
-	}
802
-
803
-	function delete_linked_data()
804
-	{
805
-
806
-	}
713
+        if (!api_is_allowed_to_edit()) {
714
+            $sql .= ' AND visible = 1';
715
+        }
716
+        if (isset($cat_id)) {
717
+            $sql .= ' AND category_id = '.intval($cat_id);
718
+        } else {
719
+            $sql .= ' AND category_id >= 0';
720
+        }
721
+
722
+        $result = Database::query($sql);
723
+        $alleval = Evaluation::create_evaluation_objects_from_sql_result($result);
724
+
725
+        return $alleval;
726
+    }
727
+
728
+    /**
729
+     * Get a list of students that do not have a result record for this evaluation
730
+     */
731
+    public function get_not_subscribed_students($first_letter_user = '')
732
+    {
733
+        $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
734
+        $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
735
+
736
+        $sql = 'SELECT user_id,lastname,firstname,username FROM '.$tbl_user
737
+            ." WHERE lastname LIKE '".Database::escape_string($first_letter_user)."%'"
738
+            .' AND status = '.STUDENT
739
+            .' AND user_id NOT IN'
740
+            .' (SELECT user_id FROM '.$tbl_grade_results
741
+            .' WHERE evaluation_id = '.intval($this->id)
742
+            .' )'
743
+            .' ORDER BY lastname';
744
+
745
+        $result = Database::query($sql);
746
+        $users = Database::store_result($result);
747
+
748
+        return $users;
749
+    }
750
+
751
+    /**
752
+     * Find evaluations by name
753
+     * @param string $name_mask search string
754
+     * @return array evaluation objects matching the search criterium
755
+     * @todo can be written more efficiently using a new (but very complex) sql query
756
+     */
757
+    public function find_evaluations($name_mask,$selectcat)
758
+    {
759
+        $rootcat = Category::load($selectcat);
760
+        $evals = $rootcat[0]->get_evaluations((api_is_allowed_to_create_course() ? null : api_get_user_id()), true);
761
+        $foundevals = array();
762
+        foreach ($evals as $eval) {
763
+            if (!(api_strpos(api_strtolower($eval->get_name()), api_strtolower($name_mask)) === false)) {
764
+                $foundevals[] = $eval;
765
+            }
766
+        }
767
+        return $foundevals;
768
+    }
769
+
770
+    public function get_item_type()
771
+    {
772
+        return 'E';
773
+    }
774
+
775
+    public function get_icon_name()
776
+    {
777
+        return $this->has_results() ? 'evalnotempty' : 'evalempty';
778
+    }
779
+
780
+    /**
781
+     * Locks an evaluation, only one who can unlock it is the platform administrator.
782
+     * @param int locked 1 or unlocked 0
783
+     *
784
+     **/
785
+    function lock($locked)
786
+    {
787
+        $table_evaluation = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
788
+        $sql = "UPDATE $table_evaluation SET locked = '".intval($locked)."' WHERE id='".intval($this->id)."'";
789
+        Database::query($sql);
790
+    }
791
+
792
+    function check_lock_permissions()
793
+    {
794
+        if (api_is_platform_admin()) {
795
+            return true;
796
+        } else {
797
+            if ($this->is_locked()) {
798
+                api_not_allowed();
799
+            }
800
+        }
801
+    }
802
+
803
+    function delete_linked_data()
804
+    {
805
+
806
+    }
807 807
 
808 808
     public function getStudentList()
809 809
     {
810 810
         return $this->studentList;
811 811
     }
812 812
 
813
-	public function setStudentList($list)
814
-	{
815
-		$this->studentList = $list;
816
-	}
813
+    public function setStudentList($list)
814
+    {
815
+        $this->studentList = $list;
816
+    }
817 817
 
818 818
 
819 819
     /**
820
-    * @return int
821
-    */
820
+     * @return int
821
+     */
822 822
     public function getCourseId()
823 823
     {
824 824
         return $this->courseId;
Please login to merge, or discard this patch.
src/Chamilo/ThemeBundle/Event/ThemeEvents.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -16,36 +16,36 @@
 block discarded – undo
16 16
     /**
17 17
      * Used to receive notification data
18 18
      */
19
-    const THEME_NOTIFICATIONS         = 'theme.notifications';
19
+    const THEME_NOTIFICATIONS = 'theme.notifications';
20 20
     /**
21 21
      * Used to receive message data
22 22
      */
23
-    const THEME_MESSAGES              = 'theme.messages';
23
+    const THEME_MESSAGES = 'theme.messages';
24 24
     /**
25 25
      * Used to receive task data
26 26
      */
27
-    const THEME_TASKS                 = 'theme.tasks';
27
+    const THEME_TASKS = 'theme.tasks';
28 28
     /**
29 29
      *
30 30
      */
31
-    const THEME_NAVBAR_USER           = 'theme.navbar_user';
31
+    const THEME_NAVBAR_USER = 'theme.navbar_user';
32 32
     /**
33 33
      * used to receive breadcrumb data
34 34
      */
35
-    const THEME_BREADCRUMB            = 'theme.breadcrumb';
35
+    const THEME_BREADCRUMB = 'theme.breadcrumb';
36 36
     /**
37 37
      * used to receive the current user for the sidebar
38 38
      */
39
-    const THEME_SIDEBAR_USER          = 'theme.sidebar_user';
39
+    const THEME_SIDEBAR_USER = 'theme.sidebar_user';
40 40
     /**
41 41
      * Used for searching
42 42
      * @unused
43 43
      */
44
-    const THEME_SIDEBAR_SEARCH        = 'theme.sidebar_search';
44
+    const THEME_SIDEBAR_SEARCH = 'theme.sidebar_search';
45 45
     /**
46 46
      * Used to receive the sidebar menu data
47 47
      */
48
-    const THEME_SIDEBAR_SETUP_MENU    = 'theme.sidebar_setup_menu';
48
+    const THEME_SIDEBAR_SETUP_MENU = 'theme.sidebar_setup_menu';
49 49
     /**
50 50
      * Used to receive the sidebar menu data
51 51
      */
Please login to merge, or discard this patch.
src/Chamilo/ThemeBundle/Controller/SidebarController.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -41,10 +41,10 @@
 block discarded – undo
41 41
         );
42 42
     }
43 43
 
44
-     /**
45
-     * User inbox, profile links
46
-     * @return Response
47
-     */
44
+        /**
45
+         * User inbox, profile links
46
+         * @return Response
47
+         */
48 48
     public function userProfileAction()
49 49
     {
50 50
         if (!$this->getDispatcher()->hasListeners(ThemeEvents::THEME_SIDEBAR_USER)) {
Please login to merge, or discard this patch.