. * * This file is a part of iCalcreator. */ namespace Kigkonsult\Icalcreator\Traits; use Kigkonsult\Icalcreator\Util\Util; use function implode; use function is_array; /** * CATEGORIES property functions * * @author Kjell-Inge Gustafsson, kigkonsult * @since 2.22.23 - 2017-02-02 */ trait CATEGORIEStrait { /** * @var array component property CATEGORIES value * @access protected */ protected $categories = null; /** * Return formatted output for calendar component property categories * * @return string */ public function createCategories() { if( empty( $this->categories )) { return null; } $output = null; $lang = $this->getConfig( Util::$LANGUAGE ); foreach( $this->categories as $cx => $category ) { if( empty( $category[Util::$LCvalue] )) { if( $this->getConfig( Util::$ALLOWEMPTY )) { $output .= Util::createElement( Util::$CATEGORIES ); } continue; } if( is_array( $category[Util::$LCvalue] )) { foreach( $category[Util::$LCvalue] as $cix => $cValue ) { $category[Util::$LCvalue][$cix] = Util::strrep( $cValue ); } $content = implode( Util::$COMMA, $category[Util::$LCvalue] ); } else { $content = Util::strrep( $category[Util::$LCvalue] ); } $output .= Util::createElement( Util::$CATEGORIES, Util::createParams( $category[Util::$LCparams], [ Util::$LANGUAGE ], $lang ), $content ); } return $output; } /** * Set calendar component property categories * * @param mixed $value * @param array $params * @param integer $index * @return bool */ public function setCategories( $value, $params = null, $index = null ) { if( empty( $value )) { if( $this->getConfig( Util::$ALLOWEMPTY )) { $value = Util::$SP0; } else { return false; } } Util::setMval( $this->categories, $value, $params, false, $index ); return true; } }