1, "Monday" => 2, "Tuesday" => 3, "Wednesday" => 4, "Thursday" => 5, "Friday" => 6, "Saturday" => 7 ); return $days[$dayName]; } abstract class QuickCalendar { protected $monthObj; private $monthNum; private $monthName; private $year; protected $allDays = array(); private $FIRST_YEAR = 2007; public function __construct($monthNum = 0, $year = 0) { //validate, assign month number (1-12) if ($monthNum > 0 && $monthNum < 13) { $this->monthNum = $monthNum; } else { $this->monthNum = date('n');} //validate, assign year if ($year >= $this->FIRST_YEAR) { $this->year = $year; } else { $this->year = date('Y'); } //create month, which creates days $this->monthObj = new Month($this, $this->monthNum, $this->year); //retrieve some information for public $this->allDays = $this->monthObj->getDays(); $this->monthName = $this->monthObj->getName(); } public function fillData($dataArray) { // array of array of data (ie links for each day) foreach ($dataArray as $date => $data) { $this->allDays[$date]->data = $data; } } public function printCalendar() { $this->weekBeginTemplate(); $this->printDaysBefore(); for ($i = 1; $i <= $this->getDaysInMonth(); $i++) { if ($this->allDays[$i]->getName() == "Sunday") { $this->weekEndTemplate(); $this->weekBeginTemplate(); } $this->dayTemplate($i, $this->allDays[$i]); } $this->printDaysAfter(); $this->weekEndTemplate(); } public function getMonthNum() { return $this->monthNum; } public function getMonthName() { return $this->monthName; } public function getYear() { return $this->monthObj->getYear(); } public function getDaysInMonth() { return $this->monthObj->getDaysInMonth(); } public function getPreviousMonthNum() { return $this->monthObj->getPreviousMonthObj()->getMonthNum(); } public function getPreviousMonthName() { return $this->monthObj->getPreviousMonthObj()->getName(); } public function getPreviousMonthYear() { return $this->monthObj->getPreviousMonthObj()->getYear(); } public function getNextMonthNum() { return $this->monthObj->getNextMonthObj()->getMonthNum(); } public function getNextMonthName() { return $this->monthObj->getNextMonthObj()->getName(); } public function getNextMonthYear() { return $this->monthObj->getNextMonthObj()->getYear(); } public function printDaysBefore() { $this->monthObj->printDaysBefore(); } public function printDaysAfter() { $this->monthObj->printDaysAfter(); } public abstract function gatherData(); } class PartialMonth { protected $year; protected $monthNum; protected $name; protected $daysInMonth; protected $todaysDate; protected $firstDayOfMonth; protected $lastDayOfMonth; public function __construct(QuickCalendar $calObj, $monthNum, $year) { $this->year = (int) $year; $this->monthNum = (int) $monthNum; $this->name = date('F', mktime(0, 0, 0, $this->monthNum, 1, $this->year)); $this->daysInMonth = date('t', mktime(0, 0, 0, $this->monthNum, 1, $this->year)); $this->setTodaysDate(); $this->firstDayOfMonth = new Day(1, $this, $this->todaysDate); $this->lastDayOfMonth = new Day($this->daysInMonth, $this, $this->todaysDate); } public function getYear() { return $this->year; } public function getMonthNum() { return $this->monthNum; } public function getName() { return $this->name; } public function getDaysInMonth() { return $this->daysInMonth; } private function setTodaysDate($date = null) { $d = -1; if ($this->monthNum != ((int) date('n'))) { } else if (isset($date)) { $d = (int) $date; } else { $d = (int) date('j'); } $this->todaysDate = $d; } } class Month extends PartialMonth { private $days = array(); //28-31 private $previousMonth; private $nextMonth; private $calObj; public function __construct(QuickCalendar $calObj, $monthNum, $year){ parent::__construct($calObj, $monthNum, $year); $this->calObj = $calObj; if ($this->monthNum == 1) { $pMonth = 12; $pYear = $this->year - 1; } else { $pMonth = $this->monthNum - 1; $pYear = $this->year; } $this->previousMonth = new PartialMonth($this->calObj, $pMonth, $pYear); if ($this->monthNum == 12) { $nMonth = 1; $nYear = $this->year + 1; } else { $nMonth = $this->monthNum + 1; $nYear = $this->year; } $this->nextMonth = new PartialMonth($this->calObj, $nMonth, $nYear); $this->makeDays(); } private function makeDays() { $this->days[1] = $this->firstDayOfMonth; $this->days[$this->daysInMonth] = $this->lastDayOfMonth; //get days except first and last for ($i = 2; $i < $this->daysInMonth; $i++) { $this->days[$i] = new Day($i, $this, $this->todaysDate); } } public function getDays() { return $this->days; } public function getPreviousMonthObj() { return $this->previousMonth; } public function getNextMonthObj() { return $this->nextMonth; } public function printDaysBefore() { $firstDayNum = getDayNumInWeek($this->firstDayOfMonth->getName()); $daysInPMonth = $this->previousMonth->getDaysInMonth(); $pMonthStartDate = ($daysInPMonth - $firstDayNum) + 2; $numDays = ($daysInPMonth - $pMonthStartDate) + 1; for ($i = $pMonthStartDate; $i <= $daysInPMonth; $i++) { $this->calObj->offDayTemplate($i); } } public function printDaysAfter() { $lastDayNum = getDayNumInWeek($this->lastDayOfMonth->getName()); $numDays = 7 - $lastDayNum; for ($i = 1; $i <= $numDays; $i++) { $this->calObj->offDayTemplate($i); } } } class Day { //check the privacy of these vars public $data = array(); //to be filled by QuickCalendar::fillData() private $date; private $name; private $monthObj; private $weekend = ''; private $today = ''; public function __construct($date, PartialMonth $monthObj, $realDate) { $date = (int) $date; if ($date > 0 && $date < 32) { $this->date = $date; } else { echo "Error: date provided for new Day was incorrect. Failed.
"; return false; } $this->monthObj = $monthObj; $this->name = date('l', mktime(0, 0, 0, $this->monthObj->getMonthNum(), $this->date, $this->monthObj->getYear())); if ($this->name == 'Saturday' || $this->name == 'Sunday') { $this->weekend = ' weekend'; } //dont assign 'today' for PartialMonth class if (get_class($this->monthObj) != "Month") { $realDate = -1; } if ($realDate == $this->date) { $this->today = ' today'; } } public function getName() { return $this->name; } public function getDate() { return $this->date; } //public function getMonthObj() { return $this->monthObj; } public function getIsWeekendString() { return $this->weekend; } public function getIsTodayString() { return $this->today; } } ?>