summaryrefslogtreecommitdiff
path: root/includes/pages
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2018-10-11 01:26:34 +0200
committermsquare <msquare@notrademark.de>2018-10-31 13:43:23 +0100
commit4e09ee3eb255160c88a378375d69123a3e000497 (patch)
treee4a03ff40c939473cc1278f8286675cfa31e4556 /includes/pages
parent7c6afc2bfe3263b91ecabf5530da57fe1162ea0b (diff)
Replaced more user related stuff
(Contains some buggy stuff too...)
Diffstat (limited to 'includes/pages')
-rw-r--r--includes/pages/admin_active.php116
-rw-r--r--includes/pages/admin_arrive.php58
-rw-r--r--includes/pages/admin_free.php42
-rw-r--r--includes/pages/guest_login.php2
-rw-r--r--includes/pages/user_atom.php6
-rw-r--r--includes/pages/user_ical.php9
-rw-r--r--includes/pages/user_messages.php11
-rw-r--r--includes/pages/user_settings.php91
8 files changed, 155 insertions, 180 deletions
diff --git a/includes/pages/admin_active.php b/includes/pages/admin_active.php
index 33c7459d..8d9f35bd 100644
--- a/includes/pages/admin_active.php
+++ b/includes/pages/admin_active.php
@@ -1,6 +1,6 @@
<?php
-use Engelsystem\Database\DB;
+use Engelsystem\Models\User\State;
use Engelsystem\Models\User\User;
/**
@@ -22,7 +22,7 @@ function admin_active()
$msg = '';
$search = '';
- $forced_count = count(DB::select('SELECT `UID` FROM `User` WHERE `force_active`=1'));
+ $forced_count = State::whereForceActive(true)->count();
$count = $forced_count;
$limit = '';
$set_active = '';
@@ -54,21 +54,26 @@ function admin_active()
$limit = ' LIMIT ' . $count;
}
if ($request->has('ack')) {
- DB::update('UPDATE `User` SET `Aktiv` = 0 WHERE `Tshirt` = 0');
- $users = DB::select(sprintf('
+ State::query()
+ ->where('got_shirt', '=', false)
+ ->update(['active' => false]);
+
+ /** @var User[] $users */
+ $users = User::query()->raw(sprintf('
SELECT
- `User`.*,
+ `users`.*,
COUNT(`ShiftEntry`.`id`) AS `shift_count`,
(%s + (
- SELECT COALESCE(SUM(`work_hours`) * 3600, 0) FROM `UserWorkLog` WHERE `user_id`=`User`.`UID`
+ SELECT COALESCE(SUM(`work_hours`) * 3600, 0) FROM `UserWorkLog` WHERE `user_id`=`users`.`id`
AND `work_timestamp` < %s
)) AS `shift_length`
- FROM `User`
- LEFT JOIN `ShiftEntry` ON `User`.`UID` = `ShiftEntry`.`UID`
+ FROM `users`
+ LEFT JOIN `ShiftEntry` ON `users`.`id` = `ShiftEntry`.`UID`
LEFT JOIN `Shifts` ON `ShiftEntry`.`SID` = `Shifts`.`SID`
- WHERE `User`.`Gekommen` = 1
- AND `User`.`force_active`=0
- GROUP BY `User`.`UID`
+ LEFT JOIN `users_state` ON `users`.`id` = `users_state`.`user_id`
+ WHERE `users_state`.`arrived` = 1
+ AND `users_state`.`force_active` = 0
+ GROUP BY `users`.`id`
ORDER BY `force_active` DESC, `shift_length` DESC
%s
',
@@ -78,10 +83,12 @@ function admin_active()
));
$user_nicks = [];
foreach ($users as $usr) {
- DB::update('UPDATE `User` SET `Aktiv` = 1 WHERE `UID`=?', [$usr['UID']]);
+ $usr->state->active = true;
+ $usr->state->save();
$user_nicks[] = User_Nick_render($usr);
}
- DB::update('UPDATE `User` SET `Aktiv`=1 WHERE `force_active`=TRUE');
+
+ State::whereForceActive(true)->update(['active' => 'true']);
engelsystem_log('These angels are active now: ' . join(', ', $user_nicks));
$limit = '';
@@ -103,7 +110,8 @@ function admin_active()
$user_id = $request->input('active');
$user_source = User::find($user_id);
if ($user_source) {
- DB::update('UPDATE `User` SET `Aktiv`=1 WHERE `UID`=? LIMIT 1', [$user_id]);
+ $user_source->state->active = true;
+ $user_source->state->save();
engelsystem_log('User ' . User_Nick_render($user_source) . ' is active now.');
$msg = success(__('Angel has been marked as active.'), true);
} else {
@@ -113,7 +121,8 @@ function admin_active()
$user_id = $request->input('not_active');
$user_source = User::find($user_id);
if (!$user_source) {
- DB::update('UPDATE `User` SET `Aktiv`=0 WHERE `UID`=? LIMIT 1', [$user_id]);
+ $user_source->state->active = false;
+ $user_source->state->save();
engelsystem_log('User ' . User_Nick_render($user_source) . ' is NOT active now.');
$msg = success(__('Angel has been marked as not active.'), true);
} else {
@@ -123,7 +132,8 @@ function admin_active()
$user_id = $request->input('tshirt');
$user_source = User::find($user_id);
if (!$user_source) {
- DB::update('UPDATE `User` SET `Tshirt`=1 WHERE `UID`=? LIMIT 1', [$user_id]);
+ $user_source->state->got_shirt = true;
+ $user_source->state->save();
engelsystem_log('User ' . User_Nick_render($user_source) . ' has tshirt now.');
$msg = success(__('Angel has got a t-shirt.'), true);
} else {
@@ -133,7 +143,8 @@ function admin_active()
$user_id = $request->input('not_tshirt');
$user_source = User::find($user_id);
if (!$user_source) {
- DB::update('UPDATE `User` SET `Tshirt`=0 WHERE `UID`=? LIMIT 1', [$user_id]);
+ $user_source->state->got_shirt = false;
+ $user_source->state->save();
engelsystem_log('User ' . User_Nick_render($user_source) . ' has NO tshirt.');
$msg = success(__('Angel has got no t-shirt.'), true);
} else {
@@ -141,20 +152,22 @@ function admin_active()
}
}
- $users = DB::select(sprintf('
+ $users = User::query()->raw(sprintf('
SELECT
- `User`.*,
+ `users`.*,
COUNT(`ShiftEntry`.`id`) AS `shift_count`,
(%s + (
- SELECT COALESCE(SUM(`work_hours`) * 3600, 0) FROM `UserWorkLog` WHERE `user_id`=`User`.`UID`
+ SELECT COALESCE(SUM(`work_hours`) * 3600, 0) FROM `UserWorkLog` WHERE `user_id`=`users`.`id`
AND `work_timestamp` < %s
)) AS `shift_length`
- FROM `User` LEFT JOIN `ShiftEntry` ON `User`.`UID` = `ShiftEntry`.`UID`
+ FROM `users`
+ LEFT JOIN `users_state` ON `users`.`id` = `users_state`.`user_id`
+ LEFT JOIN `ShiftEntry` ON `users`.`id` = `ShiftEntry`.`UID`
LEFT JOIN `Shifts` ON `ShiftEntry`.`SID` = `Shifts`.`SID` '
. ($show_all_shifts ? '' : 'AND (`Shifts`.`end` < ' . time() . " OR `Shifts`.`end` IS NULL)") . '
- WHERE `User`.`Gekommen` = 1
- GROUP BY `User`.`UID`
- ORDER BY `force_active` DESC, `shift_length` DESC
+ WHERE `users_state`.`arrived` = 1
+ GROUP BY `users`.`id`
+ ORDER BY `users_state`.`force_active` DESC, `shift_length` DESC
%s
',
$shift_sum_formula,
@@ -167,11 +180,11 @@ function admin_active()
} else {
$tokens = explode(' ', $search);
}
- foreach ($users as &$usr) {
+ foreach ($users as $usr) {
if (count($tokens) > 0) {
$match = false;
foreach ($tokens as $t) {
- if (stristr($usr['Nick'], trim($t))) {
+ if (stristr($usr->name, trim($t))) {
$match = true;
break;
}
@@ -180,18 +193,20 @@ function admin_active()
continue;
}
}
- $usr['nick'] = User_Nick_render($usr);
- $usr['shirt_size'] = $tshirt_sizes[$usr['Size']];
- $usr['work_time'] = round($usr['shift_length'] / 60)
+
+ $userData = [];
+ $userData['nick'] = User_Nick_render($usr);
+ $userData['shirt_size'] = $tshirt_sizes[$usr->personalData->shirt_size];
+ $userData['work_time'] = round($usr['shift_length'] / 60)
. ' min (' . sprintf('%.2f', $usr['shift_length'] / 3600) . '&nbsp;h)';
- $usr['active'] = glyph_bool($usr['Aktiv'] == 1);
- $usr['force_active'] = glyph_bool($usr['force_active'] == 1);
- $usr['tshirt'] = glyph_bool($usr['Tshirt'] == 1);
+ $userData['active'] = glyph_bool($usr->state->active == 1);
+ $userData['force_active'] = glyph_bool($usr->state->force_active == 1);
+ $userData['tshirt'] = glyph_bool($usr->state->got_shirt == 1);
$actions = [];
- if ($usr['Aktiv'] == 0) {
+ if (!$usr->state->active) {
$parameters = [
- 'active' => $usr['UID'],
+ 'active' => $usr->id,
'search' => $search,
];
if ($show_all_shifts) {
@@ -201,9 +216,9 @@ function admin_active()
. __('set active')
. '</a>';
}
- if ($usr['Aktiv'] == 1) {
+ if ($usr->state->active) {
$parametersRemove = [
- 'not_active' => $usr['UID'],
+ 'not_active' => $usr->id,
'search' => $search,
];
if ($show_all_shifts) {
@@ -213,9 +228,9 @@ function admin_active()
. __('remove active')
. '</a>';
}
- if ($usr['Tshirt'] == 0) {
+ if (!$usr->state->got_shirt) {
$parametersShirt = [
- 'tshirt' => $usr['UID'],
+ 'tshirt' => $usr->id,
'search' => $search,
];
if ($show_all_shifts) {
@@ -225,9 +240,9 @@ function admin_active()
. __('got t-shirt')
. '</a>';
}
- if ($usr['Tshirt'] == 1) {
+ if ($usr->state->got_shirt) {
$parameters = [
- 'not_tshirt' => $usr['UID'],
+ 'not_tshirt' => $usr->id,
'search' => $search,
];
if ($show_all_shifts) {
@@ -238,30 +253,27 @@ function admin_active()
. '</a>';
}
- $usr['actions'] = join(' ', $actions);
+ $userData['actions'] = join(' ', $actions);
- $matched_users[] = $usr;
+ $matched_users[] = $userData;
}
$shirt_statistics = [];
foreach (array_keys($tshirt_sizes) as $size) {
- $gc = DB::selectOne(
- 'SELECT count(*) FROM `User` WHERE `Size`=? AND `Tshirt`=1',
- [$size]
- );
- $gc = array_shift($gc);
-
+ $gc = State::query()
+ ->leftJoin('users_settings', 'users_state.user_id', '=', 'users_settings.user_id')
+ ->where('users_state.got_shirt', '=', true)
+ ->where('users_personal_data.shirt_size', '=', $size)
+ ->count();
$shirt_statistics[] = [
'size' => $size,
- 'given' => (int)$gc
+ 'given' => $gc
];
}
- $shirtCount = User_tshirts_count();
-
$shirt_statistics[] = [
'size' => '<b>' . __('Sum') . '</b>',
- 'given' => '<b>' . $shirtCount . '</b>'
+ 'given' => '<b>' . State::whereGotShirt(true)->count() . '</b>'
];
return page_with_title(admin_active_title(), [
diff --git a/includes/pages/admin_arrive.php b/includes/pages/admin_arrive.php
index 62d74290..f06c2c55 100644
--- a/includes/pages/admin_arrive.php
+++ b/includes/pages/admin_arrive.php
@@ -1,6 +1,5 @@
<?php
-use Engelsystem\Database\DB;
use Engelsystem\Models\User\User;
/**
@@ -29,12 +28,11 @@ function admin_arrive()
$user_id = $request->input('reset');
$user_source = User::find($user_id);
if ($user_source) {
- DB::update('
- UPDATE `User`
- SET `Gekommen`=0, `arrival_date` = NULL
- WHERE `UID`=?
- LIMIT 1
- ', [$user_id]);
+ $user_source->state->arrived = false;
+ $user_source->state->save();
+ $user_source->personalData->arrival_date = null;
+ $user_source->personalData->save();
+
engelsystem_log('User set to not arrived: ' . User_Nick_render($user_source));
success(__('Reset done. Angel has not arrived.'));
redirect(user_link($user_source->id));
@@ -45,12 +43,11 @@ function admin_arrive()
$user_id = $request->input('arrived');
$user_source = User::find($user_id);
if ($user_source) {
- DB::update('
- UPDATE `User`
- SET `Gekommen`=1, `arrival_date`=?
- WHERE `UID`=?
- LIMIT 1
- ', [time(), $user_id]);
+ $user_source->state->arrived = true;
+ $user_source->state->save();
+ $user_source->personalData->arrival_date = new Carbon\Carbon();
+ $user_source->personalData->save();
+
engelsystem_log('User set has arrived: ' . User_Nick_render($user_source));
success(__('Angel has been marked as arrived.'));
redirect(user_link($user_source->id));
@@ -59,7 +56,8 @@ function admin_arrive()
}
}
- $users = DB::select('SELECT * FROM `User` ORDER BY `Nick`');
+ /** @var User[] $users */
+ $users = User::query()->orderBy('name')->get();
$arrival_count_at_day = [];
$planned_arrival_count_at_day = [];
$planned_departure_count_at_day = [];
@@ -72,7 +70,7 @@ function admin_arrive()
foreach ($users as $usr) {
if (count($tokens) > 0) {
$match = false;
- $index = join(' ', $usr);
+ $index = join(' ', $usr->toArray());
foreach ($tokens as $t) {
if (stristr($index, trim($t))) {
$match = true;
@@ -84,43 +82,43 @@ function admin_arrive()
}
}
- $usr['nick'] = User_Nick_render($usr);
- if (!is_null($usr['planned_departure_date'])) {
- $usr['rendered_planned_departure_date'] = date('Y-m-d', $usr['planned_departure_date']);
+ $usr->name = User_Nick_render($usr);
+ if ($usr->personalData->planned_departure_date) {
+ $usr['rendered_planned_departure_date'] = $usr->personalData->planned_departure_date->format('Y-m-d');
} else {
$usr['rendered_planned_departure_date'] = '-';
}
- $usr['rendered_planned_arrival_date'] = date('Y-m-d', $usr['planned_arrival_date']);
- $usr['rendered_arrival_date'] = $usr['arrival_date'] > 0 ? date('Y-m-d', $usr['arrival_date']) : '-';
- $usr['arrived'] = $usr['Gekommen'] == 1 ? __('yes') : '';
- $usr['actions'] = $usr['Gekommen'] == 1
+ $usr['rendered_planned_arrival_date'] = $usr->personalData->planned_arrival_date->format('Y-m-d');
+ $usr['rendered_arrival_date'] = $usr->personalData->arrival_date ? $usr->personalData->arrival_date->format('Y-m-d') : '-';
+ $usr['arrived'] = $usr->state->arrived ? __('yes') : '';
+ $usr['actions'] = $usr->state->arrived == 1
? '<a href="' . page_link_to(
'admin_arrive',
- ['reset' => $usr['UID'], 'search' => $search]
+ ['reset' => $usr->id, 'search' => $search]
) . '">' . __('reset') . '</a>'
: '<a href="' . page_link_to(
'admin_arrive',
- ['arrived' => $usr['UID'], 'search' => $search]
+ ['arrived' => $usr->id, 'search' => $search]
) . '">' . __('arrived') . '</a>';
- if ($usr['arrival_date'] > 0) {
- $day = date('Y-m-d', $usr['arrival_date']);
+ if ($usr->personalData->arrival_date) {
+ $day = $usr->personalData->arrival_date->format('Y-m-d');
if (!isset($arrival_count_at_day[$day])) {
$arrival_count_at_day[$day] = 0;
}
$arrival_count_at_day[$day]++;
}
- if (!is_null($usr['planned_arrival_date'])) {
- $day = date('Y-m-d', $usr['planned_arrival_date']);
+ if ($usr->personalData->planned_arrival_date) {
+ $day = $usr->personalData->planned_arrival_date->format('Y-m-d');
if (!isset($planned_arrival_count_at_day[$day])) {
$planned_arrival_count_at_day[$day] = 0;
}
$planned_arrival_count_at_day[$day]++;
}
- if (!is_null($usr['planned_departure_date']) && $usr['Gekommen'] == 1) {
- $day = date('Y-m-d', $usr['planned_departure_date']);
+ if ($usr->personalData->planned_departure_date && $usr->state->arrived) {
+ $day = $usr->personalData->planned_departure_date->format('Y-m-d');
if (!isset($planned_departure_count_at_day[$day])) {
$planned_departure_count_at_day[$day] = 0;
}
diff --git a/includes/pages/admin_free.php b/includes/pages/admin_free.php
index d1d102c7..9b1f581b 100644
--- a/includes/pages/admin_free.php
+++ b/includes/pages/admin_free.php
@@ -1,6 +1,7 @@
<?php
use Engelsystem\Database\DB;
+use Engelsystem\Models\User\User;
/**
* @return string
@@ -28,7 +29,7 @@ function admin_free()
if (!empty($angelType)) {
$angelTypeSearch = ' INNER JOIN `UserAngelTypes` ON (`UserAngelTypes`.`angeltype_id` = '
. DB::getPdo()->quote($angelType)
- . ' AND `UserAngelTypes`.`user_id` = `User`.`UID`';
+ . ' AND `UserAngelTypes`.`user_id` = `users`.`id`';
if ($request->has('confirmed_only')) {
$angelTypeSearch .= ' AND `UserAngelTypes`.`confirm_user_id`';
}
@@ -43,26 +44,25 @@ function admin_free()
$angel_types[$angel_type['id']] = $angel_type['name'];
}
- $users = DB::select('
- SELECT `User`.*
- FROM `User`
- ' . $angelTypeSearch . '
- LEFT JOIN `ShiftEntry` ON `User`.`UID` = `ShiftEntry`.`UID`
+ /** @var User[] $users */
+ $users = User::query()->raw(sprintf('
+ SELECT `users`.*
+ FROM `users`
+ %s
+ LEFT JOIN `ShiftEntry` ON `users`.`id` = `ShiftEntry`.`UID`
+ LEFT JOIN `users_state` ON `users`.`id` = `users_state`.`user_id`
LEFT JOIN `Shifts`
ON (
`ShiftEntry`.`SID` = `Shifts`.`SID`
- AND `Shifts`.`start` < ?
- AND `Shifts`.`end` > ?
+ AND `Shifts`.`start` < %u
+ AND `Shifts`.`end` > %u
)
- WHERE `User`.`Gekommen` = 1
+ WHERE `users_state`.`arrived` = 1
AND `Shifts`.`SID` IS NULL
- GROUP BY `User`.`UID`
- ORDER BY `Nick`
- ',
- [
- time(),
- time(),
- ]
+ GROUP BY `users`.`id`
+ ORDER BY `users`
+ ', $angelTypeSearch, time(), time()
+ )
);
$free_users_table = [];
@@ -74,7 +74,7 @@ function admin_free()
foreach ($users as $usr) {
if (count($tokens) > 0) {
$match = false;
- $index = join('', $usr);
+ $index = join('', $usr->toArray());
foreach ($tokens as $t) {
if (stristr($index, trim($t))) {
$match = true;
@@ -89,12 +89,11 @@ function admin_free()
$free_users_table[] = [
'name' => User_Nick_render($usr),
'shift_state' => User_shift_state_render($usr),
- 'dect' => $usr['DECT'],
- 'jabber' => $usr['jabber'],
- 'email' => $usr['email_by_human_allowed'] ? $usr['email'] : glyph('eye-close'),
+ 'dect' => $usr->contact->dect,
+ 'email' => $usr->settings->email_human ? ($usr->contact->email ? $usr->contact->email : $usr->email) : glyph('eye-close'),
'actions' =>
in_array('admin_user', $privileges)
- ? button(page_link_to('admin_user', ['id' => $usr['UID']]), __('edit'), 'btn-xs')
+ ? button(page_link_to('admin_user', ['id' => $usr->id]), __('edit'), 'btn-xs')
: ''
];
}
@@ -119,7 +118,6 @@ function admin_free()
'name' => __('Nick'),
'shift_state' => '',
'dect' => __('DECT'),
- 'jabber' => __('Jabber'),
'email' => __('E-Mail'),
'actions' => ''
], $free_users_table)
diff --git a/includes/pages/guest_login.php b/includes/pages/guest_login.php
index 32532c6f..bc919acf 100644
--- a/includes/pages/guest_login.php
+++ b/includes/pages/guest_login.php
@@ -431,7 +431,7 @@ function guest_login()
if ($request->has('submit')) {
if ($request->has('nick') && strlen(User_validate_Nick($request->input('nick'))) > 0) {
$nick = User_validate_Nick($request->input('nick'));
- $login_user = User::whereName($nick);
+ $login_user = User::whereName($nick)->first();
if ($login_user) {
if ($request->has('password')) {
if (!verify_password($request->postData('password'), $login_user->password, $login_user->id)) {
diff --git a/includes/pages/user_atom.php b/includes/pages/user_atom.php
index f6a67a15..6aafb74f 100644
--- a/includes/pages/user_atom.php
+++ b/includes/pages/user_atom.php
@@ -7,19 +7,17 @@ use Engelsystem\Database\DB;
*/
function user_atom()
{
- global $user;
$request = request();
if (!$request->has('key') || !preg_match('/^[\da-f]{32}$/', $request->input('key'))) {
engelsystem_error('Missing key.');
}
- $key = $request->input('key');
- $user = User_by_api_key($key);
+ $user = auth()->apiUser('key');
if (empty($user)) {
engelsystem_error('Key invalid.');
}
- if (!in_array('atom', privileges_for_user($user['UID']))) {
+ if (!in_array('atom', privileges_for_user($user->id))) {
engelsystem_error('No privilege for atom.');
}
diff --git a/includes/pages/user_ical.php b/includes/pages/user_ical.php
index f7ed64dd..8a80d681 100644
--- a/includes/pages/user_ical.php
+++ b/includes/pages/user_ical.php
@@ -5,20 +5,17 @@
*/
function user_ical()
{
- global $user;
$request = request();
if (!$request->has('key') || !preg_match('/^[\da-f]{32}$/', $request->input('key'))) {
engelsystem_error('Missing key.');
}
- $key = $request->input('key');
- $user = User_by_api_key($key);
- if (empty($user)) {
+ $user = auth()->apiUser('key');
+ if (!$user) {
engelsystem_error('Key invalid.');
}
-
- if (!in_array('ical', privileges_for_user($user['UID']))) {
+ if (!in_array('ical', privileges_for_user($user->id))) {
engelsystem_error('No privilege for ical.');
}
diff --git a/includes/pages/user_messages.php b/includes/pages/user_messages.php
index 4431133e..9b587343 100644
--- a/includes/pages/user_messages.php
+++ b/includes/pages/user_messages.php
@@ -39,17 +39,18 @@ function user_messages()
$request = request();
if (!$request->has('action')) {
- $users = DB::select(
- 'SELECT `UID`, `Nick` FROM `User` WHERE NOT `UID`=? ORDER BY `Nick`',
- [$user->id]
- );
+ /** @var User[] $users */
+ $users = User::query()
+ ->whereKeyNot($user->id)
+ ->orderBy('name')
+ ->get(['id', 'name']);
$to_select_data = [
'' => __('Select recipient...')
];
foreach ($users as $u) {
- $to_select_data[$u['UID']] = $u['Nick'];
+ $to_select_data[$u->id] = $u->name;
}
$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 cf8d2f0b..fbcd8baf 100644
--- a/includes/pages/user_settings.php
+++ b/includes/pages/user_settings.php
@@ -1,7 +1,7 @@
<?php
use Carbon\Carbon;
-use Engelsystem\Database\DB;
+use Engelsystem\Models\User\User;
/**
* @return string
@@ -14,10 +14,10 @@ function settings_title()
/**
* Change user main attributes (name, dates, etc.)
*
- * @param array $user_source The user
+ * @param User $user_source The user
* @param bool $enable_tshirt_size
* @param array $tshirt_sizes
- * @return array
+ * @return User
*/
function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes)
{
@@ -26,7 +26,7 @@ function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes)
if ($request->has('mail')) {
$result = User_validate_mail($request->input('mail'));
- $user_source['email'] = $result->getValue();
+ $user_source->email = $result->getValue();
if (!$result->isValid()) {
$valid = false;
error(__('E-mail address is not correct.'));
@@ -36,20 +36,11 @@ function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes)
error(__('Please enter your e-mail.'));
}
- $user_source['email_shiftinfo'] = $request->has('email_shiftinfo');
- $user_source['email_by_human_allowed'] = $request->has('email_by_human_allowed');
-
- if ($request->has('jabber')) {
- $result = User_validate_jabber($request->input('jabber'));
- $user_source['jabber'] = $result->getValue();
- if (!$result->isValid()) {
- $valid = false;
- error(__('Please check your jabber account information.'));
- }
- }
+ $user_source->settings->email_shiftinfo = $request->has('email_shiftinfo');
+ $user_source->settings->email_human = $request->has('email_by_human_allowed');
if ($request->has('tshirt_size') && isset($tshirt_sizes[$request->input('tshirt_size')])) {
- $user_source['Size'] = $request->input('tshirt_size');
+ $user_source->personalData->shirt_size = $request->input('tshirt_size');
} elseif ($enable_tshirt_size) {
$valid = false;
}
@@ -57,7 +48,7 @@ function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes)
if ($request->has('planned_arrival_date')) {
$tmp = parse_date('Y-m-d H:i', $request->input('planned_arrival_date') . ' 00:00');
$result = User_validate_planned_arrival_date($tmp);
- $user_source['planned_arrival_date'] = $result->getValue();
+ $user_source->personalData->planned_arrival_date = Carbon::createFromTimestamp($result->getValue());
if (!$result->isValid()) {
$valid = false;
error(__('Please enter your planned date of arrival. It should be after the buildup start date and before teardown end date.'));
@@ -66,8 +57,8 @@ function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes)
if ($request->has('planned_departure_date')) {
$tmp = parse_date('Y-m-d H:i', $request->input('planned_departure_date') . ' 00:00');
- $result = User_validate_planned_departure_date($user_source['planned_arrival_date'], $tmp);
- $user_source['planned_departure_date'] = $result->getValue();
+ $result = User_validate_planned_departure_date($user_source->personalData->arrival_date->getTimestamp(), $tmp);
+ $user_source->personalData->planned_departure_date = Carbon::createFromTimestamp($result->getValue());
if (!$result->isValid()) {
$valid = false;
error(__('Please enter your planned date of departure. It should be after your planned arrival date and after buildup start date and before teardown end date.'));
@@ -75,21 +66,21 @@ function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes)
}
// Trivia
- $user_source['Name'] = strip_request_item('lastname', $user_source['Name']);
- $user_source['Vorname'] = strip_request_item('prename', $user_source['Vorname']);
- $user_source['Alter'] = strip_request_item('age', $user_source['Alter']);
- $user_source['Telefon'] = strip_request_item('tel', $user_source['Telefon']);
+ $user_source->name = strip_request_item('lastname', $user_source['Name']);
+ $user_source->personalData->first_name = strip_request_item('prename', $user_source['Vorname']);
if (strlen(strip_request_item('dect')) <= 5) {
- $user_source['DECT'] = strip_request_item('dect', $user_source['DECT']);
+ $user_source->contact->dect = strip_request_item('dect', $user_source['DECT']);
} else {
$valid = false;
error(__('For dect numbers are only 5 digits allowed.'));
}
- $user_source['Handy'] = strip_request_item('mobile', $user_source['Handy']);
- $user_source['Hometown'] = strip_request_item('hometown', $user_source['Hometown']);
+ $user_source->contact->mobile = strip_request_item('mobile', $user_source['Handy']);
if ($valid) {
- User_update($user_source);
+ $user_source->save();
+ $user_source->contact->save();
+ $user_source->personalData->save();
+ $user_source->settings->save();
success(__('Settings saved.'));
redirect(page_link_to('user_settings'));
@@ -101,14 +92,14 @@ function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes)
/**
* Change user password.
*
- * @param array $user_source The user
+ * @param User $user_source The user
*/
function user_settings_password($user_source)
{
$request = request();
if (
!$request->has('password')
- || !verify_password($request->postData('password'), $user_source['Passwort'], $user_source['UID'])
+ || !verify_password($request->postData('password'), $user_source->password, $user_source->id)
) {
error(__('-> not OK. Please try again.'));
} elseif (strlen($request->postData('new_password')) < config('min_password_length')) {
@@ -116,7 +107,7 @@ function user_settings_password($user_source)
} elseif ($request->postData('new_password') != $request->postData('new_password2')) {
error(__('Your passwords don\'t match.'));
} else {
- set_password($user_source['UID'], $request->postData('new_password'));
+ set_password($user_source->id, $request->postData('new_password'));
success(__('Password saved.'));
}
redirect(page_link_to('user_settings'));
@@ -125,9 +116,9 @@ function user_settings_password($user_source)
/**
* Change user theme
*
- * @param array $user_source The user
+ * @param User $user_source The user
* @param array $themes List of available themes
- * @return array
+ * @return User
*/
function user_settings_theme($user_source, $themes)
{
@@ -135,22 +126,13 @@ function user_settings_theme($user_source, $themes)
$request = request();
if ($request->has('theme') && isset($themes[$request->input('theme')])) {
- $user_source['color'] = $request->input('theme');
+ $user_source->settings->theme = $request->input('theme');
} else {
$valid = false;
}
if ($valid) {
- DB::update('
- UPDATE `User`
- SET `color`=?
- WHERE `UID`=?
- ',
- [
- $user_source['color'],
- $user_source['UID'],
- ]
- );
+ $user_source->settings->save();
success(__('Theme changed.'));
redirect(page_link_to('user_settings'));
@@ -162,9 +144,9 @@ function user_settings_theme($user_source, $themes)
/**
* Change use locale
*
- * @param array $user_source The user
+ * @param User $user_source The user
* @param array $locales List of available locales
- * @return array
+ * @return User
*/
function user_settings_locale($user_source, $locales)
{
@@ -173,23 +155,14 @@ function user_settings_locale($user_source, $locales)
$session = session();
if ($request->has('language') && isset($locales[$request->input('language')])) {
- $user_source['Sprache'] = $request->input('language');
+ $user_source->settings->language = $request->input('language');
} else {
$valid = false;
}
if ($valid) {
- DB::update('
- UPDATE `User`
- SET `Sprache`=?
- WHERE `UID`=?
- ',
- [
- $user_source['Sprache'],
- $user_source['UID'],
- ]
- );
- $session->set('locale', $user_source['Sprache']);
+ $user_source->settings->save();
+ $session->set('locale', $user_source->settings->language);
success('Language changed.');
redirect(page_link_to('user_settings'));
@@ -205,7 +178,6 @@ function user_settings_locale($user_source, $locales)
*/
function user_settings()
{
- global $user;
$request = request();
$config = config();
$themes = config('available_themes');
@@ -227,8 +199,7 @@ function user_settings()
$teardown_end_date = $teardown->getTimestamp();
}
- $user_source = $user;
-
+ $user_source = auth()->user();
if ($request->has('submit')) {
$user_source = user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes);
} elseif ($request->has('submit_password')) {