| Conditions | 140 |
| Paths | > 20000 |
| Total Lines | 772 |
| Code Lines | 504 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 1509 | public function returnCoursesAndSessions( |
||
| 1510 | $user_id, |
||
| 1511 | $showSessions = true, |
||
| 1512 | $categoryCodeFilter = '', |
||
| 1513 | $useUserLanguageFilterIfAvailable = true, |
||
| 1514 | $loadHistory = false |
||
| 1515 | ) { |
||
| 1516 | $gameModeIsActive = api_get_setting('gamification_mode'); |
||
| 1517 | $viewGridCourses = api_get_configuration_value('view_grid_courses'); |
||
| 1518 | $showSimpleSessionInfo = api_get_configuration_value('show_simple_session_info'); |
||
| 1519 | $coursesWithoutCategoryTemplate = '/user_portal/classic_courses_without_category.tpl'; |
||
| 1520 | $coursesWithCategoryTemplate = '/user_portal/classic_courses_with_category.tpl'; |
||
| 1521 | $showAllSessions = api_get_configuration_value('show_all_sessions_on_my_course_page') === true; |
||
| 1522 | |||
| 1523 | if ($loadHistory) { |
||
| 1524 | // Load sessions in category in *history* |
||
| 1525 | $session_categories = UserManager::get_sessions_by_category($user_id, true); |
||
| 1526 | } else { |
||
| 1527 | // Load sessions in category |
||
| 1528 | $session_categories = UserManager::get_sessions_by_category($user_id, false); |
||
| 1529 | } |
||
| 1530 | |||
| 1531 | $sessionCount = 0; |
||
| 1532 | $courseCount = 0; |
||
| 1533 | |||
| 1534 | // Student info code check (shows student progress information on |
||
| 1535 | // courses list |
||
| 1536 | $studentInfo = api_get_configuration_value('course_student_info'); |
||
| 1537 | |||
| 1538 | $studentInfoProgress = !empty($studentInfo['progress']) && $studentInfo['progress'] === true; |
||
| 1539 | $studentInfoScore = !empty($studentInfo['score']) && $studentInfo['score'] === true; |
||
| 1540 | $studentInfoCertificate = !empty($studentInfo['certificate']) && $studentInfo['certificate'] === true; |
||
| 1541 | $courseCompleteList = []; |
||
| 1542 | $coursesInCategoryCount = 0; |
||
| 1543 | $coursesNotInCategoryCount = 0; |
||
| 1544 | $listCourse = ''; |
||
| 1545 | $specialCourseList = ''; |
||
| 1546 | |||
| 1547 | // If we're not in the history view... |
||
| 1548 | if ($loadHistory === false) { |
||
| 1549 | // Display special courses. |
||
| 1550 | $specialCourses = CourseManager::returnSpecialCourses( |
||
| 1551 | $user_id, |
||
| 1552 | $this->load_directories_preview, |
||
| 1553 | $useUserLanguageFilterIfAvailable |
||
| 1554 | ); |
||
| 1555 | |||
| 1556 | // Display courses. |
||
| 1557 | $courses = CourseManager::returnCourses( |
||
| 1558 | $user_id, |
||
| 1559 | $this->load_directories_preview, |
||
| 1560 | $useUserLanguageFilterIfAvailable |
||
| 1561 | ); |
||
| 1562 | |||
| 1563 | // Course option (show student progress) |
||
| 1564 | // This code will add new variables (Progress, Score, Certificate) |
||
| 1565 | if ($studentInfoProgress || $studentInfoScore || $studentInfoCertificate) { |
||
| 1566 | if (!empty($specialCourses)) { |
||
| 1567 | foreach ($specialCourses as $key => $specialCourseInfo) { |
||
| 1568 | if ($studentInfoProgress) { |
||
| 1569 | $progress = Tracking::get_avg_student_progress( |
||
| 1570 | $user_id, |
||
| 1571 | $specialCourseInfo['course_code'] |
||
| 1572 | ); |
||
| 1573 | $specialCourses[$key]['student_info']['progress'] = $progress === false ? null : $progress; |
||
| 1574 | } |
||
| 1575 | |||
| 1576 | if ($studentInfoScore) { |
||
| 1577 | $percentage_score = Tracking::get_avg_student_score( |
||
| 1578 | $user_id, |
||
| 1579 | $specialCourseInfo['course_code'], |
||
| 1580 | [] |
||
| 1581 | ); |
||
| 1582 | $specialCourses[$key]['student_info']['score'] = $percentage_score; |
||
| 1583 | } |
||
| 1584 | |||
| 1585 | if ($studentInfoCertificate) { |
||
| 1586 | $category = Category::load( |
||
| 1587 | null, |
||
| 1588 | null, |
||
| 1589 | $specialCourseInfo['course_code'], |
||
| 1590 | null, |
||
| 1591 | null, |
||
| 1592 | null |
||
| 1593 | ); |
||
| 1594 | $specialCourses[$key]['student_info']['certificate'] = null; |
||
| 1595 | if (isset($category[0])) { |
||
| 1596 | if ($category[0]->is_certificate_available($user_id)) { |
||
| 1597 | $specialCourses[$key]['student_info']['certificate'] = Display::label( |
||
| 1598 | get_lang('Yes'), |
||
| 1599 | 'success' |
||
| 1600 | ); |
||
| 1601 | } else { |
||
| 1602 | $specialCourses[$key]['student_info']['certificate'] = Display::label( |
||
| 1603 | get_lang('No'), |
||
| 1604 | 'danger' |
||
| 1605 | ); |
||
| 1606 | } |
||
| 1607 | } |
||
| 1608 | } |
||
| 1609 | } |
||
| 1610 | } |
||
| 1611 | |||
| 1612 | if (isset($courses['in_category'])) { |
||
| 1613 | foreach ($courses['in_category'] as $key1 => $value) { |
||
| 1614 | if (isset($courses['in_category'][$key1]['courses'])) { |
||
| 1615 | foreach ($courses['in_category'][$key1]['courses'] as $key2 => $courseInCatInfo) { |
||
| 1616 | $courseCode = $courseInCatInfo['course_code']; |
||
| 1617 | if ($studentInfoProgress) { |
||
| 1618 | $progress = Tracking::get_avg_student_progress( |
||
| 1619 | $user_id, |
||
| 1620 | $courseCode |
||
| 1621 | ); |
||
| 1622 | $courses['in_category'][$key1]['courses'][$key2]['student_info']['progress'] = $progress === false ? null : $progress; |
||
| 1623 | } |
||
| 1624 | |||
| 1625 | if ($studentInfoScore) { |
||
| 1626 | $percentage_score = Tracking::get_avg_student_score( |
||
| 1627 | $user_id, |
||
| 1628 | $courseCode, |
||
| 1629 | [] |
||
| 1630 | ); |
||
| 1631 | $courses['in_category'][$key1]['courses'][$key2]['student_info']['score'] = $percentage_score; |
||
| 1632 | } |
||
| 1633 | |||
| 1634 | if ($studentInfoCertificate) { |
||
| 1635 | $category = Category::load( |
||
| 1636 | null, |
||
| 1637 | null, |
||
| 1638 | $courseCode, |
||
| 1639 | null, |
||
| 1640 | null, |
||
| 1641 | null |
||
| 1642 | ); |
||
| 1643 | $courses['in_category'][$key1]['student_info']['certificate'] = null; |
||
| 1644 | $isCertificateAvailable = $category[0]->is_certificate_available($user_id); |
||
| 1645 | if (isset($category[0])) { |
||
| 1646 | if ($viewGridCourses) { |
||
| 1647 | if ($isCertificateAvailable) { |
||
| 1648 | $courses['in_category'][$key1]['student_info']['certificate'] = get_lang( |
||
| 1649 | 'Yes' |
||
| 1650 | ); |
||
| 1651 | } else { |
||
| 1652 | $courses['in_category'][$key1]['student_info']['certificate'] = get_lang( |
||
| 1653 | 'No' |
||
| 1654 | ); |
||
| 1655 | } |
||
| 1656 | } else { |
||
| 1657 | if ($isCertificateAvailable) { |
||
| 1658 | $courses['in_category'][$key1]['student_info']['certificate'] = Display::label( |
||
| 1659 | get_lang('Yes'), |
||
| 1660 | 'success' |
||
| 1661 | ); |
||
| 1662 | } else { |
||
| 1663 | $courses['in_category'][$key1]['student_info']['certificate'] = Display::label( |
||
| 1664 | get_lang('No'), |
||
| 1665 | 'danger' |
||
| 1666 | ); |
||
| 1667 | } |
||
| 1668 | } |
||
| 1669 | } |
||
| 1670 | } |
||
| 1671 | } |
||
| 1672 | } |
||
| 1673 | } |
||
| 1674 | } |
||
| 1675 | |||
| 1676 | if (isset($courses['not_category'])) { |
||
| 1677 | foreach ($courses['not_category'] as $key => $courseNotInCatInfo) { |
||
| 1678 | $courseCode = $courseNotInCatInfo['course_code']; |
||
| 1679 | if ($studentInfoProgress) { |
||
| 1680 | $progress = Tracking::get_avg_student_progress( |
||
| 1681 | $user_id, |
||
| 1682 | $courseCode |
||
| 1683 | ); |
||
| 1684 | $courses['not_category'][$key]['student_info']['progress'] = $progress === false ? null : $progress; |
||
| 1685 | } |
||
| 1686 | |||
| 1687 | if ($studentInfoScore) { |
||
| 1688 | $percentage_score = Tracking::get_avg_student_score( |
||
| 1689 | $user_id, |
||
| 1690 | $courseCode, |
||
| 1691 | [] |
||
| 1692 | ); |
||
| 1693 | $courses['not_category'][$key]['student_info']['score'] = $percentage_score; |
||
| 1694 | } |
||
| 1695 | |||
| 1696 | if ($studentInfoCertificate) { |
||
| 1697 | $category = Category::load( |
||
| 1698 | null, |
||
| 1699 | null, |
||
| 1700 | $courseCode, |
||
| 1701 | null, |
||
| 1702 | null, |
||
| 1703 | null |
||
| 1704 | ); |
||
| 1705 | $courses['not_category'][$key]['student_info']['certificate'] = null; |
||
| 1706 | |||
| 1707 | if (isset($category[0])) { |
||
| 1708 | $certificateAvailable = $category[0]->is_certificate_available($user_id); |
||
| 1709 | if ($viewGridCourses) { |
||
| 1710 | if ($certificateAvailable) { |
||
| 1711 | $courses['not_category'][$key]['student_info']['certificate'] = get_lang('Yes'); |
||
| 1712 | } else { |
||
| 1713 | $courses['not_category'][$key]['student_info']['certificate'] = get_lang('No'); |
||
| 1714 | } |
||
| 1715 | } else { |
||
| 1716 | if ($certificateAvailable) { |
||
| 1717 | $courses['not_category'][$key]['student_info']['certificate'] = Display::label( |
||
| 1718 | get_lang('Yes'), |
||
| 1719 | 'success' |
||
| 1720 | ); |
||
| 1721 | } else { |
||
| 1722 | $courses['not_category'][$key]['student_info']['certificate'] = Display::label( |
||
| 1723 | get_lang('No'), |
||
| 1724 | 'danger' |
||
| 1725 | ); |
||
| 1726 | } |
||
| 1727 | } |
||
| 1728 | } |
||
| 1729 | } |
||
| 1730 | } |
||
| 1731 | } |
||
| 1732 | } |
||
| 1733 | |||
| 1734 | if ($viewGridCourses) { |
||
| 1735 | $coursesWithoutCategoryTemplate = '/user_portal/grid_courses_without_category.tpl'; |
||
| 1736 | $coursesWithCategoryTemplate = '/user_portal/grid_courses_with_category.tpl'; |
||
| 1737 | } |
||
| 1738 | |||
| 1739 | if ($specialCourses) { |
||
| 1740 | if ($categoryCodeFilter) { |
||
| 1741 | $specialCourses = self::filterByCategory($specialCourses, $categoryCodeFilter); |
||
| 1742 | } |
||
| 1743 | $this->tpl->assign('courses', $specialCourses); |
||
| 1744 | $specialCourseList = $this->tpl->fetch($this->tpl->get_template($coursesWithoutCategoryTemplate)); |
||
| 1745 | $courseCompleteList = array_merge($courseCompleteList, $specialCourses); |
||
| 1746 | } |
||
| 1747 | |||
| 1748 | if ($courses['in_category'] || $courses['not_category']) { |
||
| 1749 | foreach ($courses['in_category'] as $courseData) { |
||
| 1750 | if (!empty($courseData['courses'])) { |
||
| 1751 | $coursesInCategoryCount += count($courseData['courses']); |
||
| 1752 | $courseCompleteList = array_merge($courseCompleteList, $courseData['courses']); |
||
| 1753 | } |
||
| 1754 | } |
||
| 1755 | |||
| 1756 | $coursesNotInCategoryCount += count($courses['not_category']); |
||
| 1757 | $courseCompleteList = array_merge($courseCompleteList, $courses['not_category']); |
||
| 1758 | |||
| 1759 | if ($categoryCodeFilter) { |
||
| 1760 | $courses['in_category'] = self::filterByCategory( |
||
| 1761 | $courses['in_category'], |
||
| 1762 | $categoryCodeFilter |
||
| 1763 | ); |
||
| 1764 | $courses['not_category'] = self::filterByCategory( |
||
| 1765 | $courses['not_category'], |
||
| 1766 | $categoryCodeFilter |
||
| 1767 | ); |
||
| 1768 | } |
||
| 1769 | |||
| 1770 | $this->tpl->assign('courses', $courses['not_category']); |
||
| 1771 | $this->tpl->assign('categories', $courses['in_category']); |
||
| 1772 | |||
| 1773 | $listCourse = $this->tpl->fetch($this->tpl->get_template($coursesWithCategoryTemplate)); |
||
| 1774 | $listCourse .= $this->tpl->fetch($this->tpl->get_template($coursesWithoutCategoryTemplate)); |
||
| 1775 | } |
||
| 1776 | |||
| 1777 | $courseCount = count($specialCourses) + $coursesInCategoryCount + $coursesNotInCategoryCount; |
||
| 1778 | } |
||
| 1779 | |||
| 1780 | $sessions_with_category = ''; |
||
| 1781 | $sessions_with_no_category = ''; |
||
| 1782 | $collapsable = api_get_configuration_value('allow_user_session_collapsable'); |
||
| 1783 | $collapsableLink = ''; |
||
| 1784 | if ($collapsable) { |
||
| 1785 | $collapsableLink = api_get_path(WEB_PATH).'user_portal.php?action=collapse_session'; |
||
| 1786 | } |
||
| 1787 | |||
| 1788 | $extraFieldValue = new ExtraFieldValue('session'); |
||
| 1789 | if ($showSessions) { |
||
| 1790 | $coursesListSessionStyle = api_get_configuration_value('courses_list_session_title_link'); |
||
| 1791 | $coursesListSessionStyle = $coursesListSessionStyle === false ? 1 : $coursesListSessionStyle; |
||
| 1792 | if (api_is_drh()) { |
||
| 1793 | $coursesListSessionStyle = 1; |
||
| 1794 | } |
||
| 1795 | |||
| 1796 | $portalShowDescription = api_get_setting('show_session_description') === 'true'; |
||
| 1797 | |||
| 1798 | // Declared listSession variable |
||
| 1799 | $listSession = []; |
||
| 1800 | // Get timestamp in UTC to compare to DB values (in UTC by convention) |
||
| 1801 | $session_now = strtotime(api_get_utc_datetime(time())); |
||
| 1802 | if (is_array($session_categories)) { |
||
| 1803 | foreach ($session_categories as $session_category) { |
||
| 1804 | $session_category_id = $session_category['session_category']['id']; |
||
| 1805 | // Sessions and courses that are not in a session category |
||
| 1806 | if (empty($session_category_id) && |
||
| 1807 | isset($session_category['sessions']) |
||
| 1808 | ) { |
||
| 1809 | // Independent sessions |
||
| 1810 | foreach ($session_category['sessions'] as $session) { |
||
| 1811 | $session_id = $session['session_id']; |
||
| 1812 | |||
| 1813 | // Don't show empty sessions. |
||
| 1814 | if (count($session['courses']) < 1) { |
||
| 1815 | continue; |
||
| 1816 | } |
||
| 1817 | |||
| 1818 | // Courses inside the current session. |
||
| 1819 | $date_session_start = $session['access_start_date']; |
||
| 1820 | $date_session_end = $session['access_end_date']; |
||
| 1821 | $coachAccessStartDate = $session['coach_access_start_date']; |
||
| 1822 | $coachAccessEndDate = $session['coach_access_end_date']; |
||
| 1823 | $count_courses_session = 0; |
||
| 1824 | |||
| 1825 | // Loop course content |
||
| 1826 | $html_courses_session = []; |
||
| 1827 | $atLeastOneCourseIsVisible = false; |
||
| 1828 | $markAsOld = false; |
||
| 1829 | $markAsFuture = false; |
||
| 1830 | |||
| 1831 | foreach ($session['courses'] as $course) { |
||
| 1832 | $is_coach_course = api_is_coach($session_id, $course['real_id']); |
||
| 1833 | $allowed_time = 0; |
||
| 1834 | $allowedEndTime = true; |
||
| 1835 | |||
| 1836 | if (!empty($date_session_start)) { |
||
| 1837 | if ($is_coach_course) { |
||
| 1838 | $allowed_time = api_strtotime($coachAccessStartDate); |
||
| 1839 | } else { |
||
| 1840 | $allowed_time = api_strtotime($date_session_start); |
||
| 1841 | } |
||
| 1842 | |||
| 1843 | $endSessionToTms = null; |
||
| 1844 | if (!isset($_GET['history'])) { |
||
| 1845 | if (!empty($date_session_end)) { |
||
| 1846 | if ($is_coach_course) { |
||
| 1847 | // if coach end date is empty we use the default end date |
||
| 1848 | if (empty($coachAccessEndDate)) { |
||
| 1849 | $endSessionToTms = api_strtotime($date_session_end); |
||
| 1850 | if ($session_now > $endSessionToTms) { |
||
| 1851 | $allowedEndTime = false; |
||
| 1852 | } |
||
| 1853 | } else { |
||
| 1854 | $endSessionToTms = api_strtotime($coachAccessEndDate); |
||
| 1855 | if ($session_now > $endSessionToTms) { |
||
| 1856 | $allowedEndTime = false; |
||
| 1857 | } |
||
| 1858 | } |
||
| 1859 | } else { |
||
| 1860 | $endSessionToTms = api_strtotime($date_session_end); |
||
| 1861 | if ($session_now > $endSessionToTms) { |
||
| 1862 | $allowedEndTime = false; |
||
| 1863 | } |
||
| 1864 | } |
||
| 1865 | } |
||
| 1866 | } |
||
| 1867 | } |
||
| 1868 | |||
| 1869 | if ($showAllSessions) { |
||
| 1870 | if ($allowed_time < $session_now && $allowedEndTime === false) { |
||
| 1871 | $markAsOld = true; |
||
| 1872 | } |
||
| 1873 | if ($allowed_time > $session_now && $endSessionToTms > $session_now) { |
||
| 1874 | $markAsFuture = true; |
||
| 1875 | } |
||
| 1876 | $allowedEndTime = true; |
||
| 1877 | $allowed_time = 0; |
||
| 1878 | } |
||
| 1879 | |||
| 1880 | if ($session_now >= $allowed_time && $allowedEndTime) { |
||
| 1881 | // Read only and accessible. |
||
| 1882 | $atLeastOneCourseIsVisible = true; |
||
| 1883 | if (api_get_setting('hide_courses_in_sessions') === 'false') { |
||
| 1884 | $courseUserHtml = CourseManager::get_logged_user_course_html( |
||
| 1885 | $course, |
||
| 1886 | $session_id, |
||
| 1887 | 'session_course_item', |
||
| 1888 | true, |
||
| 1889 | $this->load_directories_preview |
||
| 1890 | ); |
||
| 1891 | if (isset($courseUserHtml[1])) { |
||
| 1892 | $course_session = $courseUserHtml[1]; |
||
| 1893 | $course_session['skill'] = isset($courseUserHtml['skill']) ? $courseUserHtml['skill'] : ''; |
||
| 1894 | |||
| 1895 | // Course option (show student progress) |
||
| 1896 | // This code will add new variables (Progress, Score, Certificate) |
||
| 1897 | if ($studentInfoProgress || $studentInfoScore || $studentInfoCertificate) { |
||
| 1898 | if ($studentInfoProgress) { |
||
| 1899 | $progress = Tracking::get_avg_student_progress( |
||
| 1900 | $user_id, |
||
| 1901 | $course['course_code'], |
||
| 1902 | [], |
||
| 1903 | $session_id |
||
| 1904 | ); |
||
| 1905 | $course_session['student_info']['progress'] = $progress === false ? null : $progress; |
||
| 1906 | } |
||
| 1907 | |||
| 1908 | if ($studentInfoScore) { |
||
| 1909 | $percentage_score = Tracking::get_avg_student_score( |
||
| 1910 | $user_id, |
||
| 1911 | $course['course_code'], |
||
| 1912 | [], |
||
| 1913 | $session_id |
||
| 1914 | ); |
||
| 1915 | $course_session['student_info']['score'] = $percentage_score; |
||
| 1916 | } |
||
| 1917 | |||
| 1918 | if ($studentInfoCertificate) { |
||
| 1919 | $category = Category::load( |
||
| 1920 | null, |
||
| 1921 | null, |
||
| 1922 | $course['course_code'], |
||
| 1923 | null, |
||
| 1924 | null, |
||
| 1925 | $session_id |
||
| 1926 | ); |
||
| 1927 | $course_session['student_info']['certificate'] = null; |
||
| 1928 | if (isset($category[0])) { |
||
| 1929 | if ($category[0]->is_certificate_available($user_id)) { |
||
| 1930 | $course_session['student_info']['certificate'] = Display::label( |
||
| 1931 | get_lang('Yes'), |
||
| 1932 | 'success' |
||
| 1933 | ); |
||
| 1934 | } else { |
||
| 1935 | $course_session['student_info']['certificate'] = Display::label( |
||
| 1936 | get_lang('No') |
||
| 1937 | ); |
||
| 1938 | } |
||
| 1939 | } |
||
| 1940 | } |
||
| 1941 | } |
||
| 1942 | |||
| 1943 | $course_session['extrafields'] = CourseManager::getExtraFieldsToBePresented($course['real_id']); |
||
| 1944 | |||
| 1945 | if (api_get_configuration_value( |
||
| 1946 | 'enable_unsubscribe_button_on_my_course_page' |
||
| 1947 | ) |
||
| 1948 | && '1' === $course['unsubscribe'] |
||
| 1949 | ) { |
||
| 1950 | $course_session['unregister_button'] = |
||
| 1951 | CoursesAndSessionsCatalog::return_unregister_button( |
||
| 1952 | ['code' => $course['course_code']], |
||
| 1953 | Security::get_existing_token(), |
||
| 1954 | '', |
||
| 1955 | '' |
||
| 1956 | ); |
||
| 1957 | } |
||
| 1958 | |||
| 1959 | $html_courses_session[] = $course_session; |
||
| 1960 | } |
||
| 1961 | } |
||
| 1962 | $count_courses_session++; |
||
| 1963 | } |
||
| 1964 | } |
||
| 1965 | |||
| 1966 | // No courses to show. |
||
| 1967 | if ($atLeastOneCourseIsVisible === false) { |
||
| 1968 | if (empty($html_courses_session)) { |
||
| 1969 | continue; |
||
| 1970 | } |
||
| 1971 | } |
||
| 1972 | |||
| 1973 | if ($count_courses_session > 0) { |
||
| 1974 | $params = [ |
||
| 1975 | 'id' => $session_id, |
||
| 1976 | ]; |
||
| 1977 | $session_box = Display::getSessionTitleBox($session_id); |
||
| 1978 | $coachId = $session_box['id_coach']; |
||
| 1979 | $imageField = $extraFieldValue->get_values_by_handler_and_field_variable( |
||
| 1980 | $session_id, |
||
| 1981 | 'image' |
||
| 1982 | ); |
||
| 1983 | |||
| 1984 | $params['category_id'] = $session_box['category_id']; |
||
| 1985 | $params['title'] = $session_box['title']; |
||
| 1986 | $params['id_coach'] = $coachId; |
||
| 1987 | $params['coach_url'] = api_get_path(WEB_AJAX_PATH). |
||
| 1988 | 'user_manager.ajax.php?a=get_user_popup&user_id='.$coachId; |
||
| 1989 | $params['coach_name'] = !empty($session_box['coach']) ? $session_box['coach'] : null; |
||
| 1990 | $params['coach_avatar'] = UserManager::getUserPicture( |
||
| 1991 | $coachId, |
||
| 1992 | USER_IMAGE_SIZE_SMALL |
||
| 1993 | ); |
||
| 1994 | $params['date'] = $session_box['dates']; |
||
| 1995 | $params['image'] = isset($imageField['value']) ? $imageField['value'] : null; |
||
| 1996 | $params['duration'] = isset($session_box['duration']) ? ' '.$session_box['duration'] : null; |
||
| 1997 | $params['show_actions'] = SessionManager::cantEditSession($session_id); |
||
| 1998 | |||
| 1999 | if ($collapsable) { |
||
| 2000 | $collapsableData = SessionManager::getCollapsableData( |
||
| 2001 | $user_id, |
||
| 2002 | $session_id, |
||
| 2003 | $extraFieldValue, |
||
| 2004 | $collapsableLink |
||
| 2005 | ); |
||
| 2006 | $params['collapsed'] = $collapsableData['collapsed']; |
||
| 2007 | $params['collapsable_link'] = $collapsableData['collapsable_link']; |
||
| 2008 | } |
||
| 2009 | |||
| 2010 | $params['show_description'] = $session_box['show_description'] == 1 && $portalShowDescription; |
||
| 2011 | $params['description'] = $session_box['description']; |
||
| 2012 | $params['visibility'] = $session_box['visibility']; |
||
| 2013 | $params['show_simple_session_info'] = $showSimpleSessionInfo; |
||
| 2014 | $params['course_list_session_style'] = $coursesListSessionStyle; |
||
| 2015 | $params['num_users'] = $session_box['num_users']; |
||
| 2016 | $params['num_courses'] = $session_box['num_courses']; |
||
| 2017 | $params['course_categories'] = CourseManager::getCourseCategoriesFromCourseList( |
||
| 2018 | $html_courses_session |
||
| 2019 | ); |
||
| 2020 | $params['courses'] = $html_courses_session; |
||
| 2021 | $params['is_old'] = $markAsOld; |
||
| 2022 | $params['is_future'] = $markAsFuture; |
||
| 2023 | |||
| 2024 | if ($showSimpleSessionInfo) { |
||
| 2025 | $params['subtitle'] = self::getSimpleSessionDetails( |
||
| 2026 | $session_box['coach'], |
||
| 2027 | $session_box['dates'], |
||
| 2028 | isset($session_box['duration']) ? $session_box['duration'] : null |
||
| 2029 | ); |
||
| 2030 | } |
||
| 2031 | |||
| 2032 | if ($gameModeIsActive) { |
||
| 2033 | $params['stars'] = GamificationUtils::getSessionStars( |
||
| 2034 | $params['id'], |
||
| 2035 | $this->user_id |
||
| 2036 | ); |
||
| 2037 | $params['progress'] = GamificationUtils::getSessionProgress( |
||
| 2038 | $params['id'], |
||
| 2039 | $this->user_id |
||
| 2040 | ); |
||
| 2041 | $params['points'] = GamificationUtils::getSessionPoints( |
||
| 2042 | $params['id'], |
||
| 2043 | $this->user_id |
||
| 2044 | ); |
||
| 2045 | } |
||
| 2046 | $listSession[] = $params; |
||
| 2047 | $sessionCount++; |
||
| 2048 | } |
||
| 2049 | } |
||
| 2050 | } else { |
||
| 2051 | // All sessions included in |
||
| 2052 | $count_courses_session = 0; |
||
| 2053 | $html_sessions = ''; |
||
| 2054 | if (isset($session_category['sessions'])) { |
||
| 2055 | foreach ($session_category['sessions'] as $session) { |
||
| 2056 | $session_id = $session['session_id']; |
||
| 2057 | |||
| 2058 | // Don't show empty sessions. |
||
| 2059 | if (count($session['courses']) < 1) { |
||
| 2060 | continue; |
||
| 2061 | } |
||
| 2062 | |||
| 2063 | $date_session_start = $session['access_start_date']; |
||
| 2064 | $date_session_end = $session['access_end_date']; |
||
| 2065 | $coachAccessStartDate = $session['coach_access_start_date']; |
||
| 2066 | $coachAccessEndDate = $session['coach_access_end_date']; |
||
| 2067 | $html_courses_session = []; |
||
| 2068 | $count = 0; |
||
| 2069 | $markAsOld = false; |
||
| 2070 | $markAsFuture = false; |
||
| 2071 | |||
| 2072 | foreach ($session['courses'] as $course) { |
||
| 2073 | $is_coach_course = api_is_coach($session_id, $course['real_id']); |
||
| 2074 | $allowed_time = 0; |
||
| 2075 | $allowedEndTime = true; |
||
| 2076 | |||
| 2077 | if (!empty($date_session_start)) { |
||
| 2078 | if ($is_coach_course) { |
||
| 2079 | $allowed_time = api_strtotime($coachAccessStartDate); |
||
| 2080 | } else { |
||
| 2081 | $allowed_time = api_strtotime($date_session_start); |
||
| 2082 | } |
||
| 2083 | |||
| 2084 | if (!isset($_GET['history'])) { |
||
| 2085 | if (!empty($date_session_end)) { |
||
| 2086 | if ($is_coach_course) { |
||
| 2087 | // if coach end date is empty we use the default end date |
||
| 2088 | if (empty($coachAccessEndDate)) { |
||
| 2089 | $endSessionToTms = api_strtotime($date_session_end); |
||
| 2090 | if ($session_now > $endSessionToTms) { |
||
| 2091 | $allowedEndTime = false; |
||
| 2092 | } |
||
| 2093 | } else { |
||
| 2094 | $endSessionToTms = api_strtotime($coachAccessEndDate); |
||
| 2095 | if ($session_now > $endSessionToTms) { |
||
| 2096 | $allowedEndTime = false; |
||
| 2097 | } |
||
| 2098 | } |
||
| 2099 | } else { |
||
| 2100 | $endSessionToTms = api_strtotime($date_session_end); |
||
| 2101 | if ($session_now > $endSessionToTms) { |
||
| 2102 | $allowedEndTime = false; |
||
| 2103 | } |
||
| 2104 | } |
||
| 2105 | } |
||
| 2106 | } |
||
| 2107 | } |
||
| 2108 | |||
| 2109 | if ($showAllSessions) { |
||
| 2110 | if ($allowed_time < $session_now && $allowedEndTime == false) { |
||
| 2111 | $markAsOld = true; |
||
| 2112 | } |
||
| 2113 | if ($allowed_time > $session_now && $endSessionToTms > $session_now) { |
||
| 2114 | $markAsFuture = true; |
||
| 2115 | } |
||
| 2116 | $allowedEndTime = true; |
||
| 2117 | $allowed_time = 0; |
||
| 2118 | } |
||
| 2119 | |||
| 2120 | if ($session_now >= $allowed_time && $allowedEndTime) { |
||
| 2121 | if (api_get_setting('hide_courses_in_sessions') === 'false') { |
||
| 2122 | $c = CourseManager::get_logged_user_course_html( |
||
| 2123 | $course, |
||
| 2124 | $session_id, |
||
| 2125 | 'session_course_item' |
||
| 2126 | ); |
||
| 2127 | if (isset($c[1])) { |
||
| 2128 | $html_courses_session[] = $c[1]; |
||
| 2129 | } |
||
| 2130 | } |
||
| 2131 | $count_courses_session++; |
||
| 2132 | $count++; |
||
| 2133 | } |
||
| 2134 | } |
||
| 2135 | |||
| 2136 | $sessionParams = []; |
||
| 2137 | // Category |
||
| 2138 | if ($count > 0) { |
||
| 2139 | $session_box = Display::getSessionTitleBox($session_id); |
||
| 2140 | $sessionParams[0]['id'] = $session_id; |
||
| 2141 | $sessionParams[0]['date'] = $session_box['dates']; |
||
| 2142 | $sessionParams[0]['duration'] = isset($session_box['duration']) ? ' '.$session_box['duration'] : null; |
||
| 2143 | $sessionParams[0]['course_list_session_style'] = $coursesListSessionStyle; |
||
| 2144 | $sessionParams[0]['title'] = $session_box['title']; |
||
| 2145 | $sessionParams[0]['subtitle'] = (!empty($session_box['coach']) ? $session_box['coach'].' | ' : '').$session_box['dates']; |
||
| 2146 | $sessionParams[0]['show_actions'] = SessionManager::cantEditSession($session_id); |
||
| 2147 | $sessionParams[0]['courses'] = $html_courses_session; |
||
| 2148 | $sessionParams[0]['show_simple_session_info'] = $showSimpleSessionInfo; |
||
| 2149 | $sessionParams[0]['coach_name'] = !empty($session_box['coach']) ? $session_box['coach'] : null; |
||
| 2150 | $sessionParams[0]['is_old'] = $markAsOld; |
||
| 2151 | $sessionParams[0]['is_future'] = $markAsFuture; |
||
| 2152 | |||
| 2153 | if ($collapsable) { |
||
| 2154 | $collapsableData = SessionManager::getCollapsableData( |
||
| 2155 | $user_id, |
||
| 2156 | $session_id, |
||
| 2157 | $extraFieldValue, |
||
| 2158 | $collapsableLink |
||
| 2159 | ); |
||
| 2160 | $sessionParams[0]['collapsable_link'] = $collapsableData['collapsable_link']; |
||
| 2161 | $sessionParams[0]['collapsed'] = $collapsableData['collapsed']; |
||
| 2162 | } |
||
| 2163 | |||
| 2164 | if ($showSimpleSessionInfo) { |
||
| 2165 | $sessionParams[0]['subtitle'] = self::getSimpleSessionDetails( |
||
| 2166 | $session_box['coach'], |
||
| 2167 | $session_box['dates'], |
||
| 2168 | isset($session_box['duration']) ? $session_box['duration'] : null |
||
| 2169 | ); |
||
| 2170 | } |
||
| 2171 | |||
| 2172 | $this->tpl->assign('session', $sessionParams); |
||
| 2173 | $this->tpl->assign('show_tutor', api_get_setting('show_session_coach') === 'true'); |
||
| 2174 | $this->tpl->assign('gamification_mode', $gameModeIsActive); |
||
| 2175 | $this->tpl->assign( |
||
| 2176 | 'remove_session_url', |
||
| 2177 | api_get_configuration_value('remove_session_url') |
||
| 2178 | ); |
||
| 2179 | $this->tpl->assign( |
||
| 2180 | 'hide_session_dates_in_user_portal', |
||
| 2181 | api_get_configuration_value('hide_session_dates_in_user_portal') |
||
| 2182 | ); |
||
| 2183 | |||
| 2184 | if ($viewGridCourses) { |
||
| 2185 | $html_sessions .= $this->tpl->fetch( |
||
| 2186 | $this->tpl->get_template('/user_portal/grid_session.tpl') |
||
| 2187 | ); |
||
| 2188 | } else { |
||
| 2189 | $html_sessions .= $this->tpl->fetch( |
||
| 2190 | $this->tpl->get_template('user_portal/classic_session.tpl') |
||
| 2191 | ); |
||
| 2192 | } |
||
| 2193 | $sessionCount++; |
||
| 2194 | } |
||
| 2195 | } |
||
| 2196 | } |
||
| 2197 | |||
| 2198 | if ($count_courses_session > 0) { |
||
| 2199 | $categoryParams = [ |
||
| 2200 | 'id' => $session_category['session_category']['id'], |
||
| 2201 | 'title' => $session_category['session_category']['name'], |
||
| 2202 | 'show_actions' => api_is_platform_admin(), |
||
| 2203 | 'subtitle' => '', |
||
| 2204 | 'sessions' => $html_sessions, |
||
| 2205 | ]; |
||
| 2206 | |||
| 2207 | $session_category_start_date = $session_category['session_category']['date_start']; |
||
| 2208 | $session_category_end_date = $session_category['session_category']['date_end']; |
||
| 2209 | if ($session_category_start_date == '0000-00-00') { |
||
| 2210 | $session_category_start_date = ''; |
||
| 2211 | } |
||
| 2212 | |||
| 2213 | if ($session_category_end_date == '0000-00-00') { |
||
| 2214 | $session_category_end_date = ''; |
||
| 2215 | } |
||
| 2216 | |||
| 2217 | if (!empty($session_category_start_date) && |
||
| 2218 | !empty($session_category_end_date) |
||
| 2219 | ) { |
||
| 2220 | $categoryParams['subtitle'] = sprintf( |
||
| 2221 | get_lang('FromDateXToDateY'), |
||
| 2222 | $session_category_start_date, |
||
| 2223 | $session_category_end_date |
||
| 2224 | ); |
||
| 2225 | } else { |
||
| 2226 | if (!empty($session_category_start_date)) { |
||
| 2227 | $categoryParams['subtitle'] = get_lang('From').' '.$session_category_start_date; |
||
| 2228 | } |
||
| 2229 | |||
| 2230 | if (!empty($session_category_end_date)) { |
||
| 2231 | $categoryParams['subtitle'] = get_lang('Until').' '.$session_category_end_date; |
||
| 2232 | } |
||
| 2233 | } |
||
| 2234 | |||
| 2235 | $this->tpl->assign('session_category', $categoryParams); |
||
| 2236 | $sessions_with_category .= $this->tpl->fetch( |
||
| 2237 | $this->tpl->get_template('user_portal/session_category.tpl') |
||
| 2238 | ); |
||
| 2239 | } |
||
| 2240 | } |
||
| 2241 | } |
||
| 2242 | |||
| 2243 | $allCoursesInSessions = []; |
||
| 2244 | foreach ($listSession as $currentSession) { |
||
| 2245 | $coursesInSessions = $currentSession['courses']; |
||
| 2246 | unset($currentSession['courses']); |
||
| 2247 | foreach ($coursesInSessions as $coursesInSession) { |
||
| 2248 | $coursesInSession['session'] = $currentSession; |
||
| 2249 | $allCoursesInSessions[] = $coursesInSession; |
||
| 2250 | } |
||
| 2251 | } |
||
| 2252 | |||
| 2253 | $this->tpl->assign('all_courses', $allCoursesInSessions); |
||
| 2254 | $this->tpl->assign('session', $listSession); |
||
| 2255 | $this->tpl->assign('show_tutor', (api_get_setting('show_session_coach') === 'true' ? true : false)); |
||
| 2256 | $this->tpl->assign('gamification_mode', $gameModeIsActive); |
||
| 2257 | $this->tpl->assign('remove_session_url', api_get_configuration_value('remove_session_url')); |
||
| 2258 | $this->tpl->assign( |
||
| 2259 | 'hide_session_dates_in_user_portal', |
||
| 2260 | api_get_configuration_value('hide_session_dates_in_user_portal') |
||
| 2261 | ); |
||
| 2262 | |||
| 2263 | if ($viewGridCourses) { |
||
| 2264 | $sessions_with_no_category = $this->tpl->fetch( |
||
| 2265 | $this->tpl->get_template('/user_portal/grid_session.tpl') |
||
| 2266 | ); |
||
| 2267 | } else { |
||
| 2268 | $sessions_with_no_category = $this->tpl->fetch( |
||
| 2269 | $this->tpl->get_template('user_portal/classic_session.tpl') |
||
| 2270 | ); |
||
| 2271 | } |
||
| 2272 | } |
||
| 2273 | } |
||
| 2274 | |||
| 2275 | return [ |
||
| 2276 | 'courses' => $courseCompleteList, |
||
| 2277 | 'sessions' => $session_categories, |
||
| 2278 | 'html' => trim($specialCourseList.$sessions_with_category.$sessions_with_no_category.$listCourse), |
||
| 2279 | 'session_count' => $sessionCount, |
||
| 2280 | 'course_count' => $courseCount, |
||
| 2281 | ]; |
||
| 2547 |