/** * Builds Day objects for this Week * @param array of Day or Week objs representing selected dates (optional) * @return boolean * @access public */ function build($sDates = array()) { require_once CALENDAR_PATH . 'Day.php'; foreach ($this->daysOfWeek as $key => $dayOfWeek) { if ($this->dateMath->firstDayInMonth() == $dayOfWeek) { $offset = $key; break; } } if ($this->thisWeek == 1) { $start = false; $day = 1; for ($i = 1; $i <= 7; $i++) { if (!$start && $i > $offset) { $start = true; } if ($start) { $this->children[$i] = new Day($this->year, $this->month, $day); $day++; } else { $this->children[$i] = new Day($this->year, $this->month, 1); $this->children[$i]->setEmpty(); } $this->selectDay($sDates, $i); } } else { if ($this->thisWeek == $this->numWeeks) { $end = false; for ($i = 1; $i <= 7; $i++) { $day = ($this->thisWeek - 1) * 7 + ($i - $offset); if (!$end && $this->dateMath->daysInMonth() < $day) { $end = true; } if (!$end) { $this->children[$i] = new Day($this->year, $this->month, $day); } else { $this->children[$i] = new Day($this->year, $this->month, 1); $this->children[$i]->setEmpty(); } $this->selectDay($sDates, $i); } } else { // Does not take into account offset... for ($i = 1; $i <= 7; $i++) { $day = ($this->thisWeek - 1) * 7 + ($i - $offset); $this->children[$i] = new Day($this->year, $this->month, $day); $this->selectDay($sDates, $i); } } } return true; }
/** * Builds Day objects for this Month grouped by week. This method * can be used to provide a "formatted" view of a Month, where some * Day objects are "empty" and week beginnings and ends can be * indentified * <code> * $month = new Month(2003,8); * $month->buildWeekDays(); * while ( $day = $month->fetch() ) { * if ( $day->isStart() ) * echo ( '<tr>' ); * if ( $day->isEmpty() ) * echo ( '<td> </td>' ); * else * echo ( '<td>'.$day->thisDay().'</td>' ); * if ( $day->isEnd() ) * echo ( "</tr>\n" ); * } * </code> * @see Day::isEmpty() * @see Day::isFirst() * @see Day::isLast() * @param array of Day objects representing selected dates (optional) * @return boolean * @access public */ function buildWeekDays($sDates = array()) { require_once 'Day.php'; $this->setDaysOfMonth(); $dayOfMonth = 1; $start = false; $end = false; $sizeDaysOfMonth = count($this->daysOfMonth); for ($i = 1; $i <= $sizeDaysOfMonth; $i++) { $this->children[$i] = new Day($this->year, $this->month, $dayOfMonth); if ($i <= 7) { if ($i == 1) { $this->children[$i]->setFirst(); } else { if ($i == 7) { $this->children[$i]->setLast(); } } if ($this->dateMath->firstDayInMonth() == $this->daysOfMonth[$i - 1]) { $start = true; } if ($start) { $dayOfMonth++; } else { $this->children[$i]->setEmpty(); } } else { if ($i > $sizeDaysOfMonth - 7) { if ($i == $sizeDaysOfMonth - 6) { $this->children[$i]->setFirst(); } else { if ($i == $sizeDaysOfMonth) { $this->children[$i]->setLast(); } } if (!$end && $dayOfMonth == $this->dateMath->daysInMonth()) { $end = true; $dayOfMonth++; } else { if ($end) { $this->children[$i]->setEmpty(); $dayOfMonth = 1; } else { $dayOfMonth++; } } } else { if (($i - 1) % 7 == 0) { $this->children[$i]->setFirst(); } else { if ($i % 7 == 0) { $this->children[$i]->setLast(); } } $dayOfMonth++; } } foreach ($sDates as $sDate) { if ($this->year == $sDate->thisYear() && $this->month == $sDate->thisMonth() && $dayOfMonth - 1 == $sDate->thisDay() && !$this->children[$i]->isEmpty()) { $this->children[$i]->setSelected(); } } } return true; }