mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
use trait timestamp and replace
This commit is contained in:
parent
ecdbf3fb33
commit
94c02be927
@ -74,7 +74,7 @@ class MigrationController extends EmailsController {
|
|||||||
->setChoicesMax( $d->ValueMax )
|
->setChoicesMax( $d->ValueMax )
|
||||||
->setPassword( $d->password_hash )
|
->setPassword( $d->password_hash )
|
||||||
->setDescription( $d->description )
|
->setDescription( $d->description )
|
||||||
->setCreationDate( date_create( $d->creation_date ) );
|
->setCreatedAt( date_create( $d->creation_date ) );
|
||||||
|
|
||||||
$pollsBySlug[ $d->id ] = $newPoll;
|
$pollsBySlug[ $d->id ] = $newPoll;
|
||||||
|
|
||||||
|
@ -142,7 +142,7 @@ class PollController extends EmailsController {
|
|||||||
return $this->notFoundPoll( $customUrl );
|
return $this->notFoundPoll( $customUrl );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $poll->getPassword() === $md5 ) {
|
if ( md5($poll->getPassword()) === $md5 ) {
|
||||||
// good matching pass
|
// good matching pass
|
||||||
return $this->json( $poll->display() );
|
return $this->json( $poll->display() );
|
||||||
} else {
|
} else {
|
||||||
|
@ -53,6 +53,7 @@ class Choice {
|
|||||||
private $poll;
|
private $poll;
|
||||||
|
|
||||||
public function __construct( $optionalName = null ) {
|
public function __construct( $optionalName = null ) {
|
||||||
|
$this->setCreatedAt( new DateTime());
|
||||||
$this->poll = new ArrayCollection();
|
$this->poll = new ArrayCollection();
|
||||||
$this->votes = new ArrayCollection();
|
$this->votes = new ArrayCollection();
|
||||||
$this->setDateTime( new DateTime() );
|
$this->setDateTime( new DateTime() );
|
||||||
|
@ -66,6 +66,7 @@ class Owner {
|
|||||||
$this->stackOfVotes = new ArrayCollection();
|
$this->stackOfVotes = new ArrayCollection();
|
||||||
$this->setCreatedAt( new DateTime() );
|
$this->setCreatedAt( new DateTime() );
|
||||||
$this->setModifierToken( uniqid() );
|
$this->setModifierToken( uniqid() );
|
||||||
|
$this->setCreatedAt( new DateTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setCreatedAt( DateTimeInterface $createdAt ): self {
|
public function setCreatedAt( DateTimeInterface $createdAt ): self {
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace App\Entity;
|
namespace App\Entity;
|
||||||
|
|
||||||
use App\Traits\RandomTrait;
|
use App\Traits\RandomTrait;
|
||||||
|
use App\Traits\TimeStampableTrait;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
@ -19,6 +20,8 @@ class Poll {
|
|||||||
|
|
||||||
use RandomTrait;
|
use RandomTrait;
|
||||||
|
|
||||||
|
use TimeStampableTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Id()
|
* @ORM\Id()
|
||||||
* @ORM\GeneratedValue()
|
* @ORM\GeneratedValue()
|
||||||
@ -46,11 +49,7 @@ class Poll {
|
|||||||
* @Serializer\Type("string")
|
* @Serializer\Type("string")
|
||||||
*/
|
*/
|
||||||
public $description;
|
public $description;
|
||||||
/**
|
|
||||||
* @ORM\Column(type="datetime" , options={"default"="CURRENT_TIMESTAMP"})
|
|
||||||
* @Serializer\Expose()
|
|
||||||
*/
|
|
||||||
public $creationDate;
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="datetime")
|
* @ORM\Column(type="datetime")
|
||||||
* @Serializer\Expose()
|
* @Serializer\Expose()
|
||||||
@ -196,6 +195,7 @@ class Poll {
|
|||||||
public function __construct() {
|
public function __construct() {
|
||||||
|
|
||||||
$this->initiate();
|
$this->initiate();
|
||||||
|
$this->setCreatedAt( new DateTime());
|
||||||
$this->votes = new ArrayCollection();
|
$this->votes = new ArrayCollection();
|
||||||
$this->stacksOfVotes = new ArrayCollection();
|
$this->stacksOfVotes = new ArrayCollection();
|
||||||
$this->choices = new ArrayCollection();
|
$this->choices = new ArrayCollection();
|
||||||
@ -208,7 +208,7 @@ class Poll {
|
|||||||
$this->choices = new ArrayCollection();
|
$this->choices = new ArrayCollection();
|
||||||
$this->comments = new ArrayCollection();
|
$this->comments = new ArrayCollection();
|
||||||
$this->setAdminKey( $this->generateRandomKey() );
|
$this->setAdminKey( $this->generateRandomKey() );
|
||||||
$this->setCreationDate( new DateTime() );
|
$this->setCreatedAt( new DateTime() );
|
||||||
$this->setExpiracyDate( $this->addDaysToDate(
|
$this->setExpiracyDate( $this->addDaysToDate(
|
||||||
new DateTime(),
|
new DateTime(),
|
||||||
$this->defaultExpiracyDaysFromNow
|
$this->defaultExpiracyDaysFromNow
|
||||||
@ -247,7 +247,7 @@ class Poll {
|
|||||||
return [
|
return [
|
||||||
'title' => $this->getTitle(),
|
'title' => $this->getTitle(),
|
||||||
'description' => $this->getDescription(),
|
'description' => $this->getDescription(),
|
||||||
'created_at' => $this->getCreationDate()->format( 'c' ),
|
'created_at' => $this->getCreatedAt()->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(),
|
||||||
@ -274,7 +274,8 @@ class Poll {
|
|||||||
$computedArray = [];
|
$computedArray = [];
|
||||||
$maxScore = 0;
|
$maxScore = 0;
|
||||||
|
|
||||||
$scoreInfos = ['score' => 0,
|
$scoreInfos = [
|
||||||
|
'score' => 0,
|
||||||
'yes' => [
|
'yes' => [
|
||||||
'count' => 0,
|
'count' => 0,
|
||||||
'people' => [],
|
'people' => [],
|
||||||
@ -286,11 +287,12 @@ class Poll {
|
|||||||
'no' => [
|
'no' => [
|
||||||
'count' => 0,
|
'count' => 0,
|
||||||
'people' => [],
|
'people' => [],
|
||||||
]];
|
],
|
||||||
|
];
|
||||||
|
|
||||||
// first, prefill all choices
|
// first, prefill all choices
|
||||||
foreach ( $this->getChoices() as $choice ) {
|
foreach ( $this->getChoices() as $choice ) {
|
||||||
$computedArray[ $choice->getId() ] = array_merge($scoreInfos, $choice->display($this->getKind()));
|
$computedArray[ $choice->getId() ] = array_merge( $scoreInfos, $choice->display( $this->getKind() ) );
|
||||||
}
|
}
|
||||||
// then, compute stack of votes scores on each choice
|
// then, compute stack of votes scores on each choice
|
||||||
foreach ( $this->getStacksOfVotes() as $stack_of_vote ) {
|
foreach ( $this->getStacksOfVotes() as $stack_of_vote ) {
|
||||||
@ -376,12 +378,12 @@ class Poll {
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCreationDate(): ?DateTimeInterface {
|
public function getCreatedAt(): ?DateTimeInterface {
|
||||||
return $this->creationDate;
|
return $this->createdAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setCreationDate( DateTimeInterface $creationDate ): self {
|
public function setCreatedAt( DateTimeInterface $createdAt ): self {
|
||||||
$this->creationDate = $creationDate;
|
$this->createdAt = $createdAt;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace App\Entity;
|
namespace App\Entity;
|
||||||
|
|
||||||
use App\Traits\TimeStampableTrait;
|
use App\Traits\TimeStampableTrait;
|
||||||
|
use DateTime;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
@ -52,6 +53,7 @@ class StackOfVotes {
|
|||||||
private $ip;
|
private $ip;
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
|
$this->setCreatedAt( new DateTime() );
|
||||||
$this->votes = new ArrayCollection();
|
$this->votes = new ArrayCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,13 +153,11 @@ class StackOfVotes {
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getIp(): ?string
|
public function getIp(): ?string {
|
||||||
{
|
|
||||||
return $this->ip;
|
return $this->ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setIp(string $ip): self
|
public function setIp( string $ip ): self {
|
||||||
{
|
|
||||||
$this->ip = $ip;
|
$this->ip = $ip;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -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 Vote {
|
class Vote {
|
||||||
|
|
||||||
|
use TimeStampableTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* for a text kind of choice: could be "yes" "no" "maybe" and empty.
|
* for a text kind of choice: could be "yes" "no" "maybe" and empty.
|
||||||
* for a date kind, the choice linked is equivalent to the value selected
|
* for a date kind, the choice linked is equivalent to the value selected
|
||||||
@ -20,12 +24,7 @@ class Vote {
|
|||||||
* @Serializer\Expose()
|
* @Serializer\Expose()
|
||||||
*/
|
*/
|
||||||
public $value;
|
public $value;
|
||||||
/**
|
|
||||||
* @ORM\Column(type="datetime" , options={"default"="CURRENT_TIMESTAMP"})
|
|
||||||
* @Serializer\Type("datetime")
|
|
||||||
* @Serializer\Expose()
|
|
||||||
*/
|
|
||||||
public $creationDate;
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToOne(targetEntity="App\Entity\Choice", inversedBy="votes", cascade={"persist"})
|
* @ORM\ManyToOne(targetEntity="App\Entity\Choice", inversedBy="votes", cascade={"persist"})
|
||||||
* @ORM\JoinColumn(nullable=false)
|
* @ORM\JoinColumn(nullable=false)
|
||||||
@ -54,7 +53,7 @@ class Vote {
|
|||||||
private $stacksOfVotes;
|
private $stacksOfVotes;
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
$this->setCreationDate( new DateTime() );
|
$this->setCreatedAt( new DateTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function display() {
|
public function display() {
|
||||||
|
@ -13,7 +13,7 @@ class PollType extends AbstractType {
|
|||||||
->add( 'title' )
|
->add( 'title' )
|
||||||
->add( 'customUrl' )
|
->add( 'customUrl' )
|
||||||
->add( 'description' )
|
->add( 'description' )
|
||||||
->add( 'creationDate' )
|
->add( 'createdAt' )
|
||||||
->add( 'expiracyDate' )
|
->add( 'expiracyDate' )
|
||||||
->add( 'kind' )
|
->add( 'kind' )
|
||||||
->add( 'allowedAnswers' )
|
->add( 'allowedAnswers' )
|
||||||
|
@ -28,9 +28,8 @@ trait TimeStampableTrait {
|
|||||||
|
|
||||||
|
|
||||||
public function addDaysToDate( DateTime $date, int $days ) {
|
public function addDaysToDate( DateTime $date, int $days ) {
|
||||||
$st = strtotime( $date->getTimestamp() );
|
|
||||||
|
|
||||||
return new DateTime( $st );
|
return $date->add(new \DateInterval('P'.$days.'D'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user