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