Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 27... Línea 27...
27
 
27
 
28
if (!defined('MOODLE_INTERNAL')) {
28
if (!defined('MOODLE_INTERNAL')) {
29
    die('Direct access to this script is forbidden.');    ///  It must be included from a Moodle page
29
    die('Direct access to this script is forbidden.');    ///  It must be included from a Moodle page
Línea -... Línea 30...
-
 
30
}
-
 
31
 
30
}
32
require_once(__DIR__ . '/deprecatedlib.php');
31
 
33
 
32
/**
34
/**
Línea 33... Línea 35...
33
 *  These are read by the administration component to provide default values
35
 *  These are read by the administration component to provide default values
Línea 1119... Línea 1121...
1119
     * @param   int                     $courseid The ID of the course the user wishes to view.
1121
     * @param   int                     $courseid The ID of the course the user wishes to view.
1120
     * @param   int                     $categoryid The ID of the category the user wishes to view
1122
     * @param   int                     $categoryid The ID of the category the user wishes to view
1121
     *                                  If a courseid is specified, this value is ignored.
1123
     *                                  If a courseid is specified, this value is ignored.
1122
     * @return  calendar_information
1124
     * @return  calendar_information
1123
     */
1125
     */
1124
    public static function create($time, int $courseid, int $categoryid = null): calendar_information {
1126
    public static function create($time, int $courseid, ?int $categoryid = null): calendar_information {
1125
        $calendar = new static(0, 0, 0, $time);
1127
        $calendar = new static(0, 0, 0, $time);
1126
        if ($courseid != SITEID && !empty($courseid)) {
1128
        if ($courseid != SITEID && !empty($courseid)) {
1127
            // Course ID must be valid and existing.
1129
            // Course ID must be valid and existing.
1128
            $course = get_course($courseid);
1130
            $course = get_course($courseid);
1129
            $calendar->context = context_course::instance($course->id);
1131
            $calendar->context = context_course::instance($course->id);
Línea 1176... Línea 1178...
1176
 
1178
 
1177
        return $this;
1179
        return $this;
Línea 1178... Línea 1180...
1178
    }
1180
    }
1179
 
-
 
1180
    /**
-
 
1181
     * Initialize calendar information
1181
 
1182
     *
-
 
1183
     * @deprecated 3.4
-
 
1184
     * @param stdClass $course object
-
 
1185
     * @param array $coursestoload An array of courses [$course->id => $course]
1182
    /**
1186
     * @param bool $ignorefilters options to use filter
1183
     * @deprecated 3.4
1187
     */
-
 
1188
    public function prepare_for_view(stdClass $course, array $coursestoload, $ignorefilters = false) {
1184
     */
1189
        debugging('The prepare_for_view() function has been deprecated. Please update your code to use set_sources()',
1185
    #[\core\attribute\deprecated('prepare_for_view', since: '3.4', mdl: 'MDL-59890', final: true)]
1190
                DEBUG_DEVELOPER);
1186
    public function prepare_for_view() {
Línea 1191... Línea 1187...
1191
        $this->set_sources($course, $coursestoload);
1187
        \core\deprecation::emit_deprecation([self::class, __FUNCTION__]);
1192
    }
1188
    }
1193
 
1189
 
Línea 1199... Línea 1195...
1199
     *
1195
     *
1200
     * @param   stdClass    $course The current course being viewed.
1196
     * @param   stdClass    $course The current course being viewed.
1201
     * @param   stdClass[]  $courses The list of all courses currently accessible.
1197
     * @param   stdClass[]  $courses The list of all courses currently accessible.
1202
     * @param   stdClass    $category The current category to show.
1198
     * @param   stdClass    $category The current category to show.
1203
     */
1199
     */
1204
    public function set_sources(stdClass $course, array $courses, stdClass $category = null) {
1200
    public function set_sources(stdClass $course, array $courses, ?stdClass $category = null) {
1205
        global $USER;
1201
        global $USER;
Línea 1206... Línea 1202...
1206
 
1202
 
1207
        // A cousre must always be specified.
1203
        // A cousre must always be specified.
1208
        $this->course = $course;
1204
        $this->course = $course;
Línea 1513... Línea 1509...
1513
    $calendartype = \core_calendar\type_factory::get_calendar_instance();
1509
    $calendartype = \core_calendar\type_factory::get_calendar_instance();
1514
    return $calendartype->get_starting_weekday();
1510
    return $calendartype->get_starting_weekday();
1515
}
1511
}
Línea 1516... Línea 1512...
1516
 
1512
 
1517
/**
-
 
1518
 * Get a HTML link to a course.
-
 
1519
 *
-
 
1520
 * @param int|stdClass $course the course id or course object
-
 
1521
 * @return string a link to the course (as HTML); empty if the course id is invalid
-
 
1522
 */
-
 
1523
function calendar_get_courselink($course) {
-
 
1524
    if (!$course) {
-
 
1525
        return '';
-
 
1526
    }
-
 
1527
 
-
 
1528
    if (!is_object($course)) {
-
 
1529
        $course = calendar_get_course_cached($coursecache, $course);
-
 
1530
    }
-
 
1531
    $context = \context_course::instance($course->id);
-
 
1532
    $fullname = format_string($course->fullname, true, array('context' => $context));
-
 
1533
    $url = new \moodle_url('/course/view.php', array('id' => $course->id));
-
 
1534
    $link = \html_writer::link($url, $fullname);
-
 
1535
 
-
 
1536
    return $link;
-
 
1537
}
-
 
1538
 
-
 
1539
/**
1513
/**
1540
 * Get current module cache.
1514
 * Get current module cache.
1541
 *
1515
 *
1542
 * Only use this method if you do not know courseid. Otherwise use:
1516
 * Only use this method if you do not know courseid. Otherwise use:
1543
 * get_fast_modinfo($courseid)->instances[$modulename][$instance]
1517
 * get_fast_modinfo($courseid)->instances[$modulename][$instance]
Línea 1582... Línea 1556...
1582
    }
1556
    }
1583
    return $groupscache[$groupid];
1557
    return $groupscache[$groupid];
1584
}
1558
}
Línea 1585... Línea 1559...
1585
 
1559
 
1586
/**
-
 
1587
 * Add calendar event metadata
-
 
1588
 *
-
 
1589
 * @deprecated since 3.9
-
 
1590
 *
-
 
1591
 * @param stdClass $event event info
-
 
1592
 * @return stdClass $event metadata
-
 
1593
 */
-
 
1594
function calendar_add_event_metadata($event) {
-
 
1595
    debugging('This function is no longer used', DEBUG_DEVELOPER);
-
 
1596
    global $CFG, $OUTPUT;
-
 
1597
 
-
 
1598
    // Support multilang in event->name.
-
 
1599
    $event->name = format_string($event->name, true);
-
 
1600
 
-
 
1601
    if (!empty($event->modulename)) { // Activity event.
-
 
1602
        // The module name is set. I will assume that it has to be displayed, and
-
 
1603
        // also that it is an automatically-generated event. And of course that the
-
 
1604
        // instace id and modulename are set correctly.
-
 
1605
        $instances = get_fast_modinfo($event->courseid)->get_instances_of($event->modulename);
-
 
1606
        if (!array_key_exists($event->instance, $instances)) {
-
 
1607
            return;
-
 
1608
        }
-
 
1609
        $module = $instances[$event->instance];
-
 
1610
 
-
 
1611
        $modulename = $module->get_module_type_name(false);
-
 
1612
        if (get_string_manager()->string_exists($event->eventtype, $event->modulename)) {
-
 
1613
            // Will be used as alt text if the event icon.
-
 
1614
            $eventtype = get_string($event->eventtype, $event->modulename);
-
 
1615
        } else {
-
 
1616
            $eventtype = '';
-
 
1617
        }
-
 
1618
 
-
 
1619
        $event->icon = '<img src="' . s($module->get_icon_url()) . '" alt="' . s($eventtype) .
-
 
1620
            '" title="' . s($modulename) . '" class="icon" />';
-
 
1621
        $event->referer = html_writer::link($module->url, $event->name);
-
 
1622
        $event->courselink = calendar_get_courselink($module->get_course());
-
 
1623
        $event->cmid = $module->id;
-
 
1624
    } else if ($event->courseid == SITEID) { // Site event.
-
 
1625
        $event->icon = '<img src="' . $OUTPUT->image_url('i/siteevent') . '" alt="' .
-
 
1626
            get_string('siteevent', 'calendar') . '" class="icon" />';
-
 
1627
        $event->cssclass = 'calendar_event_site';
-
 
1628
    } else if ($event->courseid != 0 && $event->courseid != SITEID && $event->groupid == 0) { // Course event.
-
 
1629
        $event->icon = '<img src="' . $OUTPUT->image_url('i/courseevent') . '" alt="' .
-
 
1630
            get_string('courseevent', 'calendar') . '" class="icon" />';
-
 
1631
        $event->courselink = calendar_get_courselink($event->courseid);
-
 
1632
        $event->cssclass = 'calendar_event_course';
-
 
1633
    } else if ($event->groupid) { // Group event.
-
 
1634
        if ($group = calendar_get_group_cached($event->groupid)) {
-
 
1635
            $groupname = format_string($group->name, true, \context_course::instance($group->courseid));
-
 
1636
        } else {
-
 
1637
            $groupname = '';
-
 
1638
        }
-
 
1639
        $event->icon = \html_writer::empty_tag('image', array('src' => $OUTPUT->image_url('i/groupevent'),
-
 
1640
            'alt' => get_string('groupevent', 'calendar'), 'title' => $groupname, 'class' => 'icon'));
-
 
1641
        $event->courselink = calendar_get_courselink($event->courseid) . ', ' . $groupname;
-
 
1642
        $event->cssclass = 'calendar_event_group';
-
 
1643
    } else if ($event->userid) { // User event.
-
 
1644
        $event->icon = '<img src="' . $OUTPUT->image_url('i/userevent') . '" alt="' .
-
 
1645
            get_string('userevent', 'calendar') . '" class="icon" />';
-
 
1646
        $event->cssclass = 'calendar_event_user';
-
 
1647
    }
-
 
1648
 
-
 
1649
    return $event;
-
 
1650
}
-
 
1651
 
-
 
1652
/**
1560
/**
1653
 * Get calendar events by id.
1561
 * Get calendar events by id.
1654
 *
1562
 *
1655
 * @since Moodle 2.5
1563
 * @since Moodle 2.5
1656
 * @param array $eventids list of event ids
1564
 * @param array $eventids list of event ids
Línea 1668... Línea 1576...
1668
 
1576
 
1669
    return $DB->get_records_select('event', $wheresql, $params);
1577
    return $DB->get_records_select('event', $wheresql, $params);
Línea 1670... Línea 1578...
1670
}
1578
}
1671
 
-
 
1672
/**
-
 
1673
 * Get control options for calendar.
-
 
1674
 *
-
 
1675
 * @deprecated since Moodle 4.3
-
 
1676
 * @param string $type of calendar
-
 
1677
 * @param array $data calendar information
-
 
1678
 * @return string $content return available control for the calendar in html
-
 
1679
 */
-
 
1680
function calendar_top_controls($type, $data) {
-
 
1681
    debugging(__FUNCTION__ . ' has been deprecated and should not be used anymore.', DEBUG_DEVELOPER);
-
 
1682
 
-
 
1683
    global $PAGE, $OUTPUT;
-
 
1684
 
-
 
1685
    // Get the calendar type we are using.
-
 
1686
    $calendartype = \core_calendar\type_factory::get_calendar_instance();
-
 
1687
 
-
 
1688
    $content = '';
-
 
1689
 
-
 
1690
    // Ensure course id passed if relevant.
-
 
1691
    $courseid = '';
-
 
1692
    if (!empty($data['id'])) {
-
 
1693
        $courseid = '&amp;course=' . $data['id'];
-
 
1694
    }
-
 
1695
 
-
 
1696
    // If we are passing a month and year then we need to convert this to a timestamp to
-
 
1697
    // support multiple calendars. No where in core should these be passed, this logic
-
 
1698
    // here is for third party plugins that may use this function.
-
 
1699
    if (!empty($data['m']) && !empty($date['y'])) {
-
 
1700
        if (!isset($data['d'])) {
-
 
1701
            $data['d'] = 1;
-
 
1702
        }
-
 
1703
        if (!checkdate($data['m'], $data['d'], $data['y'])) {
-
 
1704
            $time = time();
-
 
1705
        } else {
-
 
1706
            $time = make_timestamp($data['y'], $data['m'], $data['d']);
-
 
1707
        }
-
 
1708
    } else if (!empty($data['time'])) {
-
 
1709
        $time = $data['time'];
-
 
1710
    } else {
-
 
1711
        $time = time();
-
 
1712
    }
-
 
1713
 
-
 
1714
    // Get the date for the calendar type.
-
 
1715
    $date = $calendartype->timestamp_to_date_array($time);
-
 
1716
 
-
 
1717
    $urlbase = $PAGE->url;
-
 
1718
 
-
 
1719
    // We need to get the previous and next months in certain cases.
-
 
1720
    if ($type == 'frontpage' || $type == 'course' || $type == 'month') {
-
 
1721
        $prevmonth = calendar_sub_month($date['mon'], $date['year']);
-
 
1722
        $prevmonthtime = $calendartype->convert_to_gregorian($prevmonth[1], $prevmonth[0], 1);
-
 
1723
        $prevmonthtime = make_timestamp($prevmonthtime['year'], $prevmonthtime['month'], $prevmonthtime['day'],
-
 
1724
            $prevmonthtime['hour'], $prevmonthtime['minute']);
-
 
1725
 
-
 
1726
        $nextmonth = calendar_add_month($date['mon'], $date['year']);
-
 
1727
        $nextmonthtime = $calendartype->convert_to_gregorian($nextmonth[1], $nextmonth[0], 1);
-
 
1728
        $nextmonthtime = make_timestamp($nextmonthtime['year'], $nextmonthtime['month'], $nextmonthtime['day'],
-
 
1729
            $nextmonthtime['hour'], $nextmonthtime['minute']);
-
 
1730
    }
-
 
1731
 
-
 
1732
    switch ($type) {
-
 
1733
        case 'frontpage':
-
 
1734
            $prevlink = calendar_get_link_previous(get_string('monthprev', 'calendar'), $urlbase, false, false, false,
-
 
1735
                true, $prevmonthtime);
-
 
1736
            $nextlink = calendar_get_link_next(get_string('monthnext', 'calendar'), $urlbase, false, false, false, true,
-
 
1737
                $nextmonthtime);
-
 
1738
            $calendarlink = calendar_get_link_href(new \moodle_url(CALENDAR_URL . 'view.php', array('view' => 'month')),
-
 
1739
                false, false, false, $time);
-
 
1740
 
-
 
1741
            if (!empty($data['id'])) {
-
 
1742
                $calendarlink->param('course', $data['id']);
-
 
1743
            }
-
 
1744
 
-
 
1745
            $right = $nextlink;
-
 
1746
 
-
 
1747
            $content .= \html_writer::start_tag('div', array('class' => 'calendar-controls'));
-
 
1748
            $content .= $prevlink . '<span class="hide"> | </span>';
-
 
1749
            $content .= \html_writer::tag('span', \html_writer::link($calendarlink,
-
 
1750
                userdate($time, get_string('strftimemonthyear')), array('title' => get_string('monththis', 'calendar'))
-
 
1751
            ), array('class' => 'current'));
-
 
1752
            $content .= '<span class="hide"> | </span>' . $right;
-
 
1753
            $content .= "<span class=\"clearer\"><!-- --></span>\n";
-
 
1754
            $content .= \html_writer::end_tag('div');
-
 
1755
 
-
 
1756
            break;
-
 
1757
        case 'course':
-
 
1758
            $prevlink = calendar_get_link_previous(get_string('monthprev', 'calendar'), $urlbase, false, false, false,
-
 
1759
                true, $prevmonthtime);
-
 
1760
            $nextlink = calendar_get_link_next(get_string('monthnext', 'calendar'), $urlbase, false, false, false,
-
 
1761
                true, $nextmonthtime);
-
 
1762
            $calendarlink = calendar_get_link_href(new \moodle_url(CALENDAR_URL . 'view.php', array('view' => 'month')),
-
 
1763
                false, false, false, $time);
-
 
1764
 
-
 
1765
            if (!empty($data['id'])) {
-
 
1766
                $calendarlink->param('course', $data['id']);
-
 
1767
            }
-
 
1768
 
-
 
1769
            $content .= \html_writer::start_tag('div', array('class' => 'calendar-controls'));
-
 
1770
            $content .= $prevlink . '<span class="hide"> | </span>';
-
 
1771
            $content .= \html_writer::tag('span', \html_writer::link($calendarlink,
-
 
1772
                userdate($time, get_string('strftimemonthyear')), array('title' => get_string('monththis', 'calendar'))
-
 
1773
            ), array('class' => 'current'));
-
 
1774
            $content .= '<span class="hide"> | </span>' . $nextlink;
-
 
1775
            $content .= "<span class=\"clearer\"><!-- --></span>";
-
 
1776
            $content .= \html_writer::end_tag('div');
-
 
1777
            break;
-
 
1778
        case 'upcoming':
-
 
1779
            $calendarlink = calendar_get_link_href(new \moodle_url(CALENDAR_URL . 'view.php', array('view' => 'upcoming')),
-
 
1780
                false, false, false, $time);
-
 
1781
            if (!empty($data['id'])) {
-
 
1782
                $calendarlink->param('course', $data['id']);
-
 
1783
            }
-
 
1784
            $calendarlink = \html_writer::link($calendarlink, userdate($time, get_string('strftimemonthyear')));
-
 
1785
            $content .= \html_writer::tag('div', $calendarlink, array('class' => 'centered'));
-
 
1786
            break;
-
 
1787
        case 'display':
-
 
1788
            $calendarlink = calendar_get_link_href(new \moodle_url(CALENDAR_URL . 'view.php', array('view' => 'month')),
-
 
1789
                false, false, false, $time);
-
 
1790
            if (!empty($data['id'])) {
-
 
1791
                $calendarlink->param('course', $data['id']);
-
 
1792
            }
-
 
1793
            $calendarlink = \html_writer::link($calendarlink, userdate($time, get_string('strftimemonthyear')));
-
 
1794
            $content .= \html_writer::tag('h3', $calendarlink);
-
 
1795
            break;
-
 
1796
        case 'month':
-
 
1797
            $prevlink = calendar_get_link_previous(userdate($prevmonthtime, get_string('strftimemonthyear')),
-
 
1798
                'view.php?view=month' . $courseid . '&amp;', false, false, false, false, $prevmonthtime);
-
 
1799
            $nextlink = calendar_get_link_next(userdate($nextmonthtime, get_string('strftimemonthyear')),
-
 
1800
                'view.php?view=month' . $courseid . '&amp;', false, false, false, false, $nextmonthtime);
-
 
1801
 
-
 
1802
            $content .= \html_writer::start_tag('div', array('class' => 'calendar-controls'));
-
 
1803
            $content .= $prevlink . '<span class="hide"> | </span>';
-
 
1804
            $content .= $OUTPUT->heading(userdate($time, get_string('strftimemonthyear')), 2, 'current');
-
 
1805
            $content .= '<span class="hide"> | </span>' . $nextlink;
-
 
1806
            $content .= '<span class="clearer"><!-- --></span>';
-
 
1807
            $content .= \html_writer::end_tag('div')."\n";
-
 
1808
            break;
-
 
1809
        case 'day':
-
 
1810
            $days = calendar_get_days();
-
 
1811
 
-
 
1812
            $prevtimestamp = strtotime('-1 day', $time);
-
 
1813
            $nexttimestamp = strtotime('+1 day', $time);
-
 
1814
 
-
 
1815
            $prevdate = $calendartype->timestamp_to_date_array($prevtimestamp);
-
 
1816
            $nextdate = $calendartype->timestamp_to_date_array($nexttimestamp);
-
 
1817
 
-
 
1818
            $prevname = $days[$prevdate['wday']]['fullname'];
-
 
1819
            $nextname = $days[$nextdate['wday']]['fullname'];
-
 
1820
            $prevlink = calendar_get_link_previous($prevname, 'view.php?view=day' . $courseid . '&amp;', false, false,
-
 
1821
                false, false, $prevtimestamp);
-
 
1822
            $nextlink = calendar_get_link_next($nextname, 'view.php?view=day' . $courseid . '&amp;', false, false, false,
-
 
1823
                false, $nexttimestamp);
-
 
1824
 
-
 
1825
            $content .= \html_writer::start_tag('div', array('class' => 'calendar-controls'));
-
 
1826
            $content .= $prevlink;
-
 
1827
            $content .= '<span class="hide"> | </span><span class="current">' .userdate($time,
-
 
1828
                    get_string('strftimedaydate')) . '</span>';
-
 
1829
            $content .= '<span class="hide"> | </span>' . $nextlink;
-
 
1830
            $content .= "<span class=\"clearer\"><!-- --></span>";
-
 
1831
            $content .= \html_writer::end_tag('div') . "\n";
-
 
1832
 
-
 
1833
            break;
-
 
1834
    }
-
 
1835
 
-
 
1836
    return $content;
-
 
1837
}
-
 
1838
 
-
 
1839
/**
-
 
1840
 * Return the representation day.
-
 
1841
 *
-
 
1842
 * @param int $tstamp Timestamp in GMT
-
 
1843
 * @param int|bool $now current Unix timestamp
-
 
1844
 * @param bool $usecommonwords
-
 
1845
 * @return string the formatted date/time
-
 
1846
 */
-
 
1847
function calendar_day_representation($tstamp, $now = false, $usecommonwords = true) {
-
 
1848
    static $shortformat;
-
 
1849
 
-
 
1850
    if (empty($shortformat)) {
-
 
1851
        $shortformat = get_string('strftimedayshort');
-
 
1852
    }
-
 
1853
 
-
 
1854
    if ($now === false) {
-
 
1855
        $now = time();
-
 
1856
    }
-
 
1857
 
-
 
1858
    // To have it in one place, if a change is needed.
-
 
1859
    $formal = userdate($tstamp, $shortformat);
-
 
1860
 
-
 
1861
    $datestamp = usergetdate($tstamp);
-
 
1862
    $datenow = usergetdate($now);
-
 
1863
 
-
 
1864
    if ($usecommonwords == false) {
-
 
1865
        // We don't want words, just a date.
-
 
1866
        return $formal;
-
 
1867
    } else if ($datestamp['year'] == $datenow['year'] && $datestamp['yday'] == $datenow['yday']) {
-
 
1868
        return get_string('today', 'calendar');
-
 
1869
    } else if (($datestamp['year'] == $datenow['year'] && $datestamp['yday'] == $datenow['yday'] - 1 ) ||
-
 
1870
        ($datestamp['year'] == $datenow['year'] - 1 && $datestamp['mday'] == 31 && $datestamp['mon'] == 12
-
 
1871
            && $datenow['yday'] == 1)) {
-
 
1872
        return get_string('yesterday', 'calendar');
-
 
1873
    } else if (($datestamp['year'] == $datenow['year'] && $datestamp['yday'] == $datenow['yday'] + 1 ) ||
-
 
1874
        ($datestamp['year'] == $datenow['year'] + 1 && $datenow['mday'] == 31 && $datenow['mon'] == 12
-
 
1875
            && $datestamp['yday'] == 1)) {
-
 
1876
        return get_string('tomorrow', 'calendar');
-
 
1877
    } else {
-
 
1878
        return $formal;
-
 
1879
    }
-
 
1880
}
-
 
1881
 
-
 
1882
/**
-
 
1883
 * return the formatted representation time.
-
 
1884
 *
-
 
1885
 
-
 
1886
 * @param int $time the timestamp in UTC, as obtained from the database
-
 
1887
 * @return string the formatted date/time
-
 
1888
 */
-
 
1889
function calendar_time_representation($time) {
-
 
1890
    static $langtimeformat = null;
-
 
1891
 
-
 
1892
    if ($langtimeformat === null) {
-
 
1893
        $langtimeformat = get_string('strftimetime');
-
 
1894
    }
-
 
1895
 
-
 
1896
    $timeformat = get_user_preferences('calendar_timeformat');
-
 
1897
    if (empty($timeformat)) {
-
 
1898
        $timeformat = get_config(null, 'calendar_site_timeformat');
-
 
1899
    }
-
 
1900
 
-
 
1901
    // Allow language customization of selected time format.
-
 
1902
    if ($timeformat === CALENDAR_TF_12) {
-
 
1903
        $timeformat = get_string('strftimetime12', 'langconfig');
-
 
1904
    } else if ($timeformat === CALENDAR_TF_24) {
-
 
1905
        $timeformat = get_string('strftimetime24', 'langconfig');
-
 
1906
    }
-
 
1907
 
-
 
1908
    return userdate($time, empty($timeformat) ? $langtimeformat : $timeformat);
-
 
1909
}
-
 
1910
 
1579
 
1911
/**
1580
/**
1912
 * Adds day, month, year arguments to a URL and returns a moodle_url object.
1581
 * Adds day, month, year arguments to a URL and returns a moodle_url object.
1913
 *
1582
 *
1914
 * @param string|moodle_url $linkbase
1583
 * @param string|moodle_url $linkbase
Línea 1932... Línea 1601...
1932
 
1601
 
1933
    return $linkbase;
1602
    return $linkbase;
Línea 1934... Línea 1603...
1934
}
1603
}
1935
 
-
 
1936
/**
-
 
1937
 * Build and return a previous month HTML link, with an arrow.
-
 
1938
 *
-
 
1939
 * @deprecated since Moodle 4.3
-
 
1940
 * @param string $text The text label.
-
 
1941
 * @param string|moodle_url $linkbase The URL stub.
-
 
1942
 * @param int $d The number of the date.
-
 
1943
 * @param int $m The number of the month.
-
 
1944
 * @param int $y year The number of the year.
-
 
1945
 * @param bool $accesshide Default visible, or hide from all except screenreaders.
-
 
1946
 * @param int $time the unixtime, used for multiple calendar support. The values $d,
-
 
1947
 *     $m and $y are kept for backwards compatibility.
-
 
1948
 * @return string HTML string.
-
 
1949
 */
-
 
1950
function calendar_get_link_previous($text, $linkbase, $d, $m, $y, $accesshide = false, $time = 0) {
-
 
1951
    debugging(__FUNCTION__ . ' has been deprecated and should not be used anymore.', DEBUG_DEVELOPER);
-
 
1952
 
-
 
1953
    $href = calendar_get_link_href(new \moodle_url($linkbase), $d, $m, $y, $time);
-
 
1954
 
-
 
1955
    if (empty($href)) {
-
 
1956
        return $text;
-
 
1957
    }
-
 
1958
 
-
 
1959
    $attrs = [
-
 
1960
        'data-time' => calendar_get_timestamp($d, $m, $y, $time),
-
 
1961
        'data-drop-zone' => 'nav-link',
-
 
1962
    ];
-
 
1963
 
-
 
1964
    return link_arrow_left($text, $href->out(false), $accesshide, 'previous', $attrs);
-
 
1965
}
-
 
1966
 
-
 
1967
/**
-
 
1968
 * Build and return a next month HTML link, with an arrow.
-
 
1969
 *
-
 
1970
 * @deprecated since Moodle 4.3
-
 
1971
 * @param string $text The text label.
-
 
1972
 * @param string|moodle_url $linkbase The URL stub.
-
 
1973
 * @param int $d the number of the Day
-
 
1974
 * @param int $m The number of the month.
-
 
1975
 * @param int $y The number of the year.
-
 
1976
 * @param bool $accesshide Default visible, or hide from all except screenreaders.
-
 
1977
 * @param int $time the unixtime, used for multiple calendar support. The values $d,
-
 
1978
 *     $m and $y are kept for backwards compatibility.
-
 
1979
 * @return string HTML string.
-
 
1980
 */
-
 
1981
function calendar_get_link_next($text, $linkbase, $d, $m, $y, $accesshide = false, $time = 0) {
-
 
1982
    debugging(__FUNCTION__ . ' has been deprecated and should not be used anymore.', DEBUG_DEVELOPER);
-
 
1983
 
-
 
1984
    $href = calendar_get_link_href(new \moodle_url($linkbase), $d, $m, $y, $time);
-
 
1985
 
-
 
1986
    if (empty($href)) {
-
 
1987
        return $text;
-
 
1988
    }
-
 
1989
 
-
 
1990
    $attrs = [
-
 
1991
        'data-time' => calendar_get_timestamp($d, $m, $y, $time),
-
 
1992
        'data-drop-zone' => 'nav-link',
-
 
1993
    ];
-
 
1994
 
-
 
1995
    return link_arrow_right($text, $href->out(false), $accesshide, 'next', $attrs);
-
 
1996
}
-
 
1997
 
1604
 
1998
/**
1605
/**
1999
 * Return the number of days in month.
1606
 * Return the number of days in month.
2000
 *
1607
 *
2001
 * @param int $month the number of the month.
1608
 * @param int $month the number of the month.
Línea 2006... Línea 1613...
2006
    $calendartype = \core_calendar\type_factory::get_calendar_instance();
1613
    $calendartype = \core_calendar\type_factory::get_calendar_instance();
2007
    return $calendartype->get_num_days_in_month($year, $month);
1614
    return $calendartype->get_num_days_in_month($year, $month);
2008
}
1615
}
Línea 2009... Línea 1616...
2009
 
1616
 
2010
/**
-
 
2011
 * Get the next following month.
-
 
2012
 *
-
 
2013
 * @param int $month the number of the month.
-
 
2014
 * @param int $year the number of the year.
-
 
2015
 * @return array the following month
-
 
2016
 */
-
 
2017
function calendar_add_month($month, $year) {
-
 
2018
    $calendartype = \core_calendar\type_factory::get_calendar_instance();
-
 
2019
    return $calendartype->get_next_month($year, $month);
-
 
2020
}
-
 
2021
 
-
 
2022
/**
-
 
2023
 * Get the previous month.
-
 
2024
 *
-
 
2025
 * @param int $month the number of the month.
-
 
2026
 * @param int $year the number of the year.
-
 
2027
 * @return array previous month
-
 
2028
 */
-
 
2029
function calendar_sub_month($month, $year) {
-
 
2030
    $calendartype = \core_calendar\type_factory::get_calendar_instance();
-
 
2031
    return $calendartype->get_prev_month($year, $month);
-
 
2032
}
-
 
2033
 
-
 
2034
/**
-
 
2035
 * Get per-day basis events
-
 
2036
 *
-
 
2037
 * @param array $events list of events
-
 
2038
 * @param int $month the number of the month
-
 
2039
 * @param int $year the number of the year
-
 
2040
 * @param array $eventsbyday event on specific day
-
 
2041
 * @param array $durationbyday duration of the event in days
-
 
2042
 * @param array $typesbyday event type (eg: site, course, user, or group)
-
 
2043
 * @param array $courses list of courses
-
 
2044
 * @return void
-
 
2045
 */
-
 
2046
function calendar_events_by_day($events, $month, $year, &$eventsbyday, &$durationbyday, &$typesbyday, &$courses) {
-
 
2047
    $calendartype = \core_calendar\type_factory::get_calendar_instance();
-
 
2048
 
-
 
2049
    $eventsbyday = array();
-
 
2050
    $typesbyday = array();
-
 
2051
    $durationbyday = array();
-
 
2052
 
-
 
2053
    if ($events === false) {
-
 
2054
        return;
-
 
2055
    }
-
 
2056
 
-
 
2057
    foreach ($events as $event) {
-
 
2058
        $startdate = $calendartype->timestamp_to_date_array($event->timestart);
-
 
2059
        if ($event->timeduration) {
-
 
2060
            $enddate = $calendartype->timestamp_to_date_array($event->timestart + $event->timeduration - 1);
-
 
2061
        } else {
-
 
2062
            $enddate = $startdate;
-
 
2063
        }
-
 
2064
 
-
 
2065
        // Simple arithmetic: $year * 13 + $month is a distinct integer for each distinct ($year, $month) pair.
-
 
2066
        if (!($startdate['year'] * 13 + $startdate['mon'] <= $year * 13 + $month) &&
-
 
2067
            ($enddate['year'] * 13 + $enddate['mon'] >= $year * 13 + $month)) {
-
 
2068
            continue;
-
 
2069
        }
-
 
2070
 
-
 
2071
        $eventdaystart = intval($startdate['mday']);
-
 
2072
 
-
 
2073
        if ($startdate['mon'] == $month && $startdate['year'] == $year) {
-
 
2074
            // Give the event to its day.
-
 
2075
            $eventsbyday[$eventdaystart][] = $event->id;
-
 
2076
 
-
 
2077
            // Mark the day as having such an event.
-
 
2078
            if ($event->courseid == SITEID && $event->groupid == 0) {
-
 
2079
                $typesbyday[$eventdaystart]['startsite'] = true;
-
 
2080
                // Set event class for site event.
-
 
2081
                $events[$event->id]->class = 'calendar_event_site';
-
 
2082
            } else if ($event->courseid != 0 && $event->courseid != SITEID && $event->groupid == 0) {
-
 
2083
                $typesbyday[$eventdaystart]['startcourse'] = true;
-
 
2084
                // Set event class for course event.
-
 
2085
                $events[$event->id]->class = 'calendar_event_course';
-
 
2086
            } else if ($event->groupid) {
-
 
2087
                $typesbyday[$eventdaystart]['startgroup'] = true;
-
 
2088
                // Set event class for group event.
-
 
2089
                $events[$event->id]->class = 'calendar_event_group';
-
 
2090
            } else if ($event->userid) {
-
 
2091
                $typesbyday[$eventdaystart]['startuser'] = true;
-
 
2092
                // Set event class for user event.
-
 
2093
                $events[$event->id]->class = 'calendar_event_user';
-
 
2094
            }
-
 
2095
        }
-
 
2096
 
-
 
2097
        if ($event->timeduration == 0) {
-
 
2098
            // Proceed with the next.
-
 
2099
            continue;
-
 
2100
        }
-
 
2101
 
-
 
2102
        // The event starts on $month $year or before.
-
 
2103
        if ($startdate['mon'] == $month && $startdate['year'] == $year) {
-
 
2104
            $lowerbound = intval($startdate['mday']);
-
 
2105
        } else {
-
 
2106
            $lowerbound = 0;
-
 
2107
        }
-
 
2108
 
-
 
2109
        // Also, it ends on $month $year or later.
-
 
2110
        if ($enddate['mon'] == $month && $enddate['year'] == $year) {
-
 
2111
            $upperbound = intval($enddate['mday']);
-
 
2112
        } else {
-
 
2113
            $upperbound = calendar_days_in_month($month, $year);
-
 
2114
        }
-
 
2115
 
-
 
2116
        // Mark all days between $lowerbound and $upperbound (inclusive) as duration.
-
 
2117
        for ($i = $lowerbound + 1; $i <= $upperbound; ++$i) {
-
 
2118
            $durationbyday[$i][] = $event->id;
-
 
2119
            if ($event->courseid == SITEID && $event->groupid == 0) {
-
 
2120
                $typesbyday[$i]['durationsite'] = true;
-
 
2121
            } else if ($event->courseid != 0 && $event->courseid != SITEID && $event->groupid == 0) {
-
 
2122
                $typesbyday[$i]['durationcourse'] = true;
-
 
2123
            } else if ($event->groupid) {
-
 
2124
                $typesbyday[$i]['durationgroup'] = true;
-
 
2125
            } else if ($event->userid) {
-
 
2126
                $typesbyday[$i]['durationuser'] = true;
-
 
2127
            }
-
 
2128
        }
-
 
2129
 
-
 
2130
    }
-
 
2131
    return;
-
 
2132
}
-
 
2133
 
-
 
2134
/**
1617
/**
2135
 * Returns the courses to load events for.
1618
 * Returns the courses to load events for.
2136
 *
1619
 *
2137
 * @param array $courseeventsfrom An array of courses to load calendar events for
1620
 * @param array $courseeventsfrom An array of courses to load calendar events for
2138
 * @param bool $ignorefilters specify the use of filters, false is set as default
1621
 * @param bool $ignorefilters specify the use of filters, false is set as default
2139
 * @param stdClass $user The user object. This defaults to the global $USER object.
1622
 * @param stdClass $user The user object. This defaults to the global $USER object.
2140
 * @return array An array of courses, groups, and user to load calendar events for based upon filters
1623
 * @return array An array of courses, groups, and user to load calendar events for based upon filters
2141
 */
1624
 */
2142
function calendar_set_filters(array $courseeventsfrom, $ignorefilters = false, stdClass $user = null) {
1625
function calendar_set_filters(array $courseeventsfrom, $ignorefilters = false, ?stdClass $user = null) {
Línea 2143... Línea 1626...
2143
    global $CFG, $USER;
1626
    global $CFG, $USER;
2144
 
1627
 
2145
    if (is_null($user)) {
1628
    if (is_null($user)) {
Línea 2453... Línea 1936...
2453
 *                        calendar, even if they are not enrolled in the course).
1936
 *                        calendar, even if they are not enrolled in the course).
2454
 * @param int $userid (optional) The user which this function returns the default courses for.
1937
 * @param int $userid (optional) The user which this function returns the default courses for.
2455
 *                        By default the current user.
1938
 *                        By default the current user.
2456
 * @return array $courses Array of courses to display
1939
 * @return array $courses Array of courses to display
2457
 */
1940
 */
2458
function calendar_get_default_courses($courseid = null, $fields = '*', $canmanage = false, int $userid = null) {
1941
function calendar_get_default_courses($courseid = null, $fields = '*', $canmanage = false, ?int $userid = null) {
2459
    global $CFG, $USER;
1942
    global $CFG, $USER;
Línea 2460... Línea 1943...
2460
 
1943
 
2461
    if (!$userid) {
1944
    if (!$userid) {
2462
        if (!isloggedin()) {
1945
        if (!isloggedin()) {
Línea 2490... Línea 1973...
2490
 
1973
 
2491
    return $courses;
1974
    return $courses;
Línea 2492... Línea 1975...
2492
}
1975
}
2493
 
-
 
2494
/**
-
 
2495
 * Get event format time.
-
 
2496
 *
-
 
2497
 * @param calendar_event $event event object
-
 
2498
 * @param int $now current time in gmt
-
 
2499
 * @param array $linkparams list of params for event link
-
 
2500
 * @param bool $usecommonwords the words as formatted date/time.
-
 
2501
 * @param int $showtime determine the show time GMT timestamp
-
 
2502
 * @return string $eventtime link/string for event time
-
 
2503
 */
-
 
2504
function calendar_format_event_time($event, $now, $linkparams = null, $usecommonwords = true, $showtime = 0) {
-
 
2505
    $starttime = $event->timestart;
-
 
2506
    $endtime = $event->timestart + $event->timeduration;
-
 
2507
 
-
 
2508
    if (empty($linkparams) || !is_array($linkparams)) {
-
 
2509
        $linkparams = array();
-
 
2510
    }
-
 
2511
 
-
 
2512
    $linkparams['view'] = 'day';
-
 
2513
 
-
 
2514
    // OK, now to get a meaningful display.
-
 
2515
    // Check if there is a duration for this event.
-
 
2516
    if ($event->timeduration) {
-
 
2517
        // Get the midnight of the day the event will start.
-
 
2518
        $usermidnightstart = usergetmidnight($starttime);
-
 
2519
        // Get the midnight of the day the event will end.
-
 
2520
        $usermidnightend = usergetmidnight($endtime);
-
 
2521
        // Check if we will still be on the same day.
-
 
2522
        if ($usermidnightstart == $usermidnightend) {
-
 
2523
            // Check if we are running all day.
-
 
2524
            if ($event->timeduration == DAYSECS) {
-
 
2525
                $time = get_string('allday', 'calendar');
-
 
2526
            } else { // Specify the time we will be running this from.
-
 
2527
                $datestart = calendar_time_representation($starttime);
-
 
2528
                $dateend = calendar_time_representation($endtime);
-
 
2529
                $time = $datestart . ' <strong>&raquo;</strong> ' . $dateend;
-
 
2530
            }
-
 
2531
 
-
 
2532
            // Set printable representation.
-
 
2533
            if (!$showtime) {
-
 
2534
                $day = calendar_day_representation($event->timestart, $now, $usecommonwords);
-
 
2535
                $url = calendar_get_link_href(new \moodle_url(CALENDAR_URL . 'view.php', $linkparams), 0, 0, 0, $endtime);
-
 
2536
                $eventtime = \html_writer::link($url, $day) . ', ' . $time;
-
 
2537
            } else {
-
 
2538
                $eventtime = $time;
-
 
2539
            }
-
 
2540
        } else { // It must spans two or more days.
-
 
2541
            $daystart = calendar_day_representation($event->timestart, $now, $usecommonwords) . ', ';
-
 
2542
            if ($showtime == $usermidnightstart) {
-
 
2543
                $daystart = '';
-
 
2544
            }
-
 
2545
            $timestart = calendar_time_representation($event->timestart);
-
 
2546
            $dayend = calendar_day_representation($event->timestart + $event->timeduration, $now, $usecommonwords) . ', ';
-
 
2547
            if ($showtime == $usermidnightend) {
-
 
2548
                $dayend = '';
-
 
2549
            }
-
 
2550
            $timeend = calendar_time_representation($event->timestart + $event->timeduration);
-
 
2551
 
-
 
2552
            // Set printable representation.
-
 
2553
            if ($now >= $usermidnightstart && $now < strtotime('+1 day', $usermidnightstart)) {
-
 
2554
                $url = calendar_get_link_href(new \moodle_url(CALENDAR_URL . 'view.php', $linkparams), 0, 0, 0, $endtime);
-
 
2555
                $eventtime = $timestart . ' <strong>&raquo;</strong> ' . \html_writer::link($url, $dayend) . $timeend;
-
 
2556
            } else {
-
 
2557
                // The event is in the future, print start and end links.
-
 
2558
                $url = calendar_get_link_href(new \moodle_url(CALENDAR_URL . 'view.php', $linkparams), 0, 0, 0, $starttime);
-
 
2559
                $eventtime = \html_writer::link($url, $daystart) . $timestart . ' <strong>&raquo;</strong> ';
-
 
2560
 
-
 
2561
                $url = calendar_get_link_href(new \moodle_url(CALENDAR_URL . 'view.php', $linkparams),  0, 0, 0, $endtime);
-
 
2562
                $eventtime .= \html_writer::link($url, $dayend) . $timeend;
-
 
2563
            }
-
 
2564
        }
-
 
2565
    } else { // There is no time duration.
-
 
2566
        $time = calendar_time_representation($event->timestart);
-
 
2567
        // Set printable representation.
-
 
2568
        if (!$showtime) {
-
 
2569
            $day = calendar_day_representation($event->timestart, $now, $usecommonwords);
-
 
2570
            $url = calendar_get_link_href(new \moodle_url(CALENDAR_URL . 'view.php', $linkparams),  0, 0, 0, $starttime);
-
 
2571
            $eventtime = \html_writer::link($url, $day) . ', ' . trim($time);
-
 
2572
        } else {
-
 
2573
            $eventtime = $time;
-
 
2574
        }
-
 
2575
    }
-
 
2576
 
-
 
2577
    // Check if It has expired.
-
 
2578
    if ($event->timestart + $event->timeduration < $now) {
-
 
2579
        $eventtime = '<span class="dimmed_text">' . str_replace(' href=', ' class="dimmed" href=', $eventtime) . '</span>';
-
 
2580
    }
-
 
2581
 
-
 
2582
    return $eventtime;
-
 
2583
}
-
 
2584
 
1976
 
2585
/**
1977
/**
2586
 * Format event location property
1978
 * Format event location property
2587
 *
1979
 *
2588
 * @param calendar_event $event
1980
 * @param calendar_event $event
Línea 3107... Línea 2499...
3107
 *
2499
 *
3108
 * @param iCalendar $ical The iCalendar object.
2500
 * @param iCalendar $ical The iCalendar object.
3109
 * @param int|null $subscriptionid The subscription ID.
2501
 * @param int|null $subscriptionid The subscription ID.
3110
 * @return array A log of the import progress, including errors.
2502
 * @return array A log of the import progress, including errors.
3111
 */
2503
 */
3112
function calendar_import_events_from_ical(iCalendar $ical, int $subscriptionid = null): array {
2504
function calendar_import_events_from_ical(iCalendar $ical, ?int $subscriptionid = null): array {
3113
    global $DB;
2505
    global $DB;
Línea 3114... Línea 2506...
3114
 
2506
 
3115
    $errors = [];
2507
    $errors = [];
3116
    $eventcount = 0;
2508
    $eventcount = 0;
Línea 3640... Línea 3032...
3640
    if (is_null($eventid)) {
3032
    if (is_null($eventid)) {
3641
        if (!empty($courseid)) {
3033
        if (!empty($courseid)) {
3642
            $groupcoursedata = groups_get_course_data($courseid);
3034
            $groupcoursedata = groups_get_course_data($courseid);
3643
            $formoptions['groups'] = [];
3035
            $formoptions['groups'] = [];
3644
            foreach ($groupcoursedata->groups as $groupid => $groupdata) {
3036
            foreach ($groupcoursedata->groups as $groupid => $groupdata) {
3645
                $formoptions['groups'][$groupid] = $groupdata->name;
3037
                $formoptions['groups'][$groupid] = format_string($groupdata->name, true, ['context' => $context]);
3646
            }
3038
            }
3647
        }
3039
        }
Línea 3648... Línea 3040...
3648
 
3040
 
3649
        $mform = new \core_calendar\local\event\forms\create(
3041
        $mform = new \core_calendar\local\event\forms\create(
Línea 3684... Línea 3076...
3684
 
3076
 
3685
        if (!empty($event->courseid)) {
3077
        if (!empty($event->courseid)) {
3686
            $groupcoursedata = groups_get_course_data($event->courseid);
3078
            $groupcoursedata = groups_get_course_data($event->courseid);
3687
            $formoptions['groups'] = [];
3079
            $formoptions['groups'] = [];
3688
            foreach ($groupcoursedata->groups as $groupid => $groupdata) {
3080
            foreach ($groupcoursedata->groups as $groupid => $groupdata) {
3689
                $formoptions['groups'][$groupid] = $groupdata->name;
3081
                $formoptions['groups'][$groupid] = format_string($groupdata->name, true, ['context' => $context]);
3690
            }
3082
            }
Línea 3691... Línea 3083...
3691
        }
3083
        }
3692
 
3084
 
Línea 3831... Línea 3223...
3831
 * the logged in user belongs to.
3223
 * the logged in user belongs to.
3832
 *
3224
 *
3833
 * @param int|null $courseid The course id.
3225
 * @param int|null $courseid The course id.
3834
 * @return array The array of allowed types.
3226
 * @return array The array of allowed types.
3835
 */
3227
 */
3836
function calendar_get_allowed_event_types(int $courseid = null) {
3228
function calendar_get_allowed_event_types(?int $courseid = null) {
3837
    global $DB, $CFG, $USER;
3229
    global $DB, $CFG, $USER;
Línea 3838... Línea 3230...
3838
 
3230
 
3839
    $types = [
3231
    $types = [
3840
        'user' => false,
3232
        'user' => false,