1
0
mirror of https://framagit.org/tykayn/date-poll-api synced 2023-08-25 08:23:11 +02:00

Compare commits

...

6 Commits

15 changed files with 607 additions and 503 deletions

View File

@ -0,0 +1,8 @@
# config/packages/dev/mailer.yaml
framework:
mailer:
envelope:
sender: 'noreply@tktest.com'
recipients: ['tykayn@pm.me']
headers:
from: 'dev framadate funky <noreply@tktest.com>'

View File

@ -1,6 +1,6 @@
# see https://symfony.com/doc/current/reference/configuration/framework.html # see https://symfony.com/doc/current/reference/configuration/framework.html
framework: framework:
trusted_hosts: ['localhost:4200', 'localhost', 'tktest.lan', 'framadate-api.cipherbliss.com'] trusted_hosts: ['localhost:4200', 'localhost', 'tktest.lan', '127.0.0.1', 'framadate-api.cipherbliss.com']
secret: '%env(APP_SECRET)%' secret: '%env(APP_SECRET)%'
#csrf_protection: true #csrf_protection: true
#http_method_override: true #http_method_override: true

View File

@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20210518212646 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE poll ADD is_zero_knowledge TINYINT(1) DEFAULT NULL');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE poll DROP is_zero_knowledge');
}
}

View File

@ -9,7 +9,6 @@ use Swift_Mailer;
use Swift_Message; use Swift_Message;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Mailer\Exception\TransportExceptionInterface; use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
/** /**
* sending emails controller * sending emails controller
* *
@ -83,7 +82,7 @@ class EmailsController extends AbstractController {
$message = ( new Swift_Message( $config[ 'title' ] ) ) $message = ( new Swift_Message( $config[ 'title' ] ) )
->setContentType( "text/html" ) ->setContentType( "text/html" )
->setCharset( 'UTF-8' ) ->setCharset( 'UTF-8' )
->setFrom( [ 'ne-pas-repondre@framadate-api.cipherbliss.com' ] ) ->setFrom( [ 'ne-pas-repondre@framadate-api.cipherbliss.com'] )
->setTo( [ $config[ 'owner' ]->getEmail() ] ) ->setTo( [ $config[ 'owner' ]->getEmail() ] )
->setBody( $htmlbody, 'text/html' ); ->setBody( $htmlbody, 'text/html' );

View File

@ -97,10 +97,10 @@ class MigrationController extends EmailsController {
$moments = explode( ',', $d->moments ); $moments = explode( ',', $d->moments );
foreach ( $moments as $moment ) { foreach ( $moments as $moment ) {
$newChoice = new Choice(); $newChoice = new Choice();
$dateOfDay = date_create( strtotime( $d->title ) );
$newChoice $newChoice
->setPoll( $poll ) ->setPoll( $poll )
->setDateTime( date_create( strtotime( $d->title ) ) ) ->setName( $dateOfDay->format('y-m-d'). ' >>> ' . $moment );
->setName( $moment );
$pollChoicesOrderedBySlug[ $pollSlug ][] = $newChoice; $pollChoicesOrderedBySlug[ $pollSlug ][] = $newChoice;
$poll->addChoice( $newChoice ); $poll->addChoice( $newChoice );

View File

@ -240,9 +240,17 @@ class PollController extends EmailsController {
$data = $request->getContent(); $data = $request->getContent();
$data = json_decode( $data, true ); $data = json_decode( $data, true );
// search for existing custom url, which must be unique
$custom_url = $data[ 'custom_url' ];
$repository = $this->getDoctrine()->getRepository( Poll::class );
$poll = $repository->findOneByCustomUrl( $custom_url );
if ( $poll ) {
throw new \JsonException( 'NOPE, ce sondage existe déjà: ' . $custom_url );
}
$newpoll = new Poll(); $newpoll = new Poll();
$newpoll $newpoll
->setModificationPolicy( $data[ 'modification_policy' ] ) ->setModificationPolicy( isset( $data[ 'modification_policy' ] ) ? $data[ 'modification_policy' ] : 'everybody' )
->setTitle( $data[ 'title' ] ) ->setTitle( $data[ 'title' ] )
->setKind( $data[ 'kind' ] ) ->setKind( $data[ 'kind' ] )
->setCustomUrl( $data[ 'custom_url' ] ); ->setCustomUrl( $data[ 'custom_url' ] );
@ -294,17 +302,18 @@ class PollController extends EmailsController {
if ( $data[ 'password' ] ) { if ( $data[ 'password' ] ) {
$newpoll->setPassword( $data[ 'password' ] ); $newpoll->setPassword( $data[ 'password' ] );
} }
// manage choices
// text kind of answers, dates are below // text kind of answers, dates are below
if ( $data[ 'kind' ] == 'text' ) { if ( $data[ 'kind' ] == 'text' ) {
// manage choices
$choices = $data[ 'dateChoices' ]; $choices = $data[ 'choices' ];
foreach ( $choices as $c ) { foreach ( $choices as $c ) {
$newChoice = new Choice(); $newChoice = new Choice();
$newChoice $newChoice
->setPoll( $newpoll ) ->setPoll( $newpoll )
->setName( $c[ 'literal' ] ); ->setName( $c[ 'literal' ] );
$em->persist( $newChoice ); $em->persist( $newChoice );
$newpoll->addChoice( $newChoice );
} }
} // date kind of poll } // date kind of poll
elseif ( $data[ 'kind' ] == 'date' ) { elseif ( $data[ 'kind' ] == 'date' ) {
@ -316,7 +325,7 @@ class PollController extends EmailsController {
foreach ( $choices as $c ) { foreach ( $choices as $c ) {
$currentDate = $c[ 'literal' ]; $currentDate = $c[ 'literal' ];
$timeSlicesOfThisChoice = $c[ 'timeList' ]; $timeSlicesOfThisChoice = $c[ 'timeSlices' ];
foreach ( $timeSlicesOfThisChoice as $t ) { foreach ( $timeSlicesOfThisChoice as $t ) {
$newChoice = new Choice(); $newChoice = new Choice();
@ -324,14 +333,16 @@ class PollController extends EmailsController {
->setPoll( $newpoll ) ->setPoll( $newpoll )
->setName( $currentDate . ' >>> ' . $t[ 'literal' ] ); ->setName( $currentDate . ' >>> ' . $t[ 'literal' ] );
$em->persist( $newChoice ); $em->persist( $newChoice );
$newpoll->addChoice( $newChoice );
} }
} }
} else { } else {
// all choices will be having the same time slices from timeSlices // all choices will be having the same time slices from timeSlices
$timeSlicesForAllChoices = $data[ 'timeSlices' ]; $timeSlicesForAllChoices = $data[ 'timeSlices' ];
foreach ( $choices as $c ) { foreach ( $choices as $c ) {
$currentDate = $c[ 'literal' ]; $currentDate = $c[ 'date_object' ];
foreach ( $timeSlicesForAllChoices as $t ) { foreach ( $timeSlicesForAllChoices as $t ) {
@ -340,6 +351,7 @@ class PollController extends EmailsController {
->setPoll( $newpoll ) ->setPoll( $newpoll )
->setName( $currentDate . ' >>> ' . $t[ 'literal' ] ); ->setName( $currentDate . ' >>> ' . $t[ 'literal' ] );
$em->persist( $newChoice ); $em->persist( $newChoice );
$newpoll->addChoice( $newChoice );
} }
@ -347,7 +359,6 @@ class PollController extends EmailsController {
} }
} }
$em->persist( $newpoll ); $em->persist( $newpoll );
@ -359,8 +370,11 @@ class PollController extends EmailsController {
$this->sendCreationMailAction( $foundOwner, $newpoll ); $this->sendCreationMailAction( $foundOwner, $newpoll );
$newChoices = $newpoll->display()[ 'choices' ];
return $this->json( [ return $this->json( [
'message' => 'you created a poll ' . $precision, 'message' => 'you created the poll ' . $newpoll->getCustomUrl() . $precision,
'id' => $newpoll->getId(),
'poll' => $newpoll->displayForAdmin(), 'poll' => $newpoll->displayForAdmin(),
'password_protected' => is_string( $newpoll->getPassword() ), 'password_protected' => is_string( $newpoll->getPassword() ),
@ -388,19 +402,34 @@ class PollController extends EmailsController {
public function testSendCreationMailAction( public function testSendCreationMailAction(
$emailChoice = 'tktest_commentateur@tktest.com' $emailChoice = 'tktest_commentateur@tktest.com'
) { ) {
$em = $this->getDoctrine()->getRepository( Poll::class );
$foundPoll = $em->findOneByCustomUrl( 'dessin-anime' );
$em = $this->getDoctrine()->getRepository( Owner::class ); $em = $this->getDoctrine()->getRepository( Owner::class );
$foundOwner = $em->findOneByEmail( $emailChoice ); $foundOwner = $em->findOneByEmail( $emailChoice );
if ( $foundOwner ) {
$poll = $foundOwner->getPolls()[ 0 ];
$comment = $foundOwner->getComments()[ 0 ];
$sent = $this->sendOwnerPollsAction( $foundOwner ); return $this->render( 'emails/creation-mail.html.twig',
if ( $sent ) { [ 'poll' => $foundPoll, 'owner' => $foundPoll->getOwner() ] );
return $this->json( [ "message" => "test email sent to " . $foundOwner->getEmail() . "!" ], 200 );
}
}
return $this->json( [ "message" => "user with this email was not found" ], 400 );
// if ( $foundOwner ) {
// $sent = $this->sendOwnerPollsAction( $foundOwner );
// if ( $sent ) {
// $config = [
// 'owner' => $foundOwner,
// 'title' => $this->getParameter( 'WEBSITE_NAME' ) . ' | Mes sondages',
// 'email_template' => 'emails/owner-list.html.twig',
// ];
// return $this->render( 'emails/owner-list.html.twig', $config );
// }
// }
// return $this->json( [ "message" => "test email sent to " . $foundOwner->getEmail() . "!" ], 200 );
// $this->sendMailWithVars( $config );
// return $this->json( [ "message" => "user with this email was not found" ], 400 );
} }

View File

@ -44,17 +44,25 @@ class VoteController extends EmailsController {
string $custom_url, string $custom_url,
Request $request, Request $request,
ChoiceRepository $choice_repository ChoiceRepository $choice_repository
) { ) {
/***
* checks before persisting
*/
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
$emPol = $em->getRepository( Poll::class ); $emPol = $em->getRepository( Poll::class );
$poll = $emPol->findOneByCustomUrl( $custom_url ); $poll = $emPol->findOneByCustomUrl( $custom_url );
// check : existence of poll
if ( ! $poll ) { if ( ! $poll ) {
return $this->json( [ 'message' => 'poll "' . $custom_url . '" not found' ], 404 ); return $this->json( [ 'message' => 'poll "' . $custom_url . '" not found' ], 404 );
} }
// check : limit of number of participation max
if ( count( $poll->getStacksOfVotes() ) == $poll->getVotesMax() ) {
return $this->json( [ 'message' => 'poll "' . $custom_url . '" not allowed to have more stack of votes than ' . $poll->getVotesMax() ],
403 );
}
$data = $request->getContent(); $data = $request->getContent();
$data = json_decode( $data, true ); $data = json_decode( $data, true );
@ -63,32 +71,30 @@ class VoteController extends EmailsController {
$owner = new Owner(); $owner = new Owner();
$owner $owner
->addPoll( $poll ) ->addPoll( $poll );
;
$newStack = new StackOfVotes(); $newStack = new StackOfVotes();
$newStack $newStack
->setPoll($poll) ->setPoll( $poll )
->setIp( $_SERVER[ 'REMOTE_ADDR' ] ) ->setIp( $_SERVER[ 'REMOTE_ADDR' ] )
->setPseudo( $data[ "pseudo" ] ) ->setPseudo( $data[ "pseudo" ] )
->setOwner( $owner ); ->setOwner( $owner );
$owner $owner
->setPseudo($data['owner'][ "pseudo" ]) ->setPseudo( $data[ 'owner' ][ "pseudo" ] )
->setPseudo($data['owner'][ "email" ]) ->setPseudo( $data[ 'owner' ][ "email" ] )
->addStackOfVote($newStack); ->addStackOfVote( $newStack );
// TODO manage new comment // TODO manage new comment
$emChoice = $choice_repository; $emChoice = $choice_repository;
$newComment = new Comment(); $newComment = new Comment();
$newComment->setPseudo($data ['pseudo']) $newComment->setPseudo( $data [ 'pseudo' ] )
->setPoll($poll) ->setPoll( $poll )
->setText($data['comment']); ->setText( $data[ 'comment' ] );
$owner->addComment($newComment); $owner->addComment( $newComment );
$em->persist($newComment); $em->persist( $newComment );
foreach ( $data[ 'votes' ] as $vote ) { foreach ( $data[ 'votes' ] as $vote ) {
if(!$vote[ 'value' ]){ if ( ! $vote[ 'value' ] ) {
continue; continue;
} }
$newVote = new Vote(); $newVote = new Vote();

View File

@ -85,6 +85,15 @@ class Poll {
* @Serializer\Expose() * @Serializer\Expose()
*/ */
public $votesAllowed = true; public $votesAllowed = true;
/**
* people can add votes
* @ORM\Column(type="boolean", nullable=true)
* @Serializer\Type("boolean")
* @Serializer\Expose()
*/
public $isZeroKnowledge ;
/** /**
* max number of stack of votes possible. * max number of stack of votes possible.
* limits the number of people who can answer. as long as you trust the people to give only one answer with a reliable system. * limits the number of people who can answer. as long as you trust the people to give only one answer with a reliable system.
@ -194,574 +203,586 @@ class Poll {
public function __construct() { public function __construct() {
$this->initiate(); $this->initiate();
$this->setCreatedAt( new DateTime() ); $this->setCreatedAt( new DateTime() );
$this->setAdminKey( $this->generateRandomKey() ); $this->setAdminKey( $this->generateRandomKey() );
$this->votes = new ArrayCollection(); $this->votes = new ArrayCollection();
$this->stacksOfVotes = new ArrayCollection(); $this->stacksOfVotes = new ArrayCollection();
$this->choices = new ArrayCollection(); $this->choices = new ArrayCollection();
$this->comments = new ArrayCollection(); $this->comments = new ArrayCollection();
} }
private function initiate() { private function initiate() {
$this->votes = new ArrayCollection(); $this->votes = new ArrayCollection();
$this->stacksOfVotes = new ArrayCollection(); $this->stacksOfVotes = new ArrayCollection();
$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->setCreatedAt( new DateTime() ); $this->setCreatedAt( new DateTime() );
$this->setExpiracyDate( $this->addDaysToDate( $this->setExpiracyDate( $this->addDaysToDate(
new DateTime(), new DateTime(),
$this->defaultExpiracyDaysFromNow $this->defaultExpiracyDaysFromNow
) ); ) );
$this->setAllowedAnswers( [ 'yes', 'maybe', 'no' ] ); $this->setAllowedAnswers( [ 'yes', 'maybe', 'no' ] );
} }
public function setCreatedAt( DateTimeInterface $createdAt ): self { public function setCreatedAt( DateTimeInterface $createdAt ): self {
$this->createdAt = $createdAt; $this->createdAt = $createdAt;
return $this; return $this;
} }
public function displayForAdmin() { public function displayForAdmin() {
$content = $this->display(); $content = $this->display();
$content[ 'owner' ] = $this->getOwner()->displayForAdmin(); $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;
} }
// counts each number of answer for this choice // counts each number of answer for this choice
public function display() { public function display() {
$computedAnswers = $this->computeAnswers(); $computedAnswers = $this->computeAnswers();
$displayedStackOfVotes = []; $displayedStackOfVotes = [];
foreach ( $this->getStacksOfVotes() as $stack ) { foreach ( $this->getStacksOfVotes() as $stack ) {
$displayedStackOfVotes[] = $stack->display(); $displayedStackOfVotes[] = $stack->display();
} }
$displayedChoices = []; $displayedChoices = [];
foreach ( $this->getChoices() as $choice ) { foreach ( $this->getChoices() as $choice ) {
$displayedChoices[] = $choice->display( $this->getKind() ); $displayedChoices[] = $choice->display( $this->getKind() );
} }
$displayedComments = []; $displayedComments = [];
foreach ( $this->getComments() as $comment ) { foreach ( $this->getComments() as $comment ) {
$displayedComments[] = $comment->display(); $displayedComments[] = $comment->display();
} }
$resp = [ $resp = [
'title' => $this->getTitle(), 'title' => $this->getTitle(),
'description' => $this->getDescription(), 'description' => $this->getDescription(),
'created_at' => $this->getCreatedAt()->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(),
'custom_url' => $this->getCustomUrl(), 'custom_url' => $this->getCustomUrl(),
'choices_max' => $this->getChoicesMax(), 'choices_max' => $this->getChoicesMax(),
'kind' => $this->getKind(), 'kind' => $this->getKind(),
'allowed_answers' => $this->getAllowedAnswers(), 'allowed_answers' => $this->getAllowedAnswers(),
'votes_allowed' => $this->getVotesAllowed(), 'votes_allowed' => $this->getVotesAllowed(),
'modification_policy' => $this->getModificationPolicy(), 'modification_policy' => $this->getModificationPolicy(),
'hide_results' => $this->getHideResults(), 'hide_results' => $this->getHideResults(),
'show_results_even_if_password' => $this->getShowResultEvenIfPasswords(), 'show_results_even_if_password' => $this->getShowResultEvenIfPasswords(),
'owner' => [ 'owner' => [
'pseudo' => $this->getOwner()->getPseudo(), 'pseudo' => $this->getOwner()->getPseudo(),
] ]
, ,
'password_protected' => $this->getPassword() ? 'yes' : 'no', 'password_protected' => $this->getPassword() ? 'yes' : 'no',
'max_score' => $computedAnswers[ 'max_score' ], 'max_score' => $computedAnswers[ 'max_score' ],
'choices' => $computedAnswers[ 'answers' ], 'choices' => $computedAnswers[ 'answers' ],
'stacks' => $displayedStackOfVotes, 'stacks' => $displayedStackOfVotes,
'comments' => $displayedComments, 'comments' => $displayedComments,
]; ];
if ( $this->getKind() == 'text' ) { if ( $this->getKind() == 'text' ) {
$resp[ 'choices' ] = $computedAnswers[ 'answers' ]; $resp[ 'choices' ] = $computedAnswers[ 'answers' ];
} elseif ( $this->getKind() == 'date' ) { } elseif ( $this->getKind() == 'date' ) {
$resp[ 'choices_grouped' ] = $computedAnswers[ 'grouped_dates' ]; $resp[ 'choices_grouped' ] = $computedAnswers[ 'grouped_dates' ];
} }
return $resp; return $resp;
} }
public function computeAnswers() { public function computeAnswers() {
$computedArray = []; $computedArray = [];
$grouped_dates = []; $grouped_dates = [];
$maxScore = 0; $maxScore = 0;
if ( $this->getKind() == 'date' ) { if ( $this->getKind() == 'date' ) {
foreach ( $this->getChoices() as $choice ) { foreach ( $this->getChoices() as $choice ) {
$boom = explode( ' >>> ', $choice->getName() ); $boom = explode( ' >>> ', $choice->getName() );
if ( count( $boom ) == 2 ) { if ( count( $boom ) == 2 ) {
if ( ! isset( $grouped_dates[ $boom[ 0 ] ] ) ) { if ( ! isset( $grouped_dates[ $boom[ 0 ] ] ) ) {
$grouped_dates[ $boom[ 0 ] ] = [ $grouped_dates[ $boom[ 0 ] ] = [
"date_string" => $boom[ 0 ], "date_string" => $boom[ 0 ],
"choices" => [], "choices" => [],
]; ];
} }
$grouped_dates[ $boom[ 0 ] ][ "choices" ][] = [ $grouped_dates[ $boom[ 0 ] ][ "choices" ][] = [
"choice_id" => $choice->getId(), "choice_id" => $choice->getId(),
"name" => $boom[ 1 ], "name" => $boom[ 1 ],
]; ];
} }
} }
} }
$scoreInfos = [ $scoreInfos = [
'score' => 0, 'score' => 0,
'yes' => [ 'yes' => [
'count' => 0, 'count' => 0,
'people' => [], 'people' => [],
], ],
'maybe' => [ 'maybe' => [
'count' => 0, 'count' => 0,
'people' => [], 'people' => [],
], ],
'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 ) {
foreach ( $stack_of_vote->getVotes() as $vote ) { foreach ( $stack_of_vote->getVotes() as $vote ) {
$answer = $vote->getValue(); $answer = $vote->getValue();
$choice_id = $vote->getChoice()->getId(); $choice_id = $vote->getChoice()->getId();
$choice_url = $vote->getChoice()->getUrl(); $choice_url = $vote->getChoice()->getUrl();
if ( ! isset( $computedArray[ $choice_id ] ) ) { if ( ! isset( $computedArray[ $choice_id ] ) ) {
$computedArray[ $choice_id ] = [ $computedArray[ $choice_id ] = [
'id' => $choice_id, 'id' => $choice_id,
'url' => $choice_url, 'url' => $choice_url,
'name' => $vote->getChoice()->getName(), 'name' => $vote->getChoice()->getName(),
'score' => 0, 'score' => 0,
'yes' => [ 'yes' => [
'count' => 0, 'count' => 0,
'people' => [], 'people' => [],
], ],
'maybe' => [ 'maybe' => [
'count' => 0, 'count' => 0,
'people' => [], 'people' => [],
], ],
'no' => [ 'no' => [
'count' => 0, 'count' => 0,
'people' => [], 'people' => [],
], ],
]; ];
} }
$computedArray[ $choice_id ][ $answer ][ 'count' ] ++; $computedArray[ $choice_id ][ $answer ][ 'count' ] ++;
$computedArray[ $choice_id ][ $answer ][ 'people' ][] = $stack_of_vote->getOwner()->getPseudo(); $computedArray[ $choice_id ][ $answer ][ 'people' ][] = $stack_of_vote->getOwner()->getPseudo();
if ( $answer == 'yes' ) { if ( $answer == 'yes' ) {
$computedArray[ $choice_id ][ 'score' ] += 1; $computedArray[ $choice_id ][ 'score' ] += 1;
} elseif ( $answer == 'maybe' ) { } elseif ( $answer == 'maybe' ) {
$computedArray[ $choice_id ][ 'score' ] += 0.5; $computedArray[ $choice_id ][ 'score' ] += 0.5;
} }
// compare with max value // compare with max value
if ( $computedArray[ $choice_id ][ 'score' ] > $maxScore ) { if ( $computedArray[ $choice_id ][ 'score' ] > $maxScore ) {
$maxScore = $computedArray[ $choice_id ][ 'score' ]; $maxScore = $computedArray[ $choice_id ][ 'score' ];
} }
} }
} }
$answersWithStats = []; $answersWithStats = [];
foreach ( $computedArray as $choice_stat ) { foreach ( $computedArray as $choice_stat ) {
$answersWithStats[] = $choice_stat; $answersWithStats[] = $choice_stat;
} }
$groupsOfDates = []; $groupsOfDates = [];
foreach ( $grouped_dates as $group ) { foreach ( $grouped_dates as $group ) {
$ii = 0; $ii = 0;
foreach ( $group[ "choices" ] as $slice ) { foreach ( $group[ "choices" ] as $slice ) {
$slice[ 'score' ] = $computedArray[ $slice[ 'choice_id' ] ][ 'score' ]; $slice[ 'score' ] = $computedArray[ $slice[ 'choice_id' ] ][ 'score' ];
$slice[ 'yes' ] = $computedArray[ $slice[ 'choice_id' ] ][ 'yes' ]; $slice[ 'yes' ] = $computedArray[ $slice[ 'choice_id' ] ][ 'yes' ];
$slice[ 'maybe' ] = $computedArray[ $slice[ 'choice_id' ] ][ 'maybe' ]; $slice[ 'maybe' ] = $computedArray[ $slice[ 'choice_id' ] ][ 'maybe' ];
$slice[ 'no' ] = $computedArray[ $slice[ 'choice_id' ] ][ 'no' ]; $slice[ 'no' ] = $computedArray[ $slice[ 'choice_id' ] ][ 'no' ];
$slice[ 'id' ] = $slice[ 'choice_id' ]; $slice[ 'id' ] = $slice[ 'choice_id' ];
$group[ "choices" ][ $ii ] = $slice; $group[ "choices" ][ $ii ] = $slice;
$ii ++; $ii ++;
} }
$groupsOfDates[] = $group; $groupsOfDates[] = $group;
} }
return [ return [
'answers' => $answersWithStats, 'answers' => $answersWithStats,
'grouped_dates' => $groupsOfDates, 'grouped_dates' => $groupsOfDates,
'max_score' => $maxScore, 'max_score' => $maxScore,
]; ];
} }
/** /**
* @return Collection|Choice[] * @return Collection|Choice[]
*/ */
public function getChoices(): Collection { public function getChoices(): Collection {
return $this->choices; return $this->choices;
} }
public function getKind(): ?string { public function getKind(): ?string {
return $this->kind; return $this->kind;
} }
public function setKind( string $kind ): self { public function setKind( string $kind ): self {
$this->kind = $kind; $this->kind = $kind;
return $this; return $this;
} }
public function getStacksOfVotes() { public function getStacksOfVotes() {
return $this->stacksOfVotes; return $this->stacksOfVotes;
} }
public function setStacksOfVotes( ?StackOfVotes $stacksOfVotes ): self { public function setStacksOfVotes( ?StackOfVotes $stacksOfVotes ): self {
$this->stacksOfVotes = $stacksOfVotes; $this->stacksOfVotes = $stacksOfVotes;
return $this; return $this;
} }
/** /**
* @return Collection|Comment[] * @return Collection|Comment[]
*/ */
public function getComments(): Collection { public function getComments(): Collection {
return $this->comments; return $this->comments;
} }
public function getTitle(): ?string { public function getTitle(): ?string {
return $this->title; return $this->title;
} }
public function setTitle( string $title ): self { public function setTitle( string $title ): self {
$this->title = $title; $this->title = $title;
return $this; return $this;
} }
public function getDescription(): ?string { public function getDescription(): ?string {
return $this->description; return $this->description;
} }
public function setDescription( string $description ): self { public function setDescription( string $description ): self {
$this->description = $description; $this->description = $description;
return $this; return $this;
} }
public function getCreatedAt(): ?DateTimeInterface { public function getCreatedAt(): ?DateTimeInterface {
return $this->createdAt; return $this->createdAt;
} }
public function getExpiracyDate(): ?DateTimeInterface { public function getExpiracyDate(): ?DateTimeInterface {
return $this->expiracyDate; return $this->expiracyDate;
} }
public function setExpiracyDate( DateTimeInterface $expiracyDate ): self { public function setExpiracyDate( DateTimeInterface $expiracyDate ): self {
$this->expiracyDate = $expiracyDate; $this->expiracyDate = $expiracyDate;
return $this; return $this;
} }
public function getVotesMax() { public function getVotesMax() {
return $this->votesMax; return $this->votesMax;
} }
public function setVotesMax( $votesMax ): self { public function setVotesMax( $votesMax ): self {
$this->votesMax = $votesMax; $this->votesMax = $votesMax;
return $this; return $this;
} }
public function getChoicesMax() { public function getChoicesMax() {
return $this->choicesMax; return $this->choicesMax;
} }
public function setChoicesMax( $choicesMax ): self { public function setChoicesMax( $choicesMax ): self {
$this->choicesMax = $choicesMax; $this->choicesMax = $choicesMax;
return $this; return $this;
} }
public function getAllowedAnswers(): ?array { public function getAllowedAnswers(): ?array {
return $this->allowedAnswers; return $this->allowedAnswers;
} }
public function setAllowedAnswers( array $allowedAnswers ): self { public function setAllowedAnswers( array $allowedAnswers ): self {
if ( ! count( $allowedAnswers ) ) { if ( ! count( $allowedAnswers ) ) {
$this->allowedAnswers = [ 'yes' ]; $this->allowedAnswers = [ 'yes' ];
} else { } else {
$this->allowedAnswers = $allowedAnswers; $this->allowedAnswers = $allowedAnswers;
} }
return $this; return $this;
} }
public function getVotesAllowed(): ?bool { public function getVotesAllowed(): ?bool {
return $this->votesAllowed; return $this->votesAllowed;
} }
public function setVotesAllowed( ?bool $votesAllowed ): self { public function setVotesAllowed( ?bool $votesAllowed ): self {
$this->votesAllowed = $votesAllowed; $this->votesAllowed = $votesAllowed;
return $this; return $this;
} }
public function getModificationPolicy(): ?string { public function getModificationPolicy(): ?string {
return $this->modificationPolicy; return $this->modificationPolicy;
} }
public function setModificationPolicy( string $modificationPolicy ): self { public function setModificationPolicy( string $modificationPolicy ): self {
$this->modificationPolicy = $modificationPolicy; $this->modificationPolicy = $modificationPolicy;
return $this; return $this;
} }
public function getHideResults(): ?bool { public function getHideResults(): ?bool {
return $this->hideResults; return $this->hideResults;
} }
public function setHideResults( bool $hideResults ): self { public function setHideResults( bool $hideResults ): self {
$this->hideResults = $hideResults; $this->hideResults = $hideResults;
return $this; return $this;
} }
public function getShowResultEvenIfPasswords(): ?bool { public function getShowResultEvenIfPasswords(): ?bool {
return $this->showResultEvenIfPasswords; return $this->showResultEvenIfPasswords;
} }
public function setShowResultEvenIfPasswords( bool $showResultEvenIfPasswords ): self { public function setShowResultEvenIfPasswords( bool $showResultEvenIfPasswords ): self {
$this->showResultEvenIfPasswords = $showResultEvenIfPasswords; $this->showResultEvenIfPasswords = $showResultEvenIfPasswords;
return $this; return $this;
} }
public function getOwner(): ?Owner { public function getOwner(): ?Owner {
return $this->owner; return $this->owner;
} }
public function setOwner( ?Owner $owner ): self { public function setOwner( ?Owner $owner ): self {
$this->owner = $owner; $this->owner = $owner;
return $this; return $this;
} }
public function getPassword(): ?string { public function getPassword(): ?string {
return $this->password; return $this->password;
} }
public function setPassword( string $password ): self { public function setPassword( string $password ): self {
$this->password = md5( $password ); $this->password = md5( $password );
return $this; return $this;
} }
public function getAdminKey(): ?string { public function getAdminKey(): ?string {
return $this->adminKey; return $this->adminKey;
} }
public function setAdminKey( string $adminKey ): self { public function setAdminKey( string $adminKey ): self {
$this->adminKey = $adminKey; $this->adminKey = $adminKey;
return $this; return $this;
} }
public function getId(): ?int { public function getId(): ?int {
return $this->id; return $this->id;
} }
public function findChoiceById( int $id ) { public function findChoiceById( int $id ) {
$choices = $this->getChoices(); $choices = $this->getChoices();
$counter = 0; $counter = 0;
// there must be something cleaner than this in Doctrine ArrayCollection // there must be something cleaner than this in Doctrine ArrayCollection
foreach ( $choices as $choice ) { foreach ( $choices as $choice ) {
$counter ++; $counter ++;
if ( $counter > $this->maxChoicesLimit ) { if ( $counter > $this->maxChoicesLimit ) {
throw new ErrorException( "max number of choices reached for this poll" ); throw new ErrorException( "max number of choices reached for this poll" );
} }
if ( $choice && $choice->getId() == $id ) { if ( $choice && $choice->getId() == $id ) {
return $choice; return $choice;
} }
} }
return null; return null;
} }
/** /**
* @return Collection|Vote[] * @return Collection|Vote[]
*/ */
public function getVotes(): Collection { public function getVotes(): Collection {
return $this->votes; return $this->votes;
} }
public function getCustomUrl(): ?string { public function getCustomUrl(): ?string {
return $this->customUrl; return $this->customUrl;
} }
public function setCustomUrl( string $customUrl ): self { public function setCustomUrl( string $customUrl ): self {
$this->customUrl = $customUrl; $this->customUrl = $customUrl;
return $this; return $this;
} }
public function getMailOnComment(): ?bool { public function getMailOnComment(): ?bool {
return $this->mailOnComment; return $this->mailOnComment;
} }
public function setMailOnComment( bool $mailOnComment ): self { public function setMailOnComment( bool $mailOnComment ): self {
$this->mailOnComment = $mailOnComment; $this->mailOnComment = $mailOnComment;
return $this; return $this;
} }
public function getMailOnVote(): ?bool { public function getMailOnVote(): ?bool {
return $this->mailOnVote; return $this->mailOnVote;
} }
public function setMailOnVote( bool $mailOnVote ): self { public function setMailOnVote( bool $mailOnVote ): self {
$this->mailOnVote = $mailOnVote; $this->mailOnVote = $mailOnVote;
return $this; 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;
$comment->setPoll( $this ); $comment->setPoll( $this );
} }
return $this; return $this;
} }
public function removeComment( Comment $comment ): self { public function removeComment( Comment $comment ): self {
if ( $this->comments->contains( $comment ) ) { if ( $this->comments->contains( $comment ) ) {
$this->comments->removeElement( $comment ); $this->comments->removeElement( $comment );
// set the owning side to null (unless already changed) // set the owning side to null (unless already changed)
if ( $comment->getPoll() === $this ) { if ( $comment->getPoll() === $this ) {
$comment->setPoll( null ); $comment->setPoll( null );
} }
} }
return $this; return $this;
} }
public function addStackOfVote( StackOfVotes $stackOfVote ): self { public function addStackOfVote( StackOfVotes $stackOfVote ): self {
if ( ! $this->stacksOfVotes->contains( $stackOfVote ) ) { if ( ! $this->stacksOfVotes->contains( $stackOfVote ) ) {
$this->stacksOfVotes[] = $stackOfVote; $this->stacksOfVotes[] = $stackOfVote;
$stackOfVote->setPoll( $this ); $stackOfVote->setPoll( $this );
} }
return $this; return $this;
} }
public function removeStackOfVote( StackOfVotes $stackOfVote ): self { public function removeStackOfVote( StackOfVotes $stackOfVote ): self {
if ( $this->stacksOfVotes->contains( $stackOfVote ) ) { if ( $this->stacksOfVotes->contains( $stackOfVote ) ) {
$this->stacksOfVotes->removeElement( $stackOfVote ); $this->stacksOfVotes->removeElement( $stackOfVote );
// set the owning side to null (unless already changed) // set the owning side to null (unless already changed)
if ( $stackOfVote->getPoll() === $this ) { if ( $stackOfVote->getPoll() === $this ) {
$stackOfVote->setPoll( null ); $stackOfVote->setPoll( null );
} }
} }
return $this; return $this;
} }
public function addVote( Vote $vote ): self { public function addVote( Vote $vote ): self {
if ( ! $this->votes->contains( $vote ) ) { if ( ! $this->votes->contains( $vote ) ) {
$this->votes[] = $vote; $this->votes[] = $vote;
$vote->setPoll( $this ); $vote->setPoll( $this );
} }
return $this; return $this;
} }
public function removeVote( Vote $vote ): self { public function removeVote( Vote $vote ): self {
if ( $this->votes->contains( $vote ) ) { if ( $this->votes->contains( $vote ) ) {
$this->votes->removeElement( $vote ); $this->votes->removeElement( $vote );
// set the owning side to null (unless already changed) // set the owning side to null (unless already changed)
if ( $vote->getPoll() === $this ) { if ( $vote->getPoll() === $this ) {
$vote->setPoll( null ); $vote->setPoll( null );
} }
} }
return $this; return $this;
} }
public function addTextChoiceArray( array $choiceTextArray ): self { public function addTextChoiceArray( array $choiceTextArray ): self {
foreach ( $choiceTextArray as $text ) { foreach ( $choiceTextArray as $text ) {
$newChoice = new Choice(); $newChoice = new Choice();
$newChoice->setName( $text ); $newChoice->setName( $text );
$this->addChoice( $newChoice ); $this->addChoice( $newChoice );
} }
return $this; return $this;
} }
public function addChoice( Choice $choice ): self { public function addChoice( Choice $choice ): self {
if ( ! is_null( $this->choices ) ) { if ( ! is_null( $this->choices ) ) {
if ( ! $this->choices->contains( $choice ) ) { if ( ! $this->choices->contains( $choice ) ) {
$this->choices[] = $choice; $this->choices[] = $choice;
$choice->setPoll( $this ); $choice->setPoll( $this );
} }
} else { } else {
$this->choices[] = $choice; $this->choices[] = $choice;
$choice->setPoll( $this ); $choice->setPoll( $this );
} }
return $this; return $this;
} }
public function addStacksOfVote( StackOfVotes $stacksOfVote ): self { public function addStacksOfVote( StackOfVotes $stacksOfVote ): self {
if ( ! $this->stacksOfVotes->contains( $stacksOfVote ) ) { if ( ! $this->stacksOfVotes->contains( $stacksOfVote ) ) {
$this->stacksOfVotes[] = $stacksOfVote; $this->stacksOfVotes[] = $stacksOfVote;
$stacksOfVote->setPoll( $this ); $stacksOfVote->setPoll( $this );
} }
return $this; return $this;
} }
public function removeStacksOfVote( StackOfVotes $stacksOfVote ): self { public function removeStacksOfVote( StackOfVotes $stacksOfVote ): self {
if ( $this->stacksOfVotes->contains( $stacksOfVote ) ) { if ( $this->stacksOfVotes->contains( $stacksOfVote ) ) {
$this->stacksOfVotes->removeElement( $stacksOfVote ); $this->stacksOfVotes->removeElement( $stacksOfVote );
// set the owning side to null (unless already changed) // set the owning side to null (unless already changed)
if ( $stacksOfVote->getPoll() === $this ) { if ( $stacksOfVote->getPoll() === $this ) {
$stacksOfVote->setPoll( null ); $stacksOfVote->setPoll( null );
} }
} }
return $this; return $this;
} }
public function removeChoice( Choice $choice ): self { public function removeChoice( Choice $choice ): self {
if ( $this->choices->contains( $choice ) ) { if ( $this->choices->contains( $choice ) ) {
$this->choices->removeElement( $choice ); $this->choices->removeElement( $choice );
// set the owning side to null (unless already changed) // set the owning side to null (unless already changed)
if ( $choice->getPoll() === $this ) { if ( $choice->getPoll() === $this ) {
$choice->setPoll( null ); $choice->setPoll( null );
} }
} }
return $this; return $this;
} }
public function getCommentsAllowed(): ?bool { public function getCommentsAllowed(): ?bool {
return $this->commentsAllowed; return $this->commentsAllowed;
} }
public function setCommentsAllowed( ?bool $commentsAllowed ): self { public function setCommentsAllowed( ?bool $commentsAllowed ): self {
$this->commentsAllowed = $commentsAllowed; $this->commentsAllowed = $commentsAllowed;
return $this; return $this;
} }
public function getIsZeroKnowledge(): ?bool
{
return $this->isZeroKnowledge;
}
public function setIsZeroKnowledge(?bool $isZeroKnowledge): self
{
$this->isZeroKnowledge = $isZeroKnowledge;
return $this;
}
} }

View File

@ -9,9 +9,9 @@
<header> <header>
{% block title %} {% block title %}
{% if title is defined %} {% if title is defined %}
<h1>{{ title }}</h1> <h1 class="text-center">{{ title }}</h1>
{% else %} {% else %}
<h1>Framadate - email</h1> <h1 class="text-center">Framadate</h1>
{% endif %} {% endif %}
<hr> <hr>
{% endblock %} {% endblock %}
@ -30,6 +30,9 @@
</div> </div>
<style type="text/css"> <style type="text/css">
.text-center{
text-align:center;
}
html, body, main, header, footer, div { html, body, main, header, footer, div {
font-family: "Open Sans", "Helvetica Neue", sans-serif; font-family: "Open Sans", "Helvetica Neue", sans-serif;
} }

View File

@ -2,12 +2,12 @@
{% extends 'email-base.html.twig' %} {% extends 'email-base.html.twig' %}
{% block content %} {% block content %}
<h1>✨ Création de votre sondage {{ poll.title }} </h1>
Suite à la création de votre sondage {{ title }} vous recevez deux emails afin de ne pas transmettre par erreur aux sondés le lien d'administration de votre sondage. Suite à la création de votre sondage <strong>{{ poll.title }}</strong> vous recevez deux emails afin de ne pas transmettre par erreur aux sondés le lien d'administration de votre sondage.
<br> <br>
Ce mail est le premier, comportant le message qui doit être envoyé aux sondés.<br> Ce mail est le premier, comportant le message qui doit être envoyé aux sondés.<br>
Vous pouvez maintenant transmettre ce message à toutes les personnes susceptibles de participer au vote.<br> Vous pouvez maintenant transmettre ce message à toutes les personnes susceptibles de participer au vote. ✔️ <br>
<br> <br>
<fieldset> <fieldset>
@ -15,7 +15,7 @@
<blockquote> <blockquote>
<i> <i>
{{ owner.pseudo }} ( {{ owner.email }} ) vient de créer un sondage intitulé : " <strong>{{ title }} 💡 {{ owner.pseudo }} ( {{ owner.email }} ) vient de créer un sondage intitulé : " <strong>{{ poll.title }}
"</strong>. "</strong>.
<br> <br>
<br> <br>

View File

@ -3,13 +3,17 @@
{% block content %} {% block content %}
Ce sondage va bientôt expirer dans 1 jour, <br> <h1> 🎌 Votre sondage {{ poll.title }} va bientôt expirer dans 1 jour,</h1>
<blockquote> <blockquote>
le {{ poll.expiracyDate | date('D Y-m-d') }} le {{ poll.expiracyDate | date('D Y-m-d') }} :
</blockquote> </blockquote>
il ne sera plus possible d'y voter. <br> il ne sera plus possible d'y voter. <br>
Dans 31 jours il sera supprimé.<br> Dans 31 jours il sera supprimé.<br>
Vous pouvez exporter ses données à tout moment en vous rendant à ce lien pour l'administrer: Vous pouvez exporter ses données à tout moment en vous rendant à ce lien pour l'administrer:
<br> <br>
{% include 'emails/partial/admin_link.html.twig' %} {% include 'emails/partial/admin_link.html.twig' %}
<hr>
Plus de détails sur votre sondage :
{% include 'emails/partial/poll.html.twig' %}
{% endblock %} {% endblock %}

View File

@ -13,10 +13,10 @@
<a href="https://framagit.org/framasoft/framadate/funky-framadate-front"> <a href="https://framagit.org/framasoft/framadate/funky-framadate-front">
Sources du client Front end, Sources du client Front end,
</a> </a>
<a href="https://framagit.org/framasoft/framadate/framadate"> <a href="https://framagit.org/tykayn/date-poll-api">
API back end. API back end.
</a> </a>
<a href="https://framagit.org/framasoft/framadate/funky-framadate-front/-/wikis/home"> <a href="https://framagit.org/framasoft/framadate/funky-framadate-front/docs">
Documentation Documentation
</a> </a>

View File

@ -1,2 +1 @@
<a href="{{ BASE_URL }}/#/poll/{{ poll.id }}/admin/{{ poll.adminKey }}">{{ BASE_URL }} <a href="{{ BASE_URL }}/#/poll/{{ poll.customUrl }}/admin/{{ poll.adminKey }}">{{ BASE_URL }}/#/poll/{{ poll.customUrl }}/admin/{{ poll.adminKey }}</a>
/admin/{{ poll.adminKey }}</a>

View File

@ -2,11 +2,9 @@
<h1> <h1>
Sondage {{ poll.title }} Sondage {{ poll.title }}
</h1> </h1>
<br> <br>
<div class="creation"> <div class="creation">
créé le {{ poll.creationDate| date('Y m d ') }} créé le {{ poll.createdAt| date('Y m d ') }}
</div> </div>
<div class="creation"> <div class="creation">
expirera le {{ poll.expiracyDate| date('Y m d ') }} expirera le {{ poll.expiracyDate| date('Y m d ') }}
@ -18,22 +16,29 @@
{{ poll.comments |length }} commentaires {{ poll.comments |length }} commentaires
</span> </span>
{% if poll.password |length %} {% if poll.password |length %}
(accès avec mot de passe) <div class="protected">
🔐 (accès avec mot de passe)
</div>
{% else %}
{% endif %}
{% if poll.isZeroKnowledge |length %}
<div class="protected-zero-knoledge">
🔐 Ce sondage bénéficie du chiffrement Zéro knowledge, nos administrateurs ne sont pas en mesure de connaître les informations du sondage.
</div>
{% else %} {% else %}
{% endif %} {% endif %}
<br> <br>
<div class="public"> <div class="public">
<span> <div>
lien à donner aux votants: lien à donner aux votants:
</span> </div>
{% include 'emails/partial/public_link.html.twig' %} {% include 'emails/partial/public_link.html.twig' %}
</div> </div>
<div class="admin"> <div class="admin">
<span> <div>
administration: administration:
</span> </div>
{% include 'emails/partial/admin_link.html.twig' %} {% include 'emails/partial/admin_link.html.twig' %}
</div> </div>
</div> </div>

View File

@ -1,11 +1,10 @@
<span class="public-link"> <span class="public-link">
{% if poll.customUrl |length %} {% if poll.customUrl |length %}
<a href="{{ BASE_URL }}/#/vote/poll/key/{{ poll.customUrl }}"> <a href="{{ BASE_URL }}/#/poll/{{ poll.customUrl }}/consultation">
{{ BASE_URL }}/#/vote/poll/key/{{ poll.customUrl }}
✉️ {{ BASE_URL }}/#/poll/{{ poll.customUrl }}/consultation
</a> </a>
{% else %} {% else %}
<a href="{{ BASE_URL }}/#/vote/poll/id/{{ poll.id }}"> erreur, il manque la customUrl de ce sondage.
{{ BASE_URL }}/#/vote/poll/id/{{ poll.id }}
</a>
{% endif %} {% endif %}
</span> </span>