mirror of
https://github.com/RaspbianFrance/raspisms.git
synced 2025-04-20 16:37:48 +02:00
Change all lists to use ajax data source and high perf datatable + improve all consuming listing queries + add indexes on numbers for perf improvment
This commit is contained in:
parent
52ac5b459b
commit
b98d5a22ef
34 changed files with 1238 additions and 767 deletions
|
@ -13,6 +13,45 @@ namespace models;
|
|||
|
||||
class Group extends StandardModel
|
||||
{
|
||||
/**
|
||||
* Return a list of groups for a user.
|
||||
* Add a column nb_contacts
|
||||
*
|
||||
* @param int $id_user : user id
|
||||
* @param ?int $limit : Number of entry to return or null
|
||||
* @param ?int $offset : Number of entry to ignore or null
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function list_for_user(int $id_user, $limit, $offset)
|
||||
{
|
||||
$query = '
|
||||
SELECT g.*, COUNT(gc.id) as nb_contact
|
||||
FROM `group` as g
|
||||
LEFT JOIN group_contact as gc
|
||||
ON g.id = gc.id_group
|
||||
WHERE id_user = :id_user
|
||||
GROUP BY g.id
|
||||
';
|
||||
|
||||
if ($limit !== null)
|
||||
{
|
||||
$limit = (int) $limit;
|
||||
|
||||
$query .= ' LIMIT ' . $limit;
|
||||
if ($offset !== null)
|
||||
{
|
||||
$offset = (int) $offset;
|
||||
$query .= ' OFFSET ' . $offset;
|
||||
}
|
||||
}
|
||||
|
||||
$params = [
|
||||
'id_user' => $id_user,
|
||||
];
|
||||
|
||||
return $this->_run_query($query, $params);
|
||||
}
|
||||
/**
|
||||
* Return a group by his name for a user.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue