/**
  * Save supervisors and subordinates
  */
 public function save()
 {
     $updated = false;
     $empNumber = $this->getValue('empNumber');
     $supOrSub = $this->getValue('type_flag');
     $empData = $this->getValue('name');
     $name = $empData['empName'];
     $reportingType = $this->getValue('reportingMethodType');
     $reportingMethod = $this->getValue('reportingMethod');
     $selectedEmployee = $empData['empId'];
     $previousRecord = $this->getValue('previousRecord');
     if ($reportingMethod != null) {
         $newReportingMethod = new ReportingMethod();
         $newReportingMethod->name = $reportingMethod;
         $savedReportingMethod = $this->getReportingMethodService()->saveReportingMethod($newReportingMethod);
         $reportingType = $savedReportingMethod->id;
     }
     if ($supOrSub == ReportTo::SUPERVISOR) {
         $existingReportToObject = $this->getEmployeeService()->getReportToObject($selectedEmployee, $empNumber);
         if ($existingReportToObject != null) {
             $existingReportToObject->setReportingMethodId($reportingType);
             $existingReportToObject->save();
         } else {
             $newReportToObject = new ReportTo();
             $newReportToObject->setSupervisorId($selectedEmployee);
             $newReportToObject->setSubordinateId($empNumber);
             $newReportToObject->setReportingMethodId($reportingType);
             $newReportToObject->save();
         }
     }
     if ($supOrSub == ReportTo::SUBORDINATE) {
         $existingReportToObject = $this->getEmployeeService()->getReportToObject($empNumber, $selectedEmployee);
         if ($existingReportToObject != null) {
             $existingReportToObject->setReportingMethodId($reportingType);
             $existingReportToObject->save();
         } else {
             $newReportToObject = new ReportTo();
             $newReportToObject->setSupervisorId($empNumber);
             $newReportToObject->setSubordinateId($selectedEmployee);
             $newReportToObject->setReportingMethodId($reportingType);
             $newReportToObject->save();
         }
     }
     $returnValue = array($supOrSub, $updated);
     return $returnValue;
 }
 /**
  * Save supervisors and subordinates
  */
 public function save()
 {
     $message = 'failed';
     $updated = FALSE;
     $empNumber = $this->getValue('empNumber');
     $supOrSub = $this->getValue('type_flag');
     $supervisorName = $this->getValue('supervisorName');
     $subordinateName = $this->getValue('subordinateName');
     if ($supervisorName['empId'] != '') {
         $name = $supervisorName['empName'];
         $selectedEmployee = $supervisorName['empId'];
     } else {
         if ($subordinateName['empId'] != '') {
             $name = $subordinateName['empName'];
             $selectedEmployee = $subordinateName['empId'];
         }
     }
     $reportingType = $this->getValue('reportingMethodType');
     $reportingMethod = $this->getValue('reportingMethod');
     $previousRecord = $this->getValue('previousRecord');
     if ($reportingMethod != null) {
         $newReportingMethod = new ReportingMethod();
         $newReportingMethod->name = $reportingMethod;
         $savedReportingMethod = $this->getReportingMethodConfigurationService()->saveReportingMethod($newReportingMethod);
         $reportingType = $savedReportingMethod->id;
     }
     if ($supOrSub == ReportTo::SUPERVISOR) {
         $existingReportToObject = $this->getEmployeeService()->getReportToObject($selectedEmployee, $empNumber);
         if ($existingReportToObject != null) {
             if ($this->getOption('reportToSupervisorPermission')->canUpdate()) {
                 $existingReportToObject->setReportingMethodId($reportingType);
                 $existingReportToObject->save();
                 $updated = TRUE;
                 $message = 'updated';
             }
         } else {
             if ($this->getOption('reportToSupervisorPermission')->canCreate()) {
                 $newReportToObject = new ReportTo();
                 $newReportToObject->setSupervisorId($selectedEmployee);
                 $newReportToObject->setSubordinateId($empNumber);
                 $newReportToObject->setReportingMethodId($reportingType);
                 $newReportToObject->save();
                 $updated = TRUE;
                 $message = 'saved';
             }
         }
     }
     if ($supOrSub == ReportTo::SUBORDINATE) {
         $existingReportToObject = $this->getEmployeeService()->getReportToObject($empNumber, $selectedEmployee);
         if ($existingReportToObject != null) {
             if ($this->getOption('reportToSubordinatePermission')->canUpdate()) {
                 $existingReportToObject->setReportingMethodId($reportingType);
                 $existingReportToObject->save();
                 $updated = TRUE;
                 $message = 'updated';
             }
         } else {
             if ($this->getOption('reportToSubordinatePermission')->canCreate()) {
                 $newReportToObject = new ReportTo();
                 $newReportToObject->setSupervisorId($empNumber);
                 $newReportToObject->setSubordinateId($selectedEmployee);
                 $newReportToObject->setReportingMethodId($reportingType);
                 $newReportToObject->save();
                 $updated = TRUE;
                 $message = 'saved';
             }
         }
     }
     $returnValue = array($supOrSub, $updated, $message);
     return $returnValue;
 }