PageRenderTime 41ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Traits/REQUEST_STATUStrait.php

http://github.com/iCalcreator/iCalcreator
PHP | 185 lines | 110 code | 7 blank | 68 comment | 11 complexity | 6a46f301206484d82c9add3697962229 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0
  1. <?php
  2. /**
  3. * iCalcreator, the PHP class package managing iCal (rfc2445/rfc5445) calendar information.
  4. *
  5. * This file is a part of iCalcreator.
  6. *
  7. * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
  8. * @copyright 2007-2021 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
  9. * @link https://kigkonsult.se
  10. * @license Subject matter of licence is the software iCalcreator.
  11. * The above copyright, link, package and version notices,
  12. * this licence notice and the invariant [rfc5545] PRODID result use
  13. * as implemented and invoked in iCalcreator shall be included in
  14. * all copies or substantial portions of the iCalcreator.
  15. *
  16. * iCalcreator is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Lesser General Public License as
  18. * published by the Free Software Foundation, either version 3 of
  19. * the License, or (at your option) any later version.
  20. *
  21. * iCalcreator is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Lesser General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Lesser General Public License
  27. * along with iCalcreator. If not, see <https://www.gnu.org/licenses/>.
  28. */
  29. declare( strict_types = 1 );
  30. namespace Kigkonsult\Icalcreator\Traits;
  31. use Kigkonsult\Icalcreator\Util\StringFactory;
  32. use Kigkonsult\Icalcreator\Util\Util;
  33. use Kigkonsult\Icalcreator\Util\ParameterFactory;
  34. use InvalidArgumentException;
  35. use function number_format;
  36. use function filter_var;
  37. use function sprintf;
  38. use function var_export;
  39. /**
  40. * REQUEST-STATUS property functions
  41. *
  42. * @since 2.29.14 2019-09-03
  43. */
  44. trait REQUEST_STATUStrait
  45. {
  46. /**
  47. * @var null|array component property REQUEST-STATUS value
  48. */
  49. protected ?array $requeststatus = null;
  50. /**
  51. * Return formatted output for calendar component property request-status
  52. *
  53. * @return string
  54. * @since 2.29.9 2019-08-05
  55. */
  56. public function createRequeststatus() : string
  57. {
  58. if( empty( $this->requeststatus )) {
  59. return Util::$SP0;
  60. }
  61. $output = Util::$SP0;
  62. $lang = $this->getConfig( self::LANGUAGE );
  63. foreach( $this->requeststatus as $rStat ) {
  64. if( empty( $rStat[Util::$LCvalue][self::STATCODE] )) {
  65. if( $this->getConfig( self::ALLOWEMPTY )) {
  66. $output .= StringFactory::createElement( self::REQUEST_STATUS );
  67. }
  68. continue;
  69. }
  70. $content =
  71. $rStat[Util::$LCvalue][self::STATCODE] .
  72. Util::$SEMIC .
  73. StringFactory::strrep( $rStat[Util::$LCvalue][self::STATDESC] );
  74. if( isset( $rStat[Util::$LCvalue][self::EXTDATA] )) {
  75. $content .= Util::$SEMIC .
  76. StringFactory::strrep( $rStat[Util::$LCvalue][self::EXTDATA] );
  77. }
  78. $output .= StringFactory::createElement(
  79. self::REQUEST_STATUS,
  80. ParameterFactory::createParams(
  81. $rStat[Util::$LCparams],
  82. [ self::LANGUAGE ],
  83. $lang
  84. ),
  85. $content
  86. );
  87. } // end foreach
  88. return $output;
  89. }
  90. /**
  91. * Delete calendar component property request-status
  92. *
  93. * @param null|int $propDelIx specific property in case of multiply occurrence
  94. * @return bool
  95. * @since 2.27.1 - 2018-12-15
  96. */
  97. public function deleteRequeststatus( ? int $propDelIx = null ) : bool
  98. {
  99. if( empty( $this->requeststatus )) {
  100. unset( $this->propDelIx[self::REQUEST_STATUS] );
  101. return false;
  102. }
  103. return self::deletePropertyM(
  104. $this->requeststatus,
  105. self::REQUEST_STATUS,
  106. $this,
  107. $propDelIx
  108. );
  109. }
  110. /**
  111. * Get calendar component property request-status
  112. *
  113. * @param null|int $propIx specific property in case of multiply occurrence
  114. * @param null|bool $inclParam
  115. * @return string|array|bool
  116. * @since 2.29.9 2019-08-05
  117. */
  118. public function getRequeststatus( ?int $propIx = null, ?bool $inclParam = false ) : bool | string | array
  119. {
  120. if( empty( $this->requeststatus )) {
  121. unset( $this->propIx[self::REQUEST_STATUS] );
  122. return false;
  123. }
  124. return self::getPropertyM(
  125. $this->requeststatus,
  126. self::REQUEST_STATUS,
  127. $this,
  128. $propIx,
  129. $inclParam
  130. );
  131. }
  132. /**
  133. * Set calendar component property request-status
  134. *
  135. * @param null|int|float|string $statCode 1*DIGIT 1*2("." 1*DIGIT)
  136. * @param null|string $text
  137. * @param null|string $extData
  138. * @param null|string[] $params
  139. * @param null|integer $index
  140. * @return static
  141. * @throws InvalidArgumentException
  142. * @since 2.29.14 2019-09-03
  143. */
  144. public function setRequeststatus(
  145. null|int|float|string $statCode = null,
  146. ? string $text = null,
  147. ? string $extData = null,
  148. ? array $params = [],
  149. ? int $index = null
  150. ) : static
  151. {
  152. static $ERR = 'Invalid %s status code value %s';
  153. if( empty( $statCode ) || empty( $text )) {
  154. $this->assertEmptyValue( Util::$SP0, self::REQUEST_STATUS );
  155. $statCode = null;
  156. $text = Util::$SP0;
  157. $params = [];
  158. }
  159. else {
  160. if( false === filter_var( $statCode, FILTER_VALIDATE_FLOAT )) {
  161. throw new InvalidArgumentException(
  162. sprintf( $ERR, self::REQUEST_STATUS, var_export( $statCode, true ) )
  163. );
  164. }
  165. Util::assertString( $text, self::REQUEST_STATUS );
  166. }
  167. $input = [
  168. self::STATCODE => number_format((float) $statCode, 2, Util::$DOT, null ),
  169. self::STATDESC => StringFactory::trimTrailNL( $text ),
  170. ];
  171. if( ! empty( $extData )) {
  172. Util::assertString( $extData, self::REQUEST_STATUS );
  173. $input[self::EXTDATA] = StringFactory::trimTrailNL( $extData );
  174. }
  175. self::setMval( $this->requeststatus, $input, ( $params ?? [] ), null, $index );
  176. return $this;
  177. }
  178. }