Migrate message view
This commit is contained in:
parent
95adeca0ae
commit
a78659b2d4
|
@ -12,7 +12,6 @@ $includeFiles = [
|
|||
__DIR__ . '/../includes/sys_template.php',
|
||||
|
||||
__DIR__ . '/../includes/model/AngelType_model.php',
|
||||
__DIR__ . '/../includes/model/Message_model.php',
|
||||
__DIR__ . '/../includes/model/NeededAngelTypes_model.php',
|
||||
__DIR__ . '/../includes/model/Room_model.php',
|
||||
__DIR__ . '/../includes/model/ShiftEntry_model.php',
|
||||
|
|
|
@ -1,56 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Engelsystem\Database\DB;
|
||||
use Engelsystem\Models\User\User;
|
||||
|
||||
/**
|
||||
* Returns Message id array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function Message_ids()
|
||||
{
|
||||
return DB::select('SELECT `id` FROM `Messages`');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns message by id.
|
||||
*
|
||||
* @param int $message_id message ID
|
||||
* @return array|null
|
||||
*/
|
||||
function Message($message_id)
|
||||
{
|
||||
$message = DB::selectOne('SELECT * FROM `Messages` WHERE `id`=? LIMIT 1', [$message_id]);
|
||||
|
||||
return empty($message) ? null : $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* send message
|
||||
*
|
||||
* @param int $receiver_user_id User ID of Receiver
|
||||
* @param string $text Text of Message
|
||||
* @return bool
|
||||
*/
|
||||
function Message_send($receiver_user_id, $text)
|
||||
{
|
||||
$user = auth()->user();
|
||||
$receiver = User::find($receiver_user_id);
|
||||
|
||||
if (empty($text) || !$receiver || $receiver->id == $user->id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return DB::insert('
|
||||
INSERT INTO `Messages` (`Datum`, `SUID`, `RUID`, `Text`)
|
||||
VALUES(?, ?, ?, ?)
|
||||
',
|
||||
[
|
||||
time(),
|
||||
$user->id,
|
||||
$receiver->id,
|
||||
$text
|
||||
]
|
||||
);
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
use Engelsystem\Database\DB;
|
||||
use Engelsystem\Models\Message;
|
||||
use Engelsystem\Models\User\User;
|
||||
|
||||
/**
|
||||
|
@ -19,10 +19,10 @@ function user_unread_messages()
|
|||
$user = auth()->user();
|
||||
|
||||
if ($user) {
|
||||
$new_messages = count(DB::select(
|
||||
'SELECT `id` FROM `Messages` WHERE isRead=\'N\' AND `RUID`=?',
|
||||
[$user->id]
|
||||
));
|
||||
$new_messages = $user->messagesReceived()
|
||||
->where('read', false)
|
||||
->count();
|
||||
|
||||
if ($new_messages > 0) {
|
||||
return ' <span class="badge danger">' . $new_messages . '</span>';
|
||||
}
|
||||
|
@ -57,23 +57,12 @@ function user_messages()
|
|||
|
||||
$to_select = html_select_key('to', 'to', $to_select_data, '');
|
||||
|
||||
$messages = DB::select('
|
||||
SELECT *
|
||||
FROM `Messages`
|
||||
WHERE `SUID`=?
|
||||
OR `RUID`=?
|
||||
ORDER BY `isRead`,`Datum` DESC
|
||||
',
|
||||
[
|
||||
$user->id,
|
||||
$user->id,
|
||||
]
|
||||
);
|
||||
$messages = $user->messages;
|
||||
|
||||
$messages_table = [
|
||||
[
|
||||
'news' => '',
|
||||
'timestamp' => date('Y-m-d H:i'),
|
||||
'timestamp' => date(__('Y-m-d H:i')),
|
||||
'from' => User_Nick_render($user),
|
||||
'to' => $to_select,
|
||||
'text' => form_textarea('text', '', ''),
|
||||
|
@ -82,28 +71,28 @@ function user_messages()
|
|||
];
|
||||
|
||||
foreach ($messages as $message) {
|
||||
$sender_user_source = User::find($message['SUID']);
|
||||
$receiver_user_source = User::find($message['RUID']);
|
||||
$sender_user_source = $message->user;
|
||||
$receiver_user_source = $message->receiver;
|
||||
|
||||
$messages_table_entry = [
|
||||
'new' => $message['isRead'] == 'N' ? '<span class="glyphicon glyphicon-envelope"></span>' : '',
|
||||
'timestamp' => date('Y-m-d H:i', $message['Datum']),
|
||||
'new' => !$message->read ? '<span class="glyphicon glyphicon-envelope"></span>' : '',
|
||||
'timestamp' => $message->created_at->format(__('Y-m-d H:i')),
|
||||
'from' => User_Nick_render($sender_user_source),
|
||||
'to' => User_Nick_render($receiver_user_source),
|
||||
'text' => nl2br(htmlspecialchars($message['Text']))
|
||||
'text' => nl2br(htmlspecialchars($message->text))
|
||||
];
|
||||
|
||||
if ($message['RUID'] == $user->id) {
|
||||
if ($message['isRead'] == 'N') {
|
||||
if ($message->receiver_id == $user->id) {
|
||||
if (!$message->read) {
|
||||
$messages_table_entry['actions'] = button(
|
||||
page_link_to('user_messages', ['action' => 'read', 'id' => $message['id']]),
|
||||
page_link_to('user_messages', ['action' => 'read', 'id' => $message->id]),
|
||||
__('mark as read'),
|
||||
'btn-xs'
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$messages_table_entry['actions'] = button(
|
||||
page_link_to('user_messages', ['action' => 'delete', 'id' => $message['id']]),
|
||||
page_link_to('user_messages', ['action' => 'delete', 'id' => $message->id]),
|
||||
__('delete message'),
|
||||
'btn-xs'
|
||||
);
|
||||
|
@ -134,15 +123,10 @@ function user_messages()
|
|||
return error(__('Incomplete call, missing Message ID.'), true);
|
||||
}
|
||||
|
||||
$message = DB::selectOne(
|
||||
'SELECT `RUID` FROM `Messages` WHERE `id`=? LIMIT 1',
|
||||
[$message_id]
|
||||
);
|
||||
if (!empty($message) && $message['RUID'] == $user->id) {
|
||||
DB::update(
|
||||
'UPDATE `Messages` SET `isRead`=\'Y\' WHERE `id`=? LIMIT 1',
|
||||
[$message_id]
|
||||
);
|
||||
$message = Message::find($message_id);
|
||||
if ($message !== null && $message->receiver_id == $user->id) {
|
||||
$message->read = true;
|
||||
$message->save();
|
||||
throw_redirect(page_link_to('user_messages'));
|
||||
} else {
|
||||
return error(__('No Message found.'), true);
|
||||
|
@ -156,12 +140,9 @@ function user_messages()
|
|||
return error(__('Incomplete call, missing Message ID.'), true);
|
||||
}
|
||||
|
||||
$message = DB::selectOne(
|
||||
'SELECT `SUID` FROM `Messages` WHERE `id`=? LIMIT 1',
|
||||
[$message_id]
|
||||
);
|
||||
if (!empty($message) && $message['SUID'] == $user->id) {
|
||||
DB::delete('DELETE FROM `Messages` WHERE `id`=? LIMIT 1', [$message_id]);
|
||||
$message = Message::find($message_id);
|
||||
if ($message !== null && $message->user_id == $user->id) {
|
||||
$message->delete();
|
||||
throw_redirect(page_link_to('user_messages'));
|
||||
} else {
|
||||
return error(__('No Message found.'), true);
|
||||
|
@ -169,7 +150,15 @@ function user_messages()
|
|||
break;
|
||||
|
||||
case 'send':
|
||||
if (Message_send($request->input('to'), $request->input('text'))) {
|
||||
$receiver = User::find($request->input('to'));
|
||||
$text = $request->input('text');
|
||||
|
||||
if ($receiver !== null && !empty($text)) {
|
||||
Message::create([
|
||||
'user_id' => $user->id,
|
||||
'receiver_id' => $request->input('to'),
|
||||
'text' => $request->input('text')
|
||||
]);
|
||||
throw_redirect(page_link_to('user_messages'));
|
||||
} else {
|
||||
return error(__('Transmitting was terminated with an Error.'), true);
|
||||
|
|
|
@ -1696,6 +1696,10 @@ msgstr "Nachrichten"
|
|||
msgid "Select recipient..."
|
||||
msgstr "Empfänger auswählen..."
|
||||
|
||||
#: includes/pages/user_messages.php:61 includes/pages/user_messages.php:75
|
||||
msgid "Y-m-d H:i"
|
||||
msgstr "d.m.Y H:i"
|
||||
|
||||
#: includes/pages/user_messages.php:98
|
||||
msgid "mark as read"
|
||||
msgstr "als gelesen markieren"
|
||||
|
|
Loading…
Reference in New Issue