src/Controller/CampagneController.php line 181

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Appel;
  4. use App\Entity\Apprenant;
  5. use App\Entity\Client;
  6. use App\Entity\Compagne;
  7. use App\Entity\Cours;
  8. use App\Entity\Inscription;
  9. use App\Entity\Priorite;
  10. use App\Entity\Projet;
  11. use App\Entity\Tache;
  12. use App\Entity\Utilisateur;
  13. use App\Form\CompagneType;
  14. use App\Service\NewDoceboApi;
  15. use App\Service\Notification;
  16. use App\Service\Helper;
  17. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  18. use Symfony\Component\HttpFoundation\JsonResponse;
  19. use Symfony\Component\HttpFoundation\Request;
  20. use Symfony\Component\Routing\Annotation\Route;
  21. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  22. use PhpOffice\PhpSpreadsheet\Style\Fill;
  23. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  24. /**
  25. * Compagne controller.
  26. *
  27. * @Route("campagne")
  28. */
  29. class CampagneController extends AbstractController
  30. {
  31. /**
  32. * @Route("/liste-des-campagnes/OP", name="campagne_list")
  33. */
  34. public function campagne_list()
  35. {
  36. $compagnes = $this->getDoctrine()->getRepository(Compagne::class)->findActivesWithClient();
  37. return $this->render('campagne/index.html.twig', array_merge(
  38. ['compagnes' => $compagnes],
  39. $this->countsCompagnes($compagnes)
  40. ));
  41. }
  42. /**
  43. * Compteurs (tâches, appels) par campagne pour les listes
  44. */
  45. private function countsCompagnes(array $compagnes)
  46. {
  47. $ids = array_map(function ($compagne) {
  48. return $compagne->getId();
  49. }, $compagnes);
  50. $tacheRepository = $this->getDoctrine()->getRepository(Tache::class);
  51. return [
  52. 'nbTaches' => $tacheRepository->countByCompagnes($ids),
  53. 'nbAppels' => $tacheRepository->countAppelsByCompagnes($ids),
  54. ];
  55. }
  56. /**
  57. * @Route("/liste-des-campagnes-archive/OP", name="campagne_list_archive")
  58. */
  59. public function campagne_list_archive()
  60. {
  61. set_time_limit(180);
  62. // $user = $this->getUser();
  63. $compagnes = $this->getDoctrine()->getRepository(Compagne::class)->findByArchiveLastYear();
  64. // $priorites = array();
  65. // foreach ($compagnes as $key => $compagne) {
  66. // $priorite = $this->getDoctrine()->getRepository(Priorite::class)->findBy(['agent' => $user, 'campagne' => $compagne]);
  67. // if ($priorite) {
  68. // $priorites[$key] = $priorite[0]->getNiveau();
  69. // } else {
  70. // $priorites[$key] = 'Non défini';
  71. // }
  72. // }
  73. return $this->render('campagne/listearchives.html.twig', array_merge(
  74. ['compagnes' => $compagnes],
  75. $this->countsCompagnes($compagnes)
  76. ));
  77. }
  78. /**
  79. * @Route("/new/SP", name="campagne_add")
  80. */
  81. public function campagne_add(Request $request)
  82. {
  83. $userlogin = $this->getUser();
  84. $compagne = new Compagne();
  85. $form = $this->createForm(CompagneType::class, $compagne);
  86. $form->handleRequest($request);
  87. $em = $this->getDoctrine()->getManager();
  88. $clients = $this->getDoctrine()->getRepository(Client::class)->findClientWithProjects();
  89. if ($form->isSubmitted() && $form->isValid()) {
  90. $projectId = $_POST['projet'];
  91. $mode = $_POST['mode'];
  92. $statut = $_POST['statut'];
  93. if (isset($_POST['cours'])) {
  94. $idModule = $_POST['cours'];
  95. $module = $this->getDoctrine()->getRepository(Cours::class)->findOneById($idModule);
  96. $compagne->setCours($module);
  97. }
  98. $compagne->setStatut($statut);
  99. $projet = $this->getDoctrine()->getRepository(Projet::class)->findOneBy(["id" => $projectId]);
  100. $compagne->setProjet($projet);
  101. $compagne->setForceVip($_POST['force_vip']);
  102. $compagne->setProgression(0);
  103. $datefr = date("Y-m-d\TH:i:s", strtotime("1 hour"));
  104. $compagne->setDateCreation($datefr);
  105. $compagne->setCreateur($userlogin);
  106. $inscriptions = $this->getDoctrine()->getRepository(Inscription::class)->findInscriptionNotCategorie($projet, 5);
  107. $helper = new Helper($this->getDoctrine());
  108. $objectif = $helper->CalcObjectif($inscriptions);
  109. $compagne->setObjectif($objectif);
  110. $dateRange = $_POST['dateRange'];
  111. $dates = explode(" - ", $dateRange);
  112. $compagne->setDateDebut(date_create($dates[0]));
  113. $compagne->setDateFin(date_create($dates[1]));
  114. $compagne->setState(2);
  115. $em->persist($compagne);
  116. $em->flush();
  117. // $notification = new Notification($this->getDoctrine());
  118. // $actualite = $notification->Actualite($userlogin, "a créé une nouvelle campagne " . $compagne->getNom(), $compagne->getId(), "compagne_show");
  119. // $notification->Suivi($actualite);
  120. if ($mode == 1) {
  121. $helper->TacheCour($inscriptions, $compagne, $module, $statut);
  122. } else {
  123. $helper->Tache($inscriptions, $compagne);
  124. }
  125. return $this->redirectToRoute('compagne_show', ['id' => $compagne->getId()]);
  126. }
  127. return $this->render('campagne/add.html.twig', [
  128. 'compagne' => $compagne,
  129. 'form' => $form->createView(),
  130. 'clients' => $clients,
  131. ]);
  132. }
  133. /**
  134. * @Route("/{id}/OP", name="compagne_show")
  135. */
  136. public function compagne_show(Compagne $campagne)
  137. {
  138. $em = $this->getDoctrine()->getManager();
  139. $user = $this->getUser();
  140. $last_appel = null;
  141. $in_or_out = null;
  142. $validPeople = $campagne->getValideNumbers();
  143. $operateurs = $em->getRepository(Utilisateur::class)->findByDepartement(4);
  144. foreach ($campagne->getTaches() as $key1 => $tach) {
  145. $gsm = $tach->getApprenant()->getGsm();
  146. if (strpos($gsm, ' ') !== false) {
  147. $gsm = str_replace(' ', '', $gsm);
  148. $tach->getApprenant()->setGsm($gsm);
  149. $em->persist($tach);
  150. $em->flush();
  151. }
  152. $in_or_out[$key1] = 0;
  153. if (in_array($tach->getApprenant(), $validPeople)) {
  154. $in_or_out[$key1] = 1;
  155. }
  156. $last_appel[$key1]['semaine'] = date('W', strtotime($tach->getApprenant()->getLastAccess()));
  157. $appels = $em->getRepository(Tache::class)->findLastAppel($tach->getId());
  158. $last_appel[$key1]['date'] = ($appels) ? $appels[0]->getDate() : null;
  159. $last_appel[$key1]['statut'] = ($appels) ? $appels[0]->getStatut()->getName() : null;
  160. }
  161. $priorite = $this->getDoctrine()->getRepository(Priorite::class)->findOneBy(['agent' => $user, 'campagne' => $campagne]);
  162. return $this->render('campagne/showSP.html.twig', [
  163. 'last_appels' => $last_appel,
  164. 'in_or_out' => $in_or_out,
  165. 'compagne' => $campagne,
  166. 'priorite' => $priorite,
  167. 'operateurs' => $operateurs
  168. ]);
  169. }
  170. /**
  171. * @Route("/projets-by-client/SP", name="projets_by_client")
  172. */
  173. public function projets_by_client(Request $request)
  174. {
  175. if ($request->isXmlHttpRequest()) {
  176. if (array_key_exists('idClient', $_POST)) {
  177. $idClient = $_POST['idClient'];
  178. $projets = $this->getDoctrine()->getRepository(Projet::class)->findByClient($idClient);
  179. $projetsJson = array();
  180. $idx = 0;
  181. foreach ($projets as $projet) {
  182. $inscriptions = $this->getDoctrine()->getRepository(Inscription::class)->findByProjet($projet);
  183. $temp = [
  184. 'id' => $projet->getId(),
  185. 'nom' => $projet->getNom(),
  186. ];
  187. if (count($inscriptions) > 0 and $projet->getActif() == 1) {
  188. $temp['actif'] = "";
  189. } else {
  190. $temp['actif'] = "disabled";
  191. }
  192. $projetsJson[$idx++] = $temp;
  193. }
  194. // $projetsJson[$idx]['codeClient'] = $client[0]->getCode();
  195. return new JsonResponse($projetsJson);
  196. } elseif (array_key_exists('idProjet', $_POST)) {
  197. $idProjet = $_POST['idProjet'];
  198. $projet = $this->getDoctrine()->getRepository(Projet::class)->findById($idProjet);
  199. $jsonData1 = array(
  200. 'codeProjet' => str_replace(" ", "-", $projet[0]->getNom()),
  201. );
  202. return new JsonResponse($jsonData1);
  203. }
  204. }
  205. }
  206. /**
  207. * @Route("/csv/check-apprenants/SP", name="campagne_csv_check", methods={"POST"})
  208. */
  209. public function campagne_csv_check(Request $request)
  210. {
  211. $file = $request->files->get('csv');
  212. if (!$file || !in_array(strtolower($file->getClientOriginalExtension()), ['csv', 'txt'])) {
  213. return new JsonResponse(['message' => 'Veuillez importer un fichier CSV valide'], 400);
  214. }
  215. $handle = fopen($file->getPathname(), 'r');
  216. $firstLine = fgets($handle);
  217. $delimiter = (substr_count($firstLine, ';') > substr_count($firstLine, ',')) ? ';' : ',';
  218. rewind($handle);
  219. $usernames = [];
  220. while (($row = fgetcsv($handle, 0, $delimiter)) !== false) {
  221. $username = trim(str_replace("\xEF\xBB\xBF", '', (string) $row[0]));
  222. if ($username === '' || strtolower($username) === 'username') {
  223. continue;
  224. }
  225. $usernames[strtolower($username)] = $username;
  226. }
  227. fclose($handle);
  228. if (!count($usernames)) {
  229. return new JsonResponse(['message' => 'Le fichier CSV ne contient aucun username'], 400);
  230. }
  231. $apprenants = $this->getDoctrine()->getRepository(Apprenant::class)->findBy(['username' => array_values($usernames)]);
  232. $found = [];
  233. foreach ($apprenants as $apprenant) {
  234. $key = strtolower(trim($apprenant->getUsername()));
  235. if (!isset($found[$key])) {
  236. $found[$key] = $apprenant;
  237. }
  238. }
  239. $exist = $notExist = [];
  240. foreach ($usernames as $key => $username) {
  241. if (isset($found[$key])) {
  242. $apprenant = $found[$key];
  243. $exist[] = [
  244. 'id' => $apprenant->getId(),
  245. 'username' => $apprenant->getUsername(),
  246. 'firstname' => $apprenant->getFirstname(),
  247. 'lastname' => $apprenant->getLastname(),
  248. 'email' => $apprenant->getEmail(),
  249. ];
  250. } else {
  251. $notExist[] = $username;
  252. }
  253. }
  254. return new JsonResponse(['exist' => $exist, 'notExist' => $notExist]);
  255. }
  256. /**
  257. * @Route("/csv/create/SP", name="campagne_csv_create", methods={"POST"})
  258. */
  259. public function campagne_csv_create(Request $request)
  260. {
  261. $em = $this->getDoctrine()->getManager();
  262. $client = $this->getDoctrine()->getRepository(Client::class)->find($request->request->get('client'));
  263. $ids = (array) ($request->request->all()['apprenants'] ?? []);
  264. $apprenants = count($ids) ? $this->getDoctrine()->getRepository(Apprenant::class)->findBy(['id' => $ids]) : [];
  265. if (!$client || !count($apprenants)) {
  266. return new JsonResponse(['message' => 'Client ou apprenants manquants'], 400);
  267. }
  268. $title = trim((string) $request->request->get('title', ''));
  269. $script = trim((string) $request->request->get('script', ''));
  270. if ($title === '' || !filter_var($script, FILTER_VALIDATE_URL)) {
  271. return new JsonResponse(['message' => "Titre et script d'appel (URL valide) obligatoires"], 400);
  272. }
  273. $nom = 'CSV-' . $client->getCode() . '-' . preg_replace('/\s+/', '-', $title) . '-' . date('d-m-Y');
  274. $compagne = new Compagne();
  275. $compagne->setType(4);
  276. $compagne->setNom(mb_substr($nom, 0, 255));
  277. $compagne->setDescription($script);
  278. $compagne->setProjet(null);
  279. $compagne->setStatut(null);
  280. $compagne->setForceVip((bool) $request->request->get('force_vip'));
  281. $compagne->setProgression(0);
  282. $compagne->setDateCreation(date("Y-m-d\TH:i:s", strtotime("1 hour")));
  283. $compagne->setCreateur($this->getUser());
  284. $compagne->setDateDebut(new \DateTime('today'));
  285. $compagne->setDateFin(new \DateTime('+1 month'));
  286. $compagne->setState(2);
  287. $helper = new Helper($this->getDoctrine());
  288. $compagne->setObjectif($helper->CalcObjectifApprenants($apprenants));
  289. $em->persist($compagne);
  290. $em->flush();
  291. $helper->TacheApprenants($apprenants, $compagne);
  292. $message = 'La campagne ' . $compagne->getNom() . ' a été créée avec succès (' . count($apprenants) . ' apprenants)';
  293. $this->addFlash('success', $message);
  294. return new JsonResponse([
  295. 'success' => true,
  296. 'message' => $message,
  297. 'redirect' => $this->generateUrl('compagne_show', ['id' => $compagne->getId()]),
  298. ]);
  299. }
  300. /**
  301. * @Route("/{id}/edit/CH", name="compagne_edit")
  302. */
  303. public function compagne_edit(Request $request, Compagne $compagne)
  304. {
  305. $em = $this->getDoctrine()->getManager();
  306. $editForm = $this->createForm(CompagneType::class, $compagne);
  307. $editForm->handleRequest($request);
  308. if ($editForm->isSubmitted() && $editForm->isValid()) {
  309. $utilisateurs = $this->getDoctrine()->getRepository(Utilisateur::class)->findAll();
  310. foreach ($utilisateurs as $utilisateur) {
  311. $utilisateur->removeCompagne($compagne);
  312. $em->persist($utilisateur);
  313. }
  314. $em->flush();
  315. $dateRange = $_POST['dateRange'];
  316. $dates = explode(" - ", $dateRange);
  317. $dateBegin = date_create($dates[0]);
  318. $dateEnd = date_create($dates[1]);
  319. $compagne->setDateDebut($dateBegin);
  320. $compagne->setDateFin($dateEnd);
  321. $compagne->setForceVip($_POST["force_vip"]);
  322. $em->persist($compagne);
  323. $em->flush();
  324. $cols = $compagne->getCollaborateurs();
  325. if (!empty($cols)) {
  326. foreach ($cols as $col) {
  327. $collab = $this->getDoctrine()->getRepository(Utilisateur::class)->findById($col);
  328. $collab[0]->addCompagne($compagne);
  329. $em->persist($collab[0]);
  330. $priorite = new Priorite();
  331. $priorite->setNiveau($_POST['priorite']);
  332. $priorite->setAgent($collab[0]);
  333. $priorite->setCampagne($compagne);
  334. $em->persist($priorite);
  335. $em->flush();
  336. }
  337. }
  338. $em->flush();
  339. $this->addFlash("success", "Modification a été bien faite");
  340. return $this->redirectToRoute('compagne_show', ['id' => $compagne->getId()]);
  341. }
  342. return $this->render('campagne/edit.html.twig', [
  343. 'compagne' => $compagne,
  344. 'form' => $editForm->createView(),
  345. ]);
  346. }
  347. /**
  348. * @Route("/{id}/majTacheCampagne/SP", name="majTacheCampagne")
  349. */
  350. public function majTacheCampagne(Compagne $compagne)
  351. {
  352. if (!$compagne->getProjet()) {
  353. $this->addFlash("warning", "Mise à jour impossible : campagne sans projet (créée via CSV)");
  354. return $this->redirectToRoute("compagne_show", array('id' => $compagne->getId()));
  355. }
  356. $em = $this->getDoctrine()->getManager();
  357. $tasks = $this->getDoctrine()->getRepository(Tache::class)->findByCompagne($compagne);
  358. $doceboApi = new NewDoceboApi();
  359. $pathApi = "/manage/v1/orgchart/" . $compagne->getProjet()->getIdProjet() . "/users";
  360. $params = "page_size=200";
  361. $requete = $doceboApi->useDoceboApi($pathApi, $params);
  362. $numPages = $requete['data']['total_page_count'];
  363. $tentative = 0;
  364. foreach ($tasks as $task) {
  365. $found = 0;
  366. for ($i = 1; $i <= $numPages; $i++) {
  367. $params = "page_size=200&page=" . $i;
  368. $requete = $doceboApi->useDoceboApi($pathApi, $params);
  369. $learners = $requete['data']['items'];
  370. foreach ($learners as $learner) {
  371. if ($task->getApprenant()->getIdUser() == $learner['user_id']) {
  372. $found = 1;
  373. }
  374. }
  375. }
  376. if (!$found) {
  377. $appels = $this->getDoctrine()->getRepository(Appel::class)->findByTache($task);
  378. foreach ($appels as $appel) {
  379. $appel->setTache(null);
  380. $em->persist($appel);
  381. }
  382. $em->flush();
  383. $em->remove($task);
  384. }
  385. $calls = $this->getDoctrine()->getRepository(Appel::class)->findByTache($task);
  386. if ($calls) {
  387. $tentative++;
  388. }
  389. }
  390. $em->flush();
  391. $compagne->setTentative($tentative);
  392. $em->persist($compagne);
  393. $em->flush();
  394. for ($i = 1; $i <= $numPages; $i++) {
  395. $params = "page_size=200&page=" . $i;
  396. $requete = $doceboApi->useDoceboApi($pathApi, $params);
  397. $learners = $requete['data']['items'];
  398. foreach ($learners as $learner) {
  399. $apprenant = $this->getDoctrine()->getRepository(Apprenant::class)->findByIdUser($learner['user_id']);
  400. if ($apprenant) {
  401. $tache = $this->getDoctrine()->getRepository(Tache::class)->findBy(['apprenant' => $apprenant[0], 'compagne' => $compagne]);
  402. if (!$tache) {
  403. $tache = new Tache();
  404. $tache->setApprenant($apprenant[0]);
  405. $tache->setEtat(0);
  406. $tache->setCompagne($compagne);
  407. $tache->setLastAccess($learner['last_access_date']);
  408. $em->persist($tache);
  409. $em->flush();
  410. }
  411. } else {
  412. $apprenant = new Apprenant();
  413. $apprenant->setProjet($compagne->getProjet());
  414. $apprenant->setType(0);
  415. $apprenant->setPermissionAppel(0);
  416. $apprenant->setIdUser($learner['user_id']);
  417. $pathApi = "/manage/v1/user/" . $learner['user_id'];
  418. $requete = $doceboApi->useDoceboApi($pathApi, null);
  419. $user_data = $requete['data']['user_data'];
  420. $additional_fields = $requete['data']['additional_fields'];
  421. $gsm = "";
  422. $gsm2 = "";
  423. foreach ($additional_fields as $additional_field) {
  424. if (strcmp($additional_field['title'], "GSM") == 0) {
  425. $gsm = $additional_field['value'];
  426. }
  427. if (strcmp($additional_field['title'], "mdp text") == 0) {
  428. $mdp = $additional_field['value'];
  429. }
  430. if (strcmp($additional_field['title'], "GSM2") == 0) {
  431. $gsm2 = $additional_field['value'];
  432. }
  433. }
  434. if (strlen($gsm) == 9) {
  435. $gsm = "0" . $gsm;
  436. }
  437. if (strlen($gsm2) == 9) {
  438. $gsm2 = "0" . $gsm2;
  439. }
  440. $apprenant->setFirstname($user_data['first_name']);
  441. $apprenant->setLastname($user_data['last_name']);
  442. $apprenant->setEmail($user_data['email']);
  443. $apprenant->setGsm($gsm);
  444. $apprenant->setGsm2($gsm2);
  445. $apprenant->setUsername($user_data['username']);
  446. $apprenant->setPassword($mdp);
  447. $apprenant->setLastAccess($learner['last_access_date']);
  448. $em->persist($apprenant);
  449. $em->flush();
  450. $tache = new Tache();
  451. $tache->setApprenant($apprenant);
  452. $tache->setEtat(0);
  453. $tache->setCompagne($compagne);
  454. $tache->setLastAccess($learner['last_access_date']);
  455. $em->persist($tache);
  456. $em->flush();
  457. }
  458. }
  459. }
  460. $em->flush();
  461. $this->addFlash("success", "MAJ liste des tâches a été bien faite");
  462. return $this->redirectToRoute("compagne_show", array('id' => $compagne->getId()));
  463. }
  464. /**
  465. * @Route("/downloadComms/{id}/OP", name="downloadComms")
  466. */
  467. public function downloadComms(Compagne $compagne)
  468. {
  469. $results = array();
  470. //boucle
  471. foreach ($compagne->getTaches() as $key => $tach) {
  472. $results[$key]['Nom'] = $tach->getApprenant()->getFirstname() . ' ' . $tach->getApprenant()->getLastname();
  473. $results[$key]['Email'] = $tach->getApprenant()->getUsername();
  474. $appels = $this->getDoctrine()->getRepository(Appel::class)->findBy(['tache' => $tach->getId(), "type" => 1]);
  475. $arr1 = $arr2 = [];
  476. foreach ($appels as $appel) {
  477. $arr1[] = $appel->getDate();
  478. $arr2[] = ($appel->getDetails()) ? $appel->getDetails() : " NONE ";
  479. if ($appel) {
  480. $results[$key]['Date du dernier appel'] = implode("||", $arr1);
  481. $results[$key]['Commentaire'] = implode("||", $arr2);
  482. }
  483. }
  484. }
  485. // dd($results);
  486. $objPHPExcel = new Spreadsheet();
  487. $objPHPExcel->getActiveSheet()->setCellValue('A1', 'Nom');
  488. $objPHPExcel->getActiveSheet()->setCellValue('B1', 'Email');
  489. $objPHPExcel->getActiveSheet()->setCellValue('C1', 'Date du dernier appel');
  490. $objPHPExcel->getActiveSheet()->setCellValue('D1', 'Commentaire');
  491. $objPHPExcel->getActiveSheet()->getStyle('A1')->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setRGB('2196f3');
  492. $objPHPExcel->getActiveSheet()->getStyle('B1')->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setRGB('2196f3');
  493. $objPHPExcel->getActiveSheet()->getStyle('C1')->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setRGB('2196f3');
  494. $objPHPExcel->getActiveSheet()->getStyle('D1')->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setRGB('2196f3');
  495. $objPHPExcel->getActiveSheet()->getStyle("A1")->getFont()->setBold(true);
  496. $objPHPExcel->getActiveSheet()->getStyle("B1")->getFont()->setBold(true);
  497. $objPHPExcel->getActiveSheet()->getStyle("C1")->getFont()->setBold(true);
  498. $objPHPExcel->getActiveSheet()->getStyle("D1")->getFont()->setBold(true);
  499. // $objPHPExcel->getActiveSheet()->setCellValue('B1', 'Numéro');
  500. $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(30);
  501. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30);
  502. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);
  503. $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(60);
  504. $objPHPExcel->getActiveSheet()->fromArray($results, null, 'A2');
  505. // if (strlen($compagne->getNom()) >= 31) {
  506. // $objPHPExcel->getActiveSheet()->setTitle(substr($compagne->getNom(), 31));
  507. // } else {
  508. // $objPHPExcel->getActiveSheet()->setTitle($compagne->getNom());
  509. // }
  510. $objPHPExcel->getActiveSheet()->setTitle("Commentaires");
  511. header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  512. // if (strlen($compagne->getNom()) >= 31) {
  513. // header('Content-Disposition: attachment;filename="' . substr($compagne->getNom(), 31) . '.xlsx"');
  514. // } else {
  515. // header('Content-Disposition: attachment;filename="' . $compagne->getNom() . '.xlsx"');
  516. // }
  517. header('Content-Disposition: attachment;filename="Commentaires.xlsx"');
  518. header('Cache-Control: max-age=0');
  519. $objWriter = new Xlsx($objPHPExcel);
  520. $objWriter->save('php://output');
  521. exit;
  522. }
  523. /**
  524. * @Route("/{id}/archiver/SP",name="archiverCampagne")
  525. */
  526. public function archiverAction(Compagne $compagne)
  527. {
  528. // $user = $this->getUser();
  529. $em = $this->getDoctrine()->getManager();
  530. $compagne->setArchive(1);
  531. $em->persist($compagne);
  532. $em->flush();
  533. // $notification = new Notification($this->getDoctrine());
  534. // $actualite = $notification->Actualite($user, "a clôturé la compagne " . $compagne->getNom(), $compagne->getId(), "compagne_show");
  535. // $notification->Suivi($actualite);
  536. return $this->redirectToRoute('campagne_list');
  537. }
  538. /**
  539. * @Route("/{id}/desarchiver/SP",name="desarchiverCampagne")
  540. */
  541. public function desarchiverAction(Compagne $compagne)
  542. {
  543. $em = $this->getDoctrine()->getManager();
  544. $compagne->setArchive(0);
  545. $em->persist($compagne);
  546. $em->flush();
  547. return $this->redirectToRoute('campagne_list_archive');
  548. }
  549. /**
  550. * @Route("/{id}/recycler/SP",name="recyclerCampagne")
  551. */
  552. public function recyclerAction(Compagne $compagne)
  553. {
  554. $user = $this->getUser();
  555. $em = $this->getDoctrine()->getManager();
  556. $compagne->setState(2);
  557. $em->persist($compagne);
  558. $em->flush();
  559. // $notification = new Notification($this->getDoctrine());
  560. // $actualite = $notification->Actualite($user, "a recyclé la compagne " . $compagne->getNom(), $compagne->getId(), "compagne_show");
  561. // $notification->Suivi($actualite);
  562. return $this->redirectToRoute('campagne_list');
  563. }
  564. /**
  565. * @Route("/{id}/superVip/CH", name="compagne_superVip")
  566. */
  567. public function superVipAction(Compagne $compagne)
  568. {
  569. $em = $this->getDoctrine()->getManager();
  570. $taches = $em->getRepository(Tache::class)->findByCompagne($compagne);
  571. $operateurs = $em->getRepository(Utilisateur::class)->findCPSPOP();
  572. if (array_key_exists('formTask', $_POST) and array_key_exists('operateurs', $_POST)) {
  573. $tasks = explode(",", $_POST['formTask']);
  574. if ($_POST['operateurs'] == 0) {
  575. if (!empty($tasks)) {
  576. foreach ($tasks as $task) {
  577. $tache = $em->getRepository(Tache::class)->findBy(array('id' => $task));
  578. $tache[0]->getApprenant()->setType(2);
  579. $em->persist($tache[0]);
  580. $em->flush();
  581. }
  582. }
  583. } else {
  584. $agent = $em->getRepository(Utilisateur::class)->findById($_POST['operateurs']);
  585. if (!empty($tasks)) {
  586. foreach ($tasks as $task) {
  587. $tache = $em->getRepository(Tache::class)->findBy(array('id' => $task));
  588. $tache[0]->getApprenant()->setType(2);
  589. $tache[0]->setAgent($agent[0]);
  590. $em->persist($tache[0]);
  591. $em->flush();
  592. }
  593. }
  594. }
  595. $this->addFlash("success", "Les apprenants sélectionnés ont été définis Super VIP");
  596. return $this->redirectToRoute('compagne_show', array('id' => $compagne->getId()));
  597. }
  598. return $this->render('campagne/superVip.html.twig', [
  599. 'compagne' => $compagne,
  600. 'operateurs' => $operateurs,
  601. 'taches' => $taches,
  602. ]);
  603. }
  604. /**
  605. * @Route("/{id}/vip/CH", name="compagne_vip")
  606. */
  607. public function vipAction(Compagne $compagne)
  608. {
  609. $em = $this->getDoctrine()->getManager();
  610. $taches = $em->getRepository(Tache::class)->findByCompagne($compagne);
  611. $operateurs = $em->getRepository(Utilisateur::class)->findCPSPOP();
  612. if (array_key_exists('formTask', $_POST) and array_key_exists('operateur', $_POST)) {
  613. $tasks = explode(",", $_POST['formTask']);
  614. // dump($tasks);
  615. // die();
  616. if ($_POST['operateur'] == 0) {
  617. if (!empty($tasks)) {
  618. foreach ($tasks as $task) {
  619. $tache = $em->getRepository(Tache::class)->findBy(array('id' => $task));
  620. $tache[0]->getApprenant()->setType(1);
  621. $em->persist($tache[0]);
  622. $em->flush();
  623. }
  624. }
  625. } else {
  626. $agent = $em->getRepository(Utilisateur::class)->findById($_POST['operateur']);
  627. if (!empty($tasks)) {
  628. foreach ($tasks as $task) {
  629. $tache = $em->getRepository(Tache::class)->findBy(array('id' => $task));
  630. $tache[0]->getApprenant()->setType(1);
  631. $tache[0]->setAgent($agent[0]);
  632. $em->persist($tache[0]);
  633. $em->flush();
  634. }
  635. }
  636. }
  637. $this->addFlash("success", "Les apprenants sélectionnés ont été définis VIP");
  638. return $this->redirectToRoute('compagne_show', array('id' => $compagne->getId()));
  639. }
  640. return $this->render('campagne/vip.html.twig', array(
  641. 'compagne' => $compagne,
  642. 'operateurs' => $operateurs,
  643. 'taches' => $taches,
  644. ));
  645. }
  646. }