Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phrequent/controller/PhrequentTrackController.php
<?php | <?php | ||||
final class PhrequentTrackController | final class PhrequentTrackController | ||||
extends PhrequentController { | extends PhrequentController { | ||||
private $verb; | private $verb; | ||||
private $phid; | private $phid; | ||||
public function willProcessRequest(array $data) { | public function willProcessRequest(array $data) { | ||||
$this->phid = $data['phid']; | $this->phid = $data['phid']; | ||||
$this->verb = $data['verb']; | $this->verb = $data['verb']; | ||||
} | } | ||||
public function processRequest() { | public function processRequest() { | ||||
$request = $this->getRequest(); | $request = $this->getRequest(); | ||||
$user = $request->getUser(); | $user = $request->getUser(); | ||||
$editor = new PhrequentTrackingEditor(); | |||||
$phid = $this->phid; | $phid = $this->phid; | ||||
$handle = id(new PhabricatorHandleQuery()) | $handle = id(new PhabricatorHandleQuery()) | ||||
->setViewer($user) | ->setViewer($user) | ||||
->withPHIDs(array($phid)) | ->withPHIDs(array($phid)) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$this->isStartingTracking() && | if (!$this->isStartingTracking() && | ||||
Show All 31 Lines | if ($request->isDialogFormPost()) { | ||||
$note = $request->getStr('note'); | $note = $request->getStr('note'); | ||||
if (!$epoch_control->isValid() || $timestamp > time()) { | if (!$epoch_control->isValid() || $timestamp > time()) { | ||||
$err[] = pht('Invalid date, please enter a valid non-future date'); | $err[] = pht('Invalid date, please enter a valid non-future date'); | ||||
} | } | ||||
if (!$err) { | if (!$err) { | ||||
if ($this->isStartingTracking()) { | if ($this->isStartingTracking()) { | ||||
$this->startTracking($user, $this->phid, $timestamp); | $editor->startTracking($user, $this->phid, $timestamp); | ||||
} else if ($this->isStoppingTracking()) { | } else if ($this->isStoppingTracking()) { | ||||
$this->stopTracking($user, $this->phid, $timestamp, $note); | $editor->stopTracking($user, $this->phid, $timestamp, $note); | ||||
} | } | ||||
return id(new AphrontRedirectResponse()); | return id(new AphrontRedirectResponse()); | ||||
} | } | ||||
} | } | ||||
$dialog = $this->newDialog() | $dialog = $this->newDialog() | ||||
->setTitle($title_text) | ->setTitle($title_text) | ||||
Show All 28 Lines | final class PhrequentTrackController | ||||
private function isStartingTracking() { | private function isStartingTracking() { | ||||
return $this->verb === 'start'; | return $this->verb === 'start'; | ||||
} | } | ||||
private function isStoppingTracking() { | private function isStoppingTracking() { | ||||
return $this->verb === 'stop'; | return $this->verb === 'stop'; | ||||
} | } | ||||
private function startTracking($user, $phid, $timestamp) { | |||||
$usertime = new PhrequentUserTime(); | |||||
$usertime->setDateStarted($timestamp); | |||||
$usertime->setUserPHID($user->getPHID()); | |||||
$usertime->setObjectPHID($phid); | |||||
$usertime->save(); | |||||
} | |||||
private function stopTracking($user, $phid, $timestamp, $note) { | |||||
if (!PhrequentUserTimeQuery::isUserTrackingObject($user, $phid)) { | |||||
// Don't do anything, it's not being tracked. | |||||
return; | |||||
} | |||||
$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); | |||||
} | |||||
} | } |