Beispiel #1
0
            $alertLevel->insert($pdo);
            $reply->data = "AlertLevel created OK";
            // delete an existing AlertLevel
        } else {
            if ($method === "DELETE") {
                verifyXsrf();
                $alertLevel = AlertLevel::getAlertLevelByAlertId($pdo, $alertId);
                $alertLevel->delete($pdo);
                $reply->data = "AlertLevel deleted OK";
                // put to an existing AlertLevel
            } else {
                if ($method === "PUT") {
                    // convert PUTed JSON to an object
                    verifyXsrf();
                    $requestContent = file_get_contents("php://input");
                    $requestObject = json_decode($requestContent);
                    $alertLevel = new AlertLevel($alertId, $requestObject->alertCode, $requestObject->alertFrequency, $requestObject->alertPoint, $requestObject->alertOperator);
                    $alertLevel->update($pdo);
                    $reply->data = "AlertLevel Updated Ok";
                }
            }
        }
    }
    // create an exception to pass back to the RESTful caller
} catch (Exception $exception) {
    $reply->status = $exception->getCode();
    $reply->message = $exception->getMessage();
    unset($reply->data);
}
header("Content-type: application/json");
echo json_encode($reply);
 /**
  * test updating a alert level that does not exist
  *
  * @expectedException PDOException
  **/
 public function testUpdateInvalidAlertLevel()
 {
     //create an Alert Level and try to update it without actually inserting it
     $alertLevel = new AlertLevel(null, $this->VALID_alertCode, $this->VALID_alertFrequency, $this->VALID_alertPoint, $this->VALID_alertOperator);
     $alertLevel->update($this->getPDO());
 }