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
// |          Lorenzo Alberton <l dot alberton at quipo dot it>           |
19
// +----------------------------------------------------------------------+
20
//
21
// $Id: Weeks.php,v 1.1 2005-09-30 14:58:00 ddelon Exp $
22
//
23
/**
24
 * @package Calendar
25
 * @version $Id: Weeks.php,v 1.1 2005-09-30 14:58:00 ddelon Exp $
26
 */
27
 
28
/**
29
 * Allows Calendar include path to be redefined
30
 * @ignore
31
 */
32
if (!defined('CALENDAR_ROOT')) {
33
    define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
34
}
35
 
36
/**
37
 * Load Calendar base class
38
 */
39
require_once CALENDAR_ROOT.'Calendar.php';
40
 
41
/**
42
 * Load base month
43
 */
44
require_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
 */
59
class 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=false)
83
    {
84
        Calendar_Month::Calendar_Month($y, $m);
85
        $this->firstDay = $firstDay;
86
    }
87
 
88
    /**
89
     * Builds Calendar_Week objects for the Month. Note that Calendar_Week
90
     * builds Calendar_Day object in tabular form (with Calendar_Day->empty)
91
     * @param array (optional) Calendar_Week objects representing selected dates
92
     * @return boolean
93
     * @access public
94
     */
95
    function build($sDates=array())
96
    {
97
        require_once CALENDAR_ROOT.'Table'.DIRECTORY_SEPARATOR.'Helper.php';
98
        $this->tableHelper = & new Calendar_Table_Helper($this, $this->firstDay);
99
        require_once CALENDAR_ROOT.'Week.php';
100
        $numWeeks = $this->tableHelper->getNumWeeks();
101
        for ($i=1, $d=1; $i<=$numWeeks; $i++,
102
            $d+=$this->cE->getDaysInWeek(
103
                $this->thisYear(),
104
                $this->thisMonth(),
105
                $this->thisDay()) ) {
106
            $this->children[$i] = new Calendar_Week(
107
                $this->year, $this->month, $d, $this->tableHelper->getFirstDay());
108
        }
109
        //used to set empty days
110
        $this->children[1]->setFirst(true);
111
        $this->children[$numWeeks]->setLast(true);
112
 
113
        // Handle selected weeks here
114
        if (count($sDates) > 0) {
115
            $this->setSelection($sDates);
116
        }
117
        return true;
118
    }
119
 
120
    /**
121
     * Called from build()
122
     * @param array
123
     * @return void
124
     * @access private
125
     */
126
    function setSelection($sDates)
127
    {
128
        foreach ($sDates as $sDate) {
129
            if ($this->year == $sDate->thisYear()
130
                && $this->month == $sDate->thisMonth())
131
            {
132
                $key = $sDate->thisWeek('n_in_month');
133
                if (isset($this->children[$key])) {
134
                    $this->children[$key]->setSelected();
135
                }
136
            }
137
        }
138
    }
139
}
140
?>