mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
uniform creation key created_at and format C
This commit is contained in:
parent
7f7265c851
commit
eaee01838d
@ -45,11 +45,11 @@ class MigrationController extends EmailsController {
|
|||||||
|
|
||||||
|
|
||||||
$pdo_options[ PDO::ATTR_ERRMODE ] = PDO::ERRMODE_EXCEPTION;
|
$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_USER' ),
|
||||||
$this->getParameter( 'OLD_DATABASE_PASS' ),
|
$this->getParameter( 'OLD_DATABASE_PASS' ),
|
||||||
$pdo_options );
|
$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 ) ) {
|
while ( $d = $res_polls->fetch( PDO::FETCH_OBJ ) ) {
|
||||||
|
|
||||||
$debug .= " <br> ajout de sondage : " . $d->title . ' - ' . $d->id;
|
$debug .= " <br> ajout de sondage : " . $d->title . ' - ' . $d->id;
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Entity;
|
namespace App\Entity;
|
||||||
|
|
||||||
|
use App\Traits\TimeStampableTrait;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
@ -15,6 +16,9 @@ use JMS\Serializer\Annotation as Serializer;
|
|||||||
* @Serializer\ExclusionPolicy("all")
|
* @Serializer\ExclusionPolicy("all")
|
||||||
*/
|
*/
|
||||||
class Choice {
|
class Choice {
|
||||||
|
|
||||||
|
use TimeStampableTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Id()
|
* @ORM\Id()
|
||||||
* @ORM\GeneratedValue()
|
* @ORM\GeneratedValue()
|
||||||
@ -36,11 +40,7 @@ class Choice {
|
|||||||
*/
|
*/
|
||||||
public $url;
|
public $url;
|
||||||
|
|
||||||
/**
|
|
||||||
* @ORM\Column(type="datetime", nullable=true)
|
|
||||||
* @Serializer\Type("datetime")
|
|
||||||
*/
|
|
||||||
public $dateTime;
|
|
||||||
/**
|
/**
|
||||||
* @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="choice", cascade={"persist"})
|
* @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="choice", cascade={"persist"})
|
||||||
* @Serializer\Type("App\Entity\Vote")
|
* @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() {
|
public function display() {
|
||||||
return [
|
return [
|
||||||
'id' => $this->getId(),
|
'id' => $this->getId(),
|
||||||
'date' => $this->getDateTime(),
|
'created_at' => $this->getCreatedAtAsString(),
|
||||||
'name' => $this->getName(),
|
'name' => $this->getName(),
|
||||||
'url' => $this->getUrl(),
|
'url' => $this->getUrl(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,16 +80,6 @@ class Choice {
|
|||||||
return $this->id;
|
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 {
|
public function getName(): ?string {
|
||||||
return $this->name;
|
return $this->name;
|
||||||
}
|
}
|
||||||
@ -105,6 +100,10 @@ class Choice {
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getDateTime(): ?DateTimeInterface {
|
||||||
|
return $this->dateTime;
|
||||||
|
}
|
||||||
|
|
||||||
public function getPoll(): ?Poll {
|
public function getPoll(): ?Poll {
|
||||||
return $this->poll;
|
return $this->poll;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Entity;
|
namespace App\Entity;
|
||||||
|
|
||||||
|
use App\Traits\TimeStampableTrait;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
@ -12,6 +13,9 @@ use JMS\Serializer\Annotation as Serializer;
|
|||||||
* @Serializer\ExclusionPolicy("all")
|
* @Serializer\ExclusionPolicy("all")
|
||||||
*/
|
*/
|
||||||
class Comment {
|
class Comment {
|
||||||
|
|
||||||
|
use TimeStampableTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Id()
|
* @ORM\Id()
|
||||||
* @ORM\GeneratedValue()
|
* @ORM\GeneratedValue()
|
||||||
@ -40,13 +44,6 @@ class Comment {
|
|||||||
*/
|
*/
|
||||||
private $text;
|
private $text;
|
||||||
|
|
||||||
/**
|
|
||||||
* @ORM\Column(type="datetime")
|
|
||||||
* @Serializer\Type("datetime")
|
|
||||||
* @Serializer\Expose()
|
|
||||||
*/
|
|
||||||
private $createdAt;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToOne(targetEntity="App\Entity\Poll", inversedBy="comments")
|
* @ORM\ManyToOne(targetEntity="App\Entity\Poll", inversedBy="comments")
|
||||||
*/
|
*/
|
||||||
@ -56,12 +53,18 @@ class Comment {
|
|||||||
$this->setCreatedAt( new DateTime() );
|
$this->setCreatedAt( new DateTime() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setCreatedAt( DateTimeInterface $createdAt ): self {
|
||||||
|
$this->createdAt = $createdAt;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
function display() {
|
function display() {
|
||||||
return [
|
return [
|
||||||
'id' => $this->getId(),
|
'id' => $this->getId(),
|
||||||
'text' => $this->getText(),
|
'text' => $this->getText(),
|
||||||
'pseudo' => $this->getOwner()->getPseudo(),
|
'pseudo' => $this->getOwner()->getPseudo(),
|
||||||
'date' => $this->getCreatedAt(),
|
'created_at' => $this->getCreatedAtAsString(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,12 +96,6 @@ class Comment {
|
|||||||
return $this->createdAt;
|
return $this->createdAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setCreatedAt( DateTimeInterface $createdAt ): self {
|
|
||||||
$this->createdAt = $createdAt;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getPoll(): ?Poll {
|
public function getPoll(): ?Poll {
|
||||||
return $this->poll;
|
return $this->poll;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Entity;
|
namespace App\Entity;
|
||||||
|
|
||||||
|
use App\Traits\TimeStampableTrait;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
@ -13,6 +14,8 @@ use JMS\Serializer\Annotation as Serializer;
|
|||||||
* @ORM\Entity(repositoryClass="App\Repository\OwnerRepository")
|
* @ORM\Entity(repositoryClass="App\Repository\OwnerRepository")
|
||||||
*/
|
*/
|
||||||
class Owner {
|
class Owner {
|
||||||
|
use TimeStampableTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="string", length=255)
|
* @ORM\Column(type="string", length=255)
|
||||||
* @Serializer\Type("string")
|
* @Serializer\Type("string")
|
||||||
@ -51,10 +54,7 @@ class Owner {
|
|||||||
* @ORM\Column(type="string", length=255)
|
* @ORM\Column(type="string", length=255)
|
||||||
*/
|
*/
|
||||||
private $modifierToken;
|
private $modifierToken;
|
||||||
/**
|
|
||||||
* @ORM\Column(type="datetime" , options={"default"="CURRENT_TIMESTAMP"})
|
|
||||||
*/
|
|
||||||
private $createdAt;
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="datetime" , options={"default"="CURRENT_TIMESTAMP"},nullable=true)
|
* @ORM\Column(type="datetime" , options={"default"="CURRENT_TIMESTAMP"},nullable=true)
|
||||||
*/
|
*/
|
||||||
@ -68,6 +68,45 @@ class Owner {
|
|||||||
$this->setModifierToken( uniqid() );
|
$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 {
|
public function getId(): ?int {
|
||||||
return $this->id;
|
return $this->id;
|
||||||
@ -83,16 +122,6 @@ class Owner {
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPseudo(): ?string {
|
|
||||||
return $this->pseudo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setPseudo( string $pseudo ): self {
|
|
||||||
$this->pseudo = $pseudo;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Collection|Poll[]
|
* @return Collection|Poll[]
|
||||||
*/
|
*/
|
||||||
@ -177,16 +206,6 @@ class Owner {
|
|||||||
return $this;
|
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 {
|
public function addComment( Comment $comment ): self {
|
||||||
if ( ! $this->comments->contains( $comment ) ) {
|
if ( ! $this->comments->contains( $comment ) ) {
|
||||||
$this->comments[] = $comment;
|
$this->comments[] = $comment;
|
||||||
@ -212,12 +231,6 @@ class Owner {
|
|||||||
return $this->createdAt;
|
return $this->createdAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setCreatedAt( DateTimeInterface $createdAt ): self {
|
|
||||||
$this->createdAt = $createdAt;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getRequestedPollsDate() {
|
public function getRequestedPollsDate() {
|
||||||
return $this->requestedPollsDate;
|
return $this->requestedPollsDate;
|
||||||
}
|
}
|
||||||
|
@ -254,11 +254,11 @@ class Poll {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function displayForAdmin() {
|
public function displayForAdmin() {
|
||||||
$content = $this->display();
|
$content = $this->display();
|
||||||
$content[ 'owner_modifier_token' ] = $this->getOwner()->getModifierToken();
|
$content[ 'owner' ] = $this->getOwner()->displayForAdmin();
|
||||||
$content[ 'admin_key' ] = $this->getAdminKey();
|
$content[ 'admin_key' ] = $this->getAdminKey();
|
||||||
$content[ 'password_hash' ] = $this->getPassword();
|
$content[ 'password_hash' ] = $this->getPassword();
|
||||||
$content[ 'id' ] = $this->getId();
|
$content[ 'id' ] = $this->getId();
|
||||||
|
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
@ -282,7 +282,8 @@ class Poll {
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
'title' => $this->getTitle(),
|
'title' => $this->getTitle(),
|
||||||
'creation_date' => $this->getCreationDate()->format( 'c' ),
|
'description' => $this->getDescription(),
|
||||||
|
'created_at' => $this->getCreationDate()->format( 'c' ),
|
||||||
'expiracy_date' => $this->getExpiracyDate()->format( 'c' ),
|
'expiracy_date' => $this->getExpiracyDate()->format( 'c' ),
|
||||||
'votes_max' => $this->getVotesMax(),
|
'votes_max' => $this->getVotesMax(),
|
||||||
'choices_max' => $this->getChoicesMax(),
|
'choices_max' => $this->getChoicesMax(),
|
||||||
@ -396,6 +397,16 @@ class Poll {
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getDescription(): ?string {
|
||||||
|
return $this->description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDescription( string $description ): self {
|
||||||
|
$this->description = $description;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function getCreationDate(): ?DateTimeInterface {
|
public function getCreationDate(): ?DateTimeInterface {
|
||||||
return $this->creationDate;
|
return $this->creationDate;
|
||||||
}
|
}
|
||||||
@ -556,16 +567,6 @@ class Poll {
|
|||||||
return $this->votes;
|
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 {
|
public function getCustomUrl(): ?string {
|
||||||
return $this->customUrl;
|
return $this->customUrl;
|
||||||
}
|
}
|
||||||
|
8
src/Traits/RandomTrait.php
Executable file
8
src/Traits/RandomTrait.php
Executable file
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Traits;
|
||||||
|
|
||||||
|
trait RandomTrait {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user