diff --git a/Bpi/Sdk/Document.php b/Bpi/Sdk/Document.php index 09dd7f0..ab4bf26 100644 --- a/Bpi/Sdk/Document.php +++ b/Bpi/Sdk/Document.php @@ -276,6 +276,31 @@ public function walkProperties($callback) } /** + * Iterates over all tags of current item + */ + public function walkTags($callback) + { + $crawler = new Crawler($this->crawler->current()); + return $crawler->filter('item tags tag')->each(function($e) use($callback) { + $sxml = simplexml_import_dom($e); + $callback(current($sxml->attributes()) + array('@value' => (string) $sxml)); + }); + } + + /** + * Iterates over all assets of current item + */ + public function walkAssets($callback) + { + $crawler = new Crawler($this->crawler->current()); + return $crawler->filter('item assets file')->each(function($e) use($callback) { + $sxml = simplexml_import_dom($e); + $callback(current($sxml->attributes()) + array('@value' => (string) $sxml)); + }); + } + + /** + * * @return array */ public function propertiesToArray() diff --git a/Bpi/Sdk/Item/Node.php b/Bpi/Sdk/Item/Node.php index ba1e5ce..c769cb5 100644 --- a/Bpi/Sdk/Item/Node.php +++ b/Bpi/Sdk/Item/Node.php @@ -10,16 +10,33 @@ class Node extends BaseItem */ public function getAssets() { - $result = array(); - foreach ($this->getProperties() as $key => $val) - { - if (strpos($key, 'asset') !== FALSE) - { - $result[$key] = $val; + $assets = array(); + $this->document->walkAssets(function($e) use(&$assets) { + $type = $e['type']; + if (!isset($assets[$type])) { + $assets[$type] = array(); } - } + $assets[$type][] = $e; + }); - return $result; + return $assets; + } + + /** + * Get node tags. + * + * @return array + */ + public function getTags() + { + $tags = array(); + $this->document->walkTags(function($e) use(&$tags) { + if (!empty($e['tag_name'])) { + $tags[] = $e['tag_name']; + } + }); + + return $tags; } public function syndicate()