Exemplo n.º 1
0
 public function save()
 {
     $workShiftId = $this->getValue('workShiftId');
     if (empty($workShiftId)) {
         $workShift = new WorkShift();
         $empArray = $this->getValue('assignedEmp');
         $workShift->setName($this->getValue('name'));
         $workShift->setHoursPerDay($this->getValue('hours'));
         $workShift->save();
     } else {
         $workShift = $this->getWorkShiftService()->getWorkShiftById($workShiftId);
         $workShift->setName($this->getValue('name'));
         $workShift->setHoursPerDay($this->getValue('hours'));
         $this->getWorkShiftService()->updateWorkShift($workShift);
         $employees = $this->getValue('assignedEmp');
         $existingEmployees = $workShift->getEmployeeWorkShift();
         $idList = array();
         if ($existingEmployees[0]->getEmpNumber() != "") {
             foreach ($existingEmployees as $existingEmployee) {
                 $id = $existingEmployee->getEmpNumber();
                 if (!in_array($id, $employees)) {
                     $existingEmployee->delete();
                 } else {
                     $idList[] = $id;
                 }
             }
         }
         $this->resultArray = array();
         $employeeList = array_diff($employees, $idList);
         $newList = array();
         foreach ($employeeList as $employee) {
             $newList[] = $employee;
         }
         $empArray = $newList;
     }
     $this->_saveEmployeeWorkShift($workShift->getId(), $empArray);
 }