Remove all traces of AudioBook, clean up some warnings
This commit is contained in:
@@ -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)) {
|
||||
|
||||
@@ -53,6 +53,7 @@ class Html extends Formatter {
|
||||
|
||||
$first = reset($data);
|
||||
$single = ! is_array($first);
|
||||
$columns = array();
|
||||
|
||||
$content .= '<table class="table table-striped table-hover table-condensed table-responsive"><thead>';
|
||||
if($single) {
|
||||
|
||||
@@ -1,249 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace BSR\Lib\db;
|
||||
|
||||
/**
|
||||
* AudioBook is mapped on a Notice from NetBiblio
|
||||
*
|
||||
* @property string id
|
||||
* @property string sql_id
|
||||
* @property string title
|
||||
* @property string sql_title
|
||||
* @property string author
|
||||
* @property string sql_author
|
||||
* @property string code
|
||||
* @property string sql_code
|
||||
* @property string summary
|
||||
* @property string sql_summary
|
||||
* @property string editor
|
||||
* @property string sql_editor
|
||||
* @property string media
|
||||
* @property string sql_media
|
||||
* @property string collection
|
||||
* @property string sql_collection
|
||||
* @property string isbn
|
||||
* @property string sql_isbn
|
||||
* @property string reader
|
||||
* @property string sql_reader
|
||||
* @property string cover
|
||||
* @property string sql_cover
|
||||
* @property string category
|
||||
* @property string sql_category
|
||||
* @property string availabilityDate
|
||||
* @property string sql_availabilityDate
|
||||
* @property string producerCode
|
||||
* @property string sql_producerCode
|
||||
* @property string producer
|
||||
* @property string sql_producer
|
||||
* @property string genre
|
||||
* @property string sql_genre
|
||||
* @property string genreCode
|
||||
* @property string sql_genreCode
|
||||
* @property string link
|
||||
* @property string sql_link
|
||||
* @property string linkTitle
|
||||
* @property string sql_linkTitle
|
||||
* @property string mediaType
|
||||
* @property string sql_mediaType
|
||||
*/
|
||||
class AudioBook extends DbMapping
|
||||
{
|
||||
protected $attributeNames = 'id title author code summary editor media collection isbn reader cover category availabilityDate producerCode producer genre genreCode link linkTitle mediaType';
|
||||
|
||||
public static function find($id) {
|
||||
return self::findBy('NoticeID', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* If $id is an array, return an array of book, if it is only one id, return one book
|
||||
* Load books details only if not an array.
|
||||
*
|
||||
* Beware that this search use the NoticeID, not the NoticeNr, if you need the last one
|
||||
* use findByCode method instead;
|
||||
*
|
||||
* @param string $column
|
||||
* @param int|array $ids
|
||||
* @param bool $raw results ?
|
||||
* @return AudioBook|AudioBook[]|array
|
||||
*/
|
||||
public static function findBy($column, $ids, $raw = false)
|
||||
{
|
||||
$multiple = true;
|
||||
if(! is_array($ids)) {
|
||||
$ids = array($ids);
|
||||
$multiple = false;
|
||||
}
|
||||
|
||||
// The following query should be maintained in sync with the one in the solr data source.
|
||||
$sql = sprintf("SELECT DISTINCT
|
||||
Notices.[NoticeID] AS id,
|
||||
LTRIM(RTRIM(Notices.[Title])) AS title,
|
||||
LTRIM(RTRIM(Notices.[Author])) AS author,
|
||||
LTRIM(RTRIM(Notices.[NoticeNr])) AS code,
|
||||
Fields.[520] AS summary,
|
||||
REPLACE(Fields.[260b], ',', '') AS editor,
|
||||
LEFT(SUBSTRING(Fields.[260c], PATINDEX('%%[0-9]%%', Fields.[260c]), 8000), PATINDEX('%%[^0-9]%%', SUBSTRING(Fields.[260c], PATINDEX('%%[0-9]%%', Fields.[260c]), 8000) + 'X')-1) AS year,
|
||||
Fields.[300] AS media,
|
||||
Fields.[490a] AS collection,
|
||||
LTRIM(RTRIM(isbn.DisplayText)) AS isbn,
|
||||
Fields.[901] AS reader,
|
||||
Fields.[899a] AS cover,
|
||||
'' AS category, -- supposed to come from tags 600, 610, 650, 651, 655, 690, 691, 695, 696 but always empty anyway
|
||||
item1.AcquisitionDate AS availabilityDate,
|
||||
LTRIM(RTRIM(ProducerCode.TextFre)) As producer,
|
||||
LTRIM(RTRIM(ProducerCode.Code)) AS producerCode,
|
||||
LTRIM(RTRIM(GenreCode.TextFre)) As genre,
|
||||
LTRIM(RTRIM(GenreCode.Code)) AS genreCode,
|
||||
CASE
|
||||
WHEN Notices.CoverDisplay = 2 THEN 'http://fichiers.bibliothequesonore.ch:8089/netbiblio/images/covers/Cover' + CAST(Notices.NoticeID AS VARCHAR) + '_Original.jpg'
|
||||
ELSE 'http://ecx.images-amazon.com/images/I/' + Fields.[899a] + '._SL320_.jpg'
|
||||
END AS cover,
|
||||
Fields.[856u] AS link,
|
||||
Fields.[856z] AS linkTitle,
|
||||
LTRIM(RTRIM(Notices.[MediaType1Code])) AS mediaType
|
||||
FROM Notices
|
||||
INNER JOIN Codes As GenreCode ON Notices.MediaType2Code = GenreCode.Code AND GenreCode.Type = 2
|
||||
INNER JOIN Codes AS ProducerCode ON Notices.UserDefined3code = ProducerCode.Code AND ProducerCode.Type=6
|
||||
LEFT OUTER JOIN (
|
||||
SELECT *
|
||||
FROM (
|
||||
SELECT
|
||||
NoticeID,
|
||||
CASE
|
||||
WHEN Tag IN ('490', '260', '856', '899') THEN Tag + SubfieldCode
|
||||
ELSE Tag
|
||||
END AS Field,
|
||||
CASE
|
||||
WHEN Tag = '020' THEN LTRIM(RTRIM(CAST(AuthorityID AS varchar)))
|
||||
ELSE LTRIM(RTRIM(ContentShortPart))
|
||||
END AS Data
|
||||
FROM NoticeFields
|
||||
WHERE
|
||||
Tag IN (
|
||||
'520', -- summary
|
||||
'901', -- Reader
|
||||
'300', -- Duration (field media)
|
||||
'020' -- ISBN
|
||||
)
|
||||
OR (Tag = '490' AND SubfieldCode = 'a') -- Collection
|
||||
OR (Tag = '260' AND SubfieldCode = 'b') -- Editor
|
||||
OR (Tag = '260' AND SubfieldCode = 'c') -- Edition year
|
||||
OR (Tag = '856' AND SubfieldCode = 'u') -- Link
|
||||
OR (Tag = '856' AND SubfieldCode = 'z') -- Link title
|
||||
OR (Tag = '899' AND SubfieldCode = 'a') -- Cover
|
||||
) AS src
|
||||
PIVOT (
|
||||
MIN(Data)
|
||||
FOR Field IN ([520], [901], [300], [020], [490a], [260b], [260c], [856u], [856z], [899a])
|
||||
) AS pvt
|
||||
) Fields ON Notices.NoticeID = Fields.NoticeID
|
||||
OUTER APPLY (
|
||||
SELECT TOP 1 *
|
||||
FROM Items
|
||||
WHERE Notices.NoticeID = NoticeID
|
||||
) AS item1
|
||||
LEFT JOIN Authorities AS isbn ON isbn.AuthorityID = Fields.[020]
|
||||
WHERE
|
||||
LTRIM(RTRIM(Notices.[%s])) IN ('%s')
|
||||
AND Notices.[NoticeNr] NOT LIKE '%%~%%'
|
||||
;", $column, implode('\', \'', $ids));
|
||||
|
||||
$result = Connection::execute($sql, true);
|
||||
|
||||
$books = array();
|
||||
while($row = $result->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);
|
||||
}
|
||||
}
|
||||
87
Lib/db/DbHelper.php
Normal file
87
Lib/db/DbHelper.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace BSR\Lib\db;
|
||||
|
||||
class DbHelper
|
||||
{
|
||||
/**
|
||||
* 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());
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
*/
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
|
||||
<ul class="nav navbar-nav">
|
||||
<li><a href="/">Help</a></li>
|
||||
<li><a href="phpinfo.php">PHPInfo</a></li>
|
||||
<li><a href="/phpinfo.php">PHPInfo</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user