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

create choices for all the same time range start

This commit is contained in:
Baptiste Lemoine 2020-01-23 17:36:38 +01:00
parent 4ff254d54a
commit 6408adcb9d

View File

@ -181,15 +181,30 @@ class DefaultController extends AbstractController {
$newpoll->setPassword( $data[ 'password' ] ); $newpoll->setPassword( $data[ 'password' ] );
} }
// manage choices // manage choices
$choices = $data[ 'answers' ]; // text kind of answers, dates are below
foreach ( $choices as $c ) { if ( $data[ 'pollType' ] == 'classic' ) {
$newChoice = new Choice(); $choices = $data[ 'dateList' ];
$newChoice foreach ( $choices as $c ) {
->setPoll( $newpoll ) $newChoice = new Choice();
->setUrl( $c[ 'url' ] ) $newChoice
->setName( $c[ 'text' ] ); ->setPoll( $newpoll )
$em->persist( $newChoice ); // ->setUrl( $c[ 'url' ] )
->setName( $c[ 'literal' ] );
$em->persist( $newChoice );
// TODO add also choices for each time range in a day
}
} elseif ( $data[ 'pollType' ] == 'dates' ) {
if ( $data[ 'allowSeveralHours' ] == true ) {
// different hours spans
$choices = $data[ 'dateList' ];
} else {
// all days have the same hour spans
}
} }
$em->persist( $newpoll ); $em->persist( $newpoll );
$em->flush(); $em->flush();
$precision = ''; $precision = '';
@ -215,7 +230,10 @@ class DefaultController extends AbstractController {
* requirements = {"poll_id"="\d+"} * requirements = {"poll_id"="\d+"}
* ) * )
*/ */
public function getPollCommentsAction( Poll $poll ) { public
function getPollCommentsAction(
Poll $poll
) {
return $this->json( [ return $this->json( [
'message' => 'here are your comments of the poll', 'message' => 'here are your comments of the poll',
'data' => $poll->getComments(), 'data' => $poll->getComments(),
@ -230,7 +248,11 @@ class DefaultController extends AbstractController {
* requirements = {"poll_id"="\d+"} * requirements = {"poll_id"="\d+"}
* ) * )
*/ */
public function getPollConfig( Poll $poll, Request $request ) { public
function getPollConfig(
Poll $poll,
Request $request
) {
$pass = $poll->getPassword(); $pass = $poll->getPassword();
$data = $request->getContent(); $data = $request->getContent();
$data = json_decode( $data, true ); $data = json_decode( $data, true );
@ -289,7 +311,8 @@ class DefaultController extends AbstractController {
* name = "clean_expired_polls", * name = "clean_expired_polls",
* ) * )
*/ */
public function cleanExpiredPolls() { public
function cleanExpiredPolls() {
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
$emPoll = $this->getDoctrine()->getRepository( Poll::class ); $emPoll = $this->getDoctrine()->getRepository( Poll::class );
@ -324,7 +347,11 @@ class DefaultController extends AbstractController {
* requirements = {"content"="\w+", "poll_id"="\d+"} * requirements = {"content"="\w+", "poll_id"="\d+"}
* ) * )
*/ */
public function updatePollConfig( Poll $poll, Request $request ) { public
function updatePollConfig(
Poll $poll,
Request $request
) {
// TODO check validity of request // TODO check validity of request
// update only if we have the admin key // update only if we have the admin key
@ -345,7 +372,11 @@ class DefaultController extends AbstractController {
* requirements = {"content"="\w+", "poll_id"="\d+"} * requirements = {"content"="\w+", "poll_id"="\d+"}
* ) * )
*/ */
public function newCommentAction( Poll $poll, Request $request ) { public
function newCommentAction(
Poll $poll,
Request $request
) {
if ( ! $poll ) { if ( ! $poll ) {
return $this->json( [ 'message' => 'poll not found' ], 404 ); return $this->json( [ 'message' => 'poll not found' ], 404 );
} }
@ -426,7 +457,11 @@ class DefaultController extends AbstractController {
* requirements = {"content"="\w+", "poll_id"="\d+"} * requirements = {"content"="\w+", "poll_id"="\d+"}
* ) * )
*/ */
public function newVoteStackAction( Poll $poll, Request $request ) { public
function newVoteStackAction(
Poll $poll,
Request $request
) {
if ( ! $poll ) { if ( ! $poll ) {
return $this->json( [ 'message' => 'poll not found' ], 404 ); return $this->json( [ 'message' => 'poll not found' ], 404 );
} }
@ -523,7 +558,11 @@ class DefaultController extends AbstractController {
* *
* @return JsonResponse * @return JsonResponse
*/ */
public function deletePollAction( Poll $poll, $accessToken ) { public
function deletePollAction(
Poll $poll,
$accessToken
) {
if ( $accessToken == $poll->getAdminKey() ) { if ( $accessToken == $poll->getAdminKey() ) {
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
@ -554,7 +593,11 @@ class DefaultController extends AbstractController {
* *
* @return JsonResponse * @return JsonResponse
*/ */
public function deletePollCommentsAction( Poll $poll, $accessToken ) { public
function deletePollCommentsAction(
Poll $poll,
$accessToken
) {
if ( $accessToken == $poll->getAdminKey() ) { if ( $accessToken == $poll->getAdminKey() ) {
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
$length = count( $poll->getComments() ); $length = count( $poll->getComments() );
@ -579,7 +622,11 @@ class DefaultController extends AbstractController {
* ) * )
* @return JsonResponse * @return JsonResponse
*/ */
public function deletePollVotesAction( Poll $poll, $accessToken ) { public
function deletePollVotesAction(
Poll $poll,
$accessToken
) {
if ( $accessToken == $poll->getAdminKey() ) { if ( $accessToken == $poll->getAdminKey() ) {
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
$length = count( $poll->getVotes() ); $length = count( $poll->getVotes() );