Source for file Schedule.class.php

Documentation is available at Schedule.class.php

  1. <?php
  2. /**
  3. * @since 5/25/05
  4. * @package harmoni.primitives.chronology
  5. *
  6. * @copyright Copyright &copy; 2005, Middlebury College
  7. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  8. *
  9. * @version $Id: Schedule.class.php,v 1.4 2007/09/04 20:25:25 adamfranco Exp $
  10. *
  11. * @link http://harmoni.sourceforge.net/
  12. * @author Adam Franco <adam AT adamfranco DOT com> <afranco AT middlebury DOT edu>
  13. */
  14. require_once(dirname(__FILE__)."/Timespan.class.php");
  15.  
  16. /**
  17. * I represent a powerful class for implementing recurring schedules.
  18. *
  19. * To create new Schedule instances, <b>use one of the static instance-creation
  20. * methods</b>, NOT 'new Schedule':
  21. * - {@link current Schedule::current()}
  22. * - {@link current Schedule::current()}
  23. * - {@link epoch Schedule::epoch()}
  24. * - {@link starting Schedule::starting($aDateAndTime)}
  25. * - {@link startingDuration Schedule::startingDuration($aDateAndTime, $aDuration)}
  26. * - {@link startingEnding Schedule::startingEnding($startDateAndTime, $endDateAndTime)}
  27. *
  28. * @since 5/25/05
  29. * @package harmoni.primitives.chronology
  30. *
  31. * @copyright Copyright &copy; 2005, Middlebury College
  32. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  33. *
  34. * @version $Id: Schedule.class.php,v 1.4 2007/09/04 20:25:25 adamfranco Exp $
  35. *
  36. * @link http://harmoni.sourceforge.net/
  37. * @author Adam Franco <adam AT adamfranco DOT com> <afranco AT middlebury DOT edu>
  38. */
  39. class Schedule
  40. extends Timespan
  41. {
  42. /*******************************************************
  43. * Class Methods - Instance Creation
  44. *
  45. * All static instance creation methods have an optional
  46. * $class parameter which is used to get around the limitations
  47. * of not being able to find the class of the object that
  48. * recieved the initial method call rather than the one in
  49. * which it is implemented. These parameters SHOULD NOT BE
  50. * USED OUTSIDE OF THIS PACKAGE.
  51. *********************************************************/
  52.  
  53. /**
  54. * Answer a new object that represents now.
  55. *
  56. * @param optional string $class DO NOT USE OUTSIDE OF PACKAGE.
  57. * This parameter is used to get around the limitations of not being
  58. * able to find the class of the object that recieved the initial
  59. * method call.
  60. * @return object Schedule
  61. * @access public
  62. * @since 5/5/05
  63. * @static
  64. */
  65. function current ( $class = 'Schedule' ) {
  66. $obj = parent::current($class);
  67. return $obj;
  68. }
  69. /**
  70. * Answer a Month starting on the Squeak epoch: 1 January 1901
  71. *
  72. * @param optional string $class DO NOT USE OUTSIDE OF PACKAGE.
  73. * This parameter is used to get around the limitations of not being
  74. * able to find the class of the object that recieved the initial
  75. * method call.
  76. * @return object Schedule
  77. * @access public
  78. * @since 5/5/05
  79. * @static
  80. */
  81. function epoch ( $class = 'Schedule' ) {
  82. $obj = parent::epoch($class);
  83. return $obj;
  84. }
  85. /**
  86. * Create a new object starting now, with zero duration
  87. *
  88. * @param object DateAndTime $aDateAndTime
  89. * @param optional string $class DO NOT USE OUTSIDE OF PACKAGE.
  90. * This parameter is used to get around the limitations of not being
  91. * able to find the class of the object that recieved the initial
  92. * method call.
  93. * @return object Schedule
  94. * @access public
  95. * @since 5/5/05
  96. * @static
  97. */
  98. function starting ( $aDateAndTime, $class = 'Schedule' ) {
  99. $obj = parent::starting($aDateAndTime, $class);
  100. return $obj;
  101. }
  102. /**
  103. * Create a new object with given start and end DateAndTimes
  104. *
  105. * @param object DateAndTime $startDateAndTime
  106. * @param object DateAndTime $endDateAndTime
  107. * @param optional string $class DO NOT USE OUTSIDE OF PACKAGE.
  108. * This parameter is used to get around the limitations of not being
  109. * able to find the class of the object that recieved the initial
  110. * method call.
  111. * @return object Schedule
  112. * @access public
  113. * @since 5/11/05
  114. */
  115. function startingEnding ( $startDateAndTime, $endDateAndTime,
  116. $class = 'Schedule' )
  117. {
  118. $obj = parent::startingEnding ( $startDateAndTime, $endDateAndTime, $class);
  119. return $obj;
  120. }
  121. /**
  122. * Create a new object starting now, with a given duration.
  123. *
  124. * @param object DateAndTime $aDateAndTime
  125. * @param object Duration $aDuration
  126. * @param optional string $class DO NOT USE OUTSIDE OF PACKAGE.
  127. * This parameter is used to get around the limitations of not being
  128. * able to find the class of the object that recieved the initial
  129. * method call.
  130. * @return object Schedule
  131. * @access public
  132. * @since 5/5/05
  133. * @static
  134. */
  135. function startingDuration ( $aDateAndTime, $aDuration, $class = 'Schedule' ) {
  136. $obj = parent::startingDuration ( $aDateAndTime, $aDuration, $class);
  137. return $obj;
  138. }
  139.  
  140. /*******************************************************
  141. * Instance methods - Enumerating
  142. *********************************************************/
  143.  
  144. /**
  145. * Return an array of the DateAndTimes scheduled between aStart and anEnd.
  146. *
  147. * @param object $aStart
  148. * @param object $anEnd
  149. * @return array Of DateAndTime objects
  150. * @access public
  151. * @since 5/25/05
  152. */
  153. function between ( $aStart, $anEnd ) {
  154. $results = array();
  155. $end =$anEnd->min($this->end());
  156. // iterate to the first element in the range
  157. $element =$this->start();
  158. $i = 0;
  159. while ($element->isLessThan($aStart)) {
  160. $element =$element->plus($this->schedule[$i]);
  161. $i++;
  162. if ($i >= count($this->schedule))
  163. $i = 0;
  164. }
  165. // Reset our schedule index to the first one.
  166. // This is the way it is implemented in Squeak, though I'm not sure why.
  167. $i = 0;
  168. // Collect the results
  169. while ($element->isLessThanOrEqualTo($anEnd)) {
  170. $results[] =$element;
  171. $element =$element->plus($this->schedule[$i]);
  172. $i++;
  173. if ($i >= count($this->schedule))
  174. $i = 0;
  175. }
  176. return $results;
  177. }
  178. /**
  179. * Answer the DateAndTimes scheduled over the reciever's entire duration.
  180. *
  181. * @return Of DateAndTime objects
  182. * @access public
  183. * @since 5/25/05
  184. */
  185. function dateAndTimes () {
  186. $obj =$this->between($this->start, $this->end());
  187. return $obj;
  188. }
  189. /**
  190. * Set the schedule
  191. *
  192. * @param array $anArrayOfDurations
  193. * @return void
  194. * @access public
  195. * @since 5/25/05
  196. */
  197. function setSchedule ( $anArrayOfDurations ) {
  198. $this->schedule =$anArrayOfDurations;
  199. }
  200. /**
  201. * Get the schedule elements
  202. *
  203. * @return array $anArrayOfDurations
  204. * @access public
  205. * @since 5/25/05
  206. */
  207. function getSchedule () {
  208. return $this->schedule;
  209. }
  210. }
  211.  
  212. ?>

Documentation generated on Wed, 19 Sep 2007 10:26:14 -0400 by phpDocumentor 1.3.0RC3