diff --git a/config/config.default.php b/config/config.default.php
index 2a988788..9b93eb25 100644
--- a/config/config.default.php
+++ b/config/config.default.php
@@ -114,6 +114,9 @@ return [
// Enables prename and lastname
'enable_user_name' => false,
+ // Enable displaying the pronoun fields
+ 'enable_pronoun' => false,
+
// Enables the planned arrival/leave date
'enable_planned_arrival' => true,
diff --git a/db/migrations/2019_12_03_000000_user_personal_data_add_pronoun_field.php b/db/migrations/2019_12_03_000000_user_personal_data_add_pronoun_field.php
new file mode 100644
index 00000000..3109c888
--- /dev/null
+++ b/db/migrations/2019_12_03_000000_user_personal_data_add_pronoun_field.php
@@ -0,0 +1,34 @@
+schema->table('users_personal_data', function (Blueprint $table) {
+ $table->string('pronoun', 15)
+ ->nullable()
+ ->default(null)
+ ->after('last_name');
+ });
+ }
+
+ /**
+ * Reverse the migration
+ */
+ public function down(): void
+ {
+ $this->schema->table('users_personal_data', function (Blueprint $table) {
+ $table->dropColumn('pronoun');
+ });
+ }
+}
diff --git a/includes/controller/users_controller.php b/includes/controller/users_controller.php
index da8a9339..403b3f96 100644
--- a/includes/controller/users_controller.php
+++ b/includes/controller/users_controller.php
@@ -284,10 +284,7 @@ function users_list_controller()
}
/** @var User[] $users */
- $users = User::query()
- ->leftJoin('users_contact', 'users.id', '=', 'users_contact.user_id')
- ->leftJoin('users_personal_data', 'users.id', '=', 'users_personal_data.user_id')
- ->leftJoin('users_state', 'users.id', '=', 'users_state.user_id')
+ $users = User::with(['contact', 'personalData', 'state'])
->orderBy($order_by)
->orderBy('name')
->get();
diff --git a/includes/pages/admin_active.php b/includes/pages/admin_active.php
index 71d6914a..d82b8fa9 100644
--- a/includes/pages/admin_active.php
+++ b/includes/pages/admin_active.php
@@ -149,7 +149,7 @@ function admin_active()
}
}
- $query = User::query()
+ $query = User::with('personalData')
->selectRaw(
sprintf(
'
@@ -211,9 +211,8 @@ function admin_active()
}
$shirtSize = $usr->personalData->shirt_size;
-
$userData = [];
- $userData['nick'] = User_Nick_render($usr);
+ $userData['nick'] = User_Nick_render($usr) . User_Pronoun_render($usr);
$userData['shirt_size'] = (isset($tshirt_sizes[$shirtSize]) ? $tshirt_sizes[$shirtSize] : '');
$userData['work_time'] = round($usr['shift_length'] / 60)
. ' min (' . sprintf('%.2f', $usr['shift_length'] / 3600) . ' h)';
diff --git a/includes/pages/admin_arrive.php b/includes/pages/admin_arrive.php
index 312fd6dc..d6d7ad48 100644
--- a/includes/pages/admin_arrive.php
+++ b/includes/pages/admin_arrive.php
@@ -64,7 +64,7 @@ function admin_arrive()
}
/** @var User[] $users */
- $users = User::query()->orderBy('name')->get();
+ $users = User::with('personalData')->orderBy('name')->get();
$arrival_count_at_day = [];
$planned_arrival_count_at_day = [];
$planned_departure_count_at_day = [];
@@ -91,7 +91,7 @@ function admin_arrive()
}
}
- $usr->name = User_Nick_render($usr);
+ $usr->name = User_Nick_render($usr) . User_Pronoun_render($usr);
$plannedDepartureDate = $usr->personalData->planned_departure_date;
$arrivalDate = $usr->state->arrival_date;
$plannedArrivalDate = $usr->personalData->planned_arrival_date;
diff --git a/includes/pages/admin_free.php b/includes/pages/admin_free.php
index fa4508c5..709954a0 100644
--- a/includes/pages/admin_free.php
+++ b/includes/pages/admin_free.php
@@ -33,7 +33,7 @@ function admin_free()
}
$angelType = $request->input('angeltype', '');
- $query = User::query()
+ $query = User::with('personalData')
->select('users.*')
->leftJoin('ShiftEntry', 'users.id', 'ShiftEntry.UID')
->leftJoin('users_state', 'users.id', 'users_state.user_id')
@@ -73,10 +73,10 @@ function admin_free()
foreach ($users as $usr) {
if (count($tokens) > 0) {
$match = false;
- $index = join('', $usr->toArray());
- foreach ($tokens as $t) {
- $t = trim($t);
- if (!empty($t) && stristr($index, $t)) {
+ $index = join('', $usr->attributesToArray());
+ foreach ($tokens as $token) {
+ $token = trim($token);
+ if (!empty($token) && stristr($index, $token)) {
$match = true;
break;
}
@@ -87,7 +87,7 @@ function admin_free()
}
$free_users_table[] = [
- 'name' => User_Nick_render($usr),
+ 'name' => User_Nick_render($usr) . User_Pronoun_render($usr),
'shift_state' => User_shift_state_render($usr),
'last_shift' => User_last_shift_render($usr),
'dect' => $usr->contact->dect,
diff --git a/includes/pages/admin_questions.php b/includes/pages/admin_questions.php
index 8a63f8db..24a818a8 100644
--- a/includes/pages/admin_questions.php
+++ b/includes/pages/admin_questions.php
@@ -48,7 +48,7 @@ function admin_questions()
$user_source = $question->user;
$unanswered_questions_table[] = [
- 'from' => User_Nick_render($user_source),
+ 'from' => User_Nick_render($user_source) . User_Pronoun_render($user_source),
'question' => nl2br(htmlspecialchars($question->text)),
'answer' => form([
form_textarea('answer', '', ''),
diff --git a/includes/pages/user_messages.php b/includes/pages/user_messages.php
index 72bb9ae2..5ec6fdfb 100644
--- a/includes/pages/user_messages.php
+++ b/includes/pages/user_messages.php
@@ -41,16 +41,18 @@ function user_messages()
if (!$request->has('action')) {
/** @var User[] $users */
$users = User::query()
- ->whereKeyNot($user->id)
+ ->where('user_id', '!=', $user->id)
+ ->leftJoin('users_personal_data', 'users.id', '=', 'users_personal_data.user_id')
->orderBy('name')
- ->get(['id', 'name']);
+ ->get(['id', 'name', 'pronoun']);
$to_select_data = [
'' => __('Select recipient...')
];
foreach ($users as $u) {
- $to_select_data[$u->id] = $u->name;
+ $pronoun = ((config('enable_pronoun') && $u->pronoun) ? ' (' . htmlspecialchars($u->pronoun) . ')' : '');
+ $to_select_data[$u->id] = $u->name . $pronoun;
}
$to_select = html_select_key('to', 'to', $to_select_data, '');
diff --git a/includes/pages/user_settings.php b/includes/pages/user_settings.php
index 5646b27f..46aea33d 100644
--- a/includes/pages/user_settings.php
+++ b/includes/pages/user_settings.php
@@ -70,7 +70,11 @@ function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes)
}
// Trivia
- if(config('enable_user_name')) {
+ $pronoun = strip_request_item('pronoun', $user_source->personalData->pronoun);
+ if (config('enable_pronoun') && mb_strlen($pronoun) <= 15) {
+ $user_source->personalData->pronoun = $pronoun;
+ }
+ if (config('enable_user_name')) {
$user_source->personalData->last_name = strip_request_item('lastname', $user_source->personalData->last_name);
$user_source->personalData->first_name = strip_request_item('prename', $user_source->personalData->first_name);
}
diff --git a/includes/view/User_view.php b/includes/view/User_view.php
index 95ecb626..ec1c7434 100644
--- a/includes/view/User_view.php
+++ b/includes/view/User_view.php
@@ -26,6 +26,7 @@ function User_settings_view(
) {
$personalData = $user_source->personalData;
$enable_user_name = config('enable_user_name');
+ $enable_pronoun = config('enable_pronoun');
$enable_dect = config('enable_dect');
$enable_planned_arrival = config('enable_planned_arrival');
@@ -41,6 +42,10 @@ function User_settings_view(
'',
__('Use up to 23 letters, numbers, connecting punctuations or spaces for your nickname.')
),
+ $enable_pronoun
+ ? form_text('pronoun', __('Pronoun'), $personalData->pronoun, false, 15)
+ . form_info('', __('Will be shown on your profile page and in angel lists.'))
+ : '',
$enable_user_name ? form_text('lastname', __('Last name'), $personalData->last_name) : '',
$enable_user_name ? form_text('prename', __('First name'), $personalData->first_name) : '',
$enable_planned_arrival ? form_date(
@@ -182,7 +187,7 @@ function Users_view(
$usersList = [];
foreach ($users as $user) {
$u = [];
- $u['name'] = User_Nick_render($user);
+ $u['name'] = User_Nick_render($user) . User_Pronoun_render($user);
$u['first_name'] = $user->personalData->first_name;
$u['last_name'] = $user->personalData->last_name;
$u['dect'] = $user->contact->dect;
@@ -579,6 +584,11 @@ function User_view(
return page_with_title(
' '
+ . (
+ (config('enable_pronoun') && $user_source->personalData->pronoun)
+ ? '' . htmlspecialchars($user_source->personalData->pronoun) . ' '
+ : ''
+ )
. htmlspecialchars($user_source->name)
. (config('enable_user_name') ? ' ' . $user_name . '' : ''),
[
@@ -823,6 +833,21 @@ function User_Nick_render($user, $plain = false)
);
}
+/**
+ * Format the user pronoun
+ *
+ * @param User $user
+ * @return string
+ */
+function User_Pronoun_render(User $user): string
+{
+ if (!config('enable_pronoun') || !$user->personalData->pronoun) {
+ return '';
+ }
+
+ return ' (' . htmlspecialchars($user->personalData->pronoun) . ')';
+}
+
/**
* @param string $text
* @param int $user_id
diff --git a/resources/lang/de_DE/default.po b/resources/lang/de_DE/default.po
index 9542fa19..70160f01 100644
--- a/resources/lang/de_DE/default.po
+++ b/resources/lang/de_DE/default.po
@@ -2511,6 +2511,12 @@ msgstr "Arbeitseinsatz bearbeiten"
msgid "Add work log entry"
msgstr "Arbeitseinsatz hinzufügen"
+msgid "Pronoun"
+msgstr "Pronomen"
+
+msgid "Will be shown on your profile page and in angel lists."
+msgstr "Wird auf deiner Profilseite und in Engellisten angezeigt."
+
#: includes/view/User_view.php:37
msgid "Here you can change your user details."
msgstr "Hier kannst Du Deine Details ändern."
diff --git a/src/Models/User/PersonalData.php b/src/Models/User/PersonalData.php
index 228f55f3..445a2ceb 100644
--- a/src/Models/User/PersonalData.php
+++ b/src/Models/User/PersonalData.php
@@ -8,12 +8,14 @@ use Illuminate\Database\Query\Builder as QueryBuilder;
/**
* @property string|null $first_name
* @property string|null $last_name
+ * @property string|null $pronoun
* @property string|null $shirt_size
* @property Carbon|null $planned_arrival_date
* @property Carbon|null $planned_departure_date
*
* @method static QueryBuilder|PersonalData[] whereFirstName($value)
* @method static QueryBuilder|PersonalData[] whereLastName($value)
+ * @method static QueryBuilder|PersonalData[] wherePronoun($value)
* @method static QueryBuilder|PersonalData[] whereShirtSize($value)
* @method static QueryBuilder|PersonalData[] wherePlannedArrivalDate($value)
* @method static QueryBuilder|PersonalData[] wherePlannedDepartureDate($value)
@@ -34,6 +36,7 @@ class PersonalData extends HasUserModel
'user_id',
'first_name',
'last_name',
+ 'pronoun',
'shirt_size',
'planned_arrival_date',
'planned_departure_date',