diff --git a/src/Entities/Itunes/AbstractChannel.php b/src/Entities/Itunes/AbstractChannel.php index af96c6c..faa2238 100644 --- a/src/Entities/Itunes/AbstractChannel.php +++ b/src/Entities/Itunes/AbstractChannel.php @@ -2,6 +2,7 @@ namespace Lukaswhite\FeedWriter\Entities\Itunes; +use Lukaswhite\FeedWriter\Traits\Itunes\HasCategories; use Lukaswhite\FeedWriter\Traits\Itunes\HasAuthor; use Lukaswhite\FeedWriter\Traits\Itunes\HasBlock; use Lukaswhite\FeedWriter\Traits\Itunes\HasExplicit; @@ -19,6 +20,7 @@ abstract class AbstractChannel extends \Lukaswhite\FeedWriter\Entities\Rss\Chann use HasSubtitle, HasSummary, HasAuthor, + HasCategories, HasImage, HasExplicit, HasBlock; diff --git a/src/Entities/Itunes/Category.php b/src/Entities/Itunes/Category.php new file mode 100644 index 0000000..96ff66d --- /dev/null +++ b/src/Entities/Itunes/Category.php @@ -0,0 +1,47 @@ +createElement( 'itunes:category' ); + + if ( $this->text ) { + $category->setAttribute( 'text', $this->text ); + } + + $this->addCategoryElements( $category ); + + return $category; + } + + /** + * @param string $text + * @return Category + */ + public function text( string $text ) : self + { + $this->text = $text; + return $this; + } +} \ No newline at end of file diff --git a/src/Entities/Itunes/Channel.php b/src/Entities/Itunes/Channel.php index abce103..f5967e7 100644 --- a/src/Entities/Itunes/Channel.php +++ b/src/Entities/Itunes/Channel.php @@ -2,6 +2,7 @@ namespace Lukaswhite\FeedWriter\Entities\Itunes; + /** * Class Channel * @@ -21,4 +22,16 @@ public function addItem( ) : Item $this->items[ ] = $item; return $item; } + + /** + * Add an item + * + * @return Item + */ + public function addCategory( ) : Category + { + $category = new Category( $this->feed ); + $this->categories[ ] = $category; + return $category; + } } \ No newline at end of file diff --git a/src/Traits/Itunes/HasCategories.php b/src/Traits/Itunes/HasCategories.php new file mode 100644 index 0000000..14e846d --- /dev/null +++ b/src/Traits/Itunes/HasCategories.php @@ -0,0 +1,49 @@ +feed ) ); + $this->categories[ ] = $category; + return $category; + } + + /** + * Add the authors to the specified element. + * + * @param \DOMElement $el + * @return void + */ + protected function addCategoryElements( \DOMElement $el ) : void + { + if ( count( $this->categories ) ) { + foreach( $this->categories as $category ) { + /** @var Category $category */ + $el->appendChild( $category->element( ) ); + } + } + } +} \ No newline at end of file