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: Year.php,v 1.1 2005-09-30 14:58:00 ddelon Exp $
21
//
22
/**
23
 * @package Calendar
24
 * @version $Id: Year.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 Year and builds Months<br>
42
 * <code>
43
 * require_once 'Calendar'.DIRECTORY_SEPARATOR.'Year.php';
44
 * $Year = & new Calendar_Year(2003, 10, 21); // 21st Oct 2003
45
 * $Year->build(); // Build Calendar_Month objects
46
 * while ($Month = & $Year->fetch()) {
47
 *     echo $Month->thisMonth().'<br />';
48
 * }
49
 * </code>
50
 * @package Calendar
51
 * @access public
52
 */
53
class Calendar_Year extends Calendar
54
{
55
    /**
56
     * Constructs Calendar_Year
57
     * @param int year e.g. 2003
58
     * @access public
59
     */
60
    function Calendar_Year($y)
61
    {
62
        Calendar::Calendar($y);
63
    }
64
 
65
    /**
66
     * Builds the Months of the Year.<br>
67
     * <b>Note:</b> by defining the constant CALENDAR_MONTH_STATE you can
68
     * control what class of Calendar_Month is built e.g.;
69
     * <code>
70
     * require_once 'Calendar/Calendar_Year.php';
71
     * define ('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH_WEEKDAYS); // Use Calendar_Month_Weekdays
72
     * // define ('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH_WEEKS); // Use Calendar_Month_Weeks
73
     * // define ('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH); // Use Calendar_Month
74
     * </code>
75
     * It defaults to building Calendar_Month objects.
76
     * @param array (optional) array of Calendar_Month objects representing selected dates
77
     * @param int (optional) first day of week (e.g. 0 for Sunday, 2 for Tuesday etc.)
78
     * @return boolean
79
     * @access public
80
     */
81
    function build($sDates = array(), $firstDay = null)
82
    {
83
        require_once CALENDAR_ROOT.'Factory.php';
84
        if (is_null($firstDay)) {
85
            $firstDay = $this->cE->getFirstDayOfWeek(
86
                $this->thisYear(),
87
                $this->thisMonth(),
88
                $this->thisDay()
89
            );
90
        }
91
        $monthsInYear = $this->cE->getMonthsInYear($this->thisYear());
92
        for ($i=1; $i <= $monthsInYear; $i++) {
93
            $this->children[$i] = Calendar_Factory::create('Month',$this->year,$i);
94
        }
95
        if (count($sDates) > 0) {
96
            $this->setSelection($sDates);
97
        }
98
        return true;
99
    }
100
 
101
    /**
102
     * Called from build()
103
     * @param array
104
     * @return void
105
     * @access private
106
     */
107
    function setSelection($sDates) {
108
        foreach ($sDates as $sDate) {
109
            if ($this->year == $sDate->thisYear()) {
110
                $key = $sDate->thisMonth();
111
                if (isset($this->children[$key])) {
112
                    $sDate->setSelected();
113
                    $this->children[$key] = $sDate;
114
                }
115
            }
116
        }
117
    }
118
}
119
?>