File size: 1.41Kb
<?php
class Dialogs
{
public $offset = 0, // стандартный offset
$limit = 10; // стандартный limit
/*
// Берем у юзера offset и limit
public function __construct()
{
$this->offset = !(App::$me['offset'] ?? false) ? (int) App::$me['offset'] : $this->offset;
$this->limit = !(App::$me['limit'] ?? false) ? (int) App::$me['limit'] : $this->limit;
}
*/
// Вывод диалогов
public function get(int $userId, $offset = 0, $limit = 10, int $sort = 0)
{
$response = false;
if (!empty($userId))
{
$offset = (!$offset ? $this->offset : $offset);
$limit = (!$limit ? $this->limit : $limit);
$sort = ($sort == 0 ? 'DESC' : 'ASC');
$query = Base::query(
'SELECT * FROM `mail_contacts` WHERE `user_id` = :user_id OR `contact_id` = :contact_id ORDER BY `time` '.$sort.' LIMIT :offset,:limit', [
'offset/int' => $offset,
'limit/int' => $limit,
'user_id/int' => $userId,
'contact_id/int' => $userId,
],
'arr'
);
if (is_array($query) && count($query) > 0)
{
$response = $query;
}
}
return $response;
}
// Инфа диалога по id контакта
public function getByUserId(int $contactId)
{
}
// Создать новый диалог
public function add(int $userId, int $contactId, string $message = null)
{
}
}