2011-07-05 17:35:18 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2012-02-16 02:48:14 +01:00
|
|
|
* Copyright 2012 Facebook, Inc.
|
2011-07-05 17:35:18 +02: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 19:15:08 +02:00
|
|
|
final class PhabricatorFeedQuery
|
|
|
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
2011-07-05 17:35:18 +02:00
|
|
|
|
|
|
|
private $filterPHIDs;
|
|
|
|
|
|
|
|
public function setFilterPHIDs(array $phids) {
|
|
|
|
$this->filterPHIDs = $phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-07-03 00:41:19 +02:00
|
|
|
public function loadPage() {
|
2011-07-05 17:35:18 +02:00
|
|
|
|
2012-07-03 00:41:19 +02:00
|
|
|
$story_table = new PhabricatorFeedStoryData();
|
|
|
|
$conn = $story_table->establishConnection('r');
|
2011-07-05 17:35:18 +02:00
|
|
|
|
2012-07-03 00:41:19 +02: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-16 02:48:14 +01:00
|
|
|
}
|
|
|
|
|
2012-07-03 00:41:19 +02: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 17:35:18 +02:00
|
|
|
|
|
|
|
$ref_table = new PhabricatorFeedStoryReference();
|
2012-07-03 00:41:19 +02:00
|
|
|
return qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'JOIN %T ref ON ref.chronologicalKey = story.chronologicalKey',
|
|
|
|
$ref_table->getTableName());
|
|
|
|
}
|
2011-07-05 17:35:18 +02:00
|
|
|
|
2012-07-03 00:41:19 +02:00
|
|
|
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
2011-07-05 17:35:18 +02:00
|
|
|
$where = array();
|
2012-07-03 00:41:19 +02:00
|
|
|
|
2011-07-05 17:35:18 +02:00
|
|
|
if ($this->filterPHIDs) {
|
|
|
|
$where[] = qsprintf(
|
2012-07-03 00:41:19 +02:00
|
|
|
$conn_r,
|
2011-07-05 17:35:18 +02:00
|
|
|
'ref.objectPHID IN (%Ls)',
|
|
|
|
$this->filterPHIDs);
|
|
|
|
}
|
|
|
|
|
2012-07-03 00:41:19 +02:00
|
|
|
$where[] = $this->buildPagingClause($conn_r);
|
2012-02-16 02:48:14 +01:00
|
|
|
|
2012-07-03 00:41:19 +02:00
|
|
|
return $this->formatWhereClause($where);
|
|
|
|
}
|
2012-02-16 02:48:14 +01:00
|
|
|
|
2012-07-03 00:41:19 +02:00
|
|
|
private function buildGroupClause(AphrontDatabaseConnection $conn_r) {
|
|
|
|
return qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'GROUP BY ref.chronologicalKey');
|
|
|
|
}
|
2011-07-05 17:35:18 +02:00
|
|
|
|
2012-07-03 00:41:19 +02:00
|
|
|
protected function getPagingColumn() {
|
|
|
|
return 'ref.chronologicalKey';
|
|
|
|
}
|
2012-02-16 02:48:14 +01:00
|
|
|
|
2012-07-03 00:41:19 +02:00
|
|
|
protected function getPagingValue($item) {
|
|
|
|
return $item->getChronologicalKey();
|
2011-07-05 17:35:18 +02:00
|
|
|
}
|
2012-07-02 19:37:22 +02:00
|
|
|
|
2011-07-05 17:35:18 +02:00
|
|
|
}
|