diff --git a/gittest b/CHANGELOG.md similarity index 100% rename from gittest rename to CHANGELOG.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..e69de29 diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..e69de29 diff --git a/Lib/Exception/BookNotFoundException.php b/Lib/Exception/BookNotFoundException.php deleted file mode 100644 index 4dc9967..0000000 --- a/Lib/Exception/BookNotFoundException.php +++ /dev/null @@ -1,15 +0,0 @@ - Configuration::get('solr.server'), - 'port' => Configuration::get('solr.port'), - 'login' => Configuration::get('solr.username'), - 'password' => Configuration::get('solr.password'), - 'path' => Configuration::get('solr.path'), - ); - - $this->client = new \SolrClient($options); - - if($edismax) { - $this->query = new \SolrDisMaxQuery(); - $this->query->useEDisMaxQueryParser(); - } else { - $this->query = new \SolrQuery(); - } - - // most options like search fields, sorting, etc are already set - // as default in the Solr config and thus should be set only on a - // per request basis when needed - - /* if sometime we need to set the fields explicitly, those should be the ones we want : - $this->query->addField('id, code, isbn'); - $this->query->addField('editor, editorTown, year, producer, producerCode, availabilityDate, collection'); - $this->query->addField('title, author, reader, summary'); - $this->query->addField('jeunesse, genre, genreCode, motsMatieres, cdu'); - $this->query->addField('media, mediaType, cover, samples, zip, zip_size'); - */ - } - - public function setHandler($handler) - { - $this->client->setServlet(\SolrClient::SEARCH_SERVLET_TYPE, $handler); - } - - public function addCompoundQuery(array $texts, $field, $operator) - { - if(count($texts) > 0) { - $texts = array_map(array('SolrUtils', 'escapeQueryChars'), $texts); - $query = sprintf('%s:("%s")', $field, implode('" '.$operator.'"', $texts)); - $this->addQuery($query, null, false); - } - } - - public function addOrQuery(array $texts, $field) - { - $this->addCompoundQuery($texts, $field, 'OR'); - } - - public function addAndQuery(array $texts, $field) - { - $this->addCompoundQuery($texts, $field, 'AND'); - } - - public function addQuery($queryText, $queryField = null, $escape = true) - { - if($escape) { - $queryText = \SolrUtils::escapeQueryChars($queryText); - } - - if($queryField == 'mediaType' and $queryText=='noCDS'){ - $queryText='-mediaType:CDS'; - } else if (strlen($queryField) > 0) { - $queryText = sprintf('%s:"%s"', $queryField, $queryText); - } - - - $this->queryParts[] = $queryText; - } - - public function addFilterQuery($text, $field, $escape = true) - { - if($escape) { - $text = \SolrUtils::escapeQueryChars($text); - } - $this->filterQueryParts[] = sprintf('%s:"%s"', $field, $text); - } - - public function addRange($field, $min = '*', $max = '*') - { - $this->filterQueryParts[] = sprintf('%s:[%s TO %s]', $field, $min, $max); - } - - public function addSortField($field, $order = \SolrQuery::ORDER_DESC) - { - $this->query->addSortField($field, $order); - } - - public function addFacetField($field) - { - $this->query->addFacetField($field); - } - - public function setFacetRangeField($field) - { - $this->query->setParam('facet.range', $field); - } - - public function setFacetLimits($limit = null, $count = null) - { - if(! is_null($limit)) { - $this->query->setFacetLimit($limit); - } - - if(! is_null($count)) { - $this->query->setFacetMinCount($count); - } - } - - public function setFacetRange($start, $end, $gap) - { - $this->query->setParam('facet.range.start', $start); - $this->query->setParam('facet.range.end', $end); - $this->query->setParam('facet.range.gap', $gap); - } - - /** - * @param int $start - * @param int $count - * @param bool $facets activate faceting ? - * @param bool $spellcheck activate spellcheck ? - * @param bool $highlight activate highlighting ? - * @return array - * @throws WebException - */ - 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 { - $query = implode(' AND ', $this->queryParts); - } - foreach($this->filterQueryParts as $fq) { - $this->query->addFilterQuery($fq); - } - $this->query->setQuery($query); - $this->query->setStart($start); - $this->query->setRows($count); - - $this->query->setParam('facet', $facets ? 'true' : 'false'); - $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) { - throw new WebException ("SolrError", $e->getMessage(), -700); - } - - $books = array(); - if(isset($results['response']['docs']) && is_array($results['response']['docs'])) { - foreach($results['response']['docs'] as $r) { - $books[$r['id']] = $r; - } - } - - $highlighting = array(); - if(isset($results['highlighting'])) { - foreach($results['highlighting'] as $k => $h) { - $data = array(); - foreach($h as $f => $v) { - $data[str_replace('_fr', '', $f)] = reset($v); - } - $highlighting[$k] = $data; - } - } - - $spelling = array(); - if(isset($results['spellcheck']['suggestions'])) { - foreach($results['spellcheck']['suggestions'] as $word => $s) { - $spelling[$word] = $s['suggestion']; - } - } - - $facets = array(); - if(isset($results['facet_counts']['facet_fields'])) { - foreach($results['facet_counts']['facet_fields'] as $f => $d) { - $facets[$f] = $d; - } - } - if(isset($results['facet_counts']['facet_ranges'])) { - $integer = strpos($this->query->getParam('facet.range.gap'), '.') === false; - foreach($results['facet_counts']['facet_ranges'] as $f => $d) { - if($integer) { - $facets[$f] = array(); - foreach($d['counts'] as $k => $v) { - $facets[$f][intval($k)] = $v; - } - } else { - $facets[$f] = $d['counts']; - } - } - } - - return array( - 'count' => $results['response']['numFound'], - 'facets' => array( - 'facets' => $facets, - 'highlighting' => $highlighting, - 'spelling' => $spelling, - ), - 'books' => $books, - ); - } - - /** - * Return a list of suggested titles for the given text - * @param string $text - * @return array - * @throws WebException - */ - public function suggest($text) { - $this->query->setQuery($text); - $this->query->setStart(0); - $this->query->setRows(0); - $this->query->setParam('suggest', 'true'); - - try { - $results = $this->client->query($this->query)->getArrayResponse(); - } catch(\SolrClientException $e) { - throw new WebException ("SolrError", $e->getMessage(), -700); - } - - $text = mb_strtolower ($text, 'UTF-8'); - - $suggestions = array(); - if(isset($results['suggest'])) { - foreach($results['suggest'] as $suggester) { - foreach($suggester[$text]['suggestions'] as $s) { - $s['term'] = strip_tags($s['term']); - - $pos = strpos(mb_strtolower($s['term'], 'UTF-8'), $text); - if($pos !== false) { - // increase weight of proposition that have the words at the beginning - $s['weight'] += (int) ((1 - $pos / strlen($s['term'])) * 100); - } - $suggestions[$s['term']] = (array) $s; - } - } - } - - usort($suggestions, function($a, $b) { - return $b['weight'] - $a['weight']; - }); - - return $suggestions; - } - - /** - * Retrieve books from Solr based on their code (NoticeNr). - * - * @param array $codes - * @param string $field the field to use for the search - * @return array Books information - * @throws WebException - */ - public static function GetBooks(array $codes, $field = 'code') { - // it is faster to do multiple small request to Solr rather than one big so separate - // in chunks if we are above the limit. 15 was found by testing and seems to be a sweet spot - $limit = 15; - $count = count($codes); - if($count > $limit) { - $parts = array_chunk($codes, $limit); - $books = array(); - foreach($parts as $p) { - // if we use array_merge here the numerical keys (book code) will be lost - $books += self::GetBooks($p, $field); - } - return $books; - } - - $bs = new static(); - $bs->addOrQuery($codes, $field); - - $results = $bs->getResults(0, $count); - return $results['books']; - } - - public static function GetTerms($field) { - $s = new BookSearch(); - $s->addFilterQuery(1, 'visible'); - $s->addFacetField($field); - $s->setFacetLimits(2000, 2); - $results = $s->getResults(0, 0, true); - - return $results['facets']['facets'][$field]; - } - - - public static function GetTermsRange($field) { - $s = new BookSearch(); - $s->addFilterQuery(1, 'visible'); - $s->setFacetRangeField($field); - $s->setFacetRange(0, 250 * 60, 30); - // to avoid useless calculation, only set this 'normal' facet - $s->addFacetField('visible'); - $results = $s->getResults(0, 0, true); - - return $results['facets']['facets'][$field]; - } -} diff --git a/Lib/db/Connection.php b/Lib/db/Connection.php deleted file mode 100644 index be1d6a8..0000000 --- a/Lib/db/Connection.php +++ /dev/null @@ -1,194 +0,0 @@ -is_error()) { - if($throw_error) { - throw new SqlException($result->get_error(), $query); - } - - return $result->get_error(); - } - - return $result; - } - - public static function get() - { - if (is_null(self::$db)) { - $dsn = sprintf( - "Driver={%s};Server=%s,%s;Database=%s;", - Configuration::get('db.driver'), - Configuration::get('db.server'), - Configuration::get('db.port'), - Configuration::get('db.name') - ); - self::$db = odbc_pconnect($dsn, Configuration::get('db.username'), Configuration::get('db.password')); - - if (self::$db === false) { - throw new SqlException("Unable to connect to the server."); - } - } - // Return the connection - return self::$db; - } - - final private function __clone() {} -} - -class OdbcResultSet implements \Iterator, \ArrayAccess -{ - public $length; - - private $results; - private $error; - private $num_fields; - private $num_rows; - private $cursor_index; - - public function __construct($odbc_result) - { - if ($odbc_result === false) { - $this->error = odbc_errormsg(Connection::get()); - } else { - try { - $this->results = array(); - $this->num_fields = odbc_num_fields($odbc_result); - $this->num_rows = odbc_num_rows($odbc_result); - - if ($this->num_fields > 0) { - while ($row = odbc_fetch_row($odbc_result)) { - $data = array(); - for ($i = 1; $i <= $this->num_fields; ++$i) { - $data[odbc_field_name($odbc_result, $i)] = utf8_encode(odbc_result($odbc_result, $i)); - } - $this->results[] = $data; - } - }; - } catch (\Exception $e) { - print($e->getMessage()); - } - - $this->cursor_index = 0; - $this->length = count($this->results); - odbc_free_result($odbc_result); - } - } - - public function get_num_rows() - { - return $this->num_rows; - } - - public function is_error() - { - return ($this->error ? true : false); - } - - public function get_error() - { - return $this->error; - } - - public function get_row() - { - return $this->current(); - } - - public function to_array() - { - return $this->results; - } - - // ArrayAccess - /** - * @param int $offset - * @return bool - */ - public function offsetExists($offset) - { - return !$this->error && $this->cursor_index < $this->length && $this->cursor_index >= 0; - } - - /** - * @param int $offset - * @return bool|array - */ - public function offsetGet($offset) - { - return $this->offsetExists($offset) ? $this->results[$offset] : false; - } - - public function offsetSet($offset, $value) - { - if($this->offsetExists($offset)) { - $this->results[$offset] = $value; - } - } - - public function offsetUnset($offset) - { - throw new \RuntimeException("This makes no sense at all."); - } - - // Iterator - /** - * @return bool|array - */ - public function current() - { - return $this->offsetGet($this->cursor_index); - } - - /** - * @return int - */ - public function key() - { - return $this->cursor_index; - } - - /** - * @return array|bool - */ - public function next() - { - $current = $this->current(); - ++$this->cursor_index; - return $current; - } - - public function rewind() - { - $this->cursor_index = 0; - } - - /** - * @return bool - */ - public function valid() - { - return $this->offsetExists($this->cursor_index); - } -} \ No newline at end of file diff --git a/Lib/db/DbHelper.php b/Lib/db/DbHelper.php deleted file mode 100644 index abe8eb0..0000000 --- a/Lib/db/DbHelper.php +++ /dev/null @@ -1,63 +0,0 @@ -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 deleted file mode 100644 index b78c0ab..0000000 --- a/Lib/db/DbMapping.php +++ /dev/null @@ -1,117 +0,0 @@ -setAttributes($attributes); - } - - /** - * Define a bunch of attribute given by an associative array - * @param array $attributes - */ - public function setAttributes(array $attributes) - { - $this->assertAttributes($attributes); - foreach ($attributes as $key => $value) { - $this->__set($key, $value); - } - } - - /** - * Ensure that all keys from attributes are authorized - * @param array $attributes - */ - private function assertAttributes(array $attributes) - { - foreach ($attributes as $key => $value) { - $this->assertAttribute($key); - } - } - - /** - * Ensure that name attribute is authorized - * If public_only is false, check against PRIVATE_ATTRIBUTES_NAME too. - * Those one cannot be accessed via setAttributes and other batch methods. - * @param string $name - * @param bool $public_only - * @throws InvalidAttributeException if the attribute is not a valid one - */ - private function assertAttribute($name, $public_only = TRUE) - { - if (strpos($this->attributeNames, $name) === false && ($public_only || strpos($this->privateAttributeNames, $name) === false)) { - throw(new InvalidAttributeException("The attribute $name is invalid")); - } - } - - /** - * Get a user attribute or the linked wishes - - * @param string $name - * @return mixed - */ - public function __get($name) - { - $sql_safe = FALSE; - if (strpos($name, 'sql_') === 0) { - $name = substr($name, 4); - $sql_safe = TRUE; - } - $this->assertAttribute($name, false); - if (isset($this->attributes[$name])) { - $value = $this->attributes[$name]; - if ($sql_safe) { - $value = str_replace("'", "''", $value); - } - return $value; - } else { - return NULL; - } - } - - public function to_array() { - return $this->attributes; - } - - /** - * Set a user attribute - * @param string $name - * @param mixed $value - */ - public function __set($name, $value) - { - $this->assertAttribute($name, false); - $this->attributes[$name] = $value; - } - - /** - * Return all the public attributes in an array; - */ - public function toArray() - { - $result = array(); - foreach ($this->attributes as $name => $value) { - if (strpos($this->attributeNames, $name) !== false) { - $result[$name] = $value; - } - } - return $result; - } -} diff --git a/Lib/db/User.php b/Lib/db/User.php deleted file mode 100644 index 2e38b6f..0000000 --- a/Lib/db/User.php +++ /dev/null @@ -1,330 +0,0 @@ - 0) { - $cond = " AND $cond"; - } - - $sql = sprintf("SELECT TOP 1 - [FirstName] AS firstName, - [LastName] AS lastName, - [DisplayName] AS displayName, - [UserDefined1] AS freeOne, - [ActualAddressID] AS addressId, - [Email] AS mail, - [TelephoneMobile] AS mobilePhone, - [TelephonePrivate] AS privatePhone, - [Telephone] AS officePhone, - [UserAccountID] AS id, - 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 AND CategoryCode in ('A', 'M', 'G', 'D', 'I', 'EMP');", - $login, $cond); - - $results = Connection::execute($sql, $raiseError); - return $results->current() !== false ? new User($results->current()) : null; - } - - /** - * Circulations as needed for the BSR internal tools - */ - public function GetCirculations() - { - $sql = sprintf("SELECT - n.NoticeID, - ItemNr, - LTRIM(RTRIM(n.NoticeNr)) AS code, - LTRIM(RTRIM(n.Title)) AS Title, - LTRIM(RTRIM(n.Author)) AS author, - Fields.[300] AS media, - Fields.[901] AS readBy - FROM Circulations AS c - INNER JOIN Items AS i ON i.ItemId = c.ItemId - INNER JOIN Notices AS n ON n.NoticeID = i.NoticeID - LEFT OUTER JOIN ( - SELECT * - FROM ( - SELECT - NoticeID, - Tag AS Field, - NoticeFields.ContentShortPart AS Data - FROM NoticeFields - WHERE Tag IN ('901', '300') - ) AS src - PIVOT ( - MIN(Data) - FOR Field IN ([901], [300]) - ) AS pvt - ) Fields ON n.NoticeID = Fields.NoticeID - WHERE - c.UserAccountID = %s - ORDER BY ItemNr ASC", $this->id); - - $result = Connection::execute($sql); - return $result ? $result->to_array() : array(); - } - - public function GetOldLoansNrs() - { - $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 - 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 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 - ORDER BY %s", $table, $this->id, $sort); - - return Connection::execute($sql)->to_array(); - } - - 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 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]['checkoutDate'] = $c['CheckOutDate']; - $books[$id]['remark'] = $c['Remark']; - } - } - - return $books; - } - - /** - * Loans (Circulations) as needed on the website - * @param boolean $count return only the count - * @return array - */ - public function GetLoans($count = false) - { - return $this->_getLoans('Circulations', $count, "ItemNr ASC"); - } - - /** - * Old loans (OldCirculations) as needed on the website - * @param boolean $count return only the count - * @return array - */ - public function GetOldLoans($count = false) - { - 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(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. - - * @param string $noticeNr - * @return bool - */ - public function addWish($noticeNr) - { - if ($this->hasWish($noticeNr)) { - return false; - } - - $sql = "UPDATE Counters - SET WishID = WishID + 1 - OUTPUT INSERTED.WishID;"; - $result = Connection::execute($sql, true); - $row = $result->current(); - - $employee_id = Configuration::get('www_employee_id'); - $library_id = Configuration::get('www_library_id'); - $sql = sprintf("INSERT INTO Wishes - (WishID, NoticeID, UserAccountID, CreationDate, EmployeeID, BranchOfficeID, Remark, ModificationDate) - SELECT %s , NoticeID, %s, GETDATE() , %s , %s , '' , GETDATE() - FROM Notices - WHERE LTRIM(RTRIM(NoticeNr)) = '%s';", - $row['WishID'], $this->id, $employee_id, $library_id, $noticeNr); - - $status = Connection::execute($sql); - return $status && ! $status->is_error() && $status->get_num_rows() > 0; - } - - /** - * Return true if the book is in the wish list - * @param string $noticeNr - * @return bool - */ - private function hasWish($noticeNr) - { - $sql = sprintf("SELECT w.NoticeID - FROM Wishes AS w - INNER JOIN Notices AS n ON n.NoticeID = w.NoticeID - WHERE - LTRIM(RTRIM(n.NoticeNr)) = '%s' - AND w.UserAccountID = %s;", $noticeNr, $this->id); - $result = Connection::execute($sql); - - return $result->current() !== false; - } - - /** - * Wishes are all the books that this user want to read. - * @param boolean $count return only the count - * @param int $limit - * @return array - */ - public function getWishes($count = false, $limit = 200) - { - $sql = sprintf("SELECT TOP $limit - NoticeID, CreationDate - FROM Wishes - WHERE UserAccountID = %s - ORDER BY CreationDate DESC", $this->id); - - $result = Connection::execute($sql); - - $wishList = $result->to_array(); - $ids = array_map(function($r) { return $r['NoticeID']; }, $wishList); - if($count) { - return count($ids); - } - - $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; - } - - /** - * Remove a book from the wish list - * @param string $noticeNr - * @return boolean Was the deletion was successful or not ? - */ - public function deleteWish($noticeNr) - { - $sql = sprintf("DELETE w - FROM Wishes AS w - INNER JOIN Notices AS n ON n.NoticeID = w.NoticeID - WHERE - LTRIM(RTRIM(n.NoticeNr)) = '%s' - AND UserAccountID = %s;", $noticeNr, $this->id); - $status = Connection::execute($sql, true); - return $status && ! $status->is_error() && $status->get_num_rows() > 0; - } -} diff --git a/NetBiblio.php b/NetBiblio.php deleted file mode 100644 index 0497747..0000000 --- a/NetBiblio.php +++ /dev/null @@ -1,985 +0,0 @@ -login = $_SESSION["user"]["login"]; - $this->client = isset($_SESSION["user"]["client"]) ? $_SESSION["user"]["client"] : 'website'; - } - - /** - * Retrieve information about the current user from the database. - * If a username is given, first validate that it is the same - * currently in the session. - * - * @param string|null $login - * @return User - * @throws AuthenticationException - */ - private function getUser($login = null) - { - if(! is_null($login) && $_SESSION["user"]["login"] !== $login) { - throw new AuthenticationException("BadLogin", "Login '$login' is invalid.", AuthenticationException::BAD_LOGIN); - } - - $this->checkSession(); - - if(strlen($this->login) == 0) { - throw new AuthenticationException("LoginEmpty", "No login information found in session.", AuthenticationException::LOGIN_EMPTY); - } - - $user = User::find($this->login); - - if (!$user) { - throw new AuthenticationException("UserNotFound", "No user found for '{$this->login}'.", AuthenticationException::USER_NOT_FOUND); - } - - return $user; - } - - /** - * Retrieve file information (samples and zip) for a list of books based - * on their code (NoticeNr). - * This should be called only if those information are not already in Solr - * for the given books. - * - * @param array $codes - * @return array File information indexed by book code - */ - private function GetFiles(array $codes) - { - $codes = array_map('intval', $codes); - - - $uri = sprintf("%s%s", - 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); - $json = curl_exec($ch); - curl_close($ch); - - return json_decode($json, true); - } - - /** - * Save files information (samples and zip) for books into Solr - * based on their id (NoticeId). - * - * @param $files - */ - private function SetFiles($files) { - $json = json_encode(array_values(array_map(function($f) { - return array( - 'id' => $f['id'], - 'samples' => array('set' => isset($f['samples']) ? $f['samples'] : array()), - 'zip' => array('set' => isset($f['zip']['uri']) ? $f['zip']['uri'] : ''), - 'zip_size' => array('set' => isset($f['zip']['size']) ? $f['zip']['size'] : 0), - ); - }, $files))); - - $uri = sprintf('%s:%s/%s/update?commitWithin=500', - Configuration::get('solr.server'), - Configuration::get('solr.port'), - Configuration::get('solr.path') - ); - $ch = curl_init($uri); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); - curl_setopt($ch, CURLOPT_POSTFIELDS, $json); - curl_setopt($ch, CURLOPT_HTTPHEADER, array( - 'Content-Type: application/json', - 'Content-Length: ' . strlen($json) - )); - - curl_exec($ch); - curl_close($ch); - } - - /** - * Add some information to each books : - * 1° File information if not already their (@see GetFiles), - * those information are then saved into Solr (@see SetFiles) - * 2° Correctly set hash on zip file to authenticate download - * 3° Compatibility fields for mobile apps - * - * You can pass either a single book or an array of books. - * - * @param array $books either one or a list of books - * @return array either one or a list of books - */ - private function AddBookData(array $books) - { - 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 - $files = array(); - if(isset($b['samples']) && count($b['zip']) > 0) { - $files['samples'] = $b['samples']; - } - unset($b['samples']); - if(isset($b['zip']) && strlen($b['zip']) > 0) { - $files['zip'] = array( - 'uri' => $b['zip'], - 'size' => $b['zip_size'], - ); - } - unset($b['zip']); - unset($b['zip_size']); - - if(! empty($files)) { - $b['files'] = $files; - } - - // date will be already set if we are updating Circulations - if(! isset($b['date'])) { - $b['date'] = date('Y.m.d', strtotime($b['availabilityDate'])); - } - - // add fields for mobile apps compatibility - $b['readBy'] = isset($b['reader']) ? $b['reader'] : 'Lecteur inconnu'; - $b['category'] = $b['genre']; - $b['code3'] = $b['producerCode']; - $b['code3Long'] = $b['producer']; - $b['typeMedia1'] = $b['mediaType']; - return $b; - }, $books); - - // retrieve files information for the book that don't have all of them at this time - $booksWithoutFiles = array_filter($books, function($b) { - return ! ( - isset($b['files']) && - isset($b['files']['samples']) && - count($b['files']['samples']) == 2 && // we want two samples .wav and ogg) - isset($b['files']['zip']) // we want a zip file - ); - }); - - if(count($booksWithoutFiles) > 0) { - $ids = array_map(function($b) { return $b['code']; }, $booksWithoutFiles); - $files = $this->GetFiles($ids); - - if(count($files) > 0) { - foreach($booksWithoutFiles as $k => $b) { - $fileCode = sprintf("%05u", $b['code']); - if(isset($files[$fileCode])) { - $books[$k]['files'] = $files[$fileCode]; - $files[$fileCode]['id'] = $b['id']; - } else { - // we need to have an empty array for mobile apps compatibility. - $books[$k]['files'] = array(); - } - } - } - - $this->SetFiles($files); - } - - // retrieve login information if they exists to generate the URL - $this->CheckSession(); - - // add hash, client and login into zip file uri - $books = array_map(function($b) { - $b['files']['cacheable_uri'] = isset($b['files']['zip']['uri']) ? $b['files']['zip']['uri'] : false; - - if(strlen($this->login) > 0 && isset($b['files']['zip']['uri'])) { - $key = 'babf2cfbe2633c3082f8cfffdb3d9008b4b3b300'; - $code = sprintf("%05u", $b['code']); - $hash = sha1($this->client.$this->login.$key.$code.date('Ymd')); - - $b['files']['zip']['uri'] = str_replace(array( - '{client}', - '{login}', - '{hash}', - ), array( - $this->client, - $this->login, - $hash, - ), $b['files']['zip']['uri']); - } else { - unset($b['files']['zip']); - } - - return $b; - }, $books); - - return $books; - } - - /** - * Return true if the value matches a book code (a number with 1 to 5 digits) - * @param $val - * @return int - */ - protected function IsBookCode($val) { - return preg_match('/^[0-9]{1,5}$/', $val); - } - - // ********************************** - // * Public methods * - // ********************************** - - /** - * This method register a download made through the website or mobile application - * as a lent and returned book (OldCirculation). - * - * @param string $client - * @param string $login - * @param int $code - * @return array - * @throws Lib\Exception\SqlException - * @throws WebException - */ - public function AddDownloadLog($client, $login, $code) - { - $dl_alert = 80; - $client = str_replace("'", "", $client); - $login = str_replace("'", "", $login); - $code = ltrim(str_replace("'", "", $code), '0'); - $itemNr = $code . 'V'; - - $sql = "SELECT itemID FROM Items WHERE LTRIM(RTRIM(ItemNr)) = '$itemNr';"; - $result = Connection::execute($sql, false); - if ($row = $result->current()) { - $itemId = $row['itemID']; - } else { - throw new WebException("ItemNotFound", "cannot find item", -1030); - } - - $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 - UserAccountID= $userId AND - itemID = $itemId AND - LTRIM(RTRIM(remark)) = '$client';"; - $result = Connection::execute($sql, false); - - if ($row = $result->current()) { - $id = $row['circulationId']; - $sql = "UPDATE OldCirculations - SET - CheckInDate=GETDATE(), - CheckOutDate=GETDATE() - WHERE circulationID = $id"; - Connection::execute($sql); - return array('success' => true); - } - - $sql = "SELECT TOP 1 circulationID FROM OldCirculations ORDER BY CirculationID DESC"; - $result = Connection::execute($sql, false); - if ($row = $result->current()) { - $nextId = $row['circulationID'] + 1; - } else { - $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 = 'g@lespagesweb.ch'; - $subject = 'Limite atteinte pour '.$username.", ".$login; - $message = "Nombre de livres ce mois: ".($DLs+1); - $headers = 'From: webmaster@abage.ch' . "\r\n" . - 'Reply-To: webmaster@abage.ch' . "\r\n" . - 'X-Mailer: PHP/' . phpversion(); - - mail($to, $subject, $message, $headers); - } - } - - $sql = "UPDATE UserAccounts - SET - Circulations = Circulations + 1, - TotalCirculations = TotalCirculations + 1 - WHERE UserAccountID = $userId;"; - Connection::execute($sql); - - $sql = "UPDATE Items - SET - Circulations = Circulations + 1, - TotalCirculations = TotalCirculations + 1 - WHERE ItemID = $itemId;"; - Connection::execute($sql); - - $worker_id = Configuration::get('netbiblio_worker_id'); - $sql = "INSERT INTO OldCirculations ( - CirculationID, ItemID, UserAccountID, - Remark, - DueDate, CheckOutDate, CheckInDate, - CheckOutBranchOfficeID, CheckOutEmployeeID, CheckInBranchOfficeID, CheckInEmployeeID, - Reminders, Renewals, PreReminder, InfoCode, CheckOutSIP2Info, CheckInSIP2Info - ) VALUES ( - $nextId, $itemId, $userId, - '$client', - DATEADD(month, 2, GETDATE()), GETDATE(), GETDATE(), - 2, $worker_id, 2, $worker_id, - 0, 0, 1, '-', 1, 1 - );"; - $status = Connection::execute($sql); - return array('success' => $status && ! $status->is_error() && $status->get_num_rows() > 0); - } - - /** - * This method authenticates and store the login information into the session so - * that the next calls can be made for this user. - * - * @param $login - * @param $password - * @param string $client - * @return array - * @throws AuthenticationException - */ - public function Authenticate($login, $password, $client = "website") - { - session_unset(); /* destroy all session vars */ - - $user = User::authenticate($login, $password); - - if (! $user) { - throw new AuthenticationException("AuthenticationFailed", "Invalid login or password.", AuthenticationException::AUTHENTICATION_FAILED); - } - - $_SESSION["user"]["login"] = $login; - $_SESSION["user"]["client"] = $client; - - $this->login = $login; - $this->client = $client; - - return $user->toArray(); - } - - /** - * This method disconnects the current user and clear all session data. - * - * @return array - */ - public function Disconnect() - { - $_SESSION = array(); - - if (ini_get("session.use_cookies")) { - $params = session_get_cookie_params(); - setcookie(session_name(), '', time() - 42000, - $params["path"], $params["domain"], - $params["secure"], $params["httponly"]); - } - - return array('success' => true); - } - - /** - * Return the information associated with the currently authenticated user - * if any. - * - * @return array - * @throws AuthenticationException - */ - public function IsAuthenticated() - { - return $this->getUser()->toArray(); - } - - /** - * This method returns the account information for the given login, but only - * if it matches the currently authenticated user. - * - * @param string $login - * @return array - * @throws AuthenticationException - */ - public function FindAccount($login) - { - return $this->getUser($login)->toArray(); - } - - /** - * This method returns the books on the currently authenticated user wishlist. - * - * @return array - * @throws AuthenticationException - */ - public function GetWishes() - { - $books = $this->getUser()->getWishes(); - return array_values($this->AddBookData($books)); - } - - /** - * This method returns the list of all Circulations for the currently - * authenticated user in a format suited for BSR internal tools - * (CD engraving for example). - * - * @return array - * @throws AuthenticationException - */ - public function GetCirculations() - { - return $this->getUser()->GetCirculations(); - } - - /** - * This method returns the list of books that are currently lent to the - * authenticated user. - * - * @return array - * @throws AuthenticationException - */ - public function GetLoans() - { - $circulations = $this->getUser()->GetLoans(); - 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. - * - * @return array - * @throws AuthenticationException - */ - public function GetOldLoans() - { - $circulations = $this->getUser()->GetOldLoans(); - 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; - } - - /** - * 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 : - * - * ° 'loans' : number of current loans - * ° 'oldLoans' : number of past loans - * ° 'wishes' : number of wishes - * ° 'novelties' : new books - * ° 'recommendations' : recommended books - * - * @return array - * @throws AuthenticationException - */ - public function GetDashboardData() - { - $user = $this->getUser(); - return array( - 'loans' => $user->GetLoans(true), - 'oldLoans' => $user->GetOldLoans(true), - 'wishes' => $user->getWishes(true), - 'novelties' => $this->LastBooksByType('', 12), - 'recommendations' => $this->MoreLikeLoans(8), - ); - } - - /** - * This method adds a book to the currently authenticated user wishlist - * based on its code. - * - * @param int $code - * @return array - * @throws AuthenticationException - */ - public function AddWish($code) - { - $status = $this->getUser()->addWish($code); - return array('success' => $status); - } - - /** - * This method deletes the given book from the currently authenticated - * user wishlist based on its code. - * - * @param int $code - * @return array - * @throws AuthenticationException - */ - public function DeleteWish($code) - { - $status = $this->getUser()->deleteWish($code); - return array('success' => $status); - } - - /** - * This method returns an array of books based on their code - * - * @param array|int[] $codes - * @return array - */ - public function FindBooks($codes) - { - return array_values($this->AddBookData(BookSearch::GetBooks(json_decode($codes)))); - } - - /** - * This method return a book based on its code - * - * @param int $code - * @return array - */ - public function FindBook($code) - { - $books = $this->AddBookData(BookSearch::GetBooks(array($code))); - return reset($books); - } - - /** - * This method returns a list of random books. - * For a given seed, the list should be always the same at least while - * Solr is not restarted (or documents re-indexed) - * - * @param int $number Number of random books to return - * @param null $seed - * @param int $page - * @return array - * @throws WebException - */ - public function GetRandomBooks($number = 100, $seed = null, $page = 0) { - if(is_null($seed)) { - $seed = time(); - } - - $bs = new BookSearch(); - $bs->addSortField('random_'.$seed); - $bs->addFilterQuery(1, 'visible'); - $results = $bs->getResults($page * $number, $number); - return $this->AddBookData($results['books']); - } - - /** - * This method is used by the iOS application to perform searching. - * If a number is given, search in the book codes, otherwise perform - * a full text search. - * - * @param string $text Text to search - * @param int $start - * @param int $limit - * @return array an array of books - * @throws WebException - */ - public function Search($text, $start, $limit) - { - $query = array( - 'queryText' => $text, - 'count' => $limit, - 'page' => max(intval($start) - 1, 0), - ); - - if($this->IsBookCode($text)) { - $query['queryType'] = 'code'; - } - - $data = $this->NewSearch(json_encode($query)); - - // remove fields that are not used in "old" search - unset($data['count']); - unset($data['facets']); - return $data; - } - - /** - * This method is used by the website and the Android application to perform - * book search. - * - * Search parameters : - * - * ° queryText : the text to search for - * ° queryType : the field to search in, defaults to 'text' - * - * ° jeunesse : only display books for kids (must have format 'jeunesse' => array('filtrer' => 'filtrer') - * - * ° producerCode : filter by 'producerCode' - * ° genreCode : filter by 'genreCode' - * ° author : filter by 'author' - * ° reader : filter by 'reader' - * ° motsMatieres : filter by 'motsMatieres' - * - * ° duration : exact duration in minutes - * ° durationMin : minimal duration in minutes - * ° durationMax : maximal duration in minutes - * - * ° count : number of results we want - * ° page : page to start at (0 is the first) - * - * Shortcuts : - * - * ° producer : synonym for 'producerCode' (see above) - * ° genre : synonym for 'genreCode' (see above) - * - * Deprecated, but still in use on mobile apps : - * - * ° category : synonym for 'genre' (see above) - * - * Return value : - * - * The return value start with two keys : - * - * ° 'count' : which is the total number of available results - * ° 'facets' : which contains all other relevent information (facets, spellchecking, - * highlighting, etc). This name is used for compatibility reasons. - * - * Then, the books come right after. - * - * @param string $values JSON encoded object - * @return array - * @throws WebException - */ - public function NewSearch($values) - { - // we need the client to perform some query field replacement - $this->CheckSession(); - - $queryArray = json_decode($values, true); - if(! is_array($queryArray)) { - throw new WebException("CallArg", "Argument must be valid JSON.", -42); - } - - // shortcuts and the iOS app still uses 'category' - $compatibility = array( - 'genre' => 'genreCode', - 'category' => 'genreCode', - 'producer' => 'producerCode' - ); - foreach($compatibility as $old => $new) { - if(isset($queryArray[$old])) { - $queryArray[$new] = $queryArray[$old]; - unset($queryArray[$old]); - } - } - - $bs = new BookSearch(); - - // when search on a particular field, put results in descending date order - 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(in_array($type, array('title', 'author', 'reader'))) { - // we don't want an exact search on mobile apps - $type = $type.'_fr'; - } else if($type == 'text') { - // 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); - } - - if(isset($queryArray['genreCode']) && is_array($queryArray['genreCode'])) { - // Jeunesse is a particular genre with it's own way of being searched - if(($key = array_search('J', $queryArray['genreCode'])) !== false) { - unset($queryArray['genreCode']['J']); - $queryArray['jeunesse'] = array('filtrer' => 'filtrer'); - } - } - - if(isset($queryArray['jeunesse']) && $queryArray['jeunesse']['filtrer'] === 'filtrer') { - $bs->addFilterQuery(1, 'jeunesse'); - } - - if(isset($queryArray['duration'])) { - $bs->addQuery($queryArray['duration'], 'duration'); - } else if(isset($queryArray['durationMin']) || isset($queryArray['durationMax'])) { - $min = isset($queryArray['durationMin']) ? $queryArray['durationMin'] : '*'; - $max = isset($queryArray['durationMax']) ? $queryArray['durationMax'] : '*'; - $bs->addRange('duration', $min, $max); - } - - $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) || - (is_array($queryArray[$q]) && count($queryArray[$q]) > 0) - )) { - if(is_array($queryArray[$q])) { - // Genres cannot overlap, so we use 'OR', otherwise use 'AND' - $bs->addCompoundQuery($queryArray[$q], $q, $q == 'genreCode' ? 'OR' : 'AND'); - } else { - if($q == 'reader'){ - $q2 = 'reader_fr'; - $queryArray[$q] = ucfirst($queryArray[$q]); - } else{$q2 = $q;} - - $bs->addQuery($queryArray[$q], $q2); - } - } - } - - // we only want visible books in search results - $bs->addFilterQuery(1, 'visible'); - - $count = isset($queryArray['count']) ? (int) $queryArray['count'] : Configuration::get('solr.result_count'); - $start = isset($queryArray['page']) ? $queryArray['page'] * $count : 0; - $facets = isset($queryArray['facets']) && $queryArray['facets']; - $spellcheck = isset($queryArray['spellcheck']) && $queryArray['spellcheck']; - $highlight = isset($queryArray['highlight']) && $queryArray['highlight']; - - $results = $bs->getResults($start, $count, $facets, $spellcheck, $highlight); - - $data = array( - 'count' => $results['count'], - 'facets' => $results['facets'], - ); - - $finalResult = array_merge($data, $this->AddBookData($results['books'])); - for($i = 0; $i < count($finalResult)-2 ; $i++){ - $finalResult[$i]['position']=$i; - } - return $finalResult; - } - - /** - * 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 MoreLikeThis($ids, $number = 8) - { - $bs = new BookSearch(false); - $bs->addOrQuery(is_array($ids) ? $ids : array($ids), 'id'); - $bs->setHandler('more'); - $results = $bs->getResults(0, $number); - 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. - * - * @param int number of books - * @return array - * @throws AuthenticationException - */ - public function MoreLikeLoans($number = 8) - { - $circulations = $this->getUser()->getLoansData('OldCirculations'); - $ids = array_map(function($c) { return $c['NoticeId']; }, $circulations); - return $this->MoreLikeThis($ids, $number); - } - - /** - * This method return a list of suggested titles for the given search terms - * @param string $text - * @return array - */ - public function Suggest($text) - { - $bs = new BookSearch(); - return $bs->suggest($text); - } - - /** - * This method returns the list of durations in minutes but with 30 minutes gaps - * and the count of books in each group. - * - * @return array - */ - public function ListOfDurations() - { - return BookSearch::GetTermsRange('duration'); - } - - /** - * This method returns the list of all volunteer readers that read book - * in the database. - * @return array - */ - public function ListOfReaders() - { - $readers = array(); - foreach(BookSearch::GetTerms('reader') as $name => $count) { - $parts = explode(" ", $name); - $firstname = array_shift($parts); - $lastname = implode(" ", $parts); - - $fullname = trim($lastname.' '.$firstname); - $readers[$fullname] = array( - 'lastname' => $lastname, - 'firstname' => $firstname, - 'count' => $count, - ); - } - - // sort readers by lastname - ksort($readers); - - return array_values($readers); - } - - /** - * This method is called by the website in Drupal to get the list - * of available 'Genres'. - * @return array - */ - public function ListOfGenres() - { - return DBHelper::ListOfGenres(); - } - - /** - * This method is called by the Android application to get the list - * of available 'Genres'. - * @return array - */ - public function ListOfCategories() - { - return DBHelper::ListOfGenres(true); - } - - /** - * This method is called by the iOS application to get the list - * of available 'Genres'. 'Jeunesse' must be a part of them. - * @return array - */ - public function ListOfTypes() - { - return array_map(function($g) { - return $g['text']; - }, DBHelper::ListOfGenres(true)); - } - - /** - * This method returns the list of all books that are currently - * being read by the volunteers. - * - * @return array - */ - public function InReadingBooks() - { - return DBHelper::InReading(); - } - - /** - * This method is used by the iOS application to retrieve the last - * books for a given Genre. It may receives the genre 'Jeunesse' which - * is a boolean value on Solr documents. - * - * @param string $genre Genre for which we want books (not the code), this can be empty - * @param int $number number of books - * @return array - * @throws WebException - */ - public function LastBooksByType($genre, $number) - { - $s = new BookSearch(); - if($genre == 'Jeunesse') { - $s->addQuery(1, 'jeunesse'); - } else if(! empty($genre)) { - $s->addQuery($genre, 'genre'); - } - - $s->addSortField('availabilityDate'); - - // we only want visible books - $s->addFilterQuery(1, 'visible'); - - $results = $s->getResults(0, $number); - $books = $this->AddBookData($results['books']); - - if(empty($genre)) { - return $books; - } - - $data = array(); - foreach($books as $b) { - $data[$genre][] = $b; - } - return $data; - } -} diff --git a/composer.json b/composer.json index 77e3826..3612bd2 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name" : "bsr/webservice", - "description" : "Webservice a library", + "description" : "Webservice for a library", "repositories" : [ { "type" : "vcs", @@ -20,5 +20,8 @@ }, "autoload": { "psr-4": {"BSR\\Lib\\" : "Lib"} + }, + "require-dev": { + "pds/skeleton": "^1.0" } } diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..d0a2040 --- /dev/null +++ b/composer.lock @@ -0,0 +1,50 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "hash": "bae5c4c1d23da7b19effa06573632e18", + "content-hash": "442d9e936a1cf311fd26a8bf5bfad65e", + "packages": [], + "packages-dev": [ + { + "name": "pds/skeleton", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-pds/skeleton.git", + "reference": "95e476e5d629eadacbd721c5a9553e537514a231" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-pds/skeleton/zipball/95e476e5d629eadacbd721c5a9553e537514a231", + "reference": "95e476e5d629eadacbd721c5a9553e537514a231", + "shasum": "" + }, + "bin": [ + "bin/pds-skeleton" + ], + "type": "standard", + "autoload": { + "psr-4": { + "Pds\\Skeleton\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "CC-BY-SA-4.0" + ], + "description": "Standard for PHP package skeletons.", + "homepage": "https://github.com/php-pds/skeleton", + "time": "2017-01-25 23:30:41" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/configuration.local.php b/config/configuration.local.php similarity index 91% rename from configuration.local.php rename to config/configuration.local.php index 3e3be21..d72b9bd 100644 --- a/configuration.local.php +++ b/config/configuration.local.php @@ -1,10 +1,10 @@ NetBiblio::$version, - 'title' => 'Help', - 'content' => Help::content(new NetBiblio()), -)); diff --git a/logs.php b/logs.php deleted file mode 100644 index fe16cb3..0000000 --- a/logs.php +++ /dev/null @@ -1,16 +0,0 @@ - NetBiblio::$version, - 'title' => 'Logs', - 'content' => "
$logs", -)); diff --git a/mobile.php b/mobile.php deleted file mode 100644 index a600d04..0000000 --- a/mobile.php +++ /dev/null @@ -1,4 +0,0 @@ -Run(); diff --git a/Lib/Configuration.php b/src/Configuration.php similarity index 64% rename from Lib/Configuration.php rename to src/Configuration.php index 5524729..09bd23d 100644 --- a/Lib/Configuration.php +++ b/src/Configuration.php @@ -17,41 +17,7 @@ class Configuration { * * @var array configuration values */ - private $values = array( - 'db' => array( - 'driver' => 'SQL Server Native Client 11.0', - 'server' => 'BSR2012\SQLEXPRESS', - 'port' => '1433', - 'username' => 'alcoda', - 'password' => 'alcodaonly', - 'name' => 'NetBiblio3', - ), - 'solr' => array( - 'server' => '192.168.1.250', - 'port' => '8983', - 'username' => '', - 'password' => '', - 'path' => 'solr/bsr1', - 'result_count' => 10, - ), - 'log' => array( - 'file' => 'C:\inetpub\wwwroot\WebService\logs\log.txt', - 'format' => '%ip% - [%date%] - %status% %error% - %time% - %func%', - // The greater the verbosity, the more is displayed - // 0 : no log at all - // 1 : log summary - // 2 : log response - 'verbosity' => 0, - ), - 'session' => array( - 'save_path' => '' - ), - '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, - 'www_library_id' => 2, - ); + private $values = array(); private $custom_config_filename = 'configuration.local.php'; @@ -63,7 +29,7 @@ class Configuration { throw new \RuntimeException('No configuration.local.php file was found. Create it with the proper config.'); } - $configuration = include_once realpath(dirname(__FILE__) . '/../') . $this->custom_config_filename; + $configuration = include_once realpath(dirname(__FILE__) . '/../config/') . $this->custom_config_filename; if(!is_array($configuration)) { throw new \RuntimeException("You custom configuration in '{$this->custom_config_filename}' must be in a variable named '\$configuration' and be an array."); diff --git a/Lib/Exception/AuthenticationException.php b/src/Exception/AuthenticationException.php similarity index 100% rename from Lib/Exception/AuthenticationException.php rename to src/Exception/AuthenticationException.php diff --git a/Lib/Exception/InvalidAttributeException.php b/src/Exception/InvalidAttributeException.php similarity index 100% rename from Lib/Exception/InvalidAttributeException.php rename to src/Exception/InvalidAttributeException.php diff --git a/Lib/Exception/SqlException.php b/src/Exception/SqlException.php similarity index 100% rename from Lib/Exception/SqlException.php rename to src/Exception/SqlException.php diff --git a/Lib/Exception/UsageException.php b/src/Exception/UsageException.php similarity index 100% rename from Lib/Exception/UsageException.php rename to src/Exception/UsageException.php diff --git a/Lib/Exception/WebException.php b/src/Exception/WebException.php similarity index 100% rename from Lib/Exception/WebException.php rename to src/Exception/WebException.php diff --git a/Lib/Formatter/Formatter.php b/src/Formatter/Formatter.php similarity index 100% rename from Lib/Formatter/Formatter.php rename to src/Formatter/Formatter.php diff --git a/Lib/Formatter/Html.php b/src/Formatter/Html.php similarity index 100% rename from Lib/Formatter/Html.php rename to src/Formatter/Html.php diff --git a/Lib/Formatter/Json.php b/src/Formatter/Json.php similarity index 100% rename from Lib/Formatter/Json.php rename to src/Formatter/Json.php diff --git a/Lib/Formatter/Text.php b/src/Formatter/Text.php similarity index 100% rename from Lib/Formatter/Text.php rename to src/Formatter/Text.php diff --git a/Lib/Formatter/Xml.php b/src/Formatter/Xml.php similarity index 100% rename from Lib/Formatter/Xml.php rename to src/Formatter/Xml.php diff --git a/Lib/Help.php b/src/Help.php similarity index 100% rename from Lib/Help.php rename to src/Help.php diff --git a/Lib/Logger.php b/src/Logger.php similarity index 100% rename from Lib/Logger.php rename to src/Logger.php diff --git a/Lib/Renderer.php b/src/Renderer.php similarity index 100% rename from Lib/Renderer.php rename to src/Renderer.php diff --git a/Lib/WebService.php b/src/WebService.php similarity index 100% rename from Lib/WebService.php rename to src/WebService.php diff --git a/Lib/autoloader.php b/src/autoloader.php similarity index 100% rename from Lib/autoloader.php rename to src/autoloader.php diff --git a/templates/func_help.html b/templates/func_help.html deleted file mode 100644 index e6e1925..0000000 --- a/templates/func_help.html +++ /dev/null @@ -1,14 +0,0 @@ -