-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds flag to published decks for tracking their wild-west-edition com…
…patibility.
- Loading branch information
1 parent
6d8fe36
commit ba4b6ae
Showing
4 changed files
with
109 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
/** | ||
* Adds "is Wild West Edition" flag to deckslists | ||
*/ | ||
final class Version20230702163723 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Adds "is Wild West Edition" flag to deckslists.'; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
$this->addSql('ALTER TABLE decklist ADD is_wwe TINYINT(1) DEFAULT \'0\' NOT NULL'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
$this->addSql('ALTER TABLE decklist DROP is_wwe'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace App\EventListener; | ||
|
||
use App\Entity\Decklist; | ||
use App\Entity\Pack; | ||
use App\Services\Decks; | ||
use Doctrine\ORM\Event\LifecycleEventArgs; | ||
use Doctrine\ORM\Event\PreUpdateEventArgs; | ||
|
||
class DecklistListener | ||
{ | ||
public function prePersist(LifecycleEventArgs $args) | ||
{ | ||
$entity = $args->getEntity(); | ||
if ($entity instanceof Decklist) { | ||
$this->setFormat($entity); | ||
} | ||
} | ||
|
||
public function preUpdate(PreUpdateEventArgs $args) | ||
{ | ||
$entity = $args->getEntity(); | ||
if ($entity instanceof Decklist) { | ||
$this->setFormat($entity); | ||
} | ||
} | ||
|
||
protected function setFormat(Decklist $decklist) | ||
{ | ||
$packs = []; | ||
foreach ($decklist->getSlots() as $slot) { | ||
$packs[] = $slot->getCard()->getPack(); | ||
} | ||
usort($packs, function (Pack $a, Pack $b) { | ||
$rhett = $a->getCycle()->getNumber() <=> $b->getCycle()->getNumber(); | ||
if ($rhett) { | ||
return $rhett; | ||
} | ||
return $a->getNumber() <=> $b->getNumber(); | ||
}); | ||
$earliestPack = $packs[0]; | ||
$isWwe = ( | ||
$earliestPack->getCycle()->getNumber() > Decks::TCAR_CYCLENUMBER | ||
|| ($earliestPack->getCycle()->getNumber() === Decks::TCAR_CYCLENUMBER | ||
&& $earliestPack->getNumber() >= Decks::TCAR_NUMBER | ||
) | ||
); | ||
$decklist->setIsWwe($isWwe); | ||
} | ||
} |