Passed
Push — 1.11.x ( 020197...50bdbb )
by Julito
10:34
created

CoursesController   F

Complexity

Total Complexity 65

Size/Duplication

Total Lines 646
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 341
dl 0
loc 646
rs 3.2
c 0
b 0
f 0
wmc 65

14 Methods

Rating   Name   Duplication   Size   Complexity  
A search_courses() 0 43 4
B courses_categories() 0 64 9
A getAlreadyRegisteredInSessionLabel() 0 9 1
A unsubscribe_user_from_course() 0 23 3
A __construct() 0 6 1
A getSessionIcon() 0 7 1
B getRegisteredInSessionButton() 0 94 7
A getTabList() 0 21 4
A sessionsListByCoursesTag() 0 31 5
A getCatalogSearchSettings() 0 9 2
F getFormattedSessionsBlock() 0 130 16
A sessionsListByName() 0 31 4
A sessionList() 0 41 5
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\Repository\SequenceRepository;
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
        if ($btnBing) {
227
            $btnBing = 'btn-lg btn-block';
228
        } else {
229
            $btnBing = 'btn-sm';
230
        }
231
        if ($checkRequirements) {
232
            $url = api_get_path(WEB_AJAX_PATH);
233
            $url .= 'sequence.ajax.php?';
234
            $url .= http_build_query([
235
                'a' => 'get_requirements',
236
                'id' => $sessionId,
237
                'type' => SequenceResource::SESSION_TYPE,
238
            ]);
239
240
            return Display::toolbarButton(
241
                get_lang('CheckRequirements'),
242
                $url,
243
                'shield',
244
                'info',
245
                [
246
                    'class' => $btnBing.' ajax',
247
                    'data-title' => get_lang('CheckRequirements'),
248
                    'data-size' => 'md',
249
                    'title' => get_lang('CheckRequirements'),
250
                ],
251
                $includeText
252
            );
253
        }
254
255
        $catalogSessionAutoSubscriptionAllowed = false;
256
        if (api_get_setting('catalog_allow_session_auto_subscription') === 'true') {
257
            $catalogSessionAutoSubscriptionAllowed = true;
258
        }
259
260
        $url = api_get_path(WEB_CODE_PATH);
261
262
        if ($catalogSessionAutoSubscriptionAllowed) {
263
            $url .= 'auth/courses.php?';
264
            $url .= http_build_query([
265
                'action' => 'subscribe_to_session',
266
                'session_id' => $sessionId,
267
            ]);
268
269
            $result = Display::toolbarButton(
270
                get_lang('Subscribe'),
271
                $url,
272
                'pencil',
273
                'primary',
274
                [
275
                    'class' => $btnBing.' ajax',
276
                    'data-title' => get_lang('AreYouSureToSubscribe'),
277
                    'data-size' => 'md',
278
                    'title' => get_lang('Subscribe'),
279
                ],
280
                $includeText
281
            );
282
        } else {
283
            $url .= 'inc/email_editor.php?';
284
            $url .= http_build_query([
285
                'action' => 'subscribe_me_to_session',
286
                'session' => Security::remove_XSS($sessionName),
287
            ]);
288
289
            $result = Display::toolbarButton(
290
                get_lang('SubscribeToSessionRequest'),
291
                $url,
292
                'pencil',
293
                'primary',
294
                ['class' => $btnBing],
295
                $includeText
296
            );
297
        }
298
299
        $hook = HookResubscribe::create();
300
        if (!empty($hook)) {
301
            $hook->setEventData([
302
                'session_id' => $sessionId,
303
            ]);
304
            try {
305
                $hook->notifyResubscribe(HOOK_EVENT_TYPE_PRE);
306
            } catch (Exception $exception) {
307
                $result = $exception->getMessage();
308
            }
309
        }
310
311
        return $result;
312
    }
313
314
    /**
315
     * Generate a label if the user has been  registered in session.
316
     *
317
     * @return string The label
318
     */
319
    public function getAlreadyRegisteredInSessionLabel()
320
    {
321
        $icon = '<em class="fa fa-graduation-cap"></em>';
322
323
        return Display::div(
324
            $icon,
325
            [
326
                'class' => 'btn btn-default btn-sm registered',
327
                'title' => get_lang("AlreadyRegisteredToSession"),
328
            ]
329
        );
330
    }
331
332
    /**
333
     * Get a icon for a session.
334
     *
335
     * @param string $sessionName The session name
336
     *
337
     * @return string The icon
338
     */
339
    public function getSessionIcon($sessionName)
340
    {
341
        return Display::return_icon(
342
            'window_list.png',
343
            $sessionName,
344
            null,
345
            ICON_SIZE_MEDIUM
346
        );
347
    }
348
349
    /**
350
     * Return Session catalog rendered view.
351
     *
352
     * @param string $action
353
     * @param string $nameTools
354
     * @param array  $limit
355
     */
356
    public function sessionList($action, $nameTools, $limit = [])
357
    {
358
        $date = isset($_POST['date']) ? $_POST['date'] : date('Y-m-d');
359
        $hiddenLinks = isset($_GET['hidden_links']) ? $_GET['hidden_links'] == 1 : false;
360
        $limit = isset($limit) ? $limit : self::getLimitArray();
361
362
        $countSessions = CoursesAndSessionsCatalog::browseSessions($date, [], false, true);
363
        $sessions = CoursesAndSessionsCatalog::browseSessions($date, $limit);
364
365
        $pageTotal = ceil($countSessions / $limit['length']);
366
        // Do NOT show pagination if only one page or less
367
        $pagination = $pageTotal > 1 ? CourseCategory::getCatalogPagination($limit['current'], $limit['length'], $pageTotal) : '';
368
        $sessionsBlocks = $this->getFormattedSessionsBlock($sessions);
369
370
        // Get session search catalogue URL
371
        $courseUrl = CourseCategory::getCourseCategoryUrl(
372
            1,
373
            $limit['length'],
374
            null,
375
            0,
376
            'subscribe'
377
        );
378
379
        $tpl = new Template();
380
        $tpl->assign('actions', self::getTabList(2));
381
        $tpl->assign('show_courses', CoursesAndSessionsCatalog::showCourses());
382
        $tpl->assign('show_sessions', CoursesAndSessionsCatalog::showSessions());
383
        $tpl->assign('show_tutor', api_get_setting('show_session_coach') === 'true');
384
        $tpl->assign('course_url', $courseUrl);
385
        $tpl->assign('catalog_pagination', $pagination);
386
        $tpl->assign('hidden_links', $hiddenLinks);
387
        $tpl->assign('search_token', Security::get_token());
388
        $tpl->assign('search_date', $date);
389
        $tpl->assign('web_session_courses_ajax_url', api_get_path(WEB_AJAX_PATH).'course.ajax.php');
390
        $tpl->assign('sessions', $sessionsBlocks);
391
        $tpl->assign('already_subscribed_label', $this->getAlreadyRegisteredInSessionLabel());
392
        $tpl->assign('catalog_settings', self::getCatalogSearchSettings());
393
394
        $contentTemplate = $tpl->get_template('auth/session_catalog.tpl');
395
396
        $tpl->display($contentTemplate);
397
    }
398
399
    /**
400
     * Show the Session Catalogue with filtered session by course tags.
401
     *
402
     * @param array $limit Limit info
403
     */
404
    public function sessionsListByName(array $limit)
405
    {
406
        $keyword = isset($_POST['keyword']) ? $_POST['keyword'] : null;
407
        $hiddenLinks = isset($_GET['hidden_links']) ? (int) $_GET['hidden_links'] == 1 : false;
408
        $courseUrl = CourseCategory::getCourseCategoryUrl(
409
            1,
410
            $limit['length'],
411
            null,
412
            0,
413
            'subscribe'
414
        );
415
416
        $sessions = CoursesAndSessionsCatalog::getSessionsByName($keyword, $limit);
417
        $sessionsBlocks = $this->getFormattedSessionsBlock($sessions);
418
419
        $tpl = new Template();
420
        $tpl->assign('actions', self::getTabList(2));
421
        $tpl->assign('show_courses', CoursesAndSessionsCatalog::showCourses());
422
        $tpl->assign('show_sessions', CoursesAndSessionsCatalog::showSessions());
423
        $tpl->assign('show_tutor', api_get_setting('show_session_coach') === 'true' ? true : false);
424
        $tpl->assign('course_url', $courseUrl);
425
        $tpl->assign('already_subscribed_label', $this->getAlreadyRegisteredInSessionLabel());
426
        $tpl->assign('hidden_links', $hiddenLinks);
427
        $tpl->assign('search_token', Security::get_token());
428
        $tpl->assign('keyword', Security::remove_XSS($keyword));
429
        $tpl->assign('sessions', $sessionsBlocks);
430
        $tpl->assign('catalog_settings', self::getCatalogSearchSettings());
431
432
        $contentTemplate = $tpl->get_template('auth/session_catalog.tpl');
433
434
        $tpl->display($contentTemplate);
435
    }
436
437
    public static function getCatalogSearchSettings()
438
    {
439
        $settings = api_get_configuration_value('catalog_settings');
440
        if (empty($settings)) {
441
            // Default everything is visible
442
            $settings = ['sessions' => ['by_title' => true, 'by_date' => true, 'by_tag' => true]];
443
        }
444
445
        return $settings;
446
    }
447
448
    /**
449
     * @param int $active
450
     *
451
     * @return string
452
     */
453
    public static function getTabList($active = 1)
454
    {
455
        $pageLength = isset($_GET['pageLength']) ? (int) $_GET['pageLength'] : CoursesAndSessionsCatalog::PAGE_LENGTH;
456
457
        $url = CourseCategory::getCourseCategoryUrl(1, $pageLength, null, 0, 'display_sessions');
458
        $headers = [];
459
        if (CoursesAndSessionsCatalog::showCourses()) {
460
            $headers[] =  [
461
                'url' => api_get_self(),
462
                'content' => get_lang('CourseManagement'),
463
            ];
464
        }
465
466
        if (CoursesAndSessionsCatalog::showSessions()) {
467
            $headers[] =  [
468
                'url' => $url,
469
                'content' => get_lang('SessionList'),
470
            ];
471
        }
472
473
        return Display::tabsOnlyLink($headers, $active);
474
    }
475
476
    /**
477
     * Show the Session Catalogue with filtered session by course tags.
478
     *
479
     * @param array $limit Limit info
480
     */
481
    public function sessionsListByCoursesTag(array $limit)
482
    {
483
        $searchTag = isset($_POST['search_tag']) ? $_POST['search_tag'] : null;
484
        $searchDate = isset($_POST['date']) ? $_POST['date'] : date('Y-m-d');
485
        $hiddenLinks = isset($_GET['hidden_links']) ? (int) $_GET['hidden_links'] == 1 : false;
486
        $courseUrl = CourseCategory::getCourseCategoryUrl(
487
            1,
488
            $limit['length'],
489
            null,
490
            0,
491
            'subscribe'
492
        );
493
494
        $sessions = CoursesAndSessionsCatalog::browseSessionsByTags($searchTag, $limit);
495
        $sessionsBlocks = $this->getFormattedSessionsBlock($sessions);
496
497
        $tpl = new Template();
498
        $tpl->assign('show_courses', CoursesAndSessionsCatalog::showCourses());
499
        $tpl->assign('show_sessions', CoursesAndSessionsCatalog::showSessions());
500
        $tpl->assign('show_tutor', api_get_setting('show_session_coach') === 'true' ? true : false);
501
        $tpl->assign('course_url', $courseUrl);
502
        $tpl->assign('already_subscribed_label', $this->getAlreadyRegisteredInSessionLabel());
503
        $tpl->assign('hidden_links', $hiddenLinks);
504
        $tpl->assign('search_token', Security::get_token());
505
        $tpl->assign('search_date', Security::remove_XSS($searchDate));
506
        $tpl->assign('search_tag', Security::remove_XSS($searchTag));
507
        $tpl->assign('sessions', $sessionsBlocks);
508
509
        $contentTemplate = $tpl->get_template('auth/session_catalog.tpl');
510
511
        $tpl->display($contentTemplate);
512
    }
513
514
    /**
515
     * @return array
516
     */
517
    public static function getLimitArray()
518
    {
519
        $pageCurrent = isset($_REQUEST['pageCurrent']) ? (int) $_GET['pageCurrent'] : 1;
520
        $pageLength = isset($_REQUEST['pageLength']) ? (int) $_GET['pageLength'] : CoursesAndSessionsCatalog::PAGE_LENGTH;
521
522
        return [
523
            'start' => ($pageCurrent - 1) * $pageLength,
524
            'current' => $pageCurrent,
525
            'length' => $pageLength,
526
        ];
527
    }
528
529
    /**
530
     * Get the formatted data for sessions block to be displayed on Session Catalog page.
531
     *
532
     * @param array $sessions The session list
533
     *
534
     * @return array
535
     */
536
    private function getFormattedSessionsBlock(array $sessions)
537
    {
538
        $extraFieldValue = new ExtraFieldValue('session');
539
        $userId = api_get_user_id();
540
        $sessionsBlocks = [];
541
        $entityManager = Database::getManager();
542
        $sessionRelCourseRepo = $entityManager->getRepository('ChamiloCoreBundle:SessionRelCourse');
543
        $extraFieldRepo = $entityManager->getRepository('ChamiloCoreBundle:ExtraField');
544
        $extraFieldRelTagRepo = $entityManager->getRepository('ChamiloCoreBundle:ExtraFieldRelTag');
545
546
        $tagsField = $extraFieldRepo->findOneBy([
547
            'extraFieldType' => Chamilo\CoreBundle\Entity\ExtraField::COURSE_FIELD_TYPE,
548
            'variable' => 'tags',
549
        ]);
550
551
        /** @var \Chamilo\CoreBundle\Entity\Session $session */
552
        foreach ($sessions as $session) {
553
            $sessionDates = SessionManager::parseSessionDates([
554
                'display_start_date' => $session->getDisplayStartDate(),
555
                'display_end_date' => $session->getDisplayEndDate(),
556
                'access_start_date' => $session->getAccessStartDate(),
557
                'access_end_date' => $session->getAccessEndDate(),
558
                'coach_access_start_date' => $session->getCoachAccessStartDate(),
559
                'coach_access_end_date' => $session->getCoachAccessEndDate(),
560
            ]);
561
562
            $imageField = $extraFieldValue->get_values_by_handler_and_field_variable(
563
                $session->getId(),
564
                'image'
565
            );
566
            $sessionCourseTags = [];
567
            if (!is_null($tagsField)) {
568
                $sessionRelCourses = $sessionRelCourseRepo->findBy([
569
                    'session' => $session,
570
                ]);
571
                /** @var SessionRelCourse $sessionRelCourse */
572
                foreach ($sessionRelCourses as $sessionRelCourse) {
573
                    $courseTags = $extraFieldRelTagRepo->getTags(
574
                        $tagsField,
575
                        $sessionRelCourse->getCourse()->getId()
576
                    );
577
                    /** @var Tag $tag */
578
                    foreach ($courseTags as $tag) {
579
                        $sessionCourseTags[] = $tag->getTag();
580
                    }
581
                }
582
            }
583
584
            if (!empty($sessionCourseTags)) {
585
                $sessionCourseTags = array_unique($sessionCourseTags);
586
            }
587
588
            /** @var SequenceRepository $repo */
589
            $repo = $entityManager->getRepository('ChamiloCoreBundle:SequenceResource');
590
            $sequences = $repo->getRequirementsAndDependenciesWithinSequences(
591
                $session->getId(),
592
                SequenceResource::SESSION_TYPE
593
            );
594
595
            $hasRequirements = false;
596
            foreach ($sequences['sequences'] as $sequence) {
597
                if (count($sequence['requirements']) === 0) {
598
                    continue;
599
                }
600
                $hasRequirements = true;
601
                break;
602
            }
603
            $cat = $session->getCategory();
604
            if (empty($cat)) {
605
                $cat = null;
606
                $catName = '';
607
            } else {
608
                $catName = $cat->getName();
609
            }
610
611
            $generalCoach = $session->getGeneralCoach();
612
            $coachId = $generalCoach ? $generalCoach->getId() : 0;
613
            $coachName = $generalCoach ? UserManager::formatUserFullName($session->getGeneralCoach()) : '';
614
615
            $actions = null;
616
            if (api_is_platform_admin()) {
617
                $actions = api_get_path(WEB_CODE_PATH).'session/resume_session.php?id_session='.$session->getId();
618
            }
619
620
            $plugin = \BuyCoursesPlugin::create();
621
            $isThisSessionOnSale = $plugin->getBuyCoursePluginPrice($session);
622
623
            $sessionsBlock = [
624
                'id' => $session->getId(),
625
                'name' => $session->getName(),
626
                'image' => isset($imageField['value']) ? $imageField['value'] : null,
627
                'nbr_courses' => $session->getNbrCourses(),
628
                'nbr_users' => $session->getNbrUsers(),
629
                'coach_id' => $coachId,
630
                'coach_url' => $generalCoach
631
                    ? api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=get_user_popup&user_id='.$coachId
632
                    : '',
633
                'coach_name' => $coachName,
634
                'coach_avatar' => UserManager::getUserPicture(
635
                    $coachId,
636
                    USER_IMAGE_SIZE_SMALL
637
                ),
638
                'is_subscribed' => SessionManager::isUserSubscribedAsStudent(
639
                    $session->getId(),
640
                    $userId
641
                ),
642
                'icon' => $this->getSessionIcon($session->getName()),
643
                'date' => $sessionDates['display'],
644
                'price' => !empty($isThisSessionOnSale['html']) ? $isThisSessionOnSale['html'] : '',
645
                'subscribe_button' => isset($isThisSessionOnSale['buy_button']) ? $isThisSessionOnSale['buy_button'] : $this->getRegisteredInSessionButton(
646
                    $session->getId(),
647
                    $session->getName(),
648
                    $hasRequirements
649
                ),
650
                'show_description' => $session->getShowDescription(),
651
                'description' => $session->getDescription(),
652
                'category' => $catName,
653
                'tags' => $sessionCourseTags,
654
                'edit_actions' => $actions,
655
                'duration' => SessionManager::getDayLeftInSession(
656
                    ['id' => $session->getId(), 'duration' => $session->getDuration()],
657
                    $userId
658
                ),
659
            ];
660
661
            $sessionsBlock = array_merge($sessionsBlock, $sequences);
662
            $sessionsBlocks[] = $sessionsBlock;
663
        }
664
665
        return $sessionsBlocks;
666
    }
667
}
668