Compare commits
2 Commits
56126c6649
...
b7358021a7
Author | SHA1 | Date | |
---|---|---|---|
b7358021a7 | |||
116e1237fa |
@ -1,9 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Poll;
|
||||
//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;
|
||||
use FOS\RestBundle\Controller\Annotations\Route;
|
||||
use JMS\Serializer\Type\Exception\Exception;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use App\Entity\Owner;
|
||||
use App\Entity\Poll;
|
||||
|
||||
/**
|
||||
* Class DefaultController
|
||||
@ -31,7 +40,7 @@ class MigrationController extends FramadateController {
|
||||
$debug = '';
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$pollsByID = [];
|
||||
$pollsBySlug = [];
|
||||
|
||||
$pdo_options[ \PDO::ATTR_ERRMODE ] = \PDO::ERRMODE_EXCEPTION;
|
||||
$bdd = new \PDO( 'mysql:host=localhost;dbname=' . $this->getParameter( 'OLD_DATABASE_NAME' ),
|
||||
@ -39,26 +48,91 @@ 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 "<br> migration du sondage $d->title , $d->id";
|
||||
echo "<html> <body> ";
|
||||
echo "<br> migration du sondage $d->title , $d->id , ";
|
||||
|
||||
$u = new Poll();
|
||||
var_dump($d);
|
||||
|
||||
$u
|
||||
$newPoll = new Poll();
|
||||
$owner = new Owner();
|
||||
|
||||
$owner->setEmail( $d->admin_mail )
|
||||
->setPseudo( $d->admin_name );
|
||||
$owner->addPoll($newPoll);
|
||||
|
||||
$newPoll
|
||||
->setOwner( $owner )
|
||||
->setCustomURL( $d->id )
|
||||
// ->setKind( $d->id === 'D' ? 'date' : 'text' )
|
||||
->setHideResults( ! $d->results_publicly_visible )
|
||||
->setAdminKey( $d->admin_id )
|
||||
->setTitle( $d->title )
|
||||
// ->setVotesAllowed( $d->receiveNewVotes )
|
||||
// ->setCommentsAllowed( $d->receiveNewComments )
|
||||
->setChoicesMax( $d->ValueMax )
|
||||
->setPassword( $d->password_hash )
|
||||
->setDescription( $d->description )
|
||||
->setCreationDate( date_create( $d->creation_date ) );
|
||||
|
||||
$pollsByID[ $d->id ] = $u;
|
||||
$pollsBySlug[ $d->id ] = $newPoll;
|
||||
|
||||
|
||||
// $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);
|
||||
|
||||
// $u->setPseudo($d->pseudo)
|
||||
// ->setIp($d->ip)
|
||||
// ->setAge($d->age)
|
||||
// ->setsondage($s);
|
||||
// $em->persist( $u );
|
||||
}
|
||||
|
||||
// $em->flush();
|
||||
|
@ -58,7 +58,7 @@
|
||||
*/
|
||||
public $owner;
|
||||
/**
|
||||
* kind of poll, text or date
|
||||
* kind of poll, 'text' or 'date'
|
||||
* @ORM\Column(type="string", length=255)
|
||||
* @Serializer\Type("string")
|
||||
* @Serializer\Expose()
|
||||
@ -72,6 +72,41 @@
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
public $allowedAnswers;
|
||||
|
||||
/**
|
||||
* people can add votes
|
||||
* @ORM\Column(type="boolean", nullable=true)
|
||||
* @Serializer\Type("boolean")
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
public $votesAllowed;
|
||||
/**
|
||||
* 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.
|
||||
* @ORM\Column(type="number", nullable=true)
|
||||
* @Serializer\Type("number")
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
public $votesMax;
|
||||
|
||||
/**
|
||||
* max number of choices people can answer in a stack of vote. for text polls only, not date kind.
|
||||
* by default, people can check as many answers as they want.
|
||||
* If the question is "check your 3 favourite flavours" and displays 10 flavours, only the first 3 clicked will be taken into account. GUI should be able to make this clear and togglable so that people can change their 3 favourite flavours in their answer.
|
||||
* @ORM\Column(type="number", nullable=true)
|
||||
* @Serializer\Type("number")
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
public $choicesMax;
|
||||
|
||||
/**
|
||||
* people can add comments
|
||||
* @ORM\Column(type="boolean", nullable=true)
|
||||
* @Serializer\Type("boolean")
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
public $commentsAllowed;
|
||||
|
||||
/**
|
||||
* kind of way the people can modify the poll
|
||||
* everybody - can modify votes
|
||||
|
Loading…
Reference in New Issue
Block a user