Subversion Repositories Applications.gtt

Rev

Rev 61 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
10 jpm 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.4 2005/10/22 10:25:39 quipo Exp $
21
//
22
/**
23
 * @package Calendar
24
 * @version $Id: Year.php,v 1.4 2005/10/22 10:25:39 quipo 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
        $this->firstDay = $this->defineFirstDayOfWeek($firstDay);
85
        $monthsInYear = $this->cE->getMonthsInYear($this->thisYear());
86
        for ($i=1; $i <= $monthsInYear; $i++) {
87
            $this->children[$i] = Calendar_Factory::create('Month', $this->year, $i);
88
        }
89
        if (count($sDates) > 0) {
90
            $this->setSelection($sDates);
91
        }
92
        return true;
93
    }
94
 
95
    /**
96
     * Called from build()
97
     * @param array
98
     * @return void
99
     * @access private
100
     */
101
    function setSelection($sDates) {
102
        foreach ($sDates as $sDate) {
103
            if ($this->year == $sDate->thisYear()) {
104
                $key = $sDate->thisMonth();
105
                if (isset($this->children[$key])) {
106
                    $sDate->setSelected();
107
                    $this->children[$key] = $sDate;
108
                }
109
            }
110
        }
111
    }
112
}
113
?>