db = $db; } /** * Prosta lista autorow * @return array|bool */ public function simpleList() { return $this->db->select('pp_authors', '*', ['ORDER' => ['author' => 'ASC']]); } /** * Szczegoly autora z jezykami * @param int $authorId * @return array|bool */ public function authorDetails($authorId) { $author = $this->db->get('pp_authors', '*', ['id' => (int)$authorId]); $results = $this->db->select('pp_authors_langs', '*', ['id_author' => (int)$authorId]); if (is_array($results)) foreach ($results as $row) $author['languages'][$row['id_lang']] = $row; return $author; } /** * Zapis autora (insert lub update) * @param int $authorId * @param string $author * @param string $image * @param string|array $description * @return int|bool */ public function authorSave($authorId, $author, $image, $description) { if (!$authorId) { $this->db->insert('pp_authors', [ 'author' => $author, 'image' => $image ]); $id = $this->db->id(); if ($id) { $i = 0; $results = $this->db->select('pp_langs', ['id'], ['status' => 1, 'ORDER' => ['o' => 'ASC']]); if (is_array($results) and count($results) > 1) foreach ($results as $row) { $this->db->insert('pp_authors_langs', [ 'id_author' => (int)$id, 'id_lang' => $row['id'], 'description' => $description[$i] ]); $i++; } else if (is_array($results) and count($results) == 1) foreach ($results as $row) { $this->db->insert('pp_authors_langs', [ 'id_author' => (int)$id, 'id_lang' => $row['id'], 'description' => $description ]); } \S::delete_cache(); return $id; } } else { $this->db->update('pp_authors', [ 'author' => $author, 'image' => $image ], [ 'id' => (int)$authorId ]); $this->db->delete('pp_authors_langs', ['id_author' => (int)$authorId]); $i = 0; $results = $this->db->select('pp_langs', ['id'], ['status' => 1, 'ORDER' => ['o' => 'ASC']]); if (is_array($results) and count($results) > 1) foreach ($results as $row) { $this->db->insert('pp_authors_langs', [ 'id_author' => (int)$authorId, 'id_lang' => $row['id'], 'description' => $description[$i] ]); $i++; } else if (is_array($results) and count($results) == 1) foreach ($results as $row) { $this->db->insert('pp_authors_langs', [ 'id_author' => (int)$authorId, 'id_lang' => $row['id'], 'description' => $description ]); } \S::delete_cache(); return $authorId; } return false; } /** * Usuniecie autora * @param int $authorId * @return object|bool */ public function authorDelete($authorId) { $result = $this->db->delete('pp_authors', ['id' => (int)$authorId]); \S::delete_cache(); return $result; } /** * Szczegoly autora z cache (front) * @param int $authorId * @return array|bool */ public function authorByLang($authorId) { if (!$author = \Shared\Cache\CacheHandler::fetch("get_single_author:$authorId")) { $author = $this->db->get('pp_authors', '*', ['id' => (int)$authorId]); $results = $this->db->select('pp_authors_langs', '*', ['id_author' => (int)$authorId]); if (is_array($results)) foreach ($results as $row) $author['languages'][$row['id_lang']] = $row; \Shared\Cache\CacheHandler::store("get_single_author:$authorId", $author); } return $author; } }