2014-02-06 10:07:42 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorCalendarEventQuery
|
|
|
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
|
|
|
|
|
|
|
private $ids;
|
|
|
|
private $rangeBegin;
|
|
|
|
private $rangeEnd;
|
|
|
|
private $invitedPHIDs;
|
2014-02-06 10:10:18 -08:00
|
|
|
private $creatorPHIDs;
|
2014-02-06 10:07:42 -08:00
|
|
|
|
|
|
|
public function withIDs(array $ids) {
|
|
|
|
$this->ids = $ids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withDateRange($begin, $end) {
|
|
|
|
$this->rangeBegin = $begin;
|
|
|
|
$this->rangeEnd = $end;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withInvitedPHIDs(array $phids) {
|
|
|
|
$this->invitedPHIDs = $phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2014-02-06 10:10:18 -08:00
|
|
|
public function withCreatorPHIDs(array $phids) {
|
|
|
|
$this->creatorPHIDs = $phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2014-02-06 10:07:42 -08:00
|
|
|
protected function loadPage() {
|
|
|
|
$table = new PhabricatorCalendarEvent();
|
|
|
|
$conn_r = $table->establishConnection('r');
|
|
|
|
|
|
|
|
$data = queryfx_all(
|
|
|
|
$conn_r,
|
|
|
|
'SELECT * FROM %T %Q %Q %Q',
|
|
|
|
$table->getTableName(),
|
|
|
|
$this->buildWhereClause($conn_r),
|
|
|
|
$this->buildOrderClause($conn_r),
|
|
|
|
$this->buildLimitClause($conn_r));
|
|
|
|
|
|
|
|
return $table->loadAllFromArray($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function buildWhereClause($conn_r) {
|
|
|
|
$where = array();
|
|
|
|
|
|
|
|
if ($this->ids) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'id IN (%Ld)',
|
|
|
|
$this->ids);
|
|
|
|
}
|
|
|
|
|
2014-02-06 10:10:18 -08:00
|
|
|
if ($this->rangeBegin) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'dateTo >= %d',
|
|
|
|
$this->rangeBegin);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->rangeEnd) {
|
2014-02-06 10:07:42 -08:00
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
2014-02-06 10:10:18 -08:00
|
|
|
'dateFrom <= %d',
|
2014-02-06 10:07:42 -08:00
|
|
|
$this->rangeEnd);
|
|
|
|
}
|
|
|
|
|
2014-02-06 10:10:18 -08:00
|
|
|
// TODO: Currently, the creator is always the only invitee, but you can
|
|
|
|
// query them separately since this won't always be true.
|
|
|
|
|
2014-02-06 10:07:42 -08:00
|
|
|
if ($this->invitedPHIDs) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'userPHID IN (%Ls)',
|
|
|
|
$this->invitedPHIDs);
|
|
|
|
}
|
|
|
|
|
2014-02-06 10:10:18 -08:00
|
|
|
if ($this->creatorPHIDs) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'userPHID IN (%Ls)',
|
|
|
|
$this->creatorPHIDs);
|
|
|
|
}
|
|
|
|
|
2014-02-06 10:07:42 -08:00
|
|
|
$where[] = $this->buildPagingClause($conn_r);
|
|
|
|
|
|
|
|
return $this->formatWhereClause($where);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getQueryApplicationClass() {
|
|
|
|
return 'PhabricatorApplicationCalendar';
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|