diff --git a/assets/js/app.data.js b/assets/js/app.data.js index 7e133747..cdb44471 100755 --- a/assets/js/app.data.js +++ b/assets/js/app.data.js @@ -34,10 +34,15 @@ var selectedRestrictionCode = app.config.get('restriction'); var restrictions; if (selectedRestrictionCode) { - restrictions = data.restrictions.find({ 'active': true, 'code': selectedRestrictionCode }); - } else { - restrictions = data.restrictions.find({ 'active': true }, { $limit: 1, $orderBy: { 'effectiveOn': -1 }}); + restrictions = data.restrictions.find({ + 'active': true, + 'code': selectedRestrictionCode + }); + if (restrictions.length) { + return restrictions[0]; + } } + restrictions = data.restrictions.find({ 'active': true }, { $limit: 1, $orderBy: { 'effectiveOn': -1 }}); return restrictions.length ? restrictions[0] : null; } diff --git a/assets/js/app.ui.js b/assets/js/app.ui.js index fbbf90a4..1527db90 100755 --- a/assets/js/app.ui.js +++ b/assets/js/app.ui.js @@ -217,7 +217,7 @@ out += ''; if (1 < activeRestrictions.length) { out += 'getDateUpdate()) { $lastModified = $restriction->getDateUpdate(); @@ -650,7 +651,7 @@ public function listRestrictions(Request $request, int $cacheExpiration, Seriali return $response; } - $json = $serializer->serialize($restrictions, 'json'); + $json = json_encode($restrictions); $response->headers->set('Content-Type', 'application/json'); $response->setContent($json); return $response; diff --git a/src/Entity/Restriction.php b/src/Entity/Restriction.php index 437650ee..94d864f7 100644 --- a/src/Entity/Restriction.php +++ b/src/Entity/Restriction.php @@ -4,6 +4,7 @@ use DateTime; use Doctrine\ORM\Mapping as ORM; +use Exception; use Gedmo\Mapping\Annotation as Gedmo; use Symfony\Component\Validator\Constraints as Assert; @@ -339,8 +340,27 @@ public function getReferencedCards() : array $this->getJoustBannedList(), $this->getMeleeRestrictedList(), $this->getMeleeBannedList(), - $cardsInPods + ...$cardsInPods ) ); } + + /** + * @inheritdoc + */ + public function jsonSerialize() + { + return [ + 'code' => $this->getCode(), + 'title' => $this->getTitle(), + 'effectiveOn' => $this->getEffectiveOn()->format('c'), + 'issuer' => $this->getIssuer(), + 'cardSet' => $this->getCardSet(), + 'contents' => $this->getContents(), + 'active' => $this->isActive(), + 'version' => $this->getVersion(), + 'dateUpdate' => $this->getDateUpdate()->format('c'), + 'dateCreation' => $this->getDateCreation()->format('c'), + ]; + } } diff --git a/src/Entity/RestrictionInterface.php b/src/Entity/RestrictionInterface.php index 21c89c5c..6e7ded20 100644 --- a/src/Entity/RestrictionInterface.php +++ b/src/Entity/RestrictionInterface.php @@ -3,12 +3,13 @@ namespace App\Entity; use DateTime; +use JsonSerializable; /** * Interface RestrictionInterface * @package App\Entity */ -interface RestrictionInterface +interface RestrictionInterface extends JsonSerializable { /** * @param string $code