| 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\Traits; |
| 32 |
|
| 33 |
use Kigkonsult\Icalcreator\Util\StringFactory; |
| 34 |
use Kigkonsult\Icalcreator\Util\Util; |
| 35 |
use Kigkonsult\Icalcreator\Util\ParameterFactory; |
| 36 |
use InvalidArgumentException; |
| 37 |
|
| 38 |
/** |
| 39 |
* CONTACT property functions |
| 40 |
* |
| 41 |
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se> |
| 42 |
* @throws InvalidArgumentException |
| 43 |
* @since 2.29.14 2019-09-03 |
| 44 |
*/ |
| 45 |
trait CONTACTtrait |
| 46 |
{ |
| 47 |
/** |
| 48 |
* @var array component property CONTACT value |
| 49 |
*/ |
| 50 |
protected $contact = null; |
| 51 |
|
| 52 |
/** |
| 53 |
* Return formatted output for calendar component property contact |
| 54 |
* |
| 55 |
* @return string |
| 56 |
*/ |
| 57 |
public function createContact() |
| 58 |
{ |
| 59 |
if( empty( $this->contact )) { |
| 60 |
return null; |
| 61 |
} |
| 62 |
$output = null; |
| 63 |
$lang = $this->getConfig( self::LANGUAGE ); |
| 64 |
foreach( $this->contact as $cx => $contact ) { |
| 65 |
if( ! empty( $contact[Util::$LCvalue] )) { |
| 66 |
$output .= StringFactory::createElement( |
| 67 |
self::CONTACT, |
| 68 |
ParameterFactory::createParams( |
| 69 |
$contact[Util::$LCparams], |
| 70 |
self::$ALTRPLANGARR, |
| 71 |
$lang |
| 72 |
), |
| 73 |
StringFactory::strrep( $contact[Util::$LCvalue] ) |
| 74 |
); |
| 75 |
} |
| 76 |
elseif( $this->getConfig( self::ALLOWEMPTY )) { |
| 77 |
$output .= StringFactory::createElement( self::CONTACT ); |
| 78 |
} |
| 79 |
} // end foreach |
| 80 |
return $output; |
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* Delete calendar component property contact |
| 85 |
* |
| 86 |
* @param int $propDelIx specific property in case of multiply occurrence |
| 87 |
* @return bool |
| 88 |
* @since 2.27.1 - 2018-12-15 |
| 89 |
*/ |
| 90 |
public function deleteContact( $propDelIx = null ) |
| 91 |
{ |
| 92 |
if( empty( $this->contact )) { |
| 93 |
unset( $this->propDelIx[self::CONTACT] ); |
| 94 |
return false; |
| 95 |
} |
| 96 |
return $this->deletePropertyM( $this->contact, self::CONTACT, $propDelIx ); |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* Get calendar component property contact |
| 101 |
* |
| 102 |
* @param int $propIx specific property in case of multiply occurrence |
| 103 |
* @param bool $inclParam |
| 104 |
* @return bool|array |
| 105 |
* @since 2.27.1 - 2018-12-12 |
| 106 |
*/ |
| 107 |
public function getContact( $propIx = null, $inclParam = false ) |
| 108 |
{ |
| 109 |
if( empty( $this->contact )) { |
| 110 |
unset( $this->propIx[self::CONTACT] ); |
| 111 |
return false; |
| 112 |
} |
| 113 |
return $this->getPropertyM( |
| 114 |
$this->contact, |
| 115 |
self::CONTACT, |
| 116 |
$propIx, |
| 117 |
$inclParam |
| 118 |
); |
| 119 |
} |
| 120 |
|
| 121 |
/** |
| 122 |
* Set calendar component property contact |
| 123 |
* |
| 124 |
* @param string $value |
| 125 |
* @param array $params |
| 126 |
* @param integer $index |
| 127 |
* @return static |
| 128 |
* @throws InvalidArgumentException |
| 129 |
* @since 2.29.14 2019-09-03 |
| 130 |
*/ |
| 131 |
public function setContact( $value = null, $params = [], $index = null ) |
| 132 |
{ |
| 133 |
if( empty( $value )) { |
| 134 |
$this->assertEmptyValue( $value, self::CONTACT ); |
| 135 |
$value = Util::$SP0; |
| 136 |
$params = []; |
| 137 |
} |
| 138 |
Util::assertString( $value, self::CONTACT ); |
| 139 |
$this->setMval( |
| 140 |
$this->contact, |
| 141 |
StringFactory::trimTrailNL( $value ), |
| 142 |
$params, |
| 143 |
null, |
| 144 |
$index |
| 145 |
); |
| 146 |
return $this; |
| 147 |
} |
| 148 |
} |
| 149 |
|