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 )
|
||||
->setPassword( $d->password_hash )
|
||||
->setDescription( $d->description )
|
||||
->setCreationDate( date_create( $d->creation_date ) );
|
||||
->setCreatedAt( date_create( $d->creation_date ) );
|
||||
|
||||
$pollsBySlug[ $d->id ] = $newPoll;
|
||||
|
||||
|
@ -142,7 +142,7 @@ class PollController extends EmailsController {
|
||||
return $this->notFoundPoll( $customUrl );
|
||||
}
|
||||
|
||||
if ( $poll->getPassword() === $md5 ) {
|
||||
if ( md5($poll->getPassword()) === $md5 ) {
|
||||
// good matching pass
|
||||
return $this->json( $poll->display() );
|
||||
} else {
|
||||
|
@ -53,6 +53,7 @@ class Choice {
|
||||
private $poll;
|
||||
|
||||
public function __construct( $optionalName = null ) {
|
||||
$this->setCreatedAt( new DateTime());
|
||||
$this->poll = new ArrayCollection();
|
||||
$this->votes = new ArrayCollection();
|
||||
$this->setDateTime( new DateTime() );
|
||||
|
@ -66,6 +66,7 @@ class Owner {
|
||||
$this->stackOfVotes = new ArrayCollection();
|
||||
$this->setCreatedAt( new DateTime() );
|
||||
$this->setModifierToken( uniqid() );
|
||||
$this->setCreatedAt( new DateTime());
|
||||
}
|
||||
|
||||
public function setCreatedAt( DateTimeInterface $createdAt ): self {
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Traits\RandomTrait;
|
||||
use App\Traits\TimeStampableTrait;
|
||||
use DateTime;
|
||||
use DateTimeInterface;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
@ -19,6 +20,8 @@ class Poll {
|
||||
|
||||
use RandomTrait;
|
||||
|
||||
use TimeStampableTrait;
|
||||
|
||||
/**
|
||||
* @ORM\Id()
|
||||
* @ORM\GeneratedValue()
|
||||
@ -46,11 +49,7 @@ class Poll {
|
||||
* @Serializer\Type("string")
|
||||
*/
|
||||
public $description;
|
||||
/**
|
||||
* @ORM\Column(type="datetime" , options={"default"="CURRENT_TIMESTAMP"})
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
public $creationDate;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="datetime")
|
||||
* @Serializer\Expose()
|
||||
@ -196,6 +195,7 @@ class Poll {
|
||||
public function __construct() {
|
||||
|
||||
$this->initiate();
|
||||
$this->setCreatedAt( new DateTime());
|
||||
$this->votes = new ArrayCollection();
|
||||
$this->stacksOfVotes = new ArrayCollection();
|
||||
$this->choices = new ArrayCollection();
|
||||
@ -208,7 +208,7 @@ class Poll {
|
||||
$this->choices = new ArrayCollection();
|
||||
$this->comments = new ArrayCollection();
|
||||
$this->setAdminKey( $this->generateRandomKey() );
|
||||
$this->setCreationDate( new DateTime() );
|
||||
$this->setCreatedAt( new DateTime() );
|
||||
$this->setExpiracyDate( $this->addDaysToDate(
|
||||
new DateTime(),
|
||||
$this->defaultExpiracyDaysFromNow
|
||||
@ -247,7 +247,7 @@ class Poll {
|
||||
return [
|
||||
'title' => $this->getTitle(),
|
||||
'description' => $this->getDescription(),
|
||||
'created_at' => $this->getCreationDate()->format( 'c' ),
|
||||
'created_at' => $this->getCreatedAt()->format( 'c' ),
|
||||
'expiracy_date' => $this->getExpiracyDate()->format( 'c' ),
|
||||
'votes_max' => $this->getVotesMax(),
|
||||
'choices_max' => $this->getChoicesMax(),
|
||||
@ -274,7 +274,8 @@ class Poll {
|
||||
$computedArray = [];
|
||||
$maxScore = 0;
|
||||
|
||||
$scoreInfos = ['score' => 0,
|
||||
$scoreInfos = [
|
||||
'score' => 0,
|
||||
'yes' => [
|
||||
'count' => 0,
|
||||
'people' => [],
|
||||
@ -286,7 +287,8 @@ class Poll {
|
||||
'no' => [
|
||||
'count' => 0,
|
||||
'people' => [],
|
||||
]];
|
||||
],
|
||||
];
|
||||
|
||||
// first, prefill all choices
|
||||
foreach ( $this->getChoices() as $choice ) {
|
||||
@ -376,12 +378,12 @@ class Poll {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCreationDate(): ?DateTimeInterface {
|
||||
return $this->creationDate;
|
||||
public function getCreatedAt(): ?DateTimeInterface {
|
||||
return $this->createdAt;
|
||||
}
|
||||
|
||||
public function setCreationDate( DateTimeInterface $creationDate ): self {
|
||||
$this->creationDate = $creationDate;
|
||||
public function setCreatedAt( DateTimeInterface $createdAt ): self {
|
||||
$this->createdAt = $createdAt;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Traits\TimeStampableTrait;
|
||||
use DateTime;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
@ -52,6 +53,7 @@ class StackOfVotes {
|
||||
private $ip;
|
||||
|
||||
public function __construct() {
|
||||
$this->setCreatedAt( new DateTime() );
|
||||
$this->votes = new ArrayCollection();
|
||||
}
|
||||
|
||||
@ -151,13 +153,11 @@ class StackOfVotes {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getIp(): ?string
|
||||
{
|
||||
public function getIp(): ?string {
|
||||
return $this->ip;
|
||||
}
|
||||
|
||||
public function setIp(string $ip): self
|
||||
{
|
||||
public function setIp( string $ip ): self {
|
||||
$this->ip = $ip;
|
||||
|
||||
return $this;
|
||||
|
@ -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 Vote {
|
||||
|
||||
use TimeStampableTrait;
|
||||
|
||||
/**
|
||||
* 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
|
||||
@ -20,12 +24,7 @@ class Vote {
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
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\JoinColumn(nullable=false)
|
||||
@ -54,7 +53,7 @@ class Vote {
|
||||
private $stacksOfVotes;
|
||||
|
||||
public function __construct() {
|
||||
$this->setCreationDate( new DateTime() );
|
||||
$this->setCreatedAt( new DateTime());
|
||||
}
|
||||
|
||||
public function display() {
|
||||
|
@ -13,7 +13,7 @@ class PollType extends AbstractType {
|
||||
->add( 'title' )
|
||||
->add( 'customUrl' )
|
||||
->add( 'description' )
|
||||
->add( 'creationDate' )
|
||||
->add( 'createdAt' )
|
||||
->add( 'expiracyDate' )
|
||||
->add( 'kind' )
|
||||
->add( 'allowedAnswers' )
|
||||
|
@ -28,9 +28,8 @@ trait TimeStampableTrait {
|
||||
|
||||
|
||||
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