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 // Enables prename and lastname
'enable_user_name' => false, 'enable_user_name' => false,
// Enable displaying the pronoun fields
'enable_pronoun' => false,
// Enables the planned arrival/leave date // Enables the planned arrival/leave date
'enable_planned_arrival' => true, '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 */ /** @var User[] $users */
$users = User::query() $users = User::with(['contact', 'personalData', 'state'])
->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')
->orderBy($order_by) ->orderBy($order_by)
->orderBy('name') ->orderBy('name')
->get(); ->get();

View File

@ -149,7 +149,7 @@ function admin_active()
} }
} }
$query = User::query() $query = User::with('personalData')
->selectRaw( ->selectRaw(
sprintf( sprintf(
' '
@ -211,9 +211,8 @@ function admin_active()
} }
$shirtSize = $usr->personalData->shirt_size; $shirtSize = $usr->personalData->shirt_size;
$userData = []; $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['shirt_size'] = (isset($tshirt_sizes[$shirtSize]) ? $tshirt_sizes[$shirtSize] : '');
$userData['work_time'] = round($usr['shift_length'] / 60) $userData['work_time'] = round($usr['shift_length'] / 60)
. ' min (' . sprintf('%.2f', $usr['shift_length'] / 3600) . '&nbsp;h)'; . ' min (' . sprintf('%.2f', $usr['shift_length'] / 3600) . '&nbsp;h)';

View File

@ -64,7 +64,7 @@ function admin_arrive()
} }
/** @var User[] $users */ /** @var User[] $users */
$users = User::query()->orderBy('name')->get(); $users = User::with('personalData')->orderBy('name')->get();
$arrival_count_at_day = []; $arrival_count_at_day = [];
$planned_arrival_count_at_day = []; $planned_arrival_count_at_day = [];
$planned_departure_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; $plannedDepartureDate = $usr->personalData->planned_departure_date;
$arrivalDate = $usr->state->arrival_date; $arrivalDate = $usr->state->arrival_date;
$plannedArrivalDate = $usr->personalData->planned_arrival_date; $plannedArrivalDate = $usr->personalData->planned_arrival_date;

View File

@ -33,7 +33,7 @@ function admin_free()
} }
$angelType = $request->input('angeltype', ''); $angelType = $request->input('angeltype', '');
$query = User::query() $query = User::with('personalData')
->select('users.*') ->select('users.*')
->leftJoin('ShiftEntry', 'users.id', 'ShiftEntry.UID') ->leftJoin('ShiftEntry', 'users.id', 'ShiftEntry.UID')
->leftJoin('users_state', 'users.id', 'users_state.user_id') ->leftJoin('users_state', 'users.id', 'users_state.user_id')
@ -73,10 +73,10 @@ function admin_free()
foreach ($users as $usr) { foreach ($users as $usr) {
if (count($tokens) > 0) { if (count($tokens) > 0) {
$match = false; $match = false;
$index = join('', $usr->toArray()); $index = join('', $usr->attributesToArray());
foreach ($tokens as $t) { foreach ($tokens as $token) {
$t = trim($t); $token = trim($token);
if (!empty($t) && stristr($index, $t)) { if (!empty($token) && stristr($index, $token)) {
$match = true; $match = true;
break; break;
} }
@ -87,7 +87,7 @@ function admin_free()
} }
$free_users_table[] = [ $free_users_table[] = [
'name' => User_Nick_render($usr), 'name' => User_Nick_render($usr) . User_Pronoun_render($usr),
'shift_state' => User_shift_state_render($usr), 'shift_state' => User_shift_state_render($usr),
'last_shift' => User_last_shift_render($usr), 'last_shift' => User_last_shift_render($usr),
'dect' => $usr->contact->dect, 'dect' => $usr->contact->dect,

View File

@ -48,7 +48,7 @@ function admin_questions()
$user_source = $question->user; $user_source = $question->user;
$unanswered_questions_table[] = [ $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)), 'question' => nl2br(htmlspecialchars($question->text)),
'answer' => form([ 'answer' => form([
form_textarea('answer', '', ''), form_textarea('answer', '', ''),

View File

@ -41,16 +41,18 @@ function user_messages()
if (!$request->has('action')) { if (!$request->has('action')) {
/** @var User[] $users */ /** @var User[] $users */
$users = User::query() $users = User::query()
->whereKeyNot($user->id) ->where('user_id', '!=', $user->id)
->leftJoin('users_personal_data', 'users.id', '=', 'users_personal_data.user_id')
->orderBy('name') ->orderBy('name')
->get(['id', 'name']); ->get(['id', 'name', 'pronoun']);
$to_select_data = [ $to_select_data = [
'' => __('Select recipient...') '' => __('Select recipient...')
]; ];
foreach ($users as $u) { 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, ''); $to_select = html_select_key('to', 'to', $to_select_data, '');

View File

@ -70,6 +70,10 @@ function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes)
} }
// Trivia // Trivia
$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')) { if (config('enable_user_name')) {
$user_source->personalData->last_name = strip_request_item('lastname', $user_source->personalData->last_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); $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; $personalData = $user_source->personalData;
$enable_user_name = config('enable_user_name'); $enable_user_name = config('enable_user_name');
$enable_pronoun = config('enable_pronoun');
$enable_dect = config('enable_dect'); $enable_dect = config('enable_dect');
$enable_planned_arrival = config('enable_planned_arrival'); $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.') __('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('lastname', __('Last name'), $personalData->last_name) : '',
$enable_user_name ? form_text('prename', __('First name'), $personalData->first_name) : '', $enable_user_name ? form_text('prename', __('First name'), $personalData->first_name) : '',
$enable_planned_arrival ? form_date( $enable_planned_arrival ? form_date(
@ -182,7 +187,7 @@ function Users_view(
$usersList = []; $usersList = [];
foreach ($users as $user) { foreach ($users as $user) {
$u = []; $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['first_name'] = $user->personalData->first_name;
$u['last_name'] = $user->personalData->last_name; $u['last_name'] = $user->personalData->last_name;
$u['dect'] = $user->contact->dect; $u['dect'] = $user->contact->dect;
@ -579,6 +584,11 @@ function User_view(
return page_with_title( return page_with_title(
'<span class="icon-icon_angel"></span> ' '<span class="icon-icon_angel"></span> '
. (
(config('enable_pronoun') && $user_source->personalData->pronoun)
? '<small>' . htmlspecialchars($user_source->personalData->pronoun) . '</small> '
: ''
)
. htmlspecialchars($user_source->name) . htmlspecialchars($user_source->name)
. (config('enable_user_name') ? ' <small>' . $user_name . '</small>' : ''), . (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 string $text
* @param int $user_id * @param int $user_id

View File

@ -2511,6 +2511,12 @@ msgstr "Arbeitseinsatz bearbeiten"
msgid "Add work log entry" msgid "Add work log entry"
msgstr "Arbeitseinsatz hinzufügen" 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 #: includes/view/User_view.php:37
msgid "Here you can change your user details." msgid "Here you can change your user details."
msgstr "Hier kannst Du Deine Details ändern." 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 $first_name
* @property string|null $last_name * @property string|null $last_name
* @property string|null $pronoun
* @property string|null $shirt_size * @property string|null $shirt_size
* @property Carbon|null $planned_arrival_date * @property Carbon|null $planned_arrival_date
* @property Carbon|null $planned_departure_date * @property Carbon|null $planned_departure_date
* *
* @method static QueryBuilder|PersonalData[] whereFirstName($value) * @method static QueryBuilder|PersonalData[] whereFirstName($value)
* @method static QueryBuilder|PersonalData[] whereLastName($value) * @method static QueryBuilder|PersonalData[] whereLastName($value)
* @method static QueryBuilder|PersonalData[] wherePronoun($value)
* @method static QueryBuilder|PersonalData[] whereShirtSize($value) * @method static QueryBuilder|PersonalData[] whereShirtSize($value)
* @method static QueryBuilder|PersonalData[] wherePlannedArrivalDate($value) * @method static QueryBuilder|PersonalData[] wherePlannedArrivalDate($value)
* @method static QueryBuilder|PersonalData[] wherePlannedDepartureDate($value) * @method static QueryBuilder|PersonalData[] wherePlannedDepartureDate($value)
@ -34,6 +36,7 @@ class PersonalData extends HasUserModel
'user_id', 'user_id',
'first_name', 'first_name',
'last_name', 'last_name',
'pronoun',
'shirt_size', 'shirt_size',
'planned_arrival_date', 'planned_arrival_date',
'planned_departure_date', 'planned_departure_date',