2011-07-05 08:35:18 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/*
|
2012-02-15 17:48:14 -08:00
|
|
|
* Copyright 2012 Facebook, Inc.
|
2011-07-05 08:35:18 -07:00
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
2012-09-13 10:15:08 -07:00
|
|
|
final class PhabricatorFeedQuery
|
|
|
|
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
2011-07-05 08:35:18 -07:00
|
|
|
|
|
|
|
|
private $filterPHIDs;
|
|
|
|
|
|
|
|
|
|
public function setFilterPHIDs(array $phids) {
|
|
|
|
|
$this->filterPHIDs = $phids;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-02 15:41:19 -07:00
|
|
|
public function loadPage() {
|
2011-07-05 08:35:18 -07:00
|
|
|
|
2012-07-02 15:41:19 -07:00
|
|
|
$story_table = new PhabricatorFeedStoryData();
|
|
|
|
|
$conn = $story_table->establishConnection('r');
|
2011-07-05 08:35:18 -07:00
|
|
|
|
2012-07-02 15:41:19 -07:00
|
|
|
$data = queryfx_all(
|
|
|
|
|
$conn,
|
|
|
|
|
'SELECT story.* FROM %T story %Q %Q %Q %Q %Q',
|
|
|
|
|
$story_table->getTableName(),
|
|
|
|
|
$this->buildJoinClause($conn),
|
|
|
|
|
$this->buildWhereClause($conn),
|
|
|
|
|
$this->buildGroupClause($conn),
|
|
|
|
|
$this->buildOrderClause($conn),
|
|
|
|
|
$this->buildLimitClause($conn));
|
|
|
|
|
|
|
|
|
|
$results = PhabricatorFeedStory::loadAllFromRows($data);
|
|
|
|
|
|
|
|
|
|
return $this->processResults($results);
|
2012-02-15 17:48:14 -08:00
|
|
|
}
|
|
|
|
|
|
2012-07-02 15:41:19 -07:00
|
|
|
private function buildJoinClause(AphrontDatabaseConnection $conn_r) {
|
|
|
|
|
// NOTE: We perform this join unconditionally (even if we have no filter
|
|
|
|
|
// PHIDs) to omit rows which have no story references. These story data
|
|
|
|
|
// rows are notifications or realtime alerts.
|
2011-07-05 08:35:18 -07:00
|
|
|
|
|
|
|
|
$ref_table = new PhabricatorFeedStoryReference();
|
2012-07-02 15:41:19 -07:00
|
|
|
return qsprintf(
|
|
|
|
|
$conn_r,
|
|
|
|
|
'JOIN %T ref ON ref.chronologicalKey = story.chronologicalKey',
|
|
|
|
|
$ref_table->getTableName());
|
|
|
|
|
}
|
2011-07-05 08:35:18 -07:00
|
|
|
|
2012-07-02 15:41:19 -07:00
|
|
|
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
2011-07-05 08:35:18 -07:00
|
|
|
$where = array();
|
2012-07-02 15:41:19 -07:00
|
|
|
|
2011-07-05 08:35:18 -07:00
|
|
|
if ($this->filterPHIDs) {
|
|
|
|
|
$where[] = qsprintf(
|
2012-07-02 15:41:19 -07:00
|
|
|
$conn_r,
|
2011-07-05 08:35:18 -07:00
|
|
|
'ref.objectPHID IN (%Ls)',
|
|
|
|
|
$this->filterPHIDs);
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-02 15:41:19 -07:00
|
|
|
$where[] = $this->buildPagingClause($conn_r);
|
2012-02-15 17:48:14 -08:00
|
|
|
|
2012-07-02 15:41:19 -07:00
|
|
|
return $this->formatWhereClause($where);
|
|
|
|
|
}
|
2012-02-15 17:48:14 -08:00
|
|
|
|
2012-07-02 15:41:19 -07:00
|
|
|
private function buildGroupClause(AphrontDatabaseConnection $conn_r) {
|
|
|
|
|
return qsprintf(
|
|
|
|
|
$conn_r,
|
2012-10-04 14:49:23 -07:00
|
|
|
'GROUP BY '.($this->filterPHIDs
|
|
|
|
|
? 'ref.chronologicalKey'
|
|
|
|
|
: 'story.chronologicalKey'));
|
2012-07-02 15:41:19 -07:00
|
|
|
}
|
2011-07-05 08:35:18 -07:00
|
|
|
|
2012-07-02 15:41:19 -07:00
|
|
|
protected function getPagingColumn() {
|
2012-10-04 14:49:23 -07:00
|
|
|
return ($this->filterPHIDs
|
|
|
|
|
? 'ref.chronologicalKey'
|
|
|
|
|
: 'story.chronologicalKey');
|
2012-07-02 15:41:19 -07:00
|
|
|
}
|
2012-02-15 17:48:14 -08:00
|
|
|
|
2012-07-02 15:41:19 -07:00
|
|
|
protected function getPagingValue($item) {
|
|
|
|
|
return $item->getChronologicalKey();
|
2011-07-05 08:35:18 -07:00
|
|
|
}
|
2012-07-02 10:37:22 -07:00
|
|
|
|
2011-07-05 08:35:18 -07:00
|
|
|
}
|