From 7ad83909ffbbc48ca7966d05ee40fe7c4413e813 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 17 Aug 2021 00:02:41 +0300 Subject: [PATCH] add authors page --- app/api/book.php | 59 +++++++++++++++++++++++++++++------- app/routes/books.php | 70 +++++++++++++++++++++++++++++++++++++++++-- app/views/book.phtml | 5 ++++ app/views/books.phtml | 11 +++++-- 4 files changed, 130 insertions(+), 15 deletions(-) diff --git a/app/api/book.php b/app/api/book.php index dbe298f..a3c9c31 100644 --- a/app/api/book.php +++ b/app/api/book.php @@ -7,11 +7,30 @@ function bookid_kuri($slug) { $query = " SELECT - `price_id`, `pricename`, `categoryname`, `priceslug`, `categoryslug`, price.category_id AS category_id, `BeginDate`, `priceanons`, `priceimg`, `pricehash`, `pieces`, `price`, `offline_price`, `sub` + `price_id`, + `pricename`, + `categoryname`, + `priceslug`, + `categoryslug`, + price.category_id AS category_id, + `BeginDate`, + `priceanons`, + `priceimg`, + `pricehash`, + `pieces`, + `price`, + `offline_price`, + `sub`, + `authorslug`, + `author`, + `priceauthor_id` FROM `price` LEFT JOIN `pricecategory` - ON price.category_id = pricecategory.category_id + ON price.category_id = pricecategory.category_id + LEFT JOIN `price_authors` + ON `price`.`priceauthor_id` = `price_authors`.`author_id` + WHERE `priceslug` = '$slug' LIMIT 1 @@ -43,8 +62,9 @@ function bookid_kuri($slug) { /** * вернуть товары магазина (все или по фильтру) + * */ -function api_books_kuri($category = 'knigi', $filter = 'all', $page = 1){ +function api_books_kuri($filter = 'all', $page = 1){ $limit = 24; @@ -55,13 +75,20 @@ function api_books_kuri($category = 'knigi', $filter = 'all', $page = 1){ else { $offset_str = 0; } + + - if ($category == 'all'){ + if ($filter == 'all'){ $where = ''; } - else { + else { + $where = "$filter "; + } - $category_sql = "SELECT `category_id` FROM `pricecategory` WHERE `categoryslug` = '$category' LIMIT 1"; + + //`categoryslug` = '$category' + + /* $category_sql = "SELECT `category_id` FROM `pricecategory` WHERE $filter LIMIT 1"; $category = db_get($category_sql); @@ -70,9 +97,14 @@ function api_books_kuri($category = 'knigi', $filter = 'all', $page = 1){ $where = "WHERE `category_id` = $category_id"; } - } + } */ + + if ($where !== '') + $where .= "AND `active` = 1 "; + else + $where .= "`active` = 1 "; - $db_count = db_get("SELECT COUNT(price_id) AS count FROM `price` $where LIMIT 1;"); + $db_count = db_get("SELECT COUNT(price_id) AS count FROM `price` WHERE $where LIMIT 1;"); if (isset($db_count['error'])) return False; @@ -80,8 +112,15 @@ function api_books_kuri($category = 'knigi', $filter = 'all', $page = 1){ if (isset($db_count['count'])) $count = $db_count['count']; - $sql_books = "SELECT * FROM `price` $where AND `active` = 1 ORDER BY `price_id` DESC LIMIT $limit OFFSET $offset_str"; - + $sql_books = " + SELECT + * + FROM `price` + LEFT JOIN `price_authors` ON `price`.`priceauthor_id` = `price_authors`.`author_id` + WHERE $where + ORDER BY `price_id` DESC + LIMIT $limit OFFSET $offset_str"; + //echo $sql_books.'
'; $books = db_get($sql_books); if (!isset($books['error'])) { diff --git a/app/routes/books.php b/app/routes/books.php index d52172e..203a426 100644 --- a/app/routes/books.php +++ b/app/routes/books.php @@ -36,22 +36,36 @@ function product_kuri($slug){ } + +/** + * категории товаров + */ + function category_kuri($category = '', $filter = 'all', $page = 1){ if ($category == ''){ - if (SUBSTATUS == 1){ + if (SUBSTATUS == 1){ // категория по умолчанию $category = 'gazeta'; + $filter = "category_id = 1"; } else { $category = 'knigi'; + $filter = "category_id = 3"; } } - + elseif ($category == 'gazeta') { + $filter = "category_id = 1"; + } + elseif ($category == 'knigi') { + $filter = "category_id = 3"; + } + $cats = api_cats(); - $books = api_books_kuri($category, $filter, $page); + + $books = api_books_kuri($filter, $page); $baseurl = SITE."category/$category/$filter/"; @@ -81,4 +95,54 @@ function category_kuri($category = '', $filter = 'all', $page = 1){ $tempcontent = VIEWPATH.'books.phtml'; include VIEWPATH.'layout.phtml'; +} + +/** + * книги авторов + */ +function author_kuri($slug, $page = 1){ + + $find_author_sql = "SELECT * FROM `price_authors` WHERE `authorslug` = '$slug' LIMIT 1"; + $find_author = db_get($find_author_sql); + + + if (!isset($find_author['author_id'])){ # 404 + echo 'not fount'; + exit; + } + + $filter = "`priceauthor_id` = ".$find_author['author_id']; + + $books = api_books_kuri($filter, $page); + $baseurl = SITE."author/$slug/"; + + if ($books['pages'] > 1){ + $endurl = $baseurl.$books['pages']; + } + + if ($page > 1) { + $pagetitle = $find_author['author'].". Книги - страница $page"; + $prevpage = $page - 1 ; + $prevurl = $baseurl.$prevpage; + + } + else { + $pagetitle = $find_author['author'].". Книги"; + } + + if ($page < $books['pages']){ + $nextpage = $page+1; + $nexturl = $baseurl.$nextpage; + } + + + $breadcrumbs['page'] = $pagetitle; + + + $tempcontent = VIEWPATH.'books.phtml'; + include VIEWPATH.'layout.phtml'; + + + + } \ No newline at end of file diff --git a/app/views/book.phtml b/app/views/book.phtml index 5a7ca26..9242901 100644 --- a/app/views/book.phtml +++ b/app/views/book.phtml @@ -4,6 +4,11 @@

Артикул

+ 1):?> +

+ +

+

diff --git a/app/views/books.phtml b/app/views/books.phtml index 39c9272..fefa933 100644 --- a/app/views/books.phtml +++ b/app/views/books.phtml @@ -6,9 +6,16 @@ <?=$book['pricename']?> -

+ 1):?> +

+ +

+ +

+ +

- Читать + Читать