Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 1476 and 1497 #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Bpi/Sdk/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
33 changes: 25 additions & 8 deletions Bpi/Sdk/Item/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down