Bonjour à tous, j'ai un petit probème avec les formulaire. je m'explique
J'ai une entité evaluation, une entité Competence et une entité Score
Une evaluation peut avoir plusieurs compétence et une competence peut apparaitre dans plusieurs évaluation. j'ai dont utilisé une relation manyTomany.
l'entité Score est associé à evaluation et competence par une relation ManyToOne. J'ai dont finalement ca :
Evaluation.php
<?php
namespace App\ProfBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Evaluation
*
* @ORM\Table(name="evaluation")
* @ORM\Entity(repositoryClass="App\ProfBundle\Repository\EvaluationRepository")
*/
class Evaluation
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="App\UserBundle\Entity\User")
* @ORM\JoinColumn(nullable=false)
*/
private $user;
/**
* @ORM\ManyToMany(targetEntity="App\ProfBundle\Entity\Competence", cascade={"persist"})
*/
private $competences;
/**
* @ORM\ManyToOne(targetEntity="App\AdminBundle\Entity\Classe")
* @ORM\JoinColumn(nullable=true)
*/
private $classe;
/**
* @var string
*
* @ORM\Column(name="nom", type="string", length=255)
*/
private $nom;
/**
* @var \DateTime
*
* @ORM\Column(name="datedebut", type="date")
*/
private $datedebut;
/**
* @var \DateTime
*
* @ORM\Column(name="dateend", type="date")
*/
private $dateend;
/**
* @var bool
*
* @ORM\Column(name="statut", type="boolean")
*/
private $statut;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set nom
*
* @param string $nom
* @return Evaluation
*/
public function setNom($nom)
{
$this->nom = $nom;
return $this;
}
/**
* Get nom
*
* @return string
*/
public function getNom()
{
return $this->nom;
}
/**
* Set datedebut
*
* @param \DateTime $datedebut
* @return Evaluation
*/
public function setDatedebut($datedebut)
{
$this->datedebut = $datedebut;
return $this;
}
/**
* Get datedebut
*
* @return \DateTime
*/
public function getDatedebut()
{
return $this->datedebut;
}
/**
* Set dateend
*
* @param \DateTime $dateend
* @return Evaluation
*/
public function setDateend($dateend)
{
$this->dateend = $dateend;
return $this;
}
/**
* Get dateend
*
* @return \DateTime
*/
public function getDateend()
{
return $this->dateend;
}
/**
* Set statut
*
* @param boolean $statut
* @return Evaluation
*/
public function setStatut($statut)
{
$this->statut = $statut;
return $this;
}
/**
* Get statut
*
* @return boolean
*/
public function getStatut()
{
return $this->statut;
}
/**
* Set classe
*
* @param \App\AdminBundle\Entity\Classe $classe
* @return Evaluation
*/
public function setClasse(\App\AdminBundle\Entity\Classe $classe)
{
$this->classe = $classe;
return $this;
}
/**
* Get classe
*
* @return \App\AdminBundle\Entity\Classe
*/
public function getClasse()
{
return $this->classe;
}
/**
* Constructor
*/
public function __construct()
{
$this->competences = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add competences
*
* @param \App\ProfBundle\Entity\Competence $competences
* @return Evaluation
*/
public function addCompetence(\App\ProfBundle\Entity\Competence $competences)
{
$this->competences[] = $competences;
return $this;
}
/**
* Remove competences
*
* @param \App\ProfBundle\Entity\Competence $competences
*/
public function removeCompetence(\App\ProfBundle\Entity\Competence $competences)
{
$this->competences->removeElement($competences);
}
/**
* Get competences
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getCompetences()
{
return $this->competences;
}
/**
* Set user
*
* @param \App\UserBundle\Entity\User $user
* @return Evaluation
*/
public function setUser(\App\UserBundle\Entity\User $user)
{
$this->user = $user;
return $this;
}
/**
* Get user
*
* @return \App\UserBundle\Entity\User
*/
public function getUser()
{
return $this->user;
}
public function __toString(){
return $this->getNom();
}
}
Competence.php
<?php
namespace App\ProfBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Competence
*
* @ORM\Table(name="competence")
* @ORM\Entity(repositoryClass="App\ProfBundle\Repository\CompetenceRepository")
*/
class Competence
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="App\ProfBundle\Entity\Matiere")
* @ORM\JoinColumn(nullable=true)
*/
private $matiere;
/**
* @ORM\ManyToOne(targetEntity="App\UserBundle\Entity\User")
* @ORM\JoinColumn(nullable=false)
*/
private $user;
/**
* @var string
*
* @ORM\Column(name="nom", type="string", length=255)
*/
private $nom;
/**
* @var bool
*
* @ORM\Column(name="statut", type="boolean")
*/
private $statut;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set nom
*
* @param string $nom
* @return Competence
*/
public function setNom($nom)
{
$this->nom = $nom;
return $this;
}
/**
* Get nom
*
* @return string
*/
public function getNom()
{
return $this->nom;
}
/**
* Set statut
*
* @param boolean $statut
* @return Competence
*/
public function setStatut($statut)
{
$this->statut = $statut;
return $this;
}
/**
* Get statut
*
* @return boolean
*/
public function getStatut()
{
return $this->statut;
}
/**
* Set matiere
*
* @param \App\ProfBundle\Entity\Matiere $matiere
* @return Competence
*/
public function setMatiere(\App\ProfBundle\Entity\Matiere $matiere)
{
$this->matiere = $matiere;
return $this;
}
/**
* Get matiere
*
* @return \App\ProfBundle\Entity\Matiere
*/
public function getMatiere()
{
return $this->matiere;
}
/**
* Set user
*
* @param \App\UserBundle\Entity\User $user
* @return Competence
*/
public function setUser(\App\UserBundle\Entity\User $user)
{
$this->user = $user;
return $this;
}
/**
* Get user
*
* @return \App\UserBundle\Entity\User
*/
public function getUser()
{
return $this->user;
}
public function __toString(){
return $this->getNom();
}
}
Score.php
<?php
namespace App\EleveBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Score
*
* @ORM\Table(name="score")
* @ORM\Entity(repositoryClass="App\EleveBundle\Repository\ScoreRepository")
*/
class Score
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="App\UserBundle\Entity\User")
* @ORM\JoinColumn(nullable=false)
*/
private $user;
/**
* @ORM\ManyToOne(targetEntity="App\ProfBundle\Entity\Competence")
* @ORM\JoinColumn(nullable=false)
*/
private $competence;
/**
* @ORM\ManyToOne(targetEntity="App\ProfBundle\Entity\Evaluation")
* @ORM\JoinColumn(nullable=false)
*/
private $evaluation;
/**
* @var int
*
* @ORM\Column(name="Score", type="integer")
*/
private $score;
/**
* @var \DateTime
*
* @ORM\Column(name="date", type="datetime")
*/
private $date;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set score
*
* @param integer $score
* @return Score
*/
public function setScore($score)
{
$this->score = $score;
return $this;
}
/**
* Get score
*
* @return integer
*/
public function getScore()
{
return $this->score;
}
/**
* Set date
*
* @param \DateTime $date
* @return Score
*/
public function setDate($date)
{
$this->date = $date;
return $this;
}
/**
* Get date
*
* @return \DateTime
*/
public function getDate()
{
return $this->date;
}
/**
* Set user
*
* @param \App\UserBundle\Entity\User $user
* @return Score
*/
public function setUser(\App\UserBundle\Entity\User $user)
{
$this->user = $user;
return $this;
}
/**
* Get user
*
* @return \App\UserBundle\Entity\User
*/
public function getUser()
{
return $this->user;
}
/**
* Set competence
*
* @param \App\ProfBundle\Entity\Competence $competence
* @return Score
*/
public function setCompetence(\App\ProfBundle\Entity\Competence $competence)
{
$this->competence = $competence;
return $this;
}
/**
* Get competence
*
* @return \App\ProfBundle\Entity\Competence
*/
public function getCompetence()
{
return $this->competence;
}
/**
* Set evaluation
*
* @param \App\profBundle\Entity\Evaluation $evaluation
* @return Score
*/
public function setEvaluation(\App\profBundle\Entity\Evaluation $evaluation)
{
$this->evaluation = $evaluation;
return $this;
}
/**
* Get evaluation
*
* @return \App\profBundle\Entity\Evaluation
*/
public function getEvaluation()
{
return $this->evaluation;
}
}
finalement, une seule valeur est envoyé par l'utilisateur, il s'agit de l'attribut score. le reste doit être gérer automatiquement
j'arrive à gerer la date en mettant la date actuelle et l'utilisateur en mettant l'utilisateur courant mais je n'arrive pas à gerer automatiquement setCompetence et setEvaluation
public function pageAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$user = $this->getUser();
$id= $request->get('id');
$affiliation=$user->getAffiliation();
//recupération des informations utilises
$evaluations = $em->getRepository('AppProfBundle:Evaluation')->findBy(
array('user' =>$affiliation));
$scores = $em->getRepository('AppEleveBundle:Score')->findAll();
$score = new Score();
// ce que j'arrive à gerer automatiquement
$user = $this->getUser();
$score->setUser($user);
$score->setDate(new \DateTime());
$form = $this->createForm('App\EleveBundle\Form\ScoreType', $score);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($score);
$em->flush();
return $this->redirectToRoute('app_eleve_page');
}
return $this->render('AppEleveBundle:Default:jungle.html.twig', array(
'score' => $score,
'form' => $form->createView(),
'evaluations' => $evaluations,
'scores' => $scores,
'id'=>$id
));
}
QUelqu'un peut-il m'aider?