public function parseEditData($postArr) { $tmpObj = new Workshift(); if (!empty($postArr['txtShiftId']) && !empty($postArr['txtShiftName']) && !empty($postArr['txtHoursPerDay'])) { $tmpObj->setWorkshiftId($postArr['txtShiftId']); $tmpObj->setName($postArr['txtShiftName']); $tmpObj->setHoursPerDay($postArr['txtHoursPerDay']); $assignedEmployees = array(); if (isset($postArr['cmbAssignedEmployees']) && is_array($postArr['cmbAssignedEmployees'])) { foreach ($postArr['cmbAssignedEmployees'] as $empNum) { $assignedEmployees[] = $empNum; } } } return array($tmpObj, $assignedEmployees); }
/** * Test method for getAssignedEmployees */ public function testGetAssignedEmployees() { $workshift = new Workshift(); try { $workshift->getAssignedEmployees(); $this->fail("Trying to fetch assigned employees without setting workshift id should throw exception"); } catch (WorkshiftException $e) { $this->assertEquals(WorkshiftException::INVALID_ID, $e->getCode()); } // Workshift not in system $workshift->setWorkshiftId(1); $employees = $workshift->getAssignedEmployees(); $this->assertEquals(0, count($employees)); $this->assertTrue(mysql_query("INSERT INTO " . Workshift::WORKSHIFT_TABLE . " VALUES ('1' , 'New Test Shift', '5')")); $this->assertTrue(mysql_query("INSERT INTO " . Workshift::WORKSHIFT_TABLE . " VALUES ('2' , 'Workshift 2', '10')")); // Workshift with no assigned employees $workshift->setWorkshiftId(2); $employees = $workshift->getAssignedEmployees(); $this->assertEquals(0, count($employees)); $this->assertTrue(mysql_query("INSERT INTO hs_hr_employee_workshift(workshift_id, emp_number) VALUES (1, 1)")); $this->assertTrue(mysql_query("INSERT INTO hs_hr_employee_workshift(workshift_id, emp_number) VALUES (2, 2)")); $this->assertTrue(mysql_query("INSERT INTO hs_hr_employee_workshift(workshift_id, emp_number) VALUES (2, 3)")); $expected[2] = array(2, '0022', 'Jayasinghe', 'Aruna', 'Shantha'); $expected[3] = array(3, '0034', 'Ranasinghe', 'Nimal', 'Bandara'); $employees = $workshift->getAssignedEmployees(); $this->assertEquals(2, count($employees)); $this->_checkEmployeeList($employees, $expected); $workshift->setWorkshiftId(1); $employees = $workshift->getAssignedEmployees(); unset($expected); $expected[1] = array(1, '0011', 'Rajasinghe', 'Saman', 'Marlon'); $this->assertEquals(1, count($employees)); $this->_checkEmployeeList($employees, $expected); }
/** * Return array of workshift objects from the given results set * @return array Array of Workshift objects */ private function _getWorkshiftsFromResults($results) { $workshiftArray = array(); while ($row = mysql_fetch_array($results)) { $workshiftObj = new Workshift(); $workshiftObj->setWorkshiftId($row[self::DB_FIELD_WORKSHIFT_ID]); $workshiftObj->setName($row[self::DB_FIELD_NAME]); $workshiftObj->setHoursPerDay($row[self::DB_FIELD_HOURS]); $workshiftArray[] = $workshiftObj; } return $workshiftArray; }