Skip to content
Merged
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
11 changes: 8 additions & 3 deletions assets/js/app.data.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion assets/js/app.ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@
out += '<tr>';
if (1 < activeRestrictions.length) {
out += '<td><input name="restriction" type="radio" data-rl-code="' + rl.code + '"';
if (selectedRestriction.code === rl.code) {
if (selectedRestriction && selectedRestriction.code === rl.code) {
out += ' checked="checked"';
}
out += '></td>';
Expand Down
2 changes: 1 addition & 1 deletion assets/js/ui.deckinit.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
selectedRestriction = app.data.getBestSelectedRestrictedList();
activeRestrictions.forEach(function(rl) {
out += '<option value="' + rl.code + '"';
if (rl.code === selectedRestriction.code) {
if (selectedRestriction && rl.code === selectedRestriction.code) {
out += ' selected="selected"';
}
out += '>'
Expand Down
5 changes: 3 additions & 2 deletions src/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use App\Entity\Pack;
use App\Entity\PackInterface;
use App\Entity\Restriction;
use App\Entity\RestrictionInterface;
use App\Services\CardsData;
use DateInterval;
use DateTime;
Expand Down Expand Up @@ -639,7 +640,7 @@ public function listRestrictions(Request $request, int $cacheExpiration, Seriali
// check the last-modified-since header

$lastModified = null;
/* @var PackInterface $pack */
/* @var RestrictionInterface $restriction */
foreach ($restrictions as $restriction) {
if (!$lastModified || $lastModified < $restriction->getDateUpdate()) {
$lastModified = $restriction->getDateUpdate();
Expand All @@ -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;
Expand Down
22 changes: 21 additions & 1 deletion src/Entity/Restriction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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'),
];
}
}
3 changes: 2 additions & 1 deletion src/Entity/RestrictionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down