Exemple #1
0
 /**
  * Remove childFieldOption
  *
  * @param FieldOption $childFieldOption
  */
 public function removeChildFieldOption(FieldOption $childFieldOption)
 {
     $this->childFieldOption->removeElement($childFieldOption);
 }
Exemple #2
0
 /**
  * Importing Legacy fields Options.
  */
 public function LegacyUpdateFieldOptionsAction($fieldOptions)
 {
     global $refFieldOptions;
     $em = $this->getDoctrine()->getManager();
     $fieldOptions = json_decode($fieldOptions, True);
     foreach ($fieldOptions as $key => $fieldOption) {
         //getting the Object if Exist from the Database
         $field = $em->getRepository('HrisFormBundle:Field')->findOneby(array('name' => $fieldOption['field_name']));
         $fieldOptionObject = $em->getRepository('HrisFormBundle:FieldOption')->findOneby(array('value' => $fieldOption[0]['value'], 'field' => $field));
         if (!empty($fieldOptionObject)) {
             $refFieldOptions[$fieldOption[0]['id']] = $fieldOptionObject->getUid();
         } else {
             $fieldOptionObject = new FieldOption();
             $fieldOptionObject->setUid(uniqid());
             $fieldOptionObject->setField($field);
             $fieldOptionObject->setValue($fieldOption[0]['value']);
             //$fieldOptionObject->setDatecreated($fieldOption[0]['datecreated']);
             $em->persist($fieldOptionObject);
             $refFieldOptions[$fieldOption[0]['id']] = $fieldOptionObject->getUid();
         }
     }
     $em->flush();
     return new Response('success');
 }
Exemple #3
0
 /**
  * Creates a new Leave entity.
  *
  * @Secure(roles="ROLE_SUPER_USER,ROLE_RECORD_CREATE")
  * @Route("/addleave", name="leave_create")
  * @Method("POST")
  * @Template("HrisLeaveBundle:Leave:new.html.twig")
  */
 public function createAction(Request $request)
 {
     $entity = new LeaveType();
     $form = $this->createForm(new LeaveTypeType(), $entity);
     $form->bind($request);
     $user = $this->container->get('security.context')->getToken()->getUser();
     $field = $this->getDoctrine()->getManager()->getRepository('HrisFormBundle:Field')->findOneBy(array('id' => 136));
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $fieldoption = new FieldOption();
         $formData = $form->getData();
         $fieldoption->setDescription($formData->getDescription());
         $fieldoption->setField($field);
         $fieldoption->setHasTraining(True);
         $fieldoption->setValue($formData->getName());
         $entity->setRecord($fieldoption);
         $em->persist($fieldoption);
         $em->persist($entity);
         $em->flush();
         return $this->redirect($this->generateUrl('new_leave', array('message' => 'Added Successful')));
     }
     return array('message' => '', 'form' => $form->createView());
 }
Exemple #4
0
 /**
  * Remove fieldOption
  *
  * @param FieldOption $fieldOption
  */
 public function removeFieldOption(FieldOption $fieldOption)
 {
     $this->fieldOption->removeElement($fieldOption);
 }
Exemple #5
0
 /**
  * Loads metadata into the database
  *
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $stopwatch = new Stopwatch();
     $stopwatch->start('dummyFieldGeneration');
     $this->addDummyFields();
     $this->addDummyFieldOptions();
     $this->addDummyFieldOptionGroups();
     $this->addDummyFieldGroups();
     $this->addDummyFieldGroupsets();
     // Create FieldOptionGroupset for later OptionGroups assignment
     foreach ($this->fieldOptionGroupsets as $fieldOptionGroupsetKey => $humanResourceFieldOptionGroupsets) {
         $fieldOptionGroupset = new FieldOptionGroupset();
         $fieldOptionGroupset->setName($humanResourceFieldOptionGroupsets['name']);
         $fieldOptionGroupset->setDescription($humanResourceFieldOptionGroupsets['description']);
         $fieldOptionGroupsetReference = strtolower(str_replace(' ', '', $humanResourceFieldOptionGroupsets['name'])) . '-fieldoptiongroupset';
         $this->addReference($fieldOptionGroupsetReference, $fieldOptionGroupset);
         $manager->persist($fieldOptionGroupset);
     }
     // Populate dummy fields
     foreach ($this->fields as $fieldKey => $humanResourceField) {
         $field = new Field();
         $field->setDataType($manager->merge($this->getReference(strtolower($humanResourceField['dataType']) . '-datatype')));
         $field->setInputType($manager->merge($this->getReference(strtolower($humanResourceField['inputType']) . '-inputtype')));
         $field->setName($humanResourceField['name']);
         $field->setCaption($humanResourceField['caption']);
         $field->setDescription($humanResourceField['description']);
         $field->setHashistory($humanResourceField['history']);
         $field->setFieldrelation($humanResourceField['fieldRelation']);
         $field->setCompulsory($humanResourceField['compulsory']);
         $field->setIsUnique($humanResourceField['isUnique']);
         $field->setHastarget($humanResourceField['hastarget']);
         $field->setIsCalculated($humanResourceField['isCalculated']);
         $field->setSkipInReport($humanResourceField['skipInReport']);
         $field->setCalculatedExpression($humanResourceField['calculatedExpression']);
         if (!empty($humanResourceField['parentField'])) {
             foreach ($humanResourceField['parentField'] as $parentField) {
                 $parentFieldByReference = $manager->merge($this->getReference(strtolower(str_replace(' ', '', $parentField)) . '-field'));
                 $field->addParentField($parentFieldByReference);
             }
         }
         $fieldReference = strtolower(str_replace(' ', '', $humanResourceField['name'])) . '-field';
         $this->addReference($fieldReference, $field);
         $manager->persist($field);
         // Append  dummy options for input type of select.
         if ($humanResourceField['inputType'] == 'Select') {
             //Create Field Option Group by Field
             $fieldOptionGroup = new FieldOptionGroup();
             $fieldOptionGroup->setName($humanResourceField['name']);
             $fieldOptionGroup->setField($field);
             $fieldOptionGroup->setDescription($humanResourceField['description']);
             $fieldOptionGroupReference = strtolower(str_replace(' ', '', $humanResourceField['name'])) . '-fieldoptiongroup';
             $this->addReference($fieldOptionGroupReference, $fieldOptionGroup);
             // Assign field options to their fields & field  option group
             foreach ($this->fieldOptions as $fieldOptionKey => $humanResourceFieldOptions) {
                 // Options are assigned to option groups according to field names(grouping of option by fields they belong to)
                 if (str_replace('-field', '', $humanResourceFieldOptions['field']) == str_replace(' ', '', $humanResourceField['name'])) {
                     $fieldOption = new FieldOption();
                     $fieldOption->setField($manager->merge($this->getReference($fieldReference)));
                     $fieldOption->setSort($humanResourceFieldOptions['sort']);
                     $fieldOption->setValue($humanResourceFieldOptions['value']);
                     $fieldOption->setDescription($humanResourceFieldOptions['description']);
                     $fieldOption->setSkipInReport($humanResourceFieldOptions['skipinreport']);
                     // If it has parent Option add it
                     if (isset($humanResourceFieldOptions['parentFieldOption']) && !empty($humanResourceFieldOptions['parentFieldOption'])) {
                         // Workout parent field for child option, through parent field of current field option's field.
                         $childFieldByReference = $manager->merge($this->getReference(strtolower(str_replace(' ', '', $humanResourceFieldOptions['field']))));
                         $parentField = $childFieldByReference->getParentField()->getValues();
                         //Workout reference of parent option(note: reference is concatentaion of option value and field name, hence need for parentfieldName)
                         $parentFieldOptionReference = strtolower(str_replace(' ', '', $humanResourceFieldOptions['parentFieldOption'])) . str_replace('-field', '', $parentField[0]->getName()) . '-fieldoption';
                         $parentFieldOptionByReference = $manager->merge($this->getReference($parentFieldOptionReference));
                         $manager->persist($parentFieldOptionByReference);
                         $fieldOption->addParentFieldOption($parentFieldOptionByReference);
                     }
                     $fieldOptionReference = strtolower(str_replace(' ', '', $humanResourceFieldOptions['value'])) . str_replace('-field', '', $humanResourceFieldOptions['field']) . '-fieldoption';
                     $this->addReference($fieldOptionReference, $fieldOption);
                     $manager->persist($fieldOption);
                     // Assign field option to it's field option group
                     $fieldOptionGroup->addFieldOption($fieldOption);
                 }
                 // Append options for Indicator groups of alteast secondary school and University education.
             }
             // Assign created field option groups to groupset by compulsory and hasHistory
             // @Note: names are hard-coded same name as in addDummyFieldGroupsets
             if ($humanResourceField['compulsory'] == true) {
                 $compulsoryFieldOptionGroupset = $manager->merge($this->getReference(strtolower(str_replace(' ', '', 'Compulsory Options')) . '-fieldoptiongroupset'));
                 $compulsoryFieldOptionGroupset->addFieldOptionGroup($fieldOptionGroup);
             }
             if ($humanResourceField['history'] == true) {
                 $hasHistoryGroupsetByReference = $manager->merge($this->getReference(strtolower(str_replace(' ', '', 'History Options')) . '-fieldoptiongroupset'));
                 $hasHistoryGroupsetByReference->addFieldOptionGroup($fieldOptionGroup);
             }
             $manager->persist($fieldOptionGroup);
         }
         unset($field);
         unset($fieldOptionGroup);
     }
     // Create FieldOptionGroups specific for indicators
     foreach ($this->fieldOptionGroups as $fieldOptionGroupKey => $humanResourceFieldOptionGroup) {
         $fieldOptionGroup = new FieldOptionGroup();
         $fieldOptionGroup->setName($humanResourceFieldOptionGroup['name']);
         $fieldOptionGroup->setField($manager->merge($this->getReference(strtolower($humanResourceFieldOptionGroup['field']))));
         $fieldOptionGroup->setDescription($humanResourceFieldOptionGroup['description']);
         $fieldOptionGroupReference = strtolower(str_replace(' ', '', $humanResourceFieldOptionGroup['name'])) . '-fieldoptiongroup';
         //Add option members
         foreach ($humanResourceFieldOptionGroup['options'] as $dummyFieldOption) {
             $fieldOptionReference = $dummyFieldOption;
             $fieldOptionByReference = $manager->merge($this->getReference($fieldOptionReference));
             $fieldOptionGroup->addFieldOption($fieldOptionByReference);
         }
         $this->addReference($fieldOptionGroupReference, $fieldOptionGroup);
         $manager->persist($fieldOptionGroup);
         unset($fieldOptionGroup);
     }
     // Populate dummy field Groups
     foreach ($this->fieldGroups as $fieldGroupKey => $humanResourceFieldGroup) {
         $fieldGroup = new FieldGroup();
         $fieldGroup->setName($humanResourceFieldGroup['name']);
         $fieldGroup->setDescription($humanResourceFieldGroup['description']);
         $fieldGroupReference = strtolower(str_replace(' ', '', $humanResourceFieldGroup['name'])) . '-fieldgroup';
         $this->addReference($fieldGroupReference, $fieldGroup);
         // Add Unique fields in UniqueField Group
         if ($humanResourceFieldGroup['name'] == 'Unique Fields') {
             // Parse through fields marked unique
             foreach ($this->fields as $fieldKey => $humanResourceField) {
                 if ($humanResourceField['isUnique'] == true) {
                     $fieldReference = strtolower(str_replace(' ', '', $humanResourceField['name'])) . '-field';
                     $fieldGroup->addField($manager->merge($this->getReference($fieldReference)));
                 }
             }
         }
         //Add compulsory Fields in Compulsory Fields Group
         if ($humanResourceFieldGroup['name'] == 'Compulsory Fields') {
             // Parse through fields marked unique
             foreach ($this->fields as $fieldKey => $humanResourceField) {
                 if ($humanResourceField['compulsory'] == true) {
                     $fieldReference = strtolower(str_replace(' ', '', $humanResourceField['name'])) . '-field';
                     $fieldGroup->addField($manager->merge($this->getReference($fieldReference)));
                 }
             }
         }
         //Add compulsory Fields in Compulsory Fields Group
         if ($humanResourceFieldGroup['name'] == 'Combo Fields') {
             // Parse through fields marked unique
             foreach ($this->fields as $fieldKey => $humanResourceField) {
                 if ($humanResourceField['inputType'] == 'Select') {
                     $fieldReference = strtolower(str_replace(' ', '', $humanResourceField['name'])) . '-field';
                     $fieldGroup->addField($manager->merge($this->getReference($fieldReference)));
                 }
             }
         }
         $manager->persist($fieldGroup);
         unset($fieldGroup);
     }
     $manager->flush();
     /*
      * Check Clock for time spent
      */
     $dummyFieldGenerationGenerationTime = $stopwatch->stop('dummyFieldGeneration');
     $duration = $dummyFieldGenerationGenerationTime->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 Fields generation complete in ". $durationMessage .".\n\n";
 }