Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phrequent/query/PhrequentUserTimeQuery.php
Show All 10 Lines | final class PhrequentUserTimeQuery | ||||
const ORDER_ENDED_DESC = 5; | const ORDER_ENDED_DESC = 5; | ||||
const ORDER_DURATION_ASC = 6; | const ORDER_DURATION_ASC = 6; | ||||
const ORDER_DURATION_DESC = 7; | const ORDER_DURATION_DESC = 7; | ||||
const ENDED_YES = 0; | const ENDED_YES = 0; | ||||
const ENDED_NO = 1; | const ENDED_NO = 1; | ||||
const ENDED_ALL = 2; | const ENDED_ALL = 2; | ||||
private $ids; | |||||
private $userPHIDs; | private $userPHIDs; | ||||
private $objectPHIDs; | private $objectPHIDs; | ||||
private $afterDate; | |||||
private $beforeDate; | |||||
private $order = self::ORDER_ID_ASC; | private $order = self::ORDER_ID_ASC; | ||||
private $ended = self::ENDED_ALL; | private $ended = self::ENDED_ALL; | ||||
private $needPreemptingEvents; | private $needPreemptingEvents; | ||||
public function withIDs($ids) { | |||||
$this->ids = $ids; | |||||
return $this; | |||||
} | |||||
public function withUserPHIDs($user_phids) { | public function withUserPHIDs($user_phids) { | ||||
$this->userPHIDs = $user_phids; | $this->userPHIDs = $user_phids; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function withObjectPHIDs($object_phids) { | public function withObjectPHIDs($object_phids) { | ||||
$this->objectPHIDs = $object_phids; | $this->objectPHIDs = $object_phids; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function afterDate($after_date) { | |||||
$this->afterDate = $after_date; | |||||
return $this; | |||||
} | |||||
public function beforeDate($before_date) { | |||||
$this->beforeDate = $before_date; | |||||
return $this; | |||||
} | |||||
public function withEnded($ended) { | public function withEnded($ended) { | ||||
$this->ended = $ended; | $this->ended = $ended; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setOrder($order) { | public function setOrder($order) { | ||||
$this->order = $order; | $this->order = $order; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function needPreemptingEvents($need_events) { | public function needPreemptingEvents($need_events) { | ||||
$this->needPreemptingEvents = $need_events; | $this->needPreemptingEvents = $need_events; | ||||
return $this; | return $this; | ||||
} | } | ||||
private function buildWhereClause(AphrontDatabaseConnection $conn) { | private function buildWhereClause(AphrontDatabaseConnection $conn) { | ||||
$where = array(); | $where = array(); | ||||
if ($this->ids) { | |||||
$where[] = qsprintf( | |||||
$conn, | |||||
'id IN (%Ld)', | |||||
$this->ids); | |||||
} | |||||
if ($this->userPHIDs) { | if ($this->userPHIDs) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'userPHID IN (%Ls)', | 'userPHID IN (%Ls)', | ||||
$this->userPHIDs); | $this->userPHIDs); | ||||
} | } | ||||
if ($this->objectPHIDs) { | if ($this->objectPHIDs) { | ||||
Show All 15 Lines | switch ($this->ended) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'dateEnded IS NULL'); | 'dateEnded IS NULL'); | ||||
break; | break; | ||||
default: | default: | ||||
throw new Exception("Unknown ended '{$this->ended}'!"); | throw new Exception("Unknown ended '{$this->ended}'!"); | ||||
} | } | ||||
if ($this->afterDate) { | |||||
$where[] = qsprintf( | |||||
$conn, | |||||
'dateEnded > %d', | |||||
$this->afterDate); | |||||
} | |||||
if ($this->beforeDate) { | |||||
$where[] = qsprintf( | |||||
$conn, | |||||
'dateStarted < %d', | |||||
$this->beforeDate); | |||||
} | |||||
$where[] = $this->buildPagingClause($conn); | $where[] = $this->buildPagingClause($conn); | ||||
return $this->formatWhereClause($where); | return $this->formatWhereClause($where); | ||||
} | } | ||||
protected function getPagingColumn() { | protected function getPagingColumn() { | ||||
switch ($this->order) { | switch ($this->order) { | ||||
case self::ORDER_ID_ASC: | case self::ORDER_ID_ASC: | ||||
▲ Show 20 Lines • Show All 217 Lines • Show Last 20 Lines |