mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-11 17:32:41 +01:00
943080a4de
Summary: Ref T3569. Fixes T3567. When figuring out how much time has been spent on an object, subtract "preemptive" events which interrupted the object. Also, make the UI look vaguely sane: {F72773} Test Plan: Added a bunch of unit tests, mucked around in the UI. Reviewers: btrahan Reviewed By: btrahan CC: hach-que, skyronic, aran Maniphest Tasks: T3567, T3569 Differential Revision: https://secure.phabricator.com/D7349
66 lines
1.7 KiB
PHP
66 lines
1.7 KiB
PHP
<?php
|
|
|
|
final class PhrequentUserTime extends PhrequentDAO
|
|
implements PhabricatorPolicyInterface {
|
|
|
|
protected $userPHID;
|
|
protected $objectPHID;
|
|
protected $note;
|
|
protected $dateStarted;
|
|
protected $dateEnded;
|
|
|
|
private $preemptingEvents = self::ATTACHABLE;
|
|
|
|
public function getCapabilities() {
|
|
return array(
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
);
|
|
}
|
|
|
|
public function getPolicy($capability) {
|
|
$policy = PhabricatorPolicies::POLICY_NOONE;
|
|
|
|
switch ($capability) {
|
|
case PhabricatorPolicyCapability::CAN_VIEW:
|
|
// Since it's impossible to perform any meaningful computations with
|
|
// time if a user can't view some of it, visibility on tracked time is
|
|
// unrestricted. If we eventually lock it down, it should be per-user.
|
|
// (This doesn't mean that users can see tracked objects.)
|
|
return PhabricatorPolicies::getMostOpenPolicy();
|
|
}
|
|
|
|
return $policy;
|
|
}
|
|
|
|
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
|
|
return ($viewer->getPHID() == $this->getUserPHID());
|
|
}
|
|
|
|
|
|
public function describeAutomaticCapability($capability) {
|
|
return null;
|
|
}
|
|
|
|
public function attachPreemptingEvents(array $events) {
|
|
$this->preemptingEvents = $events;
|
|
return $this;
|
|
}
|
|
|
|
public function getPreemptingEvents() {
|
|
return $this->assertAttached($this->preemptingEvents);
|
|
}
|
|
|
|
public function isPreempted() {
|
|
if ($this->getDateEnded() !== null) {
|
|
return false;
|
|
}
|
|
foreach ($this->getPreemptingEvents() as $event) {
|
|
if ($event->getDateEnded() === null &&
|
|
$event->getObjectPHID() != $this->getObjectPHID()) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
}
|