1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-24 07:42:40 +01:00
phorge-phorge/src/applications/phrequent/editor/PhrequentTrackingEditor.php
James Rhodes 2101c3b689 Conduit APIs to start and stop tracking time in phrequent
Summary:
This adds methods to start and stop tracking any arbitrary PHID in phrequent. Currently, this uses copy-pasted code from PhrequentTrackController. I had to do this because the code to start/stop was not abstracted into a common class.

Once the code to start/stop working is extracted into a re-usable class, the conduit API can use this as well.

Test Plan: I called the functions with a PHID of a task and ensured that the fields in the phrequent database table was being updated correctly.

Reviewers: skyronic, #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: maxhodak, erik.fercak, aran, epriestley, Korvin

Maniphest Tasks: T3569, T3970

Differential Revision: https://secure.phabricator.com/D7326
2014-07-12 11:42:32 +10:00

70 lines
1.7 KiB
PHP

<?php
final class PhrequentTrackingEditor extends PhabricatorEditor {
public function startTracking(PhabricatorUser $user, $phid, $timestamp) {
$usertime = new PhrequentUserTime();
$usertime->setDateStarted($timestamp);
$usertime->setUserPHID($user->getPHID());
$usertime->setObjectPHID($phid);
$usertime->save();
return $phid;
}
public function stopTracking(
PhabricatorUser $user,
$phid,
$timestamp,
$note) {
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 = %d, '.
'usertime.note = %s '.
'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(),
$timestamp,
$note,
$user->getPHID(),
$phid);
return $phid;
}
public function stopTrackingTop(PhabricatorUser $user, $timestamp, $note) {
$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(),
$timestamp,
$note);
}
}