2012-02-19 05:16:35 +01:00
|
|
|
<?php
|
|
|
|
|
2012-03-10 00:46:25 +01:00
|
|
|
final class DifferentialRevisionStatsController extends DifferentialController {
|
2012-02-19 05:16:35 +01:00
|
|
|
private $filter;
|
|
|
|
|
|
|
|
private function loadRevisions($phid) {
|
|
|
|
$table = new DifferentialRevision();
|
|
|
|
$conn_r = $table->establishConnection('r');
|
|
|
|
$rows = queryfx_all(
|
|
|
|
$conn_r,
|
|
|
|
'SELECT revisions.* FROM %T revisions ' .
|
|
|
|
'JOIN %T comments ON comments.revisionID = revisions.id ' .
|
|
|
|
'JOIN (' .
|
|
|
|
' SELECT revisionID FROM %T WHERE objectPHID = %s ' .
|
|
|
|
' UNION ALL ' .
|
|
|
|
' SELECT id from differential_revision WHERE authorPHID = %s) rel ' .
|
|
|
|
'ON (comments.revisionID = rel.revisionID)' .
|
|
|
|
'WHERE comments.action = %s' .
|
|
|
|
'AND comments.authorPHID = %s',
|
|
|
|
$table->getTableName(),
|
|
|
|
id(new DifferentialComment())->getTableName(),
|
|
|
|
DifferentialRevision::RELATIONSHIP_TABLE,
|
|
|
|
$phid,
|
|
|
|
$phid,
|
|
|
|
$this->filter,
|
|
|
|
$phid
|
|
|
|
);
|
|
|
|
return $table->loadAllFromArray($rows);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function loadComments($phid) {
|
|
|
|
$table = new DifferentialComment();
|
|
|
|
$conn_r = $table->establishConnection('r');
|
|
|
|
$rows = queryfx_all(
|
|
|
|
$conn_r,
|
|
|
|
'SELECT comments.* FROM %T comments ' .
|
|
|
|
'JOIN (' .
|
|
|
|
' SELECT revisionID FROM %T WHERE objectPHID = %s ' .
|
|
|
|
' UNION ALL ' .
|
|
|
|
' SELECT id from differential_revision WHERE authorPHID = %s) rel ' .
|
|
|
|
'ON (comments.revisionID = rel.revisionID)' .
|
|
|
|
'WHERE comments.action = %s' .
|
|
|
|
'AND comments.authorPHID = %s',
|
|
|
|
$table->getTableName(),
|
|
|
|
DifferentialRevision::RELATIONSHIP_TABLE,
|
|
|
|
$phid,
|
|
|
|
$phid,
|
|
|
|
$this->filter,
|
|
|
|
$phid
|
|
|
|
);
|
|
|
|
|
|
|
|
return $table->loadAllFromArray($rows);
|
|
|
|
}
|
2012-07-04 03:24:58 +02:00
|
|
|
|
|
|
|
private function loadDiffs(array $revisions) {
|
|
|
|
if (!$revisions) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$diff_teml = new DifferentialDiff();
|
|
|
|
$diffs = $diff_teml->loadAllWhere(
|
|
|
|
'revisionID in (%Ld)',
|
|
|
|
array_keys($revisions)
|
|
|
|
);
|
|
|
|
return $diffs;
|
|
|
|
}
|
|
|
|
|
2012-02-19 05:16:35 +01:00
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->filter = idx($data, 'filter');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
$phid_arr = $request->getArr('view_user');
|
|
|
|
$view_target = head($phid_arr);
|
|
|
|
return id(new AphrontRedirectResponse())
|
|
|
|
->setURI($request->getRequestURI()->alter('phid', $view_target));
|
|
|
|
}
|
|
|
|
|
|
|
|
$params = array_filter(
|
|
|
|
array(
|
|
|
|
'phid' => $request->getStr('phid'),
|
|
|
|
));
|
|
|
|
|
|
|
|
// Fill in the defaults we'll actually use for calculations if any
|
|
|
|
// parameters are missing.
|
|
|
|
$params += array(
|
|
|
|
'phid' => $user->getPHID(),
|
|
|
|
);
|
|
|
|
|
|
|
|
$side_nav = new AphrontSideNavFilterView();
|
|
|
|
$side_nav->setBaseURI(id(new PhutilURI('/differential/stats/'))
|
|
|
|
->alter('phid', $params['phid']));
|
|
|
|
foreach (array(
|
2012-04-24 02:40:57 +02:00
|
|
|
DifferentialAction::ACTION_CLOSE,
|
2012-02-19 05:16:35 +01:00
|
|
|
DifferentialAction::ACTION_ACCEPT,
|
|
|
|
DifferentialAction::ACTION_REJECT,
|
|
|
|
DifferentialAction::ACTION_UPDATE,
|
|
|
|
DifferentialAction::ACTION_COMMENT,
|
|
|
|
) as $action) {
|
|
|
|
$verb = ucfirst(DifferentialAction::getActionPastTenseVerb($action));
|
|
|
|
$side_nav->addFilter($action, $verb);
|
|
|
|
}
|
|
|
|
$this->filter =
|
|
|
|
$side_nav->selectFilter($this->filter,
|
2012-04-24 02:40:57 +02:00
|
|
|
DifferentialAction::ACTION_CLOSE);
|
2012-02-19 05:16:35 +01:00
|
|
|
|
|
|
|
$panels = array();
|
2012-09-05 04:02:56 +02:00
|
|
|
$handles = $this->loadViewerHandles(array($params['phid']));
|
2012-02-19 05:16:35 +01:00
|
|
|
|
|
|
|
$filter_form = id(new AphrontFormView())
|
|
|
|
->setAction('/differential/stats/'.$this->filter.'/')
|
|
|
|
->setUser($user);
|
|
|
|
|
|
|
|
$filter_form->appendChild(
|
|
|
|
$this->renderControl($params['phid'], $handles));
|
|
|
|
$filter_form->appendChild(id(new AphrontFormSubmitControl())
|
2013-01-24 19:46:47 +01:00
|
|
|
->setValue(pht('Filter Revisions')));
|
2012-02-19 05:16:35 +01:00
|
|
|
|
|
|
|
$side_nav->appendChild($filter_form);
|
|
|
|
|
|
|
|
$comments = $this->loadComments($params['phid']);
|
|
|
|
$revisions = $this->loadRevisions($params['phid']);
|
2012-07-04 03:24:58 +02:00
|
|
|
$diffs = $this->loadDiffs($revisions);
|
2012-02-19 05:16:35 +01:00
|
|
|
|
|
|
|
$panel = new AphrontPanelView();
|
2013-01-24 19:46:47 +01:00
|
|
|
$panel->setHeader(pht('Differential rate analysis'));
|
2012-02-19 05:16:35 +01:00
|
|
|
$panel->appendChild(
|
|
|
|
id(new DifferentialRevisionStatsView())
|
|
|
|
->setComments($comments)
|
2012-07-04 03:24:58 +02:00
|
|
|
->setFilter($this->filter)
|
2012-02-19 05:16:35 +01:00
|
|
|
->setRevisions($revisions)
|
2012-07-04 03:24:58 +02:00
|
|
|
->setDiffs($diffs)
|
2012-02-19 05:16:35 +01:00
|
|
|
->setUser($user));
|
|
|
|
$panels[] = $panel;
|
|
|
|
|
|
|
|
foreach ($panels as $panel) {
|
|
|
|
$side_nav->appendChild($panel);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->buildStandardPageResponse(
|
|
|
|
$side_nav,
|
|
|
|
array(
|
2013-01-24 19:46:47 +01:00
|
|
|
'title' => pht('Differential Statistics'),
|
2012-02-19 05:16:35 +01:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
private function renderControl($view_phid, $handles) {
|
|
|
|
$value = array();
|
|
|
|
if ($view_phid) {
|
|
|
|
$value = array(
|
|
|
|
$view_phid => $handles[$view_phid]->getFullName(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return id(new AphrontFormTokenizerControl())
|
|
|
|
->setDatasource('/typeahead/common/users/')
|
2013-01-24 19:46:47 +01:00
|
|
|
->setLabel(pht('View User'))
|
2012-02-19 05:16:35 +01:00
|
|
|
->setName('view_user')
|
|
|
|
->setValue($value)
|
|
|
|
->setLimit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|