예제 #1
0
                 throw new RuntimeException("Schedule does not exist", 404);
             }
             $schedule = new Schedule($id, $requestObject->scheduleCrewId, $requestObject->scheduleStartDate);
             $schedule->update($pdo);
             $reply->message = "Schedule updated OK";
         } else {
             if ($method === "POST") {
                 $schedule = new Schedule(null, $requestObject->scheduleCrewId, $requestObject->scheduleStartDate);
                 $schedule->insert($pdo);
                 $reply->message = "Schedule created OK";
             }
         }
     } else {
         if ($method === "DELETE") {
             verifyXsrf();
             $schedule = Schedule::getScheduleByScheduleId($pdo, $id);
             if ($schedule === null) {
                 throw new RuntimeException("Schedule does not exist", 404);
             }
             $schedule->delete($pdo);
             $deletedObject = new stdClass();
             $deletedObject->scheduleId = $id;
             $reply->message = "Schedule deleted OK";
         }
     }
 } else {
     //if not an admin, and attempting a method other than get, throw an exception
     if (empty($method) === false && $method !== "GET") {
         throw new RuntimeException("Only administrators are allowed to modify entries", 401);
     }
 }
 /**
  * test grabbing a Schedule that does not exist
  **/
 public function testGetInvalidScheduleByScheduleId()
 {
     // grab a crew id that exceeds the maximum allowable scheduleCrew id
     $schedule = Schedule::getScheduleByScheduleId($this->getPDO(), TimeCrunchersTest::INVALID_KEY);
     $this->assertNull($schedule);
 }