Completed
Pull Request — master (#74)
by Stefan
02:52
created

Calendar::setCalendarColor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
ccs 0
cts 3
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php
2
3
/*
4
 * This file is part of the eluceo/iCal package.
5
 *
6
 * (c) Markus Poerschke <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Eluceo\iCal\Component;
13
14
use Eluceo\iCal\Component;
15
use Eluceo\iCal\PropertyBag;
16
17
class Calendar extends Component
18
{
19
    /**
20
     * Methods for calendar components.
21
     *
22
     * According to RFP 5545: 3.7.2. Method
23
     *
24
     * @link http://tools.ietf.org/html/rfc5545#section-3.7.2
25
     *
26
     * And then according to RFC 2446: 3 APPLICATION PROTOCOL ELEMENTS
27
     * @link https://www.ietf.org/rfc/rfc2446.txt
28
     */
29
    const METHOD_PUBLISH        = 'PUBLISH';
30
    const METHOD_REQUEST        = 'REQUEST';
31
    const METHOD_REPLY          = 'REPLY';
32
    const METHOD_ADD            = 'ADD';
33
    const METHOD_CANCEL         = 'CANCEL';
34
    const METHOD_REFRESH        = 'REFRESH';
35
    const METHOD_COUNTER        = 'COUNTER';
36
    const METHOD_DECLINECOUNTER = 'DECLINECOUNTER';
37
38
    /**
39
     * This property defines the calendar scale used for the calendar information specified in the iCalendar object.
40
     *
41
     * According to RFC 5545: 3.7.1. Calendar Scale
42
     *
43
     * @link http://tools.ietf.org/html/rfc5545#section-3.7
44
     */
45
    const CALSCALE_GREGORIAN = 'GREGORIAN';
46
47
    /**
48
     * The Product Identifier.
49
     *
50
     * According to RFC 2445: 4.7.3 Product Identifier
51
     *
52
     * This property specifies the identifier for the product that created the Calendar object.
53
     *
54
     * @link http://www.ietf.org/rfc/rfc2445.txt
55
     *
56
     * @var string
57
     */
58
    protected $prodId      = null;
59
    protected $method      = null;
60
    protected $name        = null;
61
    protected $description = null;
62
    protected $timezone    = null;
63
64
    /**
65
     * This property defines the calendar scale used for the
66
     * calendar information specified in the iCalendar object.
67
     *
68
     * Also identifies the calendar type of a non-Gregorian recurring appointment.
69
     *
70
     * @var string
71
     *
72
     * @see http://tools.ietf.org/html/rfc5545#section-3.7
73
     * @see http://msdn.microsoft.com/en-us/library/ee237520(v=exchg.80).aspx
74
     */
75
    protected $calendarScale = null;
76
77
    /**
78
     * Specifies whether or not the iCalendar file only contains one appointment.
79
     *
80
     * @var bool
81
     *
82
     * @see http://msdn.microsoft.com/en-us/library/ee203486(v=exchg.80).aspx
83
     */
84
    protected $forceInspectOrOpen = false;
85
86
    /**
87
     * Specifies a globally unique identifier for the calendar.
88
     *
89
     * @var string
90
     *
91
     * @see http://msdn.microsoft.com/en-us/library/ee179588(v=exchg.80).aspx
92
     */
93
    protected $calId = null;
94
95
    /**
96
     * Specifies a suggested iCalendar file download frequency for clients and
97
     * servers with sync capabilities.
98
     *
99
     * @var string
100
     *
101
     * @see http://msdn.microsoft.com/en-us/library/ee178699(v=exchg.80).aspx
102
     */
103
    protected $publishedTTL = 'P1W';
104
105
    /**
106
     * Specifies a color for the calendar in calendar for Apple/Outlook.
107
     *
108
     * @var string
109
     *
110
     * @see http://msdn.microsoft.com/en-us/library/ee179588(v=exchg.80).aspx
111
     */
112
    protected $calendarColor = null;
113
114 4
    public function __construct($prodId)
115
    {
116 4
        if (empty($prodId)) {
117
            throw new \UnexpectedValueException('PRODID cannot be empty');
118
        }
119
120 4
        $this->prodId = $prodId;
121 4
    }
122
123
    /**
124
     * {@inheritdoc}
125
     */
126 4
    public function getType()
127
    {
128 4
        return 'VCALENDAR';
129
    }
130
131
    /**
132
     * @param $method
133
     *
134
     * @return $this
135
     */
136
    public function setMethod($method)
137
    {
138
        $this->method = $method;
139
140
        return $this;
141
    }
142
143
    /**
144
     * @param $name
145
     *
146
     * @return $this
147
     */
148
    public function setName($name)
149
    {
150
        $this->name = $name;
151
152
        return $this;
153
    }
154
155
    /**
156
     * @param $description
157
     *
158
     * @return $this
159
     */
160
    public function setDescription($description)
161
    {
162
        $this->description = $description;
163
164
        return $this;
165
    }
166
167
    /**
168
     * @param $timezone
169
     *
170
     * @return $this
171
     */
172
    public function setTimezone($timezone)
173
    {
174
        $this->timezone = $timezone;
175
176
        return $this;
177
    }
178
179
    /**
180
     * @param $calendarColor
181
     *
182
     * @return $this
183
     */
184
    public function setCalendarColor($calendarColor)
185
    {
186
        $this->calendarColor = $calendarColor;
187
188
        return $this;
189
    }
190
191
    /**
192
     * @param $calendarScale
193
     *
194
     * @return $this
195
     */
196
    public function setCalendarScale($calendarScale)
197
    {
198
        $this->calendarScale = $calendarScale;
199
200
        return $this;
201
    }
202
203
    /**
204
     * @param bool $forceInspectOrOpen
205
     *
206
     * @return $this
207
     */
208
    public function setForceInspectOrOpen($forceInspectOrOpen)
209
    {
210
        $this->forceInspectOrOpen = $forceInspectOrOpen;
211
212
        return $this;
213
    }
214
215
    /**
216
     * @param string $calId
217
     *
218
     * @return $this
219
     */
220
    public function setCalId($calId)
221
    {
222
        $this->calId = $calId;
223
224
        return $this;
225
    }
226
227
    /**
228
     * @param string $ttl
229
     *
230
     * @return $this
231
     */
232
    public function setPublishedTTL($ttl)
233
    {
234
        $this->publishedTTL = $ttl;
235
236
        return $this;
237
    }
238
239
    /**
240
     * {@inheritdoc}
241
     */
242 4
    public function buildPropertyBag()
243
    {
244 4
        $propertyBag = new PropertyBag();
245 4
        $propertyBag->set('VERSION', '2.0');
246 4
        $propertyBag->set('PRODID', $this->prodId);
247
248 4
        if ($this->method) {
249
            $propertyBag->set('METHOD', $this->method);
250
        }
251
252 4
        if ($this->calendarColor) {
253
            $propertyBag->set('X-APPLE-CALENDAR-COLOR', $this->calendarColor);
254
            $propertyBag->set('X-OUTLOOK-COLOR', $this->calendarColor);
255
            $propertyBag->set('X-FUNAMBOL-COLOR', $this->calendarColor);
256
        }
257
258 4
        if ($this->calendarScale) {
259
            $propertyBag->set('CALSCALE', $this->calendarScale);
260
            $propertyBag->set('X-MICROSOFT-CALSCALE', $this->calendarScale);
261
        }
262
263 4
        if ($this->name) {
264
            $propertyBag->set('X-WR-CALNAME', $this->name);
265
        }
266
267 4
        if ($this->description) {
268
            $propertyBag->set('X-WR-CALDESC', $this->description);
269
        }
270
271 4
        if ($this->timezone) {
272
            if ($this->timezone instanceof Timezone) {
273
                $propertyBag->set('X-WR-TIMEZONE', $this->timezone->getZoneIdentifier());
274
                $this->addComponent($this->timezone);
275
            } else {
276
                $propertyBag->set('X-WR-TIMEZONE', $this->timezone);
277
                $this->addComponent(new Timezone($this->timezone));
278
            }
279
        }
280
281 4
        if ($this->forceInspectOrOpen) {
282
            $propertyBag->set('X-MS-OLK-FORCEINSPECTOROPEN', $this->forceInspectOrOpen);
283
        }
284
285 4
        if ($this->calId) {
286
            $propertyBag->set('X-WR-RELCALID', $this->calId);
287
        }
288
289 4
        if ($this->publishedTTL) {
290 4
            $propertyBag->set('X-PUBLISHED-TTL', $this->publishedTTL);
291 4
        }
292
293 4
        return $propertyBag;
294
    }
295
296
    /**
297
     * Adds an Event to the Calendar.
298
     *
299
     * Wrapper for addComponent()
300
     *
301
     * @see        Eluceo\iCal::addComponent
302
     * @deprecated Please, use public method addComponent() from abstract Component class
303
     *
304
     * @param Event $event
305
     */
306
    public function addEvent(Event $event)
307
    {
308
        $this->addComponent($event);
309
    }
310
311
    /**
312
     * @return null|string
313
     */
314
    public function getProdId()
315
    {
316
        return $this->prodId;
317
    }
318
319
    public function getMethod()
320
    {
321
        return $this->method;
322
    }
323
}
324