Skip to content

Commit 1d54501

Browse files
DIS-51: refactor: Only load patron dob
Load patron dob when needed rather than storing in the database
1 parent 7c41536 commit 1d54501

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

code/web/Drivers/Koha.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -1229,14 +1229,15 @@ private function loadPatronInfoFromDB($patronId, $password, $suppliedUsernameOrB
12291229
$user->ils_password = $password;
12301230
$user->email = $userFromDb['email'];
12311231
$user->patronType = $userFromDb['categorycode'];
1232-
$user->dateOfBirth = $userFromDb['dateofbirth'];
12331232

12341233
$user->_address1 = trim($userFromDb['streetnumber'] . ' ' . $userFromDb['address']);
12351234
$user->_address2 = $userFromDb['address2'];
12361235
$user->_city = $userFromDb['city'];
12371236
$user->_state = $userFromDb['state'];
12381237
$user->_zip = $userFromDb['zipcode'];
12391238
$user->phone = $userFromDb['phone'];
1239+
$user->_dateOfBirth = $userFromDb['dateofbirth'];
1240+
12401241

12411242
$user->_web_note = $userFromDb['opacnote'];
12421243

@@ -1341,7 +1342,7 @@ private function loadPatronInfoFromDB($patronId, $password, $suppliedUsernameOrB
13411342

13421343
function loadContactInformation(User $user) {
13431344
$this->initDatabaseConnection();
1344-
$sql = "SELECT borrowernumber, cardnumber, surname, firstname, streetnumber, streettype, address, address2, city, state, zipcode, country, email, phone, mobile, categorycode, dateexpiry, password, userid, branchcode, opacnote, privacy from borrowers where borrowernumber = '" . mysqli_escape_string($this->dbConnection, $user->unique_ils_id) . "';";
1345+
$sql = "SELECT borrowernumber, cardnumber, surname, firstname, streetnumber, streettype, address, address2, city, state, zipcode, country, email, phone, mobile, categorycode, dateexpiry, password, userid, branchcode, opacnote, privacy, dateofbirth from borrowers where borrowernumber = '" . mysqli_escape_string($this->dbConnection, $user->unique_ils_id) . "';";
13451346

13461347
$lookupUserResult = mysqli_query($this->dbConnection, $sql, MYSQLI_USE_RESULT);
13471348
if ($lookupUserResult) {
@@ -1358,6 +1359,7 @@ function loadContactInformation(User $user) {
13581359
$user->_state = $userFromDb['state'];
13591360
$user->_zip = $userFromDb['zipcode'];
13601361
$user->phone = $userFromDb['phone'];
1362+
$user->_dateOfBirth = $userFromDb['dateofbirth'];
13611363
}
13621364
}
13631365

code/web/sys/Account/User.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ class User extends DataObject {
5252
public $userCookiePreferenceLocalAnalytics;
5353
public $holdInfoLastLoaded;
5454
public $checkoutInfoLastLoaded;
55-
public $dateOfBirth;
5655

5756
public $onboardAppNotifications;
5857
public $shouldAskBrightness;
@@ -129,6 +128,8 @@ class User extends DataObject {
129128
public $_noticePreferenceLabel;
130129
private $_numMaterialsRequests = 0;
131130
private $_readingHistorySize = 0;
131+
public $_dateOfBirth;
132+
132133

133134
// CarlX Option
134135
public $_emailReceiptFlag;
@@ -3116,15 +3117,13 @@ public function getPTypeObj(): ?PType {
31163117
* @return int|null The user's age or null if date of birth is not set.
31173118
*/
31183119
public function getAge(): ?int {
3119-
if (empty($this->dateOfBirth)) {
3120-
return null;
3121-
}
3122-
3123-
$dob = new DateTime($this->dateOfBirth);
3120+
3121+
$this->loadContactInformation();
3122+
3123+
$dob = new DateTime($this->_dateOfBirth);
31243124
$today = new DateTime();
31253125

31263126
$age = $dob->diff($today)->y;
3127-
31283127
return $age;
31293128
}
31303129

0 commit comments

Comments
 (0)