/** * {@inheritDoc} */ public function doLoad(ObjectManager $manager) { // The ages are based on the hungarin law of 2014 year. $ages = array(0 => 20, 25 => 21, 28 => 22, 31 => 23, 33 => 24, 35 => 25, 37 => 26, 39 => 27, 41 => 28, 43 => 29, 45 => 30); foreach ($ages as $key => $value) { $leaveSetting = new LeaveSetting(); $leaveSetting->setNumber($key); $leaveSetting->setNumberOfLeaves($value); $leaveSetting->setLeaveGroup($this->getReference('age')); $manager->persist($leaveSetting); } // The number of kids are based on the hungarin law of 2014 year. $kids = array(1 => 2, 2 => 4, 3 => 7); foreach ($kids as $key => $value) { $leaveSetting = new LeaveSetting(); $leaveSetting->setNumber($key); $leaveSetting->setNumberOfLeaves($value); $leaveSetting->setLeaveGroup($this->getReference('children')); $manager->persist($leaveSetting); } $manager->flush(); }
/** * Set the leave setting entity * * @param \Opit\OpitHrm\LeaveBundle\Entity\LeaveSetting $leaveSetting * @param array $data value of leave setting * @return int|boolean */ protected function setLeaveSettingData($leaveSetting, $data) { $em = $this->getDoctrine()->getManager(); $result = array(); $result['status'] = 200; //If it is a new leave setting create, else modify it. if (false === $leaveSetting) { // Create a new leave setting and save it. $leaveSetting = new LeaveSetting(); } $leaveSetting->setNumber($data['number']); $leaveSetting->setNumberOfLeaves($data['numberOfLeaves']); // get the leave group entity by id $leaveGroup = $em->getRepository('OpitOpitHrmLeaveBundle:LeaveGroup')->find((int) $data['leaveGroup']); $leaveSetting->setLeaveGroup($leaveGroup); $validator = $this->get('validator'); $errors = $validator->validate($leaveSetting); // If the validation failed if (count($errors) > 0) { $result['status'] = 500; $result['response'] = 'error'; // Get the error messages. foreach ($errors as $e) { $result['errorMessage'][] = $e->getMessage(); } } else { $em->persist($leaveSetting); $em->flush(); } return $result; }