master
SIMON_\Simon 8 years ago
parent ddaf517579
commit 34acb97743

@ -42,12 +42,12 @@ class Configuration {
// 0 : no log at all
// 1 : log summary
// 2 : log response
'verbosity' => 2,
'verbosity' => 0,
),
'session' => array(
'save_path' => ''
),
'checkfile_url' => 'http://85.218.123.89/checkfile.php?',
'checkfile_url' => 'http://medias.bibliothequesonore.ch/checkfile.php?',
'checkfile_url_old' => 'http://fichiers.bibliothequesonore.ch/checkfile.php?',
'netbiblio_worker_id' => 45,
'www_employee_id' => 45,

@ -48,6 +48,7 @@ abstract class Formatter {
* @return string The class name to instantiate in accord to the Accept header
*/
private static function getFormatFromHeader() {
return 'BSR\Lib\Formatter\Json';
if(isset($_SERVER['HTTP_ACCEPT'])) {
$formats = array_map(function($f) {
$parts = explode(';', $f);

@ -19,7 +19,7 @@ class Renderer {
public function render($status, $data) {
header(sprintf('HTTP/1.0 %s %s', $status, self::$statusMessages[$status]));
header("Access-Control-Allow-Origin: *");
ob_clean();
flush();

@ -4,6 +4,7 @@ namespace BSR\Lib\Search;
use BSR\Lib\Configuration;
use BSR\Lib\Exception\WebException;
use BSR\Lib\Logger;
mb_http_output('UTF-8');
@ -148,6 +149,7 @@ class BookSearch
*/
public function getResults($start = 0, $count = 15, $facets = false, $spellcheck = false, $highlight = false)
{
//Logger::log(print_r($this->queryParts, true), $verbosity = Logger::QUIET);
if (count($this->queryParts) == 0)
$query = '*:*';
else {
@ -295,6 +297,7 @@ class BookSearch
$bs = new static();
$bs->addOrQuery($codes, $field);
$results = $bs->getResults(0, $count);
return $results['books'];
}

@ -32,7 +32,7 @@ abstract class WebService
$result = $this->Call();
$data["result"][$this->func] = $result;
Logger::log(print_r($result, true));
// Logger::log(print_r($result, true));
} catch (WebException $e) {
$data["error"]["code"] = $e->getCode();
$data["error"]["reason"] = $e->getMessage();

@ -1,8 +1,10 @@
<?php
namespace BSR\Lib\db;
use BSR\Lib\Configuration;
use BSR\Lib\Search\BookSearch;
use BSR\Lib\Logger;
/**
* User is mapped on the UserAccounts table. Contains user information : id, login, firstName, lastName, displayName.
@ -76,7 +78,7 @@ class User extends DbMapping
REPLACE(UserAccountNr, ' ', '') AS login
FROM [UserAccounts] AS u
LEFT JOIN [Addresses] AS a ON a.[AddressID] = u.[ActualAddressID]
WHERE LTRIM(RTRIM(UserAccountNr)) = '%s' AND disabled = 1 %s;",
WHERE LTRIM(RTRIM(UserAccountNr)) = '%s' AND disabled = 1 %s AND CategoryCode in ('A', 'M', 'G', 'D', 'I', 'EMP');",
$login, $cond);
$results = Connection::execute($sql, $raiseError);
@ -122,18 +124,36 @@ class User extends DbMapping
return $result ? $result->to_array() : array();
}
public function getLoansData($table, $sort = "ItemNr ASC")
public function GetOldLoansNrs()
{
$sql = sprintf("SELECT
n.NoticeId,
n.NoticeNr,
n.NoticeNr
FROM OldCirculations AS c
INNER JOIN Items AS i ON i.ItemId = c.ItemId
INNER JOIN Notices AS n ON n.NoticeID = i.NoticeID
WHERE
c.UserAccountID = %s AND
n.MediaType1Code in ('CDD', 'CDA', 'DVD', 'CDS') AND n.deleted=1
ORDER BY ItemNr ASC", $this->id);
$result = Connection::execute($sql);
return $result ? $result->to_array() : array();
}
public function getLoansData($table, $sort = "acquisitiondate DESC")
{
$sql = sprintf("SELECT top 50
realn.NoticeId as NoticeID,
realn.NoticeNr,
CheckOutDate,
c.Remark,
ItemNr
FROM %s AS c
INNER JOIN Items AS i ON i.ItemId = c.ItemId
INNER JOIN Notices AS n ON n.NoticeID = i.NoticeID
INNER JOIN Notices AS lentn ON lentn.NoticeID = i.NoticeID
INNER JOIN Notices AS realn ON REPLACE(ltrim(rtrim(lentn.noticenr)), 'V', '') = ltrim(rtrim(realn.noticenr))
WHERE
c.UserAccountID = %s
c.UserAccountID = %s
ORDER BY %s", $table, $this->id, $sort);
return Connection::execute($sql)->to_array();
@ -142,20 +162,23 @@ class User extends DbMapping
private function _getLoans($table, $count, $sort)
{
$circulations = $this->getLoansData($table, $sort);
//Logger::log(print_r($circulations, true));
// getting the intval of the NoticeNr will remove any 'V' or 'T' and thus we will have no issues with
// the virtual books that are used for Downloads and so.
$codes = array_unique(array_map(function($c) { return intval(trim($c['NoticeNr'])); }, $circulations));
$codes = array_unique(array_map(function($c) {
return trim($c['NoticeNr']); }, $circulations));
if($count) {
return count($circulations);
}
$books = count($codes) > 0 ? BookSearch::GetBooks($codes) : array();
//Logger::log(print_r($books, true));
foreach($circulations as $c) {
$id = $c['NoticeID'];
if(isset($books[$id])) {
$books[$id]['date'] = $c['CheckOutDate'];
$books[$id]['itemNr'] = $c['ItemNr'];
$books[$id]['checkoutDate'] = $c['CheckOutDate'];
$books[$id]['remark'] = $c['Remark'];
}
}
@ -194,7 +217,6 @@ class User extends DbMapping
INNER JOIN Notices AS n ON n.NoticeID = i.NoticeID
WHERE
c.UserAccountID = %s
AND DATEDIFF(week, CheckOutDate, GETDATE()) > 1
AND DATEDIFF(month, CheckOutDate, GETDATE()) < 5
", $this->id);

@ -6,11 +6,12 @@ use BSR\Lib\Configuration;
use BSR\Lib\db\DBHelper;
use BSR\Lib\db\Connection;
use BSR\Lib\db\User;
use BSR\Lib\Logger;
use BSR\Lib\Exception\AuthenticationException;
use BSR\Lib\Exception\WebException;
use BSR\Lib\Search\BookSearch;
use BSR\Lib\WebService;
use BSR\Lib\Logger;
class NetBiblio extends WebService
{
/** @var string $version version number */
@ -84,7 +85,7 @@ class NetBiblio extends WebService
Configuration::get('checkfile_url'),
http_build_query(array("book" => implode(',', $codes)))
);
// Logger::log($uri);
$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
@ -141,9 +142,7 @@ class NetBiblio extends WebService
* @return array either one or a list of books
*/
private function AddBookData(array $books)
{
Logger::log(print_r($books, true), 0);
{
if(isset($books['code'])) {
$result = $this->AddBookData(array($books));
return reset($result);
@ -485,6 +484,7 @@ class NetBiblio extends WebService
return array_values($this->AddBookData($circulations));
}
/**
* This method returns the list of books that the currently authenticated user
* has downloaded or that were lent to him.
@ -495,7 +495,20 @@ class NetBiblio extends WebService
public function GetOldLoans()
{
$circulations = $this->getUser()->GetOldLoans();
return array_values($this->AddBookData($circulations));
return $circulations; //array_values($this->AddBookData($circulations));
}
/**
* This method returns the list of noticenr that
* were lent to the currently authenticated user.
*
* @return array
* @throws AuthenticationException
*/
public function GetOldLoansNrs()
{
$circulations = $this->getUser()->GetOldLoansNrs();
return $circulations;
}
/**
@ -712,14 +725,14 @@ class NetBiblio extends WebService
$bs = new BookSearch();
// when search on a particular field, put results in descending date order
if(!isset($queryArray['queryText'])) {
if(!isset($queryArray['queryText']) && !isset($queryArray['author_fr']) && !isset($queryArray['title_fr']) ) {
$bs->addSortField('availabilityDate');
}
if (isset($queryArray['queryText']) && strlen($queryArray['queryText']) > 0) {
$type = isset($queryArray['queryType']) ? $queryArray['queryType'] : null;
if($this->client != 'website' && in_array($type, array('title', 'author', 'reader'))) {
if(in_array($type, array('title', 'author', 'reader'))) {
// we don't want an exact search on mobile apps
$type = $type.'_fr';
} else if($type == 'text') {
@ -782,8 +795,6 @@ class NetBiblio extends WebService
$results = $bs->getResults($start, $count, $facets, $spellcheck, $highlight);
$data = array(
'count' => $results['count'],
'facets' => $results['facets'],
@ -812,6 +823,21 @@ class NetBiblio extends WebService
return $this->AddBookData($results['books']);
}
/**
* This method return books similar to the one given.
*
* @param int|array $ids One or multiple book ids
* @param int number of books
* @return array
*/
public function MoreLikeThisByCode($codes, $number = 8)
{
$bs = new BookSearch(false);
$bs->addOrQuery(is_array($code) ? $codes : array($codes), 'code');
$bs->setHandler('more');
$results = $bs->getResults(0, $number);
return array_values($this->AddBookData($results['books']));
}
/**
* This method returns books similar to the books already
* loaned by the current user.

Loading…
Cancel
Save