Cleanup unused methods and code formatting
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once('DbMapping.php');
|
require_once('DbMapping.php');
|
||||||
|
|
||||||
class BookNotFoundException extends WebException {
|
class BookNotFoundException extends WebException {
|
||||||
@@ -7,13 +8,6 @@ class BookNotFoundException extends WebException {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function convertMSChar($src)
|
|
||||||
{
|
|
||||||
$text = preg_replace('/([\xc0-\xdf].)/se', "'&#' . ((ord(substr('$1', 0, 1)) - 192) * 64 + (ord(substr('$1', 1, 1)) - 128)) . ';'", $src);
|
|
||||||
$text = preg_replace('/([\xe0-\xef]..)/se', "'&#' . ((ord(substr('$1', 0, 1)) - 224) * 4096 + (ord(substr('$1', 1, 1)) - 128) * 64 + (ord(substr('$1', 2, 1)) - 128)) . ';'", $text);
|
|
||||||
return $text;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AudioBook is mapped on a Notice from NetBiblio
|
* AudioBook is mapped on a Notice from NetBiblio
|
||||||
*
|
*
|
||||||
@@ -168,24 +162,6 @@ class AudioBook extends DbMapping
|
|||||||
return $multiple ? $books : reset($books);
|
return $multiple ? $books : reset($books);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $code
|
|
||||||
* @return int
|
|
||||||
* @throws BookNotFoundException
|
|
||||||
* @throws SqlException
|
|
||||||
*/
|
|
||||||
public static function findIdByCode($code)
|
|
||||||
{
|
|
||||||
$sql = "SELECT NoticeId FROM Notices WHERE LTRIM(RTRIM(NoticeNr)) = '$code';";
|
|
||||||
$result = Connection::execute($sql, false);
|
|
||||||
if ($result === false || $result->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).
|
* 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
|
* Returns an associative array containing $lastname and $firstname
|
||||||
|
|||||||
@@ -48,27 +48,11 @@ class BookSearch
|
|||||||
$this->queryParts[] = $queryText;
|
$this->queryParts[] = $queryText;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addResultField($field)
|
|
||||||
{
|
|
||||||
$this->query->addField($field);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addSortField($field, $order = SolrQuery::ORDER_DESC)
|
public function addSortField($field, $order = SolrQuery::ORDER_DESC)
|
||||||
{
|
{
|
||||||
$this->query->addSortField($field, $order);
|
$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 $start
|
||||||
* @param int $count
|
* @param int $count
|
||||||
|
|||||||
@@ -49,14 +49,6 @@ class Connection
|
|||||||
return self::$db;
|
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() {}
|
final private function __clone() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,8 +59,7 @@ abstract class DbMapping
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a user attribute or the linked whishes
|
* 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
|
* @param string $name
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
@@ -98,11 +97,6 @@ abstract class DbMapping
|
|||||||
$this->attributes[$name] = $value;
|
$this->attributes[$name] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function reload()
|
|
||||||
{
|
|
||||||
$this->setAttributes(DbMapping::find($this->id)->toArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to retrieve data from an id.
|
* Function to retrieve data from an id.
|
||||||
* @param int $id
|
* @param int $id
|
||||||
@@ -125,14 +119,10 @@ abstract class DbMapping
|
|||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exception raised when an invalid attribute name is accessed
|
* Exception raised when an invalid attribute name is accessed
|
||||||
*/
|
*/
|
||||||
class InvalidAttributeException extends Exception
|
class InvalidAttributeException extends Exception { }
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
102
lib/User.php
102
lib/User.php
@@ -35,12 +35,6 @@ class User extends DbMapping
|
|||||||
protected static $addressTableName = 'Addresses';
|
protected static $addressTableName = 'Addresses';
|
||||||
protected static $addressIdColumn = 'AddressID';
|
protected static $addressIdColumn = 'AddressID';
|
||||||
protected static $wishTableName = 'Wishes';
|
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 $attributeNames = 'id login firstName lastName displayName freeOne mail addressId mobilePhone officePhone privatePhone';
|
||||||
protected $privateAttributeNames = 'password';
|
protected $privateAttributeNames = 'password';
|
||||||
@@ -94,38 +88,6 @@ class User extends DbMapping
|
|||||||
return $results->current() !== false ? new User($results->current()) : null;
|
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") {
|
private function _getCirculations($table, $sort = "ItemNr ASC") {
|
||||||
$sql = sprintf("SELECT
|
$sql = sprintf("SELECT
|
||||||
NoticeID,
|
NoticeID,
|
||||||
@@ -163,34 +125,33 @@ class User extends DbMapping
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a book to the wish list if it is not already inside.
|
* 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
|
* @param string $noticeNr
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function addWish($noticeNr)
|
public function addWish($noticeNr)
|
||||||
{
|
{
|
||||||
if (! $this->hasWish($noticeNr)) {
|
if ($this->hasWish($noticeNr)) {
|
||||||
$sql = "UPDATE Counters
|
return false;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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)
|
public function getWishes($limit = 50)
|
||||||
{
|
{
|
||||||
if (!$this->wishes) {
|
$sql = sprintf("SELECT TOP $limit
|
||||||
$sql = "SELECT TOP $limit
|
|
||||||
NoticeID
|
NoticeID
|
||||||
FROM ".User::$wishTableName."
|
FROM %s
|
||||||
WHERE ".User::$idColumn . " = $this->id
|
WHERE %s = %s
|
||||||
ORDER BY CreationDate desc";
|
ORDER BY CreationDate DESC"
|
||||||
|
,User::$wishTableName, User::$idColumn, $this->id);
|
||||||
|
|
||||||
$result = Connection::execute($sql);
|
$result = Connection::execute($sql);
|
||||||
$ids = array();
|
$ids = array_map(function($r) { return $r['NoticeID']; }, $result->to_array());
|
||||||
while ($row = $result->next()) {
|
return AudioBook::findBy('NoticeID', $ids, true);
|
||||||
$ids[] = $row['NoticeID'];
|
|
||||||
}
|
|
||||||
$this->wishes = AudioBook::findBy('NoticeID', $ids, true);
|
|
||||||
}
|
|
||||||
return $this->wishes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user