Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phrequent/editor/PhrequentTrackingEditor.php
- This file was added.
<?php | |||||
final class PhrequentTrackingEditor extends PhabricatorEditor { | |||||
epriestley: Add `final`. | |||||
public function startTracking(PhabricatorUser $user, $phid) { | |||||
$usertime = new PhrequentUserTime(); | |||||
Not Done Inline ActionsTypehint PhabricatorUser for $user. epriestley: Typehint `PhabricatorUser` for `$user`. | |||||
$usertime->setDateStarted(time()); | |||||
$usertime->setUserPHID($user->getPHID()); | |||||
$usertime->setObjectPHID($phid); | |||||
$usertime->save(); | |||||
return $phid; | |||||
} | |||||
public function stopTracking(PhabricatorUser $user, $phid) { | |||||
if (!PhrequentUserTimeQuery::isUserTrackingObject($user, $phid)) { | |||||
// Don't do anything, it's not being tracked. | |||||
return null; | |||||
} | |||||
$usertime_dao = new PhrequentUserTime(); | |||||
$conn = $usertime_dao->establishConnection('r'); | |||||
queryfx( | |||||
$conn, | |||||
'UPDATE %T usertime '. | |||||
'SET usertime.dateEnded = UNIX_TIMESTAMP() '. | |||||
'WHERE usertime.userPHID = %s '. | |||||
'AND usertime.objectPHID = %s '. | |||||
'AND usertime.dateEnded IS NULL '. | |||||
'ORDER BY usertime.dateStarted, usertime.id DESC '. | |||||
'LIMIT 1', | |||||
$usertime_dao->getTableName(), | |||||
$user->getPHID(), | |||||
$phid); | |||||
return $phid; | |||||
} | |||||
public function stopTrackingTop(PhabricatorUser $user) { | |||||
$times = id(new PhrequentUserTimeQuery()) | |||||
->setViewer($user) | |||||
->withUserPHIDs(array($user->getPHID())) | |||||
->withEnded(PhrequentUserTimeQuery::ENDED_NO) | |||||
->setOrder(PhrequentUserTimeQuery::ORDER_STARTED_DESC) | |||||
->execute(); | |||||
if (count($times) === 0) { | |||||
// Nothing to stop tracking. | |||||
return null; | |||||
} | |||||
$current = head($times); | |||||
return $this->stopTracking($user, $current->getObjectPHID()); | |||||
} | |||||
} |
Add final.