* @copyright 2003-2007 Harry Fuecks * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) * @version CVS: $Id: Month.php 300729 2010-06-24 12:05:53Z quipo $ * @link http://pear.php.net/package/Calendar */ /** * Allows Calendar include path to be redefined * @ignore */ if (!defined('CALENDAR_ROOT')) { define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR); } /** * Load Calendar base class */ require_once CALENDAR_ROOT.'Calendar.php'; /** * Represents a Month and builds Days * * require_once 'Calendar/Month.php'; * $Month = new Calendar_Month(2003, 10); // Oct 2003 * $Month->build(); // Build Calendar_Day objects * while ($Day = & $Month->fetch()) { * echo $Day->thisDay().'
'; * } *
* * @category Date and Time * @package Calendar * @author Harry Fuecks * @copyright 2003-2007 Harry Fuecks * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) * @link http://pear.php.net/package/Calendar * @access public */ class Calendar_Month extends Calendar { /** * Constructs Calendar_Month * * @param int $y year e.g. 2003 * @param int $m month e.g. 5 * @param int $firstDay first day of the week [optional] * * @access public */ function Calendar_Month($y, $m, $firstDay=null) { parent::Calendar($y, $m); $this->firstDay = $this->defineFirstDayOfWeek($firstDay); } /** * Builds Day objects for this Month. Creates as many Calendar_Day objects * as there are days in the month * * @param array $sDates (optional) Calendar_Day objects representing selected dates * * @return boolean * @access public */ function build($sDates = array()) { include_once CALENDAR_ROOT.'Day.php'; $daysInMonth = $this->cE->getDaysInMonth($this->year, $this->month); for ($i=1; $i<=$daysInMonth; $i++) { $this->children[$i] = new Calendar_Day($this->year, $this->month, $i); } if (count($sDates) > 0) { $this->setSelection($sDates); } return true; } /** * Called from build() * * @param array $sDates Calendar_Day objects representing selected dates * * @return void * @access private */ function setSelection($sDates) { foreach ($sDates as $sDate) { if ($this->year == $sDate->thisYear() && $this->month == $sDate->thisMonth() ) { $key = $sDate->thisDay(); if (isset($this->children[$key])) { $sDate->setSelected(); $class = strtolower(get_class($sDate)); if ($class == 'calendar_day' || $class == 'calendar_decorator') { $sDate->setFirst($this->children[$key]->isFirst()); $sDate->setLast($this->children[$key]->isLast()); } $this->children[$key] = $sDate; } } } } } ?>