Beispiel #1
0
 /**
  * Importing fields.
  *
  * @Secure(roles="ROLE_SUPER_USER,ROLE_IMPORT_IMPORTFIELDS")
  * @Route("/importFields", name="importexport_import_importFields")
  * @Method("POST")
  */
 public function updateFieldsAction(Request $request)
 {
     global $refField;
     $em = $this->getDoctrine()->getManager();
     $fields = json_decode($this->get('request')->request->get('fields'), True);
     foreach ($fields as $key => $field) {
         //getting the Object if Exist from the Database
         $fieldObject = $em->getRepository('HrisFormBundle:Field')->findOneby(array('name' => $field[0]['name']));
         if (!empty($fieldObject)) {
             $refField[$field[0]['uid']] = $fieldObject->getUid();
             print $field[0]['uid'];
             print '<br>';
         } else {
             $dataType = $em->getRepository('HrisFormBundle:DataType')->findOneby(array('uid' => $field['datatype_uid']));
             $inputType = $em->getRepository('HrisFormBundle:InputType')->findOneby(array('uid' => $field['inputtype_uid']));
             $fieldObject = new Field();
             $fieldObject->setUid($field[0]['uid']);
             $fieldObject->setName($field[0]['name']);
             $fieldObject->setCaption($field[0]['caption']);
             $fieldObject->setCompulsory($field[0]['compulsory']);
             $fieldObject->setIsUnique($field[0]['isUnique']);
             $fieldObject->setDescription($field[0]['description']);
             $fieldObject->setHashistory($field[0]['hashistory']);
             $fieldObject->setHastarget($field[0]['hastarget']);
             $fieldObject->setDataType($dataType);
             $fieldObject->setInputType($inputType);
             $fieldObject->setIsCalculated($field[0]['isCalculated']);
             // $fieldObject->setDatecreated($field[0]['datecreated']);
             $em->persist($fieldObject);
             $refField[$field['uid']] = $field[0]['uid'];
         }
     }
     $em->flush();
     return new Response('success');
 }
Beispiel #2
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";
 }