PageRenderTime 53ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/calendar/classes/type_base.php

https://github.com/pauln/moodle
PHP | 220 lines | 23 code | 21 blank | 176 comment | 0 complexity | 5f66754159a4a731e16a921db9d9f209 MD5 | raw file
  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. namespace core_calendar;
  17. /**
  18. * Defines functions used by calendar type plugins.
  19. *
  20. * This library provides a unified interface for calendar types.
  21. *
  22. * @package core_calendar
  23. * @copyright 2008 onwards Foodle Group {@link http://foodle.org}
  24. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25. */
  26. abstract class type_base {
  27. /**
  28. * Returns the name of the calendar.
  29. *
  30. * This is the non-translated name, usually just
  31. * the name of the calendar folder.
  32. *
  33. * @return string the calendar name
  34. */
  35. public abstract function get_name();
  36. /**
  37. * Returns a list of all the possible days for all months.
  38. *
  39. * This is used to generate the select box for the days
  40. * in the date selector elements. Some months contain more days
  41. * than others so this function should return all possible days as
  42. * we can not predict what month will be chosen (the user
  43. * may have JS turned off and we need to support this situation in
  44. * Moodle).
  45. *
  46. * @return array the days
  47. */
  48. public abstract function get_days();
  49. /**
  50. * Returns a list of all the names of the months.
  51. *
  52. * @return array the month names
  53. */
  54. public abstract function get_months();
  55. /**
  56. * Returns the minimum year for the calendar.
  57. *
  58. * @return int The minimum year
  59. */
  60. public abstract function get_min_year();
  61. /**
  62. * Returns the maximum year for the calendar
  63. *
  64. * @return int The maximum year
  65. */
  66. public abstract function get_max_year();
  67. /**
  68. * Returns an array of years.
  69. *
  70. * @param int $minyear
  71. * @param int $maxyear
  72. * @return array the years
  73. */
  74. public abstract function get_years($minyear = null, $maxyear = null);
  75. /**
  76. * Returns a multidimensional array with information for day, month, year
  77. * and the order they are displayed when selecting a date.
  78. * The order in the array will be the order displayed when selecting a date.
  79. * Override this function to change the date selector order.
  80. *
  81. * @param int $minyear The year to start with
  82. * @param int $maxyear The year to finish with
  83. * @return array Full date information
  84. */
  85. public abstract function get_date_order($minyear = null, $maxyear = null);
  86. /**
  87. * Returns the number of days in a week.
  88. *
  89. * @return int the number of days
  90. */
  91. public abstract function get_num_weekdays();
  92. /**
  93. * Returns an indexed list of all the names of the weekdays.
  94. *
  95. * The list starts with the index 0. Each index, representing a
  96. * day, must be an array that contains the indexes 'shortname'
  97. * and 'fullname'.
  98. *
  99. * @return array array of days
  100. */
  101. public abstract function get_weekdays();
  102. /**
  103. * Returns the index of the starting week day.
  104. *
  105. * This may vary, for example in the Gregorian calendar, some may consider Monday
  106. * as the start of the week, where as others may consider Sunday the start.
  107. *
  108. * @return int
  109. */
  110. public abstract function get_starting_weekday();
  111. /**
  112. * Returns the index of the weekday for a specific calendar date.
  113. *
  114. * @param int $year
  115. * @param int $month
  116. * @param int $day
  117. * @return int
  118. */
  119. public abstract function get_weekday($year, $month, $day);
  120. /**
  121. * Returns the number of days in a given month.
  122. *
  123. *
  124. * @param int $year
  125. * @param int $month
  126. * @return int the number of days
  127. */
  128. public abstract function get_num_days_in_month($year, $month);
  129. /**
  130. * Get the previous month.
  131. *
  132. * @param int $year
  133. * @param int $month
  134. * @return array previous month and year
  135. */
  136. public abstract function get_prev_month($year, $month);
  137. /**
  138. * Get the next month.
  139. *
  140. * @param int $year
  141. * @param int $month
  142. * @return array the following month and year
  143. */
  144. public abstract function get_next_month($year, $month);
  145. /**
  146. * Returns a formatted string that represents a date in user time.
  147. *
  148. * @param int $time the timestamp in UTC, as obtained from the database
  149. * @param string $format strftime format
  150. * @param int|float|string $timezone the timezone to use
  151. * {@link http://docs.moodle.org/dev/Time_API#Timezone}
  152. * @param bool $fixday if true then the leading zero from %d is removed,
  153. * if false then the leading zero is maintained
  154. * @param bool $fixhour if true then the leading zero from %I is removed,
  155. * if false then the leading zero is maintained
  156. * @return string the formatted date/time
  157. */
  158. public abstract function timestamp_to_date_string($time, $format, $timezone, $fixday, $fixhour);
  159. /**
  160. * Given a $time timestamp in GMT (seconds since epoch), returns an array that represents
  161. * the date in user time.
  162. *
  163. * @param int $time timestamp in GMT
  164. * @param float|int|string $timezone the timezone to use to calculate the time
  165. * {@link http://docs.moodle.org/dev/Time_API#Timezone}
  166. * @return array an array that represents the date in user time
  167. */
  168. public abstract function timestamp_to_date_array($time, $timezone = 99);
  169. /**
  170. * Provided with a day, month, year, hour and minute in the specific
  171. * calendar type convert it into the equivalent Gregorian date.
  172. *
  173. * @param int $year
  174. * @param int $month
  175. * @param int $day
  176. * @param int $hour
  177. * @param int $minute
  178. * @return array the converted date
  179. */
  180. public abstract function convert_to_gregorian($year, $month, $day, $hour = 0, $minute = 0);
  181. /**
  182. * Provided with a day, month, year, hour and minute in a Gregorian date
  183. * convert it into the specific calendar type date.
  184. *
  185. * @param int $year
  186. * @param int $month
  187. * @param int $day
  188. * @param int $hour
  189. * @param int $minute
  190. * @return array the converted date
  191. */
  192. public abstract function convert_from_gregorian($year, $month, $day, $hour = 0, $minute = 0);
  193. /**
  194. * This return locale for windows os.
  195. *
  196. * @return string locale
  197. */
  198. public abstract function locale_win_charset();
  199. }