Passed
Push — 1.11.x ( edf83c...19744e )
by Julito
13:08 queued 12s
created

CoursesController::getCatalogSearchSettings()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

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