| Conditions | 151 |
| Paths | > 20000 |
| Total Lines | 819 |
| Code Lines | 536 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 1597 | public function returnCoursesAndSessions( |
||
| 1598 | $user_id, |
||
| 1599 | $showSessions = true, |
||
| 1600 | $categoryCodeFilter = '', |
||
| 1601 | $useUserLanguageFilterIfAvailable = true, |
||
| 1602 | $loadHistory = false |
||
| 1603 | ) { |
||
| 1604 | $gameModeIsActive = api_get_setting('gamification_mode'); |
||
| 1605 | $viewGridCourses = api_get_configuration_value('view_grid_courses'); |
||
| 1606 | $showSimpleSessionInfo = api_get_configuration_value('show_simple_session_info'); |
||
| 1607 | $coursesWithoutCategoryTemplate = '/user_portal/classic_courses_without_category.tpl'; |
||
| 1608 | $coursesWithCategoryTemplate = '/user_portal/classic_courses_with_category.tpl'; |
||
| 1609 | $showAllSessions = api_get_configuration_value('show_all_sessions_on_my_course_page') === true; |
||
| 1610 | |||
| 1611 | if ($loadHistory) { |
||
| 1612 | // Load sessions in category in *history* |
||
| 1613 | $session_categories = UserManager::get_sessions_by_category($user_id, true); |
||
| 1614 | } else { |
||
| 1615 | // Load sessions in category |
||
| 1616 | $session_categories = UserManager::get_sessions_by_category($user_id, false); |
||
| 1617 | } |
||
| 1618 | |||
| 1619 | $sessionCount = 0; |
||
| 1620 | $courseCount = 0; |
||
| 1621 | |||
| 1622 | // Student info code check (shows student progress information on |
||
| 1623 | // courses list |
||
| 1624 | $studentInfo = api_get_configuration_value('course_student_info'); |
||
| 1625 | |||
| 1626 | $studentInfoProgress = !empty($studentInfo['progress']) && $studentInfo['progress'] === true; |
||
| 1627 | $studentInfoScore = !empty($studentInfo['score']) && $studentInfo['score'] === true; |
||
| 1628 | $studentInfoCertificate = !empty($studentInfo['certificate']) && $studentInfo['certificate'] === true; |
||
| 1629 | $courseCompleteList = []; |
||
| 1630 | $coursesInCategoryCount = 0; |
||
| 1631 | $coursesNotInCategoryCount = 0; |
||
| 1632 | $listCourse = ''; |
||
| 1633 | $specialCourseList = ''; |
||
| 1634 | |||
| 1635 | // If we're not in the history view... |
||
| 1636 | if ($loadHistory === false) { |
||
| 1637 | // Display special courses. |
||
| 1638 | $specialCourses = CourseManager::returnSpecialCourses( |
||
| 1639 | $user_id, |
||
| 1640 | $this->load_directories_preview, |
||
| 1641 | $useUserLanguageFilterIfAvailable |
||
| 1642 | ); |
||
| 1643 | |||
| 1644 | // Display courses. |
||
| 1645 | $courses = CourseManager::returnCourses( |
||
| 1646 | $user_id, |
||
| 1647 | $this->load_directories_preview, |
||
| 1648 | $useUserLanguageFilterIfAvailable |
||
| 1649 | ); |
||
| 1650 | |||
| 1651 | // Course option (show student progress) |
||
| 1652 | // This code will add new variables (Progress, Score, Certificate) |
||
| 1653 | if ($studentInfoProgress || $studentInfoScore || $studentInfoCertificate) { |
||
| 1654 | if (!empty($specialCourses)) { |
||
| 1655 | foreach ($specialCourses as $key => $specialCourseInfo) { |
||
| 1656 | if ($studentInfoProgress) { |
||
| 1657 | $progress = Tracking::get_avg_student_progress( |
||
| 1658 | $user_id, |
||
| 1659 | $specialCourseInfo['course_code'] |
||
| 1660 | ); |
||
| 1661 | $specialCourses[$key]['student_info']['progress'] = $progress === false ? null : $progress; |
||
| 1662 | } |
||
| 1663 | |||
| 1664 | if ($studentInfoScore) { |
||
| 1665 | $percentage_score = Tracking::get_avg_student_score( |
||
| 1666 | $user_id, |
||
| 1667 | $specialCourseInfo['course_code'], |
||
| 1668 | [] |
||
| 1669 | ); |
||
| 1670 | $specialCourses[$key]['student_info']['score'] = $percentage_score; |
||
| 1671 | } |
||
| 1672 | |||
| 1673 | if ($studentInfoCertificate) { |
||
| 1674 | $category = Category::load( |
||
| 1675 | null, |
||
| 1676 | null, |
||
| 1677 | $specialCourseInfo['course_code'], |
||
| 1678 | null, |
||
| 1679 | null, |
||
| 1680 | null |
||
| 1681 | ); |
||
| 1682 | $specialCourses[$key]['student_info']['certificate'] = null; |
||
| 1683 | if (isset($category[0])) { |
||
| 1684 | if ($category[0]->is_certificate_available($user_id)) { |
||
| 1685 | $specialCourses[$key]['student_info']['certificate'] = Display::label( |
||
| 1686 | get_lang('Yes'), |
||
| 1687 | 'success' |
||
| 1688 | ); |
||
| 1689 | } else { |
||
| 1690 | $specialCourses[$key]['student_info']['certificate'] = Display::label( |
||
| 1691 | get_lang('No'), |
||
| 1692 | 'danger' |
||
| 1693 | ); |
||
| 1694 | } |
||
| 1695 | } |
||
| 1696 | } |
||
| 1697 | } |
||
| 1698 | } |
||
| 1699 | |||
| 1700 | if (isset($courses['in_category'])) { |
||
| 1701 | foreach ($courses['in_category'] as $key1 => $value) { |
||
| 1702 | if (isset($courses['in_category'][$key1]['courses'])) { |
||
| 1703 | foreach ($courses['in_category'][$key1]['courses'] as $key2 => $courseInCatInfo) { |
||
| 1704 | $courseCode = $courseInCatInfo['course_code']; |
||
| 1705 | if ($studentInfoProgress) { |
||
| 1706 | $progress = Tracking::get_avg_student_progress( |
||
| 1707 | $user_id, |
||
| 1708 | $courseCode |
||
| 1709 | ); |
||
| 1710 | $courses['in_category'][$key1]['courses'][$key2]['student_info']['progress'] = $progress === false ? null : $progress; |
||
| 1711 | } |
||
| 1712 | |||
| 1713 | if ($studentInfoScore) { |
||
| 1714 | $percentage_score = Tracking::get_avg_student_score( |
||
| 1715 | $user_id, |
||
| 1716 | $courseCode, |
||
| 1717 | [] |
||
| 1718 | ); |
||
| 1719 | $courses['in_category'][$key1]['courses'][$key2]['student_info']['score'] = $percentage_score; |
||
| 1720 | } |
||
| 1721 | |||
| 1722 | if ($studentInfoCertificate) { |
||
| 1723 | $category = Category::load( |
||
| 1724 | null, |
||
| 1725 | null, |
||
| 1726 | $courseCode, |
||
| 1727 | null, |
||
| 1728 | null, |
||
| 1729 | null |
||
| 1730 | ); |
||
| 1731 | $courses['in_category'][$key1]['student_info']['certificate'] = null; |
||
| 1732 | $isCertificateAvailable = $category[0]->is_certificate_available($user_id); |
||
| 1733 | if (isset($category[0])) { |
||
| 1734 | if ($isCertificateAvailable) { |
||
| 1735 | $courses['in_category'][$key1]['student_info']['certificate'] = Display::label( |
||
| 1736 | get_lang('Yes'), |
||
| 1737 | 'success' |
||
| 1738 | ); |
||
| 1739 | } else { |
||
| 1740 | $courses['in_category'][$key1]['student_info']['certificate'] = Display::label( |
||
| 1741 | get_lang('No'), |
||
| 1742 | 'danger' |
||
| 1743 | ); |
||
| 1744 | } |
||
| 1745 | } |
||
| 1746 | } |
||
| 1747 | } |
||
| 1748 | } |
||
| 1749 | } |
||
| 1750 | } |
||
| 1751 | |||
| 1752 | if (isset($courses['not_category'])) { |
||
| 1753 | foreach ($courses['not_category'] as $key => $courseNotInCatInfo) { |
||
| 1754 | $courseCode = $courseNotInCatInfo['course_code']; |
||
| 1755 | if ($studentInfoProgress) { |
||
| 1756 | $progress = Tracking::get_avg_student_progress( |
||
| 1757 | $user_id, |
||
| 1758 | $courseCode |
||
| 1759 | ); |
||
| 1760 | $courses['not_category'][$key]['student_info']['progress'] = $progress === false ? null : $progress; |
||
| 1761 | } |
||
| 1762 | |||
| 1763 | if ($studentInfoScore) { |
||
| 1764 | $percentage_score = Tracking::get_avg_student_score( |
||
| 1765 | $user_id, |
||
| 1766 | $courseCode, |
||
| 1767 | [] |
||
| 1768 | ); |
||
| 1769 | $courses['not_category'][$key]['student_info']['score'] = $percentage_score; |
||
| 1770 | } |
||
| 1771 | |||
| 1772 | if ($studentInfoCertificate) { |
||
| 1773 | $category = Category::load( |
||
| 1774 | null, |
||
| 1775 | null, |
||
| 1776 | $courseCode, |
||
| 1777 | null, |
||
| 1778 | null, |
||
| 1779 | null |
||
| 1780 | ); |
||
| 1781 | $courses['not_category'][$key]['student_info']['certificate'] = null; |
||
| 1782 | |||
| 1783 | if (isset($category[0])) { |
||
| 1784 | $certificateAvailable = $category[0]->is_certificate_available($user_id); |
||
| 1785 | if ($certificateAvailable) { |
||
| 1786 | $courses['not_category'][$key]['student_info']['certificate'] = Display::label( |
||
| 1787 | get_lang('Yes'), |
||
| 1788 | 'success' |
||
| 1789 | ); |
||
| 1790 | } else { |
||
| 1791 | $courses['not_category'][$key]['student_info']['certificate'] = Display::label( |
||
| 1792 | get_lang('No'), |
||
| 1793 | 'danger' |
||
| 1794 | ); |
||
| 1795 | } |
||
| 1796 | } |
||
| 1797 | } |
||
| 1798 | } |
||
| 1799 | } |
||
| 1800 | } |
||
| 1801 | |||
| 1802 | if ($viewGridCourses) { |
||
| 1803 | $coursesWithoutCategoryTemplate = '/user_portal/grid_courses_without_category.tpl'; |
||
| 1804 | $coursesWithCategoryTemplate = '/user_portal/grid_courses_with_category.tpl'; |
||
| 1805 | } |
||
| 1806 | |||
| 1807 | if ($specialCourses) { |
||
| 1808 | if ($categoryCodeFilter) { |
||
| 1809 | $specialCourses = self::filterByCategory($specialCourses, $categoryCodeFilter); |
||
| 1810 | } |
||
| 1811 | $this->tpl->assign('courses', $specialCourses); |
||
| 1812 | $specialCourseList = $this->tpl->fetch($this->tpl->get_template($coursesWithoutCategoryTemplate)); |
||
| 1813 | $courseCompleteList = array_merge($courseCompleteList, $specialCourses); |
||
| 1814 | } |
||
| 1815 | |||
| 1816 | if ($courses['in_category'] || $courses['not_category']) { |
||
| 1817 | foreach ($courses['in_category'] as $courseData) { |
||
| 1818 | if (!empty($courseData['courses'])) { |
||
| 1819 | $coursesInCategoryCount += count($courseData['courses']); |
||
| 1820 | $courseCompleteList = array_merge($courseCompleteList, $courseData['courses']); |
||
| 1821 | } |
||
| 1822 | } |
||
| 1823 | |||
| 1824 | $coursesNotInCategoryCount += count($courses['not_category']); |
||
| 1825 | $courseCompleteList = array_merge($courseCompleteList, $courses['not_category']); |
||
| 1826 | |||
| 1827 | if ($categoryCodeFilter) { |
||
| 1828 | $courses['in_category'] = self::filterByCategory( |
||
| 1829 | $courses['in_category'], |
||
| 1830 | $categoryCodeFilter |
||
| 1831 | ); |
||
| 1832 | $courses['not_category'] = self::filterByCategory( |
||
| 1833 | $courses['not_category'], |
||
| 1834 | $categoryCodeFilter |
||
| 1835 | ); |
||
| 1836 | } |
||
| 1837 | |||
| 1838 | $this->tpl->assign('courses', $courses['not_category']); |
||
| 1839 | $this->tpl->assign('categories', $courses['in_category']); |
||
| 1840 | |||
| 1841 | $listCourse = $this->tpl->fetch($this->tpl->get_template($coursesWithCategoryTemplate)); |
||
| 1842 | $listCourse .= $this->tpl->fetch($this->tpl->get_template($coursesWithoutCategoryTemplate)); |
||
| 1843 | } |
||
| 1844 | |||
| 1845 | $courseCount = count($specialCourses) + $coursesInCategoryCount + $coursesNotInCategoryCount; |
||
| 1846 | } |
||
| 1847 | |||
| 1848 | $sessions_with_category = ''; |
||
| 1849 | $sessions_with_no_category = ''; |
||
| 1850 | $collapsable = api_get_configuration_value('allow_user_session_collapsable'); |
||
| 1851 | $collapsableLink = ''; |
||
| 1852 | if ($collapsable) { |
||
| 1853 | $collapsableLink = api_get_path(WEB_PATH).'user_portal.php?action=collapse_session'; |
||
| 1854 | } |
||
| 1855 | |||
| 1856 | $extraFieldValue = new ExtraFieldValue('session'); |
||
| 1857 | if ($showSessions) { |
||
| 1858 | $coursesListSessionStyle = api_get_configuration_value('courses_list_session_title_link'); |
||
| 1859 | $coursesListSessionStyle = $coursesListSessionStyle === false ? 1 : $coursesListSessionStyle; |
||
| 1860 | if (api_is_drh()) { |
||
| 1861 | $coursesListSessionStyle = 1; |
||
| 1862 | } |
||
| 1863 | |||
| 1864 | $portalShowDescription = api_get_setting('show_session_description') === 'true'; |
||
| 1865 | |||
| 1866 | // Declared listSession variable |
||
| 1867 | $listSession = []; |
||
| 1868 | // Get timestamp in UTC to compare to DB values (in UTC by convention) |
||
| 1869 | $session_now = strtotime(api_get_utc_datetime(time())); |
||
| 1870 | $allowUnsubscribe = api_get_configuration_value('enable_unsubscribe_button_on_my_course_page'); |
||
| 1871 | if (is_array($session_categories)) { |
||
| 1872 | foreach ($session_categories as $session_category) { |
||
| 1873 | $session_category_id = $session_category['session_category']['id']; |
||
| 1874 | // Sessions and courses that are not in a session category |
||
| 1875 | if (empty($session_category_id) && |
||
| 1876 | isset($session_category['sessions']) |
||
| 1877 | ) { |
||
| 1878 | // Independent sessions |
||
| 1879 | foreach ($session_category['sessions'] as $session) { |
||
| 1880 | $session_id = $session['session_id']; |
||
| 1881 | |||
| 1882 | // Don't show empty sessions. |
||
| 1883 | if (count($session['courses']) < 1) { |
||
| 1884 | continue; |
||
| 1885 | } |
||
| 1886 | |||
| 1887 | // Courses inside the current session. |
||
| 1888 | $date_session_start = $session['access_start_date']; |
||
| 1889 | $date_session_end = $session['access_end_date']; |
||
| 1890 | $coachAccessStartDate = $session['coach_access_start_date']; |
||
| 1891 | $coachAccessEndDate = $session['coach_access_end_date']; |
||
| 1892 | $count_courses_session = 0; |
||
| 1893 | |||
| 1894 | // Loop course content |
||
| 1895 | $html_courses_session = []; |
||
| 1896 | $atLeastOneCourseIsVisible = false; |
||
| 1897 | $markAsOld = false; |
||
| 1898 | $markAsFuture = false; |
||
| 1899 | |||
| 1900 | foreach ($session['courses'] as $course) { |
||
| 1901 | $is_coach_course = api_is_coach($session_id, $course['real_id']); |
||
| 1902 | $allowed_time = 0; |
||
| 1903 | $allowedEndTime = true; |
||
| 1904 | |||
| 1905 | if (!empty($date_session_start)) { |
||
| 1906 | if ($is_coach_course) { |
||
| 1907 | $allowed_time = api_strtotime($coachAccessStartDate); |
||
| 1908 | } else { |
||
| 1909 | $allowed_time = api_strtotime($date_session_start); |
||
| 1910 | } |
||
| 1911 | |||
| 1912 | $endSessionToTms = null; |
||
| 1913 | if (!isset($_GET['history'])) { |
||
| 1914 | if (!empty($date_session_end)) { |
||
| 1915 | if ($is_coach_course) { |
||
| 1916 | // if coach end date is empty we use the default end date |
||
| 1917 | if (empty($coachAccessEndDate)) { |
||
| 1918 | $endSessionToTms = api_strtotime($date_session_end); |
||
| 1919 | if ($session_now > $endSessionToTms) { |
||
| 1920 | $allowedEndTime = false; |
||
| 1921 | } |
||
| 1922 | } else { |
||
| 1923 | $endSessionToTms = api_strtotime($coachAccessEndDate); |
||
| 1924 | if ($session_now > $endSessionToTms) { |
||
| 1925 | $allowedEndTime = false; |
||
| 1926 | } |
||
| 1927 | } |
||
| 1928 | } else { |
||
| 1929 | $endSessionToTms = api_strtotime($date_session_end); |
||
| 1930 | if ($session_now > $endSessionToTms) { |
||
| 1931 | $allowedEndTime = false; |
||
| 1932 | } |
||
| 1933 | } |
||
| 1934 | } |
||
| 1935 | } |
||
| 1936 | } |
||
| 1937 | |||
| 1938 | if ($showAllSessions) { |
||
| 1939 | if ($allowed_time < $session_now && $allowedEndTime === false) { |
||
| 1940 | $markAsOld = true; |
||
| 1941 | } |
||
| 1942 | if ($allowed_time > $session_now && $endSessionToTms > $session_now) { |
||
| 1943 | $markAsFuture = true; |
||
| 1944 | } |
||
| 1945 | $allowedEndTime = true; |
||
| 1946 | $allowed_time = 0; |
||
| 1947 | } |
||
| 1948 | |||
| 1949 | if ($session_now >= $allowed_time && $allowedEndTime) { |
||
| 1950 | // Read only and accessible. |
||
| 1951 | $atLeastOneCourseIsVisible = true; |
||
| 1952 | if (api_get_setting('hide_courses_in_sessions') === 'false') { |
||
| 1953 | $courseUserHtml = CourseManager::get_logged_user_course_html( |
||
| 1954 | $course, |
||
| 1955 | $session_id, |
||
| 1956 | 'session_course_item', |
||
| 1957 | true, |
||
| 1958 | $this->load_directories_preview |
||
| 1959 | ); |
||
| 1960 | if (isset($courseUserHtml[1])) { |
||
| 1961 | $course_session = $courseUserHtml[1]; |
||
| 1962 | $course_session['skill'] = isset($courseUserHtml['skill']) ? $courseUserHtml['skill'] : ''; |
||
| 1963 | |||
| 1964 | // Course option (show student progress) |
||
| 1965 | // This code will add new variables (Progress, Score, Certificate) |
||
| 1966 | if ($studentInfoProgress || $studentInfoScore || $studentInfoCertificate) { |
||
| 1967 | if ($studentInfoProgress) { |
||
| 1968 | $progress = Tracking::get_avg_student_progress( |
||
| 1969 | $user_id, |
||
| 1970 | $course['course_code'], |
||
| 1971 | [], |
||
| 1972 | $session_id |
||
| 1973 | ); |
||
| 1974 | $course_session['student_info']['progress'] = $progress === false ? null : $progress; |
||
| 1975 | } |
||
| 1976 | |||
| 1977 | if ($studentInfoScore) { |
||
| 1978 | $percentage_score = Tracking::get_avg_student_score( |
||
| 1979 | $user_id, |
||
| 1980 | $course['course_code'], |
||
| 1981 | [], |
||
| 1982 | $session_id |
||
| 1983 | ); |
||
| 1984 | $course_session['student_info']['score'] = $percentage_score; |
||
| 1985 | } |
||
| 1986 | |||
| 1987 | if ($studentInfoCertificate) { |
||
| 1988 | $category = Category::load( |
||
| 1989 | null, |
||
| 1990 | null, |
||
| 1991 | $course['course_code'], |
||
| 1992 | null, |
||
| 1993 | null, |
||
| 1994 | $session_id |
||
| 1995 | ); |
||
| 1996 | $course_session['student_info']['certificate'] = null; |
||
| 1997 | if (isset($category[0])) { |
||
| 1998 | if ($category[0]->is_certificate_available($user_id)) { |
||
| 1999 | $course_session['student_info']['certificate'] = Display::label( |
||
| 2000 | get_lang('Yes'), |
||
| 2001 | 'success' |
||
| 2002 | ); |
||
| 2003 | } else { |
||
| 2004 | $course_session['student_info']['certificate'] = Display::label( |
||
| 2005 | get_lang('No'), |
||
| 2006 | 'danger' |
||
| 2007 | ); |
||
| 2008 | } |
||
| 2009 | } |
||
| 2010 | } |
||
| 2011 | } |
||
| 2012 | |||
| 2013 | $course_session['extrafields'] = CourseManager::getExtraFieldsToBePresented($course['real_id']); |
||
| 2014 | if (false === $is_coach_course && $allowUnsubscribe && '1' === $course['unsubscribe']) { |
||
| 2015 | $course_session['unregister_button'] = |
||
| 2016 | CoursesAndSessionsCatalog::return_unregister_button( |
||
| 2017 | ['code' => $course['course_code']], |
||
| 2018 | Security::get_existing_token(), |
||
| 2019 | '', |
||
| 2020 | '', |
||
| 2021 | $session_id |
||
| 2022 | ); |
||
| 2023 | } |
||
| 2024 | |||
| 2025 | $html_courses_session[] = $course_session; |
||
| 2026 | } |
||
| 2027 | } |
||
| 2028 | $count_courses_session++; |
||
| 2029 | } |
||
| 2030 | } |
||
| 2031 | |||
| 2032 | // No courses to show. |
||
| 2033 | if ($atLeastOneCourseIsVisible === false) { |
||
| 2034 | if (empty($html_courses_session)) { |
||
| 2035 | continue; |
||
| 2036 | } |
||
| 2037 | } |
||
| 2038 | |||
| 2039 | if ($count_courses_session > 0) { |
||
| 2040 | $params = [ |
||
| 2041 | 'id' => $session_id, |
||
| 2042 | ]; |
||
| 2043 | $session_box = Display::getSessionTitleBox($session_id); |
||
| 2044 | $coachId = $session_box['id_coach']; |
||
| 2045 | $imageField = $extraFieldValue->get_values_by_handler_and_field_variable( |
||
| 2046 | $session_id, |
||
| 2047 | 'image' |
||
| 2048 | ); |
||
| 2049 | |||
| 2050 | $params['category_id'] = $session_box['category_id']; |
||
| 2051 | $params['title'] = $session_box['title']; |
||
| 2052 | $params['id_coach'] = $coachId; |
||
| 2053 | $params['coach_url'] = ''; |
||
| 2054 | |||
| 2055 | if ($coachId) { |
||
| 2056 | $userIdHash = UserManager::generateUserHash($coachId); |
||
| 2057 | $params['coach_url'] = api_get_path(WEB_AJAX_PATH). |
||
| 2058 | 'user_manager.ajax.php?a=get_user_popup&hash='.$userIdHash; |
||
| 2059 | } |
||
| 2060 | |||
| 2061 | $params['coach_name'] = !empty($session_box['coach']) ? $session_box['coach'] : null; |
||
| 2062 | $params['coach_avatar'] = UserManager::getUserPicture( |
||
| 2063 | $coachId, |
||
| 2064 | USER_IMAGE_SIZE_SMALL |
||
| 2065 | ); |
||
| 2066 | $params['date'] = $session_box['dates']; |
||
| 2067 | $params['image'] = isset($imageField['value']) ? $imageField['value'] : null; |
||
| 2068 | $params['duration'] = isset($session_box['duration']) ? ' '.$session_box['duration'] : null; |
||
| 2069 | $params['show_actions'] = SessionManager::cantEditSession($session_id); |
||
| 2070 | |||
| 2071 | if ($collapsable) { |
||
| 2072 | $collapsableData = SessionManager::getCollapsableData( |
||
| 2073 | $user_id, |
||
| 2074 | $session_id, |
||
| 2075 | $extraFieldValue, |
||
| 2076 | $collapsableLink |
||
| 2077 | ); |
||
| 2078 | $params['collapsed'] = $collapsableData['collapsed']; |
||
| 2079 | $params['collapsable_link'] = $collapsableData['collapsable_link']; |
||
| 2080 | } |
||
| 2081 | |||
| 2082 | $params['show_description'] = $session_box['show_description'] == 1 && $portalShowDescription; |
||
| 2083 | $params['description'] = $session_box['description']; |
||
| 2084 | $params['visibility'] = $session_box['visibility']; |
||
| 2085 | $params['show_simple_session_info'] = $showSimpleSessionInfo; |
||
| 2086 | $params['course_list_session_style'] = $coursesListSessionStyle; |
||
| 2087 | $params['num_users'] = $session_box['num_users']; |
||
| 2088 | $params['num_courses'] = $session_box['num_courses']; |
||
| 2089 | $params['course_categories'] = CourseManager::getCourseCategoriesFromCourseList( |
||
| 2090 | $html_courses_session |
||
| 2091 | ); |
||
| 2092 | $params['courses'] = $html_courses_session; |
||
| 2093 | $params['is_old'] = $markAsOld; |
||
| 2094 | $params['is_future'] = $markAsFuture; |
||
| 2095 | |||
| 2096 | if ($showSimpleSessionInfo) { |
||
| 2097 | $params['subtitle'] = self::getSimpleSessionDetails( |
||
| 2098 | $session_box['coach'], |
||
| 2099 | $session_box['dates'], |
||
| 2100 | isset($session_box['duration']) ? $session_box['duration'] : null |
||
| 2101 | ); |
||
| 2102 | } |
||
| 2103 | |||
| 2104 | if ($gameModeIsActive) { |
||
| 2105 | $params['stars'] = GamificationUtils::getSessionStars( |
||
| 2106 | $params['id'], |
||
| 2107 | $this->user_id |
||
| 2108 | ); |
||
| 2109 | $params['progress'] = GamificationUtils::getSessionProgress( |
||
| 2110 | $params['id'], |
||
| 2111 | $this->user_id |
||
| 2112 | ); |
||
| 2113 | $params['points'] = GamificationUtils::getSessionPoints( |
||
| 2114 | $params['id'], |
||
| 2115 | $this->user_id |
||
| 2116 | ); |
||
| 2117 | } |
||
| 2118 | $listSession[] = $params; |
||
| 2119 | $sessionCount++; |
||
| 2120 | } |
||
| 2121 | } |
||
| 2122 | } else { |
||
| 2123 | // All sessions included in |
||
| 2124 | $count_courses_session = 0; |
||
| 2125 | $html_sessions = ''; |
||
| 2126 | if (isset($session_category['sessions'])) { |
||
| 2127 | foreach ($session_category['sessions'] as $session) { |
||
| 2128 | $session_id = $session['session_id']; |
||
| 2129 | |||
| 2130 | // Don't show empty sessions. |
||
| 2131 | if (count($session['courses']) < 1) { |
||
| 2132 | continue; |
||
| 2133 | } |
||
| 2134 | |||
| 2135 | $date_session_start = $session['access_start_date']; |
||
| 2136 | $date_session_end = $session['access_end_date']; |
||
| 2137 | $coachAccessStartDate = $session['coach_access_start_date']; |
||
| 2138 | $coachAccessEndDate = $session['coach_access_end_date']; |
||
| 2139 | $html_courses_session = []; |
||
| 2140 | $count = 0; |
||
| 2141 | $markAsOld = false; |
||
| 2142 | $markAsFuture = false; |
||
| 2143 | |||
| 2144 | foreach ($session['courses'] as $course) { |
||
| 2145 | $is_coach_course = api_is_coach($session_id, $course['real_id']); |
||
| 2146 | $allowed_time = 0; |
||
| 2147 | $allowedEndTime = true; |
||
| 2148 | |||
| 2149 | if (!empty($date_session_start)) { |
||
| 2150 | if ($is_coach_course) { |
||
| 2151 | $allowed_time = api_strtotime($coachAccessStartDate); |
||
| 2152 | } else { |
||
| 2153 | $allowed_time = api_strtotime($date_session_start); |
||
| 2154 | } |
||
| 2155 | |||
| 2156 | if (!isset($_GET['history'])) { |
||
| 2157 | if (!empty($date_session_end)) { |
||
| 2158 | if ($is_coach_course) { |
||
| 2159 | // if coach end date is empty we use the default end date |
||
| 2160 | if (empty($coachAccessEndDate)) { |
||
| 2161 | $endSessionToTms = api_strtotime($date_session_end); |
||
| 2162 | if ($session_now > $endSessionToTms) { |
||
| 2163 | $allowedEndTime = false; |
||
| 2164 | } |
||
| 2165 | } else { |
||
| 2166 | $endSessionToTms = api_strtotime($coachAccessEndDate); |
||
| 2167 | if ($session_now > $endSessionToTms) { |
||
| 2168 | $allowedEndTime = false; |
||
| 2169 | } |
||
| 2170 | } |
||
| 2171 | } else { |
||
| 2172 | $endSessionToTms = api_strtotime($date_session_end); |
||
| 2173 | if ($session_now > $endSessionToTms) { |
||
| 2174 | $allowedEndTime = false; |
||
| 2175 | } |
||
| 2176 | } |
||
| 2177 | } |
||
| 2178 | } |
||
| 2179 | } |
||
| 2180 | |||
| 2181 | if ($showAllSessions) { |
||
| 2182 | if ($allowed_time < $session_now && $allowedEndTime == false) { |
||
| 2183 | $markAsOld = true; |
||
| 2184 | } |
||
| 2185 | if ($allowed_time > $session_now && $endSessionToTms > $session_now) { |
||
| 2186 | $markAsFuture = true; |
||
| 2187 | } |
||
| 2188 | $allowedEndTime = true; |
||
| 2189 | $allowed_time = 0; |
||
| 2190 | } |
||
| 2191 | |||
| 2192 | if ($session_now >= $allowed_time && $allowedEndTime) { |
||
| 2193 | if (api_get_setting('hide_courses_in_sessions') === 'false') { |
||
| 2194 | $c = CourseManager::get_logged_user_course_html( |
||
| 2195 | $course, |
||
| 2196 | $session_id, |
||
| 2197 | 'session_course_item' |
||
| 2198 | ); |
||
| 2199 | if (isset($c[1])) { |
||
| 2200 | $course_session = $c[1]; |
||
| 2201 | $course_session['skill'] = isset($c['skill']) ? $c['skill'] : ''; |
||
| 2202 | |||
| 2203 | // Course option (show student progress) |
||
| 2204 | // This code will add new variables (Progress, Score, Certificate) |
||
| 2205 | if ($studentInfoProgress || $studentInfoScore || $studentInfoCertificate) { |
||
| 2206 | if ($studentInfoProgress) { |
||
| 2207 | $progress = Tracking::get_avg_student_progress( |
||
| 2208 | $user_id, |
||
| 2209 | $course['course_code'], |
||
| 2210 | [], |
||
| 2211 | $session_id |
||
| 2212 | ); |
||
| 2213 | $course_session['student_info']['progress'] = $progress === false ? null : $progress; |
||
| 2214 | } |
||
| 2215 | |||
| 2216 | if ($studentInfoScore) { |
||
| 2217 | $percentage_score = Tracking::get_avg_student_score( |
||
| 2218 | $user_id, |
||
| 2219 | $course['course_code'], |
||
| 2220 | [], |
||
| 2221 | $session_id |
||
| 2222 | ); |
||
| 2223 | $course_session['student_info']['score'] = $percentage_score; |
||
| 2224 | } |
||
| 2225 | |||
| 2226 | if ($studentInfoCertificate) { |
||
| 2227 | $category = Category::load( |
||
| 2228 | null, |
||
| 2229 | null, |
||
| 2230 | $course['course_code'], |
||
| 2231 | null, |
||
| 2232 | null, |
||
| 2233 | $session_id |
||
| 2234 | ); |
||
| 2235 | $course_session['student_info']['certificate'] = null; |
||
| 2236 | if (isset($category[0])) { |
||
| 2237 | if ($category[0]->is_certificate_available($user_id)) { |
||
| 2238 | $course_session['student_info']['certificate'] = Display::label( |
||
| 2239 | get_lang('Yes'), |
||
| 2240 | 'success' |
||
| 2241 | ); |
||
| 2242 | } else { |
||
| 2243 | $course_session['student_info']['certificate'] = Display::label( |
||
| 2244 | get_lang('No'), |
||
| 2245 | 'danger' |
||
| 2246 | ); |
||
| 2247 | } |
||
| 2248 | } |
||
| 2249 | } |
||
| 2250 | } |
||
| 2251 | |||
| 2252 | $course_session['extrafields'] = CourseManager::getExtraFieldsToBePresented($course['real_id']); |
||
| 2253 | if (false === $is_coach_course && $allowUnsubscribe && '1' === $course['unsubscribe']) { |
||
| 2254 | $course_session['unregister_button'] = |
||
| 2255 | CoursesAndSessionsCatalog::return_unregister_button( |
||
| 2256 | ['code' => $course['course_code']], |
||
| 2257 | Security::get_existing_token(), |
||
| 2258 | '', |
||
| 2259 | '', |
||
| 2260 | $session_id |
||
| 2261 | ); |
||
| 2262 | } |
||
| 2263 | |||
| 2264 | $html_courses_session[] = $course_session; |
||
| 2265 | } |
||
| 2266 | } |
||
| 2267 | $count_courses_session++; |
||
| 2268 | $count++; |
||
| 2269 | } |
||
| 2270 | } |
||
| 2271 | |||
| 2272 | $sessionParams = []; |
||
| 2273 | // Category |
||
| 2274 | if ($count > 0) { |
||
| 2275 | $session_box = Display::getSessionTitleBox($session_id); |
||
| 2276 | $sessionParams[0]['id'] = $session_id; |
||
| 2277 | $sessionParams[0]['date'] = $session_box['dates']; |
||
| 2278 | $sessionParams[0]['duration'] = isset($session_box['duration']) ? ' '.$session_box['duration'] : null; |
||
| 2279 | $sessionParams[0]['course_list_session_style'] = $coursesListSessionStyle; |
||
| 2280 | $sessionParams[0]['title'] = $session_box['title']; |
||
| 2281 | $sessionParams[0]['subtitle'] = (!empty($session_box['coach']) ? $session_box['coach'].' | ' : '').$session_box['dates']; |
||
| 2282 | $sessionParams[0]['show_actions'] = SessionManager::cantEditSession($session_id); |
||
| 2283 | $sessionParams[0]['courses'] = $html_courses_session; |
||
| 2284 | $sessionParams[0]['show_simple_session_info'] = $showSimpleSessionInfo; |
||
| 2285 | $sessionParams[0]['coach_name'] = !empty($session_box['coach']) ? $session_box['coach'] : null; |
||
| 2286 | $sessionParams[0]['is_old'] = $markAsOld; |
||
| 2287 | $sessionParams[0]['is_future'] = $markAsFuture; |
||
| 2288 | |||
| 2289 | if ($collapsable) { |
||
| 2290 | $collapsableData = SessionManager::getCollapsableData( |
||
| 2291 | $user_id, |
||
| 2292 | $session_id, |
||
| 2293 | $extraFieldValue, |
||
| 2294 | $collapsableLink |
||
| 2295 | ); |
||
| 2296 | $sessionParams[0]['collapsable_link'] = $collapsableData['collapsable_link']; |
||
| 2297 | $sessionParams[0]['collapsed'] = $collapsableData['collapsed']; |
||
| 2298 | } |
||
| 2299 | |||
| 2300 | if ($showSimpleSessionInfo) { |
||
| 2301 | $sessionParams[0]['subtitle'] = self::getSimpleSessionDetails( |
||
| 2302 | $session_box['coach'], |
||
| 2303 | $session_box['dates'], |
||
| 2304 | isset($session_box['duration']) ? $session_box['duration'] : null |
||
| 2305 | ); |
||
| 2306 | } |
||
| 2307 | $this->tpl->assign('session', $sessionParams); |
||
| 2308 | $this->tpl->assign('show_tutor', api_get_setting('show_session_coach') === 'true'); |
||
| 2309 | $this->tpl->assign('gamification_mode', $gameModeIsActive); |
||
| 2310 | $this->tpl->assign( |
||
| 2311 | 'remove_session_url', |
||
| 2312 | api_get_configuration_value('remove_session_url') |
||
| 2313 | ); |
||
| 2314 | $this->tpl->assign( |
||
| 2315 | 'hide_session_dates_in_user_portal', |
||
| 2316 | api_get_configuration_value('hide_session_dates_in_user_portal') |
||
| 2317 | ); |
||
| 2318 | |||
| 2319 | if ($viewGridCourses) { |
||
| 2320 | $html_sessions .= $this->tpl->fetch( |
||
| 2321 | $this->tpl->get_template('/user_portal/grid_session.tpl') |
||
| 2322 | ); |
||
| 2323 | } else { |
||
| 2324 | $html_sessions .= $this->tpl->fetch( |
||
| 2325 | $this->tpl->get_template('user_portal/classic_session.tpl') |
||
| 2326 | ); |
||
| 2327 | } |
||
| 2328 | $sessionCount++; |
||
| 2329 | } |
||
| 2330 | } |
||
| 2331 | } |
||
| 2332 | |||
| 2333 | if ($count_courses_session > 0) { |
||
| 2334 | $categoryParams = [ |
||
| 2335 | 'id' => $session_category['session_category']['id'], |
||
| 2336 | 'title' => $session_category['session_category']['name'], |
||
| 2337 | 'show_actions' => api_is_platform_admin(), |
||
| 2338 | 'subtitle' => '', |
||
| 2339 | 'sessions' => $html_sessions, |
||
| 2340 | ]; |
||
| 2341 | |||
| 2342 | $session_category_start_date = $session_category['session_category']['date_start']; |
||
| 2343 | $session_category_end_date = $session_category['session_category']['date_end']; |
||
| 2344 | if ($session_category_start_date == '0000-00-00') { |
||
| 2345 | $session_category_start_date = ''; |
||
| 2346 | } |
||
| 2347 | |||
| 2348 | if ($session_category_end_date == '0000-00-00') { |
||
| 2349 | $session_category_end_date = ''; |
||
| 2350 | } |
||
| 2351 | |||
| 2352 | if (!empty($session_category_start_date) && |
||
| 2353 | !empty($session_category_end_date) |
||
| 2354 | ) { |
||
| 2355 | $categoryParams['subtitle'] = sprintf( |
||
| 2356 | get_lang('FromDateXToDateY'), |
||
| 2357 | $session_category_start_date, |
||
| 2358 | $session_category_end_date |
||
| 2359 | ); |
||
| 2360 | } else { |
||
| 2361 | if (!empty($session_category_start_date)) { |
||
| 2362 | $categoryParams['subtitle'] = get_lang('From').' '.$session_category_start_date; |
||
| 2363 | } |
||
| 2364 | |||
| 2365 | if (!empty($session_category_end_date)) { |
||
| 2366 | $categoryParams['subtitle'] = get_lang('Until').' '.$session_category_end_date; |
||
| 2367 | } |
||
| 2368 | } |
||
| 2369 | |||
| 2370 | $this->tpl->assign('session_category', $categoryParams); |
||
| 2371 | $sessions_with_category .= $this->tpl->fetch( |
||
| 2372 | $this->tpl->get_template('user_portal/session_category.tpl') |
||
| 2373 | ); |
||
| 2374 | } |
||
| 2375 | } |
||
| 2376 | } |
||
| 2377 | |||
| 2378 | $allCoursesInSessions = []; |
||
| 2379 | foreach ($listSession as $currentSession) { |
||
| 2380 | $coursesInSessions = $currentSession['courses']; |
||
| 2381 | unset($currentSession['courses']); |
||
| 2382 | foreach ($coursesInSessions as $coursesInSession) { |
||
| 2383 | $coursesInSession['session'] = $currentSession; |
||
| 2384 | $allCoursesInSessions[] = $coursesInSession; |
||
| 2385 | } |
||
| 2386 | } |
||
| 2387 | |||
| 2388 | $this->tpl->assign('all_courses', $allCoursesInSessions); |
||
| 2389 | $this->tpl->assign('session', $listSession); |
||
| 2390 | $this->tpl->assign('show_tutor', (api_get_setting('show_session_coach') === 'true' ? true : false)); |
||
| 2391 | $this->tpl->assign('gamification_mode', $gameModeIsActive); |
||
| 2392 | $this->tpl->assign('remove_session_url', api_get_configuration_value('remove_session_url')); |
||
| 2393 | $this->tpl->assign( |
||
| 2394 | 'hide_session_dates_in_user_portal', |
||
| 2395 | api_get_configuration_value('hide_session_dates_in_user_portal') |
||
| 2396 | ); |
||
| 2397 | |||
| 2398 | if ($viewGridCourses) { |
||
| 2399 | $sessions_with_no_category = $this->tpl->fetch( |
||
| 2400 | $this->tpl->get_template('/user_portal/grid_session.tpl') |
||
| 2401 | ); |
||
| 2402 | } else { |
||
| 2403 | $sessions_with_no_category = $this->tpl->fetch( |
||
| 2404 | $this->tpl->get_template('user_portal/classic_session.tpl') |
||
| 2405 | ); |
||
| 2406 | } |
||
| 2407 | } |
||
| 2408 | } |
||
| 2409 | |||
| 2410 | return [ |
||
| 2411 | 'courses' => $courseCompleteList, |
||
| 2412 | 'sessions' => $session_categories, |
||
| 2413 | 'html' => trim($specialCourseList.$sessions_with_category.$sessions_with_no_category.$listCourse), |
||
| 2414 | 'session_count' => $sessionCount, |
||
| 2415 | 'course_count' => $courseCount, |
||
| 2416 | ]; |
||
| 2692 |