Completed
Push — master ( 1285bd...aa4c59 )
by Julito
12:22
created

CoursesController   F

Complexity

Total Complexity 63

Size/Duplication

Total Lines 634
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 339
dl 0
loc 634
rs 3.36
c 0
b 0
f 0
wmc 63

13 Methods

Rating   Name   Duplication   Size   Complexity  
A search_courses() 0 43 4
A getAlreadyRegisteredInSessionLabel() 0 9 1
B courses_categories() 0 64 9
A unsubscribe_user_from_course() 0 23 3
B getRegisteredInSessionButton() 0 94 7
A getSessionIcon() 0 7 1
A getTabList() 0 21 4
A sessionsListByCoursesTag() 0 31 5
F getFormattedSessionsBlock() 0 130 16
A sessionsListByName() 0 31 4
A sessionList() 0 41 5
A __construct() 0 5 1
A getLimitArray() 0 9 3

How to fix   Complexity   

Complex Class

Complex classes like CoursesController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use CoursesController, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
use Chamilo\CoreBundle\Entity\SequenceResource;
6
use Chamilo\CoreBundle\Entity\SessionRelCourse;
7
use Chamilo\CoreBundle\Entity\Tag;
8
use Chamilo\CoreBundle\Framework\Container;
9
use Chamilo\CoreBundle\Hook\HookResubscribe;
10
use Chamilo\CoreBundle\Repository\SequenceRepository;
11
12
/**
13
 * Class CoursesController.
14
 *
15
 * This file contains class used like controller,
16
 * it should be included inside a dispatcher file (e.g: index.php)
17
 *
18
 * @author Christian Fasanando <[email protected]> - BeezNest
19
 *
20
 * @package chamilo.auth
21
 */
22
class CoursesController
23
{
24
    private $toolname;
25
    private $view;
26
    private $model;
27
28
    /**
29
     * Constructor.
30
     */
31
    public function __construct()
32
    {
33
        $this->toolname = 'auth';
34
        $this->view = new View($this->toolname);
35
        $this->model = new Auth();
36
    }
37
38
    /**
39
     * It's used for listing courses with categories,
40
     * render to courses_categories view.
41
     *
42
     * @param string $action
43
     * @param string $category_code
44
     * @param string $message
45
     * @param string $error
46
     * @param string $content
47
     * @param array  $limit         will be used if $random_value is not set.
48
     *                              This array should contains 'start' and 'length' keys
49
     *
50
     * @internal param \action $string
51
     * @internal param \Category $string code (optional)
52
     */
53
    public function courses_categories(
54
        $action,
55
        $category_code = null,
56
        $message = '',
57
        $error = '',
58
        $content = null,
59
        $limit = []
60
    ) {
61
        $data = [];
62
        $listCategories = CoursesAndSessionsCatalog::getCourseCategoriesTree();
63
64
        $data['countCoursesInCategory'] = CourseCategory::countCoursesInCategory($category_code);
65
        if ($action === 'display_random_courses') {
66
            // Random value is used instead limit filter
67
            $data['browse_courses_in_category'] = CoursesAndSessionsCatalog::getCoursesInCategory(null, 12);
68
            $data['countCoursesInCategory'] = count($data['browse_courses_in_category']);
69
        } else {
70
            if (!isset($category_code)) {
71
                $category_code = $listCategories['ALL']['code']; // by default first category
72
            }
73
            $limit = isset($limit) ? $limit : self::getLimitArray();
74
            $listCourses = CoursesAndSessionsCatalog::getCoursesInCategory($category_code, null, $limit);
75
76
            $data['browse_courses_in_category'] = $listCourses;
77
        }
78
79
        $data['list_categories'] = $listCategories;
80
        $data['code'] = Security::remove_XSS($category_code);
81
82
        // getting all the courses to which the user is subscribed to
83
        $curr_user_id = api_get_user_id();
84
        $user_courses = $this->model->get_courses_of_user($curr_user_id);
85
        $user_coursecodes = [];
86
87
        // we need only the course codes as these will be used to match against the courses of the category
88
        if ($user_courses != '') {
89
            foreach ($user_courses as $key => $value) {
90
                $user_coursecodes[] = $value['code'];
91
            }
92
        }
93
94
        if (api_is_drh()) {
95
            $courses = CourseManager::get_courses_followed_by_drh(api_get_user_id());
96
            foreach ($courses as $course) {
97
                $user_coursecodes[] = $course['code'];
98
            }
99
        }
100
101
        $data['user_coursecodes'] = $user_coursecodes;
102
        $data['action'] = $action;
103
        $data['message'] = $message;
104
        $data['content'] = $content;
105
        $data['error'] = $error;
106
        $data['catalogShowCoursesSessions'] = 0;
107
        $showCoursesSessions = (int) api_get_setting('catalog_show_courses_sessions');
108
        if ($showCoursesSessions > 0) {
109
            $data['catalogShowCoursesSessions'] = $showCoursesSessions;
110
        }
111
112
        // render to the view
113
        $this->view->set_data($data);
114
        $this->view->set_layout('layout');
115
        $this->view->set_template('courses_categories');
116
        $this->view->render();
117
    }
118
119
    /**
120
     * @param string $search_term
121
     * @param string $message
122
     * @param string $error
123
     * @param string $content
124
     * @param array  $limit
125
     * @param bool   $justVisible Whether to search only in courses visibles in the catalogue
126
     */
127
    public function search_courses(
128
        $search_term,
129
        $message = '',
130
        $error = '',
131
        $content = null,
132
        $limit = [],
133
        $justVisible = false
134
    ) {
135
        $data = [];
136
        $limit = !empty($limit) ? $limit : self::getLimitArray();
137
        $browse_course_categories = CoursesAndSessionsCatalog::getCourseCategories();
138
        $data['countCoursesInCategory'] = CourseCategory::countCoursesInCategory('ALL', $search_term);
139
        $data['browse_courses_in_category'] = CoursesAndSessionsCatalog::search_courses(
140
            $search_term,
141
            $limit,
142
            $justVisible
143
        );
144
        $data['browse_course_categories'] = $browse_course_categories;
145
        $data['search_term'] = Security::remove_XSS($search_term); //filter before showing in template
146
147
        // getting all the courses to which the user is subscribed to
148
        $curr_user_id = api_get_user_id();
149
        $user_courses = $this->model->get_courses_of_user($curr_user_id);
150
        $user_coursecodes = [];
151
152
        // we need only the course codes as these will be used to match against the courses of the category
153
        if ($user_courses != '') {
154
            foreach ($user_courses as $value) {
155
                $user_coursecodes[] = $value['code'];
156
            }
157
        }
158
159
        $data['user_coursecodes'] = $user_coursecodes;
160
        $data['message'] = $message;
161
        $data['content'] = $content;
162
        $data['error'] = $error;
163
        $data['action'] = 'display_courses';
164
165
        // render to the view
166
        $this->view->set_data($data);
167
        $this->view->set_layout('catalog_layout');
168
        $this->view->set_template('courses_categories');
169
        $this->view->render();
170
    }
171
172
    /**
173
     * Unsubscribe user from a course
174
     * render to listing view.
175
     *
176
     * @param string $course_code
177
     * @param string $search_term
178
     * @param string $category_code
179
     */
180
    public function unsubscribe_user_from_course(
181
        $course_code,
182
        $search_term = null,
183
        $category_code = null
184
    ) {
185
        $result = $this->model->remove_user_from_course($course_code);
186
        $message = '';
187
        $error = '';
188
189
        if ($result) {
190
            Display::addFlash(
191
                Display::return_message(get_lang('You have been unsubscribed from this course'))
192
            );
193
        }
194
195
        if (!empty($search_term)) {
196
            CoursesAndSessionsCatalog::search_courses($search_term, $message, $error);
197
        } else {
198
            $this->courses_categories(
199
                'subcribe',
200
                $category_code,
201
                $message,
202
                $error
203
            );
204
        }
205
    }
206
207
    /**
208
     * Get a HTML button for subscribe to session.
209
     *
210
     * @param int    $sessionId         The session ID
211
     * @param string $sessionName       The session name
212
     * @param bool   $checkRequirements Optional.
213
     *                                  Whether the session has requirement. Default is false
214
     * @param bool   $includeText       Optional. Whether show the text in button
215
     * @param bool   $btnBing
216
     *
217
     * @return string The button HTML
218
     */
219
    public function getRegisteredInSessionButton(
220
        $sessionId,
221
        $sessionName,
222
        $checkRequirements = false,
223
        $includeText = false,
224
        $btnBing = false
225
    ) {
226
        $sessionId = (int) $sessionId;
227
        if ($btnBing) {
228
            $btnBing = 'btn-lg btn-block';
229
        } else {
230
            $btnBing = 'btn-sm';
231
        }
232
        if ($checkRequirements) {
233
            $url = api_get_path(WEB_AJAX_PATH);
234
            $url .= 'sequence.ajax.php?';
235
            $url .= http_build_query([
236
                'a' => 'get_requirements',
237
                'id' => $sessionId,
238
                'type' => SequenceResource::SESSION_TYPE,
239
            ]);
240
241
            return Display::toolbarButton(
242
                get_lang('Check requirements'),
243
                $url,
244
                'shield',
245
                'info',
246
                [
247
                    'class' => $btnBing.' ajax',
248
                    'data-title' => get_lang('Check requirements'),
249
                    'data-size' => 'md',
250
                    'title' => get_lang('Check requirements'),
251
                ],
252
                $includeText
253
            );
254
        }
255
256
        $catalogSessionAutoSubscriptionAllowed = false;
257
        if (api_get_setting('catalog_allow_session_auto_subscription') === 'true') {
258
            $catalogSessionAutoSubscriptionAllowed = true;
259
        }
260
261
        $url = api_get_path(WEB_CODE_PATH);
262
263
        if ($catalogSessionAutoSubscriptionAllowed) {
264
            $url .= 'auth/courses.php?';
265
            $url .= http_build_query([
266
                'action' => 'subscribe_to_session',
267
                'session_id' => $sessionId,
268
            ]);
269
270
            $result = Display::toolbarButton(
271
                get_lang('Subscribe'),
272
                $url,
273
                'pencil',
274
                'primary',
275
                [
276
                    'class' => $btnBing.' ajax',
277
                    'data-title' => get_lang('Are you sure to subscribe?'),
278
                    'data-size' => 'md',
279
                    'title' => get_lang('Subscribe'),
280
                ],
281
                $includeText
282
            );
283
        } else {
284
            $url .= 'inc/email_editor.php?';
285
            $url .= http_build_query([
286
                'action' => 'subscribe_me_to_session',
287
                'session' => Security::remove_XSS($sessionName),
288
            ]);
289
290
            $result = Display::toolbarButton(
291
                get_lang('Request subscription'),
292
                $url,
293
                'pencil',
294
                'primary',
295
                ['class' => $btnBing],
296
                $includeText
297
            );
298
        }
299
300
        $hook = Container::instantiateHook(HookResubscribe::class);
301
        if (!empty($hook)) {
302
            $hook->setEventData([
303
                'session_id' => $sessionId,
304
            ]);
305
            try {
306
                $hook->notifyResubscribe(HOOK_EVENT_TYPE_PRE);
307
            } catch (Exception $exception) {
308
                $result = $exception->getMessage();
309
            }
310
        }
311
312
        return $result;
313
    }
314
315
    /**
316
     * Generate a label if the user has been  registered in session.
317
     *
318
     * @return string The label
319
     */
320
    public function getAlreadyRegisteredInSessionLabel()
321
    {
322
        $icon = '<em class="fa fa-graduation-cap"></em>';
323
324
        return Display::div(
325
            $icon,
326
            [
327
                'class' => 'btn btn-default btn-sm registered',
328
                'title' => get_lang("Already registered to session"),
329
            ]
330
        );
331
    }
332
333
    /**
334
     * Get a icon for a session.
335
     *
336
     * @param string $sessionName The session name
337
     *
338
     * @return string The icon
339
     */
340
    public function getSessionIcon($sessionName)
341
    {
342
        return Display::return_icon(
343
            'window_list.png',
344
            $sessionName,
345
            null,
346
            ICON_SIZE_MEDIUM
347
        );
348
    }
349
350
    /**
351
     * Return Session catalog rendered view.
352
     *
353
     * @param string $action
354
     * @param string $nameTools
355
     * @param array  $limit
356
     */
357
    public function sessionList($action, $nameTools, $limit = [])
358
    {
359
        $date = isset($_POST['date']) ? $_POST['date'] : date('Y-m-d');
360
        $hiddenLinks = isset($_GET['hidden_links']) ? $_GET['hidden_links'] == 1 : false;
361
        $limit = isset($limit) ? $limit : self::getLimitArray();
362
363
        $countSessions = CoursesAndSessionsCatalog::browseSessions($date, [], false, true);
364
        $sessions = CoursesAndSessionsCatalog::browseSessions($date, $limit);
365
366
        $pageTotal = ceil($countSessions / $limit['length']);
367
        // Do NOT show pagination if only one page or less
368
        $pagination = $pageTotal > 1 ? CourseCategory::getCatalogPagination($limit['current'], $limit['length'], $pageTotal) : '';
369
        $sessionsBlocks = $this->getFormattedSessionsBlock($sessions);
370
371
        // Get session search catalogue URL
372
        $courseUrl = CourseCategory::getCourseCategoryUrl(
373
            1,
374
            $limit['length'],
375
            null,
376
            0,
377
            'subscribe'
378
        );
379
380
        $tpl = new Template();
381
        $tpl->assign('actions', self::getTabList(2));
382
        $tpl->assign('show_courses', CoursesAndSessionsCatalog::showCourses());
383
        $tpl->assign('show_sessions', CoursesAndSessionsCatalog::showSessions());
384
        $tpl->assign('show_tutor', api_get_setting('show_session_coach') === 'true');
385
        $tpl->assign('course_url', $courseUrl);
386
        $tpl->assign('catalog_pagination', $pagination);
387
        $tpl->assign('hidden_links', $hiddenLinks);
388
        $tpl->assign('search_token', Security::get_token());
389
        $tpl->assign('search_date', $date);
390
        $tpl->assign('web_session_courses_ajax_url', api_get_path(WEB_AJAX_PATH).'course.ajax.php');
391
        $tpl->assign('sessions', $sessionsBlocks);
392
        $tpl->assign('already_subscribed_label', $this->getAlreadyRegisteredInSessionLabel());
393
394
        $layout = $tpl->get_template('auth/session_catalog.html.twig');
395
        $content = $tpl->fetch($layout);
396
        $tpl->assign('content', $content);
397
        $tpl->display_one_col_template();
398
    }
399
400
    /**
401
     * Show the Session Catalogue with filtered session by course tags.
402
     *
403
     * @param array $limit Limit info
404
     */
405
    public function sessionsListByName(array $limit)
406
    {
407
        $keyword = isset($_POST['keyword']) ? $_POST['keyword'] : null;
408
        $hiddenLinks = isset($_GET['hidden_links']) ? (int) $_GET['hidden_links'] == 1 : false;
409
        $courseUrl = CourseCategory::getCourseCategoryUrl(
410
            1,
411
            $limit['length'],
412
            null,
413
            0,
414
            'subscribe'
415
        );
416
417
        $sessions = CoursesAndSessionsCatalog::getSessionsByName($keyword, $limit);
418
        $sessionsBlocks = $this->getFormattedSessionsBlock($sessions);
419
420
        $tpl = new Template();
421
        $tpl->assign('actions', self::getTabList(2));
422
        $tpl->assign('show_courses', CoursesAndSessionsCatalog::showCourses());
423
        $tpl->assign('show_sessions', CoursesAndSessionsCatalog::showSessions());
424
        $tpl->assign('show_tutor', api_get_setting('show_session_coach') === 'true' ? true : false);
425
        $tpl->assign('course_url', $courseUrl);
426
        $tpl->assign('already_subscribed_label', $this->getAlreadyRegisteredInSessionLabel());
427
        $tpl->assign('hidden_links', $hiddenLinks);
428
        $tpl->assign('search_token', Security::get_token());
429
        $tpl->assign('keyword', Security::remove_XSS($keyword));
430
        $tpl->assign('sessions', $sessionsBlocks);
431
432
         $layout = $tpl->get_template('auth/session_catalog.html.twig');
433
        $content = $tpl->fetch($layout);
434
        $tpl->assign('content', $content);
435
        $tpl->display_one_col_template();
436
    }
437
438
    /**
439
     * @param int $active
440
     *
441
     * @return string
442
     */
443
    public static function getTabList($active = 1)
444
    {
445
        $pageLength = isset($_GET['pageLength']) ? (int) $_GET['pageLength'] : CoursesAndSessionsCatalog::PAGE_LENGTH;
446
447
        $url = CourseCategory::getCourseCategoryUrl(1, $pageLength, null, 0, 'display_sessions');
448
        $headers = [];
449
        if (CoursesAndSessionsCatalog::showCourses()) {
450
            $headers[] =  [
451
                'url' => api_get_self(),
452
                'content' => get_lang('CourseManagement'),
453
            ];
454
        }
455
456
        if (CoursesAndSessionsCatalog::showSessions()) {
457
            $headers[] =  [
458
                'url' => $url,
459
                'content' => get_lang('SessionList'),
460
            ];
461
        }
462
463
        return Display::tabsOnlyLink($headers, $active);
464
    }
465
466
    /**
467
     * Show the Session Catalogue with filtered session by course tags.
468
     *
469
     * @param array $limit Limit info
470
     */
471
    public function sessionsListByCoursesTag(array $limit)
472
    {
473
        $searchTag = isset($_POST['search_tag']) ? $_POST['search_tag'] : null;
474
        $searchDate = isset($_POST['date']) ? $_POST['date'] : date('Y-m-d');
475
        $hiddenLinks = isset($_GET['hidden_links']) ? (int) $_GET['hidden_links'] == 1 : false;
476
        $courseUrl = CourseCategory::getCourseCategoryUrl(
477
            1,
478
            $limit['length'],
479
            null,
480
            0,
481
            'subscribe'
482
        );
483
484
        $sessions = CoursesAndSessionsCatalog::browseSessionsByTags($searchTag, $limit);
485
        $sessionsBlocks = $this->getFormattedSessionsBlock($sessions);
486
487
        $tpl = new Template();
488
        $tpl->assign('show_courses', CoursesAndSessionsCatalog::showCourses());
489
        $tpl->assign('show_sessions', CoursesAndSessionsCatalog::showSessions());
490
        $tpl->assign('show_tutor', api_get_setting('show_session_coach') === 'true' ? true : false);
491
        $tpl->assign('course_url', $courseUrl);
492
        $tpl->assign('already_subscribed_label', $this->getAlreadyRegisteredInSessionLabel());
493
        $tpl->assign('hidden_links', $hiddenLinks);
494
        $tpl->assign('search_token', Security::get_token());
495
        $tpl->assign('search_date', Security::remove_XSS($searchDate));
496
        $tpl->assign('search_tag', Security::remove_XSS($searchTag));
497
        $tpl->assign('sessions', $sessionsBlocks);
498
499
        $contentTemplate = $tpl->get_template('auth/session_catalog.tpl');
500
501
        $tpl->display($contentTemplate);
502
    }
503
504
    /**
505
     * @return array
506
     */
507
    public static function getLimitArray()
508
    {
509
        $pageCurrent = isset($_REQUEST['pageCurrent']) ? (int) $_GET['pageCurrent'] : 1;
510
        $pageLength = isset($_REQUEST['pageLength']) ? (int) $_GET['pageLength'] : CoursesAndSessionsCatalog::PAGE_LENGTH;
511
512
        return [
513
            'start' => ($pageCurrent - 1) * $pageLength,
514
            'current' => $pageCurrent,
515
            'length' => $pageLength,
516
        ];
517
    }
518
519
    /**
520
     * Get the formatted data for sessions block to be displayed on Session Catalog page.
521
     *
522
     * @param array $sessions The session list
523
     *
524
     * @return array
525
     */
526
    private function getFormattedSessionsBlock(array $sessions)
527
    {
528
        $extraFieldValue = new ExtraFieldValue('session');
529
        $userId = api_get_user_id();
530
        $sessionsBlocks = [];
531
        $entityManager = Database::getManager();
532
        $sessionRelCourseRepo = $entityManager->getRepository('ChamiloCoreBundle:SessionRelCourse');
533
        $extraFieldRepo = $entityManager->getRepository('ChamiloCoreBundle:ExtraField');
534
        $extraFieldRelTagRepo = $entityManager->getRepository('ChamiloCoreBundle:ExtraFieldRelTag');
535
536
        $tagsField = $extraFieldRepo->findOneBy([
537
            'extraFieldType' => Chamilo\CoreBundle\Entity\ExtraField::COURSE_FIELD_TYPE,
538
            'variable' => 'tags',
539
        ]);
540
541
        /** @var \Chamilo\CoreBundle\Entity\Session $session */
542
        foreach ($sessions as $session) {
543
            $sessionDates = SessionManager::parseSessionDates([
544
                'display_start_date' => $session->getDisplayStartDate(),
545
                'display_end_date' => $session->getDisplayEndDate(),
546
                'access_start_date' => $session->getAccessStartDate(),
547
                'access_end_date' => $session->getAccessEndDate(),
548
                'coach_access_start_date' => $session->getCoachAccessStartDate(),
549
                'coach_access_end_date' => $session->getCoachAccessEndDate(),
550
            ]);
551
552
            $imageField = $extraFieldValue->get_values_by_handler_and_field_variable(
553
                $session->getId(),
554
                'image'
555
            );
556
            $sessionCourseTags = [];
557
            if (!is_null($tagsField)) {
558
                $sessionRelCourses = $sessionRelCourseRepo->findBy([
559
                    'session' => $session,
560
                ]);
561
                /** @var SessionRelCourse $sessionRelCourse */
562
                foreach ($sessionRelCourses as $sessionRelCourse) {
563
                    $courseTags = $extraFieldRelTagRepo->getTags(
564
                        $tagsField,
565
                        $sessionRelCourse->getCourse()->getId()
566
                    );
567
                    /** @var Tag $tag */
568
                    foreach ($courseTags as $tag) {
569
                        $sessionCourseTags[] = $tag->getTag();
570
                    }
571
                }
572
            }
573
574
            if (!empty($sessionCourseTags)) {
575
                $sessionCourseTags = array_unique($sessionCourseTags);
576
            }
577
578
            /** @var SequenceRepository $repo */
579
            $repo = $entityManager->getRepository('ChamiloCoreBundle:SequenceResource');
580
            $sequences = $repo->getRequirementsAndDependenciesWithinSequences(
581
                $session->getId(),
582
                SequenceResource::SESSION_TYPE
583
            );
584
585
            $hasRequirements = false;
586
            foreach ($sequences['sequences'] as $sequence) {
587
                if (count($sequence['requirements']) === 0) {
588
                    continue;
589
                }
590
                $hasRequirements = true;
591
                break;
592
            }
593
            $cat = $session->getCategory();
594
            if (empty($cat)) {
595
                $cat = null;
596
                $catName = '';
597
            } else {
598
                $catName = $cat->getName();
599
            }
600
601
            $generalCoach = $session->getGeneralCoach();
602
            $coachId = $generalCoach ? $generalCoach->getId() : 0;
603
            $coachName = $generalCoach ? UserManager::formatUserFullName($session->getGeneralCoach()) : '';
604
605
            $actions = null;
606
            if (api_is_platform_admin()) {
607
                $actions = api_get_path(WEB_CODE_PATH).'session/resume_session.php?id_session='.$session->getId();
608
            }
609
610
            $plugin = \BuyCoursesPlugin::create();
611
            $isThisSessionOnSale = $plugin->getBuyCoursePluginPrice($session);
612
613
            $sessionsBlock = [
614
                'id' => $session->getId(),
615
                'name' => $session->getName(),
616
                'image' => isset($imageField['value']) ? $imageField['value'] : null,
617
                'nbr_courses' => $session->getNbrCourses(),
618
                'nbr_users' => $session->getNbrUsers(),
619
                'coach_id' => $coachId,
620
                'coach_url' => $generalCoach
621
                    ? api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=get_user_popup&user_id='.$coachId
622
                    : '',
623
                'coach_name' => $coachName,
624
                'coach_avatar' => UserManager::getUserPicture(
625
                    $coachId,
626
                    USER_IMAGE_SIZE_SMALL
627
                ),
628
                'is_subscribed' => SessionManager::isUserSubscribedAsStudent(
629
                    $session->getId(),
630
                    $userId
631
                ),
632
                'icon' => $this->getSessionIcon($session->getName()),
633
                'date' => $sessionDates['display'],
634
                'price' => !empty($isThisSessionOnSale['html']) ? $isThisSessionOnSale['html'] : '',
635
                'subscribe_button' => isset($isThisSessionOnSale['buy_button']) ? $isThisSessionOnSale['buy_button'] : $this->getRegisteredInSessionButton(
636
                    $session->getId(),
637
                    $session->getName(),
638
                    $hasRequirements
639
                ),
640
                'show_description' => $session->getShowDescription(),
641
                'description' => $session->getDescription(),
642
                'category' => $catName,
643
                'tags' => $sessionCourseTags,
644
                'edit_actions' => $actions,
645
                'duration' => SessionManager::getDayLeftInSession(
646
                    ['id' => $session->getId(), 'duration' => $session->getDuration()],
647
                    $userId
648
                ),
649
            ];
650
651
            $sessionsBlock = array_merge($sessionsBlock, $sequences);
652
            $sessionsBlocks[] = $sessionsBlock;
653
        }
654
655
        return $sessionsBlocks;
656
    }
657
}
658