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:
parent
4ff254d54a
commit
6408adcb9d
@ -181,15 +181,30 @@ class DefaultController extends AbstractController {
|
||||
$newpoll->setPassword( $data[ 'password' ] );
|
||||
}
|
||||
// manage choices
|
||||
$choices = $data[ 'answers' ];
|
||||
// text kind of answers, dates are below
|
||||
if ( $data[ 'pollType' ] == 'classic' ) {
|
||||
$choices = $data[ 'dateList' ];
|
||||
foreach ( $choices as $c ) {
|
||||
$newChoice = new Choice();
|
||||
$newChoice
|
||||
->setPoll( $newpoll )
|
||||
->setUrl( $c[ 'url' ] )
|
||||
->setName( $c[ 'text' ] );
|
||||
// ->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->flush();
|
||||
$precision = '';
|
||||
@ -215,7 +230,10 @@ class DefaultController extends AbstractController {
|
||||
* requirements = {"poll_id"="\d+"}
|
||||
* )
|
||||
*/
|
||||
public function getPollCommentsAction( Poll $poll ) {
|
||||
public
|
||||
function getPollCommentsAction(
|
||||
Poll $poll
|
||||
) {
|
||||
return $this->json( [
|
||||
'message' => 'here are your comments of the poll',
|
||||
'data' => $poll->getComments(),
|
||||
@ -230,7 +248,11 @@ class DefaultController extends AbstractController {
|
||||
* requirements = {"poll_id"="\d+"}
|
||||
* )
|
||||
*/
|
||||
public function getPollConfig( Poll $poll, Request $request ) {
|
||||
public
|
||||
function getPollConfig(
|
||||
Poll $poll,
|
||||
Request $request
|
||||
) {
|
||||
$pass = $poll->getPassword();
|
||||
$data = $request->getContent();
|
||||
$data = json_decode( $data, true );
|
||||
@ -289,7 +311,8 @@ class DefaultController extends AbstractController {
|
||||
* name = "clean_expired_polls",
|
||||
* )
|
||||
*/
|
||||
public function cleanExpiredPolls() {
|
||||
public
|
||||
function cleanExpiredPolls() {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$emPoll = $this->getDoctrine()->getRepository( Poll::class );
|
||||
|
||||
@ -324,7 +347,11 @@ class DefaultController extends AbstractController {
|
||||
* 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
|
||||
// update only if we have the admin key
|
||||
@ -345,7 +372,11 @@ class DefaultController extends AbstractController {
|
||||
* requirements = {"content"="\w+", "poll_id"="\d+"}
|
||||
* )
|
||||
*/
|
||||
public function newCommentAction( Poll $poll, Request $request ) {
|
||||
public
|
||||
function newCommentAction(
|
||||
Poll $poll,
|
||||
Request $request
|
||||
) {
|
||||
if ( ! $poll ) {
|
||||
return $this->json( [ 'message' => 'poll not found' ], 404 );
|
||||
}
|
||||
@ -426,7 +457,11 @@ class DefaultController extends AbstractController {
|
||||
* requirements = {"content"="\w+", "poll_id"="\d+"}
|
||||
* )
|
||||
*/
|
||||
public function newVoteStackAction( Poll $poll, Request $request ) {
|
||||
public
|
||||
function newVoteStackAction(
|
||||
Poll $poll,
|
||||
Request $request
|
||||
) {
|
||||
if ( ! $poll ) {
|
||||
return $this->json( [ 'message' => 'poll not found' ], 404 );
|
||||
}
|
||||
@ -523,7 +558,11 @@ class DefaultController extends AbstractController {
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function deletePollAction( Poll $poll, $accessToken ) {
|
||||
public
|
||||
function deletePollAction(
|
||||
Poll $poll,
|
||||
$accessToken
|
||||
) {
|
||||
|
||||
if ( $accessToken == $poll->getAdminKey() ) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
@ -554,7 +593,11 @@ class DefaultController extends AbstractController {
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function deletePollCommentsAction( Poll $poll, $accessToken ) {
|
||||
public
|
||||
function deletePollCommentsAction(
|
||||
Poll $poll,
|
||||
$accessToken
|
||||
) {
|
||||
if ( $accessToken == $poll->getAdminKey() ) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$length = count( $poll->getComments() );
|
||||
@ -579,7 +622,11 @@ class DefaultController extends AbstractController {
|
||||
* )
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function deletePollVotesAction( Poll $poll, $accessToken ) {
|
||||
public
|
||||
function deletePollVotesAction(
|
||||
Poll $poll,
|
||||
$accessToken
|
||||
) {
|
||||
if ( $accessToken == $poll->getAdminKey() ) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$length = count( $poll->getVotes() );
|
||||
|
Loading…
Reference in New Issue
Block a user