mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
reformat src folder
This commit is contained in:
parent
56c8b0a5c4
commit
7f7265c851
@ -2,14 +2,9 @@
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Owner;
|
||||
use App\Entity\Poll;
|
||||
use App\Repository\PollRepository;
|
||||
use App\Service\MailService;
|
||||
use FOS\RestBundle\Controller\Annotations\Get;
|
||||
use FOS\RestBundle\Controller\Annotations\Route;
|
||||
use JMS\Serializer\Type\Exception\Exception;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
|
||||
|
||||
/**
|
||||
|
@ -5,8 +5,10 @@ namespace App\Controller;
|
||||
use App\Entity\Owner;
|
||||
use App\Entity\Poll;
|
||||
use JMS\Serializer\Type\Exception\Exception;
|
||||
use Swift_Mailer;
|
||||
use Swift_Message;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
|
||||
|
||||
/**
|
||||
* sending emails controller
|
||||
@ -18,16 +20,37 @@ class EmailsController extends AbstractController {
|
||||
|
||||
private $mail_service;
|
||||
|
||||
public function __construct( \Swift_Mailer $mailer ) {
|
||||
public function __construct( Swift_Mailer $mailer ) {
|
||||
$this->mail_service = $mailer;
|
||||
}
|
||||
|
||||
/**
|
||||
* send created polls to an owner
|
||||
*
|
||||
* @param Owner $owner
|
||||
*
|
||||
* @return int|void
|
||||
* @throws Exception
|
||||
* @throws TransportExceptionInterface
|
||||
*/
|
||||
public function sendOwnerPollsAction( Owner $owner ) {
|
||||
|
||||
$config = [
|
||||
'owner' => $owner,
|
||||
'title' => $this->getParameter( 'WEBSITE_NAME' ) . ' | Mes sondages',
|
||||
'email_template' => 'emails/owner-list.html.twig',
|
||||
];
|
||||
$this->sendMailWithVars( $config );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* generic way to send email with html template
|
||||
*
|
||||
* @param $config
|
||||
*
|
||||
* @throws \Symfony\Component\Mailer\Exception\TransportExceptionInterface
|
||||
* @throws TransportExceptionInterface
|
||||
*/
|
||||
public function sendMailWithVars( $config ) {
|
||||
|
||||
@ -72,33 +95,11 @@ class EmailsController extends AbstractController {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* send created polls to an owner
|
||||
*
|
||||
* @param Owner $owner
|
||||
*
|
||||
* @return int|void
|
||||
* @throws Exception
|
||||
* @throws \Symfony\Component\Mailer\Exception\TransportExceptionInterface
|
||||
*/
|
||||
public function sendOwnerPollsAction( Owner $owner ) {
|
||||
|
||||
$config = [
|
||||
'owner' => $owner,
|
||||
'title' => $this->getParameter( 'WEBSITE_NAME' ) . ' | Mes sondages',
|
||||
'email_template' => 'emails/owner-list.html.twig',
|
||||
];
|
||||
$this->sendMailWithVars( $config );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Owner $foundOwner
|
||||
* @param Poll|null $poll
|
||||
*
|
||||
* @throws \Symfony\Component\Mailer\Exception\TransportExceptionInterface
|
||||
* @throws TransportExceptionInterface
|
||||
*/
|
||||
public function sendCreationMailAction( Owner $foundOwner, Poll $poll = null ) {
|
||||
|
||||
@ -120,7 +121,7 @@ class EmailsController extends AbstractController {
|
||||
* @param $comment
|
||||
*
|
||||
* @return int
|
||||
* @throws \Symfony\Component\Mailer\Exception\TransportExceptionInterface
|
||||
* @throws TransportExceptionInterface
|
||||
*/
|
||||
public function sendCommentNotificationAction( Owner $owner, $comment ) {
|
||||
|
||||
@ -141,7 +142,7 @@ class EmailsController extends AbstractController {
|
||||
* @param $stackOfVotes
|
||||
*
|
||||
* @return int
|
||||
* @throws \Symfony\Component\Mailer\Exception\TransportExceptionInterface
|
||||
* @throws TransportExceptionInterface
|
||||
*/
|
||||
public function sendVoteNotificationAction( Owner $owner, $stackOfVotes ) {
|
||||
|
||||
|
@ -1,20 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
//use FOS\RestBundle\Controller\Annotations\Get;
|
||||
//use FOS\RestBundle\Controller\Annotations\Route;
|
||||
use App\Entity\Choice;
|
||||
use App\Entity\Comment;
|
||||
use App\Entity\StackOfVotes;
|
||||
use App\Entity\Vote;
|
||||
use App\Repository\PollRepository;
|
||||
use App\Service\MailService;
|
||||
use FOS\RestBundle\Controller\Annotations\Get;
|
||||
use FOS\RestBundle\Controller\Annotations\Route;
|
||||
use JMS\Serializer\Type\Exception\Exception;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use App\Entity\Owner;
|
||||
use App\Entity\Poll;
|
||||
use App\Entity\StackOfVotes;
|
||||
use App\Entity\Vote;
|
||||
use FOS\RestBundle\Controller\Annotations\Get;
|
||||
use FOS\RestBundle\Controller\Annotations\Route;
|
||||
use PDO;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
|
||||
/**
|
||||
* Class DefaultController
|
||||
@ -34,7 +33,7 @@ class MigrationController extends EmailsController {
|
||||
return new JsonResponse( [
|
||||
'error' => 'NOPE! veuillez vérifier votre fichier .env',
|
||||
] );
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// fetch old Database
|
||||
@ -45,13 +44,13 @@ class MigrationController extends EmailsController {
|
||||
$pollsBySlug = [];
|
||||
|
||||
|
||||
$pdo_options[ \PDO::ATTR_ERRMODE ] = \PDO::ERRMODE_EXCEPTION;
|
||||
$bdd = new \PDO( 'mysql:host=localhost;dbname=' . $this->getParameter( 'OLD_DATABASE_NAME' ),
|
||||
$pdo_options[ PDO::ATTR_ERRMODE ] = PDO::ERRMODE_EXCEPTION;
|
||||
$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' );
|
||||
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;
|
||||
|
||||
@ -88,7 +87,7 @@ class MigrationController extends EmailsController {
|
||||
$pollChoicesOrderedBySlug = [];
|
||||
$choicesCreated = [];
|
||||
|
||||
while ( $d = $res_slots->fetch( \PDO::FETCH_OBJ ) ) {
|
||||
while ( $d = $res_slots->fetch( PDO::FETCH_OBJ ) ) {
|
||||
|
||||
$debug .= " <br> ajout de slot, converti en choix de réponse : " . $d->poll_id . ' : ' . $d->moments;
|
||||
|
||||
@ -115,7 +114,7 @@ class MigrationController extends EmailsController {
|
||||
// get votes
|
||||
$stacksOfVote = [];
|
||||
$res_votes = $bdd->query( 'SELECT * FROM fd_vote' );
|
||||
while ( $d = $res_votes->fetch( \PDO::FETCH_OBJ ) ) {
|
||||
while ( $d = $res_votes->fetch( PDO::FETCH_OBJ ) ) {
|
||||
|
||||
$debug .= " <br> ajout de stack de vote : " . $d->name;
|
||||
$pollSlug = $d->poll_id;
|
||||
@ -126,13 +125,11 @@ class MigrationController extends EmailsController {
|
||||
$newOwner
|
||||
->setPseudo( $d->name )
|
||||
->setEmail( 'the_anonymous_email_from_@_migration_offramadate.org' )
|
||||
->setModifierToken($d->uniqId)
|
||||
;
|
||||
->setModifierToken( $d->uniqId );
|
||||
|
||||
$newStack->setPoll( $poll )
|
||||
->setOwner( $newOwner )
|
||||
->setPseudo($d->name)
|
||||
;
|
||||
->setPseudo( $d->name );
|
||||
|
||||
// each choice answer is encoded in a value :
|
||||
|
||||
@ -150,8 +147,7 @@ class MigrationController extends EmailsController {
|
||||
->setChoice( $choice )
|
||||
->setStacksOfVotes( $newStack )
|
||||
->setPoll( $poll )
|
||||
->setValue( $this->mapAnswerNumberToWord($vote_code))
|
||||
;
|
||||
->setValue( $this->mapAnswerNumberToWord( $vote_code ) );
|
||||
$newStack->addVote( $newVote );
|
||||
|
||||
$em->persist( $newVote );
|
||||
@ -169,7 +165,7 @@ class MigrationController extends EmailsController {
|
||||
|
||||
$comments = [];
|
||||
$res_comments = $bdd->query( 'SELECT * FROM fd_comment' );
|
||||
while ( $d = $res_comments->fetch( \PDO::FETCH_OBJ ) ) {
|
||||
while ( $d = $res_comments->fetch( PDO::FETCH_OBJ ) ) {
|
||||
|
||||
$debug .= " <br> ajout de commentaire : " . $d->name . ' ' . $d->comment;
|
||||
|
||||
@ -194,7 +190,8 @@ class MigrationController extends EmailsController {
|
||||
// failure notice
|
||||
$debug .= " <br> <br> ça c'est fait. ";
|
||||
|
||||
return $this->render('pages/migration.html.twig' , [
|
||||
return $this->render( 'pages/migration.html.twig',
|
||||
[
|
||||
"message" => "welcome to the framadate migration endpoint, it has yet to be done",
|
||||
"debug" => $debug,
|
||||
"OLD_DATABASE_NAME" => $this->getParameter( 'OLD_DATABASE_NAME' ),
|
||||
@ -205,13 +202,15 @@ class MigrationController extends EmailsController {
|
||||
'choices' => count( $choicesCreated ),
|
||||
'stacks_of_votes' => count( $stacksOfVote ),
|
||||
'votes' => count( $votes ),
|
||||
]
|
||||
],
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $numberToConvert
|
||||
* conversion of answer:
|
||||
* space character : no answer, 0 : no , 1 : maybe , 2 : yes
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function mapAnswerNumberToWord( $numberToConvert ) {
|
||||
@ -229,6 +228,7 @@ class MigrationController extends EmailsController {
|
||||
default:
|
||||
$word = 'no';
|
||||
}
|
||||
|
||||
return $word;
|
||||
}
|
||||
|
||||
|
@ -9,25 +9,24 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
|
||||
/**
|
||||
* @Route("/poll")
|
||||
*/
|
||||
class PollController extends AbstractController
|
||||
{
|
||||
class PollController extends AbstractController {
|
||||
/**
|
||||
* @Route("/", name="poll_index", methods={"GET"})
|
||||
*/
|
||||
public function index(PollRepository $pollRepository): Response
|
||||
{
|
||||
public function index( PollRepository $pollRepository ): Response {
|
||||
|
||||
$polls = $pollRepository->findAll();
|
||||
$titles = [];
|
||||
foreach ( $polls as $poll ) {
|
||||
$titles[] = $poll->getTitle();
|
||||
}
|
||||
return $this->render('poll/index.html.twig', [
|
||||
|
||||
return $this->render( 'poll/index.html.twig',
|
||||
[
|
||||
'count' => count( $polls ),
|
||||
'titles' => $titles,
|
||||
'polls' => $polls,
|
||||
@ -37,8 +36,7 @@ class PollController extends AbstractController
|
||||
/**
|
||||
* @Route("/new", name="poll_new", methods={"GET","POST"})
|
||||
*/
|
||||
public function new(Request $request): Response
|
||||
{
|
||||
public function new( Request $request ): Response {
|
||||
$poll = new Poll();
|
||||
$form = $this->createForm( PollType::class, $poll );
|
||||
$form->handleRequest( $request );
|
||||
@ -51,7 +49,8 @@ class PollController extends AbstractController
|
||||
return $this->redirectToRoute( 'poll_index' );
|
||||
}
|
||||
|
||||
return $this->render('poll/new.html.twig', [
|
||||
return $this->render( 'poll/new.html.twig',
|
||||
[
|
||||
'poll' => $poll,
|
||||
'form' => $form->createView(),
|
||||
] );
|
||||
@ -61,17 +60,18 @@ class PollController extends AbstractController
|
||||
* on cherche un sondage par son url personnalisée
|
||||
* @Route("/{id}", name="poll_show", methods={"GET"})
|
||||
*/
|
||||
public function show($id): Response
|
||||
{
|
||||
public function show( $id ): Response {
|
||||
$repository = $this->getDoctrine()->getRepository( Poll::class );
|
||||
$foundPoll = $repository->findOneByCustomUrl( $id );
|
||||
if ( ! $foundPoll ) {
|
||||
return $this->json( [
|
||||
'message' => $id.' : not found'
|
||||
], 404);
|
||||
'message' => $id . ' : not found',
|
||||
],
|
||||
404 );
|
||||
}
|
||||
|
||||
return $this->render('poll/show.html.twig', [
|
||||
return $this->render( 'poll/show.html.twig',
|
||||
[
|
||||
'poll' => $foundPoll,
|
||||
] );
|
||||
}
|
||||
@ -79,8 +79,7 @@ class PollController extends AbstractController
|
||||
/**
|
||||
* @Route("/{id}/edit", name="poll_edit", methods={"GET","POST"})
|
||||
*/
|
||||
public function edit(Request $request, Poll $poll): Response
|
||||
{
|
||||
public function edit( Request $request, Poll $poll ): Response {
|
||||
$form = $this->createForm( PollType::class, $poll );
|
||||
$form->handleRequest( $request );
|
||||
|
||||
@ -90,7 +89,8 @@ class PollController extends AbstractController
|
||||
return $this->redirectToRoute( 'poll_index' );
|
||||
}
|
||||
|
||||
return $this->render('poll/edit.html.twig', [
|
||||
return $this->render( 'poll/edit.html.twig',
|
||||
[
|
||||
'poll' => $poll,
|
||||
'form' => $form->createView(),
|
||||
] );
|
||||
@ -99,8 +99,7 @@ class PollController extends AbstractController
|
||||
/**
|
||||
* @Route("/{id}", name="poll_delete", methods={"DELETE"})
|
||||
*/
|
||||
public function delete(Request $request, Poll $poll): Response
|
||||
{
|
||||
public function delete( Request $request, Poll $poll ): Response {
|
||||
if ( $this->isCsrfTokenValid( 'delete' . $poll->getId(), $request->request->get( '_token' ) ) ) {
|
||||
$entityManager = $this->getDoctrine()->getManager();
|
||||
$entityManager->remove( $poll );
|
||||
|
@ -38,7 +38,9 @@ class CommentController extends EmailsController {
|
||||
) {
|
||||
$jsonResponse = $serializer->serialize( [
|
||||
'message' => 'here are your comments of the poll',
|
||||
'data' => $poll->getComments()], 'json');
|
||||
'data' => $poll->getComments(),
|
||||
],
|
||||
'json' );
|
||||
|
||||
$response = new Response( $jsonResponse );
|
||||
$response->headers->set( 'Content-Type', 'application/json' );
|
||||
|
@ -7,6 +7,11 @@ use App\Entity\Choice;
|
||||
use App\Entity\Owner;
|
||||
use App\Entity\Poll;
|
||||
use App\Repository\PollRepository;
|
||||
use FOS\RestBundle\Controller\Annotations\Delete;
|
||||
use FOS\RestBundle\Controller\Annotations\Get;
|
||||
use FOS\RestBundle\Controller\Annotations\Post;
|
||||
use FOS\RestBundle\Controller\Annotations\Put;
|
||||
use FOS\RestBundle\Controller\Annotations\Route;
|
||||
use JMS\Serializer\Exception\RuntimeException;
|
||||
use JMS\Serializer\SerializerBuilder;
|
||||
use JMS\Serializer\SerializerInterface;
|
||||
@ -14,13 +19,6 @@ use Swift_Mailer;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
|
||||
use FOS\RestBundle\Controller\Annotations\Get;
|
||||
use FOS\RestBundle\Controller\Annotations\Put;
|
||||
use FOS\RestBundle\Controller\Annotations\Delete;
|
||||
use FOS\RestBundle\Controller\Annotations\Post;
|
||||
use FOS\RestBundle\Controller\Annotations\Route;
|
||||
|
||||
/**
|
||||
* Class DefaultController
|
||||
@ -63,19 +61,6 @@ class PollController extends EmailsController {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* message when the poll is not found
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function notFoundPoll( $id ): Response {
|
||||
return $this->json( [
|
||||
'message' => $id . ' : poll not found',
|
||||
],
|
||||
404 );
|
||||
}
|
||||
|
||||
/**
|
||||
* get a poll config by its custom URL, we do not want polls to be reachable by their numeric id
|
||||
* @Get(
|
||||
@ -104,7 +89,6 @@ class PollController extends EmailsController {
|
||||
$stacks = $poll->getStacksOfVotes();
|
||||
|
||||
|
||||
|
||||
$pass = $poll->getPassword();
|
||||
|
||||
|
||||
@ -125,6 +109,19 @@ class PollController extends EmailsController {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* message when the poll is not found
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function notFoundPoll( $id ): Response {
|
||||
return $this->json( [
|
||||
'message' => $id . ' : poll not found',
|
||||
],
|
||||
404 );
|
||||
}
|
||||
|
||||
/**
|
||||
* get a poll config by its custom URL, we do not want polls to be reachable by their numeric id
|
||||
* @Get(
|
||||
|
@ -31,6 +31,7 @@ class VoteController extends EmailsController {
|
||||
* name = "new_vote_stack",
|
||||
* requirements = {"content"="\w+", "poll_id"="\d+"}
|
||||
* )
|
||||
*
|
||||
* @param SerializerInterface $serializer
|
||||
* @param Poll $poll
|
||||
* @param Request $request
|
||||
@ -139,6 +140,7 @@ class VoteController extends EmailsController {
|
||||
* name = "update_vote_stack",
|
||||
* requirements = { "id"="\d+"}
|
||||
* )
|
||||
*
|
||||
* @param SerializerInterface $serializer
|
||||
* @param StackOfVotes $id
|
||||
* @param $modifierToken
|
||||
@ -175,7 +177,8 @@ class VoteController extends EmailsController {
|
||||
'message' => 'ok',
|
||||
'modifier_token' => $voteStack->getOwner()->getModifierToken(),
|
||||
'vote_stack' => $voteStack,
|
||||
], 'json');
|
||||
],
|
||||
'json' );
|
||||
|
||||
$response = new Response( $jsonResponse );
|
||||
$response->headers->set( 'Content-Type', 'application/json' );
|
||||
@ -207,11 +210,13 @@ class VoteController extends EmailsController {
|
||||
|
||||
return $this->json( [
|
||||
'message' => 'boom! les ' . $length . ' votes du sondage ont été supprimés',
|
||||
],200 );
|
||||
],
|
||||
200 );
|
||||
} else {
|
||||
return $this->json( [
|
||||
'message' => 'le token d\'autorisation est invalide, vous ne pouvez pas modifier ce sondage'
|
||||
],403 );
|
||||
'message' => 'le token d\'autorisation est invalide, vous ne pouvez pas modifier ce sondage',
|
||||
],
|
||||
403 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,10 +6,8 @@ use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
|
||||
|
||||
class AppFixtures extends Fixture
|
||||
{
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
class AppFixtures extends Fixture {
|
||||
public function load( ObjectManager $manager ) {
|
||||
// $product = new Product();
|
||||
// $manager->persist($product);
|
||||
|
||||
|
@ -3,7 +3,6 @@
|
||||
namespace App\DataFixtures;
|
||||
|
||||
use App\Entity\Owner;
|
||||
use App\Entity\Poll;
|
||||
use App\Entity\StackOfVotes;
|
||||
use App\Entity\Vote;
|
||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||
@ -11,8 +10,7 @@ use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
|
||||
class VotesStacksFixtures extends Fixture implements DependentFixtureInterface {
|
||||
public function getDependencies()
|
||||
{
|
||||
public function getDependencies() {
|
||||
return [
|
||||
AppPollFixtures::class,
|
||||
];
|
||||
|
@ -95,6 +95,16 @@
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getUrl(): ?string {
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
public function setUrl( ?string $url ): self {
|
||||
$this->url = $url;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPoll(): ?Poll {
|
||||
return $this->poll;
|
||||
}
|
||||
@ -132,14 +142,4 @@
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getUrl(): ?string {
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
public function setUrl( ?string $url ): self {
|
||||
$this->url = $url;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use DateTime;
|
||||
use DateTimeInterface;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use JMS\Serializer\Annotation as Serializer;
|
||||
@ -51,6 +52,10 @@ class Comment {
|
||||
*/
|
||||
private $poll;
|
||||
|
||||
function __construct() {
|
||||
$this->setCreatedAt( new DateTime() );
|
||||
}
|
||||
|
||||
function display() {
|
||||
return [
|
||||
'id' => $this->getId(),
|
||||
@ -60,24 +65,10 @@ class Comment {
|
||||
];
|
||||
}
|
||||
|
||||
function __construct() {
|
||||
$this->setCreatedAt( new \DateTime() );
|
||||
}
|
||||
|
||||
public function getId(): ?int {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getOwner(): ?Owner {
|
||||
return $this->owner;
|
||||
}
|
||||
|
||||
public function setOwner( ?Owner $owner ): self {
|
||||
$this->owner = $owner;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getText(): ?string {
|
||||
return $this->text;
|
||||
}
|
||||
@ -88,6 +79,16 @@ class Comment {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOwner(): ?Owner {
|
||||
return $this->owner;
|
||||
}
|
||||
|
||||
public function setOwner( ?Owner $owner ): self {
|
||||
$this->owner = $owner;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCreatedAt(): ?DateTimeInterface {
|
||||
return $this->createdAt;
|
||||
}
|
||||
@ -108,13 +109,11 @@ class Comment {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPseudo(): ?string
|
||||
{
|
||||
public function getPseudo(): ?string {
|
||||
return $this->pseudo;
|
||||
}
|
||||
|
||||
public function setPseudo(string $pseudo): self
|
||||
{
|
||||
public function setPseudo( string $pseudo ): self {
|
||||
$this->pseudo = $pseudo;
|
||||
|
||||
return $this;
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use DateTime;
|
||||
use DateTimeInterface;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
@ -17,18 +19,18 @@ class Owner {
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
public $pseudo;
|
||||
/**
|
||||
* @ORM\Id()
|
||||
* @ORM\GeneratedValue()
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
private $id;
|
||||
/**
|
||||
* @ORM\Column(type="string", length=255)
|
||||
* @Serializer\Type("string")
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
public $email;
|
||||
/**
|
||||
* @ORM\Id()
|
||||
* @ORM\GeneratedValue()
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
private $id;
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Poll", mappedBy="owner",cascade={"persist","remove"},orphanRemoval=true)
|
||||
* @Serializer\Type("App\Entity\Poll")
|
||||
@ -62,7 +64,7 @@ class Owner {
|
||||
$this->polls = new ArrayCollection();
|
||||
$this->comments = new ArrayCollection();
|
||||
$this->stackOfVotes = new ArrayCollection();
|
||||
$this->setCreatedAt( new \DateTime() );
|
||||
$this->setCreatedAt( new DateTime() );
|
||||
$this->setModifierToken( uniqid() );
|
||||
}
|
||||
|
||||
@ -206,11 +208,11 @@ class Owner {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCreatedAt(): ?\DateTimeInterface {
|
||||
public function getCreatedAt(): ?DateTimeInterface {
|
||||
return $this->createdAt;
|
||||
}
|
||||
|
||||
public function setCreatedAt( \DateTimeInterface $createdAt ): self {
|
||||
public function setCreatedAt( DateTimeInterface $createdAt ): self {
|
||||
$this->createdAt = $createdAt;
|
||||
|
||||
return $this;
|
||||
|
@ -2,11 +2,14 @@
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use DateTime;
|
||||
use DateTimeInterface;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use ErrorException;
|
||||
use JMS\Serializer\Annotation as Serializer;
|
||||
use RangeException;
|
||||
|
||||
/**
|
||||
* @ORM\Entity(repositoryClass="App\Repository\PollRepository")
|
||||
@ -168,6 +171,12 @@ class Poll {
|
||||
* @Serializer\Type("ArrayCollection<App\Entity\Comment>")
|
||||
*/
|
||||
public $comments;
|
||||
/**
|
||||
* number of days from now for default expiracy date
|
||||
* @var int
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
public $defaultExpiracyDaysFromNow = 60;
|
||||
/**
|
||||
* vote restricted by a password in md5 format
|
||||
* @ORM\Column(type="string", length=255, nullable=true)
|
||||
@ -179,14 +188,122 @@ class Poll {
|
||||
* @Serializer\Type("string")
|
||||
*/
|
||||
private $adminKey;
|
||||
private $maxChoicesLimit = 25;
|
||||
|
||||
public function __construct() {
|
||||
|
||||
$this->initiate();
|
||||
}
|
||||
|
||||
private function initiate() {
|
||||
$this->votes = new ArrayCollection();
|
||||
$this->stacksOfVotes = new ArrayCollection();
|
||||
$this->choices = new ArrayCollection();
|
||||
$this->comments = new ArrayCollection();
|
||||
$this->setAdminKey( $this->generateAdminKey() );
|
||||
$this->setCreationDate( new DateTime() );
|
||||
$this->setExpiracyDate( $this->addDaysToDate(
|
||||
new DateTime(),
|
||||
$this->defaultExpiracyDaysFromNow
|
||||
) );
|
||||
$this->setAllowedAnswers( [ 'yes', 'maybe', 'no' ] );
|
||||
}
|
||||
|
||||
public function generateAdminKey() {
|
||||
$rand = random_int( PHP_INT_MIN, PHP_INT_MAX );
|
||||
|
||||
return str_shuffle( md5( $rand ) . $rand . $this->random_str() );
|
||||
}
|
||||
|
||||
/**
|
||||
* number of days from now for default expiracy date
|
||||
* @var int
|
||||
* @Serializer\Expose()
|
||||
* Generate a random string, using a cryptographically secure
|
||||
* pseudorandom number generator (random_int)
|
||||
*
|
||||
* This function uses type hints now (PHP 7+ only), but it was originally
|
||||
* written for PHP 5 as well.
|
||||
*
|
||||
* For PHP 7, random_int is a PHP core function
|
||||
* For PHP 5.x, depends on https://github.com/paragonie/random_compat
|
||||
*
|
||||
* @param int $length How many characters do we want?
|
||||
* @param string $keyspace A string of all possible characters
|
||||
* to select from
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public $defaultExpiracyDaysFromNow = 60;
|
||||
private $maxChoicesLimit = 25;
|
||||
public function random_str(
|
||||
int $length = 64,
|
||||
string $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
): string {
|
||||
if ( $length < 1 ) {
|
||||
throw new RangeException( "Length must be a positive integer" );
|
||||
}
|
||||
$pieces = [];
|
||||
$max = mb_strlen( $keyspace, '8bit' ) - 1;
|
||||
for ( $i = 0 ; $i < $length ; ++ $i ) {
|
||||
$pieces [] = $keyspace[ random_int( 0, $max ) ];
|
||||
}
|
||||
|
||||
return implode( '', $pieces );
|
||||
}
|
||||
|
||||
public function addDaysToDate( DateTime $date, int $days ) {
|
||||
$st = strtotime( $date->getTimestamp() );
|
||||
|
||||
return new DateTime( $st );
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
public function display() {
|
||||
|
||||
$computedAnswers = $this->computeAnswers();
|
||||
$displayedStackOfVotes = [];
|
||||
foreach ( $this->getStacksOfVotes() as $stack ) {
|
||||
$displayedStackOfVotes[] = $stack->display();
|
||||
}
|
||||
$displayedChoices = [];
|
||||
foreach ( $this->getChoices() as $choice ) {
|
||||
$displayedChoices[] = $choice->display();
|
||||
}
|
||||
$displayedComments = [];
|
||||
foreach ( $this->getComments() as $comment ) {
|
||||
$displayedComments[] = $comment->display();
|
||||
}
|
||||
|
||||
|
||||
return [
|
||||
'title' => $this->getTitle(),
|
||||
'creation_date' => $this->getCreationDate()->format( 'c' ),
|
||||
'expiracy_date' => $this->getExpiracyDate()->format( 'c' ),
|
||||
'votes_max' => $this->getVotesMax(),
|
||||
'choices_max' => $this->getChoicesMax(),
|
||||
'kind' => $this->getKind(),
|
||||
'allowed_answers' => $this->getAllowedAnswers(),
|
||||
'votes_allowed' => $this->getVotesAllowed(),
|
||||
'modification_policy' => $this->getModificationPolicy(),
|
||||
'hide_results' => $this->getHideResults(),
|
||||
'show_results_even_if_password' => $this->getShowResultEvenIfPasswords(),
|
||||
'owner' => [
|
||||
'pseudo' => $this->getOwner()->getPseudo(),
|
||||
]
|
||||
,
|
||||
'password_protected' => $this->getPassword() ? 'yes' : 'no',
|
||||
'max_score' => $computedAnswers[ 'max_score' ],
|
||||
'choices' => $displayedChoices,
|
||||
'choices_stats' => $computedAnswers[ 'answersWithStats' ],
|
||||
'stacks' => $displayedStackOfVotes,
|
||||
'comments' => $displayedComments,
|
||||
];
|
||||
}
|
||||
|
||||
public function computeAnswers() {
|
||||
// counts each number of answer for this choice
|
||||
@ -237,6 +354,7 @@ class Poll {
|
||||
foreach ( $computedArray as $choice_stat ) {
|
||||
$answersWithStats[] = $choice_stat;
|
||||
}
|
||||
|
||||
return [
|
||||
'answers' => $computedArray,
|
||||
'answersWithStats' => $answersWithStats,
|
||||
@ -244,142 +362,28 @@ 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();
|
||||
return $content;
|
||||
}
|
||||
public function display() {
|
||||
|
||||
$computedAnswers = $this->computeAnswers();
|
||||
$displayedStackOfVotes = [];
|
||||
foreach ( $this->getStacksOfVotes() as $stack ) {
|
||||
$displayedStackOfVotes[] = $stack->display();
|
||||
}
|
||||
$displayedChoices = [];
|
||||
foreach ( $this->getChoices() as $choice ) {
|
||||
$displayedChoices[] = $choice->display();
|
||||
}
|
||||
$displayedComments = [];
|
||||
foreach ( $this->getComments() as $comment ) {
|
||||
$displayedComments[] = $comment->display();
|
||||
public function getStacksOfVotes() {
|
||||
return $this->stacksOfVotes;
|
||||
}
|
||||
|
||||
public function setStacksOfVotes( ?StackOfVotes $stacksOfVotes ): self {
|
||||
$this->stacksOfVotes = $stacksOfVotes;
|
||||
|
||||
|
||||
return [
|
||||
'title' => $this->getTitle(),
|
||||
'creation_date' => $this->getCreationDate()->format('c'),
|
||||
'expiracy_date' => $this->getExpiracyDate()->format('c'),
|
||||
'votes_max' => $this->getVotesMax(),
|
||||
'choices_max' => $this->getChoicesMax(),
|
||||
'kind' => $this->getKind(),
|
||||
'allowed_answers' => $this->getAllowedAnswers(),
|
||||
'votes_allowed' => $this->getVotesAllowed(),
|
||||
'modification_policy' => $this->getModificationPolicy(),
|
||||
'hide_results' => $this->getHideResults(),
|
||||
'show_results_even_if_password' => $this->getShowResultEvenIfPasswords(),
|
||||
'owner' => [
|
||||
'pseudo' => $this->getOwner()->getPseudo()]
|
||||
,
|
||||
'password_protected' => $this->getPassword() ? 'yes' : 'no',
|
||||
'max_score' => $computedAnswers['max_score'],
|
||||
'choices' => $displayedChoices,
|
||||
'choices_stats' => $computedAnswers['answersWithStats'],
|
||||
'stacks' => $displayedStackOfVotes,
|
||||
'comments' => $displayedComments,
|
||||
];
|
||||
}
|
||||
|
||||
public function __construct() {
|
||||
|
||||
$this->initiate();
|
||||
}
|
||||
|
||||
|
||||
private function initiate() {
|
||||
$this->votes = new ArrayCollection();
|
||||
$this->stacksOfVotes = new ArrayCollection();
|
||||
$this->choices = new ArrayCollection();
|
||||
$this->comments = new ArrayCollection();
|
||||
$this->setAdminKey( $this->generateAdminKey() );
|
||||
$this->setCreationDate( new \DateTime() );
|
||||
$this->setExpiracyDate( $this->addDaysToDate(
|
||||
new \DateTime(),
|
||||
$this->defaultExpiracyDaysFromNow
|
||||
) );
|
||||
$this->setAllowedAnswers( [ 'yes', 'maybe', 'no' ] );
|
||||
}
|
||||
|
||||
|
||||
public function generateAdminKey() {
|
||||
$rand = random_int( PHP_INT_MIN, PHP_INT_MAX );
|
||||
|
||||
return str_shuffle( md5( $rand ) . $rand . $this->random_str() );
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a random string, using a cryptographically secure
|
||||
* pseudorandom number generator (random_int)
|
||||
*
|
||||
* This function uses type hints now (PHP 7+ only), but it was originally
|
||||
* written for PHP 5 as well.
|
||||
*
|
||||
* For PHP 7, random_int is a PHP core function
|
||||
* For PHP 5.x, depends on https://github.com/paragonie/random_compat
|
||||
*
|
||||
* @param int $length How many characters do we want?
|
||||
* @param string $keyspace A string of all possible characters
|
||||
* to select from
|
||||
*
|
||||
* @return string
|
||||
* @return Collection|Choice[]
|
||||
*/
|
||||
public function random_str(
|
||||
int $length = 64,
|
||||
string $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
): string {
|
||||
if ( $length < 1 ) {
|
||||
throw new \RangeException( "Length must be a positive integer" );
|
||||
}
|
||||
$pieces = [];
|
||||
$max = mb_strlen( $keyspace, '8bit' ) - 1;
|
||||
for ( $i = 0 ; $i < $length ; ++ $i ) {
|
||||
$pieces [] = $keyspace[ random_int( 0, $max ) ];
|
||||
public function getChoices(): Collection {
|
||||
return $this->choices;
|
||||
}
|
||||
|
||||
return implode( '', $pieces );
|
||||
}
|
||||
|
||||
public function findChoiceById( int $id ) {
|
||||
|
||||
$choices = $this->getChoices();
|
||||
$counter = 0;
|
||||
// there must be something cleaner than this in Doctrine ArrayCollection
|
||||
foreach ( $choices as $choice ) {
|
||||
$counter ++;
|
||||
if ( $counter > $this->maxChoicesLimit ) {
|
||||
throw new \ErrorException( "max number of choices reached for this poll" );
|
||||
}
|
||||
if ( $choice && $choice->getId() == $id ) {
|
||||
return $choice;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function addDaysToDate( \DateTime $date, int $days ) {
|
||||
$st = strtotime( $date->getTimestamp() );
|
||||
|
||||
return new \DateTime( $st );
|
||||
}
|
||||
|
||||
public function getId(): ?int {
|
||||
return $this->id;
|
||||
/**
|
||||
* @return Collection|Comment[]
|
||||
*/
|
||||
public function getComments(): Collection {
|
||||
return $this->comments;
|
||||
}
|
||||
|
||||
public function getTitle(): ?string {
|
||||
@ -402,46 +406,32 @@ class Poll {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getExpiracyDate(): ?DateTimeInterface {
|
||||
return $this->expiracyDate;
|
||||
}
|
||||
|
||||
public function setExpiracyDate( DateTimeInterface $expiracyDate ): self {
|
||||
$this->expiracyDate = $expiracyDate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOwner(): ?Owner {
|
||||
return $this->owner;
|
||||
public function getVotesMax() {
|
||||
return $this->votesMax;
|
||||
}
|
||||
|
||||
public function setOwner( ?Owner $owner ): self {
|
||||
$this->owner = $owner;
|
||||
public function setVotesMax( $votesMax ): self {
|
||||
$this->votesMax = $votesMax;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection|Vote[]
|
||||
*/
|
||||
public function getVotes(): Collection {
|
||||
return $this->votes;
|
||||
public function getChoicesMax() {
|
||||
return $this->choicesMax;
|
||||
}
|
||||
|
||||
|
||||
public function getAdminKey(): ?string {
|
||||
return $this->adminKey;
|
||||
}
|
||||
|
||||
public function setAdminKey( string $adminKey ): self {
|
||||
$this->adminKey = $adminKey;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDescription(): ?string {
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
public function setDescription( string $description ): self {
|
||||
$this->description = $description;
|
||||
public function setChoicesMax( $choicesMax ): self {
|
||||
$this->choicesMax = $choicesMax;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -456,22 +446,22 @@ class Poll {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCustomUrl(): ?string {
|
||||
return $this->customUrl;
|
||||
public function getAllowedAnswers(): ?array {
|
||||
return $this->allowedAnswers;
|
||||
}
|
||||
|
||||
public function setCustomUrl( string $customUrl ): self {
|
||||
$this->customUrl = $customUrl;
|
||||
public function setAllowedAnswers( array $allowedAnswers ): self {
|
||||
$this->allowedAnswers = $allowedAnswers;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPassword(): ?string {
|
||||
return $this->password;
|
||||
public function getVotesAllowed(): ?bool {
|
||||
return $this->votesAllowed;
|
||||
}
|
||||
|
||||
public function setPassword( string $password ): self {
|
||||
$this->password = md5( $password );
|
||||
public function setVotesAllowed( ?bool $votesAllowed ): self {
|
||||
$this->votesAllowed = $votesAllowed;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -486,26 +476,6 @@ class Poll {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMailOnComment(): ?bool {
|
||||
return $this->mailOnComment;
|
||||
}
|
||||
|
||||
public function setMailOnComment( bool $mailOnComment ): self {
|
||||
$this->mailOnComment = $mailOnComment;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMailOnVote(): ?bool {
|
||||
return $this->mailOnVote;
|
||||
}
|
||||
|
||||
public function setMailOnVote( bool $mailOnVote ): self {
|
||||
$this->mailOnVote = $mailOnVote;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getHideResults(): ?bool {
|
||||
return $this->hideResults;
|
||||
}
|
||||
@ -526,12 +496,104 @@ class Poll {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOwner(): ?Owner {
|
||||
return $this->owner;
|
||||
}
|
||||
|
||||
public function setOwner( ?Owner $owner ): self {
|
||||
$this->owner = $owner;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPassword(): ?string {
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
public function setPassword( string $password ): self {
|
||||
$this->password = md5( $password );
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAdminKey(): ?string {
|
||||
return $this->adminKey;
|
||||
}
|
||||
|
||||
public function setAdminKey( string $adminKey ): self {
|
||||
$this->adminKey = $adminKey;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getId(): ?int {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function findChoiceById( int $id ) {
|
||||
|
||||
$choices = $this->getChoices();
|
||||
$counter = 0;
|
||||
// there must be something cleaner than this in Doctrine ArrayCollection
|
||||
foreach ( $choices as $choice ) {
|
||||
$counter ++;
|
||||
if ( $counter > $this->maxChoicesLimit ) {
|
||||
throw new ErrorException( "max number of choices reached for this poll" );
|
||||
}
|
||||
if ( $choice && $choice->getId() == $id ) {
|
||||
return $choice;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection|Comment[]
|
||||
* @return Collection|Vote[]
|
||||
*/
|
||||
public function getComments(): Collection {
|
||||
return $this->comments;
|
||||
public function getVotes(): Collection {
|
||||
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;
|
||||
}
|
||||
|
||||
public function setCustomUrl( string $customUrl ): self {
|
||||
$this->customUrl = $customUrl;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMailOnComment(): ?bool {
|
||||
return $this->mailOnComment;
|
||||
}
|
||||
|
||||
public function setMailOnComment( bool $mailOnComment ): self {
|
||||
$this->mailOnComment = $mailOnComment;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMailOnVote(): ?bool {
|
||||
return $this->mailOnVote;
|
||||
}
|
||||
|
||||
public function setMailOnVote( bool $mailOnVote ): self {
|
||||
$this->mailOnVote = $mailOnVote;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addComment( Comment $comment ): self {
|
||||
@ -555,17 +617,6 @@ class Poll {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getStacksOfVotes() {
|
||||
return $this->stacksOfVotes;
|
||||
}
|
||||
|
||||
public function setStacksOfVotes( ?StackOfVotes $stacksOfVotes ): self {
|
||||
$this->stacksOfVotes = $stacksOfVotes;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function addStackOfVote( StackOfVotes $stackOfVote ): self {
|
||||
if ( ! $this->stacksOfVotes->contains( $stackOfVote ) ) {
|
||||
$this->stacksOfVotes[] = $stackOfVote;
|
||||
@ -587,10 +638,6 @@ class Poll {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getExpiracyDate(): ?\DateTimeInterface {
|
||||
return $this->expiracyDate;
|
||||
}
|
||||
|
||||
public function addVote( Vote $vote ): self {
|
||||
if ( ! $this->votes->contains( $vote ) ) {
|
||||
$this->votes[] = $vote;
|
||||
@ -612,13 +659,6 @@ class Poll {
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection|Choice[]
|
||||
*/
|
||||
public function getChoices(): Collection {
|
||||
return $this->choices;
|
||||
}
|
||||
|
||||
public function addTextChoiceArray( array $choiceTextArray ): self {
|
||||
foreach ( $choiceTextArray as $text ) {
|
||||
$newChoice = new Choice();
|
||||
@ -629,13 +669,17 @@ class Poll {
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function getAllowedAnswers(): ?array {
|
||||
return $this->allowedAnswers;
|
||||
public function addChoice( Choice $choice ): self {
|
||||
if ( ! is_null( $this->choices ) ) {
|
||||
if ( ! $this->choices->contains( $choice ) ) {
|
||||
$this->choices[] = $choice;
|
||||
$choice->setPoll( $this );
|
||||
}
|
||||
} else {
|
||||
$this->choices[] = $choice;
|
||||
$choice->setPoll( $this );
|
||||
}
|
||||
|
||||
public function setAllowedAnswers( array $allowedAnswers ): self {
|
||||
$this->allowedAnswers = $allowedAnswers;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -661,21 +705,6 @@ class Poll {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addChoice( Choice $choice ): self {
|
||||
if ( ! is_null( $this->choices ) ) {
|
||||
if ( ! $this->choices->contains( $choice ) ) {
|
||||
$this->choices[] = $choice;
|
||||
$choice->setPoll( $this );
|
||||
}
|
||||
} else {
|
||||
$this->choices[] = $choice;
|
||||
$choice->setPoll( $this );
|
||||
}
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeChoice( Choice $choice ): self {
|
||||
if ( $this->choices->contains( $choice ) ) {
|
||||
$this->choices->removeElement( $choice );
|
||||
@ -688,36 +717,6 @@ class Poll {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getVotesAllowed(): ?bool {
|
||||
return $this->votesAllowed;
|
||||
}
|
||||
|
||||
public function setVotesAllowed( ?bool $votesAllowed ): self {
|
||||
$this->votesAllowed = $votesAllowed;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getVotesMax() {
|
||||
return $this->votesMax;
|
||||
}
|
||||
|
||||
public function setVotesMax( $votesMax ): self {
|
||||
$this->votesMax = $votesMax;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getChoicesMax() {
|
||||
return $this->choicesMax;
|
||||
}
|
||||
|
||||
public function setChoicesMax( $choicesMax ): self {
|
||||
$this->choicesMax = $choicesMax;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCommentsAllowed(): ?bool {
|
||||
return $this->commentsAllowed;
|
||||
}
|
||||
|
@ -18,12 +18,6 @@ class StackOfVotes {
|
||||
|
||||
use TimeStampableTrait;
|
||||
|
||||
/**
|
||||
* @ORM\Id()
|
||||
* @ORM\GeneratedValue()
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
private $id;
|
||||
/**
|
||||
* @ORM\Column(type="string", length=255)
|
||||
* @Serializer\Type("string")
|
||||
@ -35,6 +29,12 @@ class StackOfVotes {
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
public $votes;
|
||||
/**
|
||||
* @ORM\Id()
|
||||
* @ORM\GeneratedValue()
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
private $id;
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="App\Entity\Poll", inversedBy="stacksOfVotes", cascade={"persist"})
|
||||
*/
|
||||
@ -46,6 +46,9 @@ class StackOfVotes {
|
||||
*/
|
||||
private $owner;
|
||||
|
||||
public function __construct() {
|
||||
$this->votes = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function display() {
|
||||
$votes = $this->getVotes();
|
||||
@ -72,6 +75,23 @@ class StackOfVotes {
|
||||
return $tab;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection|poll[]
|
||||
*/
|
||||
public function getVotes(): Collection {
|
||||
return $this->votes;
|
||||
}
|
||||
|
||||
public function getPseudo(): ?string {
|
||||
return $this->pseudo;
|
||||
}
|
||||
|
||||
public function setPseudo( ?string $pseudo ): self {
|
||||
$this->pseudo = $pseudo;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\PrePersist
|
||||
*/
|
||||
@ -79,21 +99,20 @@ class StackOfVotes {
|
||||
$this->setPseudo( $this->getOwner()->getPseudo() );
|
||||
}
|
||||
|
||||
public function __construct() {
|
||||
$this->votes = new ArrayCollection();
|
||||
public function getOwner(): ?Owner {
|
||||
return $this->owner;
|
||||
}
|
||||
|
||||
public function setOwner( ?Owner $owner ): self {
|
||||
$this->owner = $owner;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getId(): ?int {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection|poll[]
|
||||
*/
|
||||
public function getVotes(): Collection {
|
||||
return $this->votes;
|
||||
}
|
||||
|
||||
public function addVote( Vote $vote ): self {
|
||||
if ( ! $this->votes->contains( $vote ) ) {
|
||||
$vote->setPoll( $this->getPoll() );
|
||||
@ -105,6 +124,16 @@ class StackOfVotes {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPoll(): ?Poll {
|
||||
return $this->poll;
|
||||
}
|
||||
|
||||
public function setPoll( ?Poll $poll ): self {
|
||||
$this->poll = $poll;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeVote( Vote $vote ): self {
|
||||
if ( $this->votes->contains( $vote ) ) {
|
||||
$this->votes->removeElement( $vote );
|
||||
@ -116,34 +145,4 @@ class StackOfVotes {
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPseudo(): ?string {
|
||||
return $this->pseudo;
|
||||
}
|
||||
|
||||
public function setPseudo( ?string $pseudo ): self {
|
||||
$this->pseudo = $pseudo;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOwner(): ?Owner {
|
||||
return $this->owner;
|
||||
}
|
||||
|
||||
public function setOwner( ?Owner $owner ): self {
|
||||
$this->owner = $owner;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPoll(): ?Poll {
|
||||
return $this->poll;
|
||||
}
|
||||
|
||||
public function setPoll( ?Poll $poll ): self {
|
||||
$this->poll = $poll;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use DateTime;
|
||||
use DateTimeInterface;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use JMS\Serializer\Annotation as Serializer;
|
||||
@ -52,6 +53,10 @@ class Vote {
|
||||
*/
|
||||
private $stacksOfVotes;
|
||||
|
||||
public function __construct() {
|
||||
$this->setCreationDate( new DateTime() );
|
||||
}
|
||||
|
||||
public function display() {
|
||||
$value = $this->getValue();
|
||||
if ( ! $value ) {
|
||||
@ -67,27 +72,20 @@ class Vote {
|
||||
}
|
||||
}
|
||||
|
||||
public function __construct() {
|
||||
$this->setCreationDate( new \DateTime() );
|
||||
public function getValue(): ?string {
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public function setValue( ?string $value ): self {
|
||||
$this->value = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getId(): ?int {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getPoll(): ?Poll {
|
||||
return $this->poll;
|
||||
}
|
||||
|
||||
public function setPoll( ?Poll $poll ): self {
|
||||
$this->poll = $poll;
|
||||
if ( $poll ) {
|
||||
$poll->addVote( $this );
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getChoice(): ?Choice {
|
||||
return $this->choice;
|
||||
}
|
||||
@ -98,12 +96,15 @@ class Vote {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getValue(): ?string {
|
||||
return $this->value;
|
||||
public function getPoll(): ?Poll {
|
||||
return $this->poll;
|
||||
}
|
||||
|
||||
public function setValue( ?string $value ): self {
|
||||
$this->value = $value;
|
||||
public function setPoll( ?Poll $poll ): self {
|
||||
$this->poll = $poll;
|
||||
if ( $poll ) {
|
||||
$poll->addVote( $this );
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -7,10 +7,8 @@ use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class PollType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
class PollType extends AbstractType {
|
||||
public function buildForm( FormBuilderInterface $builder, array $options ) {
|
||||
$builder
|
||||
->add( 'title' )
|
||||
->add( 'customUrl' )
|
||||
@ -26,12 +24,10 @@ class PollType extends AbstractType
|
||||
->add( 'showResultEvenIfPasswords' )
|
||||
->add( 'password' )
|
||||
->add( 'adminKey' )
|
||||
->add('owner')
|
||||
;
|
||||
->add( 'owner' );
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
public function configureOptions( OptionsResolver $resolver ) {
|
||||
$resolver->setDefaults( [
|
||||
'data_class' => Poll::class,
|
||||
] );
|
||||
|
@ -6,32 +6,30 @@ use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
|
||||
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
|
||||
use function dirname;
|
||||
|
||||
class Kernel extends BaseKernel
|
||||
{
|
||||
class Kernel extends BaseKernel {
|
||||
use MicroKernelTrait;
|
||||
|
||||
protected function configureContainer(ContainerConfigurator $container): void
|
||||
{
|
||||
protected function configureContainer( ContainerConfigurator $container ): void {
|
||||
$container->import( '../config/{packages}/*.yaml' );
|
||||
$container->import( '../config/{packages}/' . $this->environment . '/*.yaml' );
|
||||
|
||||
if (is_file(\dirname(__DIR__).'/config/services.yaml')) {
|
||||
if ( is_file( dirname( __DIR__ ) . '/config/services.yaml' ) ) {
|
||||
$container->import( '../config/services.yaml' );
|
||||
$container->import( '../config/{services}_' . $this->environment . '.yaml' );
|
||||
} elseif (is_file($path = \dirname(__DIR__).'/config/services.php')) {
|
||||
} elseif ( is_file( $path = dirname( __DIR__ ) . '/config/services.php' ) ) {
|
||||
( require $path )( $container->withPath( $path ), $this );
|
||||
}
|
||||
}
|
||||
|
||||
protected function configureRoutes(RoutingConfigurator $routes): void
|
||||
{
|
||||
protected function configureRoutes( RoutingConfigurator $routes ): void {
|
||||
$routes->import( '../config/{routes}/' . $this->environment . '/*.yaml' );
|
||||
$routes->import( '../config/{routes}/*.yaml' );
|
||||
|
||||
if (is_file(\dirname(__DIR__).'/config/routes.yaml')) {
|
||||
if ( is_file( dirname( __DIR__ ) . '/config/routes.yaml' ) ) {
|
||||
$routes->import( '../config/routes.yaml' );
|
||||
} elseif (is_file($path = \dirname(__DIR__).'/config/routes.php')) {
|
||||
} elseif ( is_file( $path = dirname( __DIR__ ) . '/config/routes.php' ) ) {
|
||||
( require $path )( $routes->withPath( $path ), $this );
|
||||
}
|
||||
}
|
||||
|
@ -12,10 +12,8 @@ use Doctrine\Common\Persistence\ManagerRegistry;
|
||||
* @method Choice[] findAll()
|
||||
* @method Choice[] findBy( array $criteria, array $orderBy = null, $limit = null, $offset = null )
|
||||
*/
|
||||
class ChoiceRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
class ChoiceRepository extends ServiceEntityRepository {
|
||||
public function __construct( ManagerRegistry $registry ) {
|
||||
parent::__construct( $registry, Choice::class );
|
||||
}
|
||||
|
||||
|
@ -12,10 +12,8 @@ use Doctrine\Common\Persistence\ManagerRegistry;
|
||||
* @method Comment[] findAll()
|
||||
* @method Comment[] findBy( array $criteria, array $orderBy = null, $limit = null, $offset = null )
|
||||
*/
|
||||
class CommentRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
class CommentRepository extends ServiceEntityRepository {
|
||||
public function __construct( ManagerRegistry $registry ) {
|
||||
parent::__construct( $registry, Comment::class );
|
||||
}
|
||||
|
||||
|
@ -12,10 +12,8 @@ use Doctrine\Common\Persistence\ManagerRegistry;
|
||||
* @method Owner[] findAll()
|
||||
* @method Owner[] findBy( array $criteria, array $orderBy = null, $limit = null, $offset = null )
|
||||
*/
|
||||
class OwnerRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
class OwnerRepository extends ServiceEntityRepository {
|
||||
public function __construct( ManagerRegistry $registry ) {
|
||||
parent::__construct( $registry, Owner::class );
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,6 @@ namespace App\Repository;
|
||||
use App\Entity\Poll;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use MongoDB\Driver\Manager;
|
||||
|
||||
/**
|
||||
* @method Poll|null find( $id, $lockMode = null, $lockVersion = null )
|
||||
@ -13,11 +12,10 @@ use MongoDB\Driver\Manager;
|
||||
* @method Poll[] findAll()
|
||||
* @method Poll[] findBy( array $criteria, array $orderBy = null, $limit = null, $offset = null )
|
||||
*/
|
||||
class PollRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry
|
||||
$registry)
|
||||
{
|
||||
class PollRepository extends ServiceEntityRepository {
|
||||
public function __construct(
|
||||
ManagerRegistry $registry
|
||||
) {
|
||||
parent::__construct( $registry, Poll::class );
|
||||
}
|
||||
|
||||
|
@ -12,10 +12,8 @@ use Doctrine\Common\Persistence\ManagerRegistry;
|
||||
* @method StackOfVotes[] findAll()
|
||||
* @method StackOfVotes[] findBy( array $criteria, array $orderBy = null, $limit = null, $offset = null )
|
||||
*/
|
||||
class StackOfVotesRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
class StackOfVotesRepository extends ServiceEntityRepository {
|
||||
public function __construct( ManagerRegistry $registry ) {
|
||||
parent::__construct( $registry, StackOfVotes::class );
|
||||
}
|
||||
|
||||
|
@ -12,10 +12,8 @@ use Doctrine\Common\Persistence\ManagerRegistry;
|
||||
* @method Vote[] findAll()
|
||||
* @method Vote[] findBy( array $criteria, array $orderBy = null, $limit = null, $offset = null )
|
||||
*/
|
||||
class VoteRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
class VoteRepository extends ServiceEntityRepository {
|
||||
public function __construct( ManagerRegistry $registry ) {
|
||||
parent::__construct( $registry, Vote::class );
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@ use Exception;
|
||||
use Swift_Mailer;
|
||||
use Swift_Message;
|
||||
use Swift_SmtpTransport;
|
||||
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
|
||||
|
||||
class MailService {
|
||||
|
||||
@ -49,7 +50,7 @@ class MailService {
|
||||
* @param Owner $foundOwner
|
||||
* @param Poll|null $poll
|
||||
*
|
||||
* @throws \Symfony\Component\Mailer\Exception\TransportExceptionInterface
|
||||
* @throws TransportExceptionInterface
|
||||
*/
|
||||
public function sendCreationMailAction( Owner $foundOwner, Poll $poll = null ) {
|
||||
|
||||
@ -66,74 +67,12 @@ class MailService {
|
||||
return $this->sendMailWithVars( $config );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* anti spam , limit to every minute TODO
|
||||
*
|
||||
* @param Owner $owner
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function antispamCheck( Owner $owner ) {
|
||||
|
||||
// $lastSend = $admin_user->getRequestedPollsDate();
|
||||
// $now = new \DateTime();
|
||||
|
||||
// if ( date_diff( $lastSend, $now ) < 60 ) {
|
||||
// // too soon!
|
||||
// die( 'too soon!' );
|
||||
// }
|
||||
// $admin_user->setRequestedPollsDate( $now );
|
||||
// $em->persist( $admin_user );
|
||||
// $em->flush();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* send created polls to an owner
|
||||
*
|
||||
* @param Owner $owner
|
||||
*
|
||||
* @return int|void
|
||||
* @throws Exception
|
||||
* @throws \Symfony\Component\Mailer\Exception\TransportExceptionInterface
|
||||
*/
|
||||
public function sendOwnerPollsAction( Owner $owner ) {
|
||||
|
||||
$config = [
|
||||
'owner' => $owner,
|
||||
'title' => 'Framadate | Mes sondages',
|
||||
'email_template' => 'emails/owner-list.html.twig',
|
||||
];
|
||||
$this->sendMailWithVars( $config );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Comment $comment
|
||||
*
|
||||
* @throws \Symfony\Component\Mailer\Exception\TransportExceptionInterface
|
||||
*/
|
||||
public function sendCommentNotification( Comment $comment ) {
|
||||
|
||||
$config = [
|
||||
'comment' => $comment,
|
||||
'owner' => $comment->getOwner(),
|
||||
'title' => 'Framadate | commentaire de ' . $comment->getOwner()->getPseudo() . ' _ sondage ' . $comment->getPoll()->getTitle(),
|
||||
'email_template' => 'emails/comment-notification.html.twig',
|
||||
];
|
||||
|
||||
$this->sendMailWithVars( $config );
|
||||
}
|
||||
|
||||
/**
|
||||
* generic way to send email with html template
|
||||
*
|
||||
* @param $config
|
||||
*
|
||||
* @throws \Symfony\Component\Mailer\Exception\TransportExceptionInterface
|
||||
* @throws TransportExceptionInterface
|
||||
*/
|
||||
public function sendMailWithVars( $config ) {
|
||||
|
||||
@ -209,4 +148,64 @@ class MailService {
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* anti spam , limit to every minute TODO
|
||||
*
|
||||
* @param Owner $owner
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function antispamCheck( Owner $owner ) {
|
||||
|
||||
// $lastSend = $admin_user->getRequestedPollsDate();
|
||||
// $now = new \DateTime();
|
||||
|
||||
// if ( date_diff( $lastSend, $now ) < 60 ) {
|
||||
// // too soon!
|
||||
// die( 'too soon!' );
|
||||
// }
|
||||
// $admin_user->setRequestedPollsDate( $now );
|
||||
// $em->persist( $admin_user );
|
||||
// $em->flush();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* send created polls to an owner
|
||||
*
|
||||
* @param Owner $owner
|
||||
*
|
||||
* @return int|void
|
||||
* @throws Exception
|
||||
* @throws TransportExceptionInterface
|
||||
*/
|
||||
public function sendOwnerPollsAction( Owner $owner ) {
|
||||
|
||||
$config = [
|
||||
'owner' => $owner,
|
||||
'title' => 'Framadate | Mes sondages',
|
||||
'email_template' => 'emails/owner-list.html.twig',
|
||||
];
|
||||
$this->sendMailWithVars( $config );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Comment $comment
|
||||
*
|
||||
* @throws TransportExceptionInterface
|
||||
*/
|
||||
public function sendCommentNotification( Comment $comment ) {
|
||||
|
||||
$config = [
|
||||
'comment' => $comment,
|
||||
'owner' => $comment->getOwner(),
|
||||
'title' => 'Framadate | commentaire de ' . $comment->getOwner()->getPseudo() . ' _ sondage ' . $comment->getPoll()->getTitle(),
|
||||
'email_template' => 'emails/comment-notification.html.twig',
|
||||
];
|
||||
|
||||
$this->sendMailWithVars( $config );
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ namespace App\Traits;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
|
||||
trait TimeStampableTrait {
|
||||
/**
|
||||
@ -15,9 +14,6 @@ trait TimeStampableTrait {
|
||||
public function getCreatedAt(): ?DateTimeInterface {
|
||||
return $this->createdAt;
|
||||
}
|
||||
public function getCreatedAtAsString(): string {
|
||||
return $this->createdAt->format('c');
|
||||
}
|
||||
|
||||
public function setCreatedAt( DateTimeInterface $createdAt ): self {
|
||||
$this->createdAt = $createdAt;
|
||||
@ -25,4 +21,8 @@ trait TimeStampableTrait {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCreatedAtAsString(): string {
|
||||
return $this->createdAt->format( 'c' );
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user