uniform creation key created_at and format C

This commit is contained in:
Tykayn 2021-04-27 10:30:45 +02:00 committed by tykayn
parent 7f7265c851
commit eaee01838d
6 changed files with 102 additions and 84 deletions

View File

@ -45,11 +45,11 @@ class MigrationController extends EmailsController {
$pdo_options[ PDO::ATTR_ERRMODE ] = PDO::ERRMODE_EXCEPTION;
$bdd = new PDO( 'mysql:host=localhost;dbname=' . $this->getParameter( 'OLD_DATABASE_NAME' ),
$bdd = new PDO( 'mysql:host=localhost;dbname=' . $this->getParameter( 'OLD_DATABASE_NAME' ),
$this->getParameter( 'OLD_DATABASE_USER' ),
$this->getParameter( 'OLD_DATABASE_PASS' ),
$pdo_options );
$res_polls = $bdd->query( 'SELECT * FROM fd_poll' );
$res_polls = $bdd->query( 'SELECT * FROM fd_poll' );
while ( $d = $res_polls->fetch( PDO::FETCH_OBJ ) ) {
$debug .= " <br> ajout de sondage : " . $d->title . ' - ' . $d->id;

View File

@ -2,6 +2,7 @@
namespace App\Entity;
use App\Traits\TimeStampableTrait;
use DateTime;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
@ -15,6 +16,9 @@ use JMS\Serializer\Annotation as Serializer;
* @Serializer\ExclusionPolicy("all")
*/
class Choice {
use TimeStampableTrait;
/**
* @ORM\Id()
* @ORM\GeneratedValue()
@ -36,11 +40,7 @@ class Choice {
*/
public $url;
/**
* @ORM\Column(type="datetime", nullable=true)
* @Serializer\Type("datetime")
*/
public $dateTime;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="choice", cascade={"persist"})
* @Serializer\Type("App\Entity\Vote")
@ -61,13 +61,18 @@ class Choice {
}
}
public function setDateTime( ?DateTimeInterface $dateTime ): self {
$this->dateTime = $dateTime;
return $this;
}
public function display() {
return [
'id' => $this->getId(),
'date' => $this->getDateTime(),
'name' => $this->getName(),
'url' => $this->getUrl(),
'id' => $this->getId(),
'created_at' => $this->getCreatedAtAsString(),
'name' => $this->getName(),
'url' => $this->getUrl(),
];
}
@ -75,16 +80,6 @@ class Choice {
return $this->id;
}
public function getDateTime(): ?DateTimeInterface {
return $this->dateTime;
}
public function setDateTime( ?DateTimeInterface $dateTime ): self {
$this->dateTime = $dateTime;
return $this;
}
public function getName(): ?string {
return $this->name;
}
@ -105,6 +100,10 @@ class Choice {
return $this;
}
public function getDateTime(): ?DateTimeInterface {
return $this->dateTime;
}
public function getPoll(): ?Poll {
return $this->poll;
}

View File

@ -2,6 +2,7 @@
namespace App\Entity;
use App\Traits\TimeStampableTrait;
use DateTime;
use DateTimeInterface;
use Doctrine\ORM\Mapping as ORM;
@ -12,6 +13,9 @@ use JMS\Serializer\Annotation as Serializer;
* @Serializer\ExclusionPolicy("all")
*/
class Comment {
use TimeStampableTrait;
/**
* @ORM\Id()
* @ORM\GeneratedValue()
@ -40,13 +44,6 @@ class Comment {
*/
private $text;
/**
* @ORM\Column(type="datetime")
* @Serializer\Type("datetime")
* @Serializer\Expose()
*/
private $createdAt;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Poll", inversedBy="comments")
*/
@ -56,12 +53,18 @@ class Comment {
$this->setCreatedAt( new DateTime() );
}
public function setCreatedAt( DateTimeInterface $createdAt ): self {
$this->createdAt = $createdAt;
return $this;
}
function display() {
return [
'id' => $this->getId(),
'text' => $this->getText(),
'pseudo' => $this->getOwner()->getPseudo(),
'date' => $this->getCreatedAt(),
'id' => $this->getId(),
'text' => $this->getText(),
'pseudo' => $this->getOwner()->getPseudo(),
'created_at' => $this->getCreatedAtAsString(),
];
}
@ -93,12 +96,6 @@ class Comment {
return $this->createdAt;
}
public function setCreatedAt( DateTimeInterface $createdAt ): self {
$this->createdAt = $createdAt;
return $this;
}
public function getPoll(): ?Poll {
return $this->poll;
}

View File

@ -2,6 +2,7 @@
namespace App\Entity;
use App\Traits\TimeStampableTrait;
use DateTime;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
@ -13,6 +14,8 @@ use JMS\Serializer\Annotation as Serializer;
* @ORM\Entity(repositoryClass="App\Repository\OwnerRepository")
*/
class Owner {
use TimeStampableTrait;
/**
* @ORM\Column(type="string", length=255)
* @Serializer\Type("string")
@ -51,10 +54,7 @@ class Owner {
* @ORM\Column(type="string", length=255)
*/
private $modifierToken;
/**
* @ORM\Column(type="datetime" , options={"default"="CURRENT_TIMESTAMP"})
*/
private $createdAt;
/**
* @ORM\Column(type="datetime" , options={"default"="CURRENT_TIMESTAMP"},nullable=true)
*/
@ -68,6 +68,45 @@ class Owner {
$this->setModifierToken( uniqid() );
}
public function setCreatedAt( DateTimeInterface $createdAt ): self {
$this->createdAt = $createdAt;
return $this;
}
public function display() {
return [
'pseudo' => $this->getPseudo(),
];
}
public function getPseudo(): ?string {
return $this->pseudo;
}
public function setPseudo( string $pseudo ): self {
$this->pseudo = $pseudo;
return $this;
}
public function displayForAdmin() {
return [
'pseudo' => $this->getPseudo(),
'modifier_token' => $this->getModifierToken(),
'created_at' => $this->getCreatedAtAsString(),
];
}
public function getModifierToken(): ?string {
return $this->modifierToken;
}
public function setModifierToken( string $modifierToken ): self {
$this->modifierToken = $modifierToken;
return $this;
}
public function getId(): ?int {
return $this->id;
@ -83,16 +122,6 @@ class Owner {
return $this;
}
public function getPseudo(): ?string {
return $this->pseudo;
}
public function setPseudo( string $pseudo ): self {
$this->pseudo = $pseudo;
return $this;
}
/**
* @return Collection|Poll[]
*/
@ -177,16 +206,6 @@ class Owner {
return $this;
}
public function getModifierToken(): ?string {
return $this->modifierToken;
}
public function setModifierToken( string $modifierToken ): self {
$this->modifierToken = $modifierToken;
return $this;
}
public function addComment( Comment $comment ): self {
if ( ! $this->comments->contains( $comment ) ) {
$this->comments[] = $comment;
@ -212,12 +231,6 @@ class Owner {
return $this->createdAt;
}
public function setCreatedAt( DateTimeInterface $createdAt ): self {
$this->createdAt = $createdAt;
return $this;
}
public function getRequestedPollsDate() {
return $this->requestedPollsDate;
}

View File

@ -254,11 +254,11 @@ class Poll {
}
public function displayForAdmin() {
$content = $this->display();
$content[ 'owner_modifier_token' ] = $this->getOwner()->getModifierToken();
$content[ 'admin_key' ] = $this->getAdminKey();
$content[ 'password_hash' ] = $this->getPassword();
$content[ 'id' ] = $this->getId();
$content = $this->display();
$content[ 'owner' ] = $this->getOwner()->displayForAdmin();
$content[ 'admin_key' ] = $this->getAdminKey();
$content[ 'password_hash' ] = $this->getPassword();
$content[ 'id' ] = $this->getId();
return $content;
}
@ -282,7 +282,8 @@ class Poll {
return [
'title' => $this->getTitle(),
'creation_date' => $this->getCreationDate()->format( 'c' ),
'description' => $this->getDescription(),
'created_at' => $this->getCreationDate()->format( 'c' ),
'expiracy_date' => $this->getExpiracyDate()->format( 'c' ),
'votes_max' => $this->getVotesMax(),
'choices_max' => $this->getChoicesMax(),
@ -396,6 +397,16 @@ class Poll {
return $this;
}
public function getDescription(): ?string {
return $this->description;
}
public function setDescription( string $description ): self {
$this->description = $description;
return $this;
}
public function getCreationDate(): ?DateTimeInterface {
return $this->creationDate;
}
@ -556,16 +567,6 @@ class Poll {
return $this->votes;
}
public function getDescription(): ?string {
return $this->description;
}
public function setDescription( string $description ): self {
$this->description = $description;
return $this;
}
public function getCustomUrl(): ?string {
return $this->customUrl;
}

8
src/Traits/RandomTrait.php Executable file
View File

@ -0,0 +1,8 @@
<?php
namespace App\Traits;
trait RandomTrait {
}