Page MenuHomec4science

PhabricatorC4sHomeFeed.php
No OneTemporary

File Metadata

Created
Wed, Jun 26, 04:53

PhabricatorC4sHomeFeed.php

<?php
final class PhabricatorC4sHomeFeed
extends PhabricatorController {
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) {
require_celerity_resource('phabricator-dashboard-css');
$content = $this->getFeedContent($request);
return id(new AphrontAjaxResponse())
->setContent(array(
'panelMarkup' => hsprintf('%s', $content),
));
}
private function getFeedContent($request) {
// hack to have global in the request
$global = $request->getBool('dashboardID', true);
$viewer = $this->getViewer();
$limit = $global ? 30 : 12;
$phids = array();
$epoch_min = time() - 7*24*3600; // 7 days
$epoch_max = time();
if(!$global) {
//User
$phids += array($viewer->getPHID());
// Projects
$projects = id(new PhabricatorProjectQuery())
->setViewer($viewer)
->withMemberPHIDs(array($viewer->getPHID()))
->execute();
$project_phids = mpull($projects, 'getPHID');
$phids += array_fuse($project_phids);
// Repositories (created by user)
$repo_transaction = id(new PhabricatorRepositoryTransactionQuery())
->setViewer($viewer)
->withAuthorPHIDs(array($viewer->getPHID()))
->withTransactionTypes(array(PhabricatorTransactions::TYPE_CREATE))
->needComments(false)
->needHandles(false)
->execute();
$repo = array_fuse(mpull($repo_transaction, 'getObjectPHID'));
// Repositories (in project user is member of)
if(!empty($projects)) {
$any = array();
foreach($project_phids as $phid) {
$any[] = 'any(' . $phid . ')';
}
$datasource = id(new PhabricatorProjectLogicalDatasource())
->setViewer($viewer);
$constraints = $datasource->evaluateTokens($any);
$query = id(new PhabricatorRepositoryQuery())
->setViewer($viewer)
->withEdgeLogicConstraints(
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST,
$constraints)
->execute();
$repo += array_fuse(mpull($query, 'getPHID'));
}
// Commits for selected Repositories
if(!empty($repo)) {
$commits = id(new DiffusionCommitQuery())
->setViewer($viewer)
->withRepositoryPHIDs($repo)
->withEpochRange($epoch_min, $epoch_max)
->execute();
$phids += array_fuse(mpull($commits, 'getPHID'));
}
// Phriction pages
if(!empty($projects)) {
$slugs = array();
foreach($projects as $p) {
$slugs[] = PhabricatorProjectWikiCreate::getAllSlugs($p);
}
$wiki = id(new PhrictionDocumentQuery())
->setViewer($viewer)
->withSlugsPrefix($slugs)
->withStatus(PhrictionDocumentQuery::STATUS_OPEN)
->execute();
$phids += array_fuse(mpull($wiki, 'getPHID'));
}
}
// Build Feed stories
$stories = id(new PhabricatorFeedQuery())
->setViewer($viewer)
->withFilterPHIDs($phids)
->withEpochInRange($epoch_min, $epoch_max)
->setLimit($limit)
->execute();
$view = id(new PhabricatorFeedBuilder($stories))
->setUser($viewer)
->buildView();
return $view;
}
}

Event Timeline