|
| 1 | +<?php |
| 2 | +// This file is part of Moodle - http://moodle.org/ |
| 3 | +// |
| 4 | +// Moodle is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU General Public License as published by |
| 6 | +// the Free Software Foundation, either version 3 of the License, or |
| 7 | +// (at your option) any later version. |
| 8 | +// |
| 9 | +// Moodle is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU General Public License for more details. |
| 13 | +// |
| 14 | +// You should have received a copy of the GNU General Public License |
| 15 | +// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +/** |
| 18 | + * List of deprecated calendar functions. |
| 19 | + * |
| 20 | + * @package core_calendar |
| 21 | + * @copyright 2025 Amaia Anabitarte <amaia@moodle.com> |
| 22 | + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 23 | + */ |
| 24 | + |
| 25 | +defined('MOODLE_INTERNAL') || die(); |
| 26 | + |
| 27 | +use core\url; |
| 28 | +use core_calendar\output\humandate; |
| 29 | +use core_calendar\output\humantimeperiod; |
| 30 | + |
| 31 | +/** |
| 32 | + * Return the representation day. |
| 33 | + * |
| 34 | + * @param int $tstamp Timestamp in GMT |
| 35 | + * @param int|bool $now current Unix timestamp |
| 36 | + * @param bool $usecommonwords |
| 37 | + * @return string the formatted date/time |
| 38 | + * |
| 39 | + * @deprecated since Moodle 5.0. |
| 40 | + * @todo MDL-84268 Final deprecation in Moodle 6.0. |
| 41 | + */ |
| 42 | +#[\core\attribute\deprecated( |
| 43 | + replacement: '\core_calendar\output\humandate', |
| 44 | + since: '5.0', |
| 45 | + mdl: 'MDL-83873', |
| 46 | +)] |
| 47 | +function calendar_day_representation($tstamp, $now = false, $usecommonwords = true) { |
| 48 | + static $shortformat; |
| 49 | + |
| 50 | + \core\deprecation::emit_deprecation_if_present(__FUNCTION__); |
| 51 | + |
| 52 | + if (empty($shortformat)) { |
| 53 | + $shortformat = get_string('strftimedayshort'); |
| 54 | + } |
| 55 | + |
| 56 | + if ($now === false) { |
| 57 | + $now = time(); |
| 58 | + } |
| 59 | + |
| 60 | + // To have it in one place, if a change is needed. |
| 61 | + $formal = userdate($tstamp, $shortformat); |
| 62 | + |
| 63 | + $datestamp = usergetdate($tstamp); |
| 64 | + $datenow = usergetdate($now); |
| 65 | + |
| 66 | + if ($usecommonwords == false) { |
| 67 | + // We don't want words, just a date. |
| 68 | + return $formal; |
| 69 | + } else if ($datestamp['year'] == $datenow['year'] && $datestamp['yday'] == $datenow['yday']) { |
| 70 | + return get_string('today', 'calendar'); |
| 71 | + } else if (($datestamp['year'] == $datenow['year'] && $datestamp['yday'] == $datenow['yday'] - 1 ) || |
| 72 | + ($datestamp['year'] == $datenow['year'] - 1 && $datestamp['mday'] == 31 && $datestamp['mon'] == 12 |
| 73 | + && $datenow['yday'] == 1)) { |
| 74 | + return get_string('yesterday', 'calendar'); |
| 75 | + } else if (($datestamp['year'] == $datenow['year'] && $datestamp['yday'] == $datenow['yday'] + 1 ) || |
| 76 | + ($datestamp['year'] == $datenow['year'] + 1 && $datenow['mday'] == 31 && $datenow['mon'] == 12 |
| 77 | + && $datestamp['yday'] == 1)) { |
| 78 | + return get_string('tomorrow', 'calendar'); |
| 79 | + } else { |
| 80 | + return $formal; |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +/** |
| 85 | + * return the formatted representation time. |
| 86 | + * |
| 87 | + * @param int $time the timestamp in UTC, as obtained from the database |
| 88 | + * @return string the formatted date/time |
| 89 | + * |
| 90 | + * @deprecated since Moodle 5.0. |
| 91 | + * @todo MDL-84268 Final deprecation in Moodle 6.0. |
| 92 | + */ |
| 93 | +#[\core\attribute\deprecated( |
| 94 | + replacement: '\core_calendar\output\humandate', |
| 95 | + since: '5.0', |
| 96 | + mdl: 'MDL-83873', |
| 97 | +)] |
| 98 | +function calendar_time_representation($time) { |
| 99 | + \core\deprecation::emit_deprecation_if_present(__FUNCTION__); |
| 100 | + |
| 101 | + global $OUTPUT; |
| 102 | + |
| 103 | + $humantime = humandate::create_from_timestamp( |
| 104 | + timestamp: $time, |
| 105 | + near: null, |
| 106 | + timeonly: true |
| 107 | + ); |
| 108 | + return $OUTPUT->render($humantime); |
| 109 | +} |
| 110 | + |
| 111 | +/** |
| 112 | + * Get event format time. |
| 113 | + * |
| 114 | + * @param calendar_event $event event object |
| 115 | + * @param int $now current time in gmt |
| 116 | + * @param array $linkparams list of params for event link |
| 117 | + * @param bool $usecommonwords the words as formatted date/time. |
| 118 | + * @param int $showtime determine the show time GMT timestamp |
| 119 | + * @return string $eventtime link/string for event time |
| 120 | + * |
| 121 | + * @deprecated since Moodle 5.0. |
| 122 | + * @todo MDL-84268 Final deprecation in Moodle 6.0. |
| 123 | + */ |
| 124 | +#[\core\attribute\deprecated( |
| 125 | + replacement: '\core_calendar\output\humantimeperiod', |
| 126 | + since: '5.0', |
| 127 | + mdl: 'MDL-83873', |
| 128 | +)] |
| 129 | +function calendar_format_event_time($event, $now, $linkparams = null, $usecommonwords = true, $showtime = 0) { |
| 130 | + \core\deprecation::emit_deprecation_if_present(__FUNCTION__); |
| 131 | + |
| 132 | + global $OUTPUT; |
| 133 | + |
| 134 | + $humanperiod = humantimeperiod::create_from_timestamp( |
| 135 | + starttimestamp: $event->timestart, |
| 136 | + endtimestamp: $event->timestart + $event->timeduration, |
| 137 | + link: new url(CALENDAR_URL . 'view.php'), |
| 138 | + ); |
| 139 | + |
| 140 | + return $OUTPUT->render($humanperiod); |
| 141 | + |
| 142 | +} |
0 commit comments