Completed
Push — master ( cc4351...a3ace3 )
by Julito
08:52
created

CourseHome::getDisableIcon()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
use Chamilo\CourseBundle\Entity\CLpCategory;
5
use Chamilo\CourseBundle\Entity\CTool;
6
7
/**
8
 * Class CourseHome.
9
 */
10
class CourseHome
11
{
12
    /**
13
     * Gets the tools of a certain category. Returns an array expected
14
     * by show_tools_category().
15
     *
16
     * @param string $course_tool_category contains the category of tools to
17
     *                                     display: "toolauthoring", "toolinteraction", "tooladmin", "tooladminplatform", "toolplugin"
18
     * @param int    $courseId             Optional
19
     * @param int    $sessionId            Optional
20
     *
21
     * @return array
22
     */
23
    public static function get_tools_category(
24
        $course_tool_category,
25
        $courseId = 0,
26
        $sessionId = 0
27
    ) {
28
        $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST);
29
        $is_platform_admin = api_is_platform_admin();
30
        $all_tools_list = [];
31
32
        // Condition for the session
33
        $sessionId = $sessionId ?: api_get_session_id();
34
        $course_id = $courseId ?: api_get_course_int_id();
35
        $courseInfo = api_get_course_info_by_id($course_id);
36
        $userId = api_get_user_id();
37
        $user = api_get_user_entity($userId);
38
        $condition_session = api_get_session_condition(
39
            $sessionId,
40
            true,
41
            true,
42
            't.session_id'
43
        );
44
45
        $lpTable = Database::get_course_table(TABLE_LP_MAIN);
46
        $tblLpCategory = Database::get_course_table(TABLE_LP_CATEGORY);
47
        $studentView = api_is_student_view_active();
48
49
        $orderBy = ' ORDER BY id ';
50
        switch ($course_tool_category) {
51
            case TOOL_STUDENT_VIEW:
52
                $conditions = ' WHERE visibility = 1 AND 
53
                                (category = "authoring" OR category = "interaction" OR category = "plugin") AND 
54
                                t.name <> "notebookteacher" ';
55
                if ((api_is_coach() || api_is_course_tutor() || api_is_platform_admin()) && !$studentView) {
56
                    $conditions = ' WHERE (
57
                        visibility = 1 AND (
58
                            category = "authoring" OR 
59
                            category = "interaction" OR 
60
                            category = "plugin"
61
                        ) OR (t.name = "'.TOOL_TRACKING.'") 
62
                    )';
63
                }
64
65
                // Add order if there are LPs
66
                $sql = "SELECT t.* FROM $course_tool_table t
67
                        LEFT JOIN $lpTable l 
68
                        ON (t.c_id = l.c_id AND link LIKE concat('%/lp_controller.php?action=view&lp_id=', l.id, '&%'))
69
                        LEFT JOIN $tblLpCategory lc
70
                        ON (t.c_id = lc.c_id AND l.category_id = lc.iid)
71
                        $conditions AND
72
                        t.c_id = $course_id $condition_session 
73
                        ORDER BY
74
                            CASE WHEN l.category_id IS NULL THEN 0 ELSE 1 END,
75
                            CASE WHEN l.display_order IS NULL THEN 0 ELSE 1 END,
76
                            lc.position,
77
                            l.display_order,
78
                            t.id";
79
                $orderBy = '';
80
                break;
81
            case TOOL_AUTHORING:
82
                $sql = "SELECT t.* FROM $course_tool_table t
83
                        LEFT JOIN $lpTable l
84
                        ON (t.c_id = l.c_id AND link LIKE concat('%/lp_controller.php?action=view&lp_id=', l.id, '&%'))
85
                        LEFT JOIN $tblLpCategory lc
86
                        ON (t.c_id = lc.c_id AND l.category_id = lc.iid)
87
                        WHERE
88
                            category = 'authoring' AND t.c_id = $course_id $condition_session
89
                        ORDER BY
90
                            CASE WHEN l.category_id IS NULL THEN 0 ELSE 1 END,
91
                            CASE WHEN l.display_order IS NULL THEN 0 ELSE 1 END,
92
                            lc.position,
93
                            l.display_order,
94
                            t.id";
95
                $orderBy = '';
96
                break;
97
            case TOOL_INTERACTION:
98
                $sql = "SELECT * FROM $course_tool_table t
99
                        WHERE category = 'interaction' AND c_id = $course_id $condition_session
100
                        ";
101
                break;
102
            case TOOL_ADMIN_VISIBLE:
103
                $sql = "SELECT * FROM $course_tool_table t
104
                        WHERE category = 'admin' AND visibility ='1' AND c_id = $course_id $condition_session
105
                        ";
106
                break;
107
            case TOOL_ADMIN_PLATFORM:
108
                $sql = "SELECT * FROM $course_tool_table t
109
                        WHERE category = 'admin' AND c_id = $course_id $condition_session
110
                        ";
111
                break;
112
            case TOOL_DRH:
113
                $sql = "SELECT * FROM $course_tool_table t
114
                        WHERE t.name IN ('tracking') AND c_id = $course_id $condition_session
115
                        ";
116
                break;
117
            case TOOL_COURSE_PLUGIN:
118
                //Other queries recover id, name, link, image, visibility, admin, address, added_tool, target, category and session_id
119
                // but plugins are not present in the tool table, only globally and inside the course_settings table once configured
120
                $sql = "SELECT * FROM $course_tool_table t
121
                        WHERE category = 'plugin' AND name <> 'courseblock' AND c_id = $course_id $condition_session
122
                        ";
123
                break;
124
        }
125
        $sql .= $orderBy;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $sql does not seem to be defined for all execution paths leading up to this point.
Loading history...
126
        $result = Database::query($sql);
127
        $tools = [];
128
        while ($row = Database::fetch_assoc($result)) {
129
            $tools[] = $row;
130
        }
131
132
        // Get the list of hidden tools - this might imply performance slowdowns
133
        // if the course homepage is loaded many times, so the list of hidden
134
        // tools might benefit from a shared memory storage later on
135
        $list = api_get_settings('Tools', 'list', api_get_current_access_url_id());
136
        $hide_list = [];
137
        $check = false;
138
        foreach ($list as $line) {
139
            // Admin can see all tools even if the course_hide_tools configuration is set
140
            if ($is_platform_admin) {
141
                continue;
142
            }
143
            if ($line['variable'] == 'course_hide_tools' && $line['selected_value'] == 'true') {
144
                $hide_list[] = $line['subkey'];
145
                $check = true;
146
            }
147
        }
148
149
        $allowEditionInSession = api_get_configuration_value('allow_edit_tool_visibility_in_session');
150
        // If exists same tool (by name) from session in base course then avoid it. Allow them pass in other cases
151
        $tools = array_filter($tools, function (array $toolToFilter) use ($sessionId, $tools) {
0 ignored issues
show
Unused Code introduced by
The import $sessionId is not used and could be removed.

This check looks for imports that have been defined, but are not used in the scope.

Loading history...
152
            if (!empty($toolToFilter['session_id'])) {
153
                foreach ($tools as $originalTool) {
154
                    if ($toolToFilter['name'] == $originalTool['name'] && empty($originalTool['session_id'])) {
155
                        return false;
156
                    }
157
                }
158
            }
159
160
            return true;
161
        });
162
163
        foreach ($tools as $temp_row) {
164
            $add = false;
165
            if ($check) {
166
                if (!in_array($temp_row['name'], $hide_list)) {
167
                    $add = true;
168
                }
169
            } else {
170
                $add = true;
171
            }
172
173
            if ($allowEditionInSession && !empty($sessionId)) {
174
                // Checking if exist row in session
175
                $criteria = [
176
                    'course' => $course_id,
177
                    'name' => $temp_row['name'],
178
                    'sessionId' => $sessionId,
179
                ];
180
                /** @var CTool $toolObj */
181
                $toolObj = Database::getManager()->getRepository('ChamiloCourseBundle:CTool')->findOneBy($criteria);
182
                if ($toolObj) {
183
                    if (api_is_allowed_to_edit() == false && $toolObj->getVisibility() == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
184
                        continue;
185
                    }
186
                }
187
            }
188
189
            switch ($temp_row['image']) {
190
                case 'scormbuilder.gif':
191
                    $lpId = self::getPublishedLpIdFromLink($temp_row['link']);
192
                    $lp = new learnpath(
193
                        api_get_course_id(),
194
                        $lpId,
195
                        $userId
196
                    );
197
                    $path = $lp->get_preview_image_path(ICON_SIZE_BIG);
198
199
                    if (api_is_allowed_to_edit(null, true)) {
200
                        $add = true;
201
                    } else {
202
                        $add = learnpath::is_lp_visible_for_student(
203
                            $lpId,
204
                            $userId,
205
                            $courseInfo,
206
                            $sessionId
207
                        );
208
                    }
209
                    if ($path) {
210
                        $temp_row['custom_image'] = $path;
211
                    }
212
                    break;
213
                case 'lp_category.gif':
214
                    $lpCategory = self::getPublishedLpCategoryFromLink(
215
                        $temp_row['link']
216
                    );
217
                    $add = learnpath::categoryIsVisibleForStudent(
218
                        $lpCategory,
219
                        $user
220
                    );
221
                    break;
222
            }
223
224
            if ($add) {
225
                $all_tools_list[] = $temp_row;
226
            }
227
        }
228
229
        // Grabbing all the links that have the property on_homepage set to 1
230
        $course_link_table = Database::get_course_table(TABLE_LINK);
231
        $course_item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
232
        $condition_session = api_get_session_condition(
233
            $sessionId,
234
            true,
235
            true,
236
            'tip.session_id'
237
        );
238
239
        switch ($course_tool_category) {
240
            case TOOL_AUTHORING:
241
                $sql_links = "SELECT tl.*, tip.visibility
242
                    FROM $course_link_table tl
243
                    LEFT JOIN $course_item_property_table tip
244
                    ON tip.tool='link' AND tip.ref=tl.id
245
                    WHERE
246
                        tl.c_id = $course_id AND
247
                        tip.c_id = $course_id AND
248
                        tl.on_homepage='1' $condition_session";
249
                break;
250
            case TOOL_INTERACTION:
251
                $sql_links = null;
252
                /*
253
                  $sql_links = "SELECT tl.*, tip.visibility
254
                  FROM $course_link_table tl
255
                  LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id
256
                  WHERE tl.on_homepage='1' ";
257
                 */
258
                break;
259
            case TOOL_STUDENT_VIEW:
260
                $sql_links = "SELECT tl.*, tip.visibility
261
                    FROM $course_link_table tl
262
                    LEFT JOIN $course_item_property_table tip
263
                    ON tip.tool='link' AND tip.ref=tl.id
264
                    WHERE
265
                        tl.c_id 		= $course_id AND
266
                        tip.c_id 		= $course_id AND
267
                        tl.on_homepage	='1' $condition_session";
268
                break;
269
            case TOOL_ADMIN:
270
                $sql_links = "SELECT tl.*, tip.visibility
271
                    FROM $course_link_table tl
272
                    LEFT JOIN $course_item_property_table tip
273
                    ON tip.tool='link' AND tip.ref=tl.id
274
                    WHERE
275
                        tl.c_id = $course_id AND
276
                        tip.c_id = $course_id AND
277
                        tl.on_homepage='1' $condition_session";
278
                break;
279
            default:
280
                $sql_links = null;
281
                break;
282
        }
283
284
        // Edited by Kevin Van Den Haute ([email protected]) for integrating Smartblogs
285
        if ($sql_links != null) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $sql_links of type null|string against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
286
            $result_links = Database::query($sql_links);
287
            if (Database::num_rows($result_links) > 0) {
288
                while ($links_row = Database::fetch_array($result_links, 'ASSOC')) {
289
                    $properties = [];
290
                    $properties['name'] = $links_row['title'];
291
                    $properties['session_id'] = $links_row['session_id'];
292
                    $properties['link'] = $links_row['url'];
293
                    $properties['visibility'] = $links_row['visibility'];
294
                    $properties['image'] = $links_row['visibility'] == '0' ? 'file_html.png' : 'file_html.png';
295
                    $properties['adminlink'] = api_get_path(WEB_CODE_PATH).'link/link.php?action=editlink&id='.$links_row['id'];
296
                    $properties['target'] = $links_row['target'];
297
                    $tmp_all_tools_list[] = $properties;
298
                }
299
            }
300
        }
301
302
        if (isset($tmp_all_tools_list)) {
303
            $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
304
            foreach ($tmp_all_tools_list as $tool) {
305
                if ($tool['image'] == 'blog.gif') {
306
                    // Get blog id
307
                    $blog_id = substr($tool['link'], strrpos($tool['link'], '=') + 1, strlen($tool['link']));
308
309
                    // Get blog members
310
                    if ($is_platform_admin) {
311
                        $sql = "SELECT * FROM $tbl_blogs_rel_user blogs_rel_user
312
                                WHERE blog_id = ".$blog_id;
313
                    } else {
314
                        $sql = "SELECT * FROM $tbl_blogs_rel_user blogs_rel_user
315
                                WHERE blog_id = ".$blog_id." AND user_id = ".$userId;
316
                    }
317
                    $result = Database::query($sql);
318
                    if (Database::num_rows($result) > 0) {
319
                        $all_tools_list[] = $tool;
320
                    }
321
                } else {
322
                    $all_tools_list[] = $tool;
323
                }
324
            }
325
        }
326
327
        $list = self::filterPluginTools($all_tools_list, $course_tool_category);
328
329
        return $list;
330
    }
331
332
    /**
333
     * Displays the tools of a certain category.
334
     *
335
     * @param array $all_tools_list List of tools as returned by get_tools_category()
336
     *
337
     * @return array
338
     */
339
    public static function show_tools_category($all_tools_list)
340
    {
341
        $_user = api_get_user_info();
342
        $theme = api_get_setting('homepage_view');
343
344
        if ($theme === 'vertical_activity') {
345
            //ordering by get_lang name
346
            $order_tool_list = [];
347
            if (is_array($all_tools_list) && count($all_tools_list) > 0) {
348
                foreach ($all_tools_list as $key => $new_tool) {
349
                    $tool_name = self::translate_tool_name($new_tool);
350
                    $order_tool_list[$key] = $tool_name;
351
                }
352
                natsort($order_tool_list);
353
                $my_temp_tool_array = [];
354
                foreach ($order_tool_list as $key => $new_tool) {
355
                    $my_temp_tool_array[] = $all_tools_list[$key];
356
                }
357
                $all_tools_list = $my_temp_tool_array;
358
            } else {
359
                $all_tools_list = [];
360
            }
361
        }
362
        $web_code_path = api_get_path(WEB_CODE_PATH);
363
        $session_id = api_get_session_id();
364
        $is_platform_admin = api_is_platform_admin();
365
        $allowEditionInSession = api_get_configuration_value('allow_edit_tool_visibility_in_session');
366
        if ($session_id == 0) {
367
            $is_allowed_to_edit = api_is_allowed_to_edit(null, true) && api_is_course_admin();
368
        } else {
369
            $is_allowed_to_edit = api_is_allowed_to_edit(null, true) && !api_is_coach();
370
            if ($allowEditionInSession) {
371
                $is_allowed_to_edit = api_is_allowed_to_edit(null, true) && api_is_coach($session_id, api_get_course_int_id());
372
            }
373
        }
374
375
        $items = [];
376
        $app_plugin = new AppPlugin();
377
378
        if (isset($all_tools_list)) {
379
            $lnk = '';
380
            foreach ($all_tools_list as &$tool) {
381
                $item = [];
382
                $studentview = false;
383
                $tool['original_link'] = $tool['link'];
384
                if ($tool['image'] === 'scormbuilder.gif') {
385
                    // Check if the published learnpath is visible for student
386
                    $lpId = self::getPublishedLpIdFromLink($tool['link']);
387
                    if (api_is_allowed_to_edit(null, true)) {
388
                        $studentview = true;
389
                    }
390
                    if (!api_is_allowed_to_edit(null, true) &&
391
                        !learnpath::is_lp_visible_for_student(
392
                            $lpId,
393
                            api_get_user_id(),
394
                            api_get_course_info(),
395
                            api_get_session_id()
396
                        )
397
                    ) {
398
                        continue;
399
                    }
400
                }
401
402
                if ($session_id != 0 && in_array($tool['name'], ['course_setting'])) {
403
                    continue;
404
                }
405
406
                // This part displays the links to hide or remove a tool.
407
                // These links are only visible by the course manager.
408
                unset($lnk);
409
410
                $item['extra'] = null;
411
                $toolAdmin = isset($tool['admin']) ? $tool['admin'] : '';
412
413
                if ($is_allowed_to_edit) {
414
                    if (empty($session_id)) {
415
                        if (isset($tool['id'])) {
416
                            if ($tool['visibility'] == '1' && $toolAdmin != '1') {
417
                                $link['name'] = Display::return_icon(
418
                                    'visible.png',
419
                                    get_lang('Deactivate'),
420
                                    ['id' => 'linktool_'.$tool['iid']],
421
                                    ICON_SIZE_SMALL,
422
                                    false
423
                                );
424
                                $link['cmd'] = 'hide=yes';
425
                                $lnk[] = $link;
426
                            }
427
                            if ($tool['visibility'] == '0' && $toolAdmin != '1') {
428
                                $link['name'] = Display::return_icon(
429
                                    'invisible.png',
430
                                    get_lang('Activate'),
431
                                    ['id' => 'linktool_'.$tool['iid']],
432
                                    ICON_SIZE_SMALL,
433
                                    false
434
                                );
435
                                $link['cmd'] = 'restore=yes';
436
                                $lnk[] = $link;
437
                            }
438
                        }
439
                    } elseif ($allowEditionInSession) {
440
                        $criteria = [
441
                            'course' => api_get_course_int_id(),
442
                            'name' => $tool['name'],
443
                            'sessionId' => $session_id,
444
                        ];
445
                        /** @var CTool $tool */
446
                        $toolObj = Database::getManager()->getRepository('ChamiloCourseBundle:CTool')->findOneBy($criteria);
447
                        if ($toolObj) {
448
                            $visibility = (int) $toolObj->getVisibility();
449
                            switch ($visibility) {
450
                                case '0':
451
                                    $info = pathinfo($tool['image']);
452
                                    $basename = basename($tool['image'], '.'.$info['extension']);
453
                                    $tool['image'] = $basename.'_na.'.$info['extension'];
454
                                    $link['name'] = Display::return_icon(
455
                                        'invisible.png',
456
                                        get_lang('Activate'),
457
                                        ['id' => 'linktool_'.$tool['iid']],
458
                                        ICON_SIZE_SMALL,
459
                                        false
460
                                    );
461
                                    $link['cmd'] = 'restore=yes';
462
                                    $lnk[] = $link;
463
                                    break;
464
                                case '1':
465
                                    $link['name'] = Display::return_icon(
466
                                        'visible.png',
467
                                        get_lang('Deactivate'),
468
                                        ['id' => 'linktool_'.$tool['iid']],
469
                                        ICON_SIZE_SMALL,
470
                                        false
471
                                    );
472
                                    $link['cmd'] = 'hide=yes';
473
                                    $lnk[] = $link;
474
                                    break;
475
                            }
476
                        } else {
477
                            $link['name'] = Display::return_icon(
478
                                'visible.png',
479
                                get_lang('Deactivate'),
480
                                ['id' => 'linktool_'.$tool['iid']],
481
                                ICON_SIZE_SMALL,
482
                                false
483
                            );
484
                            $link['cmd'] = 'hide=yes';
485
                            $lnk[] = $link;
486
                        }
487
                    }
488
                    if (!empty($tool['adminlink'])) {
489
                        $item['extra'] = '<a href="'.$tool['adminlink'].'">'.
490
                            Display::return_icon('edit.gif', get_lang('Edit')).
491
                        '</a>';
492
                    }
493
                }
494
495
                // Both checks are necessary as is_platform_admin doesn't take student view into account
496
                if ($is_platform_admin && $is_allowed_to_edit) {
497
                    if ($toolAdmin != '1') {
498
                        $link['cmd'] = 'hide=yes';
499
                    }
500
                }
501
502
                $item['visibility'] = '';
503
                if (isset($lnk) && is_array($lnk)) {
504
                    foreach ($lnk as $this_link) {
505
                        if (empty($tool['adminlink'])) {
506
                            $item['visibility'] .=
507
                                '<a class="make_visible_and_invisible" href="'.api_get_self().'?'.api_get_cidreq().'&id='.$tool['iid'].'&'.$this_link['cmd'].'">'.
508
                                $this_link['name'].'</a>';
509
                        }
510
                    }
511
                }
512
513
                // NOTE : Table contains only the image file name, not full path
514
                if (stripos($tool['link'], 'http://') === false &&
515
                    stripos($tool['link'], 'https://') === false &&
516
                    stripos($tool['link'], 'ftp://') === false
517
                ) {
518
                    $tool['link'] = $web_code_path.$tool['link'];
519
                }
520
521
                $class = '';
522
                if ($tool['visibility'] == '0' && $toolAdmin != '1') {
523
                    $class = 'text-muted';
524
                    $info = pathinfo($tool['image']);
525
                    $basename = basename($tool['image'], '.'.$info['extension']);
526
                    $tool['image'] = $basename.'_na.'.$info['extension'];
527
                }
528
529
                $qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&';
530
531
                // If it's a link, we don't add the cidReq
532
                if ($tool['image'] === 'file_html.png' || $tool['image'] === 'file_html_na.png') {
533
                    $tool['link'] = $tool['link'];
534
                } else {
535
                    $tool['link'] = $tool['link'].$qm_or_amp.api_get_cidreq();
536
                }
537
538
                $toolIid = isset($tool['iid']) ? $tool['iid'] : null;
539
540
                //@todo this visio stuff should be removed
541
                if (strpos($tool['name'], 'visio_') !== false) {
542
                    $tool_link_params = [
543
                        'id' => 'tooldesc_'.$toolIid,
544
                        'href' => '"javascript: void(0);"',
545
                        'class' => $class,
546
                        'onclick' => 'javascript: window.open(\''.$tool['link'].'\',\'window_visio'.api_get_course_id().'\',config=\'height=\'+730+\', width=\'+1020+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')',
547
                        'target' => $tool['target'],
548
                    ];
549
                } elseif (strpos($tool['name'], 'chat') !== false &&
550
                    api_get_course_setting('allow_open_chat_window')
551
                ) {
552
                    $tool_link_params = [
553
                        'id' => 'tooldesc_'.$toolIid,
554
                        'class' => $class,
555
                        'href' => 'javascript: void(0);',
556
                        'onclick' => 'javascript: window.open(\''.$tool['link'].'\',\'window_chat'.api_get_course_id().'\',config=\'height=\'+600+\', width=\'+825+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')', //Chat Open Windows
557
                        'target' => $tool['target'],
558
                    ];
559
                } else {
560
                    $tool_link_params = [
561
                        'id' => 'tooldesc_'.$toolIid,
562
                        'href' => $tool['link'],
563
                        'class' => $class,
564
                        'target' => $tool['target'],
565
                    ];
566
                }
567
568
                $tool_name = self::translate_tool_name($tool);
569
570
                // Including Courses Plugins
571
                // Creating title and the link
572
                if (isset($tool['category']) && $tool['category'] == 'plugin') {
573
                    $plugin_info = $app_plugin->getPluginInfo($tool['name']);
574
                    if (isset($plugin_info) && isset($plugin_info['title'])) {
575
                        $tool_name = $plugin_info['title'];
576
                    }
577
578
                    if (!file_exists(api_get_path(SYS_CODE_PATH).'img/'.$tool['image']) &&
579
                        !file_exists(api_get_path(SYS_CODE_PATH).'img/icons/64/'.$tool['image'])) {
580
                        $tool['image'] = 'plugins.png';
581
                    }
582
                    $tool_link_params['href'] = api_get_path(WEB_PLUGIN_PATH)
583
                        .$tool['original_link'].$qm_or_amp.api_get_cidreq();
584
                }
585
586
                // Use in the course home
587
                $icon = Display::return_icon(
588
                    $tool['image'],
589
                    $tool_name,
590
                    ['class' => 'tool-icon', 'id' => 'toolimage_'.$toolIid],
591
                    ICON_SIZE_BIG,
592
                    false
593
                );
594
595
                // Used in the top bar
596
                $iconMedium = Display::return_icon(
597
                    $tool['image'],
598
                    $tool_name,
599
                    ['class' => 'tool-icon', 'id' => 'toolimage_'.$toolIid],
600
                    ICON_SIZE_MEDIUM,
601
                    false
602
                );
603
604
                // Used for vertical navigation
605
                $iconSmall = Display::return_icon(
606
                    $tool['image'],
607
                    $tool_name,
608
                    ['class' => 'tool-img', 'id' => 'toolimage_'.$toolIid],
609
                    ICON_SIZE_SMALL,
610
                    false
611
                );
612
613
                /*if (!empty($tool['custom_icon'])) {
614
                    $image = self::getCustomWebIconPath().$tool['custom_icon'];
615
                    $icon = Display::img(
616
                        $image,
617
                        $tool['description'],
618
                        array(
619
                            'class' => 'tool-icon',
620
                            'id' => 'toolimage_'.$tool['id']
621
                        )
622
                    );
623
                }*/
624
625
                // Validation when belongs to a session
626
                $session_img = api_get_session_image(
627
                    $tool['session_id'],
628
                    !empty($_user['status']) ? $_user['status'] : ''
0 ignored issues
show
Bug introduced by
It seems like ! empty($_user['status']) ? $_user['status'] : '' can also be of type string; however, parameter $statusId of api_get_session_image() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

628
                    /** @scrutinizer ignore-type */ !empty($_user['status']) ? $_user['status'] : ''
Loading history...
629
                );
630
                if ($studentview) {
631
                    $tool_link_params['href'] .= '&isStudentView=true';
632
                }
633
                $item['url_params'] = $tool_link_params;
634
                $item['icon'] = Display::url($icon, $tool_link_params['href'], $tool_link_params);
635
                $item['only_icon'] = $icon;
636
                $item['only_icon_medium'] = $iconMedium;
637
                $item['only_icon_small'] = $iconSmall;
638
                $item['only_href'] = $tool_link_params['href'];
639
                $item['tool'] = $tool;
640
                $item['name'] = $tool_name;
641
                $tool_link_params['id'] = 'is'.$tool_link_params['id'];
642
                $item['link'] = Display::url(
643
                    $tool_name.$session_img,
644
                    $tool_link_params['href'],
645
                    $tool_link_params
646
                );
647
                $items[] = $item;
648
            }
649
        }
650
651
        foreach ($items as &$item) {
652
            $originalImage = self::getToolIcon($item, ICON_SIZE_BIG);
653
            $item['tool']['only_icon_medium'] = self::getToolIcon($item, ICON_SIZE_MEDIUM, false);
654
            $item['tool']['only_icon_small'] = self::getToolIcon($item, ICON_SIZE_SMALL, false);
655
656
            if ($theme === 'activity_big') {
657
                $item['tool']['image'] = Display::url(
658
                    $originalImage,
659
                    $item['url_params']['href'],
660
                    $item['url_params']
661
                );
662
            }
663
        }
664
665
        return $items;
666
    }
667
668
    /**
669
     * Shows the general data for a particular meeting.
670
     *
671
     * @param int $id_session
672
     *
673
     * @return string session data
674
     */
675
    public static function show_session_data($id_session)
676
    {
677
        $sessionInfo = api_get_session_info($id_session);
678
679
        if (empty($sessionInfo)) {
680
            return '';
681
        }
682
683
        $table = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
684
        $sql = 'SELECT name FROM '.$table.'
685
                WHERE id = "'.intval($sessionInfo['session_category_id']).'"';
686
        $rs_category = Database::query($sql);
687
        $session_category = '';
688
        if (Database::num_rows($rs_category) > 0) {
689
            $rows_session_category = Database::store_result($rs_category);
690
            $rows_session_category = $rows_session_category[0];
691
            $session_category = $rows_session_category['name'];
692
        }
693
694
        $coachInfo = api_get_user_info($sessionInfo['id_coach']);
695
696
        $output = '';
697
        if (!empty($session_category)) {
698
            $output .= '<tr><td>'.get_lang('SessionCategory').': '.'<b>'.$session_category.'</b></td></tr>';
699
        }
700
        $dateInfo = SessionManager::parseSessionDates($sessionInfo);
701
702
        $msgDate = $dateInfo['access'];
703
        $output .= '<tr>
704
                    <td style="width:50%">'.get_lang('SessionName').': '.'<b>'.$sessionInfo['name'].'</b></td>
705
                    <td>'.get_lang('GeneralCoach').': '.'<b>'.$coachInfo['complete_name'].'</b></td></tr>';
706
        $output .= '<tr>
707
                        <td>'.get_lang('SessionIdentifier').': '.
708
                            Display::return_icon('star.png', ' ', ['align' => 'absmiddle']).'
709
                        </td>
710
                        <td>'.get_lang('Date').': '.'<b>'.$msgDate.'</b>
711
                        </td>
712
                    </tr>';
713
714
        return $output;
715
    }
716
717
    /**
718
     * Retrieves the name-field within a tool-record and translates it on necessity.
719
     *
720
     * @param array $tool the input record
721
     *
722
     * @return string returns the name of the corresponding tool
723
     */
724
    public static function translate_tool_name(&$tool)
725
    {
726
        static $already_translated_icons = [
727
            'file_html.gif',
728
            'file_html_na.gif',
729
            'file_html.png',
730
            'file_html_na.png',
731
            'scormbuilder.gif',
732
            'scormbuilder_na.gif',
733
            'blog.gif',
734
            'blog_na.gif',
735
            'external.gif',
736
            'external_na.gif',
737
        ];
738
739
        $toolName = Security::remove_XSS(stripslashes(strip_tags($tool['name'])));
740
741
        if (isset($tool['image']) && in_array($tool['image'], $already_translated_icons)) {
742
            return $toolName;
743
        }
744
745
        $toolName = api_underscore_to_camel_case($toolName);
746
747
        if (isset($tool['category']) && 'plugin' !== $tool['category'] &&
748
            isset($GLOBALS['Tool'.$toolName])
749
        ) {
750
            return get_lang('Tool'.$toolName);
751
        }
752
753
        return $toolName;
754
    }
755
756
    /**
757
     * Get published learning path id from link inside course home.
758
     *
759
     * @param 	string	Link to published lp
760
     *
761
     * @return int Learning path id
762
     */
763
    public static function getPublishedLpIdFromLink($link)
764
    {
765
        $lpId = 0;
766
        $param = strstr($link, 'lp_id=');
767
        if (!empty($param)) {
768
            $paramList = explode('=', $param);
769
            if (isset($paramList[1])) {
770
                $lpId = (int) $paramList[1];
771
            }
772
        }
773
774
        return $lpId;
775
    }
776
777
    /**
778
     * Get published learning path category from link inside course home.
779
     *
780
     * @param string $link
781
     *
782
     * @return CLpCategory
783
     */
784
    public static function getPublishedLpCategoryFromLink($link)
785
    {
786
        $query = parse_url($link, PHP_URL_QUERY);
787
        parse_str($query, $params);
788
        $id = isset($params['id']) ? (int) $params['id'] : 0;
789
        $em = Database::getManager();
790
        /** @var CLpCategory $category */
791
        $category = $em->find('ChamiloCourseBundle:CLpCategory', $id);
792
793
        return $category;
794
    }
795
796
    /**
797
     * Show a navigation menu.
798
     */
799
    public static function show_navigation_menu()
800
    {
801
        $blocks = self::getUserBlocks();
802
        $class = null;
803
        $idLearn = null;
804
        $item = null;
805
        $marginLeft = 160;
806
807
        $html = '<div id="toolnav">';
808
        $html .= '<ul id="toolnavbox">';
809
810
        $showOnlyText = api_get_setting('show_navigation_menu') === 'text';
811
        $showOnlyIcons = api_get_setting('show_navigation_menu') === 'icons';
812
813
        foreach ($blocks as $block) {
814
            $blockItems = $block['content'];
815
            foreach ($blockItems as $item) {
816
                $html .= '<li>';
817
                if ($showOnlyText) {
818
                    $class = 'text';
819
                    $marginLeft = 170;
820
                    $show = $item['name'];
821
                } elseif ($showOnlyIcons) {
822
                    $class = 'icons';
823
                    $marginLeft = 25;
824
                    $show = $item['tool']['only_icon_small'];
825
                } else {
826
                    $class = 'icons-text';
827
                    $show = $item['name'].$item['tool']['only_icon_small'];
828
                }
829
830
                $item['url_params']['class'] = 'btn btn-default text-left '.$class;
831
                $html .= Display::url(
832
                    $show,
833
                    $item['only_href'],
834
                    $item['url_params']
835
                );
836
                $html .= '</li>';
837
            }
838
        }
839
840
        $html .= '</ul>';
841
        $html .= '<script>$(function() {
842
                $("#toolnavbox a").stop().animate({"margin-left":"-'.$marginLeft.'px"},1000);
843
                $("#toolnavbox > li").hover(
844
                    function () {
845
                        $("a",$(this)).stop().animate({"margin-left":"-2px"},200);
846
                        $("span",$(this)).css("display","block");
847
                    },
848
                    function () {
849
                        $("a",$(this)).stop().animate({"margin-left":"-'.$marginLeft.'px"},200);
850
                        $("span",$(this)).css("display","initial");
851
                    }
852
                );
853
            });</script>';
854
        $html .= '</div>';
855
856
        return $html;
857
    }
858
859
    /**
860
     * Show a toolbar with shortcuts to the course tool.
861
     *
862
     * @param int $orientation
863
     *
864
     * @return string
865
     */
866
    public static function show_navigation_tool_shortcuts($orientation = SHORTCUTS_HORIZONTAL)
867
    {
868
        $origin = api_get_origin();
869
        $courseInfo = api_get_course_info();
870
        if ($origin === 'learnpath') {
871
            return '';
872
        }
873
874
        $blocks = self::getUserBlocks();
875
        $html = '';
876
        if (!empty($blocks)) {
877
            $styleId = 'toolshortcuts_vertical';
878
            if ($orientation == SHORTCUTS_HORIZONTAL) {
879
                $styleId = 'toolshortcuts_horizontal';
880
            }
881
            $html .= '<div id="'.$styleId.'">';
882
883
            $html .= Display::url(
884
                Display::return_icon('home.png', get_lang('CourseHomepageLink'), '', ICON_SIZE_MEDIUM),
885
                $courseInfo['course_public_url'],
886
                ['class' => 'items-icon']
887
            );
888
889
            foreach ($blocks as $block) {
890
                $blockItems = $block['content'];
891
                foreach ($blockItems as $item) {
892
                    $item['url_params']['id'] = '';
893
                    $item['url_params']['class'] = 'items-icon';
894
                    $html .= Display::url(
895
                        $item['tool']['only_icon_medium'],
896
                        $item['only_href'],
897
                        $item['url_params']
898
                    );
899
                    if ($orientation == SHORTCUTS_VERTICAL) {
900
                        $html .= '<br />';
901
                    }
902
                }
903
            }
904
            $html .= '</div>';
905
        }
906
907
        return $html;
908
    }
909
910
    /**
911
     * List course homepage tools from authoring and interaction sections.
912
     *
913
     * @param int $courseId  The course ID (guessed from context if not provided)
914
     * @param int $sessionId The session ID (guessed from context if not provided)
915
     *
916
     * @return array List of all tools data from the c_tools table
917
     */
918
    public static function toolsIconsAction($courseId = null, $sessionId = null)
919
    {
920
        if (empty($courseId)) {
921
            $courseId = api_get_course_int_id();
922
        } else {
923
            $courseId = intval($courseId);
924
        }
925
        if (empty($sessionId)) {
926
            $sessionId = api_get_session_id();
927
        } else {
928
            $sessionId = intval($sessionId);
929
        }
930
931
        if (empty($courseId)) {
932
            // We shouldn't get here, but for some reason api_get_course_int_id()
933
            // doesn't seem to get the course from the context, sometimes
934
            return [];
935
        }
936
937
        $table = Database::get_course_table(TABLE_TOOL_LIST);
938
        $sql = "SELECT * FROM $table
939
                WHERE category in ('authoring','interaction')
940
                AND c_id = $courseId
941
                AND session_id = $sessionId
942
                ORDER BY id";
943
944
        $result = Database::query($sql);
945
        $data = Database::store_result($result, 'ASSOC');
946
947
        return $data;
948
    }
949
950
    /**
951
     * @param int $editIcon
952
     *
953
     * @return array
954
     */
955
    public static function getTool($editIcon)
956
    {
957
        $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST);
958
        $editIcon = intval($editIcon);
959
960
        $sql = "SELECT * FROM $course_tool_table
961
                WHERE iid = $editIcon";
962
        $result = Database::query($sql);
963
        $tool = Database::fetch_assoc($result, 'ASSOC');
964
965
        return $tool;
966
    }
967
968
    /**
969
     * @return string
970
     */
971
    public static function getCustomSysIconPath()
972
    {
973
        // Check if directory exists or create it if it doesn't
974
        $dir = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/course_home_icons/';
975
        if (!is_dir($dir)) {
976
            mkdir($dir, api_get_permissions_for_new_directories(), true);
977
        }
978
979
        return $dir;
980
    }
981
982
    /**
983
     * @return string
984
     */
985
    public static function getCustomWebIconPath()
986
    {
987
        // Check if directory exists or create it if it doesn't
988
        $dir = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/upload/course_home_icons/';
989
990
        return $dir;
991
    }
992
993
    /**
994
     * @param string $icon
995
     *
996
     * @return string
997
     */
998
    public static function getDisableIcon($icon)
999
    {
1000
        $fileInfo = pathinfo($icon);
1001
1002
        return $fileInfo['filename'].'_na.'.$fileInfo['extension'];
1003
    }
1004
1005
    /**
1006
     * @param int   $id
1007
     * @param array $values
1008
     */
1009
    public static function updateTool($id, $values)
1010
    {
1011
        $table = Database::get_course_table(TABLE_TOOL_LIST);
1012
        $params = [
1013
            'name' => $values['name'],
1014
            'link' => $values['link'],
1015
            'target' => $values['target'],
1016
            'visibility' => $values['visibility'],
1017
            'description' => $values['description'],
1018
        ];
1019
1020
        if (isset($_FILES['icon']['size']) && $_FILES['icon']['size'] !== 0) {
1021
            $dir = self::getCustomSysIconPath();
1022
1023
            // Resize image if it is larger than 64px
1024
            $temp = new Image($_FILES['icon']['tmp_name']);
1025
            $picture_infos = $temp->get_image_info();
1026
            if ($picture_infos['width'] > 64) {
1027
                $thumbwidth = 64;
1028
            } else {
1029
                $thumbwidth = $picture_infos['width'];
1030
            }
1031
            if ($picture_infos['height'] > 64) {
1032
                $new_height = 64;
1033
            } else {
1034
                $new_height = $picture_infos['height'];
1035
            }
1036
            $temp->resize($thumbwidth, $new_height, 0);
1037
1038
            //copy the image to the course upload folder
1039
            $path = $dir.$_FILES['icon']['name'];
1040
            $result = $temp->send_image($path);
1041
1042
            $temp = new Image($path);
1043
            $r = $temp->convert2bw();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $r is correct as $temp->convert2bw() targeting Image::convert2bw() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
1044
            $ext = pathinfo($path, PATHINFO_EXTENSION);
1045
            $bwPath = substr($path, 0, -(strlen($ext) + 1)).'_na.'.$ext;
1046
1047
            if ($r === false) {
1048
                error_log('Conversion to B&W of '.$path.' failed in '.__FILE__.' at line '.__LINE__);
1049
            } else {
1050
                $temp->send_image($bwPath);
1051
                $iconName = $_FILES['icon']['name'];
1052
                $params['custom_icon'] = $iconName;
1053
            }
1054
        }
1055
1056
        Database::update(
1057
            $table,
1058
            $params,
1059
            [' iid = ?' => [$id]]
1060
        );
1061
    }
1062
1063
    /**
1064
     * @param int $id
1065
     */
1066
    public static function deleteIcon($id)
1067
    {
1068
        $table = Database::get_course_table(TABLE_TOOL_LIST);
1069
        $tool = self::getTool($id);
1070
1071
        if ($tool && !empty($tool['custom_icon'])) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $tool of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
1072
            $file = self::getCustomSysIconPath().$tool['custom_icon'];
1073
            $fileInfo = pathinfo($file);
1074
            $fileGray = $fileInfo['filename'].'_na.'.$fileInfo['extension'];
1075
            $fileGray = self::getCustomSysIconPath().$fileGray;
1076
1077
            if (file_exists($file) && is_file($file)) {
1078
                if (Security::check_abs_path($file, self::getCustomSysIconPath())) {
1079
                    unlink($file);
1080
                }
1081
            }
1082
1083
            if (file_exists($fileGray) && is_file($fileGray)) {
1084
                if (Security::check_abs_path($fileGray, self::getCustomSysIconPath())) {
1085
                    unlink($fileGray);
1086
                }
1087
            }
1088
1089
            $params = [
1090
                'custom_icon' => '',
1091
            ];
1092
1093
            Database::update(
1094
                $table,
1095
                $params,
1096
                [' iid = ?' => [$id]]
1097
            );
1098
        }
1099
    }
1100
1101
    /**
1102
     * @return array
1103
     */
1104
    public static function getCourseAdminBlocks()
1105
    {
1106
        $blocks = [];
1107
        $my_list = self::get_tools_category(TOOL_AUTHORING);
1108
1109
        $blocks[] = [
1110
            'title' => get_lang('Authoring'),
1111
            'class' => 'course-tools-author',
1112
            'content' => self::show_tools_category($my_list),
1113
        ];
1114
1115
        $list1 = self::get_tools_category(TOOL_INTERACTION);
1116
        $list2 = self::get_tools_category(TOOL_COURSE_PLUGIN);
1117
        $my_list = array_merge($list1, $list2);
1118
1119
        $blocks[] = [
1120
            'title' => get_lang('Interaction'),
1121
            'class' => 'course-tools-interaction',
1122
            'content' => self::show_tools_category($my_list),
1123
        ];
1124
1125
        $my_list = self::get_tools_category(TOOL_ADMIN_PLATFORM);
1126
1127
        $blocks[] = [
1128
            'title' => get_lang('Administration'),
1129
            'class' => 'course-tools-administration',
1130
            'content' => self::show_tools_category($my_list),
1131
        ];
1132
1133
        return $blocks;
1134
    }
1135
1136
    /**
1137
     * @return array
1138
     */
1139
    public static function getCoachBlocks()
1140
    {
1141
        $blocks = [];
1142
        $my_list = self::get_tools_category(TOOL_STUDENT_VIEW);
1143
1144
        $blocks[] = [
1145
            'content' => self::show_tools_category($my_list),
1146
        ];
1147
1148
        $sessionsCopy = api_get_setting('allow_session_course_copy_for_teachers');
1149
        if ($sessionsCopy === 'true') {
1150
            // Adding only maintenance for coaches.
1151
            $myList = self::get_tools_category(TOOL_ADMIN_PLATFORM);
1152
            $onlyMaintenanceList = [];
1153
1154
            foreach ($myList as $item) {
1155
                if ($item['name'] === 'course_maintenance') {
1156
                    $item['link'] = 'course_info/maintenance_coach.php';
1157
1158
                    $onlyMaintenanceList[] = $item;
1159
                }
1160
            }
1161
1162
            $blocks[] = [
1163
                'title' => get_lang('Administration'),
1164
                'content' => self::show_tools_category($onlyMaintenanceList),
1165
            ];
1166
        }
1167
1168
        return $blocks;
1169
    }
1170
1171
    /**
1172
     * @return array
1173
     */
1174
    public static function getStudentBlocks()
1175
    {
1176
        $blocks = [];
1177
        $tools = self::get_tools_category(TOOL_STUDENT_VIEW);
1178
        $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
1179
            api_get_user_id(),
1180
            api_get_course_info()
1181
        );
1182
1183
        // Force user icon for DRH
1184
        if ($isDrhOfCourse) {
1185
            $addUserTool = true;
1186
            foreach ($tools as $tool) {
1187
                if ($tool['name'] === 'user') {
1188
                    $addUserTool = false;
1189
                    break;
1190
                }
1191
            }
1192
1193
            if ($addUserTool) {
1194
                $tools[] = [
1195
                    'c_id' => api_get_course_int_id(),
1196
                    'name' => 'user',
1197
                    'link' => 'user/user.php',
1198
                    'image' => 'members.gif',
1199
                    'visibility' => '1',
1200
                    'admin' => '0',
1201
                    'address' => 'squaregrey.gif',
1202
                    'added_tool' => '0',
1203
                    'target' => '_self',
1204
                    'category' => 'interaction',
1205
                    'session_id' => api_get_session_id(),
1206
                ];
1207
            }
1208
        }
1209
1210
        if (count($tools) > 0) {
1211
            $blocks[] = ['content' => self::show_tools_category($tools)];
1212
        }
1213
1214
        if ($isDrhOfCourse) {
1215
            $drhTool = self::get_tools_category(TOOL_DRH);
1216
            $blocks[] = ['content' => self::show_tools_category($drhTool)];
1217
        }
1218
1219
        return $blocks;
1220
    }
1221
1222
    /**
1223
     * @return array
1224
     */
1225
    public static function getUserBlocks()
1226
    {
1227
        $sessionId = api_get_session_id();
1228
        // Start of tools for CourseAdmins (teachers/tutors)
1229
        if ($sessionId === 0 && api_is_course_admin() && api_is_allowed_to_edit(null, true)) {
1230
            $blocks = self::getCourseAdminBlocks();
1231
        } elseif (api_is_coach()) {
1232
            $blocks = self::getCoachBlocks();
1233
        } else {
1234
            $blocks = self::getStudentBlocks();
1235
        }
1236
1237
        return $blocks;
1238
    }
1239
1240
    /**
1241
     * Filter tool icons. Only show if $patronKey is = :teacher
1242
     * Example dataIcons[i]['name']: parameter titleIcons1:teacher || titleIcons2 || titleIcons3:teacher.
1243
     *
1244
     * @param array  $dataIcons          array Reference to icons
1245
     * @param string $courseToolCategory Current tools category
1246
     *
1247
     * @return array
1248
     */
1249
    private static function filterPluginTools($dataIcons, $courseToolCategory)
1250
    {
1251
        $patronKey = ':teacher';
1252
1253
        if ($courseToolCategory == TOOL_STUDENT_VIEW) {
1254
            //Fix only coach can see external pages - see #8236 - icpna
1255
            if (api_is_coach()) {
1256
                foreach ($dataIcons as $index => $array) {
1257
                    if (isset($array['name'])) {
1258
                        $dataIcons[$index]['name'] = str_replace($patronKey, '', $array['name']);
1259
                    }
1260
                }
1261
1262
                return $dataIcons;
1263
            }
1264
1265
            $flagOrder = false;
1266
1267
            foreach ($dataIcons as $index => $array) {
1268
                if (!isset($array['name'])) {
1269
                    continue;
1270
                }
1271
1272
                $pos = strpos($array['name'], $patronKey);
1273
1274
                if ($pos !== false) {
1275
                    unset($dataIcons[$index]);
1276
                    $flagOrder = true;
1277
                }
1278
            }
1279
1280
            if ($flagOrder) {
1281
                return array_values($dataIcons);
1282
            }
1283
1284
            return $dataIcons;
1285
        }
1286
1287
        // clean patronKey of name icons
1288
        foreach ($dataIcons as $index => $array) {
1289
            if (isset($array['name'])) {
1290
                $dataIcons[$index]['name'] = str_replace($patronKey, '', $array['name']);
1291
            }
1292
        }
1293
1294
        return $dataIcons;
1295
    }
1296
1297
    /**
1298
     * Find the tool icon when homepage_view is activity_big.
1299
     *
1300
     * @param array $item
1301
     * @param int   $iconSize
1302
     * @param bool  $generateId
1303
     *
1304
     * @return string
1305
     */
1306
    private static function getToolIcon(array $item, $iconSize, $generateId = true)
1307
    {
1308
        $image = str_replace('.gif', '.png', $item['tool']['image']);
1309
        $toolIid = isset($item['tool']['iid']) ? $item['tool']['iid'] : null;
1310
1311
        if (isset($item['tool']['custom_image'])) {
1312
            return Display::img(
1313
                $item['tool']['custom_image'],
1314
                $item['name'],
1315
                ['id' => 'toolimage_'.$toolIid]
1316
            );
1317
        }
1318
1319
        if (isset($item['tool']['custom_icon']) && !empty($item['tool']['custom_icon'])) {
1320
            $customIcon = $item['tool']['custom_icon'];
1321
1322
            if ($item['tool']['visibility'] == '0') {
1323
                $customIcon = self::getDisableIcon($item['tool']['custom_icon']);
1324
            }
1325
1326
            return Display::img(
1327
                self::getCustomWebIconPath().$customIcon,
1328
                $item['name'],
1329
                ['id' => 'toolimage_'.$toolIid]
1330
            );
1331
        }
1332
1333
        $id = '';
1334
        if ($generateId) {
1335
            $id = 'toolimage_'.$toolIid;
1336
        }
1337
1338
        return Display::return_icon(
1339
            $image,
1340
            $item['name'],
1341
            ['id' => $id],
1342
            $iconSize,
1343
            false
1344
        );
1345
    }
1346
}
1347