Exemplo n.º 1
0
 public function load(ObjectManager $manager)
 {
     $stopwatch = new Stopwatch();
     $stopwatch->start('dummyFormGeneration');
     // Populate dummy forms
     $this->addDummyForms();
     // Seek dummy fields
     $loadFieldData = new LoadFieldData();
     $loadFieldData->addDummyFields();
     $dummyFields = $loadFieldData->getFields();
     // Once forms are in database, assign admin with all forms
     // district user to public and private
     // and hospital user to hospital form
     //admin user
     $adminUserByReference = $manager->merge($this->getReference('admin-user'));
     //district user
     $districtUserByReference = $manager->merge($this->getReference('district-user'));
     //hospital user
     $hospitalUserByReference = $manager->merge($this->getReference('hospital-user'));
     foreach ($this->forms as $key => $humanResourceForm) {
         $form = new Form();
         $form->setName($humanResourceForm['name']);
         $form->setTitle($humanResourceForm['name']);
         $this->addReference(strtolower(str_replace(' ', '', $humanResourceForm['name'])) . '-form', $form);
         $manager->persist($form);
         // Assign all forms to admin user
         $adminUserByReference->addForm($form);
         $manager->persist($adminUserByReference);
         // Assign public and private form to district user and hospital to hospital user
         if ($humanResourceForm['name'] == 'Public Employee Form' || $humanResourceForm['name'] == 'Private Employee Form') {
             $districtUserByReference->addForm($form);
             $manager->persist($districtUserByReference);
         } elseif ($humanResourceForm['name'] == 'Hospital Employee Form') {
             $hospitalUserByReference->addForm($form);
             $manager->persist($hospitalUserByReference);
         }
         // Add Field Members for the form created
         $sort = 1;
         foreach ($humanResourceForm['fields'] as $dummyField) {
             $fieldByReference = $manager->merge($this->getReference(strtolower(str_replace(' ', '', $dummyField)) . '-field'));
             $formByReference = $manager->merge($this->getReference(strtolower(str_replace(' ', '', $humanResourceForm['name'])) . '-form'));
             $formMember = new FormFieldMember();
             $formMember->setField($fieldByReference);
             $formMember->setForm($formByReference);
             $formMember->setSort($sort++);
             //$referenceName = strtolower(str_replace(' ','',$humanResourceForm['name']).str_replace(' ','',$dummyField)).'-form-field-member';
             //$this->addReference($referenceName, $formMember);
             $manager->persist($formMember);
             // Overwrite fieldnames in inputags ids with uids
             $humanResourceForm['hypertext'] = str_replace("id=\"" . $dummyField . "\"", "id=\"" . $fieldByReference->getUid() . "\"", $humanResourceForm['hypertext']);
             if ($fieldByReference->getInputType()->getName() == "Select") {
                 $humanResourceForm['hypertext'] = str_replace("changeRelatedFieldOptions('" . $dummyField . "')", "changeRelatedFieldOptions('" . $fieldByReference->getUid() . "')", $humanResourceForm['hypertext']);
                 $humanResourceForm['hypertext'] = str_replace("loadFieldOptions('" . $dummyField . "')", "loadFieldOptions('" . $fieldByReference->getUid() . "')", $humanResourceForm['hypertext']);
             }
             unset($formMember);
         }
         $sort = 1;
         foreach ($humanResourceForm['visibleFields'] as $key => $dummyField) {
             $fieldByReference = $manager->merge($this->getReference(strtolower(str_replace(' ', '', $dummyField)) . '-field'));
             $formByReference = $manager->merge($this->getReference(strtolower(str_replace(' ', '', $humanResourceForm['name'])) . '-form'));
             $visibleFieldMember = new FormVisibleFields();
             $visibleFieldMember->setField($fieldByReference);
             $visibleFieldMember->setForm($formByReference);
             $visibleFieldMember->setSort($sort++);
             $manager->persist($visibleFieldMember);
             unset($visibleFieldMember);
         }
         foreach ($humanResourceForm['uniqueFields'] as $key => $dummyField) {
             $fieldByReference = $manager->merge($this->getReference(strtolower(str_replace(' ', '', $dummyField)) . '-field'));
             $form->addUniqueRecordField($fieldByReference);
         }
         $form->setHypertext($humanResourceForm['hypertext']);
         $manager->persist($form);
         unset($form);
     }
     $manager->flush();
     /*
      * Check Clock for time spent
      */
     $dummyFormGenerationTime = $stopwatch->stop('dummyFormGeneration');
     $duration = $dummyFormGenerationTime->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";
 }
Exemplo n.º 2
0
 /**
  * Edits an existing Form entity.
  *
  * @Secure(roles="ROLE_SUPER_USER,ROLE_FORM_UPDATE")
  * @Route("/{id}", requirements={"id"="\d+"}, name="form_update")
  * @Method("PUT")
  * @Template("HrisFormBundle:Form:edit.html.twig")
  */
 public function updateAction(Request $request, $id)
 {
     $em = $this->getDoctrine()->getManager();
     $entity = $em->getRepository('HrisFormBundle:Form')->find($id);
     if (!$entity) {
         throw $this->createNotFoundException('Unable to find Form entity.');
     }
     $deleteForm = $this->createDeleteForm($id);
     $editForm = $this->createForm(new FormType(), $entity);
     $editForm->bind($request);
     if ($editForm->isValid()) {
         $requestcontent = $request->request->get('hris_formbundle_formtype');
         $formFieldMemberIds = $requestcontent['formFieldMembers'];
         // Clear Form Field Members
         //$entity->removeAllFormFieldMember();
         $em->createQueryBuilder('formFieldMember')->delete('HrisFormBundle:FormFieldMember', 'formFieldMember')->where('formFieldMember.form= :form')->setParameter('form', $entity)->getQuery()->getResult();
         $em->flush();
         $incr = 1;
         foreach ($formFieldMemberIds as $formFieldMemberIdKey => $formFieldMemberId) {
             $field = $this->getDoctrine()->getRepository('HrisFormBundle:Field')->findOneBy(array('id' => $formFieldMemberId));
             $formFieldMember = new FormFieldMember();
             $formFieldMember->setForm($entity);
             $formFieldMember->setField($field);
             $formFieldMember->setSort($incr++);
             $entity->addFormFieldMember($formFieldMember);
         }
         $visibleFormFieldIds = $requestcontent['formVisibleFields'];
         $em->persist($entity);
         // Clear Visible Form Field
         //$entity->removeAllFormVisibleFields();
         $em->createQueryBuilder('formVisibleFields')->delete('HrisFormBundle:FormVisibleFields', 'formVisibleFields')->where('formVisibleFields.form= :form')->setParameter('form', $entity)->getQuery()->getResult();
         $em->flush();
         $incr = 1;
         foreach ($visibleFormFieldIds as $visibleFormFieldIdKey => $visibleFormFieldId) {
             $field = $this->getDoctrine()->getRepository('HrisFormBundle:Field')->findOneBy(array('id' => $visibleFormFieldId));
             $visibleFormField = new FormVisibleFields();
             $visibleFormField->setForm($entity);
             $visibleFormField->setField($field);
             $visibleFormField->setSort($incr++);
             $entity->addFormVisibleField($visibleFormField);
         }
         $em->persist($entity);
         $em->flush();
         return $this->redirect($this->generateUrl('form_show', array('id' => $id)));
     }
     return array('entity' => $entity, 'edit_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView());
 }