Update Phrequent to use new search infrastructure.
Summary:
This updates Phrequent to use new the search infrastructure. Now it looks like:
{F60141}
I've also added the policy infrastructure stubs, but it's probably not even close to being right in terms of enforcing policies (in particular being able to see time tracked against objects the user wouldn't normally be able to see).
At some point I'd like to be able to filter on the objects that the time is tracked against, but I don't believe there's a tokenizer / readahead control that allows you to type any kind of object.
Test Plan: Clicked around the new interface, created some custom queries and saved them.
Reviewers: epriestley
CC: Korvin, aran
Maniphest Tasks: T3870
Differential Revision: https://secure.phabricator.com/D7163
This commit is contained in:
@@ -1,56 +1,46 @@
|
||||
<?php
|
||||
|
||||
final class PhrequentUserTimeQuery extends PhabricatorOffsetPagedQuery {
|
||||
final class PhrequentUserTimeQuery
|
||||
extends PhabricatorCursorPagedPolicyAwareQuery {
|
||||
|
||||
const ORDER_ID = 'order-id';
|
||||
const ORDER_STARTED = 'order-started';
|
||||
const ORDER_ENDED = 'order-ended';
|
||||
const ORDER_DURATION = 'order-duration';
|
||||
const ORDER_ID_ASC = 0;
|
||||
const ORDER_ID_DESC = 1;
|
||||
const ORDER_STARTED_ASC = 2;
|
||||
const ORDER_STARTED_DESC = 3;
|
||||
const ORDER_ENDED_ASC = 4;
|
||||
const ORDER_ENDED_DESC = 5;
|
||||
const ORDER_DURATION_ASC = 6;
|
||||
const ORDER_DURATION_DESC = 7;
|
||||
|
||||
const ENDED_YES = "ended-yes";
|
||||
const ENDED_NO = "ended-no";
|
||||
const ENDED_ALL = "ended-all";
|
||||
const ENDED_YES = 0;
|
||||
const ENDED_NO = 1;
|
||||
const ENDED_ALL = 2;
|
||||
|
||||
private $userPHIDs;
|
||||
private $objectPHIDs;
|
||||
private $order = self::ORDER_ID;
|
||||
private $order = self::ORDER_ID_ASC;
|
||||
private $ended = self::ENDED_ALL;
|
||||
|
||||
public function setUsers($user_phids) {
|
||||
public function withUserPHIDs($user_phids) {
|
||||
$this->userPHIDs = $user_phids;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setObjects($object_phids) {
|
||||
public function withObjectPHIDs($object_phids) {
|
||||
$this->objectPHIDs = $object_phids;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withEnded($ended) {
|
||||
$this->ended = $ended;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setOrder($order) {
|
||||
$this->order = $order;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setEnded($ended) {
|
||||
$this->ended = $ended;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute() {
|
||||
$usertime_dao = new PhrequentUserTime();
|
||||
$conn = $usertime_dao->establishConnection('r');
|
||||
|
||||
$data = queryfx_all(
|
||||
$conn,
|
||||
'SELECT usertime.* FROM %T usertime %Q %Q %Q',
|
||||
$usertime_dao->getTableName(),
|
||||
$this->buildWhereClause($conn),
|
||||
$this->buildOrderClause($conn),
|
||||
$this->buildLimitClause($conn));
|
||||
|
||||
return $usertime_dao->loadAllFromArray($data);
|
||||
}
|
||||
|
||||
private function buildWhereClause(AphrontDatabaseConnection $conn) {
|
||||
$where = array();
|
||||
|
||||
@@ -85,27 +75,100 @@ final class PhrequentUserTimeQuery extends PhabricatorOffsetPagedQuery {
|
||||
throw new Exception("Unknown ended '{$this->ended}'!");
|
||||
}
|
||||
|
||||
$where[] = $this->buildPagingClause($conn);
|
||||
|
||||
return $this->formatWhereClause($where);
|
||||
}
|
||||
|
||||
private function buildOrderClause(AphrontDatabaseConnection $conn) {
|
||||
protected function getPagingColumn() {
|
||||
switch ($this->order) {
|
||||
case self::ORDER_ID:
|
||||
return 'ORDER BY id ASC';
|
||||
case self::ORDER_STARTED:
|
||||
return 'ORDER BY dateStarted DESC';
|
||||
case self::ORDER_ENDED:
|
||||
return 'ORDER BY dateEnded IS NULL, dateEnded DESC, dateStarted DESC';
|
||||
case self::ORDER_DURATION:
|
||||
return 'ORDER BY COALESCE(dateEnded, UNIX_TIMESTAMP()) - dateStarted '.
|
||||
'DESC';
|
||||
case self::ORDER_ID_ASC:
|
||||
case self::ORDER_ID_DESC:
|
||||
return 'id';
|
||||
case self::ORDER_STARTED_ASC:
|
||||
case self::ORDER_STARTED_DESC:
|
||||
return 'dateStarted';
|
||||
case self::ORDER_ENDED_ASC:
|
||||
case self::ORDER_ENDED_DESC:
|
||||
return 'dateEnded';
|
||||
case self::ORDER_DURATION_ASC:
|
||||
case self::ORDER_DURATION_DESC:
|
||||
return 'COALESCE(dateEnded, UNIX_TIMESTAMP()) - dateStarted';
|
||||
default:
|
||||
throw new Exception("Unknown order '{$this->order}'!");
|
||||
}
|
||||
}
|
||||
|
||||
protected function getPagingValue($result) {
|
||||
switch ($this->order) {
|
||||
case self::ORDER_ID_ASC:
|
||||
case self::ORDER_ID_DESC:
|
||||
return $result->getID();
|
||||
case self::ORDER_STARTED_ASC:
|
||||
case self::ORDER_STARTED_DESC:
|
||||
return $result->getDateStarted();
|
||||
case self::ORDER_ENDED_ASC:
|
||||
case self::ORDER_ENDED_DESC:
|
||||
return $result->getDateEnded();
|
||||
case self::ORDER_DURATION_ASC:
|
||||
case self::ORDER_DURATION_DESC:
|
||||
return ($result->getDateEnded() || time()) - $result->getDateStarted();
|
||||
default:
|
||||
throw new Exception("Unknown order '{$this->order}'!");
|
||||
}
|
||||
}
|
||||
|
||||
protected function getReversePaging() {
|
||||
switch ($this->order) {
|
||||
case self::ORDER_ID_ASC:
|
||||
case self::ORDER_STARTED_ASC:
|
||||
case self::ORDER_ENDED_ASC:
|
||||
case self::ORDER_DURATION_ASC:
|
||||
return true;
|
||||
case self::ORDER_ID_DESC:
|
||||
case self::ORDER_STARTED_DESC:
|
||||
case self::ORDER_ENDED_DESC:
|
||||
case self::ORDER_DURATION_DESC:
|
||||
return false;
|
||||
default:
|
||||
throw new Exception("Unknown order '{$this->order}'!");
|
||||
}
|
||||
}
|
||||
|
||||
protected function loadPage() {
|
||||
$usertime = new PhrequentUserTime();
|
||||
$conn = $usertime->establishConnection('r');
|
||||
|
||||
$data = queryfx_all(
|
||||
$conn,
|
||||
'SELECT usertime.* FROM %T usertime %Q %Q %Q',
|
||||
$usertime->getTableName(),
|
||||
$this->buildWhereClause($conn),
|
||||
$this->buildOrderClause($conn),
|
||||
$this->buildLimitClause($conn));
|
||||
|
||||
return $usertime->loadAllFromArray($data);
|
||||
}
|
||||
|
||||
/* -( Helper Functions ) --------------------------------------------------- */
|
||||
|
||||
public static function getEndedSearchOptions() {
|
||||
return array(
|
||||
self::ENDED_ALL => pht('All'),
|
||||
self::ENDED_NO => pht('No'),
|
||||
self::ENDED_YES => pht('Yes'));
|
||||
}
|
||||
|
||||
public static function getOrderSearchOptions() {
|
||||
return array(
|
||||
self::ORDER_STARTED_ASC => pht('by furthest start date'),
|
||||
self::ORDER_STARTED_DESC => pht('by nearest start date'),
|
||||
self::ORDER_ENDED_ASC => pht('by furthest end date'),
|
||||
self::ORDER_ENDED_DESC => pht('by nearest end date'),
|
||||
self::ORDER_DURATION_ASC => pht('by smallest duration'),
|
||||
self::ORDER_DURATION_DESC => pht('by largest duration'));
|
||||
}
|
||||
|
||||
public static function getUserTotalObjectsTracked(
|
||||
PhabricatorUser $user) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user