1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-04 04:32:43 +01:00
phorge-phorge/src/applications/dashboard/query/PhabricatorDashboardQuery.php
epriestley 941f0ba7ae Allow panels to appear on dashboards
Summary:
Ref T3583. Adds edges, query relationships, etc. Lots of debugging/temporary UI.

My general intent here is to use edges to track where panels appear, and then put additional data on the dashboard itself to control layout, positioning, etc.

Dashboards don't actually render yet so this is still pretty boring.

Test Plan:
{F149175}

{F149176}

{F149177}

Reviewers: chad, btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T3583

Differential Revision: https://secure.phabricator.com/D8916
2014-04-30 14:28:55 -07:00

102 lines
2.4 KiB
PHP

<?php
final class PhabricatorDashboardQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $ids;
private $phids;
private $needPanels;
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
}
public function withPHIDs(array $phids) {
$this->phids = $phids;
return $this;
}
public function needPanels($need_panels) {
$this->needPanels = $need_panels;
return $this;
}
protected function loadPage() {
$table = new PhabricatorDashboard();
$conn_r = $table->establishConnection('r');
$data = queryfx_all(
$conn_r,
'SELECT * FROM %T %Q %Q %Q',
$table->getTableName(),
$this->buildWhereClause($conn_r),
$this->buildOrderClause($conn_r),
$this->buildLimitClause($conn_r));
return $table->loadAllFromArray($data);
}
protected function didFilterPage(array $dashboards) {
if ($this->needPanels) {
$edge_query = id(new PhabricatorEdgeQuery())
->withSourcePHIDs(mpull($dashboards, 'getPHID'))
->withEdgeTypes(
array(
PhabricatorEdgeConfig::TYPE_DASHBOARD_HAS_PANEL,
));
$edge_query->execute();
$panel_phids = $edge_query->getDestinationPHIDs();
if ($panel_phids) {
$panels = id(new PhabricatorDashboardPanelQuery())
->setParentQuery($this)
->setViewer($this->getViewer())
->withPHIDs($panel_phids)
->execute();
$panels = mpull($panels, null, 'getPHID');
} else {
$panels = array();
}
foreach ($dashboards as $dashboard) {
$dashboard_phids = $edge_query->getDestinationPHIDs(
array($dashboard->getPHID()));
$dashboard_panels = array_select_keys($panels, $dashboard_phids);
$dashboard->attachPanelPHIDs($dashboard_phids);
$dashboard->attachPanels($dashboard_panels);
}
}
return $dashboards;
}
protected function buildWhereClause($conn_r) {
$where = array();
if ($this->ids) {
$where[] = qsprintf(
$conn_r,
'id IN (%Ld)',
$this->ids);
}
if ($this->phids) {
$where[] = qsprintf(
$conn_r,
'phid IN (%Ls)',
$this->phids);
}
$where[] = $this->buildPagingClause($conn_r);
return $this->formatWhereClause($where);
}
public function getQueryApplicationClass() {
return 'PhabricatorApplicationDashboard';
}
}