Completed
Push — 1.11.x ( fdd33a...84601d )
by José
88:26 queued 42:33
created

CourseCategory::getLimitArray()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 11
c 1
b 0
f 0
nc 4
nop 0
dl 0
loc 15
rs 9.4285
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
/**
5
 * Class CourseCategory
6
 */
7
class CourseCategory
8
{
9
    /**
10
     * Returns the category fields from the database from an int ID
11
     * @param int $categoryId The category ID
12
     * @return array
13
     */
14
    public static function getCategoryById($categoryId)
15
    {
16
        $tbl_category = Database::get_main_table(TABLE_MAIN_CATEGORY);
17
        $categoryId = intval($categoryId);
18
        $sql = "SELECT * FROM $tbl_category WHERE id = $categoryId";
19
        $result = Database::query($sql);
20
        if (Database::num_rows($result)) {
21
            return Database::fetch_array($result, 'ASSOC');
22
        }
23
24
        return array();
25
    }
26
27
    /**
28
     * Get category details from a simple category code
29
     * @param string $category The literal category code
30
     * @return array
31
     */
32
    public static function getCategory($category)
33
    {
34
        $tbl_category = Database::get_main_table(TABLE_MAIN_CATEGORY);
35
        $category = Database::escape_string($category);
36
        $sql = "SELECT * FROM $tbl_category WHERE code ='$category'";
37
        $result = Database::query($sql);
38
        if (Database::num_rows($result)) {
39
            return Database::fetch_array($result, 'ASSOC');
40
        }
41
42
        return array();
43
    }
44
45
    /**
46
     * @param string $category
47
     *
48
     * @return array
49
     */
50
    public static function getCategories($category)
51
    {
52
        $tbl_category = Database::get_main_table(TABLE_MAIN_CATEGORY);
53
        $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
54
        $category = Database::escape_string($category);
55
        $conditions = null;
56
57
        $table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY);
58
        $conditions = " INNER JOIN $table a ON (t1.id = a.course_category_id)";
59
        $whereCondition = " AND a.access_url_id = ".api_get_current_access_url_id();
60
61
        $parentIdCondition = " AND (t1.parent_id IS NULL OR t1.parent_id = '' )";
62
        if (!empty($category)) {
63
            $parentIdCondition = " AND t1.parent_id  = '$category' ";
64
        }
65
66
        $sql = "SELECT
67
                t1.name,
68
                t1.code,
69
                t1.parent_id,
70
                t1.tree_pos,
71
                t1.children_count,
72
                COUNT(DISTINCT t3.code) AS nbr_courses
73
                FROM $tbl_category t1
74
                $conditions
75
                LEFT JOIN $tbl_category t2
76
                ON t1.code = t2.parent_id
77
                LEFT JOIN $tbl_course t3
78
                ON t3.category_code=t1.code
79
                WHERE
80
                    1 = 1
81
                    $parentIdCondition
82
                    $whereCondition
83
                GROUP BY t1.name,
84
                         t1.code,
85
                         t1.parent_id,
86
                         t1.tree_pos,
87
                         t1.children_count
88
                ORDER BY t1.tree_pos";
89
90
        $result = Database::query($sql);
91
92
        $categories = Database::store_result($result);
93
        foreach ($categories as $category) {
94
            $category['nbr_courses'] = 1;
95
        }
96
97
        return $categories;
98
    }
99
100
    /**
101
     * @param string $code
102
     * @param string $name
103
     * @param string $canHaveCourses
104
     * @param int $parent_id
105
     *
106
     * @return bool
107
     */
108
    public static function addNode($code, $name, $canHaveCourses, $parent_id)
109
    {
110
        $tbl_category = Database::get_main_table(TABLE_MAIN_CATEGORY);
111
        $code = trim($code);
112
        $name = trim($name);
113
        $parent_id = trim($parent_id);
114
115
        $code = CourseManager::generate_course_code($code);
116
        $sql = "SELECT 1 FROM $tbl_category
117
            WHERE code = '".Database::escape_string($code)."'";
118
        $result = Database::query($sql);
119
        if (Database::num_rows($result)) {
120
            return false;
121
        }
122
        $result = Database::query("SELECT MAX(tree_pos) AS maxTreePos FROM $tbl_category");
123
        $row = Database::fetch_array($result);
124
        $tree_pos = $row['maxTreePos'] + 1;
125
126
        $params = [
127
            'name' => $name,
128
            'code' => $code,
129
            'parent_id' => empty($parent_id) ? null : $parent_id,
130
            'tree_pos' => $tree_pos,
131
            'children_count' => 0,
132
            'auth_course_child' => $canHaveCourses,
133
            'auth_cat_child' => 'TRUE'
134
        ];
135
136
        $categoryId = Database::insert($tbl_category, $params);
137
138
        self::updateParentCategoryChildrenCount($parent_id, 1);
139
        self::addToUrl($categoryId);
140
141
        return $categoryId;
142
    }
143
144
    /**
145
     * Recursive function that updates the count of children in the parent
146
     * @param string $categoryId Category ID
147
     * @param    int $delta The number to add or delete (1 to add one, -1 to remove one)
148
     */
149
    public static function updateParentCategoryChildrenCount($categoryId, $delta = 1)
150
    {
151
        $tbl_category = Database::get_main_table(TABLE_MAIN_CATEGORY);
152
        $categoryId = Database::escape_string($categoryId);
153
        $delta = intval($delta);
154
        // First get to the highest level possible in the tree
155
        $result = Database::query("SELECT parent_id FROM $tbl_category WHERE code = '$categoryId'");
156
        $row = Database::fetch_array($result);
157
        if ($row !== false and $row['parent_id'] != 0) {
158
            // if a parent was found, enter there to see if he's got one more parent
159
            self::updateParentCategoryChildrenCount($row['parent_id'], $delta);
160
        }
161
        // Now we're at the top, get back down to update each child
162
        //$children_count = courseCategoryChildrenCount($categoryId);
163
        if ($delta >= 0) {
164
            $sql = "UPDATE $tbl_category SET children_count = (children_count + $delta)
165
                WHERE code = '$categoryId'";
166
        } else {
167
            $sql = "UPDATE $tbl_category SET children_count = (children_count - ".abs($delta).")
168
                WHERE code = '$categoryId'";
169
        }
170
        Database::query($sql);
171
    }
172
173
    /**
174
     * @param string $node
175
     */
176
    public static function deleteNode($node)
177
    {
178
        $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
179
        $tbl_category = Database::get_main_table(TABLE_MAIN_CATEGORY);
180
181
        $node = Database::escape_string($node);
182
183
        $result = Database::query("SELECT parent_id, tree_pos FROM $tbl_category WHERE code='$node'");
184
185
        if ($row = Database::fetch_array($result)) {
186
            if (!empty($row['parent_id'])) {
187
                Database::query(
188
                    "UPDATE $tbl_course SET category_code = '".$row['parent_id']."' WHERE category_code='$node'"
189
                );
190
                Database::query("UPDATE $tbl_category SET parent_id='".$row['parent_id']."' WHERE parent_id='$node'");
191
            } else {
192
                Database::query("UPDATE $tbl_course SET category_code='' WHERE category_code='$node'");
193
                Database::query("UPDATE $tbl_category SET parent_id=NULL WHERE parent_id='$node'");
194
            }
195
196
            Database::query("UPDATE $tbl_category SET tree_pos=tree_pos-1 WHERE tree_pos > '".$row['tree_pos']."'");
197
            Database::query("DELETE FROM $tbl_category WHERE code='$node'");
198
199
            if (!empty($row['parent_id'])) {
200
                self::updateParentCategoryChildrenCount($row['parent_id'], -1);
201
            }
202
        }
203
    }
204
205
    /**
206
     * @param string $code
207
     * @param string $name
208
     * @param string $canHaveCourses
209
     * @param string $old_code
210
     * @return bool
211
     */
212
    public static function editNode($code, $name, $canHaveCourses, $old_code)
213
    {
214
        $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
215
        $tbl_category = Database::get_main_table(TABLE_MAIN_CATEGORY);
216
217
        $code = trim(Database::escape_string($code));
218
        $name = trim(Database::escape_string($name));
219
        $old_code = Database::escape_string($old_code);
220
        $canHaveCourses = Database::escape_string($canHaveCourses);
221
222
        $code = CourseManager::generate_course_code($code);
223
        // Updating category
224
        $sql = "UPDATE $tbl_category SET name='$name', code='$code', auth_course_child = '$canHaveCourses'
225
            WHERE code = '$old_code'";
226
        Database::query($sql);
227
228
        // Updating children
229
        $sql = "UPDATE $tbl_category SET parent_id = '$code'
230
            WHERE parent_id = '$old_code'";
231
        Database::query($sql);
232
233
        // Updating course category
234
        $sql = "UPDATE $tbl_course SET category_code = '$code'
235
            WHERE category_code = '$old_code' ";
236
        Database::query($sql);
237
238
        return true;
239
    }
240
241
    /**
242
     * Move a node up on display
243
     * @param string $code
244
     * @param int $tree_pos
245
     * @param string $parent_id
246
     *
247
     * @return bool
248
     */
249
    public static function moveNodeUp($code, $tree_pos, $parent_id)
250
    {
251
        $tbl_category = Database::get_main_table(TABLE_MAIN_CATEGORY);
252
        $code = Database::escape_string($code);
253
        $tree_pos = intval($tree_pos);
254
        $parent_id = Database::escape_string($parent_id);
255
256
        $parentIdCondition = " AND (parent_id IS NULL OR parent_id = '' )";
257
        if (!empty($parent_id)) {
258
            $parentIdCondition = " AND parent_id = '$parent_id' ";
259
        }
260
261
        $sql = "SELECT code,tree_pos
262
            FROM $tbl_category
263
            WHERE
264
                tree_pos < $tree_pos
265
                $parentIdCondition
266
            ORDER BY tree_pos DESC
267
            LIMIT 0,1";
268
269
        $result = Database::query($sql);
270
        if (!$row = Database::fetch_array($result)) {
271
            $sql = "SELECT code, tree_pos
272
                FROM $tbl_category
273
                WHERE
274
                    tree_pos > $tree_pos
275
                    $parentIdCondition
276
                ORDER BY tree_pos DESC
277
                LIMIT 0,1";
278
            $result2 = Database::query($sql);
279
            if (!$row = Database::fetch_array($result2)) {
280
                return false;
281
            }
282
        }
283
284
        $sql = "UPDATE $tbl_category
285
            SET tree_pos ='".$row['tree_pos']."'
286
            WHERE code='$code'";
287
        Database::query($sql);
288
289
        $sql = "UPDATE $tbl_category
290
            SET tree_pos = '$tree_pos'
291
            WHERE code= '".$row['code']."'";
292
        Database::query($sql);
293
294
        return true;
295
    }
296
297
    /**
298
     * Counts the number of children categories a category has
299
     * @param int $categoryId The ID of the category of which we want to count the children
300
     * @param int $count The number of subcategories we counted this far
0 ignored issues
show
Bug introduced by
There is no parameter named $count. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
301
     * @return mixed The number of subcategories this category has
302
     */
303
    public static function courseCategoryChildrenCount($categoryId)
304
    {
305
        $tbl_category = Database::get_main_table(TABLE_MAIN_CATEGORY);
306
        $categoryId = intval($categoryId);
307
        $count = 0;
308
        if (empty($categoryId)) {
309
            return 0;
310
        }
311
        $sql = "SELECT id, code FROM $tbl_category WHERE parent_id = $categoryId";
312
        $result = Database::query($sql);
313
        while ($row = Database::fetch_array($result)) {
314
            $count += self::courseCategoryChildrenCount($row['id']);
315
        }
316
        $sql = "UPDATE $tbl_category SET children_count = $count WHERE id = $categoryId";
317
        Database::query($sql);
318
319
        return $count + 1;
320
    }
321
322
    /**
323
     * @param string $categoryCode
324
     *
325
     * @return array
326
     */
327 View Code Duplication
    public static function getChildren($categoryCode)
328
    {
329
        $tbl_category = Database::get_main_table(TABLE_MAIN_CATEGORY);
330
        $categoryCode = Database::escape_string($categoryCode);
331
        $result = Database::query("SELECT code, id FROM $tbl_category WHERE parent_id = '$categoryCode'");
332
        $children = array();
333
        while ($row = Database::fetch_array($result, 'ASSOC')) {
334
            $children[] = $row;
335
            $subChildren = self::getChildren($row['code']);
336
            $children = array_merge($children, $subChildren);
337
        }
338
339
        return $children;
340
    }
341
342
    /**
343
     * @param string $categoryCode
344
     *
345
     * @return array
346
     */
347
    public static function getParents($categoryCode)
348
    {
349
        if (empty($categoryCode)) {
350
            return array();
351
        }
352
353
        $tbl_category = Database::get_main_table(TABLE_MAIN_CATEGORY);
354
        $categoryCode = Database::escape_string($categoryCode);
355
        $sql = "SELECT code, parent_id FROM $tbl_category
356
            WHERE code = '$categoryCode'";
357
358
        $result = Database::query($sql);
359
        $children = array();
360
        while ($row = Database::fetch_array($result, 'ASSOC')) {
361
            $parent = self::getCategory($row['parent_id']);
362
            $children[] = $row;
363
            $subChildren = self::getParents($parent ? $parent['code'] : null);
364
            $children = array_merge($children, $subChildren);
365
        }
366
367
        return $children;
368
    }
369
370
    /**
371
     * @param string $categoryCode
372
     * @return null|string
373
     */
374
    public static function getParentsToString($categoryCode)
375
    {
376
        $parents = self::getParents($categoryCode);
377
378
        if (!empty($parents)) {
379
            $parents = array_reverse($parents);
380
            $categories = array();
381
            foreach ($parents as $category) {
382
                $categories[] = $category['code'];
383
            }
384
            $categoriesInString = implode(' > ', $categories).' > ';
385
386
            return $categoriesInString;
387
        }
388
389
        return null;
390
    }
391
392
    /**
393
     * @param string $categorySource
394
     *
395
     * @return string
396
     */
397
    public static function listCategories($categorySource)
398
    {
399
        $categorySource = isset($categorySource) ? $categorySource : null;
400
        $categories = self::getCategories($categorySource);
401
402
        if (count($categories) > 0) {
403
            $table = new HTML_Table(array('class' => 'data_table'));
404
            $column = 0;
405
            $row = 0;
406
            $headers = array(
407
                get_lang('Category'),
408
                get_lang('CategoriesNumber'),
409
                get_lang('Courses'),
410
                get_lang('Actions')
411
            );
412
            foreach ($headers as $header) {
413
                $table->setHeaderContents($row, $column, $header);
414
                $column++;
415
            }
416
            $row++;
417
            $mainUrl = api_get_path(WEB_CODE_PATH).'admin/course_category.php?category='.$categorySource;
418
419
            $editIcon = Display::return_icon('edit.png', get_lang('EditNode'), null, ICON_SIZE_SMALL);
420
            $deleteIcon = Display::return_icon('delete.png', get_lang('DeleteNode'), null, ICON_SIZE_SMALL);
421
            $moveIcon = Display::return_icon('up.png', get_lang('UpInSameLevel'), null, ICON_SIZE_SMALL);
422
423
            foreach ($categories as $category) {
424
425
                $editUrl = $mainUrl.'&id='.$category['code'].'&action=edit';
426
                $moveUrl = $mainUrl.'&id='.$category['code'].'&action=moveUp&tree_pos='.$category['tree_pos'];
427
                $deleteUrl = $mainUrl.'&id='.$category['code'].'&action=delete';
428
429
                $actions = Display::url($editIcon, $editUrl).Display::url($moveIcon, $moveUrl).Display::url(
430
                        $deleteIcon,
431
                        $deleteUrl
432
                    );
433
                $url = api_get_path(WEB_CODE_PATH).'admin/course_category.php?category='.$category['code'];
434
                $title = Display::url(
435
                    Display::return_icon(
436
                        'folder_document.gif',
437
                        get_lang('OpenNode'),
438
                        null,
439
                        ICON_SIZE_SMALL
440
                    ).' '.$category['name'],
441
                    $url
442
                );
443
                $content = array(
444
                    $title,
445
                    $category['children_count'],
446
                    $category['nbr_courses'],
447
                    $actions
448
                );
449
                $column = 0;
450
                foreach ($content as $value) {
451
                    $table->setCellContents($row, $column, $value);
452
                    $column++;
453
                }
454
                $row++;
455
            }
456
457
            return $table->toHtml();
458
        } else {
459
            return Display::return_message(get_lang("NoCategories"), 'warning');
460
        }
461
    }
462
463
    /**
464
     * @return array
465
     */
466
    public static function getCategoriesToDisplayInHomePage()
467
    {
468
        $tbl_category = Database::get_main_table(TABLE_MAIN_CATEGORY);
469
        $sql = "SELECT name FROM $tbl_category
470
            WHERE parent_id IS NULL
471
            ORDER BY tree_pos";
472
473
        return Database::store_result(Database::query($sql));
0 ignored issues
show
Bug introduced by
It seems like \Database::query($sql) can be null; however, store_result() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
474
    }
475
476
    /**
477
     * @param int $id
478
     *
479
     * @return bool
480
     */
481
    public static function addToUrl($id)
482
    {
483
        UrlManager::addCourseCategoryListToUrl(array($id), array(api_get_current_access_url_id()));
484
    }
485
486
    /**
487
     * @param string $categoryCode
488
     *
489
     * @return array
490
     */
491
    public static function getCategoriesCanBeAddedInCourse($categoryCode)
492
    {
493
        $table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY);
494
        $conditions = " INNER JOIN $table a ON (c.id = a.course_category_id)";
495
        $whereCondition = " AND a.access_url_id = ".api_get_current_access_url_id();
496
497
        $tbl_category = Database::get_main_table(TABLE_MAIN_CATEGORY);
498
        $sql = "SELECT code, name
499
            FROM $tbl_category c
500
            $conditions
501
            WHERE (auth_course_child = 'TRUE' OR code = '".Database::escape_string($categoryCode)."')
502
                   $whereCondition
503
            ORDER BY tree_pos";
504
        $res = Database::query($sql);
505
506
        $categories[''] = '-';
507
        while ($cat = Database::fetch_array($res)) {
508
            $categories[$cat['code']] = '('.$cat['code'].') '.$cat['name'];
509
            ksort($categories);
510
        }
511
512
        return $categories;
513
    }
514
515
    /**
516
     * @return array
517
     */
518
    public static function browseCourseCategories()
519
    {
520
        $tbl_category = Database::get_main_table(TABLE_MAIN_CATEGORY);
521
        $conditions = null;
522
523
        $table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY);
524
        $conditions = " INNER JOIN $table a ON (c.id = a.course_category_id)";
525
        $whereCondition = " WHERE a.access_url_id = ".api_get_current_access_url_id();
526
527
        $sql = "SELECT c.* FROM $tbl_category c
528
            $conditions
529
            $whereCondition
530
            ORDER BY tree_pos ASC";
531
        $result = Database::query($sql);
532
        $url_access_id = 1;
533
        if (api_is_multiple_url_enabled()) {
534
            $url_access_id = api_get_current_access_url_id();
535
        }
536
        $countCourses = CourseManager::countAvailableCourses($url_access_id);
537
538
        $categories = array();
539
        $categories[0][0] = array(
540
            'id' => 0,
541
            'name' => get_lang('DisplayAll'),
542
            'code' => 'ALL',
543
            'parent_id' => null,
544
            'tree_pos' => 0,
545
            'count_courses' => $countCourses
546
547
        );
548
        while ($row = Database::fetch_array($result)) {
549
            $count_courses = self::countCoursesInCategory($row['code']);
550
            $row['count_courses'] = $count_courses;
551
            if (!isset($row['parent_id'])) {
552
                $categories[0][$row['tree_pos']] = $row;
553
            } else {
554
                $categories[$row['parent_id']][$row['tree_pos']] = $row;
555
            }
556
        }
557
558
        $count_courses = self::countCoursesInCategory();
559
560
        $categories[0][count($categories[0]) + 1] = array(
561
            'id' => 0,
562
            'name' => get_lang('None'),
563
            'code' => 'NONE',
564
            'parent_id' => null,
565
            'tree_pos' => $row['tree_pos'] + 1,
566
            'children_count' => 0,
567
            'auth_course_child' => true,
568
            'auth_cat_child' => true,
569
            'count_courses' => $count_courses
570
        );
571
572
        return $categories;
573
    }
574
575
    /**
576
     * @param string $category_code
577
     * @param string $searchTerm
578
     * @return int
579
     */
580
    public static function countCoursesInCategory($category_code = "", $searchTerm = '')
581
    {
582
        $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
583
        $categoryCode = Database::escape_string($category_code);
584
        $searchTerm = Database::escape_string($searchTerm);
585
        $categoryFilter = '';
586
        $searchFilter = '';
587
588
        $specialCourseList = CourseManager::get_special_course_list();
589
590
        $without_special_courses = '';
591
        if (!empty($specialCourseList)) {
592
            $without_special_courses = ' AND course.code NOT IN ("'.implode('","', $specialCourseList).'")';
593
        }
594
595
        $visibilityCondition = null;
596
        $hidePrivate = api_get_setting('course_catalog_hide_private');
597 View Code Duplication
        if ($hidePrivate === 'true') {
598
            $courseInfo = api_get_course_info();
599
            $courseVisibility = $courseInfo['visibility'];
600
            $visibilityCondition = ' AND course.visibility <> 1';
601
        }
602
603
        if ($categoryCode == 'ALL') {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
604
            // Nothing to do
605
        } elseif ($categoryCode == 'NONE') {
606
            $categoryFilter = ' AND category_code = "" ';
607
        } else {
608
            $categoryFilter = ' AND category_code = "'.$categoryCode.'" ';
609
        }
610
611
        if (!empty($searchTerm)) {
612
            $searchFilter = ' AND (code LIKE "%'.$searchTerm.'%"
613
            OR title LIKE "%'.$searchTerm.'%"
614
            OR tutor_name LIKE "%'.$searchTerm.'%") ';
615
        }
616
617
        $sql = "SELECT * FROM $tbl_course
618
            WHERE
619
                visibility != '0' AND
620
                visibility != '4'
621
                $categoryFilter
622
                $searchFilter
623
                $without_special_courses
624
                $visibilityCondition
625
            ";
626
        // Showing only the courses of the current portal access_url_id.
627
628 View Code Duplication
        if (api_is_multiple_url_enabled()) {
629
            $url_access_id = api_get_current_access_url_id();
630
            if ($url_access_id != -1) {
631
                $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
632
                $sql = "SELECT * FROM $tbl_course as course
633
                    INNER JOIN $tbl_url_rel_course as url_rel_course
634
                    ON (url_rel_course.c_id = course.id)
635
                    WHERE
636
                        access_url_id = $url_access_id AND
637
                        course.visibility != '0' AND
638
                        course.visibility != '4' AND
639
                        category_code = '$category_code'
640
                        $searchTerm
641
                        $without_special_courses
642
                        $visibilityCondition
643
                    ";
644
            }
645
        }
646
647
        return Database::num_rows(Database::query($sql));
0 ignored issues
show
Bug introduced by
It seems like \Database::query($sql) can be null; however, num_rows() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
648
    }
649
650
    /**
651
     * @param string $category_code
652
     * @param int $random_value
653
     * @param array $limit will be used if $random_value is not set.
654
     * This array should contains 'start' and 'length' keys
655
     * @return array
656
     */
657
    public static function browseCoursesInCategory($category_code, $random_value = null, $limit = array())
658
    {
659
        $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
660
661
        $specialCourseList = CourseManager::get_special_course_list();
662
663
        $without_special_courses = '';
664
        if (!empty($specialCourseList)) {
665
            $without_special_courses = ' AND course.code NOT IN ("'.implode('","', $specialCourseList).'")';
666
        }
667
        $visibilityCondition = null;
668
        $hidePrivate = api_get_setting('course_catalog_hide_private');
669 View Code Duplication
        if ($hidePrivate === 'true') {
670
            $courseInfo = api_get_course_info();
671
            $courseVisibility = $courseInfo['visibility'];
672
            $visibilityCondition = ' AND course.visibility <> 1';
673
        }
674
        if (!empty($random_value)) {
675
            $random_value = intval($random_value);
676
677
            $sql = "SELECT COUNT(*) FROM $tbl_course";
678
            $result = Database::query($sql);
679
            list($num_records) = Database::fetch_row($result);
0 ignored issues
show
Bug introduced by
It seems like $result can be null; however, fetch_row() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
680
681
            if (api_is_multiple_url_enabled()) {
682
683
                $url_access_id = api_get_current_access_url_id();
684
                $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
685
686
                $sql = "SELECT COUNT(*) FROM $tbl_course course
687
                    INNER JOIN $tbl_url_rel_course as url_rel_course
688
                    ON (url_rel_course.c_id = course.id)
689
                    WHERE access_url_id = $url_access_id ";
690
                $result = Database::query($sql);
691
                list($num_records) = Database::fetch_row($result);
0 ignored issues
show
Bug introduced by
It seems like $result can be null; however, fetch_row() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
692
693
                $sql = "SELECT course.id FROM $tbl_course course
694
                    INNER JOIN $tbl_url_rel_course as url_rel_course
695
                    ON (url_rel_course.c_id = course.id)
696
                    WHERE
697
                        access_url_id = $url_access_id AND
698
                        RAND()*$num_records< $random_value
699
                        $without_special_courses $visibilityCondition
700
                    ORDER BY RAND()
701
                    LIMIT 0, $random_value";
702
            } else {
703
                $sql = "SELECT id FROM $tbl_course course
704
                    WHERE RAND()*$num_records< $random_value $without_special_courses $visibilityCondition
705
                    ORDER BY RAND()
706
                    LIMIT 0, $random_value";
707
            }
708
709
            $result = Database::query($sql);
710
            $id_in = null;
711
            while (list($id) = Database::fetch_row($result)) {
0 ignored issues
show
Bug introduced by
It seems like $result can be null; however, fetch_row() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
712
                if ($id_in) {
713
                    $id_in .= ",$id";
714
                } else {
715
                    $id_in = "$id";
716
                }
717
            }
718
            if ($id_in === null) {
719
                return array();
720
            }
721
            $sql = "SELECT * FROM $tbl_course WHERE id IN($id_in)";
722
        } else {
723
            $limitFilter = self::getLimitFilterFromArray($limit);
724
            $category_code = Database::escape_string($category_code);
725
            if (empty($category_code) || $category_code == "ALL") {
726
                $sql = "SELECT * FROM $tbl_course
727
                    WHERE
728
                        1=1
729
                        $without_special_courses
730
                        $visibilityCondition
731
                    ORDER BY title $limitFilter ";
732
            } else {
733
                if ($category_code == 'NONE') {
734
                    $category_code = '';
735
                }
736
                $sql = "SELECT * FROM $tbl_course
737
                    WHERE
738
                        category_code='$category_code'
739
                        $without_special_courses
740
                        $visibilityCondition
741
                    ORDER BY title $limitFilter ";
742
            }
743
744
            //showing only the courses of the current Chamilo access_url_id
745 View Code Duplication
            if (api_is_multiple_url_enabled()) {
746
                $url_access_id = api_get_current_access_url_id();
747
                $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
748
                if ($category_code != "ALL") {
749
                    $sql = "SELECT * FROM $tbl_course as course
750
                        INNER JOIN $tbl_url_rel_course as url_rel_course
751
                        ON (url_rel_course.c_id = course.id)
752
                        WHERE
753
                            access_url_id = $url_access_id AND
754
                            category_code='$category_code'
755
                            $without_special_courses
756
                            $visibilityCondition
757
                        ORDER BY title $limitFilter";
758
                } else {
759
                    $sql = "SELECT * FROM $tbl_course as course
760
                        INNER JOIN $tbl_url_rel_course as url_rel_course
761
                        ON (url_rel_course.c_id = course.id)
762
                        WHERE
763
                            access_url_id = $url_access_id
764
                            $without_special_courses
765
                            $visibilityCondition
766
                        ORDER BY title $limitFilter";
767
                }
768
            }
769
        }
770
771
        $result = Database::query($sql);
772
        $courses = array();
773
        while ($row = Database::fetch_array($result)) {
774
            $row['registration_code'] = !empty($row['registration_code']);
775
            $count_users = CourseManager::get_users_count_in_course($row['code']);
776
            $count_connections_last_month = Tracking::get_course_connections_count(
777
                $row['id'],
778
                0,
779
                api_get_utc_datetime(time() - (30 * 86400))
780
            );
781
782
            if ($row['tutor_name'] == '0') {
783
                $row['tutor_name'] = get_lang('NoManager');
784
            }
785
            $point_info = CourseManager::get_course_ranking($row['id'], 0);
786
            $courses[] = array(
787
                'real_id' => $row['id'],
788
                'point_info' => $point_info,
789
                'code' => $row['code'],
790
                'directory' => $row['directory'],
791
                'visual_code' => $row['visual_code'],
792
                'title' => $row['title'],
793
                'tutor' => $row['tutor_name'],
794
                'subscribe' => $row['subscribe'],
795
                'unsubscribe' => $row['unsubscribe'],
796
                'registration_code' => $row['registration_code'],
797
                'creation_date' => $row['creation_date'],
798
                'visibility' => $row['visibility'],
799
                'category' => $row['category_code'],
800
                'count_users' => $count_users,
801
                'count_connections' => $count_connections_last_month
802
            );
803
        }
804
        return $courses;
805
    }
806
807
    /**
808
     * create recursively all categories as option of the select passed in parameter.
809
     *
810
     * @param HTML_QuickForm_Element $element
811
     * @param string $defaultCode the option value to select by default (used mainly for edition of courses)
812
     * @param string $parentCode the parent category of the categories added (default=null for root category)
813
     * @param string $padding the indent param (you shouldn't indicate something here)
814
     */
815
    public static function setCategoriesInForm($element, $defaultCode = null, $parentCode = null, $padding = null)
816
    {
817
        $tbl_category = Database::get_main_table(TABLE_MAIN_CATEGORY);
818
819
        $table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY);
820
        $conditions = " INNER JOIN $table a ON (c.id = a.course_category_id)";
821
        $whereCondition = " AND a.access_url_id = ".api_get_current_access_url_id();
822
823
        $sql = "SELECT code, name, auth_course_child, auth_cat_child
824
            FROM ".$tbl_category." c
825
            $conditions
826
            WHERE parent_id ".(empty($parentCode) ? "IS NULL" : "='".Database::escape_string($parentCode)."'")."
827
            $whereCondition
828
            ORDER BY name,  code";
829
        $res = Database::query($sql);
830
831
        while ($cat = Database::fetch_array($res, 'ASSOC')) {
832
            $params = $cat['auth_course_child'] == 'TRUE' ? '' : 'disabled';
833
            $params .= ($cat['code'] == $defaultCode) ? ' selected' : '';
834
            $option = $padding.' '.$cat['name'].' ('.$cat['code'].')';
835
836
            $element->addOption($option, $cat['code'], $params);
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class HTML_QuickForm_element as the method addOption() does only exist in the following sub-classes of HTML_QuickForm_element: HTML_QuickForm_advmultiselect, HTML_QuickForm_hiddenselect, HTML_QuickForm_select, SelectAjax, SelectLanguage, SelectTheme. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
837
            if ($cat['auth_cat_child'] == 'TRUE') {
838
                self::setCategoriesInForm($element, $defaultCode, $cat['code'], $padding.' - ');
839
            }
840
        }
841
    }
842
843
    /**
844
     * @param array $list
845
     * @return array
846
     */
847 View Code Duplication
    public static function getCourseCategoryNotInList($list)
848
    {
849
        $table = Database::get_main_table(TABLE_MAIN_CATEGORY);
850
        if (empty($list)) {
851
            return array();
852
        }
853
854
        $list = array_map('intval', $list);
855
        $listToString = implode("','", $list);
856
857
        $sql = "SELECT * FROM $table
858
            WHERE id NOT IN ('$listToString') AND (parent_id IS NULL) ";
859
        $result = Database::query($sql);
860
861
        return Database::store_result($result, 'ASSOC');
862
    }
863
864
    /**
865
     * @param string $keyword
866
     * @return array|null
867
     */
868 View Code Duplication
    public static function searchCategoryByKeyword($keyword)
869
    {
870
        if (empty($keyword)) {
871
            return null;
872
        }
873
874
        $tableCategory = Database::get_main_table(TABLE_MAIN_CATEGORY);
875
876
        $table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY);
877
        $conditions = " INNER JOIN $table a ON (c.id = a.course_category_id)";
878
        $whereCondition = " AND a.access_url_id = ".api_get_current_access_url_id();
879
880
        $keyword = Database::escape_string($keyword);
881
882
        $sql = "SELECT c.*, c.name as text
883
            FROM $tableCategory c $conditions
884
            WHERE
885
                (
886
                    c.code LIKE '%$keyword%' OR name LIKE '%$keyword%'
887
                ) AND
888
                auth_course_child = 'TRUE'
889
                $whereCondition ";
890
        $result = Database::query($sql);
891
892
        return Database::store_result($result, 'ASSOC');
893
    }
894
895
    /**
896
     * @param array $list
897
     * @return array
898
     */
899
    public static function searchCategoryById($list)
900
    {
901
        if (empty($list)) {
902
            return array();
903
        } else {
904
            $list = array_map('intval', $list);
905
            $list = implode("','", $list);
906
        }
907
908
        $tableCategory = Database::get_main_table(TABLE_MAIN_CATEGORY);
909
910
        $table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY);
911
        $conditions = " INNER JOIN $table a ON (c.id = a.course_category_id)";
912
        $whereCondition = " AND a.access_url_id = ".api_get_current_access_url_id();
913
914
        $sql = "SELECT c.*, c.name as text FROM $tableCategory c $conditions
915
            WHERE c.id IN $list $whereCondition";
916
        $result = Database::query($sql);
917
918
        return Database::store_result($result, 'ASSOC');
919
    }
920
921
    /**
922
     * @return array
923
     */
924
    public static function getLimitArray()
925
    {
926
        $pageCurrent = isset($_REQUEST['pageCurrent']) ?
927
            intval($_GET['pageCurrent']) :
928
            1;
929
        $pageLength = isset($_REQUEST['pageLength']) ?
930
            intval($_GET['pageLength']) :
931
            10;
932
933
        return array(
934
            'start' => ($pageCurrent - 1) * $pageLength,
935
            'current' => $pageCurrent,
936
            'length' => $pageLength,
937
        );
938
    }
939
940
    /**
941
     * Return LIMIT to filter SQL query
942
     * @param array $limit
943
     * @return string
944
     */
945
    public static function getLimitFilterFromArray($limit)
946
    {
947
        $limitFilter = '';
948
        if (!empty($limit) && is_array($limit)) {
949
            $limitStart = isset($limit['start']) ? $limit['start'] : 0;
950
            $limitLength = isset($limit['length']) ? $limit['length'] : 10;
951
            $limitFilter = 'LIMIT '.$limitStart.', '.$limitLength;
952
        }
953
954
        return $limitFilter;
955
    }
956
957
    /**
958
     * Get Pagination HTML div
959
     * @param $pageCurrent
960
     * @param $pageLength
961
     * @param $pageTotal
962
     * @return string
963
     */
964
    public static function getCatalogPagination($pageCurrent, $pageLength, $pageTotal)
965
    {
966
        // Start empty html
967
        $pageDiv = '';
968
        $html = '';
969
        $pageBottom = max(1, $pageCurrent - 3);
970
        $pageTop = min($pageTotal, $pageCurrent + 3);
971
972
        if ($pageBottom > 1) {
973
            $pageDiv .= self::getPageNumberItem(1, $pageLength);
974
            if ($pageBottom > 2) {
975
                $pageDiv .= self::getPageNumberItem($pageBottom - 1, $pageLength, null, '...');
976
            }
977
        }
978
979
        // For each page add its page button to html
980
        for (
981
            $i = $pageBottom;
982
            $i <= $pageTop;
983
            $i++
984
        ) {
985
            if ($i === $pageCurrent) {
986
                $pageItemAttributes = array('class' => 'active');
987
            } else {
988
                $pageItemAttributes = array();
989
            }
990
            $pageDiv .= self::getPageNumberItem($i, $pageLength, $pageItemAttributes);
991
992
        }
993
        // Check if current page is the last page
994
995
        if ($pageTop < $pageTotal) {
996
            if ($pageTop < ($pageTotal - 1)) {
997
                $pageDiv .= self::getPageNumberItem($pageTop + 1, $pageLength, null, '...');
998
            }
999
            $pageDiv .= self::getPageNumberItem($pageTotal, $pageLength);
1000
        }
1001
1002
        // Complete pagination html
1003
        $pageDiv = Display::tag('ul', $pageDiv, array('class' => 'pagination'));
1004
        $html .= '<nav>'.$pageDiv.'</nav>';
1005
1006
        return $html;
1007
    }
1008
1009
    /**
1010
     * Return URL to course catalog
1011
     * @param int $pageCurrent
1012
     * @param int $pageLength
1013
     * @param string $categoryCode
1014
     * @param int $hiddenLinks
1015
     * @param string $action
1016
     * @return string
1017
     */
1018
    public static function getCourseCategoryUrl(
1019
        $pageCurrent,
1020
        $pageLength,
1021
        $categoryCode = null,
1022
        $hiddenLinks = null,
1023
        $action = null
1024
    ) {
1025
        $requestAction = isset($_REQUEST['action']) ? Security::remove_XSS($_REQUEST['action']) : null;
1026
        $action = isset($action) ? Security::remove_XSS($action) : $requestAction;
1027
        $searchTerm = isset($_REQUEST['search_term']) ? Security::remove_XSS($_REQUEST['search_term']) : null;
1028
1029
        if ($action === 'subscribe_user_with_password') {
1030
            $action = 'subscribe';
1031
        }
1032
1033
        $categoryCodeRequest = isset($_REQUEST['category_code']) ? Security::remove_XSS(
1034
            $_REQUEST['category_code']
1035
        ) : null;
1036
        $categoryCode = isset($categoryCode) ? Security::remove_XSS($categoryCode) : $categoryCodeRequest;
1037
1038
        $hiddenLinksRequest = isset($_REQUEST['hidden_links']) ? Security::remove_XSS($_REQUEST['hidden_links']) : null;
1039
        $hiddenLinks = isset($hiddenLinks) ? Security::remove_XSS($hiddenLinksRequest) : $categoryCodeRequest;
1040
1041
        // Start URL with params
1042
        $pageUrl = api_get_self().
1043
            '?action='.$action.
1044
            '&category_code='.$categoryCode.
1045
            '&hidden_links='.$hiddenLinks.
1046
            '&pageCurrent='.$pageCurrent.
1047
            '&pageLength='.$pageLength;
1048
1049
        switch ($action) {
1050
            case 'subscribe':
1051
                // for search
1052
                $pageUrl .=
1053
                    '&search_term='.$searchTerm.
1054
                    '&search_course=1'.
1055
                    '&sec_token='.$_SESSION['sec_token'];
1056
                break;
1057
            case 'display_courses':
1058
                // No break
1059
            default:
1060
                break;
1061
        }
1062
1063
        return $pageUrl;
1064
    }
1065
1066
    /**
1067
     * Get li HTML of page number
1068
     * @param $pageNumber
1069
     * @param $pageLength
1070
     * @param array $liAttributes
1071
     * @param string $content
1072
     * @return string
1073
     */
1074
    public static function getPageNumberItem($pageNumber, $pageLength, $liAttributes = array(), $content = '')
1075
    {
1076
        // Get page URL
1077
        $url = self::getCourseCategoryUrl(
1078
            $pageNumber,
1079
            $pageLength
1080
        );
1081
1082
        // If is current page ('active' class) clear URL
1083
        if (isset($liAttributes) && is_array($liAttributes) && isset($liAttributes['class'])) {
1084
            if (strpos('active', $liAttributes['class']) !== false) {
1085
                $url = '';
1086
            }
1087
        }
1088
1089
        $content = !empty($content) ? $content : $pageNumber;
1090
1091
        return Display::tag(
1092
            'li',
1093
            Display::url(
1094
                $content,
1095
                $url
1096
            ),
1097
            $liAttributes
0 ignored issues
show
Bug introduced by
It seems like $liAttributes can also be of type null; however, Display::tag() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
1098
        );
1099
    }
1100
1101
    /**
1102
     * Return the name tool by action
1103
     * @param string $action
1104
     * @return string
1105
     */
1106
    public static function getCourseCatalogNameTools($action)
1107
    {
1108
        $nameTools = get_lang('SortMyCourses');
1109
        if (empty($action)) {
1110
            return $nameTools; //should never happen
1111
        }
1112
1113
        switch ($action) {
1114
            case 'createcoursecategory':
1115
                $nameTools = get_lang('CreateCourseCategory');
1116
                break;
1117
            case 'subscribe':
1118
                $nameTools = get_lang('CourseManagement');
1119
                break;
1120
            case 'subscribe_user_with_password':
1121
                $nameTools = get_lang('CourseManagement');
1122
                break;
1123
            case 'display_random_courses':
1124
                // No break
1125
            case 'display_courses':
1126
                $nameTools = get_lang('CourseManagement');
1127
                break;
1128
            case 'display_sessions':
1129
                $nameTools = get_lang('Sessions');
1130
                break;
1131
            default:
1132
                // Nothing to do
1133
                break;
1134
        }
1135
1136
        return $nameTools;
1137
    }
1138
}
1139