appbox = $appbox; $this->id = $id; $sql = 'SELECT `type`, `data`, created FROM api_webhooks WHERE id = :id'; $stmt = $this->appbox->get_connection()->prepare($sql); $stmt->execute(array(':id' => $id)); $row = $stmt->fetch(\PDO::FETCH_ASSOC); if (!$row) { throw new RuntimeException('Webhooks not found'); } $stmt->closeCursor(); $this->type = $row['type']; $this->data = json_decode($row['data']); $this->created = new \DateTime($row['created']); } public function delete() { $sql = 'DELETE FROM api_webhooks WHERE id = :id'; $stmt = $this->appbox->get_connection()->prepare($sql); $stmt->execute(array(':id' => $this->id)); $stmt->closeCursor(); return; } public static function create(appbox $appbox, $type, array $data) { $sql = 'INSERT INTO api_webhooks (id, `type`, `data`, created) VALUES (null, :type, :data, NOW())'; $stmt = $appbox->get_connection()->prepare($sql); $stmt->execute(array( 'type' => $type, 'data' => json_encode($data), )); $stmt->closeCursor(); return new API_Webhook($appbox, $appbox->get_connection()->lastInsertId()); } /** * @return \DateTime */ public function getCreated() { return $this->created; } /** * @return mixed */ public function getData() { return $this->data; } /** * @return mixed */ public function getType() { return $this->type; } }