| 1 |
<?php |
| 2 |
/** |
| 3 |
* iCalcreator, the PHP class package managing iCal (rfc2445/rfc5445) calendar information. |
| 4 |
* |
| 5 |
* copyright (c) 2007-2021 Kjell-Inge Gustafsson, kigkonsult, All rights reserved |
| 6 |
* Link https://kigkonsult.se |
| 7 |
* Package iCalcreator |
| 8 |
* Version 2.30 |
| 9 |
* License Subject matter of licence is the software iCalcreator. |
| 10 |
* The above copyright, link, package and version notices, |
| 11 |
* this licence notice and the invariant [rfc5545] PRODID result use |
| 12 |
* as implemented and invoked in iCalcreator shall be included in |
| 13 |
* all copies or substantial portions of the iCalcreator. |
| 14 |
* |
| 15 |
* iCalcreator is free software: you can redistribute it and/or modify |
| 16 |
* it under the terms of the GNU Lesser General Public License as published |
| 17 |
* by the Free Software Foundation, either version 3 of the License, |
| 18 |
* or (at your option) any later version. |
| 19 |
* |
| 20 |
* iCalcreator is distributed in the hope that it will be useful, |
| 21 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 |
* GNU Lesser General Public License for more details. |
| 24 |
* |
| 25 |
* You should have received a copy of the GNU Lesser General Public License |
| 26 |
* along with iCalcreator. If not, see <https://www.gnu.org/licenses/>. |
| 27 |
* |
| 28 |
* This file is a part of iCalcreator. |
| 29 |
*/ |
| 30 |
|
| 31 |
namespace Kigkonsult\Icalcreator; |
| 32 |
|
| 33 |
use Exception; |
| 34 |
|
| 35 |
use function array_keys; |
| 36 |
use function sprintf; |
| 37 |
use function strtoupper; |
| 38 |
|
| 39 |
/** |
| 40 |
* iCalcreator VTIMEZONE component class |
| 41 |
* |
| 42 |
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se> |
| 43 |
* @since 2.29.9 2019-08-05 |
| 44 |
*/ |
| 45 |
final class Vtimezone extends CalendarComponent |
| 46 |
{ |
| 47 |
use Traits\COMMENTtrait, |
| 48 |
Traits\DTSTARTtrait, |
| 49 |
Traits\LAST_MODIFIEDtrait, |
| 50 |
Traits\RDATEtrait, |
| 51 |
Traits\RRULEtrait, |
| 52 |
Traits\TZIDtrait, |
| 53 |
Traits\TZNAMEtrait, |
| 54 |
Traits\TZOFFSETFROMtrait, |
| 55 |
Traits\TZOFFSETTOtrait, |
| 56 |
Traits\TZURLtrait; |
| 57 |
|
| 58 |
/** |
| 59 |
* @var string |
| 60 |
*/ |
| 61 |
protected static $compSgn = 'tz'; |
| 62 |
|
| 63 |
/** |
| 64 |
* Destructor |
| 65 |
* |
| 66 |
* @since 2.26 - 2018-11-10 |
| 67 |
*/ |
| 68 |
public function __destruct() |
| 69 |
{ |
| 70 |
if( ! empty( $this->components )) { |
| 71 |
foreach( $this->components as $cix => $component ) { |
| 72 |
$this->components[$cix]->__destruct(); |
| 73 |
} |
| 74 |
} |
| 75 |
unset( |
| 76 |
$this->compType, |
| 77 |
$this->xprop, |
| 78 |
$this->components, |
| 79 |
$this->unparsed, |
| 80 |
$this->config, |
| 81 |
$this->propIx, |
| 82 |
$this->compix, |
| 83 |
$this->propDelIx |
| 84 |
); |
| 85 |
unset( |
| 86 |
$this->cno, |
| 87 |
$this->srtk |
| 88 |
); |
| 89 |
unset( |
| 90 |
$this->comment, |
| 91 |
$this->dtstart, |
| 92 |
$this->lastmodified, |
| 93 |
$this->rdate, |
| 94 |
$this->rrule, |
| 95 |
$this->tzid, |
| 96 |
$this->tzname, |
| 97 |
$this->tzoffsetfrom, |
| 98 |
$this->tzoffsetto, |
| 99 |
$this->tzurl, |
| 100 |
$this->timezonetype |
| 101 |
); |
| 102 |
} |
| 103 |
|
| 104 |
/** |
| 105 |
* Return formatted output for calendar component VTIMEZONE object instance |
| 106 |
* |
| 107 |
* @return string |
| 108 |
* @throws Exception (on Rdate err) |
| 109 |
* @since 2.29.9 2019-08-05 |
| 110 |
*/ |
| 111 |
public function createComponent() |
| 112 |
{ |
| 113 |
$compType = strtoupper( $this->getCompType()); |
| 114 |
$component = sprintf( self::$FMTBEGIN, $compType ); |
| 115 |
$component .= $this->createTzid(); |
| 116 |
$component .= $this->createLastmodified(); |
| 117 |
$component .= $this->createTzurl(); |
| 118 |
$component .= $this->createDtstart(); |
| 119 |
$component .= $this->createTzoffsetfrom(); |
| 120 |
$component .= $this->createTzoffsetto(); |
| 121 |
$component .= $this->createComment(); |
| 122 |
$component .= $this->createRdate(); |
| 123 |
$component .= $this->createRrule(); |
| 124 |
$component .= $this->createTzname(); |
| 125 |
$component .= $this->createXprop(); |
| 126 |
$component .= $this->createSubComponent(); |
| 127 |
return $component . sprintf( self::$FMTEND, $compType ); |
| 128 |
} |
| 129 |
|
| 130 |
/** |
| 131 |
* Return formatted output for subcomponents |
| 132 |
* |
| 133 |
* @return string |
| 134 |
* @since 2.27.2 - 2018-12-21 |
| 135 |
* @throws Exception (on Valarm/Standard/Daylight) err) |
| 136 |
*/ |
| 137 |
public function createSubComponent() |
| 138 |
{ |
| 139 |
if( self::VTIMEZONE == $this->getCompType()) { |
| 140 |
$this->sortVtimezonesSubComponents(); |
| 141 |
} |
| 142 |
return parent::createSubComponent(); |
| 143 |
} |
| 144 |
|
| 145 |
/** |
| 146 |
* Sort Vtimezones subComponents |
| 147 |
* |
| 148 |
* sort : standard, daylight, in dtstart order |
| 149 |
* @since 2.29.1 - 2019-06-28 |
| 150 |
*/ |
| 151 |
private function sortVtimezonesSubComponents() |
| 152 |
{ |
| 153 |
if( empty( $this->components )) { |
| 154 |
return; |
| 155 |
} |
| 156 |
$stdArr = $dlArr = []; |
| 157 |
foreach( array_keys( $this->components ) as $cix ) { |
| 158 |
if( empty( $this->components[$cix] )) { |
| 159 |
continue; |
| 160 |
} |
| 161 |
$key = $this->components[$cix]->getDtstart(); |
| 162 |
if( empty( $key )) { |
| 163 |
$key = $cix * 10; |
| 164 |
} |
| 165 |
else { |
| 166 |
$key = $key->getTimestamp(); |
| 167 |
} |
| 168 |
if( self::STANDARD == $this->components[$cix]->getCompType()) { |
| 169 |
while( isset( $stdArr[$key] )) { |
| 170 |
$key += 1; |
| 171 |
} |
| 172 |
$stdArr[$key] = $this->components[$cix]; |
| 173 |
} |
| 174 |
elseif( self::DAYLIGHT == $this->components[$cix]->getCompType()) { |
| 175 |
while( isset( $dlArr[$key] )) { |
| 176 |
$key += 1; |
| 177 |
} |
| 178 |
$dlArr[$key] = $this->components[$cix]; |
| 179 |
} |
| 180 |
} // end foreach |
| 181 |
$this->components = []; |
| 182 |
ksort( $stdArr, SORT_NUMERIC ); |
| 183 |
foreach( $stdArr as $std ) { |
| 184 |
$this->components[] = $std; |
| 185 |
} |
| 186 |
unset( $stdArr ); |
| 187 |
ksort( $dlArr, SORT_NUMERIC ); |
| 188 |
foreach( $dlArr as $dl ) { |
| 189 |
$this->components[] = $dl; |
| 190 |
} |
| 191 |
unset( $dlArr ); |
| 192 |
} |
| 193 |
|
| 194 |
/** |
| 195 |
* Return timezone standard object instance |
| 196 |
* |
| 197 |
* @return Standard |
| 198 |
* @since 2.27.2 - 2018-12-21 |
| 199 |
*/ |
| 200 |
public function newStandard() |
| 201 |
{ |
| 202 |
array_unshift( $this->components, new Standard( $this->getConfig())); |
| 203 |
return $this->components[0]; |
| 204 |
} |
| 205 |
|
| 206 |
/** |
| 207 |
* Return timezone daylight object instance |
| 208 |
* |
| 209 |
* @return Daylight |
| 210 |
* @since 2.27.2 - 2018-12-21 |
| 211 |
*/ |
| 212 |
public function newDaylight() |
| 213 |
{ |
| 214 |
$ix = ( empty( $this->components )) |
| 215 |
? 0 |
| 216 |
: key( array_slice( $this->components, -1, 1, true )) + 1; |
| 217 |
$this->components[$ix] = new Daylight( $this->getConfig()); |
| 218 |
return $this->components[$ix]; |
| 219 |
} |
| 220 |
} |
| 221 |
|