/**
  * Creates a new Feedbackcycle entity.
  *
  */
 public function createAction(Request $request)
 {
     $entity = new Feedbackcycle();
     $form = $this->createCreateForm($entity);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $unavailable = $em->getRepository('IntoPeopleDatabaseBundle:Formstatus')->find(9);
         $available = $em->getRepository('IntoPeopleDatabaseBundle:Formstatus')->find(1);
         // FIND NEWEST CDP TEMPLATE
         // ---
         $repository = $this->getDoctrine()->getRepository('IntoPeopleDatabaseBundle:Cdptemplate');
         $cdptemplate = $repository->findNewest($entity->getUser()->getOrganization());
         // FIND NEWEST MID YEAR TEMPLATE
         // ---
         $repository = $this->getDoctrine()->getRepository('IntoPeopleDatabaseBundle:Midyeartemplate');
         $midyeartemplate = $repository->findNewest($entity->getUser()->getOrganization());
         // FIND NEWEST END YEAR TEMPLATE
         // ---
         $repository = $this->getDoctrine()->getRepository('IntoPeopleDatabaseBundle:Endyeartemplate');
         $endyeartemplate = $repository->findNewest($entity->getUser()->getOrganization());
         $developmentneeds = new Developmentneeds();
         $cdp = new Cdp();
         $cdp->setDevelopmentneeds($developmentneeds);
         $cdp->setFormstatus($available);
         $cdp->setCdptemplate($cdptemplate);
         $entity->setCdp($cdp);
         $midyear = new Midyear();
         $midyear->setDevelopmentneeds($developmentneeds);
         $midyear->setFormstatus($unavailable);
         $midyear->setMidyeartemplate($midyeartemplate);
         $entity->setMidyear($midyear);
         $endyear = new Endyear();
         $endyear->setDevelopmentneeds($developmentneeds);
         $endyear->setFormstatus($unavailable);
         $endyear->setEndyeartemplate($endyeartemplate);
         $entity->setEndyear($endyear);
         $em = $this->getDoctrine()->getManager();
         $em->persist($entity);
         $em->flush();
         return $this->redirect($this->generateUrl('feedbackcycle_show', array('id' => $entity->getId())));
     }
     return $this->render('IntoPeopleDatabaseBundle:Feedbackcycle:new.html.twig', array('entity' => $entity, 'form' => $form->createView()));
 }
Esempio n. 2
0
 /**
  * Lists all User entities.
  */
 public function indexAction(Request $request)
 {
     $defaultData = array();
     $form = $this->createFormBuilder($defaultData)->add('template', 'file', array('constraints' => new File(array('maxSize' => "10M", 'mimeTypes' => array('application/vnd.ms-office')))))->add('create users', 'submit')->getForm();
     $form->handleRequest($request);
     if ($form->isValid()) {
         $data = $form->getData();
         $em = $this->getDoctrine()->getManager();
         $languages = $em->getRepository('IntoPeopleDatabaseBundle:Language')->findAll();
         $mails = array();
         foreach ($languages as $language) {
             $query = $em->getRepository('IntoPeopleDatabaseBundle:Systemmail')->createQueryBuilder('s')->join('s.mailtype', 'm')->where('s.language = :id')->andWhere('m.name = :name')->setParameter('id', $language)->setParameter('name', 'usercreated')->getQuery();
             $mails[$language->getName()] = $query->setMaxResults(1)->getOneOrNullResult();
         }
         $filereadablecheck = '';
         $objReader = \PHPExcel_IOFactory::createReader('Excel5');
         try {
             $objPHPExcel = $objReader->load($data['template']);
         } catch (Exception $e) {
             $filereadablecheck = "no";
             $this->addFlash('warning', $this->get('translator')->trans('user.readexcelfileerror'));
         }
         if ($filereadablecheck != "no") {
             $highestRow = $objPHPExcel->setActiveSheetIndex(0)->getHighestRow();
             $worksheet = $objPHPExcel->getActiveSheet();
             $generalcycleactivestatus = $em->getRepository('IntoPeopleDatabaseBundle:Generalcyclestatus')->findOneByName('Active');
             $generalcycle = $em->getRepository('IntoPeopleDatabaseBundle:Generalcycle')->findOneByGeneralcyclestatus($generalcycleactivestatus);
             $unsupervisedusers = array();
             for ($i = 2; $i <= $highestRow; $i++) {
                 $email = $worksheet->getCell('A' . $i)->getValue();
                 $firstname = $worksheet->getCell('B' . $i)->getValue();
                 $lastname = $worksheet->getCell('C' . $i)->getValue();
                 $languagekey = $worksheet->getCell('D' . $i)->getValue();
                 $addtoactivecycle = $worksheet->getCell('E' . $i)->getValue();
                 $supervisormail = $worksheet->getCell('F' . $i)->getValue();
                 $issupervisor = $worksheet->getCell('G' . $i)->getValue();
                 $ishr = $worksheet->getCell('H' . $i)->getValue();
                 $emailConstraint = new EmailConstraint();
                 $emailConstraint->message = 'Your customized error message';
                 $errors = $this->get('validator')->validateValue($email, $emailConstraint);
                 if (count($errors) == 0) {
                     $user = $repository = $this->getDoctrine()->getRepository('IntoPeopleDatabaseBundle:User')->findOneByEmail($email);
                     if (!$user) {
                         $tokenGenerator = $this->get('fos_user.util.token_generator');
                         $password = substr($tokenGenerator->generateToken(), 0, 10);
                         $user = new User();
                         $user->setEmail($email);
                         $user->setUsername($email);
                         $user->setPlainPassword($password);
                         $user->setEnabled(true);
                         $user->setRoles(array(User::ROLE_DEFAULT));
                         $user->setFirstname($firstname);
                         $user->setLastname($lastname);
                         $language = $em->getRepository('IntoPeopleDatabaseBundle:Language')->findOneByName($languagekey);
                         if ($language != null) {
                             $user->setLanguage($language);
                             if ($issupervisor == 'x') {
                                 $user->addRole('ROLE_SUPERVISOR');
                             }
                             if ($ishr == 'x') {
                                 $user->addRole('ROLE_HR');
                             }
                             $em->persist($user);
                             $em->flush();
                             $repository = $this->getDoctrine()->getRepository('IntoPeopleDatabaseBundle:Formstatus');
                             $available = $repository->find(1);
                             $unavailable = $repository->find(9);
                             // FIND NEWEST CDP TEMPLATE
                             // ---
                             $repository = $this->getDoctrine()->getRepository('IntoPeopleDatabaseBundle:Cdptemplate');
                             $cdptemplate = $repository->findNewest();
                             // FIND NEWEST MID YEAR TEMPLATE
                             // ---
                             $repository = $this->getDoctrine()->getRepository('IntoPeopleDatabaseBundle:Midyeartemplate');
                             $midyeartemplate = $repository->findNewest();
                             // FIND NEWEST END YEAR TEMPLATE
                             // ---
                             $repository = $this->getDoctrine()->getRepository('IntoPeopleDatabaseBundle:Endyeartemplate');
                             $endyeartemplate = $repository->findNewest();
                             if ($addtoactivecycle == 'x') {
                                 $feedbackcycle = new Feedbackcycle();
                                 $feedbackcycle->setUser($user);
                                 $feedbackcycle->setGeneralcycle($generalcycle);
                                 $developmentneeds = new Developmentneeds();
                                 $cdp = new Cdp();
                                 $cdp->setDevelopmentneeds($developmentneeds);
                                 $cdp->setFormstatus($available);
                                 $cdp->setCdptemplate($cdptemplate);
                                 $feedbackcycle->setCdp($cdp);
                                 $midyear = new Midyear();
                                 $midyear->setDevelopmentneeds($developmentneeds);
                                 $midyear->setFormstatus($unavailable);
                                 $midyear->setMidyeartemplate($midyeartemplate);
                                 $feedbackcycle->setMidyear($midyear);
                                 $endyear = new Endyear();
                                 $endyear->setDevelopmentneeds($developmentneeds);
                                 $endyear->setFormstatus($unavailable);
                                 $endyear->setEndyeartemplate($endyeartemplate);
                                 $feedbackcycle->setEndyear($endyear);
                                 $em = $this->getDoctrine()->getManager();
                                 $em->persist($feedbackcycle);
                             }
                             $systemmail = $mails[$user->getLanguage()->getName()];
                             $message = \Swift_Message::newInstance()->setSubject($systemmail->getSubject())->setFrom($systemmail->getSender())->setTo($user->getEmail())->setBody(str_replace(array('$url', '$username', '$password'), array('https://' . $request->getHttpHost() . $this->generateUrl('user_firstlogin', array('token' => $password, 'id' => $user->getId())), $user->getEmail(), $password), $systemmail->getBody()));
                             $this->get('mailer')->send($message);
                             if ($supervisormail != '') {
                                 $unsuperviseduser = new \stdClass();
                                 $unsuperviseduser->supervisormail = $supervisormail;
                                 $unsuperviseduser->usermail = $user->getEmail();
                                 array_push($unsupervisedusers, $unsuperviseduser);
                             }
                         } else {
                             $this->addFlash('warning', $this->get('translator')->trans('user.invalidlanguageerror'));
                         }
                     }
                 }
             }
             foreach ($unsupervisedusers as $unsuperviseduser) {
                 $user = $em->getRepository('IntoPeopleDatabaseBundle:User')->findOneByEmail($unsuperviseduser->usermail);
                 $supervisor = $em->getRepository('IntoPeopleDatabaseBundle:User')->findOneByEmail($unsuperviseduser->supervisormail);
                 if ($supervisor != null) {
                     $user->setSupervisor($supervisor);
                 } else {
                     $translated = $this->get('translator')->trans('Setting supervisor with email %supervisoremail% for user %name%, supervisor does not exist.', array('%name%' => $user->getFirstname() . ' ' . $user->getLastname(), '%supervisoremail%' => $unsuperviseduser->supervisormail));
                     $this->addFlash('warning', $translated);
                 }
             }
             $em->flush();
         }
     }
     $repository = $this->getDoctrine()->getRepository('IntoPeopleDatabaseBundle:User');
     $entities = $repository->findAll();
     return $this->render('IntoPeopleDatabaseBundle:User:index.html.twig', array('entities' => $entities, 'formtemplate' => $form->createView()));
 }
 /**
  * Creates a new Generalcycle entity.
  */
 public function createAction(Request $request)
 {
     $user = $this->getUser();
     $entity = new Generalcycle();
     $form = $this->createCreateForm($entity);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         // Does generalcycle with this year already exist?
         if ($em->getRepository('IntoPeopleDatabaseBundle:Generalcycle')->checkYearByOrganization($user->getOrganization(), $entity->getYear())) {
             $this->addFlash('error', 'A cycle already exists for ' . $entity->getYear() . '!');
             return $this->render('IntoPeopleDatabaseBundle:Generalcycle:new.html.twig', array('entity' => $entity, 'form' => $form->createView()));
         }
         if ($em->getRepository('IntoPeopleDatabaseBundle:Generalcycle')->getActiveCycleByOrganization()) {
             $status = $em->getReference('IntoPeopleDatabaseBundle:Generalcyclestatus', 3);
         } else {
             $status = $em->getReference('IntoPeopleDatabaseBundle:Generalcyclestatus', 1);
         }
         $entity->setGeneralcyclestatus($status);
         // Set organization of generalcycle to user's organization
         if ($entity->getOrganization() == null) {
             $entity->setOrganization($user->getOrganization());
         }
         // Startdate is current date
         $dt = new \DateTime();
         $entity->setStartdate($dt);
         // Generalcycle started by current user
         $user = $this->getUser();
         $entity->setStartedby($user);
         // Foreach user in organization create feedbackcycle for generalcycle
         $repository = $this->getDoctrine()->getRepository('IntoPeopleDatabaseBundle:User');
         $users = $repository->findAll();
         $repository = $this->getDoctrine()->getRepository('IntoPeopleDatabaseBundle:Formstatus');
         $available = $repository->find(1);
         $unavailable = $repository->find(9);
         // FIND NEWEST CDP TEMPLATE
         // ---
         $repository = $this->getDoctrine()->getRepository('IntoPeopleDatabaseBundle:Cdptemplate');
         $cdptemplate = $repository->findNewest();
         // FIND NEWEST MID YEAR TEMPLATE
         // ---
         $repository = $this->getDoctrine()->getRepository('IntoPeopleDatabaseBundle:Midyeartemplate');
         $midyeartemplate = $repository->findNewest();
         // FIND NEWEST END YEAR TEMPLATE
         // ---
         $repository = $this->getDoctrine()->getRepository('IntoPeopleDatabaseBundle:Endyeartemplate');
         $endyeartemplate = $repository->findNewest();
         foreach ($users as $user) {
             if ($user->getUserstatus()->getId() == 1) {
                 $feedbackcycle = new Feedbackcycle();
                 $feedbackcycle->setUser($user);
                 $feedbackcycle->setGeneralcycle($entity);
                 $developmentneeds = new Developmentneeds();
                 $cdp = new Cdp();
                 $cdp->setDevelopmentneeds($developmentneeds);
                 $cdp->setFormstatus($available);
                 $cdp->setCdptemplate($cdptemplate);
                 $feedbackcycle->setCdp($cdp);
                 $midyear = new Midyear();
                 $midyear->setDevelopmentneeds($developmentneeds);
                 $midyear->setFormstatus($unavailable);
                 $midyear->setMidyeartemplate($midyeartemplate);
                 $feedbackcycle->setMidyear($midyear);
                 $endyear = new Endyear();
                 $endyear->setDevelopmentneeds($developmentneeds);
                 $endyear->setFormstatus($unavailable);
                 $endyear->setEndyeartemplate($endyeartemplate);
                 $feedbackcycle->setEndyear($endyear);
                 $em = $this->getDoctrine()->getManager();
                 $em->persist($feedbackcycle);
             }
         }
         $em->persist($entity);
         $em->flush();
         // Notification message after Core Quality has been created
         //
         $tr = $this->get('translator');
         $message = $tr->trans('notification.create.generalcycle');
         $this->addFlash('success', $message);
         return $this->redirect($this->generateUrl('generalcycle', array('id' => $entity->getId())));
     }
     return $this->render('IntoPeopleDatabaseBundle:Generalcycle:new.html.twig', array('entity' => $entity, 'form' => $form->createView()));
 }