. * * This file is a part of iCalcreator. */ namespace Kigkonsult\Icalcreator\Traits; use Kigkonsult\Icalcreator\Util\Util; /** * RELATED-TO property functions * * @author Kjell-Inge Gustafsson, kigkonsult * @since 2.22.23 - 2017-02-17 */ trait RELATED_TOtrait { /** * @var array component property RELATED_TO value * @access protected */ protected $relatedto = null; /** * Return formatted output for calendar component property related-to * * @return string */ public function createRelatedTo() { if( empty( $this->relatedto )) { return null; } $output = null; foreach( $this->relatedto as $rx => $relation ) { if( ! empty( $relation[Util::$LCvalue] )) { $output .= Util::createElement( Util::$RELATED_TO, Util::createParams( $relation[Util::$LCparams] ), Util::strrep( $relation[Util::$LCvalue] ) ); } elseif( $this->getConfig( Util::$ALLOWEMPTY )) { $output .= Util::createElement( Util::$RELATED_TO ); } } return $output; } /** * Set calendar component property related-to * * @param string $value * @param array $params * @param int $index * @return bool */ public function setRelatedTo( $value, $params = [], $index = null ) { static $RELTYPE = 'RELTYPE'; static $PARENT = 'PARENT'; if( empty( $value )) { if( $this->getConfig( Util::$ALLOWEMPTY )) { $value = Util::$SP0; } else { return false; } } if( ! empty( $params )) { Util::existRem( $params, $RELTYPE, $PARENT, true ); // remove default } Util::setMval( $this->relatedto, Util::trimTrailNL( $value ), $params, false, $index ); return true; } }