|
|
|
|
@ -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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|