6 PhabricatorPolicyInterface
,
7 PhabricatorApplicationTransactionInterface
{
9 const STATUS_IMPORTING
= 'importing';
10 const STATUS_ROUTING
= 'routing';
11 const STATUS_OPEN
= 'open';
12 const STATUS_CLOSED
= 'closed';
16 protected $requestorPHID;
17 protected $sourcePHID;
21 protected $itemContainerKey;
22 protected $data = array();
25 private $queue = self
::ATTACHABLE
;
26 private $source = self
::ATTACHABLE
;
27 private $implementation = self
::ATTACHABLE
;
29 public static function initializeNewItem($item_type) {
31 // TODO: Validate that the type is valid, and construct and attach it.
33 return id(new NuanceItem())
34 ->setItemType($item_type)
35 ->setStatus(self
::STATUS_OPEN
);
38 protected function getConfiguration() {
40 self
::CONFIG_AUX_PHID
=> true,
41 self
::CONFIG_SERIALIZATION
=> array(
42 'data' => self
::SERIALIZATION_JSON
,
44 self
::CONFIG_COLUMN_SCHEMA
=> array(
45 'ownerPHID' => 'phid?',
46 'requestorPHID' => 'phid?',
47 'queuePHID' => 'phid?',
48 'itemType' => 'text64',
49 'itemKey' => 'text64?',
50 'itemContainerKey' => 'text64?',
52 'mailKey' => 'bytes20',
54 self
::CONFIG_KEY_SCHEMA
=> array(
55 'key_source' => array(
56 'columns' => array('sourcePHID', 'status'),
59 'columns' => array('ownerPHID', 'status'),
61 'key_requestor' => array(
62 'columns' => array('requestorPHID', 'status'),
65 'columns' => array('queuePHID', 'status'),
67 'key_container' => array(
68 'columns' => array('sourcePHID', 'itemContainerKey'),
71 'columns' => array('sourcePHID', 'itemKey'),
75 ) + parent
::getConfiguration();
78 public function generatePHID() {
79 return PhabricatorPHID
::generateNewPHID(
80 NuanceItemPHIDType
::TYPECONST
);
83 public function save() {
84 if (!$this->getMailKey()) {
85 $this->setMailKey(Filesystem
::readRandomCharacters(20));
87 return parent
::save();
90 public function getURI() {
91 return '/nuance/item/view/'.$this->getID().'/';
94 public function getSource() {
95 return $this->assertAttached($this->source
);
98 public function attachSource(NuanceSource
$source) {
99 $this->source
= $source;
102 public function getItemProperty($key, $default = null) {
103 return idx($this->data
, $key, $default);
106 public function setItemProperty($key, $value) {
107 $this->data
[$key] = $value;
111 public function getCapabilities() {
113 PhabricatorPolicyCapability
::CAN_VIEW
,
114 PhabricatorPolicyCapability
::CAN_EDIT
,
118 public function getPolicy($capability) {
119 // TODO - this should be based on the queues the item currently resides in
120 return PhabricatorPolicies
::POLICY_USER
;
123 public function hasAutomaticCapability($capability, PhabricatorUser
$viewer) {
124 // TODO - requestors should get auto access too!
125 return $viewer->getPHID() == $this->ownerPHID
;
128 public function describeAutomaticCapability($capability) {
129 switch ($capability) {
130 case PhabricatorPolicyCapability
::CAN_VIEW
:
131 return pht('Owners of an item can always view it.');
132 case PhabricatorPolicyCapability
::CAN_EDIT
:
133 return pht('Owners of an item can always edit it.');
138 public function getDisplayName() {
139 return $this->getImplementation()->getItemDisplayName($this);
142 public function scheduleUpdate() {
143 PhabricatorWorker
::scheduleTask(
144 'NuanceItemUpdateWorker',
146 'itemPHID' => $this->getPHID(),
149 'objectPHID' => $this->getPHID(),
153 public function issueCommand(
156 array $parameters = array()) {
158 $command = id(NuanceItemCommand
::initializeNewCommand())
159 ->setItemPHID($this->getPHID())
160 ->setAuthorPHID($author_phid)
161 ->setCommand($command)
162 ->setParameters($parameters)
165 $this->scheduleUpdate();
170 public function getImplementation() {
171 return $this->assertAttached($this->implementation
);
174 public function attachImplementation(NuanceItemType
$type) {
175 $this->implementation
= $type;
179 public function getQueue() {
180 return $this->assertAttached($this->queue
);
183 public function attachQueue(NuanceQueue
$queue = null) {
184 $this->queue
= $queue;
189 /* -( PhabricatorApplicationTransactionInterface )------------------------- */
192 public function getApplicationTransactionEditor() {
193 return new NuanceItemEditor();
196 public function getApplicationTransactionTemplate() {
197 return new NuanceItemTransaction();