Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
493 ddelon 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.1 2005-09-30 14:58:00 ddelon Exp $
21
//
22
/**
23
 * @package Calendar
24
 * @version $Id: Month.php,v 1.1 2005-09-30 14:58:00 ddelon Exp $
25
 */
26
 
27
/**
28
 * Allows Calendar include path to be redefined
29
 * @ignore
30
 */
31
if (!defined('CALENDAR_ROOT')) {
32
    define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
33
}
34
 
35
/**
36
 * Load Calendar base class
37
 */
38
require_once CALENDAR_ROOT.'Calendar.php';
39
 
40
/**
41
 * Represents a Month and builds Days
42
 * <code>
43
 * require_once 'Calendar'.DIRECTORY_SEPARATOR.'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
 */
53
class Calendar_Month extends Calendar
54
{
55
    /**
56
     * Constructs Calendar_Month
57
     * @param int year e.g. 2003
58
     * @param int month e.g. 5
59
     * @param int (optional) unused in this class
60
     * @access public
61
     */
62
    function Calendar_Month($y, $m, $firstDay=null)
63
    {
64
        Calendar::Calendar($y, $m);
65
    }
66
 
67
    /**
68
     * Builds Day objects for this Month. Creates as many Calendar_Day objects
69
     * as there are days in the month
70
     * @param array (optional) Calendar_Day objects representing selected dates
71
     * @return boolean
72
     * @access public
73
     */
74
    function build($sDates=array())
75
    {
76
        require_once CALENDAR_ROOT.'Day.php';
77
        $daysInMonth = $this->cE->getDaysInMonth($this->year, $this->month);
78
        for ($i=1; $i<=$daysInMonth; $i++) {
79
            $this->children[$i] = new Calendar_Day($this->year, $this->month, $i);
80
        }
81
        if (count($sDates) > 0) {
82
            $this->setSelection($sDates);
83
        }
84
        return true;
85
    }
86
 
87
    /**
88
     * Called from build()
89
     * @param array
90
     * @return void
91
     * @access private
92
     */
93
    function setSelection($sDates)
94
    {
95
        foreach ($sDates as $sDate) {
96
            if ($this->year == $sDate->thisYear()
97
                && $this->month == $sDate->thisMonth() )
98
            {
99
                $key = $sDate->thisDay();
100
                if (isset($this->children[$key])) {
101
                    $sDate->setSelected();
102
                    $class = strtolower(get_class($sDate));
103
                    if ( $class == 'calendar_day' || $class == 'calendar_decorator' ) {
104
                        $sDate->setFirst($this->children[$key]->isFirst());
105
                        $sDate->setLast($this->children[$key]->isLast());
106
                    }
107
                    $this->children[$key] = $sDate;
108
                }
109
            }
110
        }
111
    }
112
}
113
?>