/** * Loads metadata into the database * * @param ObjectManager $manager */ public function load(ObjectManager $manager) { $stopwatch = new Stopwatch(); $stopwatch->start('dummyFriendlyReportGeneration'); $this->addDummyFriendlyReports(); //Persist friendly reports foreach ($this->getFriendlyReports() as $friendlyReportKey => $humanResourceFriendlyReport) { $friendlyReport = new FriendlyReport(); $friendlyReport->setName($humanResourceFriendlyReport['name']); $friendlyReport->setSort($humanResourceFriendlyReport['sort']); $friendlyReport->setDescription($humanResourceFriendlyReport['description']); $seriesReference = strtolower(str_replace(' ', '', $humanResourceFriendlyReport['series'])) . '-fieldoptiongroup'; $seriesByReference = $manager->merge($this->getReference($seriesReference)); $friendlyReport->setSerie($seriesByReference); $manager->persist($friendlyReport); $sort = 1; foreach ($humanResourceFriendlyReport['categories'] as $friendlyCategoryKey => $friendlyCategory) { $fieldOptionGroupReference = strtolower(str_replace(' ', '', $friendlyCategory)) . '-fieldoptiongroup'; $fieldOptionGroupByReference = $manager->merge($this->getReference($fieldOptionGroupReference)); $friendlyReportCategory = new FriendlyReportCategory(); $friendlyReportCategory->setFriendlyReport($friendlyReport); $friendlyReportCategory->setFieldOptionGroup($fieldOptionGroupByReference); $friendlyReportCategory->setSort($sort++); $manager->persist($friendlyReportCategory); } } $manager->flush(); /* * Check Clock for time spent */ $dummyFriendlyReportGenerationTime = $stopwatch->stop('dummyFriendlyReportGeneration'); $duration = $dummyFriendlyReportGenerationTime->getDuration() / 1000; unset($stopwatch); if ($duration < 60) { $durationMessage = round($duration, 2) . ' seconds'; } elseif ($duration >= 60 && $duration < 3600) { $durationMessage = round($duration / 60, 2) . ' minutes'; } elseif ($duration >= 3600 && $duration < 216000) { $durationMessage = round($duration / 3600, 2) . ' hours'; } else { $durationMessage = round($duration / 86400, 2) . ' hours'; } //echo "Dummy Form generation complete in ". $durationMessage .".\n\n"; }
/** * Remove friendlyReportCategory * * @param FriendlyReportCategory $friendlyReportCategory */ public function removeFriendlyReportCategory(FriendlyReportCategory $friendlyReportCategory) { $this->friendlyReportCategory->removeElement($friendlyReportCategory); }
/** * Edits an existing FriendlyReport entity. * * @Secure(roles="ROLE_SUPER_USER,ROLE_FRIENDLYREPORT_UPDATE") * @Route("/{id}", requirements={"id"="\d+"}, name="friendlyreport_update") * @Method("PUT") * @Template("HrisFormBundle:FriendlyReport:edit.html.twig") */ public function updateAction(Request $request, $id) { $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository('HrisFormBundle:FriendlyReport')->find($id); if (!$entity) { throw $this->createNotFoundException('Unable to find FriendlyReport entity.'); } $deleteForm = $this->createDeleteForm($id); $editForm = $this->createForm(new FriendlyReportType(), $entity); $editForm->bind($request); if ($editForm->isValid()) { $incr = 1; $requestcontent = $request->request->get('hris_formbundle_friendlyreporttype'); $fieldOptionGroupIds = $requestcontent['friendlyReportCategory']; // Clear Report categories //Get rid of current expectations $em->createQueryBuilder('friendlyReportCategory')->delete('HrisFormBundle:FriendlyReportCategory', 'friendlyReportCategory')->where('friendlyReportCategory.friendlyReport= :friendlyReport')->setParameter('friendlyReport', $entity)->getQuery()->getResult(); $em->flush(); foreach ($fieldOptionGroupIds as $fieldOptionGroupIdKey => $fieldOptionGroupId) { $fieldOptionGroup = $this->getDoctrine()->getRepository('HrisFormBundle:FieldOptionGroup')->findOneBy(array('id' => $fieldOptionGroupId)); $friendlyReportCategory = new FriendlyReportCategory(); $friendlyReportCategory->setFriendlyReport($entity); $friendlyReportCategory->setFieldOptionGroup($fieldOptionGroup); $friendlyReportCategory->setSort($incr++); $entity->addFriendlyReportCategory($friendlyReportCategory); } $em->persist($entity); $em->flush(); return $this->redirect($this->generateUrl('friendlyreport_show', array('id' => $id))); } return array('entity' => $entity, 'edit_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView()); }
/** * Remove All friendlyReportCategory * */ public function removeAllFriendlyReportCategory() { foreach ($this->friendlyReportCategory as $key => $reportCategory) { $this->friendlyReportCategory->removeElement($reportCategory); } }