Completed
Push — master ( 3fdf06...e648ff )
by Julito
33:51
created

PageController::setCourseBlock()   C

Complexity

Conditions 14
Paths 72

Size

Total Lines 70
Code Lines 42

Duplication

Lines 15
Ratio 21.43 %

Importance

Changes 0
Metric Value
cc 14
eloc 42
nc 72
nop 1
dl 15
loc 70
rs 5.6188
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A PageController::returnNotice() 0 19 3
A PageController::show_right_block() 0 14 3

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\CoreBundle\Framework;
5
6
use Pagerfanta\Adapter\FixedAdapter;
7
use Pagerfanta\Pagerfanta;
8
use Pagerfanta\View\TwitterBootstrapView;
9
use SystemAnnouncementManager;
10
use UserManager;
11
use CourseManager;
12
use ChamiloSession as Session;
13
use Display;
14
use Chamilo\CoreBundle\Framework\Container;
15
16
/**
17
 * Class PageController
18
 * Controller for pages presentation in general
19
 * @package chamilo.page.controller
20
 * @author Julio Montoya <[email protected]>
21
 *
22
 * @todo move functions in the Template class, remove this class.
23
 */
24
class PageController
25
{
26
    public $maxPerPage = 5;
27
28
29
    /**
30
     * Returns an online help block read from the home/home_menu_[lang].html
31
     * file
32
     * @return string HTML block
33
     */
34
    public function returnHelp()
35
    {
36
        $home                   = api_get_home_path();
37
        $user_selected_language = api_get_language_isocode();
38
        $sys_path               = api_get_path(SYS_PATH);
39
        $platformLanguage = api_get_setting('language.platform_language');
40
41
        if (!isset($user_selected_language)) {
42
            $user_selected_language = $platformLanguage;
43
        }
44
        $home_menu = @(string)file_get_contents($sys_path.$home.'home_menu_'.$user_selected_language.'.html');
45 View Code Duplication
        if (!empty($home_menu)) {
46
            $home_menu_content = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
47
            $this->show_right_block(
0 ignored issues
show
Unused Code introduced by
The call to the method Chamilo\CoreBundle\Frame...ler::show_right_block() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
48
                get_lang('MenuGeneral'),
49
                null,
50
                'help_block',
51
                array('content' => $home_menu_content)
52
            );
53
        }
54
    }
55
56
    /**
57
     * Returns an HTML block with links to the skills tools
58
     * @return string HTML <div> block
59
     */
60
    public function returnSkillsLinks()
61
    {
62
        if (api_get_setting('skill.allow_skills_tool') == 'true') {
63
            $content   = array();
64
            $content[] = array(
65
                'title' => get_lang('MySkills'),
66
                'href'  => api_get_path(WEB_CODE_PATH).'social/skills_wheel.php'
67
            );
68
69 View Code Duplication
            if (api_get_setting('skill.allow_hr_skills_management') == 'true'
70
                || api_is_platform_admin()) {
71
                $content[] = array(
72
                    'title' => get_lang('ManageSkills'),
73
                    'href'  => api_get_path(WEB_CODE_PATH).'admin/skills_wheel.php'
74
                );
75
            }
76
            $this->show_right_block(get_lang("Skills"), $content, 'skill_block');
0 ignored issues
show
Unused Code introduced by
The call to the method Chamilo\CoreBundle\Frame...ler::show_right_block() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
77
        }
78
    }
79
80
    /**
81
     * Returns an HTML block with the notice, as found in the
82
     * home/home_notice_[lang].html file
83
     * @return string HTML <div> block
84
     */
85
    public function returnNotice()
86
    {
87
        $sys_path               = api_get_path(SYS_PATH);
88
        $user_selected_language = api_get_language_isocode();
89
        $home                   = api_get_home_path();
90
91
        // Notice
92
        $home_notice = @(string)file_get_contents($sys_path.$home.'home_notice_'.$user_selected_language.'.html');
93
        if (empty($home_notice)) {
94
            $home_notice = @(string)file_get_contents($sys_path.$home.'home_notice.html');
95
        }
96
97
        if (!empty($home_notice)) {
98
            $home_notice = api_to_system_encoding($home_notice, api_detect_encoding(strip_tags($home_notice)));
99
            $home_notice = Display::div($home_notice, array('class' => 'homepage_notice'));
100
101
            $this->show_right_block(get_lang('Notice'), null, 'notice_block', array('content' => $home_notice));
0 ignored issues
show
Unused Code introduced by
The call to the method Chamilo\CoreBundle\Frame...ler::show_right_block() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
102
        }
103
    }
104
105
    /**
106
     * Returns the received content packaged in <div> block, with the title as
107
     * <h4>
108
     * @param string Title to include as h4
109
     * @param string Longer content to show (usually a <ul> list)
110
     * @param string ID to be added to the HTML attributes for the block
111
     * @param array Array of attributes to add to the HTML block
112
     * @return string HTML <div> block
113
     * @todo use the menu builder
114
     */
115
    public function show_right_block($title, $content, $id, $params = null)
116
    {
117
        if (!empty($id)) {
118
            $params['id'] = $id;
119
        }
120
        $block_menu = array(
121
            'id'       => $params['id'],
122
            'title'    => $title,
123
            'elements' => $content,
124
            'content'  => isset($params['content']) ? $params['content'] : null
125
        );
126
127
        //$app['template']->assign($id, $block_menu);
128
    }
129
130
131
    /**
132
     * Returns a content search form in an HTML <div>, pointing at the
133
     * main/search/ directory. If search_enabled is not set, then it returns
134
     * an empty string
135
     * @return string HTML <div> block showing the search form, or an empty string if search not enabled
136
     */
137 View Code Duplication
    public function return_search_block()
138
    {
139
        $html = '';
140
        if (api_get_setting('search.search_enabled') == 'true') {
141
            $html .= '<div class="searchbox">';
142
            $search_btn     = get_lang('Search');
143
            $search_content = '<br />
144
                <form action="main/search/" method="post">
145
                <input type="text" id="query" class="span2" name="query" value="" />
146
                <button class="save" type="submit" name="submit" value="'.$search_btn.'" />'.$search_btn.' </button>
147
                </form></div>';
148
            $html .= $this->show_right_block(get_lang('Search'), $search_content, 'search_block');
149
        }
150
151
        return $html;
152
    }
153
154
    /**
155
     * Returns a list of announcements
156
     * @param int User ID
157
     * @param bool True: show the announcements as a slider. False: show them as a vertical list
158
     * @return string HTML list of announcements
159
     */
160
    public function getAnnouncements($user_id = null, $show_slide = true)
161
    {
162
        // Display System announcements
163
        $hideAnnouncements = api_get_setting('hide_global_announcements_when_not_connected');
164
        if ($hideAnnouncements == 'true' && empty($user_id)) {
165
            return null;
166
        }
167
168
        $announcement = isset($_GET['announcement']) ? $_GET['announcement'] : null;
169
        $announcement = intval($announcement);
170
171
        if (!api_is_anonymous() && $user_id) {
172
            $visibility = api_is_allowed_to_create_course() ? SystemAnnouncementManager::VISIBLE_TEACHER : SystemAnnouncementManager::VISIBLE_STUDENT;
173
            if ($show_slide) {
174
                $announcements = SystemAnnouncementManager:: display_announcements_slider(
175
                    $visibility,
176
                    $announcement
177
                );
178
            } else {
179
                $announcements = SystemAnnouncementManager:: display_all_announcements(
180
                    $visibility,
181
                    $announcement
182
                );
183
            }
184
        } else {
185
            if ($show_slide) {
186
                $announcements = SystemAnnouncementManager:: display_announcements_slider(
187
                    SystemAnnouncementManager::VISIBLE_GUEST,
188
                    $announcement
189
                );
190
            } else {
191
                $announcements = SystemAnnouncementManager:: display_all_announcements(
192
                    SystemAnnouncementManager::VISIBLE_GUEST,
193
                    $announcement
194
                );
195
            }
196
        }
197
198
        return $announcements;
199
    }
200
201
    /**
202
     * Return the homepage, including announcements
203
     * @return string The portal's homepage as an HTML string
204
     */
205
    public function returnHomePage()
206
    {
207
        // Including the page for the news
208
        $html          = null;
209
        $home          = api_get_path(SYS_DATA_PATH).api_get_home_path();
210
        $home_top_temp = null;
211
212
        if (!empty($_GET['include']) && preg_match('/^[a-zA-Z0-9_-]*\.html$/', $_GET['include'])) {
213
            $open = @(string)file_get_contents(api_get_path(SYS_PATH).$home.$_GET['include']);
214
            $html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
215
        } else {
216
            $user_selected_language = api_get_user_language();
217
218
            if (!file_exists($home.'home_news_'.$user_selected_language.'.html')) {
219
                if (file_exists($home.'home_top.html')) {
220
                    $home_top_temp = file($home.'home_top.html');
221
                } else {
0 ignored issues
show
Unused Code introduced by
This else statement is empty and can be removed.

This check looks for the else branches 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 else branches can be removed.

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

could be turned into

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

This is much more concise to read.

Loading history...
222
                    //$home_top_temp = file('home/'.'home_top.html');
223
                }
224
                if (!empty($home_top_temp)) {
225
                    $home_top_temp = implode('', $home_top_temp);
226
                }
227
            } else {
228
                if (file_exists($home.'home_top_'.$user_selected_language.'.html')) {
229
                    $home_top_temp = file_get_contents($home.'home_top_'.$user_selected_language.'.html');
230
                } else {
231
                    $home_top_temp = file_get_contents($home.'home_top.html');
232
                }
233
            }
234
235
            if (empty($home_top_temp) && api_is_platform_admin()) {
236
                $home_top_temp = get_lang('PortalHomepageDefaultIntroduction');
237
            }
238
            $open = str_replace('{rel_path}', api_get_path(REL_PATH), $home_top_temp);
239
            if (!empty($open)) {
240
                $html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
241
            }
242
        }
243
244
        return $html;
245
    }
246
247
    /**
248
     * Returns an HTML block with classes (if show_groups_to_users is true)
249
     * @return string A list of links to users classes tools, or an empty string if show_groups_to_users is disabled
250
     */
251 View Code Duplication
    public function return_classes_block()
252
    {
253
        $html = '';
254
        if (api_get_setting('show_groups_to_users') == 'true') {
255
            $usergroup      = new Usergroup();
256
            $usergroup_list = $usergroup->get_usergroup_by_user(api_get_user_id());
257
            $classes        = '';
258
            if (!empty($usergroup_list)) {
259
                foreach ($usergroup_list as $group_id) {
260
                    $data         = $usergroup->get($group_id);
261
                    $data['name'] = Display::url(
262
                        $data['name'],
263
                        api_get_path(WEB_CODE_PATH).'user/classes.php?id='.$data['id']
264
                    );
265
                    $classes .= Display::tag('li', $data['name']);
266
                }
267
            }
268
            if (api_is_platform_admin()) {
269
                $classes .= Display::tag(
270
                    'li',
271
                    Display::url(get_lang('AddClasses'), api_get_path(WEB_CODE_PATH).'admin/usergroups.php?action=add')
272
                );
273
            }
274
            if (!empty($classes)) {
275
                $classes = Display::tag('ul', $classes, array('class' => 'nav nav-list'));
276
                $html .= $this->show_right_block(get_lang('Classes'), $classes, 'classes_block');
277
            }
278
        }
279
280
        return $html;
281
    }
282
283
    /**
284
     * Prepares a block with all the pending exercises in all courses
285
     * @param array Array of courses (arrays) of the user
286
     * @return void Doesn't return anything but prepares and HTML block for use in templates
287
     */
288
    public function return_exercise_block($personal_course_list, $tpl)
289
    {
290
        $exercise_list = array();
291
        if (!empty($personal_course_list)) {
292 View Code Duplication
            foreach ($personal_course_list as $course_item) {
293
                $course_code = $course_item['c'];
294
                $session_id  = $course_item['id_session'];
295
296
                $exercises = ExerciseLib::get_exercises_to_be_taken($course_code, $session_id);
297
298
                foreach ($exercises as $exercise_item) {
299
                    $exercise_item['course_code'] = $course_code;
300
                    $exercise_item['session_id']  = $session_id;
301
                    $exercise_item['tms']         = api_strtotime($exercise_item['end_time'], 'UTC');
302
303
                    $exercise_list[] = $exercise_item;
304
                }
305
            }
306
            if (!empty($exercise_list)) {
307
                $exercise_list = ArrayClass::msort($exercise_list, 'tms');
308
                $my_exercise   = $exercise_list[0];
309
                $url           = Display::url(
310
                    $my_exercise['title'],
311
                    api_get_path(
312
                        WEB_CODE_PATH
313
                    ).'exercise/overview.php?exerciseId='.$my_exercise['id'].'&cidReq='.$my_exercise['course_code'].'&id_session='.$my_exercise['session_id']
314
                );
315
                $tpl->assign('exercise_url', $url);
316
                $tpl->assign(
317
                    'exercise_end_date',
318
                    api_convert_and_format_date($my_exercise['end_time'], DATE_FORMAT_SHORT)
319
                );
320
            }
321
        }
322
    }
323
324
    /**
325
     * Display list of courses in a category.
326
     * (for anonymous users)
327
     *
328
     * @version 1.1
329
     * @author Patrick Cool <[email protected]>, Ghent University - refactoring and code cleaning
330
     * @author Julio Montoya <[email protected]>, Beeznest template modifs
331
     */
332
    public function return_courses_in_categories()
333
    {
334
        $result = '';
335
        $stok   = Security::get_token();
336
337
        // Initialization.
338
        $user_identified                  = (api_get_user_id() > 0 && !api_is_anonymous());
339
        $web_course_path                  = api_get_path(WEB_COURSE_PATH);
340
        $category                         = Database::escape_string($_GET['category']);
341
        $setting_show_also_closed_courses = api_get_setting('show_closed_courses') == 'true';
342
343
        // Database table definitions.
344
        $main_course_table   = Database :: get_main_table(TABLE_MAIN_COURSE);
345
        $main_category_table = Database :: get_main_table(TABLE_MAIN_CATEGORY);
346
347
        // Get list of courses in category $category.
348
        $sql_get_course_list = "SELECT * FROM $main_course_table cours
349
                                    WHERE category_code = '".Database::escape_string($_GET['category'])."'
350
                                    ORDER BY title, UPPER(visual_code)";
351
352
        // Showing only the courses of the current access_url_id.
353
        if (api_is_multiple_url_enabled()) {
354
            $url_access_id = api_get_current_access_url_id();
355
            if ($url_access_id != -1) {
356
                $tbl_url_rel_course  = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
357
                $sql_get_course_list = "SELECT * FROM $main_course_table as course INNER JOIN $tbl_url_rel_course as url_rel_course
358
                        ON (url_rel_course.c_id = course.id)
359
                        WHERE access_url_id = $url_access_id AND category_code = '".Database::escape_string(
360
                    $_GET['category']
361
                )."' ORDER BY title, UPPER(visual_code)";
362
            }
363
        }
364
365
        // Removed: AND cours.visibility='".COURSE_VISIBILITY_OPEN_WORLD."'
366
        $sql_result_courses = Database::query($sql_get_course_list);
367
368
        while ($course_result = Database::fetch_array($sql_result_courses)) {
369
            $course_list[] = $course_result;
370
        }
371
372
        $platform_visible_courses = '';
373
        // $setting_show_also_closed_courses
374 View Code Duplication
        if ($user_identified) {
375
            if ($setting_show_also_closed_courses) {
376
                $platform_visible_courses = '';
377
            } else {
378
                $platform_visible_courses = "  AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' OR t3.visibility='".COURSE_VISIBILITY_OPEN_PLATFORM."' )";
379
            }
380
        } else {
381
            if ($setting_show_also_closed_courses) {
382
                $platform_visible_courses = '';
383
            } else {
384
                $platform_visible_courses = "  AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' )";
385
            }
386
        }
387
        $sqlGetSubCatList = "
388
                    SELECT t1.name,t1.code,t1.parent_id,t1.children_count,COUNT(DISTINCT t3.code) AS nbCourse
389
                    FROM $main_category_table t1
390
                    LEFT JOIN $main_category_table t2 ON t1.code=t2.parent_id
391
                    LEFT JOIN $main_course_table t3 ON (t3.category_code=t1.code $platform_visible_courses)
392
                    WHERE t1.parent_id ".(empty($category) ? "IS NULL" : "='$category'")."
393
                    GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count ORDER BY t1.tree_pos, t1.name";
394
395
396
        // Showing only the category of courses of the current access_url_id
397
        if (api_is_multiple_url_enabled()) {
398
            $url_access_id = api_get_current_access_url_id();
399 View Code Duplication
            if ($url_access_id != -1) {
400
                $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
401
                $sqlGetSubCatList   = "
402
                    SELECT t1.name,t1.code,t1.parent_id,t1.children_count,COUNT(DISTINCT t3.code) AS nbCourse
403
                    FROM $main_category_table t1
404
                    LEFT JOIN $main_category_table t2 ON t1.code=t2.parent_id
405
                    LEFT JOIN $main_course_table t3 ON (t3.category_code=t1.code $platform_visible_courses)
406
                    INNER JOIN $tbl_url_rel_course as url_rel_course
407
                        ON (url_rel_course.c_id = t3.id)
408
                    WHERE access_url_id = $url_access_id AND t1.parent_id ".(empty($category) ? "IS NULL" : "='$category'")."
409
                    GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count ORDER BY t1.tree_pos, t1.name";
410
            }
411
        }
412
413
        $resCats       = Database::query($sqlGetSubCatList);
414
        $thereIsSubCat = false;
415
        if (Database::num_rows($resCats) > 0) {
416
            $htmlListCat = Display::page_header(get_lang('CatList'));
417
            $htmlListCat .= '<ul>';
418
            while ($catLine = Database::fetch_array($resCats)) {
419
                if ($catLine['code'] != $category) {
420
                    $category_has_open_courses = $this->category_has_open_courses($catLine['code']);
421 View Code Duplication
                    if ($category_has_open_courses) {
422
                        // The category contains courses accessible to anonymous visitors.
423
                        $htmlListCat .= '<li>';
424
                        $htmlListCat .= '<a href="'.api_get_self(
425
                        ).'?category='.$catLine['code'].'">'.$catLine['name'].'</a>';
426
                        if (api_get_setting('show_number_of_courses') == 'true') {
427
                            $htmlListCat .= ' ('.$catLine['nbCourse'].' '.get_lang('Courses').')';
428
                        }
429
                        $htmlListCat .= "</li>";
430
                        $thereIsSubCat = true;
431
                    } elseif ($catLine['children_count'] > 0) {
432
                        // The category has children, subcategories.
433
                        $htmlListCat .= '<li>';
434
                        $htmlListCat .= '<a href="'.api_get_self(
435
                        ).'?category='.$catLine['code'].'">'.$catLine['name'].'</a>';
436
                        $htmlListCat .= "</li>";
437
                        $thereIsSubCat = true;
438
                    } elseif (api_get_setting('show_empty_course_categories') == 'true') {
439
                        /* End changed code to eliminate the (0 courses) after empty categories. */
440
                        $htmlListCat .= '<li>';
441
                        $htmlListCat .= $catLine['name'];
442
                        $htmlListCat .= "</li>";
443
                        $thereIsSubCat = true;
444
                    } // Else don't set thereIsSubCat to true to avoid printing things if not requested.
445
                } else {
446
                    $htmlTitre = '<p>';
447 View Code Duplication
                    if (api_get_setting('show_back_link_on_top_of_tree') == 'true') {
448
                        $htmlTitre .= '<a href="'.api_get_self().'">&lt;&lt; '.get_lang('BackToHomePage').'</a>';
449
                    }
450
                    if (!is_null($catLine['parent_id']) ||
451
                        (api_get_setting('show_back_link_on_top_of_tree') != 'true' &&
452
                        !is_null($catLine['code']))
453
                    ) {
454
                        $htmlTitre .= '<a href="'.api_get_self(
455
                        ).'?category='.$catLine['parent_id'].'">&lt;&lt; '.get_lang('Up').'</a>';
456
                    }
457
                    $htmlTitre .= "</p>";
458 View Code Duplication
                    if ($category != "" && !is_null($catLine['code'])) {
459
                        $htmlTitre .= '<h3>'.$catLine['name']."</h3>";
460
                    } else {
461
                        $htmlTitre .= '<h3>'.get_lang('Categories')."</h3>";
462
                    }
463
                }
464
            }
465
            $htmlListCat .= "</ul>";
466
        }
467
        $result .= $htmlTitre;
468
        if ($thereIsSubCat) {
469
            $result .= $htmlListCat;
470
        }
471
        while ($categoryName = Database::fetch_array($resCats)) {
472
            $result .= '<h3>'.$categoryName['name']."</h3>\n";
473
        }
474
        $numrows             = Database::num_rows($sql_result_courses);
475
        $courses_list_string = '';
476
        $courses_shown       = 0;
477
        if ($numrows > 0) {
478
479
            $courses_list_string .= Display::page_header(get_lang('CourseList'));
480
            $courses_list_string .= "<ul>";
481
482
            if (api_get_user_id()) {
483
                $courses_of_user = $this->get_courses_of_user(api_get_user_id());
484
            }
485
486
            foreach ($course_list as $course) {
487
                // $setting_show_also_closed_courses
488
                if (!$setting_show_also_closed_courses) {
489
                    // If we do not show the closed courses
490
                    // we only show the courses that are open to the world (to everybody)
491
                    // and the courses that are open to the platform (if the current user is a registered user.
492
                    if (($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) || ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD)) {
493
                        $courses_shown++;
494
                        $courses_list_string .= "<li>\n";
495
                        $courses_list_string .= '<a href="'.$web_course_path.$course['directory'].'/">'.$course['title'].'</a><br />';
496
                        $course_details = array();
497
                        if (api_get_setting('course.display_coursecode_in_courselist') ==
498
                            'true') {
499
                            $course_details[] = $course['visual_code'];
500
                        }
501
                        if (api_get_setting('course.display_teacher_in_courselist') ==
502
                            'true') {
503
                            $course_details[] = $course['tutor_name'];
504
                        }
505
                        if (api_get_setting('display.show_different_course_language') ==
506
                            'true' && $course['course_language'] != api_get_setting(
507
                                'language.platform_language'
508
                            )
509
                        ) {
510
                            $course_details[] = $course['course_language'];
511
                        }
512
                        $courses_list_string .= implode(' - ', $course_details);
513
                        $courses_list_string .= "</li>\n";
514
                    }
515
                } else {
516
                    // We DO show the closed courses.
517
                    // The course is accessible if (link to the course homepage):
518
                    // 1. the course is open to the world (doesn't matter if the user is logged in or not): $course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD);
519
                    // 2. the user is logged in and the course is open to the world or open to the platform: ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM);
520
                    // 3. the user is logged in and the user is subscribed to the course and the course visibility is not COURSE_VISIBILITY_CLOSED;
521
                    // 4. the user is logged in and the user is course admin of te course (regardless of the course visibility setting);
522
                    // 5. the user is the platform admin api_is_platform_admin().
523
                    //
524
                    $courses_shown++;
525
                    $courses_list_string .= "<li>\n";
526 View Code Duplication
                    if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
527
                        || ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
528
                        || ($user_identified && key_exists(
529
                            $course['code'],
530
                            $courses_of_user
531
                        ) && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
532
                        || $courses_of_user[$course['code']]['status'] == '1'
533
                        || api_is_platform_admin()
534
                    ) {
535
                        $courses_list_string .= '<a href="'.$web_course_path.$course['directory'].'/">';
536
                    }
537
                    $courses_list_string .= $course['title'];
538 View Code Duplication
                    if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
539
                        || ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
540
                        || ($user_identified && key_exists(
541
                            $course['code'],
542
                            $courses_of_user
543
                        ) && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
544
                        || $courses_of_user[$course['code']]['status'] == '1'
545
                        || api_is_platform_admin()
546
                    ) {
547
                        $courses_list_string .= '</a><br />';
548
                    }
549
                    $course_details = array();
550
                    if (api_get_setting('course.display_coursecode_in_courselist') == 'true') {
551
                        $course_details[] = $course['visual_code'];
552
                    }
553
                    if (api_get_setting('course.display_teacher_in_courselist') == 'true') {
554
                        $course_details[] = $course['tutor_name'];
555
                    }
556
                    if (api_get_setting(
557
                            'display.show_different_course_language'
558
                        ) == 'true' && $course['course_language'] != api_get_setting(
559
                            'language.platform_language'
560
                        )
561
                    ) {
562
                        $course_details[] = $course['course_language'];
563
                    }
564 View Code Duplication
                    if (api_get_setting(
565
                        'show_different_course_language'
566
                        ) == 'true' && $course['course_language'] != api_get_setting(
567
                            'language.platform_language'
568
                        )
569
                    ) {
570
                        $course_details[] = $course['course_language'];
571
                    }
572
573
                    $courses_list_string .= implode(' - ', $course_details);
574
                    // We display a subscription link if:
575
                    // 1. it is allowed to register for the course and if the course is not already in the courselist of the user and if the user is identiefied
576
                    // 2.
577
                    if ($user_identified && !array_key_exists($course['code'], $courses_of_user)) {
578
                        if ($course['subscribe'] == '1') {
579
                            $courses_list_string .= '<form action="main/auth/courses.php?action=subscribe&category='.Security::remove_XSS(
580
                                $_GET['category']
581
                            ).'" method="post">';
582
                            $courses_list_string .= '<input type="hidden" name="sec_token" value="'.$stok.'">';
583
                            $courses_list_string .= '<input type="hidden" name="subscribe" value="'.$course['code'].'" />';
584
                            $courses_list_string .= '<input type="image" name="unsub" src="'.api_get_path(WEB_IMG_PATH).'enroll.gif" alt="'.get_lang('Subscribe').'" />'.get_lang('Subscribe').'
585
                            </form>';
586
                        } else {
587
                            $courses_list_string .= '<br />'.get_lang('SubscribingNotAllowed');
588
                        }
589
                    }
590
                    $courses_list_string .= "</li>";
591
                } //end else
592
            } // end foreach
593
            $courses_list_string .= "</ul>";
594
        }
595
        if ($courses_shown > 0) {
596
            // Only display the list of courses and categories if there was more than
597
            // 0 courses visible to the world (we're in the anonymous list here).
598
            $result .= $courses_list_string;
599
        }
600 View Code Duplication
        if ($category != '') {
601
            $result .= '<p><a href="'.api_get_self().'"> '.Display :: return_icon('back.png', get_lang('BackToHomePage')).get_lang('BackToHomePage').'</a></p>';
602
        }
603
604
        return $result;
605
    }
606
607
    /**
608
     * @param int $user_id
609
     * @param string $filter
610
     * @param int $page
611
     *
612
     * @return bool
613
     */
614 View Code Duplication
    public function returnMyCourseCategories($user_id, $filter, $page)
615
    {
616
        if (empty($user_id)) {
617
            return false;
618
        }
619
        $loadDirs = api_get_setting('document.show_documents_preview') == 'true' ? true : false;
620
        $start    = ($page - 1) * $this->maxPerPage;
621
622
        $nbResults = (int)CourseManager::displayPersonalCourseCategories($user_id, $filter, $loadDirs, true);
623
624
        $html = CourseManager::displayPersonalCourseCategories(
625
            $user_id,
626
            $filter,
627
            $loadDirs,
628
            false,
629
            $start,
630
            $this->maxPerPage
631
        );
632
633
        $adapter    = new FixedAdapter($nbResults, array());
634
        $pagerfanta = new Pagerfanta($adapter);
635
        $pagerfanta->setMaxPerPage($this->maxPerPage); // 10 by default
636
        $pagerfanta->setCurrentPage($page); // 1 by default
637
638
        $this->app['pagerfanta.view.router.name']   = 'userportal';
639
        $this->app['pagerfanta.view.router.params'] = array(
640
            'filter' => $filter,
641
            'type'   => 'courses',
642
            'page'   => $page
643
        );
644
        $this->app['template']->assign('pagination', $pagerfanta);
645
646
        return $html;
647
648
    }
649
650 View Code Duplication
    function returnSpecialCourses($user_id, $filter, $page)
651
    {
652
        if (empty($user_id)) {
653
            return false;
654
        }
655
656
        $loadDirs = api_get_setting('document.show_documents_preview') == 'true' ? true : false;
657
        $start    = ($page - 1) * $this->maxPerPage;
658
659
        $nbResults = CourseManager::displaySpecialCourses($user_id, $filter, $loadDirs, true);
660
661
        $html = CourseManager::displaySpecialCourses($user_id, $filter, $loadDirs, false, $start, $this->maxPerPage);
662
        if (!empty($html)) {
663
664
            $adapter    = new FixedAdapter($nbResults, array());
665
            $pagerfanta = new Pagerfanta($adapter);
666
            $pagerfanta->setMaxPerPage($this->maxPerPage); // 10 by default
667
            $pagerfanta->setCurrentPage($page); // 1 by default
668
            $this->app['pagerfanta.view.router.name']   = 'userportal';
669
            $this->app['pagerfanta.view.router.params'] = array(
670
                'filter' => $filter,
671
                'type'   => 'courses',
672
                'page'   => $page
673
            );
674
            $this->app['template']->assign('pagination', $pagerfanta);
675
        }
676
677
        return $html;
678
    }
679
680
    /**
681
    * The most important function here, prints the session and course list (user_portal.php)
682
    *
683
    * @param int $user_id
684
    * @param string $filter
685
    * @param int $page
686
    * @return string HTML list of sessions and courses
687
    *
688
    */
689
    public function returnCourses($user_id, $filter, $page)
690
    {
691
        if (empty($user_id)) {
692
            return false;
693
        }
694
695
        $loadDirs = api_get_setting('document.show_documents_preview') == 'true' ? true : false;
696
        $start = ($page - 1) * $this->maxPerPage;
697
698
        $nbResults = CourseManager::displayCourses(
699
            $user_id,
700
            $filter,
701
            $loadDirs,
702
            true
703
        );
704
705
        $html = CourseManager::displayCourses(
706
            $user_id,
707
            $filter,
708
            $loadDirs,
709
            false,
710
            $start,
711
            $this->maxPerPage
712
        );
713
714
        if (!empty($html)) {
715
            $adapter    = new FixedAdapter($nbResults, array());
716
            $pagerfanta = new Pagerfanta($adapter);
717
            $pagerfanta->setMaxPerPage($this->maxPerPage); // 10 by default
718
            $pagerfanta->setCurrentPage($page); // 1 by default
719
720
            /*
721
            Original pagination construction
722
            $view = new TwitterBootstrapView();
723
            $routeGenerator = function($page) use ($app, $filter) {
724
                return $app['url_generator']->generate('userportal', array(
725
                    'filter' => $filter,
726
                    'type' => 'courses',
727
                    'page' => $page)
728
                );
729
            };
730
            $pagination = $view->render($pagerfanta, $routeGenerator, array(
731
                'proximity' => 3,
732
            ));
733
            */
734
            //Pagination using the pagerfanta silex service provider
735
            /*$this->app['pagerfanta.view.router.name']   = 'userportal';
736
            $this->app['pagerfanta.view.router.params'] = array(
737
                'filter' => $filter,
738
                'type'   => 'courses',
739
                'page'   => $page
740
            );
741
            $this->app['template']->assign('pagination', $pagerfanta);*/
742
            // {{ pagerfanta(my_pager, 'twitter_bootstrap3') }}
743
        }
744
745
        return $html;
746
    }
747
748
    public function returnSessionsCategories($user_id, $filter, $page)
749
    {
750
        if (empty($user_id)) {
751
            return false;
752
        }
753
754
        $load_history = (isset($filter) && $filter == 'history') ? true : false;
755
756
        $start = ($page - 1) * $this->maxPerPage;
757
758
        $nbResults = UserManager::getCategories($user_id, false, true, true);
759
        $session_categories = UserManager::getCategories(
760
            $user_id,
761
            false,
762
            false,
763
            true,
764
            $start,
765
            $this->maxPerPage
766
        );
767
768
        $html = null;
769
        //Showing history title
770
        if ($load_history) {
771
            $html .= Display::page_subheader(get_lang('HistoryTrainingSession'));
772
            if (empty($session_categories)) {
773
                $html .= get_lang('YouDoNotHaveAnySessionInItsHistory');
774
            }
775
        }
776
777
        $load_directories_preview = api_get_setting('document.show_documents_preview') == 'true' ? true : false;
778
        $sessions_with_category   = $html;
779
780
        if (isset($session_categories) && !empty($session_categories)) {
781
            foreach ($session_categories as $session_category) {
782
                $session_category_id = $session_category['session_category']['id'];
783
784
                // All sessions included in
785
                $count_courses_session = 0;
786
                $html_sessions = '';
787
                foreach ($session_category['sessions'] as $session) {
788
                    $session_id = $session['session_id'];
789
790
                    // Don't show empty sessions.
791
                    if (count($session['courses']) < 1) {
792
                        continue;
793
                    }
794
795
                    $html_courses_session = '';
796
                    $count                = 0;
797
                    foreach ($session['courses'] as $course) {
798
                        if (api_get_setting('session.hide_courses_in_sessions') == 'false') {
799
                            $html_courses_session .= CourseManager::get_logged_user_course_html($course, $session_id);
800
                        }
801
                        $count_courses_session++;
802
                        $count++;
803
                    }
804
805
                    $params = array();
806
                    if ($count > 0) {
807
                        $params['icon'] = Display::return_icon(
808
                            'window_list.png',
809
                            $session['session_name'],
810
                            array('id' => 'session_img_'.$session_id),
811
                            ICON_SIZE_LARGE
812
                        );
813
814
                        //Default session name
815
                        $session_link   = $session['session_name'];
816
                        $params['link'] = null;
817
818 View Code Duplication
                        if (api_get_setting('session.session_page_enabled') == 'true' && !api_is_drh()) {
819
                            //session name with link
820
                            $session_link = Display::tag(
821
                                'a',
822
                                $session['session_name'],
823
                                array('href' => api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id)
824
                            );
825
                            $params['link'] = api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id;
826
                        }
827
828
                        $params['title'] = $session_link;
829
830
                        $moved_status = \SessionManager::getSessionChangeUserReason(
831
                            $session['moved_status']
832
                        );
833
                        $moved_status = isset($moved_status) && !empty($moved_status) ? ' ('.$moved_status.')' : null;
834
835
                        $params['subtitle'] = isset($session['coach_info']) ? $session['coach_info']['complete_name'] : null.$moved_status;
836
                        $params['dates'] = \SessionManager::parseSessionDates(
837
                            $session
838
                        );
839
840 View Code Duplication
                        if (api_is_platform_admin()) {
841
                            $params['right_actions'] = '<a href="'.api_get_path(WEB_CODE_PATH).'session/resume_session.php?id_session='.$session_id.'">'.Display::return_icon(
842
                                'edit.png',
843
                                get_lang('Edit'),
844
                                array('align' => 'absmiddle'),
845
                                ICON_SIZE_SMALL
846
                            ).'</a>';
847
                        }
848
                        $html_sessions .= CourseManager::course_item_html($params, true).$html_courses_session;
849
                    }
850
                }
851
852
                if ($count_courses_session > 0) {
853
                    $params = array();
854
                    $params['icon'] = Display::return_icon(
855
                        'folder_blue.png',
856
                        $session_category['session_category']['name'],
857
                        array(),
858
                        ICON_SIZE_LARGE
859
                    );
860
861
                    if (api_is_platform_admin()) {
862
                        $params['right_actions'] = '<a href="'.api_get_path(
863
                            WEB_CODE_PATH
864
                        ).'admin/session_category_edit.php?&id='.$session_category['session_category']['id'].'">'.Display::return_icon(
865
                            'edit.png',
866
                            get_lang('Edit'),
867
                            array(),
868
                            ICON_SIZE_SMALL
869
                        ).'</a>';
870
                    }
871
872
                    $params['title'] = $session_category['session_category']['name'];
873
874
                    if (api_is_platform_admin()) {
875
                        $params['link'] = api_get_path(
876
                            WEB_CODE_PATH
877
                        ).'admin/session_category_edit.php?&id='.$session_category['session_category']['id'];
878
                    }
879
880
                    $session_category_start_date = $session_category['session_category']['date_start'];
881
                    $session_category_end_date   = $session_category['session_category']['date_end'];
882
883
                    if (!empty($session_category_start_date) && $session_category_start_date != '0000-00-00' && !empty($session_category_end_date) && $session_category_end_date != '0000-00-00') {
884
                        $params['subtitle'] = sprintf(
885
                            get_lang('FromDateXToDateY'),
886
                            $session_category['session_category']['date_start'],
887
                            $session_category['session_category']['date_end']
888
                        );
889
                    } else {
890
                        if (!empty($session_category_start_date) && $session_category_start_date != '0000-00-00') {
891
                            $params['subtitle'] = get_lang('From').' '.$session_category_start_date;
892
                        }
893
                        if (!empty($session_category_end_date) && $session_category_end_date != '0000-00-00') {
894
                            $params['subtitle'] = get_lang('Until').' '.$session_category_end_date;
895
                        }
896
                    }
897
                    $sessions_with_category .= CourseManager::course_item_parent(
898
                        CourseManager::course_item_html($params, true),
899
                        $html_sessions
900
                    );
901
                }
902
            }
903
904
            //Pagination
905
            $adapter    = new FixedAdapter($nbResults, array());
906
            $pagerfanta = new Pagerfanta($adapter);
907
            $pagerfanta->setMaxPerPage($this->maxPerPage); // 10 by default
908
            $pagerfanta->setCurrentPage($page); // 1 by default
909
910
            $this->app['pagerfanta.view.router.name']   = 'userportal';
911
            $this->app['pagerfanta.view.router.params'] = array(
912
                'filter' => $filter,
913
                'type'   => 'sessioncategories',
914
                'page'   => $page
915
            );
916
            $this->app['template']->assign('pagination', $pagerfanta);
917
        }
918
919
        return $sessions_with_category;
920
    }
921
922
    /**
923
     * @param int $user_id
924
     * @param string $filter current|history
925
     * @param int $page
926
     * @return bool|null|string
927
     */
928
    public function returnSessions($user_id, $filter, $page)
929
    {
930
        if (empty($user_id)) {
931
            return false;
932
        }
933
934
        $loadHistory = (isset($filter) && $filter == 'history') ? true : false;
935
936
        /*$app['session_menu'] = function ($app) use ($loadHistory) {
937
            $menu = $app['knp_menu.factory']->createItem(
938
                'root',
939
                array(
940
                    'childrenAttributes' => array(
941
                        'class'        => 'nav nav-tabs',
942
                        'currentClass' => 'active'
943
                    )
944
                )
945
            );
946
947
            $current = $menu->addChild(
948
                get_lang('Current'),
949
                array(
950
                    'route'           => 'userportal',
951
                    'routeParameters' => array(
952
                        'filter' => 'current',
953
                        'type'   => 'sessions'
954
                    )
955
                )
956
            );
957
            $history = $menu->addChild(
958
                get_lang('HistoryTrainingSession'),
959
                array(
960
                    'route'           => 'userportal',
961
                    'routeParameters' => array(
962
                        'filter' => 'history',
963
                        'type'   => 'sessions'
964
                    )
965
                )
966
            );
967
            //@todo use URIVoter
968
            if ($loadHistory) {
969
                $history->setCurrent(true);
970
            } else {
971
                $current->setCurrent(true);
972
            }
973
974
            return $menu;
975
        };*/
976
977
        //@todo move this in template
978
        //$app['knp_menu.menus'] = array('actions_menu' => 'session_menu');
979
980
        $start = ($page - 1) * $this->maxPerPage;
981
982
        if ($loadHistory) {
983
            // Load sessions in category in *history*.
984
            $nbResults = (int)UserManager::get_sessions_by_category(
985
                $user_id,
986
                true,
987
                true,
988
                true,
989
                null,
990
                null,
991
                'no_category'
992
            );
993
994
            $session_categories = UserManager::get_sessions_by_category(
995
                $user_id,
996
                true,
997
                false,
998
                true,
999
                $start,
1000
                $this->maxPerPage,
1001
                'no_category'
1002
            );
1003
        } else {
1004
            // Load sessions in category.
1005
            $nbResults = (int)UserManager::get_sessions_by_category(
1006
                $user_id,
1007
                false,
1008
                true,
1009
                false,
1010
                null,
1011
                null,
1012
                'no_category'
1013
            );
1014
1015
            $session_categories = UserManager::get_sessions_by_category(
1016
                $user_id,
1017
                false,
1018
                false,
1019
                false,
1020
                $start,
1021
                $this->maxPerPage,
1022
                'no_category'
1023
            );
1024
        }
1025
1026
        $html = null;
1027
1028
        // Showing history title
1029
        if ($loadHistory) {
1030
            // $html .= Display::page_subheader(get_lang('HistoryTrainingSession'));
1031
            if (empty($session_categories)) {
1032
                $html .= get_lang('YouDoNotHaveAnySessionInItsHistory');
1033
            }
1034
        }
1035
1036
        $load_directories_preview = api_get_setting('document.show_documents_preview') == 'true' ? true : false;
1037
        $sessions_with_no_category = $html;
1038
1039
        if (isset($session_categories) && !empty($session_categories)) {
1040
            foreach ($session_categories as $session_category) {
1041
                $session_category_id = $session_category['session_category']['id'];
1042
1043
                // Sessions does not belong to a session category
1044
                if ($session_category_id == 0) {
1045
1046
                    // Independent sessions
1047
                    if (isset($session_category['sessions'])) {
1048
                        foreach ($session_category['sessions'] as $session) {
1049
                            $session_id = $session['session_id'];
1050
1051
                            // Don't show empty sessions.
1052
                            if (count($session['courses']) < 1) {
1053
                                continue;
1054
                            }
1055
1056
                            // Courses inside the current session.
1057
                            $date_session_start = $session['access_start_date'];
1058
                            $date_session_end = $session['access_end_date'];
1059
                            $coachAccessStartDate = $session['coach_access_start_date'];
1060
                            $coachAccessEndDate = $session['coach_access_end_date'];
1061
1062
                            $session_now = time();
1063
                            $count_courses_session = 0;
1064
                            $count_courses_session = 0;
1065
1066
                            // Loop course content
1067
                            $html_courses_session = [];
1068
                            $atLeastOneCourseIsVisible = false;
1069
1070
                            foreach ($session['courses'] as $course) {
1071
                                $is_coach_course = api_is_coach($session_id, $course['real_id']);
1072
                                $allowed_time = 0;
1073
1074
                                // Read only and accessible
1075 View Code Duplication
                                if (api_get_setting('session.hide_courses_in_sessions') == 'false') {
1076
                                    $courseUserHtml = CourseManager::get_logged_user_course_html(
1077
                                        $course,
1078
                                        $session_id,
1079
                                        $load_directories_preview
1080
                                    );
1081
1082
                                    if (isset($courseUserHtml[1])) {
1083
                                        $course_session = $courseUserHtml[1];
1084
                                        $course_session['skill'] = isset($courseUserHtml['skill']) ? $courseUserHtml['skill'] : '';
1085
                                        $html_courses_session[] = $course_session;
1086
                                    }
1087
1088
                                }
1089
                                $count_courses_session++;
1090
                            }
1091
1092
                            if ($count_courses_session > 0) {
1093
                                $params = array();
1094
1095
                                $params['icon'] = Display::return_icon(
1096
                                    'window_list.png',
1097
                                    $session['session_name'],
1098
                                    array('id' => 'session_img_'.$session_id),
1099
                                    ICON_SIZE_LARGE
1100
                                );
1101
                                $params['is_session'] = true;
1102
                                //Default session name
1103
                                $session_link   = $session['session_name'];
1104
                                $params['link'] = null;
1105
1106 View Code Duplication
                                if (api_get_setting('session.session_page_enabled') == 'true' && !api_is_drh()) {
1107
                                    //session name with link
1108
                                    $session_link = Display::tag(
1109
                                        'a',
1110
                                        $session['session_name'],
1111
                                        array(
1112
                                            'href' => api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id
1113
                                        )
1114
                                    );
1115
                                    $params['link'] = api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id;
1116
                                }
1117
1118
                                $params['title'] = $session_link;
1119
1120
                                $moved_status = \SessionManager::getSessionChangeUserReason(
1121
                                    $session['moved_status']
1122
                                );
1123
                                $moved_status = isset($moved_status) && !empty($moved_status) ? ' ('.$moved_status.')' : null;
1124
1125
                                $params['subtitle'] = isset($session['coach_info']) ? $session['coach_info']['complete_name'] : null.$moved_status;
1126
                                //$params['dates'] = $session['date_message'];
1127
1128
                                $params['dates'] = \SessionManager::parseSessionDates(
1129
                                    $session
1130
                                );
1131
                                $params['right_actions'] = '';
1132 View Code Duplication
                                if (api_is_platform_admin()) {
1133
                                    $params['right_actions'] .=
1134
                                        Display::url(
1135
                                            Display::return_icon(
1136
                                                'edit.png',
1137
                                                get_lang('Edit'),
1138
                                                array('align' => 'absmiddle'),
1139
                                                ICON_SIZE_SMALL
1140
                                            ),
1141
                                            api_get_path(WEB_CODE_PATH).'session/resume_session.php?id_session='.$session_id
1142
                                        );
1143
                                }
1144
1145
                                if (api_get_setting('session.hide_courses_in_sessions') == 'false') {
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...
1146
                                    //    $params['extra'] .=  $html_courses_session;
1147
                                }
1148
                                $courseDataToString = CourseManager::parseCourseListData($html_courses_session);
1149
                                $sessions_with_no_category .= CourseManager::course_item_parent(
1150
                                    CourseManager::course_item_html($params, true),
1151
                                    $courseDataToString
1152
                                );
1153
                            }
1154
                        }
1155
                    }
1156
                }
1157
            }
1158
1159
            /*$adapter = new FixedAdapter($nbResults, array());
1160
            $pagerfanta = new Pagerfanta($adapter);
1161
            $pagerfanta->setMaxPerPage($this->maxPerPage); // 10 by default
1162
            $pagerfanta->setCurrentPage($page); // 1 by default
1163
1164
            $this->app['pagerfanta.view.router.name']   = 'userportal';
1165
            $this->app['pagerfanta.view.router.params'] = array(
1166
                'filter' => $filter,
1167
                'type'   => 'sessions',
1168
                'page'   => $page
1169
            );
1170
            $this->app['template']->assign('pagination', $pagerfanta);*/
1171
        }
1172
1173
        return $sessions_with_no_category;
1174
    }
1175
1176
    /**
1177
     * Shows a welcome message when the user doesn't have any content in
1178
     * the course list
1179
     * @param object A Template object used to declare variables usable in the given template
1180
     * @return void
1181
     */
1182
    public function return_welcome_to_course_block($tpl)
1183
    {
1184
        if (empty($tpl)) {
1185
            return false;
1186
        }
1187
        $count_courses = CourseManager::count_courses();
1188
1189
        $course_catalog_url = api_get_path(WEB_CODE_PATH).'auth/courses.php';
1190
        $course_list_url    = api_get_path(WEB_PATH).'user_portal.php';
1191
1192
        $tpl->assign('course_catalog_url', $course_catalog_url);
1193
        $tpl->assign('course_list_url', $course_list_url);
1194
        $tpl->assign('course_catalog_link', Display::url(get_lang('here'), $course_catalog_url));
1195
        $tpl->assign('course_list_link', Display::url(get_lang('here'), $course_list_url));
1196
        $tpl->assign('count_courses', $count_courses);
1197
        $tpl->assign('welcome_to_course_block', 1);
1198
    }
1199
1200
     /**
1201
     * @param array
1202
     */
1203
    public function returnNavigationLinks($items)
1204
    {
1205
        // Main navigation section.
1206
        // Tabs that are deactivated are added here.
1207
        if (!empty($items)) {
1208
            $content = '<ul class="nav nav-list">';
1209
            foreach ($items as $section => $navigation_info) {
1210
                $current = isset($GLOBALS['this_section']) && $section == $GLOBALS['this_section'] ? ' id="current"' : '';
1211
                $content .= '<li '.$current.'>';
1212
                $content .= '<a href="'.$navigation_info['url'].'" target="_self">'.$navigation_info['title'].'</a>';
1213
                $content .= '</li>';
1214
            }
1215
            $content .= '</ul>';
1216
            $this->show_right_block(get_lang('MainNavigation'), null, 'navigation_block', array('content' => $content));
0 ignored issues
show
Unused Code introduced by
The call to the method Chamilo\CoreBundle\Frame...ler::show_right_block() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
1217
        }
1218
    }
1219
}
1220