mirror of
https://github.com/moodle/moodle.git
synced 2025-08-08 18:36:42 +02:00
MDL-41792 core_calendar: refactored the calendar to allow the use of multiple calendar types
This commit is contained in:
parent
bb74cdfef3
commit
da3041379a
14 changed files with 759 additions and 475 deletions
|
@ -27,6 +27,16 @@ namespace core_calendar;
|
|||
*/
|
||||
abstract class type_base {
|
||||
|
||||
/**
|
||||
* Returns the name of the calendar.
|
||||
*
|
||||
* This is the non-translated name, usually just
|
||||
* the name of the calendar folder.
|
||||
*
|
||||
* @return string the calendar name
|
||||
*/
|
||||
public abstract function get_name();
|
||||
|
||||
/**
|
||||
* Returns a list of all the possible days for all months.
|
||||
*
|
||||
|
@ -62,10 +72,76 @@ abstract class type_base {
|
|||
*/
|
||||
public abstract function get_max_year();
|
||||
|
||||
/**
|
||||
* Returns the number of days in a week.
|
||||
*
|
||||
* @return int the number of days
|
||||
*/
|
||||
public abstract function get_num_weekdays();
|
||||
|
||||
/**
|
||||
* Returns an indexed list of all the names of the weekdays.
|
||||
*
|
||||
* The list starts with the index 0. Each index, representing a
|
||||
* day, must be an array that contains the indexes 'shortname'
|
||||
* and 'fullname'.
|
||||
*
|
||||
* @return array array of days
|
||||
*/
|
||||
public abstract function get_weekdays();
|
||||
|
||||
/**
|
||||
* Returns the index of the starting week day.
|
||||
*
|
||||
* This may vary, for example in the Gregorian calendar, some may consider Monday
|
||||
* as the start of the week, where as others may consider Sunday the start.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public abstract function get_starting_weekday();
|
||||
|
||||
/**
|
||||
* Returns the index of the weekday for a specific calendar date.
|
||||
*
|
||||
* @param int $year
|
||||
* @param int $month
|
||||
* @param int $day
|
||||
* @return int
|
||||
*/
|
||||
public abstract function get_weekday($year, $month, $day);
|
||||
|
||||
/**
|
||||
* Returns the number of days in a given month.
|
||||
*
|
||||
*
|
||||
* @param int $year
|
||||
* @param int $month
|
||||
* @return int the number of days
|
||||
*/
|
||||
public abstract function get_num_days_in_month($year, $month);
|
||||
|
||||
/**
|
||||
* Get the previous month.
|
||||
*
|
||||
* @param int $year
|
||||
* @param int $month
|
||||
* @return array previous month and year
|
||||
*/
|
||||
public abstract function get_prev_month($year, $month);
|
||||
|
||||
/**
|
||||
* Get the next month.
|
||||
*
|
||||
* @param int $year
|
||||
* @param int $month
|
||||
* @return array the following month and year
|
||||
*/
|
||||
public abstract function get_next_month($year, $month);
|
||||
|
||||
/**
|
||||
* Returns a formatted string that represents a date in user time.
|
||||
*
|
||||
* @param int $date the timestamp in UTC, as obtained from the database
|
||||
* @param int $time the timestamp in UTC, as obtained from the database
|
||||
* @param string $format strftime format
|
||||
* @param int|float|string $timezone the timezone to use
|
||||
* {@link http://docs.moodle.org/dev/Time_API#Timezone}
|
||||
|
@ -75,7 +151,7 @@ abstract class type_base {
|
|||
* if false then the leading zero is maintained
|
||||
* @return string the formatted date/time
|
||||
*/
|
||||
public abstract function timestamp_to_date_string($date, $format, $timezone, $fixday, $fixhour);
|
||||
public abstract function timestamp_to_date_string($time, $format, $timezone, $fixday, $fixhour);
|
||||
|
||||
/**
|
||||
* Given a $time timestamp in GMT (seconds since epoch), returns an array that represents
|
||||
|
@ -86,7 +162,7 @@ abstract class type_base {
|
|||
* {@link http://docs.moodle.org/dev/Time_API#Timezone}
|
||||
* @return array an array that represents the date in user time
|
||||
*/
|
||||
public abstract function timestamp_to_date_array($time, $timezone);
|
||||
public abstract function timestamp_to_date_array($time, $timezone = 99);
|
||||
|
||||
/**
|
||||
* Provided with a day, month, year, hour and minute in the specific
|
||||
|
@ -97,7 +173,7 @@ abstract class type_base {
|
|||
* @param int $day
|
||||
* @param int $hour
|
||||
* @param int $minute
|
||||
* @return array the converted day, month and year.
|
||||
* @return array the converted date
|
||||
*/
|
||||
public abstract function convert_to_gregorian($year, $month, $day, $hour = 0, $minute = 0);
|
||||
|
||||
|
@ -110,7 +186,7 @@ abstract class type_base {
|
|||
* @param int $day
|
||||
* @param int $hour
|
||||
* @param int $minute
|
||||
* @return array the converted day, month and year.
|
||||
* @return array the converted date
|
||||
*/
|
||||
public abstract function convert_from_gregorian($year, $month, $day, $hour = 0, $minute = 0);
|
||||
}
|
||||
|
|
|
@ -74,7 +74,8 @@ class type_factory {
|
|||
public 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.
|
||||
// Course calendartype can override all other settings for this page.
|
||||
if (!empty($COURSE->id) and $COURSE->id != SITEID and !empty($COURSE->calendartype)) {
|
||||
$return = $COURSE->calendartype;
|
||||
} else if (!empty($SESSION->calendartype)) { // Session calendartype can override other settings.
|
||||
$return = $SESSION->calendartype;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue