. * * This file is a part of iCalcreator. */ namespace Kigkonsult\Icalcreator\Traits; use Kigkonsult\Icalcreator\Util\Util; use function implode; use function is_array; /** * RESOURCES property functions * * @author Kjell-Inge Gustafsson, kigkonsult * @since 2.22.23 - 2017-02-17 */ trait RESOURCEStrait { /** * @var array component property RESOURCES value * @access protected */ protected $resources = null; /** * Return formatted output for calendar component property resources * * @return string */ public function createResources() { if( empty( $this->resources )) { return null; } $output = null; $lang = $this->getConfig( Util::$LANGUAGE ); foreach( $this->resources as $rx => $resource ) { if( empty( $resource[Util::$LCvalue] )) { if( $this->getConfig( Util::$ALLOWEMPTY )) { $output .= Util::createElement( Util::$RESOURCES ); } continue; } if( is_array( $resource[Util::$LCvalue] )) { foreach( $resource[Util::$LCvalue] as $rix => $rValue ) { $resource[Util::$LCvalue][$rix] = Util::strrep( $rValue ); } $content = implode( Util::$COMMA, $resource[Util::$LCvalue] ); } else { $content = Util::strrep( $resource[Util::$LCvalue] ); } $output .= Util::createElement( Util::$RESOURCES, Util::createParams( $resource[Util::$LCparams], Util::$ALTRPLANGARR, $lang ), $content ); } return $output; } /** * Set calendar component property recources * * @param mixed $value * @param array $params * @param integer $index * @return bool */ public function setResources( $value, $params = null, $index = null ) { if( empty( $value )) { if( $this->getConfig( Util::$ALLOWEMPTY )) { $value = Util::$SP0; } else { return false; } } if( is_array( $value )) { foreach( $value as & $valuePart ) { $valuePart = Util::trimTrailNL( $valuePart ); } } else { $value = Util::trimTrailNL( $value ); } Util::setMval( $this->resources, $value, $params, false, $index ); return true; } }