Système de feedback par gilles

envoi du mail après un certain nombre de tl.
Amélioration de la rcherche.
2-3 autres trucs.
This commit is contained in:
SIMON_\Simon
2017-07-24 17:05:05 +02:00
parent c140c28bd4
commit ddaf517579
5 changed files with 121 additions and 26 deletions

View File

@@ -6,6 +6,7 @@ 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;
@@ -14,10 +15,9 @@ class NetBiblio extends WebService
{
/** @var string $version version number */
public static $version = '1.2.0';
private $login = '';
private $client = 'website';
public function __construct() {
parent::__construct(self::$version);
}
@@ -79,6 +79,7 @@ class NetBiblio extends WebService
{
$codes = array_map('intval', $codes);
$uri = sprintf("%s%s",
Configuration::get('checkfile_url'),
http_build_query(array("book" => implode(',', $codes)))
@@ -141,11 +142,13 @@ class NetBiblio extends WebService
*/
private function AddBookData(array $books)
{
Logger::log(print_r($books, true), 0);
if(isset($books['code'])) {
$result = $this->AddBookData(array($books));
return reset($result);
}
// add complementary data to each book
$books = array_map(function($b) {
// add files if we already have them
@@ -178,7 +181,6 @@ class NetBiblio extends WebService
$b['code3'] = $b['producerCode'];
$b['code3Long'] = $b['producer'];
$b['typeMedia1'] = $b['mediaType'];
return $b;
}, $books);
@@ -187,7 +189,7 @@ class NetBiblio extends WebService
return ! (
isset($b['files']) &&
isset($b['files']['samples']) &&
count($b['files']['samples']) == 2 && // we want two samples (mp3 and ogg)
count($b['files']['samples']) == 2 && // we want two samples .wav and ogg)
isset($b['files']['zip']) // we want a zip file
);
});
@@ -269,6 +271,7 @@ class NetBiblio extends WebService
*/
public function AddDownloadLog($client, $login, $code)
{
$dl_alert = 80;
$client = str_replace("'", "", $client);
$login = str_replace("'", "", $login);
$code = ltrim(str_replace("'", "", $code), '0');
@@ -282,19 +285,20 @@ class NetBiblio extends WebService
throw new WebException("ItemNotFound", "cannot find item", -1030);
}
$sql = "SELECT UserAccountID FROM UserAccounts WHERE LTRIM(RTRIM(UserAccountNr)) = '$login';";
$sql = "SELECT UserAccountID, DisplayName FROM UserAccounts WHERE LTRIM(RTRIM(UserAccountNr)) = '$login';";
$result = Connection::execute($sql, false);
if ($row = $result->current()) {
$userId = $row['UserAccountID'];
$username = $row['DisplayName'];
} else {
throw new WebException("UserNotFound", "cannot find user", -1031);
}
$sql = "SELECT circulationId
FROM OldCirculations
WHERE
FROM OldCirculations
WHERE
UserAccountID= $userId AND
itemID = $itemId AND
itemID = $itemId AND
LTRIM(RTRIM(remark)) = '$client';";
$result = Connection::execute($sql, false);
@@ -317,6 +321,27 @@ class NetBiblio extends WebService
$nextId = 1;
}
$sql = "SELECT count(*) as DLs FROM OldCirculations WHERE UserAccountID = $userId
AND checkoutdate >= Dateadd(month, Datediff(month, 0, Getdate()), 0);";
$result = Connection::execute($sql, false);
if ($row = $result->current()) {
$DLs = $row['DLs'];
if($DLs >= $dl_alert){
$to = 'sschule@bibliothequesonore.ch';
$subject = 'Limite atteinte pour '.$username.", ".$login;
$message = "Nombre de livres ce mois: ".($DLs+1);
$headers = 'From: webmaster@bibliothequesonore.ch' . "\r\n" .
'Reply-To: webmaster@bibliothequesonore.ch' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
}
}
$sql = "UPDATE UserAccounts
SET
Circulations = Circulations + 1,
@@ -473,6 +498,18 @@ class NetBiblio extends WebService
return array_values($this->AddBookData($circulations));
}
/**
* This method returns the books lent to the current user in the time period
* 2 weeks to 4 month.
*
* @return array
* @throws AuthenticationException
*/
public function GetBooksForFeedback()
{
return array_values($this->getUser()->GetBooksForFeedback());
}
/**
* This method return information for the user dashboard :
*
@@ -674,6 +711,11 @@ class NetBiblio extends WebService
$bs = new BookSearch();
// when search on a particular field, put results in descending date order
if(!isset($queryArray['queryText'])) {
$bs->addSortField('availabilityDate');
}
if (isset($queryArray['queryText']) && strlen($queryArray['queryText']) > 0) {
$type = isset($queryArray['queryType']) ? $queryArray['queryType'] : null;
@@ -684,7 +726,7 @@ class NetBiblio extends WebService
// The field 'text' is still used by the Android app but does not exists anymore
// We use the default search fields in this case.
$type = null;
}
}
$bs->addQuery($queryArray['queryText'], $type);
}
@@ -709,7 +751,7 @@ class NetBiblio extends WebService
$bs->addRange('duration', $min, $max);
}
$availableFields = array('producerCode', 'genreCode', 'author', 'reader', 'motsMatieres');
$availableFields = array('producerCode', 'genreCode', 'author', 'author_fr', 'title_fr', 'reader', 'reader_fr', 'motsMatieres', 'mediaType');
foreach($availableFields as $q) {
if(isset($queryArray[$q]) && (
(is_string($queryArray[$q]) && strlen($queryArray[$q]) > 0) ||
@@ -719,7 +761,12 @@ class NetBiblio extends WebService
// Genres cannot overlap, so we use 'OR', otherwise use 'AND'
$bs->addCompoundQuery($queryArray[$q], $q, $q == 'genreCode' ? 'OR' : 'AND');
} else {
$bs->addQuery($queryArray[$q], $q);
if($q == 'reader'){
$q2 = 'reader_fr';
$queryArray[$q] = ucfirst($queryArray[$q]);
} else{$q2 = $q;}
$bs->addQuery($queryArray[$q], $q2);
}
}
}
@@ -734,12 +781,19 @@ class NetBiblio extends WebService
$highlight = isset($queryArray['highlight']) && $queryArray['highlight'];
$results = $bs->getResults($start, $count, $facets, $spellcheck, $highlight);
$data = array(
'count' => $results['count'],
'facets' => $results['facets'],
);
return array_merge($data, $this->AddBookData($results['books']));
$finalResult = array_merge($data, $this->AddBookData($results['books']));
for($i = 0; $i < count($finalResult)-2 ; $i++){
$finalResult[$i]['position']=$i;
}
return $finalResult;
}
/**