mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
persist date choices on creation
This commit is contained in:
parent
f5a154b20e
commit
03cba297d5
@ -1,6 +1,6 @@
|
||||
# see https://symfony.com/doc/current/reference/configuration/framework.html
|
||||
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)%'
|
||||
#csrf_protection: true
|
||||
#http_method_override: true
|
||||
|
@ -240,9 +240,17 @@ class PollController extends EmailsController {
|
||||
$data = $request->getContent();
|
||||
$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
|
||||
->setModificationPolicy( $data[ 'modification_policy' ] )
|
||||
->setModificationPolicy( isset( $data[ 'modification_policy' ] ) ? $data[ 'modification_policy' ] : 'everybody' )
|
||||
->setTitle( $data[ 'title' ] )
|
||||
->setKind( $data[ 'kind' ] )
|
||||
->setCustomUrl( $data[ 'custom_url' ] );
|
||||
@ -294,17 +302,18 @@ class PollController extends EmailsController {
|
||||
if ( $data[ 'password' ] ) {
|
||||
$newpoll->setPassword( $data[ 'password' ] );
|
||||
}
|
||||
// manage choices
|
||||
|
||||
// text kind of answers, dates are below
|
||||
if ( $data[ 'kind' ] == 'text' ) {
|
||||
|
||||
$choices = $data[ 'dateChoices' ];
|
||||
// manage choices
|
||||
$choices = $data[ 'choices' ];
|
||||
foreach ( $choices as $c ) {
|
||||
$newChoice = new Choice();
|
||||
$newChoice
|
||||
->setPoll( $newpoll )
|
||||
->setName( $c[ 'literal' ] );
|
||||
$em->persist( $newChoice );
|
||||
$newpoll->addChoice( $newChoice );
|
||||
}
|
||||
} // date kind of poll
|
||||
elseif ( $data[ 'kind' ] == 'date' ) {
|
||||
@ -316,7 +325,7 @@ class PollController extends EmailsController {
|
||||
foreach ( $choices as $c ) {
|
||||
$currentDate = $c[ 'literal' ];
|
||||
|
||||
$timeSlicesOfThisChoice = $c[ 'timeList' ];
|
||||
$timeSlicesOfThisChoice = $c[ 'timeSlices' ];
|
||||
foreach ( $timeSlicesOfThisChoice as $t ) {
|
||||
|
||||
$newChoice = new Choice();
|
||||
@ -324,14 +333,16 @@ class PollController extends EmailsController {
|
||||
->setPoll( $newpoll )
|
||||
->setName( $currentDate . ' >>> ' . $t[ 'literal' ] );
|
||||
$em->persist( $newChoice );
|
||||
$newpoll->addChoice( $newChoice );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
// all choices will be having the same time slices from timeSlices
|
||||
$timeSlicesForAllChoices = $data[ 'timeSlices' ];
|
||||
foreach ( $choices as $c ) {
|
||||
$currentDate = $c[ 'literal' ];
|
||||
$currentDate = $c[ 'date_object' ];
|
||||
|
||||
foreach ( $timeSlicesForAllChoices as $t ) {
|
||||
|
||||
@ -340,6 +351,7 @@ class PollController extends EmailsController {
|
||||
->setPoll( $newpoll )
|
||||
->setName( $currentDate . ' >>> ' . $t[ 'literal' ] );
|
||||
$em->persist( $newChoice );
|
||||
$newpoll->addChoice( $newChoice );
|
||||
}
|
||||
|
||||
|
||||
@ -347,7 +359,6 @@ class PollController extends EmailsController {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
$em->persist( $newpoll );
|
||||
@ -359,8 +370,11 @@ class PollController extends EmailsController {
|
||||
|
||||
$this->sendCreationMailAction( $foundOwner, $newpoll );
|
||||
|
||||
$newChoices = $newpoll->display()[ 'choices' ];
|
||||
|
||||
return $this->json( [
|
||||
'message' => 'you created a poll ' . $precision,
|
||||
'message' => 'you created the poll ' . $newpoll->getCustomUrl() . $precision,
|
||||
'id' => $newpoll->getId(),
|
||||
'poll' => $newpoll->displayForAdmin(),
|
||||
'password_protected' => is_string( $newpoll->getPassword() ),
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user