/
IntegrationList.php
62 lines (50 loc) · 1.56 KB
/
IntegrationList.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
namespace Concrete\Core\Api;
use Concrete\Core\Entity\OAuth\Client;
use Concrete\Core\Search\ItemList\EntityItemList;
use Concrete\Core\Search\Pagination\Pagination;
use Doctrine\ORM\EntityManagerInterface;
use Pagerfanta\Adapter\DoctrineORMAdapter;
class IntegrationList extends EntityItemList
{
protected $entityManager;
protected $itemsPerPage = 20;
protected $autoSortColumns = ['c.name'];
public function __construct(EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
parent::__construct();
$this->sortBy('c.name', 'asc');
}
public function filterByKeywords($keywords)
{
$this->query->andWhere(
$this->query->expr()->like('c.name', ':name')
);
$this->query->setParameter('name', '%' . $keywords . '%');
}
public function getEntityManager()
{
return $this->entityManager;
}
public function createQuery()
{
$this->query->select('c')->from(Client::class, 'c');
}
protected function createPaginationObject()
{
$adapter = new DoctrineORMAdapter($this->query, function ($query) {
$query->select('count(distinct c.identifier)')->setMaxResults(1);
});
$pagination = new Pagination($this, $adapter);
return $pagination;
}
public function getResult($result)
{
return $result;
}
public function getTotalResults(): int
{
return $this->query->select('count(c)')->setMaxResults(1)->getQuery()->getSingleScalarResult();
}
}