Files
anpdf/app/api/book.php

238 lines
4.8 KiB
PHP
Raw Normal View History

2021-01-13 21:09:17 +03:00
<?php
/**
*
*/
2021-05-24 01:13:43 +03:00
function bookid_kuri($slug) {
2021-01-13 21:09:17 +03:00
2021-05-24 01:13:43 +03:00
$query = "
SELECT
2021-08-17 00:02:41 +03:00
`price_id`,
`pricename`,
`categoryname`,
`priceslug`,
`categoryslug`,
price.category_id AS category_id,
`BeginDate`,
`priceanons`,
`priceimg`,
`pricehash`,
`pieces`,
`price`,
`offline_price`,
`sub`,
`authorslug`,
`author`,
2021-08-17 00:44:56 +03:00
`priceauthor_id`,
`price`.`pricepart_id` as `pricepart_id`,
`partname`,
`partalias`
2021-05-24 01:13:43 +03:00
FROM
`price`
LEFT JOIN `pricecategory`
2021-08-17 00:02:41 +03:00
ON price.category_id = pricecategory.category_id
LEFT JOIN `price_authors`
ON `price`.`priceauthor_id` = `price_authors`.`author_id`
2021-08-17 00:44:56 +03:00
LEFT JOIN
`priceparts`
ON `price`.`pricepart_id` = `priceparts`.`pricepart_id`
2021-08-17 00:02:41 +03:00
2021-05-24 01:13:43 +03:00
WHERE
`priceslug` = '$slug'
LIMIT 1
";
2021-01-13 21:09:17 +03:00
$book = dbl_get($query);
if (isset($book['price_id'])){
2021-06-16 16:05:30 +03:00
//$book['pic'] = IMGSRV."price/300x470/{$book['price_id']}.{$book['priceimg']}";
$book['pic'] = picbook($book, 300, 470);
2021-01-13 21:09:17 +03:00
$book['links']['pdf'] = SITE.'read/'.$book['pricehash'];
$book['links']['text'] = SITE.'readtext/'.$book['pricehash'];
2021-06-15 20:47:20 +03:00
$file = PDFSOURCE.$book['price_id'].'.pdf';
2021-06-15 20:49:41 +03:00
$pdf = pdfs_init($file ,1);
$book['links']['download'] = $pdf['pdfurl'];
2021-01-13 21:09:17 +03:00
return $book;
}
2021-05-16 14:15:10 +03:00
}
/**
* вернуть товары магазина (все или по фильтру)
2021-08-17 00:02:41 +03:00
*
2021-05-16 14:15:10 +03:00
*/
2021-08-17 00:02:41 +03:00
function api_books_kuri($filter = 'all', $page = 1){
2021-05-16 14:15:10 +03:00
2021-05-24 01:13:43 +03:00
$limit = 24;
2021-05-16 14:15:10 +03:00
if ($page > 1){
$offset = $limit * ($page - 1);
2021-08-16 21:37:40 +03:00
$offset_str = $offset;
2021-05-16 14:15:10 +03:00
}
else {
2021-08-16 21:37:40 +03:00
$offset_str = 0;
2021-05-16 14:15:10 +03:00
}
2021-08-17 00:02:41 +03:00
2021-05-24 01:13:43 +03:00
2021-08-17 00:02:41 +03:00
if ($filter == 'all'){
2021-05-16 14:15:10 +03:00
$where = '';
}
2021-08-17 00:02:41 +03:00
else {
$where = "$filter ";
}
2021-05-16 14:15:10 +03:00
2021-08-17 00:02:41 +03:00
//`categoryslug` = '$category'
/* $category_sql = "SELECT `category_id` FROM `pricecategory` WHERE $filter LIMIT 1";
2021-05-16 14:15:10 +03:00
$category = db_get($category_sql);
if (isset($category['category_id'])) {
$category_id = $category['category_id'];
$where = "WHERE `category_id` = $category_id";
}
2021-08-17 00:02:41 +03:00
} */
if ($where !== '')
$where .= "AND `active` = 1 ";
else
$where .= "`active` = 1 ";
2021-05-16 14:15:10 +03:00
2021-08-17 00:02:41 +03:00
$db_count = db_get("SELECT COUNT(price_id) AS count FROM `price` WHERE $where LIMIT 1;");
2021-05-24 01:13:43 +03:00
if (isset($db_count['error']))
return False;
if (isset($db_count['count']))
2021-08-16 21:37:40 +03:00
$count = $db_count['count'];
2021-08-17 00:02:41 +03:00
$sql_books = "
SELECT
2021-08-17 00:44:56 +03:00
`price_id`,
`pricename`,
`priceslug`,
price.category_id AS category_id,
`BeginDate`,
`priceanons`,
`priceimg`,
`pricehash`,
`pieces`,
`price`,
`offline_price`,
`sub`,
`authorslug`,
`author`,
`priceauthor_id`,
`price`.`pricepart_id` as `pricepart_id`,
`partname`,
`partalias`
2021-08-17 00:02:41 +03:00
FROM `price`
2021-08-17 00:44:56 +03:00
LEFT JOIN
`price_authors`
ON `price`.`priceauthor_id` = `price_authors`.`author_id`
LEFT JOIN
`priceparts`
ON `price`.`pricepart_id` = `priceparts`.`pricepart_id`
2021-08-17 00:02:41 +03:00
WHERE $where
ORDER BY `price_id` DESC
LIMIT $limit OFFSET $offset_str";
//echo $sql_books.'<br>';
2021-05-24 01:13:43 +03:00
$books = db_get($sql_books);
2021-08-17 00:44:56 +03:00
2021-05-24 01:13:43 +03:00
if (!isset($books['error'])) {
if ($count > $limit){
$pages = ceil($count / $limit);
}
else{
$pages = 1;
}
$result['books'] = $books;
$result['count'] = $count;
$result['pages'] = $pages;
$result['page'] = $page;
}
return $result;
}
/**
все категории
*/
function api_cats(){
$cats = db_get(
"SELECT * FROM pricecategory WHERE visibled = 1"
);
2021-05-16 14:15:10 +03:00
2021-05-24 01:13:43 +03:00
if (isset($cats['error']))
return False;
$result = [];
foreach ($cats as $cat){
$result[$cat['categoryslug']] = $cat;
}
return $result;
}
function book_slug($book){
$return = '';
if ($book['category_id'] == 1){
$name = $book['pricename'];
$start = strpos($name, '(');
$end = strpos($name, ')');
$end = $end -1;
$number = substr($book['pricename'], $start + 1, $end - $start);
$result = "argumenty-nedeli-$number";
}
else {
$result = transliturl($book['pricename']);
}
return $result;
}
function add_book_slug(){
$books = db_get(
"SELECT * FROM price;"
);
foreach ($books as $book){
$slug = book_slug($book);
$sql = "UPDATE `price` SET `priceslug` = '$slug' WHERE price_id = ".$book['price_id'].';';
echo "$sql<br>";
}
2021-01-13 21:09:17 +03:00
}