public function viewShifts() { if ($_SESSION['isAdmin'] == 'No') { die('You are not authorized to view this page'); } $path = "/templates/time/workShifts.php"; $objs[] = Workshift::getWorkshifts(); $template = new TemplateMerger($objs, $path); $template->display(); }
/** * Test case for testGetWorkshifts(). */ public function testGetWorkshifts() { // No workshifts, should return empty array $workshifts = Workshift::getWorkshifts(); $this->assertTrue(is_array($workshifts)); $this->assertEquals(0, count($workshifts)); // Only one workshift, should return array with one workshift $sql = "INSERT INTO " . Workshift::WORKSHIFT_TABLE . " VALUES ('1' , 'New Test Shift', '5')"; $this->assertTrue(mysql_query($sql)); $workshifts = Workshift::getWorkshifts(); $this->assertTrue(is_array($workshifts)); $this->assertEquals(1, count($workshifts)); $this->assertEquals('New Test Shift', $workshifts[0]->getName()); $this->assertEquals(1, $workshifts[0]->getWorkshiftId()); $this->assertEquals(5, $workshifts[0]->getHoursPerDay()); // Many workshifts, should return array with all available workshifts $sql = "INSERT INTO " . Workshift::WORKSHIFT_TABLE . " VALUES ('2' , 'Workshift 2', '8')"; $this->assertTrue(mysql_query($sql)); $sql = "INSERT INTO " . Workshift::WORKSHIFT_TABLE . " VALUES ('3' , 'Workshift 3', '6')"; $this->assertTrue(mysql_query($sql)); $workshifts = Workshift::getWorkshifts(); $this->assertTrue(is_array($workshifts)); $this->assertEquals(3, count($workshifts)); $ids = array(1, 2, 3); $names = array("New Test Shift", "Workshift 2", "Workshift 3"); $hours = array(5, 8, 6); foreach ($workshifts as $workshift) { $id = $workshift->getWorkshiftId(); $index = array_search($id, $ids); $this->assertTrue($index !== false); $this->assertEquals($names[$index], $workshift->getName()); $this->assertEquals($hours[$index], $workshift->getHoursPerDay()); unset($ids[$index]); unset($names[$index]); unset($hours[$index]); } }
private function _isWorkshiftNameAvailable($workShift) { $flag = 0; $objs = Workshift::getWorkshifts(); foreach ($objs as $workShiftSelect) { if (strtolower($workShiftSelect->getName()) == strtolower($workShift->getName())) { $flag = 1; break; } } if ($flag == 1) { return true; } return false; }