plan to add stacks of vote

This commit is contained in:
Tykayn 2021-04-17 16:07:35 +02:00 committed by tykayn
parent 116e1237fa
commit b7358021a7
1 changed files with 55 additions and 1 deletions

View File

@ -3,6 +3,8 @@
namespace App\Controller;
//use FOS\RestBundle\Controller\Annotations\Get;
//use FOS\RestBundle\Controller\Annotations\Route;
use App\Entity\Choice;
use App\Entity\StackOfVotes;
use App\Repository\PollRepository;
use App\Service\MailService;
use FOS\RestBundle\Controller\Annotations\Get;
@ -46,7 +48,6 @@ class MigrationController extends FramadateController {
$this->getParameter( 'OLD_DATABASE_PASS' ),
$pdo_options );
$res_Poll = $bdd->query( 'SELECT * FROM fd_poll' );
//boucler pour ranger
while ( $d = $res_Poll->fetch( \PDO::FETCH_OBJ ) ) {
echo "<html> <body> ";
echo "<br> migration du sondage $d->title , $d->id , ";
@ -80,6 +81,59 @@ class MigrationController extends FramadateController {
// $em->persist( $owner );
// $em->persist( $newPoll );
}
// get choices, slots and link them with poll by their slug
$res_slots = $bdd->query( 'SELECT * FROM fd_slot' );
while ( $d = $res_slots->fetch( \PDO::FETCH_OBJ ) ) {
$pollSlug = $d->poll_id;
$poll = $pollsBySlug[$pollSlug];
$moments = explode(',' , $d->moments);
foreach ( $moments as $moment ) {
$newChoice = new Choice();
$newChoice
->setPoll($poll)
->setDateTime($d->title)
->setName($moment);
$poll->addChoice($newChoice);
// $em->persist( $newChoice );
// $em->persist( $newPoll );
}
}
// get choices, slots and link them with poll by their slug
$res_votes = $bdd->query( 'SELECT * FROM fd_vote' );
while ( $d = $res_votes->fetch( \PDO::FETCH_OBJ ) ) {
$pollSlug = $d->poll_id;
$poll = $pollsBySlug[ $pollSlug ];
$newStack = new StackOfVotes();
$newStack->setPoll($poll)
->setPseudo($d->name)
;
// each choice answer is encoded in a value :
// space character : no answer, 0 : no , 1 : maybe , 2 : yes
$voteCodes = explode( '', $d->moments );
// get choices of the poll and answer accordingly
$ii=0;
foreach ( $voteCodes as $vote_code ) {
if($vote_code !== ' '){
// TODO
// $newStack->addVote($newVote);
}
$ii++;
}
$poll->addStackOfVotes($newStack);
}
// $em->flush();