Passed
Push — master ( 6d3a7a...482b77 )
by Julito
12:08 queued 02:23
created

CoursesController::getRequirements()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 18
nc 1
nop 4
dl 0
loc 27
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
use Chamilo\CoreBundle\Repository\SequenceResourceRepository;
6
use Chamilo\CoreBundle\Entity\SequenceResource;
7
use Chamilo\CoreBundle\Entity\SessionRelCourse;
8
use Chamilo\CoreBundle\Entity\Tag;
9
use Chamilo\CoreBundle\Framework\Container;
10
use Chamilo\CoreBundle\Hook\HookResubscribe;
11
use Chamilo\CoreBundle\Repository\SequenceRepository;
12
13
/**
14
 * Class CoursesController.
15
 *
16
 * This file contains class used like controller,
17
 * it should be included inside a dispatcher file (e.g: index.php)
18
 *
19
 * @author Christian Fasanando <[email protected]> - BeezNest
20
 */
21
class CoursesController
22
{
23
    private $toolname;
24
    private $view;
25
    private $model;
26
27
    /**
28
     * Constructor.
29
     */
30
    public function __construct()
31
    {
32
        $this->toolname = 'auth';
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 ('display_random_courses' === $action) {
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('You have been unsubscribed from this course'))
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 ('true' === api_get_setting('catalog_allow_session_auto_subscription')) {
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('Are you sure to subscribe?'),
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('Request subscription'),
273
                $url,
274
                'pencil',
275
                'primary',
276
                ['class' => $btnBing],
277
                $includeText
278
            );
279
        }
280
281
        $hook = Container::instantiateHook(HookResubscribe::class);
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("Already registered to session"),
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']) ? 1 == $_GET['hidden_links'] : 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', 'true' === api_get_setting('show_session_coach'));
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
        $layout = $tpl->get_template('auth/session_catalog.html.twig');
405
        $content = $tpl->fetch($layout);
406
        $tpl->assign('content', $content);
407
        $tpl->display_one_col_template();
408
    }
409
410
    /**
411
     * Show the Session Catalogue with filtered session by course tags.
412
     *
413
     * @param array $limit Limit info
414
     */
415
    public function sessionsListByName(array $limit)
416
    {
417
        $keyword = isset($_POST['keyword']) ? $_POST['keyword'] : null;
418
        $hiddenLinks = isset($_GET['hidden_links']) ? 1 == (int) $_GET['hidden_links'] : false;
419
        $courseUrl = CourseCategory::getCourseCategoryUrl(
420
            1,
421
            $limit['length'],
422
            null,
423
            0,
424
            'subscribe'
425
        );
426
427
        $sessions = CoursesAndSessionsCatalog::getSessionsByName($keyword, $limit);
428
        $sessionsBlocks = $this->getFormattedSessionsBlock($sessions);
429
430
        $tpl = new Template();
431
        $tpl->assign('actions', self::getTabList(2));
432
        $tpl->assign('show_courses', CoursesAndSessionsCatalog::showCourses());
433
        $tpl->assign('show_sessions', CoursesAndSessionsCatalog::showSessions());
434
        $tpl->assign('show_tutor', 'true' === api_get_setting('show_session_coach') ? true : false);
435
        $tpl->assign('course_url', $courseUrl);
436
        $tpl->assign('already_subscribed_label', $this->getAlreadyRegisteredInSessionLabel());
437
        $tpl->assign('hidden_links', $hiddenLinks);
438
        $tpl->assign('search_token', Security::get_token());
439
        $tpl->assign('keyword', Security::remove_XSS($keyword));
440
        $tpl->assign('sessions', $sessionsBlocks);
441
        $tpl->assign('catalog_settings', self::getCatalogSearchSettings());
442
443
        $layout = $tpl->get_template('auth/session_catalog.html.twig');
444
        $content = $tpl->fetch($layout);
445
        $tpl->assign('content', $content);
446
        $tpl->display_one_col_template();
447
    }
448
449
    public static function getCatalogSearchSettings()
450
    {
451
        $settings = api_get_configuration_value('catalog_settings');
452
        if (empty($settings)) {
453
            // Default everything is visible
454
            $settings = [
455
                'sessions' => [
456
                    'by_title' => true,
457
                    'by_date' => true,
458
                    'by_tag' => true,
459
                    'show_session_info' => true,
460
                    'show_session_date' => true,
461
                ],
462
            ];
463
        }
464
465
        return $settings;
466
    }
467
468
    /**
469
     * @param int $active
470
     *
471
     * @return string
472
     */
473
    public static function getTabList($active = 1)
474
    {
475
        $pageLength = isset($_GET['pageLength']) ? (int) $_GET['pageLength'] : CoursesAndSessionsCatalog::PAGE_LENGTH;
476
477
        $url = CourseCategory::getCourseCategoryUrl(1, $pageLength, null, 0, 'display_sessions');
478
        $headers = [];
479
        if (CoursesAndSessionsCatalog::showCourses()) {
480
            $headers[] = [
481
                'url' => api_get_self(),
482
                'content' => get_lang('CourseManagement'),
483
            ];
484
        }
485
486
        if (CoursesAndSessionsCatalog::showSessions()) {
487
            $headers[] = [
488
                'url' => $url,
489
                'content' => get_lang('SessionList'),
490
            ];
491
        }
492
493
        return Display::tabsOnlyLink($headers, $active);
494
    }
495
496
    /**
497
     * Show the Session Catalogue with filtered session by course tags.
498
     *
499
     * @param array $limit Limit info
500
     */
501
    public function sessionsListByCoursesTag(array $limit)
502
    {
503
        $searchTag = isset($_POST['search_tag']) ? $_POST['search_tag'] : null;
504
        $searchDate = isset($_POST['date']) ? $_POST['date'] : date('Y-m-d');
505
        $hiddenLinks = isset($_GET['hidden_links']) ? 1 == (int) $_GET['hidden_links'] : false;
506
        $courseUrl = CourseCategory::getCourseCategoryUrl(
507
            1,
508
            $limit['length'],
509
            null,
510
            0,
511
            'subscribe'
512
        );
513
514
        $sessions = CoursesAndSessionsCatalog::browseSessionsByTags($searchTag, $limit);
515
        $sessionsBlocks = $this->getFormattedSessionsBlock($sessions);
516
517
        $tpl = new Template();
518
        $tpl->assign('show_courses', CoursesAndSessionsCatalog::showCourses());
519
        $tpl->assign('show_sessions', CoursesAndSessionsCatalog::showSessions());
520
        $tpl->assign('show_tutor', 'true' === api_get_setting('show_session_coach') ? true : false);
521
        $tpl->assign('course_url', $courseUrl);
522
        $tpl->assign('already_subscribed_label', $this->getAlreadyRegisteredInSessionLabel());
523
        $tpl->assign('hidden_links', $hiddenLinks);
524
        $tpl->assign('search_token', Security::get_token());
525
        $tpl->assign('search_date', Security::remove_XSS($searchDate));
526
        $tpl->assign('search_tag', Security::remove_XSS($searchTag));
527
        $tpl->assign('sessions', $sessionsBlocks);
528
529
        $contentTemplate = $tpl->get_template('auth/session_catalog.tpl');
530
531
        $tpl->display($contentTemplate);
532
    }
533
534
    /**
535
     * @return array
536
     */
537
    public static function getLimitArray()
538
    {
539
        $pageCurrent = isset($_REQUEST['pageCurrent']) ? (int) $_GET['pageCurrent'] : 1;
540
        $pageLength = isset($_REQUEST['pageLength']) ? (int) $_GET['pageLength'] : CoursesAndSessionsCatalog::PAGE_LENGTH;
541
542
        return [
543
            'start' => ($pageCurrent - 1) * $pageLength,
544
            'current' => $pageCurrent,
545
            'length' => $pageLength,
546
        ];
547
    }
548
549
    /**
550
     * Get the formatted data for sessions block to be displayed on Session Catalog page.
551
     *
552
     * @param array $sessions The session list
553
     *
554
     * @return array
555
     */
556
    private function getFormattedSessionsBlock(array $sessions)
557
    {
558
        $extraFieldValue = new ExtraFieldValue('session');
559
        $userId = api_get_user_id();
560
        $sessionsBlocks = [];
561
        $entityManager = Database::getManager();
562
        $sessionRelCourseRepo = $entityManager->getRepository('ChamiloCoreBundle:SessionRelCourse');
563
        $extraFieldRepo = $entityManager->getRepository('ChamiloCoreBundle:ExtraField');
564
        $extraFieldRelTagRepo = $entityManager->getRepository('ChamiloCoreBundle:ExtraFieldRelTag');
565
566
        $tagsField = $extraFieldRepo->findOneBy([
567
            'extraFieldType' => Chamilo\CoreBundle\Entity\ExtraField::COURSE_FIELD_TYPE,
568
            'variable' => 'tags',
569
        ]);
570
571
        /** @var \Chamilo\CoreBundle\Entity\Session $session */
572
        foreach ($sessions as $session) {
573
            $sessionDates = SessionManager::parseSessionDates([
574
                'display_start_date' => $session->getDisplayStartDate(),
575
                'display_end_date' => $session->getDisplayEndDate(),
576
                'access_start_date' => $session->getAccessStartDate(),
577
                'access_end_date' => $session->getAccessEndDate(),
578
                'coach_access_start_date' => $session->getCoachAccessStartDate(),
579
                'coach_access_end_date' => $session->getCoachAccessEndDate(),
580
            ]);
581
582
            $imageField = $extraFieldValue->get_values_by_handler_and_field_variable(
583
                $session->getId(),
584
                'image'
585
            );
586
            $sessionCourseTags = [];
587
            if (!is_null($tagsField)) {
588
                $sessionRelCourses = $sessionRelCourseRepo->findBy([
589
                    'session' => $session,
590
                ]);
591
                /** @var SessionRelCourse $sessionRelCourse */
592
                foreach ($sessionRelCourses as $sessionRelCourse) {
593
                    $courseTags = $extraFieldRelTagRepo->getTags(
594
                        $tagsField,
595
                        $sessionRelCourse->getCourse()->getId()
596
                    );
597
                    /** @var Tag $tag */
598
                    foreach ($courseTags as $tag) {
599
                        $sessionCourseTags[] = $tag->getTag();
600
                    }
601
                }
602
            }
603
604
            if (!empty($sessionCourseTags)) {
605
                $sessionCourseTags = array_unique($sessionCourseTags);
606
            }
607
608
            /** @var SequenceRepository $repo */
609
            $repo = $entityManager->getRepository('ChamiloCoreBundle:SequenceResource');
610
            $sequences = $repo->getRequirementsAndDependenciesWithinSequences(
611
                $session->getId(),
612
                SequenceResource::SESSION_TYPE
613
            );
614
615
            $hasRequirements = false;
616
            foreach ($sequences as $sequence) {
617
                if (count($sequence['requirements']) === 0) {
618
                    continue;
619
                }
620
                $hasRequirements = true;
621
                break;
622
            }
623
            $cat = $session->getCategory();
624
            if (empty($cat)) {
625
                $cat = null;
626
                $catName = '';
627
            } else {
628
                $catName = $cat->getName();
629
            }
630
631
            $generalCoach = $session->getGeneralCoach();
632
            $coachId = $generalCoach ? $generalCoach->getId() : 0;
633
            $coachName = $generalCoach ? UserManager::formatUserFullName($session->getGeneralCoach()) : '';
634
635
            $actions = null;
636
            if (api_is_platform_admin()) {
637
                $actions = api_get_path(WEB_CODE_PATH).'session/resume_session.php?id_session='.$session->getId();
638
            }
639
640
            $plugin = \BuyCoursesPlugin::create();
641
            $isThisSessionOnSale = $plugin->getBuyCoursePluginPrice($session);
642
643
            $sessionsBlock = [
644
                'id' => $session->getId(),
645
                'name' => $session->getName(),
646
                'image' => isset($imageField['value']) ? $imageField['value'] : null,
647
                'nbr_courses' => $session->getNbrCourses(),
648
                'nbr_users' => $session->getNbrUsers(),
649
                'coach_id' => $coachId,
650
                'coach_url' => $generalCoach
651
                    ? api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=get_user_popup&user_id='.$coachId
652
                    : '',
653
                'coach_name' => $coachName,
654
                'coach_avatar' => UserManager::getUserPicture(
655
                    $coachId,
656
                    USER_IMAGE_SIZE_SMALL
657
                ),
658
                'is_subscribed' => SessionManager::isUserSubscribedAsStudent(
659
                    $session->getId(),
660
                    $userId
661
                ),
662
                'icon' => $this->getSessionIcon($session->getName()),
663
                'date' => $sessionDates['display'],
664
                'price' => !empty($isThisSessionOnSale['html']) ? $isThisSessionOnSale['html'] : '',
665
                'subscribe_button' => isset($isThisSessionOnSale['buy_button']) ? $isThisSessionOnSale['buy_button'] : $this->getRegisteredInSessionButton(
666
                    $session->getId(),
667
                    $session->getName(),
668
                    $hasRequirements
669
                ),
670
                'show_description' => $session->getShowDescription(),
671
                'description' => $session->getDescription(),
672
                'category' => $catName,
673
                'tags' => $sessionCourseTags,
674
                'edit_actions' => $actions,
675
                'duration' => SessionManager::getDayLeftInSession(
676
                    ['id' => $session->getId(), 'duration' => $session->getDuration()],
677
                    $userId
678
                ),
679
            ];
680
681
            $sessionsBlocks[] = array_merge($sessionsBlock, $sequences);
682
        }
683
684
        return $sessionsBlocks;
685
    }
686
}
687