From b587047d17b96d075642794b3949b38745b4b0bf Mon Sep 17 00:00:00 2001 From: Gilles Crettenand Date: Tue, 2 Jun 2015 23:06:02 +0200 Subject: [PATCH] stop using const for table and column names --- Lib/db/User.php | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/Lib/db/User.php b/Lib/db/User.php index 487e3ef..2ba6a38 100644 --- a/Lib/db/User.php +++ b/Lib/db/User.php @@ -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); } } \ No newline at end of file