stop using const for table and column names

master
Gilles Crettenand 11 years ago
parent f2f5078dbd
commit b587047d17

@ -31,13 +31,6 @@ use BSR\Lib\Search\BookSearch;
*/
class User extends DbMapping
{
public static $tableName = 'Useraccounts';
public static $idColumn = 'UseraccountID';
protected static $addressTableName = 'Addresses';
protected static $addressIdColumn = 'AddressID';
protected static $wishTableName = 'Wishes';
protected $attributeNames = 'id login firstName lastName displayName freeOne mail addressId mobilePhone officePhone privatePhone';
protected $privateAttributeNames = 'password';
@ -79,12 +72,12 @@ class User extends DbMapping
[TelephoneMobile] AS mobilePhone,
[TelephonePrivate] AS privatePhone,
[Telephone] AS officePhone,
[%s] AS id,
[UserAccountId] AS id,
REPLACE(UseraccountNr, ' ', '') AS login
FROM [%s] AS u
LEFT JOIN [%s] AS a ON a.[%s] = u.[ActualAddressID]
FROM [UserAccounts] AS u
LEFT JOIN [Addresses] AS a ON a.[AddressID] = u.[ActualAddressID]
WHERE REPLACE(UseraccountNr, ' ', '') = '%s' AND disabled = 1 %s;",
self::$idColumn, self::$tableName, self::$addressTableName, self::$addressIdColumn, $login, $cond);
$login, $cond);
$results = Connection::execute($sql, $raiseError);
return $results->current() !== false ? new User($results->current()) : null;
@ -145,12 +138,12 @@ class User extends DbMapping
$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)
$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';",
User::$wishTableName, User::$idColumn, $row['WishID'], $this->id, $employee_id, $library_id, $noticeNr);
$row['WishID'], $this->id, $employee_id, $library_id, $noticeNr);
Connection::execute($sql);
return true;
@ -183,10 +176,9 @@ class User extends DbMapping
{
$sql = sprintf("SELECT TOP $limit
NoticeID
FROM %s
WHERE %s = %s
ORDER BY CreationDate DESC"
,User::$wishTableName, User::$idColumn, $this->id);
FROM Wished
WHERE UserAccountID = %s
ORDER BY CreationDate DESC", $this->id);
$result = Connection::execute($sql);
$ids = array_map(function($r) { return $r['NoticeID']; }, $result->to_array());
@ -200,11 +192,11 @@ class User extends DbMapping
public function deleteWish($noticeNr)
{
$sql = sprintf("DELETE w
FROM %s AS w
FROM Wishes AS w
INNER JOIN Notices AS n ON n.NoticeID = w.NoticeID
WHERE
LTRIM(RTRIM(n.NoticeNr)) = '%s'
AND %s = %s;", User::$wishTableName, $noticeNr, User::$idColumn, $this->id);
AND UserAccountID = %s;", $noticeNr, $this->id);
Connection::execute($sql, true);
}
}
Loading…
Cancel
Save