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

Day::setSelection()   A

Complexity

Conditions 6
Paths 4

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

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