Esempio n. 1
0
                 throw new RuntimeException("Shift does not exist", 404);
             }
             $shift = new Shift($id, $requestObject->shiftUserId, $requestObject->shiftCrewId, $requestObject->shiftRequestId, $requestObject->shiftStartTime, $requestObject->shiftDuration, $requestObject->shiftDate, $requestObject->shiftDelete);
             $shift->update($pdo);
             $reply->message = "Shift updated OK";
         } else {
             if ($method === "POST") {
                 $shift = new Shift(null, $requestObject->shiftUserId, $requestObject->shiftCrewId, $requestObject->shiftRequestId, $requestObject->shiftStartTime, $requestObject->shiftDuration, $requestObject->shiftDate, $requestObject->shiftDelete);
                 $shift->insert($pdo);
                 $reply->message = "Shift created OK";
             }
         }
     } else {
         if ($method === "DELETE") {
             verifyXsrf();
             $shift = Shift::getShiftByShiftId($pdo, $id);
             if ($shift === null) {
                 throw new RuntimeException("Shift does not exist", 404);
             }
             $shift->delete($pdo);
             $deleteObject = new \stdClass();
             $deleteObject->shiftId = $id;
             $reply->message = "Shift 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);
     }
 }
 public function testGetShiftByShiftRequestId()
 {
     //count the number of rows and save it for later
     $numRows = $this->getConnection()->getRowCount("shift");
     //create a new Shift and insert to into mySQL
     $shift = new Shift(null, $this->requestor->getUserId(), $this->crew->getCrewId(), $this->request->getRequestId(), $this->VALID_SHIFTSTARTTIME, $this->VALID_SHIFTDURATION, $this->VALID_SHIFTDATE, $this->VALID_SHIFTDELETE);
     $shift->insert($this->getPDO());
     //grab the data from mySQL and enforce the fields match our expectations
     $pdoShift = Shift::getShiftByShiftRequestId($this->getPDO(), $shift->getShiftRequestId());
     $this->assertEquals($numRows + 1, $this->getConnection()->getRowCount("shift"));
     $this->assertEquals($pdoShift->getShiftUserId(), $this->requestor->getUserId());
     $this->assertEquals($pdoShift->getShiftCrewId(), $this->crew->getCrewId());
     $this->assertEquals($pdoShift->getShiftRequestId(), $this->request->getRequestId());
     $this->assertEquals($pdoShift->getShiftStartTime(), $this->VALID_SHIFTSTARTTIME);
     $this->assertEquals($pdoShift->getShiftDuration(), $this->VALID_SHIFTDURATION);
     $this->assertEquals($pdoShift->getShiftDate()->format("Y-m-d"), $this->VALID_SHIFTDATE);
     $this->assertEquals($pdoShift->getShiftDelete(), $this->VALID_SHIFTDELETE);
 }