-
Notifications
You must be signed in to change notification settings - Fork 453
/
EventList.php
92 lines (77 loc) · 2.43 KB
/
EventList.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
namespace Concrete\Core\Calendar\Event;
use Concrete\Core\Entity\Calendar\Calendar;
use Concrete\Core\Search\Pagination\Pagination;
use Pagerfanta\Adapter\DoctrineDbalAdapter;
class EventList extends \Concrete\Core\Search\ItemList\Database\AttributedItemList
{
protected $autoSortColumns = array(
'eventID',
'name',
'description',
);
/**
* @return bool
*/
public function isIncludeInactiveEvents()
{
return $this->includeInactiveEvents;
}
/**
* @param bool $includeInactiveEvents
*/
public function includeInactiveEvents()
{
$this->includeInactiveEvents = true;
}
protected $includeInactiveEvents = false;
public function getResult($row)
{
return Event::getByID(array_get($row, 'eventID'));
}
public function filterByCalendar(Calendar $calendar)
{
$this->query->andWhere('e.caID = :caID');
$this->query->setParameter('caID', $calendar->getID());
}
public function finalizeQuery(\Doctrine\DBAL\Query\QueryBuilder $query)
{
if ($this->includeInactiveEvents) {
$query->andWhere('ve.eventVersionID = (select max(eventVersionID) from CalendarEventVersions where eventID = e.eventID)');
} else {
$query->andWhere('ve.evIsApproved = 1');
}
return $query;
}
/**
* Returns the total results in this item list.
*
* @return int
*/
public function getTotalResults()
{
$query = $this->deliverQueryObject();
return $query->select('count(distinct e.eventID)')->setMaxResults(1)->execute()->fetchColumn();
}
public function createQuery()
{
$this->query->select('e.eventID')->from('CalendarEvents', 'e')
->innerJoin('e', 'CalendarEventVersions', 've', 'e.eventID = ve.eventID')
->leftJoin('e', 'CalendarEventSearchIndexAttributes', 'ea', 'e.eventID = ea.eventID');
}
protected function getAttributeKeyClassName()
{
return '\\Concrete\\Core\\Attribute\\Key\\EventKey';
}
/**
* @return \Concrete\Core\Search\Pagination\Pagination
*/
protected function createPaginationObject()
{
$adapter = new DoctrineDbalAdapter(
$this->deliverQueryObject(), function ($query) {
$query->select('count(distinct e.eventID)')->setMaxResults(1);
});
return new Pagination($this, $adapter);
}
}