Passed
Pull Request — master (#2)
by tsms
02:27 queued 57s
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
 * Represents a Day and builds Hours.
50
 * <code>
51
 * $Day = new \PEAR\Calendar\Day(2003, 10, 21); // Oct 21st 2003
52
 * while ($Hour = & $Day->fetch()) {
53
 *    echo $Hour->thisHour().'<br />';
54
 * }
55
 * </code>
56
 *
57
 * @category  Date and Time
58
 * @package   Calendar
59
 * @author    Harry Fuecks <[email protected]>
60
 * @copyright 2003-2007 Harry Fuecks
61
 * @license   http://www.debian.org/misc/bsd.license  BSD License (3 Clause)
62
 * @link      http://pear.php.net/package/Calendar
63
 * @access    public
64
 */
65
class Day extends Calendar
66
{
67
    /**
68
     * Marks the Day at the beginning of a week
69
     * @access private
70
     * @var boolean
71
     */
72
    var $first = false;
73
74
    /**
75
     * Marks the Day at the end of a week
76
     * @access private
77
     * @var boolean
78
     */
79
    var $last = false;
80
81
82
    /**
83
     * Used for tabular calendars
84
     * @access private
85
     * @var boolean
86
     */
87
    var $empty = false;
88
89
    /**
90
     * Constructs Calendar_Day
91
     *
92
     * @param int $y year e.g. 2003
93
     * @param int $m month e.g. 8
94
     * @param int $d day e.g. 15
95
     *
96
     * @access public
97
     */
98
    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...
99
    {
100
        parent::__construct($y, $m, $d);
101
    }
102
103
    /**
104
     * Builds the Hours of the Day
105
     *
106
     * @param array $sDates (optional) Caledar_Hour objects representing selected dates
107
     *
108
     * @return boolean
109
     * @access public
110
     */
111
    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...
112
    {
113
        include_once CALENDAR_ROOT.'Hour.php';
114
115
        $hID = $this->cE->getHoursInDay($this->year, $this->month, $this->day);
116
        for ($i=0; $i < $hID; $i++) {
117
            $this->children[$i] =
118
                new Hour($this->year, $this->month, $this->day, $i);
119
        }
120
        if (count($sDates) > 0) {
121
            $this->setSelection($sDates);
122
        }
123
        return true;
124
    }
125
126
    /**
127
     * Called from build()
128
     *
129
     * @param array $sDates dates to be selected
130
     *
131
     * @return void
132
     * @access private
133
     */
134
    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...
135
    {
136
        foreach ($sDates as $sDate) {
137
            if ($this->year == $sDate->thisYear()
138
                && $this->month == $sDate->thisMonth()
139
                && $this->day == $sDate->thisDay())
140
            {
141
                $key = (int)$sDate->thisHour();
142
                if (isset($this->children[$key])) {
143
                    $sDate->setSelected();
144
                    $this->children[$key] = $sDate;
145
                }
146
            }
147
        }
148
    }
149
150
    /**
151
     * Defines Day object as first in a week
152
     * Only used by Calendar_Month_Weekdays::build()
153
     *
154
     * @param boolean $state set this day as first in week
155
     *
156
     * @return void
157
     * @access private
158
     */
159
    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...
160
    {
161
        $this->first = $state;
162
    }
163
164
    /**
165
     * Defines Day object as last in a week
166
     * Used only following Calendar_Month_Weekdays::build()
167
     *
168
     * @param boolean $state set this day as last in week
169
     *
170
     * @return void
171
     * @access private
172
     */
173
    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...
174
    {
175
        $this->last = $state;
176
    }
177
178
    /**
179
     * Returns true if Day object is first in a Week
180
     * Only relevant when Day is created by Calendar_Month_Weekdays::build()
181
     *
182
     * @return boolean
183
     * @access public
184
     */
185
    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...
186
    {
187
        return $this->first;
188
    }
189
190
    /**
191
     * Returns true if Day object is last in a Week
192
     * Only relevant when Day is created by Calendar_Month_Weekdays::build()
193
     *
194
     * @return boolean
195
     * @access public
196
     */
197
    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...
198
    {
199
        return $this->last;
200
    }
201
202
    /**
203
     * Defines Day object as empty
204
     * Only used by Calendar_Month_Weekdays::build()
205
     *
206
     * @param boolean $state set this day as empty
207
     *
208
     * @return void
209
     * @access private
210
     */
211
    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...
212
    {
213
        $this->empty = $state;
214
    }
215
216
    /**
217
     * Check if this day is empty
218
     *
219
     * @return boolean
220
     * @access public
221
     */
222
    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...
223
    {
224
        return $this->empty;
225
    }
226
}
227