From ddaf517579cccaab2eb6a1dd722e024c2fa29dda Mon Sep 17 00:00:00 2001 From: "SIMON_\\Simon" Date: Mon, 24 Jul 2017 17:05:05 +0200 Subject: [PATCH] =?UTF-8?q?Syst=C3=A8me=20de=20feedback=20par=20gilles=20e?= =?UTF-8?q?nvoi=20du=20mail=20apr=C3=A8s=20un=20certain=20nombre=20de=20tl?= =?UTF-8?q?.=20Am=C3=A9lioration=20de=20la=20rcherche.=202-3=20autres=20tr?= =?UTF-8?q?ucs.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lib/Configuration.php | 7 ++-- Lib/Search/BookSearch.php | 9 +++-- Lib/db/DbHelper.php | 5 ++- Lib/db/User.php | 46 +++++++++++++++++++--- NetBiblio.php | 80 ++++++++++++++++++++++++++++++++------- 5 files changed, 121 insertions(+), 26 deletions(-) diff --git a/Lib/Configuration.php b/Lib/Configuration.php index 5ca20bd..3b97a6c 100644 --- a/Lib/Configuration.php +++ b/Lib/Configuration.php @@ -42,14 +42,13 @@ class Configuration { // 0 : no log at all // 1 : log summary // 2 : log response - 'verbosity' => 0, + 'verbosity' => 2, ), 'session' => array( 'save_path' => '' ), - - 'checkfile_url' => 'http://fichiers.bibliothequesonore.ch/checkfile.php?', - + 'checkfile_url' => 'http://85.218.123.89/checkfile.php?', + 'checkfile_url_old' => 'http://fichiers.bibliothequesonore.ch/checkfile.php?', 'netbiblio_worker_id' => 45, 'www_employee_id' => 45, 'www_library_id' => 2, diff --git a/Lib/Search/BookSearch.php b/Lib/Search/BookSearch.php index ce3aa1f..e3758af 100644 --- a/Lib/Search/BookSearch.php +++ b/Lib/Search/BookSearch.php @@ -81,10 +81,13 @@ class BookSearch $queryText = \SolrUtils::escapeQueryChars($queryText); } - if (strlen($queryField) > 0) { + if($queryField == 'mediaType' and $queryText=='noCDS'){ + $queryText='-mediaType:CDS'; + } else if (strlen($queryField) > 0) { $queryText = sprintf('%s:"%s"', $queryField, $queryText); } + $this->queryParts[] = $queryText; } @@ -161,7 +164,7 @@ class BookSearch $this->query->setParam('hl', $highlight ? 'true' : 'false'); $this->query->setParam('spellcheck', $spellcheck ? 'true' : 'false'); - + try { $results = $this->client->query($this->query)->getArrayResponse(); } catch(\SolrException $e) { @@ -300,7 +303,7 @@ class BookSearch $s = new BookSearch(); $s->addFilterQuery(1, 'visible'); $s->addFacetField($field); - $s->setFacetLimits(2000, 10); + $s->setFacetLimits(2000, 2); $results = $s->getResults(0, 0, true); return $results['facets']['facets'][$field]; diff --git a/Lib/db/DbHelper.php b/Lib/db/DbHelper.php index 2207e0b..abe8eb0 100644 --- a/Lib/db/DbHelper.php +++ b/Lib/db/DbHelper.php @@ -21,7 +21,10 @@ class DbHelper AND Notices.NoticeNr NOT LIKE '%~%' AND Notices.NoticeNr NOT LIKE '%V%' AND Notices.NoticeNr NOT LIKE '%T%' - AND Notices.MediaType1Code = 'CDD';"; + AND Codes.TextFre !='' + AND Notices.MediaType1Code = 'CDD' + ORDER BY text;"; + $results = Connection::execute($sql)->to_array(); diff --git a/Lib/db/User.php b/Lib/db/User.php index 2e8c2bc..33691cf 100644 --- a/Lib/db/User.php +++ b/Lib/db/User.php @@ -182,6 +182,24 @@ class User extends DbMapping return $this->_getLoans('OldCirculations', $count, 'CheckOutDate DESC'); } + /** + * Books eligible for feedback by the user. Lent or downloaded more than 2 weeks ago and less than 5 monthes. + * @return array + */ + public function GetBooksForFeedback() + { + $sql = sprintf("SELECT 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 DATEDIFF(week, CheckOutDate, GETDATE()) > 1 + AND DATEDIFF(month, CheckOutDate, GETDATE()) < 5 + ", $this->id); + + return Connection::execute($sql)->to_array(); } + /** * Add a book to the wish list if it is not already inside. @@ -237,20 +255,38 @@ class User extends DbMapping * @param int $limit * @return array */ - public function getWishes($count = false, $limit = 50) + public function getWishes($count = false, $limit = 200) { $sql = sprintf("SELECT TOP $limit - NoticeID + NoticeID, CreationDate FROM Wishes WHERE UserAccountID = %s ORDER BY CreationDate DESC", $this->id); $result = Connection::execute($sql); - $ids = array_map(function($r) { return $r['NoticeID']; }, $result->to_array()); + + $wishList = $result->to_array(); + $ids = array_map(function($r) { return $r['NoticeID']; }, $wishList); if($count) { return count($ids); } - return BookSearch::GetBooks($ids, 'id'); + + $books = BookSearch::GetBooks($ids, 'id'); + foreach($wishList as $w) { + $id = $w['NoticeID']; + if(isset($books[$id])) { + $books[$id]['creationDate'] = $w['CreationDate']; + } + } + + $creationDates = array(); + foreach ($books as $key => $book) + { + $creationDates[$key] = $book['creationDate']; + } + array_multisort($creationDates, SORT_DESC, $books); + + return $books; } /** @@ -269,4 +305,4 @@ class User extends DbMapping $status = Connection::execute($sql, true); return $status && ! $status->is_error() && $status->get_num_rows() > 0; } -} \ No newline at end of file +} diff --git a/NetBiblio.php b/NetBiblio.php index 654e760..7f8a1cc 100644 --- a/NetBiblio.php +++ b/NetBiblio.php @@ -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; } /**