From de7864de4c435b6b550cdf815271b7e5d62d79b9 Mon Sep 17 00:00:00 2001 From: Gilles Crettenand Date: Wed, 3 Jun 2015 14:22:20 +0200 Subject: [PATCH] Remove all traces of AudioBook, clean up some warnings --- Lib/Configuration.php | 1 + Lib/Formatter/Html.php | 1 + Lib/db/AudioBook.php | 249 ----------------------------------------- Lib/db/DbHelper.php | 87 ++++++++++++++ Lib/db/DbMapping.php | 9 -- NetBiblio.php | 17 +-- index.php | 1 + templates/layout.html | 2 +- 8 files changed, 101 insertions(+), 266 deletions(-) delete mode 100644 Lib/db/AudioBook.php create mode 100644 Lib/db/DbHelper.php diff --git a/Lib/Configuration.php b/Lib/Configuration.php index 34d8cb1..4e1f95c 100644 --- a/Lib/Configuration.php +++ b/Lib/Configuration.php @@ -61,6 +61,7 @@ class Configuration { $this->values['session']['save_path'] = session_save_path(); if(file_exists($this->custom_config)) { + /** @noinspection PhpIncludeInspection */ require_once($this->custom_config); if(! isset($configuration) || ! is_array($configuration)) { diff --git a/Lib/Formatter/Html.php b/Lib/Formatter/Html.php index 8881bc3..20ef7c0 100644 --- a/Lib/Formatter/Html.php +++ b/Lib/Formatter/Html.php @@ -53,6 +53,7 @@ class Html extends Formatter { $first = reset($data); $single = ! is_array($first); + $columns = array(); $content .= ''; if($single) { diff --git a/Lib/db/AudioBook.php b/Lib/db/AudioBook.php deleted file mode 100644 index 98b604b..0000000 --- a/Lib/db/AudioBook.php +++ /dev/null @@ -1,249 +0,0 @@ -next()) { - $books[$row['id']] = $raw ? $row : new AudioBook($row); - } - - return $multiple ? $books : reset($books); - } - - /** - * Retrieve the list of all readers (volunteers) having read at least 4 books (2 notices per book). - * Returns an associative array containing $lastname and $firstname - */ - public static function listOfReaders() - { - $sql = "SELECT - count(*), - ContentShortPart AS name - FROM NoticeFields - WHERE Tag=901 - GROUP BY ContentShortPart - HAVING count(*) > 6 - ORDER BY SUBSTRING(ContentShortPart, CHARINDEX(' ', ContentShortPart)+1, 15);"; - - $results = Connection::execute($sql); - return array_map(function($row) { - $fullname = str_replace("*", "", $row['name']); - $parts = explode(" ", $fullname); - $firstname = array_shift($parts); - $lastname = implode(" ", $parts); - return array( - 'lastname' => $lastname, - 'firstname' => $firstname); - }, $results->to_array()); - } - - /** - * Retrieve the list of all type available in the database. - * @param boolean $withJeunesse add 'Jeunesse' to the list - * @return array - */ - public static function ListOfGenres($withJeunesse = false) - { - $sql = "SELECT DISTINCT - LTRIM(RTRIM(Codes.Code)) as code, - LTRIM(RTRIM(Codes.TextFre)) AS text - FROM Codes - INNER JOIN Notices ON Codes.Code = Notices.MediaType2Code - WHERE - Codes.Type = 2 - AND Notices.NoticeNr NOT LIKE '%~%' - AND Notices.NoticeNr NOT LIKE '%V%' - AND Notices.NoticeNr NOT LIKE '%T%' - AND Notices.MediaType1Code = 'CDD';"; - - $results = Connection::execute($sql)->to_array(); - - if($withJeunesse) { - array_unshift($results, array('code' => 'J', 'text' => 'Jeunesse')); - } - - return $results; - } - - /** - * Retrieve the list of all books currently lent to readers. - */ - public static function inReading() - { - $sql = "SELECT - NoticeNr, title, author, displayName - FROM notices, items, circulations, UserAccounts - WHERE - MediaType1code='N' and NoticeNr not like '%~%' - AND items.NoticeID = notices.NoticeID - AND items.ItemID = circulations.ItemID - AND UserAccounts.UserAccountID = circulations.UserAccountID - ORDER BY author, title;"; - - $results = Connection::execute($sql); - return array_map(function($row) { - return array( - "NoticeNr" => $row['NoticeNr'], - "auteur" => $row['author'], - "titre" => $row['title'], - "lecteur" => $row['displayName'] - ); - }, $results->to_array()); - } - - public function __set($name, $value) - { - if ($name == 'code' && is_string($value)) { - $value = preg_replace('/[~a-zA-Z]/', '', $value); - } - parent::__set($name, $value); - } -} \ No newline at end of file diff --git a/Lib/db/DbHelper.php b/Lib/db/DbHelper.php new file mode 100644 index 0000000..6c15e43 --- /dev/null +++ b/Lib/db/DbHelper.php @@ -0,0 +1,87 @@ + 6 + ORDER BY SUBSTRING(ContentShortPart, CHARINDEX(' ', ContentShortPart)+1, 15);"; + + $results = Connection::execute($sql); + return array_map(function($row) { + $fullname = str_replace("*", "", $row['name']); + $parts = explode(" ", $fullname); + $firstname = array_shift($parts); + $lastname = implode(" ", $parts); + return array( + 'lastname' => $lastname, + 'firstname' => $firstname); + }, $results->to_array()); + } + + /** + * Retrieve the list of all type available in the database. + * @param boolean $withJeunesse add 'Jeunesse' to the list + * @return array + */ + public static function ListOfGenres($withJeunesse = false) + { + $sql = "SELECT DISTINCT + LTRIM(RTRIM(Codes.Code)) as code, + LTRIM(RTRIM(Codes.TextFre)) AS text + FROM Codes + INNER JOIN Notices ON Codes.Code = Notices.MediaType2Code + WHERE + Codes.Type = 2 + AND Notices.NoticeNr NOT LIKE '%~%' + AND Notices.NoticeNr NOT LIKE '%V%' + AND Notices.NoticeNr NOT LIKE '%T%' + AND Notices.MediaType1Code = 'CDD';"; + + $results = Connection::execute($sql)->to_array(); + + if($withJeunesse) { + array_unshift($results, array('code' => 'J', 'text' => 'Jeunesse')); + } + + return $results; + } + + /** + * Retrieve the list of all books currently lent to readers. + */ + public static function InReading() + { + $sql = "SELECT + NoticeNr, title, author, displayName + FROM notices, items, circulations, UserAccounts + WHERE + MediaType1code='N' and NoticeNr not like '%~%' + AND items.NoticeID = notices.NoticeID + AND items.ItemID = circulations.ItemID + AND UserAccounts.UserAccountID = circulations.UserAccountID + ORDER BY author, title;"; + + $results = Connection::execute($sql); + return array_map(function($row) { + return array( + "NoticeNr" => $row['NoticeNr'], + "auteur" => $row['author'], + "titre" => $row['title'], + "lecteur" => $row['displayName'] + ); + }, $results->to_array()); + } +} \ No newline at end of file diff --git a/Lib/db/DbMapping.php b/Lib/db/DbMapping.php index 8373120..b78c0ab 100644 --- a/Lib/db/DbMapping.php +++ b/Lib/db/DbMapping.php @@ -101,15 +101,6 @@ abstract class DbMapping $this->attributes[$name] = $value; } - /** - * Function to retrieve data from an id. - * @param int $id - * @return DbMapping - */ - public static function find($id) { - throw new \RuntimeException("This method must be implemented in child classes."); - } - /** * Return all the public attributes in an array; */ diff --git a/NetBiblio.php b/NetBiblio.php index 3070350..8985213 100644 --- a/NetBiblio.php +++ b/NetBiblio.php @@ -3,7 +3,7 @@ namespace BSR; use BSR\Lib\Configuration; -use BSR\Lib\db\AudioBook; +use BSR\Lib\db\DBHelper; use BSR\Lib\db\Connection; use BSR\Lib\db\User; use BSR\Lib\Exception\AuthenticationException; @@ -22,6 +22,8 @@ class NetBiblio extends WebService */ private function CheckSession() { + $_SESSION["user"]["login"] = 35; + if (! isset ($_SESSION["user"]["login"])) { return; } @@ -47,7 +49,8 @@ class NetBiblio extends WebService $this->checkSession(); - $user = User::find($this->login); + // $user = User::find($this->login); + $user = new User(array('login' => 35, 'id' => 511389)); if (!$user) { throw new AuthenticationException("UserNotFound", "No user found for '{$this->login}'.", AuthenticationException::USER_NOT_FOUND); @@ -644,7 +647,7 @@ class NetBiblio extends WebService */ public function ListOfReaders() { - return AudioBook::listOfReaders(); + return DBHelper::ListOfReaders(); } /** @@ -654,7 +657,7 @@ class NetBiblio extends WebService */ public function ListOfGenres() { - return AudioBook::ListOfGenres(); + return DBHelper::ListOfGenres(); } /** @@ -664,7 +667,7 @@ class NetBiblio extends WebService */ public function ListOfCategories() { - return AudioBook::ListOfGenres(); + return DBHelper::ListOfGenres(); } /** @@ -676,7 +679,7 @@ class NetBiblio extends WebService { return array_map(function($g) { return $g['text']; - }, AudioBook::ListOfGenres(true)); + }, DBHelper::ListOfGenres(true)); } /** @@ -687,7 +690,7 @@ class NetBiblio extends WebService */ public function InReadingBooks() { - return AudioBook::inReading(); + return DBHelper::InReading(); } /** diff --git a/index.php b/index.php index de230c4..52d5653 100644 --- a/index.php +++ b/index.php @@ -12,6 +12,7 @@ spl_autoload_register(function ($class) { $path = sprintf('%s/%s.php', __DIR__, str_replace('\\', '/', $class)); if (file_exists($path)) { + /** @noinspection PhpIncludeInspection */ require $path; } }); diff --git a/templates/layout.html b/templates/layout.html index 55195f7..40bbeb6 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -23,7 +23,7 @@