Skip to content

Commit

Permalink
Merge pull request #32 from bookboon/hotfix/blacklist-reordered
Browse files Browse the repository at this point in the history
Hotfix/blacklist reordered
  • Loading branch information
lkm authored Jan 30, 2019
2 parents e6aed58 + b14be38 commit 7d7965b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/Entity/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,22 @@ public static function getTree(
*/
private static function recursiveBlacklist(array &$categories, array $blacklistedCategoryIds) : void
{
$hasAlteredArray = false;

foreach ($categories as $key => $category) {
if (in_array($category['_id'], $blacklistedCategoryIds)) {
if (in_array($category['_id'], $blacklistedCategoryIds, true)) {
unset($categories[$key]);
$hasAlteredArray = true;
continue;
}
if (isset($category['categories'])) {
self::recursiveBlacklist($categories[$key]['categories'], $blacklistedCategoryIds);
}
}

if ($hasAlteredArray) {
$categories = array_values($categories);
}
}

/**
Expand Down
15 changes: 14 additions & 1 deletion src/Entity/EntityStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
use Bookboon\Api\Exception\UsageException;
use Countable;
use Iterator;
use JsonSerializable;

class EntityStore implements Iterator, Countable
class EntityStore implements Iterator, Countable, JsonSerializable
{
/**
* @var array
Expand Down Expand Up @@ -113,4 +114,16 @@ public function count()
{
return count($this->contents);
}

/**
* Specify data which should be serialized to JSON
* @link https://php.net/manual/en/jsonserializable.jsonserialize.php
* @return mixed data which can be serialized by <b>json_encode</b>,
* which is a value of any type other than a resource.
* @since 5.4.0
*/
public function jsonSerialize()
{
return $this->contents;
}
}

0 comments on commit 7d7965b

Please sign in to comment.