src/Controller/AppController.php line 66

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Evenement;
  4. use App\Form\MonCompteType;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Doctrine\Persistence\ManagerRegistry;
  10. class AppController extends AbstractController
  11. {
  12.     private $doctrine;
  13.     public function __construct(ManagerRegistry $doctrine )
  14.     {
  15.         $this->doctrine $doctrine;
  16.     }
  17.     /**
  18.      * @Route("/", name="main")
  19.      */
  20.     public function homepage()
  21.     {
  22.         $securityContext $this->container->get('security.authorization_checker');
  23.         if($securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')){
  24.             if (sizeof($this->getUser()->getRoles()) > 1) {
  25.                 return $this->redirectToRoute('choix_role');
  26.             }else{
  27.                 return $this->redirectToRoute('reservation_mois');
  28.             }
  29.         }else{
  30.             return $this->redirectToRoute('arshdf_user_login');
  31.         }
  32.     }
  33.     /**
  34.      * @Route("/app/choix", name="choix_role")
  35.      */
  36.     public function choix_role(){
  37.         $info = [];
  38.         $roles = [];
  39.         foreach($this->getUser()->getRoles() as $role){
  40.             if($role == 'ROLE_USER'){
  41.                 $roles['Utilisateur'] =  'reservation_mois';
  42.             }elseif ($role == 'ROLE_HAB'){
  43.                 $roles['Habilitation'] =  'toactivate';
  44.             }
  45.         }
  46.         $info['roles'] = $roles;
  47.         return $this->render('app/choix_profil.html.twig'$info);
  48.     }
  49.     /**
  50.      * @Route("/app/mon/compte", name="monCompte")
  51.      */
  52.     public function monCompte(Request $request){
  53.         $info = [];
  54.         $form $this->createForm(MonCompteType::class, $this->getUser());
  55.         $form->handleRequest($request);
  56.         $info['form'] = $form->createView();
  57.         if ($form->isSubmitted() && $form->isValid()) {
  58.             $em $this->doctrine->getManager();
  59.             $em->persist($this->getUser());
  60.             $em->flush();
  61.             return $this->redirectToRoute('choix_role');
  62.         }
  63.         return $this->render('app/monCompte.html.twig'$info);
  64.     }
  65.     /**
  66.      * @Route("/teletravail/automatique", name="teletravailAutomatique")
  67.      */
  68.     public function teletravailAutomatique(){
  69.         $em $this->doctrine->getManager();
  70.         // ==== DEBUT ==== Désactiver les comptes ldap inactifs
  71. //        $agent_a_desactiver = $this->doctrine->getRepository('App\Entity\Ldap')->findBy(['actif'=>'0']);
  72. //        foreach ($agent_a_desactiver as $a){
  73. //            $compte = $this->doctrine->getRepository('App\Entity\User')->findBy(['email'=>$a->getEmail()]);
  74. //            if(!empty($compte)){
  75. //                foreach ($compte as $user){
  76. //                    $user->setDeleted(true);
  77. //                    $user->setEnabled(false);
  78. //                    $user->setToActivate(true);
  79. //                    $em->persist($user);
  80. //                }
  81. //            }
  82. //        }
  83. //        $em->flush();
  84.         // ==== FIN ==== Désactiver les comptes ldap inactifs
  85.         // ==== DEBUT ==== Libérer les places télétravails
  86.         //0 : dimanche
  87.         $response file_get_contents('teletravail.json');
  88.         $data json_decode($response);
  89.         $day strtotime(date('Y-m-d')." + 2 weeks");
  90.         $traduction = [
  91.             'Lundi'     =>'Monday',
  92.             'Mardi'     =>'Tuesday',
  93.             'Mercredi'  =>'Wednesday',
  94.             'Jeudi'     =>'Thursday',
  95.             'Vendredi'  =>'Friday'
  96.         ];
  97.         $agents $this->doctrine->getRepository('App\Entity\User')->findAgentPlace();
  98.         foreach ($agents as $a){
  99.             if(isset($data->{trim($a->getEmail())})){
  100.                 foreach ($data->{trim($a->getEmail())} as $j){
  101.                     $d = new \DateTimedate('Y-m-d',  strtotime($traduction[$j],$day)));
  102.                     // je vérifie que la place n'est pas libéré
  103.                     $evmntExiste $this->doctrine->getRepository('App\Entity\Evenement')->findBy(['placeAppartientAgent'=>$a->getId(), 'dateLiberee'=>$d]);
  104.                     if(sizeof($evmntExiste) == 0){
  105.                         // je libère
  106.                         $e = new Evenement();
  107.                         $e->setPlaceAppartientAgent($a);
  108.                         $e->setDateLibereeAutomatique(true);
  109.                         $e->setDateLiberee($d);
  110.                         $e->setDateCreated(new \DateTime("now"));
  111.                         $em->persist($e);
  112.                     }
  113.                 }
  114.             }
  115.         }
  116.         $em->flush();
  117.         // ==== FIN ==== Libérer les places télétravails
  118.         return new Response('Ok');
  119.     }
  120.     /**
  121.      * @Route("/site/{id}", name="user_site")
  122.      */
  123. //    public function user_site($id, Request $request){
  124. //        $info = [];
  125. //        $em = $this->getDoctrine()->getManager();
  126. //
  127. //        $agent      = $this->getDoctrine()->getRepository('ARSHDF\UserBundle\Entity\User')->find($id);
  128. //        $site       = $this->getDoctrine()->getRepository('App:GestSite')->find(1);
  129. //        $user_site  = $this->getDoctrine()->getRepository('App:UserSite')->findBy(['user'=>$agent]);
  130. //
  131. //        if(null == $user_site){
  132. //            // créer l'enregistrement si n'existe pas
  133. //            $add = new UserSite();
  134. //            $add->setUser($agent);
  135. //            $add->setSite($site);
  136. //            $em->persist($add);
  137. //            $em->flush();
  138. //            $user_site  = $this->getDoctrine()->getRepository('App:UserSite')->findBy(['user'=>$add->getUser()]);
  139. //        }
  140. //
  141. //
  142. //        $form = $this->createForm(UserSiteType::class, $user_site[0]);
  143. //        $form->handleRequest($request);
  144. //
  145. //        if($form->isSubmitted() && $form->isValid()){
  146. //            $em->persist($user_site[0]);
  147. //            $em->flush();
  148. //            return $this->redirectToRoute('app_user_habilitation_index');
  149. //        }
  150. //
  151. //
  152. //        $info['form'] = $form->createView();
  153. //        $info['agent'] = $user_site;
  154. //        return $this->render('habilitation/user_site.html.twig', $info);
  155. //
  156. //    }
  157. }