public function saveBook(array $val, $t = 'new', bool $admin = false)
{
$db = db();
$title = sanitizeText($val['title'] ?? '');
$description = sanitizeText($val['description'] ?? '');
$category = sanitizeText($val['category'] ?? '');
$privacy = (int)($val['privacy'] ?? 1);
$comment = (int)($val['comment'] ?? 1);
$genre = sanitizeText($val['genre'] ?? '');
$price = sanitizeText($val['price'] ?? '');
$author = sanitizeText($val['author'] ?? '');
$book = sanitizeText($val['book'] ?? '');
$slug = sanitizeText($val['slug'] ?? '');
$photo = sanitizeText($val['photo'] ?? '');
if ($t === 'new') {
$time = time();
$userId = get_userid();
$sql = "
INSERT INTO {$this->table_name}
(title, description, category, image, user_id, comment, privacy, price, author, genre, time, book, slug)
VALUES
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
";
$stmt = $db->prepare($sql);
$stmt->bind_param(
"ssssiiisssiss",
$title,
$description,
$category,
$photo,
$userId,
$comment,
$privacy,
$price,
$author,
$genre,
$time,
$book,
$slug
);
$stmt->execute();
$id = $stmt->insert_id;
if ($admin && isset($val['featured'])) {
$featured = (int)$val['featured'];
$db->query("UPDATE {$this->table_name} SET featured={$featured} WHERE id={$id}");
}
fire_hook("added.new.book", null, [$val, $id]);
return $id;
}
// UPDATE
$id = (int)$t;
$sql = "
UPDATE {$this->table_name}
SET
title=?,
description=?,
category=?,
book=?,
slug=?,
image=?,
comment=?,
privacy=?,
price=?,
author=?,
genre=?
WHERE id=?
";
$stmt = $db->prepare($sql);
$stmt->bind_param(
"ssssssiiissi",
$title,
$description,
$category,
$book,
$slug,
$photo,
$comment,
$privacy,
$price,
$author,
$genre,
$id
);
$stmt->execute();
return $id;
}
Safenation - Renato Verlindo
link whatsapp
Novos feeds
Torne-se um profissional especializado em Segurança e Saúde no Trabalho em ambientes com risco de incêndio ou explosão na indústria naval.
Tem certeza de que deseja realizar esta ação?