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: Hour.php,v 1.1 2005-09-30 14:58:00 ddelon Exp $
|
|
|
21 |
//
|
|
|
22 |
/**
|
|
|
23 |
* @package Calendar
|
|
|
24 |
* @version $Id: Hour.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 an Hour and builds Minutes
|
|
|
42 |
* <code>
|
|
|
43 |
* require_once 'Calendar'.DIRECTORY_SEPARATOR.'Hour.php';
|
|
|
44 |
* $Hour = & new Calendar_Hour(2003, 10, 21, 15); // Oct 21st 2003, 3pm
|
|
|
45 |
* $Hour->build(); // Build Calendar_Minute objects
|
|
|
46 |
* while ($Minute = & $Hour->fetch()) {
|
|
|
47 |
* echo $Minute->thisMinute().'<br />';
|
|
|
48 |
* }
|
|
|
49 |
* </code>
|
|
|
50 |
* @package Calendar
|
|
|
51 |
* @access public
|
|
|
52 |
*/
|
|
|
53 |
class Calendar_Hour extends Calendar
|
|
|
54 |
{
|
|
|
55 |
/**
|
|
|
56 |
* Constructs Calendar_Hour
|
|
|
57 |
* @param int year e.g. 2003
|
|
|
58 |
* @param int month e.g. 5
|
|
|
59 |
* @param int day e.g. 11
|
|
|
60 |
* @param int hour e.g. 13
|
|
|
61 |
* @access public
|
|
|
62 |
*/
|
|
|
63 |
function Calendar_Hour($y, $m, $d, $h)
|
|
|
64 |
{
|
|
|
65 |
Calendar::Calendar($y, $m, $d, $h);
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
/**
|
|
|
69 |
* Builds the Minutes in the Hour
|
|
|
70 |
* @param array (optional) Calendar_Minute objects representing selected dates
|
|
|
71 |
* @return boolean
|
|
|
72 |
* @access public
|
|
|
73 |
*/
|
|
|
74 |
function build($sDates=array())
|
|
|
75 |
{
|
|
|
76 |
require_once CALENDAR_ROOT.'Minute.php';
|
|
|
77 |
$mIH = $this->cE->getMinutesInHour($this->year, $this->month, $this->day,
|
|
|
78 |
$this->hour);
|
|
|
79 |
for ($i=0; $i < $mIH; $i++) {
|
|
|
80 |
$this->children[$i]=
|
|
|
81 |
new Calendar_Minute($this->year, $this->month, $this->day,
|
|
|
82 |
$this->hour, $i);
|
|
|
83 |
}
|
|
|
84 |
if (count($sDates) > 0) {
|
|
|
85 |
$this->setSelection($sDates);
|
|
|
86 |
}
|
|
|
87 |
return true;
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
/**
|
|
|
91 |
* Called from build()
|
|
|
92 |
* @param array
|
|
|
93 |
* @return void
|
|
|
94 |
* @access private
|
|
|
95 |
*/
|
|
|
96 |
function setSelection($sDates)
|
|
|
97 |
{
|
|
|
98 |
foreach ($sDates as $sDate) {
|
|
|
99 |
if ($this->year == $sDate->thisYear()
|
|
|
100 |
&& $this->month == $sDate->thisMonth()
|
|
|
101 |
&& $this->day == $sDate->thisDay()
|
|
|
102 |
&& $this->hour == $sDate->thisHour())
|
|
|
103 |
{
|
|
|
104 |
$key = (int)$sDate->thisMinute();
|
|
|
105 |
if (isset($this->children[$key])) {
|
|
|
106 |
$sDate->setSelected();
|
|
|
107 |
$this->children[$key] = $sDate;
|
|
|
108 |
}
|
|
|
109 |
}
|
|
|
110 |
}
|
|
|
111 |
}
|
|
|
112 |
}
|
|
|
113 |
?>
|