Exemplo n.º 1
0
     //Set XSRF cookie
     setXsrfCookie("/");
     //Get Schedule based on given field
     if (empty($id) === false) {
         $schedule = Schedule::getScheduleByScheduleId($pdo, $id);
         if ($schedule !== null) {
             $reply->data = $schedule;
         }
     } else {
         if (empty($scheduleAddress1) === false) {
             $schedule = Schedule::getScheduleByScheduleCrewId($pdo, $id);
             if ($schedule !== null) {
                 $reply->data = $schedule;
             }
         } else {
             $schedules = Schedule::getAllSchedules($pdo);
             if ($schedules !== null) {
                 $reply->data = $schedules;
             }
         }
     }
 }
 //	block non-admin users from doing admin-only tasks
 if (Access::isAdminLoggedIn() === true) {
     if ($method === "PUT" || $method === "POST") {
         verifyXsrf();
         $requestContent = file_get_contents("php://input");
         $requestObject = json_decode($requestContent);
         //make sure all fields are present, in order to prevent database issues
         if (empty($requestObject->scheduleCrewId) === true) {
             throw new InvalidArgumentException("crew ID for this schedule cannot be empty", 405);
 /**
  * test grabbing all Schedules
  **/
 public function testGetAllValidSchedules()
 {
     // count the number of rows and save it for later
     $numRows = $this->getConnection()->getRowCount("schedule");
     // create a new Schedule and insert to into mySQL
     $schedule = new Schedule(null, $this->crew->getCrewId(), $this->VALID_SCHEDULESTARTDATE);
     $schedule->insert($this->getPDO());
     // grab the data from mySQL and enforce the fields match our expectations
     $results = Schedule::getAllSchedules($this->getPDO());
     $this->assertEquals($numRows + 1, $this->getConnection()->getRowCount("schedule"));
     $this->assertCount(1, $results);
     $this->assertContainsOnlyInstancesOf("Edu\\Cnm\\Timecrunchers\\Schedule", $results);
     // grab the result from the array and validate it
     $pdoSchedule = $results[0];
     $this->assertEquals($pdoSchedule->getScheduleCrewId(), $this->crew->getCrewId());
     $this->assertSame($pdoSchedule->getScheduleStartDate()->format("Y:m:d"), $schedule->getScheduleStartDate()->format("Y:m:d"));
 }