Differential D7326 Diff 23742 src/applications/phrequent/conduit/ConduitAPI_phrequent_tracking_Method.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phrequent/conduit/ConduitAPI_phrequent_tracking_Method.php
- This file was added.
<?php | |||||
/** | |||||
*@group conduit | |||||
*/ | |||||
final class ConduitAPI_phrequent_tracking_Method | |||||
extends ConduitAPI_phrequent_Method { | |||||
public function getMethodDescription() { | |||||
return pht( | |||||
'Returns current objects being tracked in Phrequent.'); | |||||
} | |||||
public function getMethodStatus() { | |||||
return self::METHOD_STATUS_UNSTABLE; | |||||
} | |||||
public function defineParamTypes() { | |||||
return array(); | |||||
} | |||||
public function defineReturnType() { | |||||
return 'array'; | |||||
} | |||||
public function defineErrorTypes() { | |||||
return array( | |||||
); | |||||
} | |||||
protected function execute(ConduitAPIRequest $request) { | |||||
$user = $request->getUser(); | |||||
$times = id(new PhrequentUserTimeQuery()) | |||||
->setViewer($user) | |||||
->needPreemptingEvents(true) | |||||
->withUserPHIDs(array($user->getPHID())) | |||||
->execute(); | |||||
$now = time(); | |||||
$ranges = id(new PhrequentTimeBlock($times)) | |||||
->getObjectTimeRanges($now); | |||||
$results = array(); | |||||
foreach ($ranges as $phid => $blocks) { | |||||
$total = 0; | |||||
foreach ($blocks as $block) { | |||||
$total += $block[1] - $block[0]; | |||||
} | |||||
$type = 'inactive'; | |||||
foreach ($blocks as $block) { | |||||
if ($block[1] === $now) { | |||||
if ($block[0] === $block[1]) { | |||||
epriestley: Making this kind of stuff methods on the ranges is probably cleaner, at some point? Maybe… | |||||
$type = 'suspended'; | |||||
} else { | |||||
$type = 'active'; | |||||
} | |||||
break; | |||||
} | |||||
} | |||||
// TODO Make this filter an option on the Conduit method | |||||
if ($type !== 'inactive') { | |||||
$results[] = array( | |||||
'phid' => $phid, | |||||
'time' => $total, | |||||
'type' => $type); | |||||
} | |||||
} | |||||
return $results; | |||||
} | |||||
Not Done Inline ActionsThis should probably return modern pagination stuff, but as long as we fix it before building on top of it it's pretty whatever. epriestley: This should probably return modern pagination stuff, but as long as we fix it before building… | |||||
} |
Making this kind of stuff methods on the ranges is probably cleaner, at some point? Maybe getObjectTimeRanges() reuturns objects instead of a simple map or something.