source: branches/version-2_13_0/data/module/Calendar/Month.php @ 23143

Revision 23143, 3.8 KB checked in by m_uehara, 7 years ago (diff)

#2348 r23140 をマージ

  • Property svn:eol-style set to LF
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/* vim: set expandtab tabstop=4 shiftwidth=4: */
3//
4// +----------------------------------------------------------------------+
5// | PHP Version 4                                                        |
6// +----------------------------------------------------------------------+
7// | Copyright (c) 1997-2002 The PHP Group                                |
8// +----------------------------------------------------------------------+
9// | This source file is subject to version 2.02 of the PHP license,      |
10// | that is bundled with this package in the file LICENSE, and is        |
11// | available at through the world-wide-web at                           |
12// | http://www.php.net/license/3_0.txt.                                  |
13// | If you did not receive a copy of the PHP license and are unable to   |
14// | obtain it through the world-wide-web, please send a note to          |
15// | license@php.net so we can mail you a copy immediately.               |
16// +----------------------------------------------------------------------+
17// | Authors: Harry Fuecks <hfuecks@phppatterns.com>                      |
18// +----------------------------------------------------------------------+
19//
20// $Id: Month.php,v 1.3 2005/10/22 10:10:26 quipo Exp $
21//
22/**
23 * @package Calendar
24 * @version $Id: Month.php,v 1.3 2005/10/22 10:10:26 quipo Exp $
25 */
26
27/**
28 * Allows Calendar include path to be redefined
29 * @ignore
30 */
31if (!defined('CALENDAR_ROOT')) {
32    define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
33}
34
35/**
36 * Load Calendar base class
37 */
38require_once CALENDAR_ROOT.'Calendar.php';
39
40/**
41 * Represents a Month and builds Days
42 * <code>
43 * require_once 'Calendar/Month.php';
44 * $Month = & new Calendar_Month(2003, 10); // Oct 2003
45 * $Month->build(); // Build Calendar_Day objects
46 * while ($Day = & $Month->fetch()) {
47 *     echo $Day->thisDay().'<br />';
48 * }
49 * </code>
50 * @package Calendar
51 * @access public
52 */
53class Calendar_Month extends Calendar
54{
55    /**
56     * Constructs Calendar_Month
57     * @param int $y year e.g. 2003
58     * @param int $m month e.g. 5
59     * @param int $firstDay first day of the week [optional]
60     * @access public
61     */
62    function Calendar_Month($y, $m, $firstDay=null)
63    {
64        Calendar::Calendar($y, $m);
65        $this->firstDay = $this->defineFirstDayOfWeek($firstDay);
66    }
67
68    /**
69     * Builds Day objects for this Month. Creates as many Calendar_Day objects
70     * as there are days in the month
71     * @param array (optional) Calendar_Day objects representing selected dates
72     * @return boolean
73     * @access public
74     */
75    function build($sDates=array())
76    {
77        require_once CALENDAR_ROOT.'Day.php';
78        $daysInMonth = $this->cE->getDaysInMonth($this->year, $this->month);
79        for ($i=1; $i<=$daysInMonth; $i++) {
80            $this->children[$i] = new Calendar_Day($this->year, $this->month, $i);
81        }
82        if (count($sDates) > 0) {
83            $this->setSelection($sDates);
84        }
85        return true;
86    }
87
88    /**
89     * Called from build()
90     * @param array
91     * @return void
92     * @access private
93     */
94    function setSelection($sDates)
95    {
96        foreach ($sDates as $sDate) {
97            if ($this->year == $sDate->thisYear()
98                && $this->month == $sDate->thisMonth()
99            ) {
100                $key = $sDate->thisDay();
101                if (isset($this->children[$key])) {
102                    $sDate->setSelected();
103                    $class = strtolower(get_class($sDate));
104                    if ($class == 'calendar_day' || $class == 'calendar_decorator') {
105                        $sDate->setFirst($this->children[$key]->isFirst());
106                        $sDate->setLast($this->children[$key]->isLast());
107                    }
108                    $this->children[$key] = $sDate;
109                }
110            }
111        }
112    }
113}
114?>
Note: See TracBrowser for help on using the repository browser.