mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-18375 calendar: huge refactor of the initial patch
1) Moved the calendar types location to a sub-folder in the calendar directory. 2) Removed/moved language strings. 3) Removed calendar types that should be downloaded as plugins. 4) Removed a Non-English language pack for the Gregorian calendar type that should be downloaded separately. 5) Removed custom files responsible for checking for updates and uninstalling calendar types, which should be done by core. 6) Removed JS from the calendar_month block as there is no non-JS alternative provided and the JS written does not make use of the YUI library to ensure multiple browser support. 7) Removed code from the base class responsible for creating timestamps that are saved in the DB. 8) Added PHPDocs. Note: In the original patch we are editing core functions responsible for saving time in the database in the calendar base class. This is very dangerous, we do not want to touch these functions as it could cause a complete fubar of the database. There are places we are forcing the use of the gregorian calendar as we are passing dates generated by the PHP date function, where as sometimes we pass dates from usergetdate (which was being overwritten to return the date specific to the calendar). We can not expect third party modules to change the calendar type depending on the format they pass to these functions.
This commit is contained in:
parent
6dd59aabfa
commit
2f00e1b245
45 changed files with 606 additions and 1931 deletions
|
@ -133,10 +133,9 @@ if ($eventid !== 0) {
|
|||
unset($formoptions->eventtypes->groups);
|
||||
}
|
||||
}
|
||||
// MDL-18375, Multi-Calendar Support
|
||||
if($cal_y && $cal_m && $cal_d && $CALENDARSYSTEM->checkdate($cal_m, $cal_d, $cal_y)) {
|
||||
if($cal_y && $cal_m && $cal_d && checkdate($cal_m, $cal_d, $cal_y)) {
|
||||
$event->timestart = make_timestamp($cal_y, $cal_m, $cal_d, 0, 0, 0);
|
||||
} else if($cal_y && $cal_m && $CALENDARSYSTEM->checkdate($cal_m, 1, $cal_y)) {
|
||||
} else if($cal_y && $cal_m && checkdate($cal_m, 1, $cal_y)) {
|
||||
$now = usergetdate(time());
|
||||
if($cal_y == $now['year'] && $cal_m == $now['mon']) {
|
||||
$event->timestart = make_timestamp($cal_y, $cal_m, $now['mday'], 0, 0, 0);
|
||||
|
|
|
@ -34,9 +34,7 @@ if (!$authuserid && !$authusername) {
|
|||
$what = optional_param('preset_what', 'all', PARAM_ALPHA);
|
||||
$time = optional_param('preset_time', 'weeknow', PARAM_ALPHA);
|
||||
|
||||
// MDL-18375, Multi-Calendar Support
|
||||
$calendarsystem_gregorian = calendarsystem_plugin_factory::factory('gregorian');
|
||||
$now = $calendarsystem_gregorian->usergetdate(time());
|
||||
$now = usergetdate(time());
|
||||
// Let's see if we have sufficient and correct data
|
||||
$allowed_what = array('all', 'courses');
|
||||
$allowed_time = array('weeknow', 'weeknext', 'monthnow', 'monthnext', 'recentupcoming', 'custom');
|
||||
|
@ -82,47 +80,47 @@ if(!empty($what) && !empty($time)) {
|
|||
$startmonthday = find_day_in_month($now['mday'] - 6, $startweekday, $now['mon'], $now['year']);
|
||||
$startmonth = $now['mon'];
|
||||
$startyear = $now['year'];
|
||||
if($startmonthday > $calendarsystem_gregorian->calendar_days_in_month($startmonth, $startyear)) {
|
||||
if($startmonthday > calendar_days_in_month($startmonth, $startyear)) {
|
||||
list($startmonth, $startyear) = calendar_add_month($startmonth, $startyear);
|
||||
$startmonthday = find_day_in_month(1, $startweekday, $startmonth, $startyear);
|
||||
}
|
||||
$timestart = $calendarsystem_gregorian->make_timestamp($startyear, $startmonth, $startmonthday);
|
||||
$timestart = make_timestamp($startyear, $startmonth, $startmonthday);
|
||||
$endmonthday = $startmonthday + 7;
|
||||
$endmonth = $startmonth;
|
||||
$endyear = $startyear;
|
||||
if($endmonthday > $calendarsystem_gregorian->calendar_days_in_month($endmonth, $endyear)) {
|
||||
if($endmonthday > calendar_days_in_month($endmonth, $endyear)) {
|
||||
list($endmonth, $endyear) = calendar_add_month($endmonth, $endyear);
|
||||
$endmonthday = find_day_in_month(1, $startweekday, $endmonth, $endyear);
|
||||
}
|
||||
$timeend = $calendarsystem_gregorian->make_timestamp($endyear, $endmonth, $endmonthday) - 1;
|
||||
$timeend = make_timestamp($endyear, $endmonth, $endmonthday) - 1;
|
||||
break;
|
||||
case 'weeknext':
|
||||
$startweekday = get_user_preferences('calendar_startwday', calendar_get_starting_weekday());
|
||||
$startmonthday = find_day_in_month($now['mday'] + 1, $startweekday, $now['mon'], $now['year']);
|
||||
$startmonth = $now['mon'];
|
||||
$startyear = $now['year'];
|
||||
if($startmonthday > $calendarsystem_gregorian->calendar_days_in_month($startmonth, $startyear)) {
|
||||
if($startmonthday > calendar_days_in_month($startmonth, $startyear)) {
|
||||
list($startmonth, $startyear) = calendar_add_month($startmonth, $startyear);
|
||||
$startmonthday = find_day_in_month(1, $startweekday, $startmonth, $startyear);
|
||||
}
|
||||
$timestart = $calendarsystem_gregorian->make_timestamp($startyear, $startmonth, $startmonthday);
|
||||
$timestart = make_timestamp($startyear, $startmonth, $startmonthday);
|
||||
$endmonthday = $startmonthday + 7;
|
||||
$endmonth = $startmonth;
|
||||
$endyear = $startyear;
|
||||
if($endmonthday > $calendarsystem_gregorian->calendar_days_in_month($endmonth, $endyear)) {
|
||||
if($endmonthday > calendar_days_in_month($endmonth, $endyear)) {
|
||||
list($endmonth, $endyear) = calendar_add_month($endmonth, $endyear);
|
||||
$endmonthday = find_day_in_month(1, $startweekday, $endmonth, $endyear);
|
||||
}
|
||||
$timeend = $calendarsystem_gregorian->make_timestamp($endyear, $endmonth, $endmonthday) - 1;
|
||||
$timeend = make_timestamp($endyear, $endmonth, $endmonthday) - 1;
|
||||
break;
|
||||
case 'monthnow':
|
||||
$timestart = $calendarsystem_gregorian->make_timestamp($now['year'], $now['mon'], 1);
|
||||
$timeend = $calendarsystem_gregorian->make_timestamp($now['year'], $now['mon'], calendar_days_in_month($now['mon'], $now['year']), 23, 59, 59);
|
||||
$timestart = make_timestamp($now['year'], $now['mon'], 1);
|
||||
$timeend = make_timestamp($now['year'], $now['mon'], calendar_days_in_month($now['mon'], $now['year']), 23, 59, 59);
|
||||
break;
|
||||
case 'monthnext':
|
||||
list($nextmonth, $nextyear) = calendar_add_month($now['mon'], $now['year']);
|
||||
$timestart = $calendarsystem_gregorian->make_timestamp($nextyear, $nextmonth, 1);
|
||||
$timeend = $calendarsystem_gregorian->make_timestamp($nextyear, $nextmonth, calendar_days_in_month($nextmonth, $nextyear), 23, 59, 59);
|
||||
$timestart = make_timestamp($nextyear, $nextmonth, 1);
|
||||
$timeend = make_timestamp($nextyear, $nextmonth, calendar_days_in_month($nextmonth, $nextyear), 23, 59, 59);
|
||||
break;
|
||||
case 'recentupcoming':
|
||||
//Events in the last 5 or next 60 days
|
||||
|
|
|
@ -187,8 +187,6 @@ function calendar_get_starting_weekday() {
|
|||
*/
|
||||
function calendar_get_mini($courses, $groups, $users, $cal_month = false, $cal_year = false, $placement = false, $courseid = false ) {
|
||||
global $CFG, $USER, $OUTPUT;
|
||||
// MDL-18375, Multi-Calendar Support
|
||||
global $CALENDARSYSTEM;
|
||||
|
||||
$display = new stdClass;
|
||||
$display->minwday = get_user_preferences('calendar_startwday', calendar_get_starting_weekday());
|
||||
|
@ -204,7 +202,7 @@ function calendar_get_mini($courses, $groups, $users, $cal_month = false, $cal_y
|
|||
$display->thismonth = true;
|
||||
} else {
|
||||
// Navigated to other month, let's do a nice trick and save us a lot of work...
|
||||
if(!$CALENDARSYSTEM->checkdate($cal_month, 1, $cal_year)) {
|
||||
if(!checkdate($cal_month, 1, $cal_year)) {
|
||||
$date = array('mday' => 1, 'mon' => $thisdate['mon'], 'year' => $thisdate['year']);
|
||||
$display->thismonth = true;
|
||||
} else {
|
||||
|
@ -223,12 +221,12 @@ function calendar_get_mini($courses, $groups, $users, $cal_month = false, $cal_y
|
|||
|
||||
if (get_user_timezone_offset() < 99) {
|
||||
// We 'll keep these values as GMT here, and offset them when the time comes to query the db
|
||||
$display->tstart = $CALENDARSYSTEM->gmmktime(0, 0, 0, $m, 1, $y); // This is GMT
|
||||
$display->tend = $CALENDARSYSTEM->gmmktime(23, 59, 59, $m, $display->maxdays, $y); // GMT
|
||||
$display->tstart = gmmktime(0, 0, 0, $m, 1, $y); // This is GMT
|
||||
$display->tend = gmmktime(23, 59, 59, $m, $display->maxdays, $y); // GMT
|
||||
} else {
|
||||
// no timezone info specified
|
||||
$display->tstart = $CALENDARSYSTEM->mktime(0, 0, 0, $m, 1, $y);
|
||||
$display->tend = $CALENDARSYSTEM->mktime(23, 59, 59, $m, $display->maxdays, $y);
|
||||
$display->tstart = mktime(0, 0, 0, $m, 1, $y);
|
||||
$display->tend = mktime(23, 59, 59, $m, $display->maxdays, $y);
|
||||
}
|
||||
|
||||
$startwday = dayofweek(1, $m, $y);
|
||||
|
@ -826,8 +824,6 @@ function calendar_get_events_by_id($eventids) {
|
|||
*/
|
||||
function calendar_top_controls($type, $data) {
|
||||
global $CFG, $PAGE;
|
||||
// MDL-18375, Multi-Calendar Support
|
||||
global $CALENDARSYSTEM;
|
||||
$content = '';
|
||||
if(!isset($data['d'])) {
|
||||
$data['d'] = 1;
|
||||
|
@ -840,11 +836,11 @@ function calendar_top_controls($type, $data) {
|
|||
$courseid = '&course='.$data['id'];
|
||||
}
|
||||
|
||||
if(!$CALENDARSYSTEM->checkdate($data['m'], $data['d'], $data['y'])) {
|
||||
if(!checkdate($data['m'], $data['d'], $data['y'])) {
|
||||
$time = time();
|
||||
}
|
||||
else {
|
||||
$time = $CALENDARSYSTEM->make_timestamp($data['y'], $data['m'], $data['d']);
|
||||
$time = make_timestamp($data['y'], $data['m'], $data['d']);
|
||||
}
|
||||
$date = usergetdate($time);
|
||||
|
||||
|
@ -1214,9 +1210,7 @@ function calendar_wday_name($englishname) {
|
|||
* @return int
|
||||
*/
|
||||
function calendar_days_in_month($month, $year) {
|
||||
// MDL-18375, Multi-Calendar Support
|
||||
global $CALENDARSYSTEM;
|
||||
return $CALENDARSYSTEM->calendar_days_in_month($month, $year);
|
||||
return intval(date('t', mktime(0, 0, 0, $month, 1, $year)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1739,11 +1733,10 @@ function calendar_format_event_time($event, $now, $linkparams = null, $usecommon
|
|||
* @param string|array $selected options for select elements
|
||||
*/
|
||||
function calendar_print_month_selector($name, $selected) {
|
||||
// MDL-18375, Multi-Calendar Support
|
||||
global $CALENDARSYSTEM;
|
||||
|
||||
$months = $CALENDARSYSTEM->get_month_names();
|
||||
|
||||
$months = array();
|
||||
for ($i=1; $i<=12; $i++) {
|
||||
$months[$i] = userdate(gmmktime(12, 0, 0, $i, 15, 2000), '%B');
|
||||
}
|
||||
echo html_writer::label(get_string('months'), 'menu'. $name, false, array('class' => 'accesshide'));
|
||||
echo html_writer::select($months, $name, $selected, false);
|
||||
}
|
||||
|
|
|
@ -380,8 +380,6 @@ class core_calendar_renderer extends plugin_renderer_base {
|
|||
*/
|
||||
public function show_month_detailed(calendar_information $calendar, moodle_url $returnurl = null) {
|
||||
global $CFG;
|
||||
// MDL-18375, Multi-Calendar Support
|
||||
global $CALENDARSYSTEM;
|
||||
|
||||
if (empty($returnurl)) {
|
||||
$returnurl = $this->page->url;
|
||||
|
@ -398,13 +396,13 @@ class core_calendar_renderer extends plugin_renderer_base {
|
|||
$startwday = 0;
|
||||
if (get_user_timezone_offset() < 99) {
|
||||
// We 'll keep these values as GMT here, and offset them when the time comes to query the db
|
||||
$display->tstart = $CALENDARSYSTEM->gmmktime(0, 0, 0, $calendar->month, 1, $calendar->year); // This is GMT
|
||||
$display->tend = $CALENDARSYSTEM->gmmktime(23, 59, 59, $calendar->month, $display->maxdays, $calendar->year); // GMT
|
||||
$display->tstart = gmmktime(0, 0, 0, $calendar->month, 1, $calendar->year); // This is GMT
|
||||
$display->tend = gmmktime(23, 59, 59, $calendar->month, $display->maxdays, $calendar->year); // GMT
|
||||
$startwday = gmdate('w', $display->tstart); // $display->tstart is already GMT, so don't use date(): messes with server's TZ
|
||||
} else {
|
||||
// no timezone info specified
|
||||
$display->tstart = $CALENDARSYSTEM->mktime(0, 0, 0, $calendar->month, 1, $calendar->year);
|
||||
$display->tend = $CALENDARSYSTEM->mktime(23, 59, 59, $calendar->month, $display->maxdays, $calendar->year);
|
||||
$display->tstart = mktime(0, 0, 0, $calendar->month, 1, $calendar->year);
|
||||
$display->tend = mktime(23, 59, 59, $calendar->month, $display->maxdays, $calendar->year);
|
||||
$startwday = date('w', $display->tstart); // $display->tstart not necessarily GMT, so use date()
|
||||
}
|
||||
|
||||
|
|
304
calendar/type/calendartype.class.php
Normal file
304
calendar/type/calendartype.class.php
Normal file
|
@ -0,0 +1,304 @@
|
|||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Defines functions used by calendar type plugins.
|
||||
*
|
||||
* This library provides a unified interface for calendar types.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @author Shamim Rezaie <support@foodle.org>
|
||||
* @author Mark Nelson <markn@moodle.com>
|
||||
* @copyright 2008 onwards Foodle Group {@link http://foodle.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
abstract class calendar_type_plugin_base {
|
||||
|
||||
/**
|
||||
* Returns a list of all the possible days for all months.
|
||||
*
|
||||
* This is used to generate the select box for the days
|
||||
* in the date selector elements. Some months contain more days
|
||||
* than others so this function should return all possible days as
|
||||
* we can not predict what month will be chosen (the user
|
||||
* may have JS turned off and we need to support this situation in
|
||||
* Moodle).
|
||||
*
|
||||
* @return array the days
|
||||
*/
|
||||
public abstract function get_days();
|
||||
|
||||
/**
|
||||
* Returns a list of all the names of the months.
|
||||
*
|
||||
* @return array the month names
|
||||
*/
|
||||
public abstract function get_months();
|
||||
|
||||
/**
|
||||
* Returns the minimum year of the calendar.
|
||||
*
|
||||
* @return int the minumum year
|
||||
*/
|
||||
public abstract function get_min_year();
|
||||
|
||||
/**
|
||||
* Returns the maximum year of the calendar.
|
||||
*
|
||||
* @return int the max year
|
||||
*/
|
||||
public abstract function get_max_year();
|
||||
|
||||
/**
|
||||
* Provided with a day, month, year, hour and minute in the specific
|
||||
* calendar type convert it into the equivalent Gregorian date.
|
||||
*
|
||||
* @param int $year
|
||||
* @param int $month
|
||||
* @param int $day
|
||||
* @param int $hour
|
||||
* @param int $minute
|
||||
* @return array the converted day, month and year.
|
||||
*/
|
||||
public abstract function convert_to_gregorian($year, $month, $day, $hour = 0, $minute = 0);
|
||||
|
||||
/**
|
||||
* Provided with a day, month, year, hour and minute in a Gregorian date
|
||||
* convert it into the specific calendar type date.
|
||||
*
|
||||
* @param int $year
|
||||
* @param int $month
|
||||
* @param int $day
|
||||
* @param int $hour
|
||||
* @param int $minute
|
||||
* @return array the converted day, month and year.
|
||||
*/
|
||||
public abstract function convert_from_gregorian($year, $month, $day, $hour = 0, $minute = 0);
|
||||
|
||||
/**
|
||||
* Returns a formatted string that represents a date in user time.
|
||||
*
|
||||
* Returns a formatted string that represents a date in user time
|
||||
* <b>WARNING: note that the format is for strftime(), not date().</b>
|
||||
* Because of a bug in most Windows time libraries, we can't use
|
||||
* the nicer %e, so we have to use %d which has leading zeroes.
|
||||
* A lot of the fuss in the function is just getting rid of these leading
|
||||
* zeroes as efficiently as possible.
|
||||
*
|
||||
* If parameter fixday = true (default), then take off leading
|
||||
* zero from %d, else maintain it.
|
||||
*
|
||||
* @param int $date the timestamp in UTC, as obtained from the database.
|
||||
* @param string $format strftime format. You should probably get this using
|
||||
* get_string('strftime...', 'langconfig');
|
||||
* @param int|float|string $timezone by default, uses the user's time zone. if numeric and
|
||||
* not 99 then daylight saving will not be added.
|
||||
* {@link http://docs.moodle.org/dev/Time_API#Timezone}
|
||||
* @param bool $fixday if true (default) then the leading zero from %d is removed.
|
||||
* If false then the leading zero is maintained.
|
||||
* @param bool $fixhour if true (default) then the leading zero from %I is removed.
|
||||
* @return string the formatted date/time.
|
||||
*/
|
||||
function userdate($date, $format, $timezone, $fixday, $fixhour) {
|
||||
global $CFG;
|
||||
|
||||
if (empty($format)) {
|
||||
$format = get_string('strftimedaydatetime', 'langconfig');
|
||||
}
|
||||
|
||||
if (!empty($CFG->nofixday)) { // Config.php can force %d not to be fixed.
|
||||
$fixday = false;
|
||||
} else if ($fixday) {
|
||||
$formatnoday = str_replace('%d', 'DD', $format);
|
||||
$fixday = ($formatnoday != $format);
|
||||
$format = $formatnoday;
|
||||
}
|
||||
|
||||
// Note: This logic about fixing 12-hour time to remove unnecessary leading
|
||||
// zero is required because on Windows, PHP strftime function does not
|
||||
// support the correct 'hour without leading zero' parameter (%l).
|
||||
if (!empty($CFG->nofixhour)) {
|
||||
// Config.php can force %I not to be fixed.
|
||||
$fixhour = false;
|
||||
} else if ($fixhour) {
|
||||
$formatnohour = str_replace('%I', 'HH', $format);
|
||||
$fixhour = ($formatnohour != $format);
|
||||
$format = $formatnohour;
|
||||
}
|
||||
|
||||
// Add daylight saving offset for string timezones only, as we can't get dst for
|
||||
// float values. if timezone is 99 (user default timezone), then try update dst.
|
||||
if ((99 == $timezone) || !is_numeric($timezone)) {
|
||||
$date += dst_offset_on($date, $timezone);
|
||||
}
|
||||
|
||||
$timezone = get_user_timezone_offset($timezone);
|
||||
|
||||
// If we are running under Windows convert to windows encoding and then back to UTF-8
|
||||
// (because it's impossible to specify UTF-8 to fetch locale info in Win32).
|
||||
if (abs($timezone) > 13) { // Server time.
|
||||
$datestring = date_format_string($date, $format, $timezone);
|
||||
if ($fixday) {
|
||||
$daystring = ltrim(str_replace(array(' 0', ' '), '', strftime(' %d', $date)));
|
||||
$datestring = str_replace('DD', $daystring, $datestring);
|
||||
}
|
||||
if ($fixhour) {
|
||||
$hourstring = ltrim(str_replace(array(' 0', ' '), '', strftime(' %I', $date)));
|
||||
$datestring = str_replace('HH', $hourstring, $datestring);
|
||||
}
|
||||
} else {
|
||||
$date += (int)($timezone * 3600);
|
||||
$datestring = date_format_string($date, $format, $timezone);
|
||||
if ($fixday) {
|
||||
$daystring = ltrim(str_replace(array(' 0', ' '), '', gmstrftime(' %d', $date)));
|
||||
$datestring = str_replace('DD', $daystring, $datestring);
|
||||
}
|
||||
if ($fixhour) {
|
||||
$hourstring = ltrim(str_replace(array(' 0', ' '), '', gmstrftime(' %I', $date)));
|
||||
$datestring = str_replace('HH', $hourstring, $datestring);
|
||||
}
|
||||
}
|
||||
|
||||
return $datestring;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a $time timestamp in GMT (seconds since epoch), returns an array that
|
||||
* represents the date in user time.
|
||||
*
|
||||
* @param int $time Timestamp in GMT
|
||||
* @param float|int|string $timezone offset's time with timezone, if float and not 99, then no
|
||||
* dst offset is applyed {@link http://docs.moodle.org/dev/Time_API#Timezone}
|
||||
* @return array An array that represents the date in user time
|
||||
*/
|
||||
function usergetdate($time, $timezone) {
|
||||
// Save input timezone, required for dst offset check.
|
||||
$passedtimezone = $timezone;
|
||||
|
||||
$timezone = get_user_timezone_offset($timezone);
|
||||
|
||||
if (abs($timezone) > 13) { // Server time.
|
||||
return getdate($time);
|
||||
}
|
||||
|
||||
// Add daylight saving offset for string timezones only, as we can't get dst for
|
||||
// float values. if timezone is 99 (user default timezone), then try update dst.
|
||||
if ($passedtimezone == 99 || !is_numeric($passedtimezone)) {
|
||||
$time += dst_offset_on($time, $passedtimezone);
|
||||
}
|
||||
|
||||
$time += intval((float)$timezone * HOURSECS);
|
||||
|
||||
$datestring = gmstrftime('%B_%A_%j_%Y_%m_%w_%d_%H_%M_%S', $time);
|
||||
|
||||
// Be careful to ensure the returned array matches that produced by getdate() above.
|
||||
list (
|
||||
$getdate['month'],
|
||||
$getdate['weekday'],
|
||||
$getdate['yday'],
|
||||
$getdate['year'],
|
||||
$getdate['mon'],
|
||||
$getdate['wday'],
|
||||
$getdate['mday'],
|
||||
$getdate['hours'],
|
||||
$getdate['minutes'],
|
||||
$getdate['seconds']
|
||||
) = explode('_', $datestring);
|
||||
|
||||
// Set correct datatype to match with getdate().
|
||||
$getdate['seconds'] = (int) $getdate['seconds'];
|
||||
$getdate['yday'] = (int) $getdate['yday'] - 1;
|
||||
$getdate['year'] = (int) $getdate['year'];
|
||||
$getdate['mon'] = (int) $getdate['mon'];
|
||||
$getdate['wday'] = (int) $getdate['wday'];
|
||||
$getdate['mday'] = (int) $getdate['mday'];
|
||||
$getdate['hours'] = (int) $getdate['hours'];
|
||||
$getdate['minutes'] = (int) $getdate['minutes'];
|
||||
|
||||
return $getdate;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class calendar_type_plugin_factory.
|
||||
*
|
||||
* Factory class producing required subclasses of {@link calendar_type_plugin_base}.
|
||||
*/
|
||||
class calendar_type_plugin_factory {
|
||||
|
||||
/**
|
||||
* Returns an instance of the currently used calendar type.
|
||||
*
|
||||
* @return calendar_type_plugin_* the created calendar_type class
|
||||
* @throws coding_exception if the calendar type file could not be loaded
|
||||
*/
|
||||
static function factory() {
|
||||
global $CFG;
|
||||
|
||||
$type = self::get_calendar_type();
|
||||
$file = 'calendar/type/' . $type . '/lib.php';
|
||||
$fullpath = $CFG->dirroot . '/' . $file;
|
||||
if (is_readable($fullpath)) {
|
||||
require_once($fullpath);
|
||||
$class = "calendar_type_plugin_$type";
|
||||
return new $class();
|
||||
} else {
|
||||
throw new coding_exception("The calendar type file $file could not be initialised, check that it exists
|
||||
and that the web server has permission to read it.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of calendar typess available for use.
|
||||
*
|
||||
* @return array the list of calendar types
|
||||
*/
|
||||
static function get_list_of_calendar_types() {
|
||||
$calendars = array();
|
||||
$calendardirs = core_component::get_plugin_list('calendartype');
|
||||
|
||||
foreach ($calendardirs as $name => $location) {
|
||||
$calendars[$name] = get_string('name', "calendartype_{$name}");
|
||||
}
|
||||
|
||||
return $calendars;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current calendar type in use.
|
||||
*
|
||||
* @return string the current calendar type being used
|
||||
*/
|
||||
static function get_calendar_type() {
|
||||
global $CFG, $USER, $SESSION, $COURSE;
|
||||
|
||||
if (!empty($COURSE->id) and $COURSE->id != SITEID and !empty($COURSE->calendartype)) { // Course calendartype can override all other settings for this page.
|
||||
$return = $COURSE->calendartype;
|
||||
} else if (!empty($SESSION->calendartype)) { // Session calendartype can override other settings.
|
||||
$return = $SESSION->calendartype;
|
||||
} else if (!empty($USER->calendartype)) {
|
||||
$return = $USER->calendartype;
|
||||
} else if (!empty($CFG->calendartype)) {
|
||||
$return = $CFG->calendartype;
|
||||
} else {
|
||||
$return = 'gregorian';
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
27
calendar/type/gregorian/lang/en/calendartype_gregorian.php
Normal file
27
calendar/type/gregorian/lang/en/calendartype_gregorian.php
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Strings for component 'calendar_type_plugin_gregorian', language 'en'.
|
||||
*
|
||||
* @package calendar_type_plugin_gregorian
|
||||
* @copyright 2008 onwards Foodle Group {@link http://foodle.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
$string['name'] = 'Gregorian';
|
||||
$string['pluginname'] = 'Gregorian calendar type';
|
133
calendar/type/gregorian/lib.php
Normal file
133
calendar/type/gregorian/lib.php
Normal file
|
@ -0,0 +1,133 @@
|
|||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Handles calendar functions for the gregorian calendar.
|
||||
*
|
||||
* @package calendar_type_plugin_gregorian
|
||||
* @author Shamim Rezaie <support@foodle.org>
|
||||
* @author Mark Nelson <markn@moodle.com>
|
||||
* @copyright 2008 onwards Foodle Group {@link http://foodle.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class calendar_type_plugin_gregorian extends calendar_type_plugin_base {
|
||||
|
||||
/**
|
||||
* Returns a list of all the possible days for all months.
|
||||
*
|
||||
* This is used to generate the select box for the days
|
||||
* in the date selector elements. Some months contain more days
|
||||
* than others so this function should return all possible days as
|
||||
* we can not predict what month will be chosen (the user
|
||||
* may have JS turned off and we need to support this situation in
|
||||
* Moodle).
|
||||
*
|
||||
* @return array the days
|
||||
*/
|
||||
public function get_days() {
|
||||
$days = array();
|
||||
|
||||
for ($i = 1; $i <= 31; $i++) {
|
||||
$days[$i] = $i;
|
||||
}
|
||||
|
||||
return $days;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all the names of the months.
|
||||
*
|
||||
* @return array the month names
|
||||
*/
|
||||
public function get_months() {
|
||||
$months = array();
|
||||
|
||||
for ($i = 1; $i <= 12; $i++) {
|
||||
$months[$i] = userdate(gmmktime(12, 0, 0, $i, 15, 2000), '%B');
|
||||
}
|
||||
|
||||
return $months;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the minimum year of the calendar.
|
||||
*
|
||||
* @return int the minumum year
|
||||
*/
|
||||
public function get_min_year() {
|
||||
return 1900;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum year of the calendar.
|
||||
*
|
||||
* @return int the max year
|
||||
*/
|
||||
public function get_max_year() {
|
||||
return 2050;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provided with a day, month, year, hour and minute in a specific
|
||||
* calendar type convert it into the equivalent Gregorian date.
|
||||
*
|
||||
* In this function we don't need to do anything except pass the data
|
||||
* back as an array. This is because the date received is Gregorian.
|
||||
*
|
||||
* @param int $year
|
||||
* @param int $month
|
||||
* @param int $day
|
||||
* @param int $hour
|
||||
* @param int $minute
|
||||
* @return array the converted day, month, year, hour and minute.
|
||||
*/
|
||||
public function convert_from_gregorian($year, $month, $day, $hour = 0, $minute = 0) {
|
||||
$date = array();
|
||||
$date['year'] = $year;
|
||||
$date['month'] = $month;
|
||||
$date['day'] = $day;
|
||||
$date['hour'] = $hour;
|
||||
$date['minute'] = $minute;
|
||||
|
||||
return $date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provided with a day, month, year, hour and minute in a specific
|
||||
* calendar type convert it into the equivalent Gregorian date.
|
||||
*
|
||||
* In this function we don't need to do anything except pass the data
|
||||
* back as an array. This is because the date received is Gregorian.
|
||||
*
|
||||
* @param int $year
|
||||
* @param int $month
|
||||
* @param int $day
|
||||
* @param int $hour
|
||||
* @param int $minute
|
||||
* @return array the converted day, month, year, hour and minute.
|
||||
*/
|
||||
public function convert_to_gregorian($year, $month, $day, $hour = 0, $minute = 0) {
|
||||
$date = array();
|
||||
$date['year'] = $year;
|
||||
$date['month'] = $month;
|
||||
$date['day'] = $day;
|
||||
$date['hour'] = $hour;
|
||||
$date['minute'] = $minute;
|
||||
|
||||
return $date;
|
||||
}
|
||||
}
|
29
calendar/type/gregorian/version.php
Normal file
29
calendar/type/gregorian/version.php
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Version details.
|
||||
*
|
||||
* @package calendar_type_plugin_gregorian
|
||||
* @copyright 2008 onwards Foodle Group {@link http://foodle.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2013062000; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->requires = 2012120300; // Requires this Moodle version.
|
||||
$plugin->component = 'calendartype_gregorian'; // Full name of the plugin (used for diagnostics).
|
|
@ -88,8 +88,7 @@ $pagetitle = '';
|
|||
|
||||
$strcalendar = get_string('calendar', 'calendar');
|
||||
|
||||
// MDL-18375, Multi-Calendar Support
|
||||
if (!$CALENDARSYSTEM->checkdate($mon, $day, $yr)) {
|
||||
if (!checkdate($mon, $day, $yr)) {
|
||||
$day = intval($now['mday']);
|
||||
$mon = intval($now['mon']);
|
||||
$yr = intval($now['year']);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue