Ejemplo n.º 1
0
                if ($request === null) {
                    throw new RuntimeException("Request does not exist", 404);
                }
                $request->setRequestAdminId($_SESSION["user"]->getUserId());
                $request->setRequestApprove((bool) $requestObject->requestApprove);
                $request->setRequestActionTimeStamp(new DateTime());
                $request->setRequestAdminText($requestObject->requestAdminText);
                $request->update($pdo);
                $reply->message = "Request updated successfully";
            }
        } else {
            throw new RuntimeException("Must be an Administrator");
        }
    } elseif ($method === "DELETE") {
        verifyXsrf();
        $request = Request::getRequestByRequestId($pdo, $id);
        if ($request === null) {
            throw new RuntimeException("Request does not exist", 404);
        }
        $request->delete($pdo);
        $deletedObject = new stdClass();
        $deletedObject->requestId = $id;
        $reply->message = "Request deleted successfully";
    }
} catch (Exception $exception) {
    $reply->status = $exception->getCode();
    $reply->message = $exception->getMessage();
} catch (TypeError $typeError) {
    $reply->status = $typeError->getCode();
    $reply->message = $typeError->getMessage();
}
Ejemplo n.º 2
0
 /**
  * test grabbing all Requests
  **/
 public function testGetAllValidRequests()
 {
     // count the number of rows and save it for later
     $numRows = $this->getConnection()->getRowCount("request");
     // create a new Request and insert to into mySQL
     $request = new Request(null, $this->requestor->getUserId(), $this->admin->getUserId(), $this->VALID_REQUESTTIMESTAMP, $this->VALID_REQUESTACTIONTIMESTAMP, $this->requestApprove, $this->VALID_REQUESTREQUESTORTEXT, $this->VALID_REQUESTADMINTEXT);
     $request->insert($this->getPDO());
     // grab the data from mySQL and enforce the fields match our expectations
     $results = Request::getAllRequests($this->getPDO());
     $this->assertEquals($numRows + 1, $this->getConnection()->getRowCount("request"));
     $this->assertCount(1, $results);
     $this->assertContainsOnlyInstancesOf("Edu\\Cnm\\TimeCrunchers\\Request", $results);
     // grab the result from the array and validate it
     $pdoRequest = $results[0];
     $this->assertEquals($pdoRequest->getRequestRequestorId(), $this->requestor->getUserId());
     $this->assertEquals($pdoRequest->getRequestAdminId(), $this->admin->getUserId());
     $this->assertEquals($pdoRequest->getRequestTimeStamp(), $this->VALID_REQUESTTIMESTAMP);
     $this->assertEquals($pdoRequest->getRequestActionTimeStamp(), $this->VALID_REQUESTACTIONTIMESTAMP);
     $this->assertEquals($pdoRequest->getRequestApprove(), $this->requestApprove);
     $this->assertEquals($pdoRequest->getRequestRequestorText(), $this->VALID_REQUESTREQUESTORTEXT2);
     $this->assertEquals($pdoRequest->getRequestAdminText(), $this->VALID_REQUESTADMINTEXT);
 }