Passed
Pull Request — master (#2)
by tsms
01:30
created

Day::isFirst()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/* vim: set expandtab tabstop=4 shiftwidth=4: */
3
4
/**
5
 * Contains the Calendar_Day class
6
 *
7
 * PHP versions 4 and 5
8
 *
9
 * LICENSE: Redistribution and use in source and binary forms, with or without
10
 * modification, are permitted provided that the following conditions are met:
11
 * 1. Redistributions of source code must retain the above copyright
12
 *    notice, this list of conditions and the following disclaimer.
13
 * 2. Redistributions in binary form must reproduce the above copyright
14
 *    notice, this list of conditions and the following disclaimer in the
15
 *    documentation and/or other materials provided with the distribution.
16
 * 3. The name of the author may not be used to endorse or promote products
17
 *    derived from this software without specific prior written permission.
18
 *
19
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
20
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22
 * IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
23
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
 *
30
 * @category  Date and Time
31
 * @package   Calendar
32
 * @author    Harry Fuecks <[email protected]>
33
 * @copyright 2003-2007 Harry Fuecks
34
 * @license   http://www.debian.org/misc/bsd.license  BSD License (3 Clause)
35
 * @version   CVS: $Id$
36
 * @link      http://pear.php.net/package/Calendar
37
 */
38
namespace Pear\Calendar;
39
40
/**
41
 * Allows Calendar include path to be redefined
42
 * @ignore
43
 */
44
if (!defined('CALENDAR_ROOT')) {
45
    define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
46
}
47
48
/**
49
 * Load Calendar base class
50
 */
51
require_once CALENDAR_ROOT.'Calendar.php';
52
53
/**
54
 * Represents a Day and builds Hours.
55
 * <code>
56
 * require_once 'Calendar/Day.php';
57
 * $Day = new Calendar_Day(2003, 10, 21); // Oct 21st 2003
58
 * while ($Hour = & $Day->fetch()) {
59
 *    echo $Hour->thisHour().'<br />';
60
 * }
61
 * </code>
62
 *
63
 * @category  Date and Time
64
 * @package   Calendar
65
 * @author    Harry Fuecks <[email protected]>
66
 * @copyright 2003-2007 Harry Fuecks
67
 * @license   http://www.debian.org/misc/bsd.license  BSD License (3 Clause)
68
 * @link      http://pear.php.net/package/Calendar
69
 * @access    public
70
 */
71
class Day extends Calendar
72
{
73
    /**
74
     * Marks the Day at the beginning of a week
75
     * @access private
76
     * @var boolean
77
     */
78
    var $first = false;
79
80
    /**
81
     * Marks the Day at the end of a week
82
     * @access private
83
     * @var boolean
84
     */
85
    var $last = false;
86
87
88
    /**
89
     * Used for tabular calendars
90
     * @access private
91
     * @var boolean
92
     */
93
    var $empty = false;
94
95
    /**
96
     * Constructs Calendar_Day
97
     *
98
     * @param int $y year e.g. 2003
99
     * @param int $m month e.g. 8
100
     * @param int $d day e.g. 15
101
     *
102
     * @access public
103
     */
104
    function __construct($y, $m, $d)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
105
    {
106
        parent::__construct($y, $m, $d);
107
    }
108
109
    /**
110
     * Builds the Hours of the Day
111
     *
112
     * @param array $sDates (optional) Caledar_Hour objects representing selected dates
113
     *
114
     * @return boolean
115
     * @access public
116
     */
117
    function build($sDates = array())
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
118
    {
119
        include_once CALENDAR_ROOT.'Hour.php';
120
121
        $hID = $this->cE->getHoursInDay($this->year, $this->month, $this->day);
122
        for ($i=0; $i < $hID; $i++) {
123
            $this->children[$i] =
124
                new Hour($this->year, $this->month, $this->day, $i);
125
        }
126
        if (count($sDates) > 0) {
127
            $this->setSelection($sDates);
128
        }
129
        return true;
130
    }
131
132
    /**
133
     * Called from build()
134
     *
135
     * @param array $sDates dates to be selected
136
     *
137
     * @return void
138
     * @access private
139
     */
140
    function setSelection($sDates)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
141
    {
142
        foreach ($sDates as $sDate) {
143
            if ($this->year == $sDate->thisYear()
144
                && $this->month == $sDate->thisMonth()
145
                && $this->day == $sDate->thisDay())
146
            {
147
                $key = (int)$sDate->thisHour();
148
                if (isset($this->children[$key])) {
149
                    $sDate->setSelected();
150
                    $this->children[$key] = $sDate;
151
                }
152
            }
153
        }
154
    }
155
156
    /**
157
     * Defines Day object as first in a week
158
     * Only used by Calendar_Month_Weekdays::build()
159
     *
160
     * @param boolean $state set this day as first in week
161
     *
162
     * @return void
163
     * @access private
164
     */
165
    function setFirst($state = true)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
166
    {
167
        $this->first = $state;
168
    }
169
170
    /**
171
     * Defines Day object as last in a week
172
     * Used only following Calendar_Month_Weekdays::build()
173
     *
174
     * @param boolean $state set this day as last in week
175
     *
176
     * @return void
177
     * @access private
178
     */
179
    function setLast($state = true)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
180
    {
181
        $this->last = $state;
182
    }
183
184
    /**
185
     * Returns true if Day object is first in a Week
186
     * Only relevant when Day is created by Calendar_Month_Weekdays::build()
187
     *
188
     * @return boolean
189
     * @access public
190
     */
191
    function isFirst() 
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
192
    {
193
        return $this->first;
194
    }
195
196
    /**
197
     * Returns true if Day object is last in a Week
198
     * Only relevant when Day is created by Calendar_Month_Weekdays::build()
199
     *
200
     * @return boolean
201
     * @access public
202
     */
203
    function isLast()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
204
    {
205
        return $this->last;
206
    }
207
208
    /**
209
     * Defines Day object as empty
210
     * Only used by Calendar_Month_Weekdays::build()
211
     *
212
     * @param boolean $state set this day as empty
213
     *
214
     * @return void
215
     * @access private
216
     */
217
    function setEmpty ($state = true)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
218
    {
219
        $this->empty = $state;
220
    }
221
222
    /**
223
     * Check if this day is empty
224
     *
225
     * @return boolean
226
     * @access public
227
     */
228
    function isEmpty()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
229
    {
230
        return $this->empty;
231
    }
232
}
233