/** * get existing employee * * @param HumanResources_Model_Employee $employee * @return HumanResources_Model_Employee */ protected function _getCurrentEmployee($employee) { $result = NULL; $currentEmployee = NULL; if ($employee->getId()) { try { $currentEmployee = HumanResources_Controller_Employee::getInstance()->get($employee->getId()); $currentEmployee->contracts = HumanResources_Controller_Contract::getInstance()->getContractsByEmployeeId($employee->getId())->toArray(); if ($currentEmployee->n_fn === $employee->n_fn) { return $currentEmployee; } } catch (Tinebase_Exception_NotFound $tenf) { $currentEmployee = NULL; } } $result = HumanResources_Controller_Employee::getInstance()->search(new HumanResources_Model_EmployeeFilter(array(array('field' => 'query', 'operator' => 'contains', 'value' => $employee->n_fn))))->getFirstRecord(); if ($result === NULL && $currentEmployee !== NULL) { // use the employee with matching number if no one with the same name could be found $result = $currentEmployee; } return $result; }