Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/calendar/query/PhabricatorCalendarImportLogQuery.php
12256 views
1
<?php
2
3
final class PhabricatorCalendarImportLogQuery
4
extends PhabricatorCursorPagedPolicyAwareQuery {
5
6
private $ids;
7
private $phids;
8
private $importPHIDs;
9
10
public function withIDs(array $ids) {
11
$this->ids = $ids;
12
return $this;
13
}
14
15
public function withPHIDs(array $phids) {
16
$this->phids = $phids;
17
return $this;
18
}
19
20
public function withImportPHIDs(array $phids) {
21
$this->importPHIDs = $phids;
22
return $this;
23
}
24
25
public function newResultObject() {
26
return new PhabricatorCalendarImportLog();
27
}
28
29
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
30
$where = parent::buildWhereClauseParts($conn);
31
32
if ($this->ids !== null) {
33
$where[] = qsprintf(
34
$conn,
35
'log.id IN (%Ld)',
36
$this->ids);
37
}
38
39
if ($this->phids !== null) {
40
$where[] = qsprintf(
41
$conn,
42
'log.phid IN (%Ls)',
43
$this->phids);
44
}
45
46
if ($this->importPHIDs !== null) {
47
$where[] = qsprintf(
48
$conn,
49
'log.importPHID IN (%Ls)',
50
$this->importPHIDs);
51
}
52
53
54
return $where;
55
}
56
57
protected function willFilterPage(array $page) {
58
$viewer = $this->getViewer();
59
60
$type_map = PhabricatorCalendarImportLogType::getAllLogTypes();
61
foreach ($page as $log) {
62
$type_constant = $log->getParameter('type');
63
64
$type_object = idx($type_map, $type_constant);
65
if (!$type_object) {
66
$type_object = new PhabricatorCalendarImportDefaultLogType();
67
}
68
69
$type_object = clone $type_object;
70
$log->attachLogType($type_object);
71
}
72
73
$import_phids = mpull($page, 'getImportPHID');
74
75
if ($import_phids) {
76
$imports = id(new PhabricatorCalendarImportQuery())
77
->setViewer($viewer)
78
->withPHIDs($import_phids)
79
->execute();
80
$imports = mpull($imports, null, 'getPHID');
81
} else {
82
$imports = array();
83
}
84
85
foreach ($page as $key => $log) {
86
$import = idx($imports, $log->getImportPHID());
87
if (!$import) {
88
$this->didRejectResult($import);
89
unset($page[$key]);
90
continue;
91
}
92
93
$log->attachImport($import);
94
}
95
96
return $page;
97
}
98
99
protected function getPrimaryTableAlias() {
100
return 'log';
101
}
102
103
public function getQueryApplicationClass() {
104
return 'PhabricatorCalendarApplication';
105
}
106
107
}
108
109