User: Add pronoun statement

This commit is contained in:
Igor Scheller 2019-12-26 19:07:51 +01:00
parent ec47d124bb
commit e1471248fe
12 changed files with 94 additions and 21 deletions

View File

@ -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,

View File

@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
use Illuminate\Database\Schema\Blueprint;
class UserPersonalDataAddPronounField extends Migration
{
/**
* Run the migration
*/
public function up(): void
{
$this->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');
});
}
}

View File

@ -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();

View File

@ -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) . '&nbsp;h)';

View File

@ -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;

View File

@ -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,

View File

@ -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', '', ''),

View File

@ -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, '');

View File

@ -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);
}

View File

@ -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(
'<span class="icon-icon_angel"></span> '
. (
(config('enable_pronoun') && $user_source->personalData->pronoun)
? '<small>' . htmlspecialchars($user_source->personalData->pronoun) . '</small> '
: ''
)
. htmlspecialchars($user_source->name)
. (config('enable_user_name') ? ' <small>' . $user_name . '</small>' : ''),
[
@ -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

View File

@ -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."

View File

@ -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',