[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/phrequent/editor/ -> PhrequentTrackingEditor.php (source)

   1  <?php
   2  
   3  final class PhrequentTrackingEditor extends PhabricatorEditor {
   4  
   5    public function startTracking(PhabricatorUser $user, $phid, $timestamp) {
   6      $usertime = new PhrequentUserTime();
   7      $usertime->setDateStarted($timestamp);
   8      $usertime->setUserPHID($user->getPHID());
   9      $usertime->setObjectPHID($phid);
  10      $usertime->save();
  11  
  12      return $phid;
  13    }
  14  
  15    public function stopTracking(
  16      PhabricatorUser $user,
  17      $phid,
  18      $timestamp,
  19      $note) {
  20  
  21      if (!PhrequentUserTimeQuery::isUserTrackingObject($user, $phid)) {
  22        // Don't do anything, it's not being tracked.
  23        return null;
  24      }
  25  
  26      $usertime_dao = new PhrequentUserTime();
  27      $conn = $usertime_dao->establishConnection('r');
  28  
  29      queryfx(
  30        $conn,
  31        'UPDATE %T usertime '.
  32        'SET usertime.dateEnded = %d, '.
  33        'usertime.note = %s '.
  34        'WHERE usertime.userPHID = %s '.
  35        'AND usertime.objectPHID = %s '.
  36        'AND usertime.dateEnded IS NULL '.
  37        'ORDER BY usertime.dateStarted, usertime.id DESC '.
  38        'LIMIT 1',
  39        $usertime_dao->getTableName(),
  40        $timestamp,
  41        $note,
  42        $user->getPHID(),
  43        $phid);
  44  
  45      return $phid;
  46    }
  47  
  48    public function stopTrackingTop(PhabricatorUser $user, $timestamp, $note) {
  49      $times = id(new PhrequentUserTimeQuery())
  50        ->setViewer($user)
  51        ->withUserPHIDs(array($user->getPHID()))
  52        ->withEnded(PhrequentUserTimeQuery::ENDED_NO)
  53        ->setOrder(PhrequentUserTimeQuery::ORDER_STARTED_DESC)
  54        ->execute();
  55  
  56      if (count($times) === 0) {
  57        // Nothing to stop tracking.
  58        return null;
  59      }
  60  
  61      $current = head($times);
  62  
  63      return $this->stopTracking(
  64        $user,
  65        $current->getObjectPHID(),
  66        $timestamp,
  67        $note);
  68    }
  69  
  70  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1