Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F72975
D7346.diff
All Users
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
7 KB
Referenced Files
None
Subscribers
None
D7346.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -1957,6 +1957,7 @@
'PhrequentController' => 'applications/phrequent/controller/PhrequentController.php',
'PhrequentDAO' => 'applications/phrequent/storage/PhrequentDAO.php',
'PhrequentListController' => 'applications/phrequent/controller/PhrequentListController.php',
+ 'PhrequentReportController' => 'applications/phrequent/controller/PhrequentReportController.php',
'PhrequentSearchEngine' => 'applications/phrequent/query/PhrequentSearchEngine.php',
'PhrequentTrackController' => 'applications/phrequent/controller/PhrequentTrackController.php',
'PhrequentTrackableInterface' => 'applications/phrequent/interface/PhrequentTrackableInterface.php',
@@ -4229,6 +4230,7 @@
0 => 'PhrequentController',
1 => 'PhabricatorApplicationSearchResultsControllerInterface',
),
+ 'PhrequentReportController' => 'PhabricatorController',
'PhrequentSearchEngine' => 'PhabricatorApplicationSearchEngine',
'PhrequentTrackController' => 'PhrequentController',
'PhrequentUIEventListener' => 'PhutilEventListener',
diff --git a/src/applications/phrequent/application/PhabricatorApplicationPhrequent.php b/src/applications/phrequent/application/PhabricatorApplicationPhrequent.php
--- a/src/applications/phrequent/application/PhabricatorApplicationPhrequent.php
+++ b/src/applications/phrequent/application/PhabricatorApplicationPhrequent.php
@@ -37,7 +37,8 @@
'/phrequent/' => array(
'(?:query/(?P<queryKey>[^/]+)/)?' => 'PhrequentListController',
'track/(?P<verb>[a-z]+)/(?P<phid>[^/]+)/'
- => 'PhrequentTrackController'
+ => 'PhrequentTrackController',
+ 'report/(?:(?P<view>\w+)/)?' => 'PhrequentReportController',
),
);
}
diff --git a/src/applications/phrequent/controller/PhrequentController.php b/src/applications/phrequent/controller/PhrequentController.php
--- a/src/applications/phrequent/controller/PhrequentController.php
+++ b/src/applications/phrequent/controller/PhrequentController.php
@@ -12,6 +12,12 @@
->setViewer($user)
->addNavigationItems($nav->getMenu());
+ if ($user->isLoggedIn()) {
+ // For now, don't give logged-out users access to reports.
+ $nav->addLabel(pht('Reports'));
+ $nav->addFilter('report', pht('Reports'));
+ }
+
$nav->selectFilter(null);
return $nav;
diff --git a/src/applications/phrequent/controller/PhrequentReportController.php b/src/applications/phrequent/controller/PhrequentReportController.php
new file mode 100644
--- /dev/null
+++ b/src/applications/phrequent/controller/PhrequentReportController.php
@@ -0,0 +1,102 @@
+<?php
+
+class PhrequentReportController extends PhabricatorController {
+ private $view;
+
+ public function willProcessRequest(array $data) {
+ $this->view = idx($data, 'view');
+ }
+
+
+ public function processRequest() {
+ $request = $this->getRequest();
+ $user = $request->getUser();
+
+ $nav = new AphrontSideNavFilterView();
+ $nav->setBaseURI(new PhutilURI('/phrequent/report/'));
+ $nav->addLabel(pht('Standard Reports'));
+ $nav->addFilter('user', pht('By User'));
+
+ $this->view = $nav->selectFilter($this->view, 'user');
+
+ switch ($this->view) {
+ case 'user':
+ $core = $this->renderUserReport();
+ break;
+ default:
+ return new Aphront404Response();
+ }
+
+ $nav->appendChild($core);
+ $nav->setCrumbs(
+ $this->buildApplicationCrumbs()
+ ->addCrumb(
+ id(new PhabricatorCrumbView())
+ ->setName(pht('Reports'))));
+
+ return $this->buildApplicationPage(
+ $nav,
+ array(
+ 'title' => pht('Phrequent Reports'),
+ ));
+ }
+
+ public function renderUserReport() {
+ $request = $this->getRequest();
+ $user = $request->getUser();
+
+ $cname = array();
+ $cname[] = array(
+ javelin_tag(
+ 'span',
+ array(
+ 'sigil' => 'has-tooltip',
+ 'meta' => array(
+ 'tip' => pht('User Name.'),
+ 'size' => 200,
+ ),
+ ),
+ pht('User'))
+ );
+ $cname[] = array(
+ javelin_tag(
+ 'span',
+ array(
+ 'sigil' => 'has-tooltip',
+ 'meta' => array(
+ 'tip' => pht('Total time logged.'),
+ 'size' => 200,
+ ),
+ ),
+ pht('Total Time'))
+ );
+ $rows = array();
+
+ // Get a list of users who are tracking time
+ $userPHIDs = PhrequentUserTimeQuery::getAllUsersTrackingTime();
+
+ // get the handles of the all the users
+ $handles = id(new PhabricatorHandleQuery())
+ ->setViewer($user)
+ ->withPHIDs($userPHIDs)
+ ->execute();
+
+ foreach ($userPHIDs as $userID) {
+ $count_for_user = PhrequentUserTimeQuery::getTotalTimeSpentByUser ($userID);
+ $user_name = $handles[$userID]->getName ();
+
+ $rows[] = array($user_name, $count_for_user);
+ }
+
+ $table = new AphrontTableView($rows);
+ $table->setHeaders($cname);
+ $header = pht('Amount of time logged by each user');
+
+ $panel = new AphrontPanelView();
+ $panel->setHeader($header);
+ $panel->appendChild($table);
+
+
+ return array($panel);
+ }
+}
diff --git a/src/applications/phrequent/query/PhrequentUserTimeQuery.php b/src/applications/phrequent/query/PhrequentUserTimeQuery.php
--- a/src/applications/phrequent/query/PhrequentUserTimeQuery.php
+++ b/src/applications/phrequent/query/PhrequentUserTimeQuery.php
@@ -204,6 +204,23 @@
return $count['N'] > 0;
}
+ public static function getAllUsersTrackingTime() {
+ $usertime_dao = new PhrequentUserTime();
+ $conn = $usertime_dao->establishConnection('r');
+
+ $userPHIDs = queryfx_all(
+ $conn,
+ 'SELECT DISTINCT(usertime.userPHID) userPHID FROM %T usertime',
+ $usertime_dao->getTableName());
+
+ $result = array();
+ foreach ($userPHIDs as $row) {
+ $result[] = $row['userPHID'];
+ }
+
+ return $result;
+ }
+
public static function loadUserStack(PhabricatorUser $user) {
if (!$user->isLoggedIn()) {
return array();
@@ -244,6 +261,35 @@
return $sum_ended['N'] + $sum_not_ended['N'];
}
+ public static function getTotalTimeSpentByUser($phid) {
+ $usertime_dao = new PhrequentUserTime();
+ $conn = $usertime_dao->establishConnection('r');
+
+ // First calculate all the time spent where the
+ // usertime blocks have ended.
+ $sum_ended = queryfx_one(
+ $conn,
+ 'SELECT SUM(usertime.dateEnded - usertime.dateStarted) N '.
+ 'FROM %T usertime '.
+ 'WHERE usertime.userPHID = %s '.
+ 'AND usertime.dateEnded IS NOT NULL',
+ $usertime_dao->getTableName(),
+ $phid);
+
+ // Now calculate the time spent where the usertime
+ // blocks have not yet ended.
+ $sum_not_ended = queryfx_one(
+ $conn,
+ 'SELECT SUM(UNIX_TIMESTAMP() - usertime.dateStarted) N '.
+ 'FROM %T usertime '.
+ 'WHERE usertime.userPHID = %s '.
+ 'AND usertime.dateEnded IS NULL',
+ $usertime_dao->getTableName(),
+ $phid);
+
+ return $sum_ended['N'] + $sum_not_ended['N'];
+ }
+
public static function getUserTimeSpentOnObject(
PhabricatorUser $user,
$phid) {
File Metadata
Details
Attached
Mime Type
text/x-diff
Storage Engine
amazon-s3
Storage Format
Raw Data
Storage Handle
phabricator/pm/mo/3a64krcjmhwxe5sc
Default Alt Text
D7346.diff (7 KB)
Attached To
Mode
D7346: Very CRUDE implementation of reporting for phrequent
Attached
Detach File
Event Timeline
Log In to Comment