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