Skip to content

Commit

Permalink
Renamed surname to last_name [SLE-192]
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelgfeller committed May 8, 2024
1 parent 90c7de1 commit cdf5711
Show file tree
Hide file tree
Showing 29 changed files with 72 additions and 72 deletions.
2 changes: 1 addition & 1 deletion public/assets/user/create/user-create-modal.html.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function displayUserCreateModal() {
</div>
<div class="form-input-div">
<label for="last-name-input">${translated['Last name']}</label>
<input type="text" name="surname" id="last-name-input" placeholder="Zimmer" class="form-input"
<input type="text" name="last_name" id="last-name-input" placeholder="Zimmer" class="form-input"
minlength="2" maxlength="100" required>
</div>
<div class="form-input-div">
Expand Down
2 changes: 1 addition & 1 deletion public/assets/user/list/user-list-card.html.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {html} from "../../general/general-js/functions.js?v=0.4.1";
export function getUserCardHtml(user, statuses) {
return `<div class="user-card" tabindex="0" data-user-id="${user.id}">
<div class="card-content">
<h3>${user.firstName !== null ? html(user.firstName) : ''} ${user.surname !== null ? html(user.surname) : ''}</h3>
<h3>${user.firstName !== null ? html(user.firstName) : ''} ${user.lastName !== null ? html(user.lastName) : ''}</h3>
<div class="card-icon-and-span-div">
<img src="assets/general/general-img/personal-data-icons/email-icon.svg" class="card-icon default-icon" alt="email">
<a href="mailto:${html(user.email)}">${html(user.email)}</a>
Expand Down
2 changes: 1 addition & 1 deletion public/assets/user/read/user-read-update-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ loadUserActivities(`user=${userId}`);
document.querySelector('#edit-first-name-btn')?.addEventListener('click', makeUserFieldEditable);
document.querySelector('h1[data-name="first_name"]')?.addEventListener('dblclick', makeUserFieldEditable);
document.querySelector('#edit-last-name-btn')?.addEventListener('click', makeUserFieldEditable);
document.querySelector('h1[data-name="surname"]')?.addEventListener('dblclick', makeUserFieldEditable);
document.querySelector('h1[data-name="last_name"]')?.addEventListener('dblclick', makeUserFieldEditable);
document.querySelector('#edit-email-btn')?.addEventListener('click', makeUserFieldEditable);
document.querySelector('[data-name="email"]')?.addEventListener('dblclick', makeUserFieldEditable);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ public function change()
'encoding' => 'utf8mb4',
'after' => 'id',
])
->addColumn('surname', 'string', [
->addColumn('last_name', 'string', [
'null' => true,
'default' => null,
'limit' => 100,
Expand All @@ -434,7 +434,7 @@ public function change()
'null' => false,
'default' => '0',
'limit' => MysqlAdapter::INT_REGULAR,
'after' => 'surname',
'after' => 'last_name',
])
->addColumn('status', 'enum', [
'null' => true,
Expand Down
4 changes: 2 additions & 2 deletions resources/schema/schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -1751,11 +1751,11 @@
'IS_GENERATED' => 'NEVER',
'GENERATION_EXPRESSION' => NULL,
),
'surname' =>
'last_name' =>
array (
'TABLE_CATALOG' => 'def',
'TABLE_NAME' => 'user',
'COLUMN_NAME' => 'surname',
'COLUMN_NAME' => 'last_name',
'ORDINAL_POSITION' => 3,
'COLUMN_DEFAULT' => 'NULL',
'IS_NULLABLE' => 'YES',
Expand Down
20 changes: 10 additions & 10 deletions resources/schema/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ CREATE TABLE `authentication_log` (
`created_at` datetime DEFAULT current_timestamp(),
PRIMARY KEY (`id`),
KEY `authentication_log_user_id_fk` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC;

CREATE TABLE `client` (
`id` int(11) NOT NULL AUTO_INCREMENT,
Expand All @@ -29,14 +29,14 @@ CREATE TABLE `client` (
PRIMARY KEY (`id`),
KEY `FK_client_user` (`user_id`),
KEY `FK_client_status` (`client_status_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='Advisors help and consult clients';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='Advisors help and consult clients';

CREATE TABLE `client_status` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL DEFAULT '0',
`deleted_at` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='Client status';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='Client status';

CREATE TABLE `email_log` (
`id` int(11) NOT NULL AUTO_INCREMENT,
Expand All @@ -48,7 +48,7 @@ CREATE TABLE `email_log` (
`created_at` datetime DEFAULT current_timestamp(),
PRIMARY KEY (`id`),
KEY `email_log_user_id_fk` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC;

CREATE TABLE `note` (
`id` int(11) NOT NULL AUTO_INCREMENT,
Expand All @@ -63,7 +63,7 @@ CREATE TABLE `note` (
PRIMARY KEY (`id`),
KEY `FK__user` (`user_id`),
KEY `FK_note_client` (`client_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci ROW_FORMAT=DYNAMIC;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci ROW_FORMAT=DYNAMIC;

CREATE TABLE `phinx_migration_log` (
`version` bigint(20) NOT NULL,
Expand All @@ -77,7 +77,7 @@ CREATE TABLE `phinx_migration_log` (
CREATE TABLE `user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`first_name` varchar(100) DEFAULT NULL,
`surname` varchar(100) DEFAULT NULL,
`last_name` varchar(100) DEFAULT NULL,
`user_role_id` int(11) NOT NULL DEFAULT 0,
`status` enum('active','locked','unverified','suspended') DEFAULT 'unverified',
`email` varchar(254) NOT NULL,
Expand All @@ -89,7 +89,7 @@ CREATE TABLE `user` (
`deleted_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FK_user_user_role` (`user_role_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;

CREATE TABLE `user_activity` (
`id` int(11) NOT NULL AUTO_INCREMENT,
Expand All @@ -103,7 +103,7 @@ CREATE TABLE `user_activity` (
`user_agent` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `user_activity_user_id_fk` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;

CREATE TABLE `user_filter_setting` (
`user_id` int(11) NOT NULL,
Expand All @@ -117,7 +117,7 @@ CREATE TABLE `user_role` (
`name` varchar(30) NOT NULL,
`hierarchy` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC;

CREATE TABLE `user_verification` (
`id` int(11) NOT NULL AUTO_INCREMENT,
Expand All @@ -129,4 +129,4 @@ CREATE TABLE `user_verification` (
`deleted_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FK__user_table` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;
2 changes: 1 addition & 1 deletion resources/seeds/AdminUserSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function run(): void
$userRows = [
[
'first_name' => 'Admin',
'surname' => 'Admin',
'last_name' => 'Admin',
'user_role_id' => 1,
'status' => 'active',
'email' => '[email protected]',
Expand Down
6 changes: 3 additions & 3 deletions resources/seeds/UserSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function run(): void
[
'id' => 2,
'first_name' => 'Managing-advisor',
'surname' => 'Surname',
'last_name' => 'Last name',
'user_role_id' => 2,
'status' => 'active',
'language' => 'en_US',
Expand All @@ -44,7 +44,7 @@ public function run(): void
[
'id' => 3,
'first_name' => 'Advisor',
'surname' => 'Surname',
'last_name' => 'Surname',
'user_role_id' => 3,
'status' => 'active',
'language' => 'de_CH',
Expand All @@ -54,7 +54,7 @@ public function run(): void
[
'id' => 4,
'first_name' => 'Newcomer',
'surname' => 'Surname',
'last_name' => 'Surname',
'user_role_id' => 4,
'status' => 'active',
'language' => 'fr_CH',
Expand Down
4 changes: 2 additions & 2 deletions src/Domain/Client/Repository/ClientFinderRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function findClientsWithResultAggregate(array $whereArray = ['client.dele
'deleted_at' => 'client.deleted_at',
// User data prefixed with user_
'user_first_name' => 'user.first_name',
'user_surname' => 'user.surname',
'user_last_name' => 'user.last_name',
// Client status data prefixed with client_status_
'client_status_name' => 'client_status.name',
])// Multiple joins doc: https://book.cakephp.org/4/en/orm/query-builder.html#adding-joins
Expand Down Expand Up @@ -116,7 +116,7 @@ public function findClientAggregateByIdIncludingDeleted(int $id): ClientReadResu
'deleted_at' => 'client.deleted_at',
// User data prefixed with user_
'user_first_name' => 'user.first_name',
'user_surname' => 'user.surname',
'user_last_name' => 'user.last_name',
// Client status data prefixed with client_status_
'client_status_name' => 'client_status.name',
// Main note data loaded in page renderer prefixed with `note_`
Expand Down
6 changes: 3 additions & 3 deletions src/Domain/Note/Repository/NoteFinderRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function findAllNotesExceptMainByUserId(int $userId): array
{
$query = $this->queryFactory->selectQuery()->from('note');

$concatName = $query->func()->concat(['user.first_name' => 'identifier', ' ', 'user.surname' => 'identifier']);
$concatName = $query->func()->concat(['user.first_name' => 'identifier', ' ', 'user.last_name' => 'identifier']);

$query->select(array_merge($this->noteResultFields, ['user_full_name' => $concatName]))
->join(['table' => 'user', 'conditions' => 'note.user_id = user.id'])
Expand Down Expand Up @@ -87,7 +87,7 @@ public function findAllNotesExceptMainWithUserByClientId(int $clientId): array
$concatName = $query->func()->concat([
$query->func()->coalesce(['user.first_name' => 'identifier', '']),
' ',
$query->func()->coalesce(['user.surname' => 'identifier', '']),
$query->func()->coalesce(['user.last_name' => 'identifier', '']),
]);

$query->select(array_merge($this->noteResultFields, ['user_full_name' => $concatName]))
Expand Down Expand Up @@ -123,7 +123,7 @@ public function findMostRecentNotes(int $notesAmount): array

$concatUserName = $query->func()->concat(
// Not very sexy to put IFNULL function there but with "identifier", cake interprets the string literally
['IFNULL(user.first_name, "")' => 'identifier', ' ', 'IFNULL(user.surname, "")' => 'identifier']
['IFNULL(user.first_name, "")' => 'identifier', ' ', 'IFNULL(user.last_name, "")' => 'identifier']
);
$concatClientName = $query->func()->concat(
['IFNULL(client.first_name, "")' => 'identifier', ' ', 'IFNULL(client.last_name, "")' => 'identifier']
Expand Down
2 changes: 1 addition & 1 deletion src/Domain/Note/Service/NoteCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function createNote(array $noteValues): array

return [
'note_id' => $noteId,
'user_full_name' => $user->firstName . ' ' . $user->surname,
'user_full_name' => $user->firstName . ' ' . $user->lastName,
'formatted_creation_timestamp' => $dateFormatter->format($noteCreatedAtTimestamp),
];
}
Expand Down
12 changes: 6 additions & 6 deletions src/Domain/User/Data/UserData.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class UserData implements \JsonSerializable
// Variable names matching database columns (camelCase instead of snake_case)
public ?int $id; // Mysql always returns string from db https://stackoverflow.com/a/5323169/9013718
public ?string $firstName;
public ?string $surname;
public ?string $lastName;
// Email has to be default null as it is an indicator that user obj is empty in AuthService register function
public ?string $email;
public ?string $password;
Expand All @@ -30,7 +30,7 @@ public function __construct(array $userData = [])
// Keys may be taken from view form or database, so they have to correspond to both; otherwise use mapper
$this->id = $userData['id'] ?? null;
$this->firstName = $userData['first_name'] ?? null;
$this->surname = $userData['surname'] ?? null;
$this->lastName = $userData['last_name'] ?? null;
$this->email = $userData['email'] ?? null;
$this->password = $userData['password'] ?? null;
$this->password2 = $userData['password2'] ?? null;
Expand All @@ -47,13 +47,13 @@ public function __construct(array $userData = [])
}

/**
* Returns the first and surname in one string separated by a whitespace.
* Returns the first and lastName in one string separated by a whitespace.
*
* @return string
*/
public function getFullName(): string
{
return $this->firstName . ' ' . $this->surname;
return $this->firstName . ' ' . $this->lastName;
}

/**
Expand All @@ -68,7 +68,7 @@ public function toArrayForDatabase(): array
return [
'id' => $this->id,
'first_name' => $this->firstName,
'surname' => $this->surname,
'last_name' => $this->lastName,
'email' => $this->email,
'password_hash' => $this->passwordHash,
'user_role_id' => $this->userRoleId,
Expand All @@ -83,7 +83,7 @@ public function jsonSerialize(): array
return [
'id' => $this->id,
'firstName' => $this->firstName,
'surname' => $this->surname,
'lastName' => $this->lastName,
'email' => $this->email,
'status' => $this->status,
'userRoleId' => $this->userRoleId,
Expand Down
2 changes: 1 addition & 1 deletion src/Domain/User/Repository/UserFinderRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class UserFinderRepository
private array $fields = [
'id',
'first_name',
'surname',
'last_name',
'email',
'user_role_id',
'status',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public function isGrantedToUpdate(array $userDataToUpdate, string|int $userIdToU
// Personal info are values such as first name, last name and email
$grantedUpdateKeys[] = 'personal_info';
$grantedUpdateKeys[] = 'first_name';
$grantedUpdateKeys[] = 'surname';
$grantedUpdateKeys[] = 'last_name';
$grantedUpdateKeys[] = 'email';
$grantedUpdateKeys[] = 'password_hash';
$grantedUpdateKeys[] = 'theme';
Expand Down
6 changes: 3 additions & 3 deletions src/Domain/User/Service/UserNameAbbreviator.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private function buildLastNameAbbreviation(string $lastName, array $usersToCheck
): string {
// When $i (amount of letters) of last name to abbreviate is the same as the full name,
// there is no short form and the function must end as it would cause infinite recursion.
// Checks if short form ($i letters from the beginning of surname) is contained in name to check
// Checks if short form ($i letters from the beginning of lastName) is contained in name to check
if (strlen($lastName) > $i && str_contains($lastNameToCheck, substr($lastName, 0, $i))) {
// Increase number of letters that should be used of the last name as it exists in the name to check
$i++;
Expand All @@ -41,7 +41,7 @@ private function buildLastNameAbbreviation(string $lastName, array $usersToCheck
return $shortName;
};
// Always privilege longest lastname abbreviation as it means that this length necessary
if (strlen($builtLastName = $buildLastName($lastName, (string)$userToCheck->surname)) > strlen(
if (strlen($builtLastName = $buildLastName($lastName, (string)$userToCheck->lastName)) > strlen(
$abbreviatedLastName
)) {
$abbreviatedLastName = $builtLastName;
Expand Down Expand Up @@ -94,7 +94,7 @@ public function abbreviateUserNames(array $users): array
unset($usersToCheckAgainst[$userId]);
// Call recursive function which compares last name of currently iterated user with other users with same
// first name and returns the shortest version of non-duplicate lastname
$lastNameAbbr = $this->buildLastNameAbbreviation((string)$user->surname, $usersToCheckAgainst);
$lastNameAbbr = $this->buildLastNameAbbreviation((string)$user->lastName, $usersToCheckAgainst);
$outputNames[(int)$userId] = $user->firstName . ' ' . $lastNameAbbr;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Domain/User/Service/UserUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function updateUser(int $userIdToChange, array $userValues): bool
// Check that keys are one of the database columns that may be updated
if (in_array($column, [
'first_name',
'surname',
'last_name',
'email',
'status',
'user_role_id',
Expand Down
10 changes: 5 additions & 5 deletions src/Domain/User/Service/UserValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ public function validateUserValues(array $userValues, bool $isCreateMode = true)

// For the user, there are no optional fields meaning that if any field is passed, it has to contain a value.
$validator
// First name and surname are required to have values if they're given so no allowEmptyString
// First name and lastName are required to have values if they're given so no allowEmptyString
->requirePresence('first_name', $isCreateMode, __('Field is required'))
->minLength('first_name', 2, __('Minimum length is %d', 2))
->maxLength('first_name', 100, __('Maximum length is %d', 100))
// Disallow empty strings as field is required
->notEmptyString('first_name', __('Required'))
->requirePresence('surname', $isCreateMode, __('Field is required'))
->minLength('surname', 2, __('Minimum length is %d', 2))
->maxLength('surname', 100, __('Maximum length is %d', 100))
->notEmptyString('surname', __('Required'))
->requirePresence('last_name', $isCreateMode, __('Field is required'))
->minLength('last_name', 2, __('Minimum length is %d', 2))
->maxLength('last_name', 100, __('Maximum length is %d', 100))
->notEmptyString('last_name', __('Required'))
->requirePresence('email', $isCreateMode, __('Field is required'))
// email() automatically disallows empty strings
->email('email', false, __('Invalid email'))
Expand Down
2 changes: 1 addition & 1 deletion src/Domain/UserActivity/Service/UserActivityFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private function findUserActivitiesGroupedByDate(int|string|array $userIds): arr
if (count($userIds) > 1) {
$userRow = $this->userFinderRepository->findUserById((int)$userActivity->userId);
$userActivity->timeAndActionName = '<span style="color: var(--black-white-text-color)">' . $userRow['first_name'] . ' '
. $userRow['surname'] . '</span> • ' .
. $userRow['last_name'] . '</span> • ' .
$userActivity->timeAndActionName;
}
$formattedDate = ucfirst(
Expand Down
4 changes: 2 additions & 2 deletions templates/user/user-read.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ class="contenteditable-edit-icon cursor-pointer"
id="edit-last-name-btn">
<?php
} ?>
<h1 data-name="surname" data-minlength="2" data-maxlength="100" spellcheck="false"><?=
!empty($user->surname) ? html($user->surname) : '&nbsp;' ?></h1>
<h1 data-name="last_name" data-minlength="2" data-maxlength="100" spellcheck="false"><?=
!empty($user->lastName) ? html($user->lastName) : '&nbsp;' ?></h1>
</div>
</div>

Expand Down
Loading

0 comments on commit cdf5711

Please sign in to comment.