public function load(ObjectManager $manager) { $actualdate = date('m', strtotime('now')); if ($actualdate >= 9) { $beginDate = '01-09-' . date('Y'); $endDate = '30-06-' . date('Y', strtotime('+1 year')); $schoolYearName = date('Y') . '-' . date('Y', strtotime('+1 year')); } else { $beginDate = '01-09-' . date('Y', strtotime('-1 year')); $endDate = '30-06-' . date('Y'); $schoolYearName = date('Y', strtotime('-1 year')) . '-' . date('Y'); } $beginDateFormat = \DateTime::createFromFormat('d-m-Y', $beginDate); $endDateFormat = \DateTime::createFromFormat('d-m-Y', $endDate); $beginHourFormat = \DateTime::createFromFormat('H:i', '07:00'); $endHourFormat = \DateTime::createFromFormat('H:i', '17:00'); $demoSchoolYear = new SchoolYear(); $demoSchoolYear->setSchoolYearName($schoolYearName); $demoSchoolYear->setSchoolYearBegin($beginDateFormat); $demoSchoolYear->setSchoolYearEnd($endDateFormat); $demoSchoolYear->setSchoolDayBeginHour($beginHourFormat); $demoSchoolYear->setSchoolDayendHour($endHourFormat); $demoSchoolYear->setSchoolYearActual(true); $manager->persist($demoSchoolYear); $demoStatus = new Status(); $demoStatus->setStatusByDefault(true); $demoStatus->setStatusColor('#0fef40'); $demoStatus->setStatusName('Présent'); $manager->persist($demoStatus); $demoStatus2 = new Status(); $demoStatus2->setStatusByDefault(true); $demoStatus2->setStatusColor('#f20000'); $demoStatus2->setStatusName('Absent'); $manager->persist($demoStatus2); $demoStatus3 = new Status(); $demoStatus3->setStatusByDefault(true); $demoStatus3->setStatusColor('#ffb31f'); $demoStatus3->setStatusName('Retard'); $manager->persist($demoStatus3); $manager->flush(); }
/** * @EXT\Route( * "/presence/schoolYear_modif/id/{theSchoolYear}", * name="formalibre_school_year_modif", * options={"expose"=true} * ) * * @EXT\ParamConverter("user", options={"authenticatedUser" = true}) * * @param User $user * @EXT\Template() */ public function SchoolYearModifAction(SchoolYear $theSchoolYear) { $ModifSchoolYearForm = $this->createFormBuilder()->add('nameModifSchoolYear', 'text')->add('beginDateModifSchoolYear', 'text')->add('endDateModifSchoolYear', 'text')->add('beginHourModifSchoolYear', 'text')->add('endHourModifSchoolYear', 'text')->add('actualModifSchoolYear', 'checkbox', array('required' => false))->add('validerModifSchoolYear', 'submit', array('label' => 'Ajouter'))->getForm(); $request = $this->getRequest(); if ($request->getMethod() === 'POST') { $ModifSchoolYearForm->handleRequest($request); $modifName = $ModifSchoolYearForm->get('nameModifSchoolYear')->getData(); $modifBeginDate = $ModifSchoolYearForm->get('beginDateModifSchoolYear')->getData(); $modifEndDate = $ModifSchoolYearForm->get('endDateModifSchoolYear')->getData(); $modifBeginHour = $ModifSchoolYearForm->get('beginHourModifSchoolYear')->getData(); $modifEndHour = $ModifSchoolYearForm->get('endHourModifSchoolYear')->getData(); $modifActual = $ModifSchoolYearForm->get('actualModifSchoolYear')->getData(); if ($modifActual) { $AllSchoolYear = $this->schoolYearRepo->findAll(); foreach ($AllSchoolYear as $oneSchoolYear) { $oneSchoolYear->setSchoolYearActual(false); } } $beginDateFormat = \DateTime::createFromFormat('d-m-Y', $modifBeginDate); $endDateFormat = \DateTime::createFromFormat('d-m-Y', $modifEndDate); $beginHourFormat = \DateTime::createFromFormat('H:i', $modifBeginHour); $endHourFormat = \DateTime::createFromFormat('H:i', $modifEndHour); $theSchoolYear->setSchoolYearName($modifName); $theSchoolYear->setSchoolYearBegin($beginDateFormat); $theSchoolYear->setSchoolYearEnd($endDateFormat); $theSchoolYear->setSchoolDayBeginHour($beginHourFormat); $theSchoolYear->setSchoolDayEndHour($endHourFormat); $theSchoolYear->setSchoolYearActual($modifActual); $this->em->persist($theSchoolYear); $this->em->flush(); return new JsonResponse('success', 200); } return array('ModifSchoolYearForm' => $ModifSchoolYearForm->createView(), 'theSchoolYear' => $theSchoolYear); }