2013-01-25 02:23:05 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2013-04-26 19:30:41 +02:00
|
|
|
* Query class that answers these questions:
|
|
|
|
*
|
|
|
|
* - Q: What are the conpherences to show when I land on /conpherence/ ?
|
|
|
|
* - A:
|
|
|
|
*
|
|
|
|
* id(new ConpherenceParticipantQuery())
|
|
|
|
* ->withParticipantPHIDs(array($my_phid))
|
|
|
|
* ->execute();
|
|
|
|
*
|
|
|
|
* - Q: What are the next set of conpherences as I scroll up (more recent) or
|
|
|
|
* down (less recent) this list of conpherences?
|
|
|
|
* - A:
|
|
|
|
*
|
|
|
|
* id(new ConpherenceParticipantQuery())
|
|
|
|
* ->withParticipantPHIDs(array($my_phid))
|
|
|
|
* ->withParticipantCursor($top_participant)
|
|
|
|
* ->setOrder(ConpherenceParticipantQuery::ORDER_NEWER)
|
|
|
|
* ->execute();
|
|
|
|
*
|
|
|
|
* -or-
|
|
|
|
*
|
|
|
|
* id(new ConpherenceParticipantQuery())
|
|
|
|
* ->withParticipantPHIDs(array($my_phid))
|
|
|
|
* ->withParticipantCursor($bottom_participant)
|
|
|
|
* ->setOrder(ConpherenceParticipantQuery::ORDER_OLDER)
|
|
|
|
* ->execute();
|
|
|
|
*
|
|
|
|
* For counts of read, un-read, or all conpherences by participant, see
|
|
|
|
* @{class:ConpherenceParticipantCountQuery}.
|
2013-01-25 02:23:05 +01:00
|
|
|
*/
|
2014-07-10 00:12:48 +02:00
|
|
|
final class ConpherenceParticipantQuery extends PhabricatorOffsetPagedQuery {
|
2013-01-25 02:23:05 +01:00
|
|
|
|
2013-04-26 19:30:41 +02:00
|
|
|
const LIMIT = 100;
|
|
|
|
const ORDER_NEWER = 'newer';
|
|
|
|
const ORDER_OLDER = 'older';
|
2013-01-25 02:23:05 +01:00
|
|
|
|
2013-04-26 19:30:41 +02:00
|
|
|
private $participantPHIDs;
|
|
|
|
private $participantCursor;
|
|
|
|
private $order = self::ORDER_OLDER;
|
2013-01-25 02:23:05 +01:00
|
|
|
|
|
|
|
public function withParticipantPHIDs(array $phids) {
|
|
|
|
$this->participantPHIDs = $phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-04-26 19:30:41 +02:00
|
|
|
public function withParticipantCursor(ConpherenceParticipant $participant) {
|
|
|
|
$this->participantCursor = $participant;
|
2013-01-25 02:23:05 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-04-26 19:30:41 +02:00
|
|
|
public function setOrder($order) {
|
|
|
|
$this->order = $order;
|
2013-01-25 02:23:05 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function execute() {
|
|
|
|
$table = new ConpherenceParticipant();
|
|
|
|
$conn_r = $table->establishConnection('r');
|
|
|
|
|
|
|
|
$data = queryfx_all(
|
|
|
|
$conn_r,
|
|
|
|
'SELECT * FROM %T participant %Q %Q %Q',
|
|
|
|
$table->getTableName(),
|
|
|
|
$this->buildWhereClause($conn_r),
|
|
|
|
$this->buildOrderClause($conn_r),
|
|
|
|
$this->buildLimitClause($conn_r));
|
|
|
|
|
|
|
|
$participants = $table->loadAllFromArray($data);
|
|
|
|
|
|
|
|
$participants = mpull($participants, null, 'getConpherencePHID');
|
|
|
|
|
2013-04-26 19:30:41 +02:00
|
|
|
if ($this->order == self::ORDER_NEWER) {
|
|
|
|
$participants = array_reverse($participants);
|
|
|
|
}
|
|
|
|
|
2013-01-25 02:23:05 +01:00
|
|
|
return $participants;
|
|
|
|
}
|
|
|
|
|
Make buildWhereClause() a method of AphrontCursorPagedPolicyAwareQuery
Summary:
Ref T4100. Ref T5595.
To support a unified "Projects:" query across all applications, a future diff is going to add a set of "Edge Logic" capabilities to `PolicyAwareQuery` which write the required SELECT, JOIN, WHERE, HAVING and GROUP clauses for you.
With the addition of "Edge Logic", we'll have three systems which may need to build components of query claues: ordering/paging, customfields/applicationsearch, and edge logic.
For most clauses, queries don't currently call into the parent explicitly to get default components. I want to move more query construction logic up the class tree so it can be shared.
For most methods, this isn't a problem, but many subclasses define a `buildWhereClause()`. Make all such definitions protected and consistent.
This causes no behavioral changes.
Test Plan: Ran `arc unit --everything`, which does a pretty through job of verifying this statically.
Reviewers: btrahan
Reviewed By: btrahan
Subscribers: yelirekim, hach-que, epriestley
Maniphest Tasks: T4100, T5595
Differential Revision: https://secure.phabricator.com/D12453
2015-04-18 16:08:30 +02:00
|
|
|
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
2013-01-25 02:23:05 +01:00
|
|
|
$where = array();
|
|
|
|
|
|
|
|
if ($this->participantPHIDs) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'participantPHID IN (%Ls)',
|
|
|
|
$this->participantPHIDs);
|
|
|
|
}
|
|
|
|
|
2013-04-26 19:30:41 +02:00
|
|
|
if ($this->participantCursor) {
|
|
|
|
$date_touched = $this->participantCursor->getDateTouched();
|
|
|
|
$id = $this->participantCursor->getID();
|
|
|
|
if ($this->order == self::ORDER_OLDER) {
|
|
|
|
$compare_date = '<';
|
|
|
|
$compare_id = '<=';
|
|
|
|
} else {
|
|
|
|
$compare_date = '>';
|
|
|
|
$compare_id = '>=';
|
|
|
|
}
|
2013-01-25 02:23:05 +01:00
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
2013-04-26 19:30:41 +02:00
|
|
|
'(dateTouched %Q %d OR (dateTouched = %d AND id %Q %d))',
|
|
|
|
$compare_date,
|
|
|
|
$date_touched,
|
|
|
|
$date_touched,
|
|
|
|
$compare_id,
|
|
|
|
$id);
|
2013-01-25 02:23:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->formatWhereClause($where);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildOrderClause(AphrontDatabaseConnection $conn_r) {
|
2013-04-26 19:30:41 +02:00
|
|
|
$order_word = ($this->order == self::ORDER_OLDER) ? 'DESC' : 'ASC';
|
|
|
|
// if these are different direction we won't get as efficient a query
|
|
|
|
// see http://dev.mysql.com/doc/refman/5.5/en/order-by-optimization.html
|
|
|
|
$order = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'ORDER BY dateTouched %Q, id %Q',
|
|
|
|
$order_word,
|
|
|
|
$order_word);
|
|
|
|
|
|
|
|
return $order;
|
2013-01-25 02:23:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|