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

Revision 23143, 4.4 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// |          Lorenzo Alberton <l dot alberton at quipo dot it>           |
19// +----------------------------------------------------------------------+
20//
21// $Id: Weeks.php,v 1.3 2005/10/22 10:28:49 quipo Exp $
22//
23/**
24 * @package Calendar
25 * @version $Id: Weeks.php,v 1.3 2005/10/22 10:28:49 quipo Exp $
26 */
27
28/**
29 * Allows Calendar include path to be redefined
30 * @ignore
31 */
32if (!defined('CALENDAR_ROOT')) {
33    define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
34}
35
36/**
37 * Load Calendar base class
38 */
39require_once CALENDAR_ROOT.'Calendar.php';
40
41/**
42 * Load base month
43 */
44require_once CALENDAR_ROOT.'Month.php';
45
46/**
47 * Represents a Month and builds Weeks
48 * <code>
49 * require_once 'Calendar'.DIRECTORY_SEPARATOR.'Month'.DIRECTORY_SEPARATOR.'Weeks.php';
50 * $Month = & new Calendar_Month_Weeks(2003, 10); // Oct 2003
51 * $Month->build(); // Build Calendar_Day objects
52 * while ($Week = & $Month->fetch()) {
53 *     echo $Week->thisWeek().'<br />';
54 * }
55 * </code>
56 * @package Calendar
57 * @access public
58 */
59class Calendar_Month_Weeks extends Calendar_Month
60{
61    /**
62     * Instance of Calendar_Table_Helper
63     * @var Calendar_Table_Helper
64     * @access private
65     */
66    var $tableHelper;
67
68    /**
69     * First day of the week
70     * @access private
71     * @var string
72     */
73    var $firstDay;
74
75    /**
76     * Constructs Calendar_Month_Weeks
77     * @param int year e.g. 2003
78     * @param int month e.g. 5
79     * @param int (optional) first day of week (e.g. 0 for Sunday, 2 for Tuesday etc.)
80     * @access public
81     */
82    function Calendar_Month_Weeks($y, $m, $firstDay=null)
83    {
84        Calendar_Month::Calendar_Month($y, $m, $firstDay);
85    }
86
87    /**
88     * Builds Calendar_Week objects for the Month. Note that Calendar_Week
89     * builds Calendar_Day object in tabular form (with Calendar_Day->empty)
90     * @param array (optional) Calendar_Week objects representing selected dates
91     * @return boolean
92     * @access public
93     */
94    function build($sDates=array())
95    {
96        require_once CALENDAR_ROOT.'Table/Helper.php';
97        $this->tableHelper = & new Calendar_Table_Helper($this, $this->firstDay);
98        require_once CALENDAR_ROOT.'Week.php';
99        $numWeeks = $this->tableHelper->getNumWeeks();
100        for ($i=1, $d=1; $i<=$numWeeks; $i++,
101            $d+=$this->cE->getDaysInWeek(
102                $this->thisYear(),
103                $this->thisMonth(),
104                $this->thisDay()) ) {
105            $this->children[$i] = new Calendar_Week(
106                $this->year, $this->month, $d, $this->tableHelper->getFirstDay());
107        }
108        //used to set empty days
109        $this->children[1]->setFirst(true);
110        $this->children[$numWeeks]->setLast(true);
111
112        // Handle selected weeks here
113        if (count($sDates) > 0) {
114            $this->setSelection($sDates);
115        }
116        return true;
117    }
118
119    /**
120     * Called from build()
121     * @param array
122     * @return void
123     * @access private
124     */
125    function setSelection($sDates)
126    {
127        foreach ($sDates as $sDate) {
128            if ($this->year == $sDate->thisYear()
129                && $this->month == $sDate->thisMonth())
130            {
131                $key = $sDate->thisWeek('n_in_month');
132                if (isset($this->children[$key])) {
133                    $this->children[$key]->setSelected();
134                }
135            }
136        }
137    }
138}
139?>
Note: See TracBrowser for help on using the repository browser.