/** * @Route("/mail/{id}") */ public function mailAction($id) { $t = new Test(); $t->setId(-1); $t->setDate(new \DateTime()); $t->setName("Exam de test"); $t->setNumReminder($id); $teacher = new Teacher(); $teacher->setId(-1); $teacher->setName("Prénom"); $teacher->setSurname("Nom"); $t->setTeacher($teacher); $c = new Classroom(); $c->setName("Class_A"); $t->addClassroom($c); $c = new Classroom(); $c->setName("Class_B"); $t->addClassroom($c); $html = $this->renderView("CorrigeatonMailerBundle:Mail:mail-" . $id . ".html.twig", array("test" => $t)); $css = file_get_contents($this->get("templating.helper.assets")->getUrl('bundles/corrigeatonmailer/css/main.css')); $inline = new CssToInlineStyles($html, $css); return new Response($inline->convert()); }
/** * @Route("/mails/{id}", name="mail_show") */ public function mailAction($id) { if (!in_array($id, array("1", "2", "3", "4", "5", "6", "7", "corrected"))) { throw $this->createAccessDeniedException("Not found"); } $t = new Test(); $t->setId(-1); $t->setDate(new \DateTime()); $t->setName("Exam de test"); $t->setNumReminder($id); $teacher = new Teacher(); $teacher->setId(-1); $teacher->setName("Prénom"); $teacher->setSurname("Nom"); $t->setTeacher($teacher); $c = new Classroom(); $c->setName("Class A"); $t->addClassroom($c); $c = new Classroom(); $c->setName("Class B"); $t->addClassroom($c); $html = $this->renderView("CorrigeatonMailerBundle:Mail:mail-" . $id . ".html.twig", array("test" => $t)); $css = file_get_contents($this->get("templating.helper.assets")->getUrl('bundles/corrigeatonmailer/css/main.css')); $inline = new CssToInlineStyles($html, $css); return new Response($inline->convert()); }
/** * Find in INSA annuaire the teacher * @param $nameAndInitial * @return Teacher * @throws \Corrigeaton\Bundle\ScheduleBundle\Exception\ResourceNotFoundException */ private function findTeacherAnnuaire($surname, $initial) { $teacher = new Teacher(); $teacher->setADEname($surname); // Data post to send $data = array('texteNom' => $surname); // Get page detail for a teacher $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $this->urlAnnuaire); curl_setopt($ch, CURLOPT_POST, count($data)); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Follow 302 redirection return by the first page curl_setopt($ch, CURLOPT_PROXY, "wwwcache.insa-toulouse.fr:3128"); $output = curl_exec($ch); curl_close($ch); $crawler = new Crawler($output); $detail = $crawler->filter("#content > dl.detail"); if ($detail->count() === 1) { // Have 1 result $detail = $detail->children(); $teacher->setSurname($detail->eq(1)->html()); $teacher->setName($detail->eq(3)->html()); $teacher->setEmail($this->clearEmail($detail->eq(5)->children()->html())); } else { // Have more or 0 result $results = $crawler->filter("#content div.results"); $teachers = array(); if ($results->count() === 1) { // Have more results $results->filter("tbody > tr")->each(function ($node, $i) use($surname, $initial, &$teachers) { $node = $node->children(); if (strcasecmp($node->eq(0)->html(), $surname) === 0 && stripos($node->eq(1)->html(), $initial) === 0) { $teacher = new Teacher(); $teacher->setADEname($surname); $teacher->setSurname($node->eq(0)->html()); $teacher->setName($node->eq(1)->html()); $teacher->setEmail($this->clearEmail($node->eq(2)->children()->html())); $teachers[] = $teacher; } }); if (count($teachers) == 1) { $teacher = $teachers[0]; } else { throw new ResourceNotFoundException($teacher, "Teacher \"" . $surname . ' ' . $initial . "\" not found"); } } else { // Unknown throw new ResourceNotFoundException($teacher, "Teacher \"" . $surname . ' ' . $initial . "\" not found"); } } $this->em->persist($teacher); $this->em->flush(); return $teacher; }