/** * Get employee list after sorting and filtering using given parameters. * * @param EmployeeSearchParameterHolder $parameterHolder */ public function searchEmployees(EmployeeSearchParameterHolder $parameterHolder) { $sortField = $parameterHolder->getOrderField(); $sortOrder = $parameterHolder->getOrderBy(); $offset = $parameterHolder->getOffset(); $limit = $parameterHolder->getLimit(); $filters = $parameterHolder->getFilters(); $returnType = $parameterHolder->getReturnType(); $select = ''; $query = ''; $bindParams = array(); $orderBy = ''; $this->_getEmployeeListQuery($select, $query, $bindParams, $orderBy, $sortField, $sortOrder, $filters); $completeQuery = $select . ' ' . $query . ' ' . $orderBy; if (!is_null($offset) && !is_null($limit)) { $completeQuery .= ' LIMIT ' . $offset . ', ' . $limit; } if (sfConfig::get('sf_logging_enabled')) { $msg = $completeQuery; if (count($bindParams) > 0) { $msg .= ' (' . implode(',', $bindParams) . ')'; } sfContext::getInstance()->getLogger()->info($msg); } $conn = Doctrine_Manager::connection(); $statement = $conn->prepare($completeQuery); $result = $statement->execute($bindParams); if ($returnType == EmployeeSearchParameterHolder::RETURN_TYPE_OBJECT) { $employees = new Doctrine_Collection(Doctrine::getTable('Employee')); if ($result) { while ($row = $statement->fetch()) { $employee = new Employee(); $employee->setEmpNumber($row['empNumber']); $employee->setEmployeeId($row['employeeId']); $employee->setFirstName($row['firstName']); $employee->setMiddleName($row['middleName']); $employee->setLastName($row['lastName']); $employee->setTerminationId($row['terminationId']); $jobTitle = new JobTitle(); $jobTitle->setId($row['jobTitleId']); $jobTitle->setJobTitleName($row['jobTitle']); $jobTitle->setIsDeleted($row['isDeleted']); $employee->setJobTitle($jobTitle); $employeeStatus = new EmploymentStatus(); $employeeStatus->setId($row['employeeStatusId']); $employeeStatus->setName($row['employeeStatus']); $employee->setEmployeeStatus($employeeStatus); $workStation = new SubUnit(); $workStation->setName($row['subDivision']); $workStation->setId($row['subDivisionId']); $employee->setSubDivision($workStation); $supervisorList = isset($row['supervisors']) ? $row['supervisors'] : ''; if (!empty($supervisorList)) { $supervisors = new Doctrine_Collection(Doctrine::getTable('Employee')); $supervisorArray = explode(',', $supervisorList); foreach ($supervisorArray as $supervisor) { list($first, $middle, $last) = explode('##', $supervisor); $supervisor = new Employee(); $supervisor->setFirstName($first); $supervisor->setMiddleName($middle); $supervisor->setLastName($last); $employee->supervisors[] = $supervisor; } } $locationList = $row['locationIds']; if (!empty($locationList)) { // $locations = new Doctrine_Collection(Doctrine::getTable('EmpLocations')); $locationArray = explode(',', $locationList); foreach ($locationArray as $location) { list($id, $name) = explode('##', $location); $empLocation = new Location(); $empLocation->setId($id); $empLocation->setName($name); $employee->locations[] = $empLocation; } } $employees[] = $employee; } } } else { return $statement->fetchAll(); } return $employees; }