From f7bfdf58def6aadc922e1632f407d1418269a0d7 Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Sat, 9 Jul 2022 19:40:17 +0300 Subject: initial --- lib/pages.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 lib/pages.php (limited to 'lib/pages.php') diff --git a/lib/pages.php b/lib/pages.php new file mode 100644 index 0000000..281ee52 --- /dev/null +++ b/lib/pages.php @@ -0,0 +1,32 @@ +insert('pages', $data)) + return null; + return $db->insertId(); + } + + public static function delete(Page $page): void { + getDb()->query("DELETE FROM pages WHERE short_name=?", $page->shortName); + } + + public static function getPageByName(string $short_name): ?Page { + $db = getDb(); + $q = $db->query("SELECT * FROM pages WHERE short_name=?", $short_name); + return $db->numRows($q) ? new Page($db->fetch($q)) : null; + } + + /** + * @return Page[] + */ + public static function getAll(): array { + $db = getDb(); + return array_map('Page::create_instance', $db->fetchAll($db->query("SELECT * FROM pages"))); + } + +} \ No newline at end of file -- cgit v1.2.3