Commit 090d252b authored by therealwa3er's avatar therealwa3er
Browse files

clean code

parent 4f0f8bcb
......@@ -9,82 +9,74 @@ use Alecsia\AnnotationBundle\Controller\Export\HTMLExport;
use Alecsia\AnnotationBundle\Controller\Communication\CRUDReponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
// provides functions to ask the user for more information. It is included in the default helper set, which you can get by calling getHelperSet()
use Symfony\Component\Console\Helper\DialogHelper;
//EntityServices
use Alecsia\AnnotationBundle\Service\EntityServices\UEService;
class NotesExporterController extends AlecsiaController {
// export not without freezing notes
// public function exportNoteWithoutFreezNot(){
// $em = $this->getDoctrine()->getManager();
// $this->setError("exporter les notes", "Les note ne seront pas geler.");
// }
private function createCSVFile($twigFile, $csvFilename, $data) {
$response = $this->render('AnnotationBundle:Notes:' . $twigFile, $data);
$response->headers->set('Content-Type', 'text/csv');
$response->headers->set('Content-Disposition', 'attachment; filename="' . $csvFilename);
private function createCSVFile($twigFile, $csvFilename, $data) {
$response = $this->render('AnnotationBundle:Notes:' . $twigFile, $data);
return $response;
}
$response->headers->set('Content-Type', 'text/csv');
private function noNoteToExport() {
$this->setError("Impossible d'exporter les notes", "Il n'y a aucune note à exporter (il faut commencer par les geler).");
return new RedirectResponse($this->getRequest()->headers->get('referer'));
}
public function createCSVFileForSujetGroupAction($sujet_id, $group_id) {
$em = $this->getDoctrine()->getManager();
$request = $this->getRequest();
$response->headers->set('Content-Disposition', 'attachment; filename="' . $csvFilename);
$sujet_obj = $em->getRepository('AnnotationBundle:Sujet')->findOneById($sujet_id);
$group = $em->getRepository('AnnotationBundle:Group')->findOneById($group_id);
if (!$sujet_obj || !$sujet_obj->isFrozen()) {
$this->setError("Impossible d'exporter les notes", "Le rendu n'a pas été trouvé ou n'a pas été gelé");
return new RedirectResponse($this->getRequest()->headers->get('referer'));
}
return $response;
}
$notes = $sujet_obj->getNotes(array($group_id));
private function noNoteToExport() {
$this->setError("Impossible d'exporter les notes", "Il n'y a aucune note à exporter (il faut commencer par les geler).");
return new RedirectResponse($this->getRequest()->headers->get('referer'));
}
$shortSujetName = preg_split('/[\s\/|!]+/', $sujet_obj->getNom());
$shortSujetName = $shortSujetName[0];
public function createCSVFileForSujetGroupAction($sujet_id, $group_id) {
$em = $this->getDoctrine()->getManager();
$request = $this->getRequest();
if (empty($notes)) {
return $this->noNoteToExport();
}
$sujet_obj = $em->getRepository('AnnotationBundle:Sujet')->findOneById($sujet_id);
$group = $em->getRepository('AnnotationBundle:Group')->findOneById($group_id);
if (!$sujet_obj || !$sujet_obj->isFrozen()) {
$this->setError("Impossible d'exporter les notes", "Le rendu n'a pas été trouvé ou n'a pas été gelé");
return new RedirectResponse($this->getRequest()->headers->get('referer'));
}
return $this->createCSVFile('notes.csv.twig', 'notes_' . $sujet_obj->getUE()->getNomCourt() . '_' . $shortSujetName . (empty($group->getName()) ? '' : '_' . $group->getName()) . '.csv', array('notes' => $notes, 'subject' => $sujet_obj));
}
$notes = $sujet_obj->getNotes(array($group_id));
$shortSujetName = preg_split('/[\s\/|!]+/', $sujet_obj->getNom());
$shortSujetName = $shortSujetName[0];
if (empty($notes)) {
return $this->noNoteToExport();
}
public function createCSVFileForUEAction($ue_id) {
$targetURL = $this->generateUrl('AlecsiaShowActiveUEs');
return $this->createCSVFile('notes.csv.twig', 'notes_' . $sujet_obj->getUE()->getNomCourt() . '_' . $shortSujetName . (empty($group->getName()) ? '' : '_' . $group->getName()) . '.csv', array('notes' => $notes, 'subject' => $sujet_obj));
}
$em = $this->getDoctrine()->getManager();
$request = $this->getRequest();
$ue_obj = $em->getRepository('AnnotationBundle:UE')->findOneById($ue_id);
if (!$ue_obj) {
$this->setError("Impossible d'exporter les notes", "L'UE n'a pas été trouvée");
return new RedirectResponse($this->getRequest()->headers->get('referer'));
}
//si certtain sujet ne sont pas gelé
if(!$ue_obj->isAllSujetFrozen()){
$this->setSuccess("certain sujet ne sont pas!");
}
//Meme les si les notes sont pas gelé on prend les notes avec la fonction getFrozenAndNonFrozenNotes,
$notes = $ue_obj->getFrozenAndNonFrozenNotes();
public function createCSVFileForUEAction($ue_id) {
$targetURL = $this->generateUrl('AlecsiaShowActiveUEs');
if (empty($notes['student'])) {
return $this->noNoteToExport();
}
return $this->createCSVFile('notes_ue.csv.twig', 'notes_' . $ue_obj->getNomCourt() . '.csv', array('notes' => $notes));
}
}
$em = $this->getDoctrine()->getManager();
$request = $this->getRequest();
$ue_obj = $em->getRepository('AnnotationBundle:UE')->findOneById($ue_id);
if (!$ue_obj) {
$this->setError("Impossible d'exporter les notes", "L'UE n'a pas été trouvée");
return new RedirectResponse($this->getRequest()->headers->get('referer'));
}
//si certtain sujet ne sont pas gelé
if(!$ue_obj->isAllSujetFrozen()){
$this->setSuccess("certain sujet ne sont pas!");
}
else{
$this->setSuccess("tout les sujets sont gelés!");
}
//Meme les si les notes sont pas gelé on prend les notes avec la fonction getFrozenAndNonFrozenNotes,
$notes = $ue_obj->getFrozenAndNonFrozenNotes();
if (empty($notes['student'])) {
return $this->noNoteToExport();
}
return $this->createCSVFile('notes_ue.csv.twig', 'notes_' . $ue_obj->getNomCourt() . '.csv', array('notes' => $notes));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment