From 794f59990aaccfb1f468e41ead2c299ce8a8982d Mon Sep 17 00:00:00 2001 From: Mikkel Ricky Date: Wed, 11 May 2016 11:25:58 +0200 Subject: [PATCH 1/2] Revert "Revert 3708a34 3bca4df f8d9500 to remove asset support" This reverts commit 1bd85cfca874366ab59aa73d62f841bb682dea1e. --- Bpi/Sdk/Item/Node.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Bpi/Sdk/Item/Node.php b/Bpi/Sdk/Item/Node.php index ba1e5ce..1925d0b 100644 --- a/Bpi/Sdk/Item/Node.php +++ b/Bpi/Sdk/Item/Node.php @@ -10,16 +10,16 @@ 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; } public function syndicate() From a3d5c484392dab8fe4681826ff195822b10e865a Mon Sep 17 00:00:00 2001 From: Mikkel Ricky Date: Wed, 11 May 2016 11:26:23 +0200 Subject: [PATCH 2/2] Revert "Revert 94018eb to remove asset support." This reverts commit 98ca793a2e11e00abb23331e36892bbe0d51bc07. --- Bpi/Sdk/Document.php | 25 +++++++++++++++++++++++++ Bpi/Sdk/Item/Node.php | 17 +++++++++++++++++ 2 files changed, 42 insertions(+) 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 1925d0b..c769cb5 100644 --- a/Bpi/Sdk/Item/Node.php +++ b/Bpi/Sdk/Item/Node.php @@ -22,6 +22,23 @@ public function getAssets() 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() { // @todo implementation