コード例 #1
0
ファイル: LoadIndicatorData.php プロジェクト: mattvaadi/hris
 public function load(ObjectManager $manager)
 {
     $stopwatch = new Stopwatch();
     $stopwatch->start('dummyIndicatorGeneration');
     // Populate dummy forms
     $this->addDummyTargets();
     foreach ($this->getTargets() as $key => $humanResourceTarget) {
         $target = new Target();
         $target->setName($humanResourceTarget['name']);
         $target->setDescription($humanResourceTarget['description']);
         $organisationunitGroupByReference = $manager->merge($this->getReference(strtolower(str_replace(' ', '', $humanResourceTarget['organisationunitGroup'])) . '-organisationunitgroup'));
         $target->setOrganisationunitGroup($organisationunitGroupByReference);
         foreach ($humanResourceTarget['targets'] as $targetKey => $humaResourceTargetFieldOption) {
             $targetFieldOption = new TargetFieldOption();
             $fieldOptionReference = strtolower(str_replace(' ', '', $humaResourceTargetFieldOption['fieldOption'])) . str_replace('-field', '', $humanResourceTarget['field']) . '-fieldoption';
             $fieldOptionByReference = $manager->merge($this->getReference($fieldOptionReference));
             $targetFieldOption->setFieldOption($fieldOptionByReference);
             $targetFieldOption->setTarget($target);
             $targetFieldOption->setValue($humaResourceTargetFieldOption['target']);
             $target->addTargetFieldOption($targetFieldOption);
         }
         $this->addReference(strtolower(str_replace(' ', '', $humanResourceTarget['name'])) . '-target', $target);
         $manager->persist($target);
     }
     $manager->flush();
     /*
      * Check Clock for time spent
      */
     $dummyIndicatorGenerationTime = $stopwatch->stop('dummyIndicatorGeneration');
     $duration = $dummyIndicatorGenerationTime->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 Indicators generation complete in ". $durationMessage .".\n\n";
 }
コード例 #2
0
ファイル: Target.php プロジェクト: mattvaadi/hris
 /**
  * Remove All targetFieldOption
  *
  * @internal param \Hris\FormBundle\Entity\TargetFieldOption $targetFieldOption
  */
 public function removeAllTargetFieldOption()
 {
     foreach ($this->targetFieldOption as $key => $targetFieldOption) {
         $this->targetFieldOption->removeElement($targetFieldOption);
     }
 }
コード例 #3
0
ファイル: TargetController.php プロジェクト: mattvaadi/hris
 /**
  * Edits an existing Target entity.
  *
  * @Secure(roles="ROLE_SUPER_USER,ROLE_TARGET_UPDATE")
  * @Route("/{id}", name="target_update")
  * @Method("PUT")
  * @Template("HrisIndicatorBundle:Target:edit.html.twig")
  */
 public function updateAction(Request $request, $id)
 {
     $em = $this->getDoctrine()->getManager();
     $entity = $em->getRepository('HrisIndicatorBundle:Target')->find($id);
     if (!$entity) {
         throw $this->createNotFoundException('Unable to find Target entity.');
     }
     $deleteForm = $this->createDeleteForm($id);
     $editForm = $this->createForm(new TargetType(), $entity);
     $editForm->submit($request);
     if ($editForm->isValid()) {
         //Get rid of current expectations
         $em->createQueryBuilder('targetFieldOption')->delete('HrisIndicatorBundle:TargetFieldOption', 'targetFieldOption')->where('targetFieldOption.target= :targetId')->setParameter('targetId', $entity->getId())->getQuery()->getResult();
         $em->flush();
         // Persist completeness figures too
         $targettypeform = $request->request->get('hris_indicatorbundle_targettype');
         $fieldOptions = $this->getDoctrine()->getManager()->getRepository('HrisFormBundle:FieldOption')->findBy(array('field' => $targettypeform['fields']));
         $fieldOptionTargets = $request->request->get('hris_indicatorbundle_targettype_fieldoptiontarget');
         foreach ($fieldOptions as $fieldOptionKey => $fieldOption) {
             if (isset($fieldOptionTargets[$fieldOption->getId()]) && !empty($fieldOptionTargets[$fieldOption->getId()])) {
                 $fieldOptionTarget = new TargetFieldOption();
                 $fieldOptionTarget->setFieldOption($fieldOption);
                 $fieldOptionTarget->setTarget($entity);
                 $fieldOptionTarget->setValue((int) $fieldOptionTargets[$fieldOption->getId()]);
                 $entity->addTargetFieldOption($fieldOptionTarget);
                 unset($fieldOptionTarget);
             }
         }
         $em->persist($entity);
         $em->flush();
         return $this->redirect($this->generateUrl('target_show', array('id' => $id)));
     }
     return array('entity' => $entity, 'edit_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView());
 }