2014-01-07 15:50:16 +01:00
|
|
|
<?php
|
|
|
|
|
2017-01-21 13:58:53 +01:00
|
|
|
use Engelsystem\Database\DB;
|
2018-12-28 22:32:36 +01:00
|
|
|
use Engelsystem\Models\User\User;
|
2017-01-21 13:58:53 +01:00
|
|
|
|
2016-09-29 11:18:17 +02:00
|
|
|
/**
|
|
|
|
* Returns Message id array
|
2017-01-03 03:22:48 +01:00
|
|
|
*
|
2017-01-21 13:58:53 +01:00
|
|
|
* @return array
|
2014-01-07 15:50:16 +01:00
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function Message_ids()
|
|
|
|
{
|
2017-01-21 13:58:53 +01:00
|
|
|
return DB::select('SELECT `id` FROM `Messages`');
|
2014-01-07 15:50:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns message by id.
|
|
|
|
*
|
2017-01-03 03:22:48 +01:00
|
|
|
* @param int $message_id message ID
|
2018-01-14 23:07:34 +01:00
|
|
|
* @return array|null
|
2014-01-07 15:50:16 +01:00
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function Message($message_id)
|
|
|
|
{
|
2018-01-14 23:07:34 +01:00
|
|
|
$message = DB::selectOne('SELECT * FROM `Messages` WHERE `id`=? LIMIT 1', [$message_id]);
|
|
|
|
|
|
|
|
return empty($message) ? null : $message;
|
2014-01-07 15:50:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* send message
|
|
|
|
*
|
2017-12-25 21:29:00 +01:00
|
|
|
* @param int $receiver_user_id User ID of Receiver
|
2017-01-03 03:22:48 +01:00
|
|
|
* @param string $text Text of Message
|
|
|
|
* @return bool
|
2014-01-07 15:50:16 +01:00
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function Message_send($receiver_user_id, $text)
|
|
|
|
{
|
2018-10-31 12:48:22 +01:00
|
|
|
$user = auth()->user();
|
2018-12-28 22:32:36 +01:00
|
|
|
$receiver = User::find($receiver_user_id);
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2018-12-28 22:32:36 +01:00
|
|
|
if (empty($text) || !$receiver || $receiver->id == $user->id) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2018-12-28 22:32:36 +01:00
|
|
|
return DB::insert('
|
2017-01-21 13:58:53 +01:00
|
|
|
INSERT INTO `Messages` (`Datum`, `SUID`, `RUID`, `Text`)
|
|
|
|
VALUES(?, ?, ?, ?)
|
|
|
|
',
|
2018-12-28 22:32:36 +01:00
|
|
|
[
|
|
|
|
time(),
|
|
|
|
$user->id,
|
|
|
|
$receiver->id,
|
|
|
|
$text
|
|
|
|
]
|
|
|
|
);
|
2014-01-07 15:50:16 +01:00
|
|
|
}
|