diff --git a/lib/AudioBook.php b/lib/AudioBook.php index 17a3cf5..2658118 100644 --- a/lib/AudioBook.php +++ b/lib/AudioBook.php @@ -1,4 +1,5 @@ length == 0) { - throw new BookNotFoundException($code); - } - - $row = $result->current(); - return $row['NoticeId']; - } - /** * 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 diff --git a/lib/BookSearch.php b/lib/BookSearch.php index 962b782..fe57629 100644 --- a/lib/BookSearch.php +++ b/lib/BookSearch.php @@ -48,27 +48,11 @@ class BookSearch $this->queryParts[] = $queryText; } - public function addResultField($field) - { - $this->query->addField($field); - } - public function addSortField($field, $order = SolrQuery::ORDER_DESC) { $this->query->addSortField($field, $order); } - public function addFacet($field, $minCount = 2) - { - $this->query->setFacet(true); - $this->query->addFacetField($field); - $this->query->setFacetMinCount($minCount, $field); - } - - public function setYearInterval($beginning = 0, $end = 2500) - { - } - /** * @param int $start * @param int $count diff --git a/lib/Connection.php b/lib/Connection.php index d1774cd..a63f6e0 100644 --- a/lib/Connection.php +++ b/lib/Connection.php @@ -49,14 +49,6 @@ class Connection return self::$db; } - public static function escape($data) - { - if (is_numeric($data)) - return $data; - $unpacked = unpack('H*hex', $data); - return '0x' . $unpacked['hex']; - } - final private function __clone() {} } diff --git a/lib/DbMapping.php b/lib/DbMapping.php index 9bcab3c..a4b87ed 100644 --- a/lib/DbMapping.php +++ b/lib/DbMapping.php @@ -59,8 +59,7 @@ abstract class DbMapping /** * Get a user attribute or the linked whishes - * - * If the name start with sql_, escape the string before to return it to avoid SQL injection. + * @param string $name * @return mixed */ @@ -98,11 +97,6 @@ abstract class DbMapping $this->attributes[$name] = $value; } - public function reload() - { - $this->setAttributes(DbMapping::find($this->id)->toArray()); - } - /** * Function to retrieve data from an id. * @param int $id @@ -125,14 +119,10 @@ abstract class DbMapping } return $result; } - } /** * Exception raised when an invalid attribute name is accessed */ -class InvalidAttributeException extends Exception -{ - -} +class InvalidAttributeException extends Exception { } diff --git a/lib/User.php b/lib/User.php index d27aa41..453e68f 100644 --- a/lib/User.php +++ b/lib/User.php @@ -35,12 +35,6 @@ class User extends DbMapping protected static $addressTableName = 'Addresses'; protected static $addressIdColumn = 'AddressID'; protected static $wishTableName = 'Wishes'; - protected static $circulationTableName = 'Circulations'; - protected static $itemTableName = 'Items'; - - protected $wishes; - protected $circulations; - protected $oldCirculations; protected $attributeNames = 'id login firstName lastName displayName freeOne mail addressId mobilePhone officePhone privatePhone'; protected $privateAttributeNames = 'password'; @@ -94,38 +88,6 @@ class User extends DbMapping return $results->current() !== false ? new User($results->current()) : null; } - public function __toString() - { - return $this->displayName; - } - - /** - * Update the database. Note that new user insertion don't work in this implementation. - */ - public function save() - { - $strSQL = "UPDATE " . User::$tableName . " SET FirstName = '$this->sql_firstName', LastName = '$this->sql_lastName', "; - $strSQL .= "DisplayName = '$this->sql_displayName'"; - $strSQL .= "WHERE Replace(UseraccountNr, ' ', '') = '$this->sql_login'"; - Connection::execute($strSQL, true); - - $strSQL = "UPDATE " . User::$addressTableName . " SET Email = '$this->sql_mail', TelephoneMobile = '$this->sql_mobilePhone', "; - $strSQL .= "Telephone = '$this->sql_officePhone', TelephonePrivate = '$this->sql_privatePhone' "; - $strSQL .= "WHERE " . User::$addressTableName . "." . User::$addressIdColumn . " = $this->sql_addressId"; - Connection::execute($strSQL, true); - - if ($this->password) { - $strSQL = "UPDATE " . User::$tableName . " SET Password = UPPER('$this->sql_password') "; - $strSQL .= "WHERE Replace(UseraccountNr, ' ', '') = '$this->sql_login'"; - Connection::execute($strSQL, true); - } - } - - public function reload() - { - $this->setAttributes(User::find($this->login)->toArray()); - } - private function _getCirculations($table, $sort = "ItemNr ASC") { $sql = sprintf("SELECT NoticeID, @@ -163,34 +125,33 @@ class User extends DbMapping /** * Add a book to the wish list if it is not already inside. - * - * delete the wishes cache for it to be reloaded the next time getWishes will be called. + * @param string $noticeNr * @return bool */ public function addWish($noticeNr) { - if (! $this->hasWish($noticeNr)) { - $sql = "UPDATE Counters - SET WishID = WishID + 1 - OUTPUT INSERTED.WishID;"; - $result = Connection::execute($sql, true); - - if ($row = $result->current()) { - $employee_id = Configuration::get('www_employee_id'); - $library_id = Configuration::get('www_library_id'); - $sql = sprintf("INSERT INTO %s - (WishID, NoticeID, %s, CreationDate, EmployeeID, BranchOfficeID, Remark, ModificationDate) - SELECT %s , NoticeID, %s, GETDATE() , %s , %s , '' , GETDATE() - FROM Notices - WHERE LTRIM(RTRIM(NoticeNr)) = '%s';", - User::$wishTableName, User::$idColumn, $row['WishID'], $this->id, $employee_id, $library_id, $noticeNr); - - Connection::execute($sql); - return true; - } + if ($this->hasWish($noticeNr)) { + return false; } - 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 %s + (WishID, NoticeID, %s, CreationDate, EmployeeID, BranchOfficeID, Remark, ModificationDate) + SELECT %s , NoticeID, %s, GETDATE() , %s , %s , '' , GETDATE() + FROM Notices + WHERE LTRIM(RTRIM(NoticeNr)) = '%s';", + User::$wishTableName, User::$idColumn, $row['WishID'], $this->id, $employee_id, $library_id, $noticeNr); + + Connection::execute($sql); + return true; } /** @@ -218,21 +179,16 @@ class User extends DbMapping */ public function getWishes($limit = 50) { - if (!$this->wishes) { - $sql = "SELECT TOP $limit + $sql = sprintf("SELECT TOP $limit NoticeID - FROM ".User::$wishTableName." - WHERE ".User::$idColumn . " = $this->id - ORDER BY CreationDate desc"; - - $result = Connection::execute($sql); - $ids = array(); - while ($row = $result->next()) { - $ids[] = $row['NoticeID']; - } - $this->wishes = AudioBook::findBy('NoticeID', $ids, true); - } - return $this->wishes; + FROM %s + WHERE %s = %s + ORDER BY CreationDate DESC" + ,User::$wishTableName, User::$idColumn, $this->id); + + $result = Connection::execute($sql); + $ids = array_map(function($r) { return $r['NoticeID']; }, $result->to_array()); + return AudioBook::findBy('NoticeID', $ids, true); } /**