Last active
December 25, 2015 23:18
-
-
Save girub/7055646 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Pagina compilo ecm. | |
* | |
* @Route("/{accreditamento_id}/{anagrafica_id}/compila/ecm", name="compila_ecm") | |
* @Template() | |
*/ | |
public function compilaEcmAction($accreditamento_id, $anagrafica_id) { | |
$entityManager = $this->getDoctrine() | |
->getEntityManager(); | |
//##################### INIZIO ################################### | |
//controllo se già ha compilato il questionario ecm, se si | |
//ridirigo l'utente al questionario di valutazione | |
$query = $entityManager->createQuery( | |
'SELECT a.anagrafica_id FROM AccreditamentiCongressiBundle:RisposteUtentiQuestionarioEcm a | |
WHERE a.anagrafica_id = :id' | |
)->setParameter('id', $anagrafica_id); | |
$risposteEcm = $query->getResult(); | |
// die($risposteEcm[0]['anagrafica_id']); | |
if (isset($risposteEcm[0]['anagrafica_id'])) { | |
// aggiungere nome e cognome | |
$this->get('session')->setFlash('notice', 'Ben tornato continua a compilare il questionario!'); | |
return $this->redirect($this->generateUrl('compila_valutazione', array( | |
'accreditamento_id' => $accreditamento_id, | |
'anagrafica_id' => $anagrafica_id, | |
))); | |
} | |
//######################## fine ################################ | |
$accreditamento = $entityManager | |
->getRepository('AccreditamentiCongressiBundle:Accreditamento') | |
->find($accreditamento_id); | |
$formDomande = $this | |
->createQuestionarioForm($accreditamento); | |
return array( | |
'formDomande' => $formDomande, | |
'accreditamento_id' => $accreditamento_id, | |
'anagrafica_id' => $anagrafica_id, | |
); | |
} | |
/** | |
* Questo metodo crea il form per un questionario a partire dal suo accretiamento. | |
* | |
* @param \Accreditamenti\CongressiBundle\Entity\Accreditamento $accreditamento | |
* @return form | |
* @throws type | |
*/ | |
private function createQuestionarioForm(Accreditamento $accreditamento) { | |
$entityManager = $this->getDoctrine() | |
->getEntityManager(); | |
$questionario = $accreditamento->getQuestionarioEcm(); | |
if (!$questionario[0]) { | |
throw $this->createNotFoundException('Unable to find QuestionarioEcm entity'); | |
} | |
$domande = $entityManager->getRepository('AccreditamentiCongressiBundle:Domanda') | |
->findDomandeDelQuestionario($questionario[0]); | |
$formBuilder = $this->createFormBuilder(); | |
$arrayDiDomande = array(); | |
/* Carico tutte quante le domande */ | |
foreach ($domande as $domanda) { | |
$arrayDiDomande[] .= $domanda->getId(); | |
} | |
/* Modifico l'ordine dell'array */ | |
shuffle($arrayDiDomande); | |
/* Costruisco il form con domande ordinate in modo randomizzato */ | |
foreach ($arrayDiDomande as $domanda) { | |
$domanda = $entityManager | |
->getRepository('AccreditamentiCongressiBundle:Domanda') | |
->find((int) $domanda); | |
$formBuilder->add("domanda_" . ($domanda->getId()) . "", 'entity', array( | |
'label' => $domanda->getDescrizione(), | |
'class' => 'AccreditamentiCongressiBundle:Risposta', | |
'multiple' => false, | |
'expanded' => true, | |
'query_builder' => function(RispostaRepository $risposta) use ($domanda) { | |
$ordinamento = rand(0, 1) == 0 ? 'ASC' : 'DESC'; | |
$elencoRisposte = $risposta->createQueryBuilder('r') | |
->where('r.domanda=:domanda') | |
->setParameter('domanda', $domanda) | |
->orderBy('r.id', $ordinamento); | |
return $elencoRisposte; | |
}, | |
)); | |
} | |
return $formBuilder->getForm() | |
->createView(); | |
} | |
/** | |
* Creates a new QuestionarioEcm entity. | |
* | |
* | |
* @Route("/{accreditamento_id}/{anagrafica_id}/controlla/questionario/ecm", name="controlla_questionario_ecm") | |
*/ | |
public function controllaQuestionarioEcmAction($accreditamento_id, $anagrafica_id) { | |
$entityManager = $this->getDoctrine() | |
->getEntityManager(); | |
$accreditamento = $entityManager | |
->getRepository('AccreditamentiCongressiBundle:Accreditamento') | |
->find($accreditamento_id); | |
$questionario = $accreditamento | |
->getQuestionarioEcm(); | |
$domande = $entityManager | |
->getRepository('AccreditamentiCongressiBundle:Domanda') | |
->findDomandeDelQuestionario($questionario[0]); | |
$anagrafica = $entityManager | |
->getRepository('AccreditamentiCongressiBundle:Anagrafica') | |
->find($anagrafica_id); | |
$request = $this->getRequest(); | |
$form = $this->createFormBuilder()->getForm(); | |
$form->bindRequest($request); | |
foreach ($domande as $domanda) { | |
if (!isset($_POST['form']['domanda_' . $domanda->getId()])) { | |
// return $this->render('AccreditamentiCongressiBundle:Accreditamento:compilaEcmError.html.twig'); | |
return $this->redirect($this->generateUrl('compila_ecm', array( | |
'accreditamento_id' => $accreditamento_id, | |
'anagrafica_id' => $anagrafica_id, | |
'form' => $form->createView() | |
))); | |
} | |
$risposte = $domanda->getRisposta(); | |
$idRispostaGiusta = null; | |
foreach ($risposte as $risposta) { | |
if ($risposta->getVero() === true) | |
$idRispostaGiusta = $risposta->getId(); | |
} | |
$idRispostaRicevuta = $_POST['form']['domanda_' . $domanda->getId()]; | |
$risposteUtenti = new \Accreditamenti\CongressiBundle\Entity\RisposteUtentiQuestionarioEcm; | |
$risposteUtenti->setAnagraficaId($anagrafica_id); | |
$risposteUtenti->setRispostaId($idRispostaRicevuta); | |
$entityManager->persist($risposteUtenti); | |
} | |
//aggiungiamo una data di compilazione | |
$dataCompilazione = \DateTime::createFromFormat('Y-m-d', date('Y-m-d')); | |
$anagrafica->setDataCompEcm($dataCompilazione); | |
//effettuo salvataggio risposte ecm | |
$entityManager->flush(); | |
//faccio un redirect su compila_valutazione (view che conterrà il questionario di valutazione) | |
return $this->redirect($this->generateUrl('compila_valutazione', array( | |
'accreditamento_id' => $accreditamento_id, | |
'anagrafica_id' => $anagrafica_id | |
))); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form action="{{ path('controlla_questionario_ecm', {'accreditamento_id': accreditamento_id,'anagrafica_id': anagrafica_id}) }}" method="post"> | |
{{form_widget(formDomande, { 'attr' : { 'class' : 'myForm' } })}} | |
<button type="submit">Continua</button> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment