1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
/////////////////////////////Entity TypeVote/////////////////////////////////////////////
class TypeVote {
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string $nom
*
* @ORM\Column(name="nom", type="string", length=255)
*/
private $nom;
}
///////////////////////////Entity Critere///////////////////////////////////////////
class Critere
{
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="My\VoteBundle\Entity\TypeVote", cascade={"persist"})
* @ORM\JoinColumn(name="TypeVote_id",nullable=false)
*/
private $typeVote;
/**
* @var string $nom
*
* @ORM\Column(name="nom", type="string", length=255)
*/
private $nom;
}
///////////////////////////////////Controlleur///////////////////////////////////
public function voteAction(Request $request, Entreprise $entreprise) {
// $test = 2 ; ladybug_dump($test); exit;
ini_set('display_errors', '1');
$voteId=12;//on suppose que le type de vote a comme id 12
$em = $this->container->get('doctrine')->getManager();
$user = $this->container->get('security.context')->getToken()->getUser();
$note = 0;
//echo get_class($user);
/* if (!is_object($user) || !$user instanceof UserInterface) {
throw new AccessDeniedException('This user does not have access to this section.');
} */
$vote = new Vote();
$vote
->setDateVote(new \DateTime())
->setUser($user)
->setEntreprise($entreprise);
$form = $this->container->get('form.factory')->create(new VoterForm(), $vote);
if ($request->getMethod() == 'POST') {
$form->bindRequest($request);
if ($form->isValid()) {
$typeVote = $this->getDoctrine() ->getRepository('MyVoteBundle:TypeVote')->find($voteId);
$vote->setTypeVote($typeVote);
$note=20;
$vote->setNote($note);
$em->persist($vote);
$em->flush();
return $this->redirect($this->generateUrl('my_vote_liste'));
}
}
return $this->container->get('templating')->renderResponse('MyVoteBundle:SearchEntreprise:vote.html.twig', array(
'entreprise' => $entreprise,
'form' => $form->createView())
);
} |
Partager