-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
40544ce
commit 08b6e33
Showing
7 changed files
with
310 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Migrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
|
||
/** | ||
* Version 20231019133431 | ||
*/ | ||
class Version20231019133431 extends \Doctrine\Migrations\AbstractMigration | ||
{ | ||
/** | ||
* @param \Doctrine\DBAL\Schema\Schema $schema | ||
* @return void | ||
*/ | ||
public function up(Schema $schema) : void | ||
{ | ||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); | ||
|
||
$this->addSql('CREATE SEQUENCE shop_reservations_bans_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); | ||
$this->addSql('CREATE TABLE shop_reservations_bans (id BIGINT NOT NULL, person_username VARCHAR(50) DEFAULT NULL, startTimestamp TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, endTimestamp TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY(id))'); | ||
$this->addSql('CREATE INDEX IDX_197F9CC06C18A340 ON shop_reservations_bans (person_username)'); | ||
$this->addSql('ALTER TABLE shop_reservations_bans ADD CONSTRAINT FK_197F9CC06C18A340 FOREIGN KEY (person_username) REFERENCES users_people (username) NOT DEFERRABLE INITIALLY IMMEDIATE'); | ||
} | ||
|
||
/** | ||
* @param \Doctrine\DBAL\Schema\Schema $schema | ||
* @return void | ||
*/ | ||
public function down(Schema $schema) : void | ||
{ | ||
$this->throwIrreversibleMigrationException(); | ||
} | ||
} |
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,37 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Migrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
|
||
/** | ||
* Version 20231019134846 | ||
*/ | ||
class Version20231019134846 extends \Doctrine\Migrations\AbstractMigration | ||
{ | ||
/** | ||
* @param \Doctrine\DBAL\Schema\Schema $schema | ||
* @return void | ||
*/ | ||
public function up(Schema $schema) : void | ||
{ | ||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); | ||
|
||
$this->addSql('ALTER TABLE shop_reservations_bans DROP CONSTRAINT fk_197f9cc06c18a340'); | ||
$this->addSql('DROP INDEX idx_197f9cc06c18a340'); | ||
$this->addSql('ALTER TABLE shop_reservations_bans ADD person BIGINT DEFAULT NULL'); | ||
$this->addSql('ALTER TABLE shop_reservations_bans DROP person_username'); | ||
$this->addSql('ALTER TABLE shop_reservations_bans ADD CONSTRAINT FK_197F9CC034DCD176 FOREIGN KEY (person) REFERENCES users_people (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); | ||
$this->addSql('CREATE INDEX IDX_197F9CC034DCD176 ON shop_reservations_bans (person)'); | ||
} | ||
|
||
/** | ||
* @param \Doctrine\DBAL\Schema\Schema $schema | ||
* @return void | ||
*/ | ||
public function down(Schema $schema) : void | ||
{ | ||
$this->throwIrreversibleMigrationException(); | ||
} | ||
} |
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,132 @@ | ||
<?php | ||
|
||
namespace ShopBundle\Entity\Reservation; | ||
|
||
use DateTime; | ||
use CommonBundle\Entity\User\Person; | ||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* This entity stores a reservation ban for a user. | ||
* | ||
* @ORM\Entity(repositoryClass="ShopBundle\Repository\Reservation\Ban") | ||
* @ORM\Table(name="shop_reservations_bans") | ||
*/ | ||
class Ban | ||
{ | ||
/** | ||
* @var integer The ID of this ban | ||
* | ||
* @ORM\Id | ||
* @ORM\GeneratedValue | ||
* @ORM\Column(type="bigint") | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* @var Person The person this ban belongs to | ||
* | ||
* @ORM\ManyToOne(targetEntity="CommonBundle\Entity\User\Person") | ||
* @ORM\JoinColumn(name="person", referencedColumnName="id") | ||
*/ | ||
private $person; | ||
|
||
/** | ||
* @var DateTime The timestamp at which the ban starts | ||
* | ||
* @ORM\Column(type="datetime") | ||
*/ | ||
private $startTimestamp; | ||
|
||
/** | ||
* @var DateTime The timestamp at which the ban ends (null if it does not end) | ||
* | ||
* @ORM\Column(type="datetime", nullable=true) | ||
*/ | ||
private $endTimestamp; | ||
|
||
public function __construct() { | ||
} | ||
|
||
/** | ||
* @return Person The person this ban applies to | ||
*/ | ||
public function GetPerson() { | ||
return $this->person; | ||
} | ||
|
||
/** | ||
* @param $person | ||
* @return $this | ||
*/ | ||
public function SetPerson($person) { | ||
$this->person = $person; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return DateTime | ||
*/ | ||
public function getStartTimestamp() { | ||
return $this->startTimestamp; | ||
} | ||
|
||
/** | ||
* @param $timestamp | ||
* @return $this | ||
*/ | ||
public function setStartTimestamp($timestamp) { | ||
$this->startTimestamp = $timestamp; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return DateTime|null | ||
*/ | ||
public function getEndTimestamp() { | ||
return $this->endTimestamp; | ||
} | ||
|
||
/** | ||
* @param $timestamp | ||
* @return $this | ||
*/ | ||
public function setEndTimestamp($timestamp) { | ||
$this->endTimestamp = $timestamp; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Set end timestamp to null so that ban will never end | ||
* | ||
* @return $this | ||
*/ | ||
public function removeEndTimestamp() { | ||
$this->endTimestamp = null; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return bool Whether the ban is currently active on the user | ||
*/ | ||
public function IsActive() { | ||
// Get the current timestamp | ||
$currentTimestamp = time(); | ||
|
||
if ($currentTimestamp >= $this->startTimestamp) { | ||
if ($this->endTimestamp === null) { | ||
return true; // User is banned indefinitely | ||
} | ||
|
||
if ($currentTimestamp <= $this->endTimestamp) { | ||
return true; // User is currently banned | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
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,48 @@ | ||
<?php | ||
|
||
namespace ShopBundle\Hydrator\Reservation; | ||
|
||
use ShopBundle\Entity\Reservation\Ban as BanEntity; | ||
|
||
class Ban extends \CommonBundle\Component\Hydrator\Hydrator | ||
{ | ||
protected function doExtract($object = null) | ||
{ | ||
error_log("extract"); | ||
return array(); | ||
// error_log("extract"); | ||
// if ($object === null) { | ||
// return array(); | ||
// } | ||
// | ||
// $data = $this->stdExtract($object); | ||
// $data['start_timestamp'] = $object->getStartTimestamp()->format('d/m/Y H:i'); | ||
// $data['end_timestamp'] = $object->getEndTimestamp() ? $object->getEndTimestamp()->format('d/m/Y H:i') : ' '; | ||
//// $data['person']['id'] = $object->getPerson()->getId(); | ||
// | ||
// return $data; | ||
} | ||
|
||
protected function doHydrate(array $data, $object = null) | ||
{ | ||
error_log("hydrate"); | ||
|
||
if ($object === null) { | ||
$object = new BanEntity(); | ||
} | ||
|
||
return $object; | ||
// | ||
// | ||
// | ||
// $object->setStartTimestamp(self::loadDateTime($data['start_timestamp'])); | ||
// $object->setEndTimestamp(self::loadDateTime($data['end_timestamp'])); | ||
// | ||
// $person = $this->getEntityManager() | ||
// ->getRepository('CommonBundle\Entity\User\Person') | ||
// ->find($data['person']['id']); | ||
// $object->setPerson($person); | ||
// | ||
// return $object; | ||
} | ||
} |
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,8 @@ | ||
<?php | ||
|
||
namespace ShopBundle\Repository\Reservation; | ||
|
||
class Ban extends \CommonBundle\Component\Doctrine\ORM\EntityRepository | ||
{ | ||
|
||
} |