Remove product literal strings in "pht()", part 18
[phabricator.git] / src / applications / nuance / storage / NuanceItem.php
blobf182e175801aec0ac38b0099e80cdf70dbec7af3
1 <?php
3 final class NuanceItem
4 extends NuanceDAO
5 implements
6 PhabricatorPolicyInterface,
7 PhabricatorApplicationTransactionInterface {
9 const STATUS_IMPORTING = 'importing';
10 const STATUS_ROUTING = 'routing';
11 const STATUS_OPEN = 'open';
12 const STATUS_CLOSED = 'closed';
14 protected $status;
15 protected $ownerPHID;
16 protected $requestorPHID;
17 protected $sourcePHID;
18 protected $queuePHID;
19 protected $itemType;
20 protected $itemKey;
21 protected $itemContainerKey;
22 protected $data = array();
23 protected $mailKey;
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() {
39 return array(
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?',
51 'status' => 'text32',
52 'mailKey' => 'bytes20',
54 self::CONFIG_KEY_SCHEMA => array(
55 'key_source' => array(
56 'columns' => array('sourcePHID', 'status'),
58 'key_owner' => array(
59 'columns' => array('ownerPHID', 'status'),
61 'key_requestor' => array(
62 'columns' => array('requestorPHID', 'status'),
64 'key_queue' => array(
65 'columns' => array('queuePHID', 'status'),
67 'key_container' => array(
68 'columns' => array('sourcePHID', 'itemContainerKey'),
70 'key_item' => array(
71 'columns' => array('sourcePHID', 'itemKey'),
72 'unique' => true,
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;
108 return $this;
111 public function getCapabilities() {
112 return array(
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.');
135 return null;
138 public function getDisplayName() {
139 return $this->getImplementation()->getItemDisplayName($this);
142 public function scheduleUpdate() {
143 PhabricatorWorker::scheduleTask(
144 'NuanceItemUpdateWorker',
145 array(
146 'itemPHID' => $this->getPHID(),
148 array(
149 'objectPHID' => $this->getPHID(),
153 public function issueCommand(
154 $author_phid,
155 $command,
156 array $parameters = array()) {
158 $command = id(NuanceItemCommand::initializeNewCommand())
159 ->setItemPHID($this->getPHID())
160 ->setAuthorPHID($author_phid)
161 ->setCommand($command)
162 ->setParameters($parameters)
163 ->save();
165 $this->scheduleUpdate();
167 return $this;
170 public function getImplementation() {
171 return $this->assertAttached($this->implementation);
174 public function attachImplementation(NuanceItemType $type) {
175 $this->implementation = $type;
176 return $this;
179 public function getQueue() {
180 return $this->assertAttached($this->queue);
183 public function attachQueue(NuanceQueue $queue = null) {
184 $this->queue = $queue;
185 return $this;
189 /* -( PhabricatorApplicationTransactionInterface )------------------------- */
192 public function getApplicationTransactionEditor() {
193 return new NuanceItemEditor();
196 public function getApplicationTransactionTemplate() {
197 return new NuanceItemTransaction();