Changeset View
Changeset View
Standalone View
Standalone View
src/applications/nuance/storage/NuanceItem.php
<?php | <?php | ||||
final class NuanceItem | final class NuanceItem | ||||
extends NuanceDAO | extends NuanceDAO | ||||
implements | implements | ||||
PhabricatorPolicyInterface, | PhabricatorPolicyInterface, | ||||
PhabricatorApplicationTransactionInterface { | PhabricatorApplicationTransactionInterface { | ||||
const STATUS_OPEN = 0; | const STATUS_IMPORTING = 'importing'; | ||||
const STATUS_ASSIGNED = 10; | const STATUS_OPEN = 'open'; | ||||
const STATUS_CLOSED = 20; | const STATUS_ASSIGNED = 'assigned'; | ||||
const STATUS_CLOSED = 'closed'; | |||||
protected $status; | protected $status; | ||||
protected $ownerPHID; | protected $ownerPHID; | ||||
protected $requestorPHID; | protected $requestorPHID; | ||||
protected $sourcePHID; | protected $sourcePHID; | ||||
protected $sourceLabel; | protected $queuePHID; | ||||
protected $itemType; | |||||
protected $itemKey; | |||||
protected $itemContainerKey; | |||||
protected $data = array(); | protected $data = array(); | ||||
protected $mailKey; | protected $mailKey; | ||||
protected $queuePHID; | |||||
private $source = self::ATTACHABLE; | private $source = self::ATTACHABLE; | ||||
public static function initializeNewItem() { | public static function initializeNewItem() { | ||||
return id(new NuanceItem()) | return id(new NuanceItem()) | ||||
->setStatus(self::STATUS_OPEN); | ->setStatus(self::STATUS_OPEN); | ||||
} | } | ||||
protected function getConfiguration() { | protected function getConfiguration() { | ||||
return array( | return array( | ||||
self::CONFIG_AUX_PHID => true, | self::CONFIG_AUX_PHID => true, | ||||
self::CONFIG_SERIALIZATION => array( | self::CONFIG_SERIALIZATION => array( | ||||
'data' => self::SERIALIZATION_JSON, | 'data' => self::SERIALIZATION_JSON, | ||||
), | ), | ||||
self::CONFIG_COLUMN_SCHEMA => array( | self::CONFIG_COLUMN_SCHEMA => array( | ||||
'ownerPHID' => 'phid?', | 'ownerPHID' => 'phid?', | ||||
'sourceLabel' => 'text255?', | 'requestorPHID' => 'phid?', | ||||
'status' => 'uint32', | 'queuePHID' => 'phid?', | ||||
'itemType' => 'text64', | |||||
'itemKey' => 'text64', | |||||
'itemContainerKey' => 'text64?', | |||||
'status' => 'text32', | |||||
'mailKey' => 'bytes20', | 'mailKey' => 'bytes20', | ||||
), | ), | ||||
self::CONFIG_KEY_SCHEMA => array( | self::CONFIG_KEY_SCHEMA => array( | ||||
'key_source' => array( | 'key_source' => array( | ||||
'columns' => array('sourcePHID', 'status'), | 'columns' => array('sourcePHID', 'status'), | ||||
), | ), | ||||
'key_owner' => array( | 'key_owner' => array( | ||||
'columns' => array('ownerPHID', 'status'), | 'columns' => array('ownerPHID', 'status'), | ||||
), | ), | ||||
'key_requestor' => array( | 'key_requestor' => array( | ||||
'columns' => array('requestorPHID', 'status'), | 'columns' => array('requestorPHID', 'status'), | ||||
), | ), | ||||
'key_queue' => array( | 'key_queue' => array( | ||||
'columns' => array('queuePHID', 'status'), | 'columns' => array('queuePHID', 'status'), | ||||
), | ), | ||||
'key_container' => array( | |||||
'columns' => array('sourcePHID', 'itemContainerKey'), | |||||
), | |||||
'key_item' => array( | |||||
'columns' => array('sourcePHID', 'itemKey'), | |||||
'unique' => true, | |||||
), | |||||
), | ), | ||||
) + parent::getConfiguration(); | ) + parent::getConfiguration(); | ||||
} | } | ||||
public function generatePHID() { | public function generatePHID() { | ||||
return PhabricatorPHID::generateNewPHID( | return PhabricatorPHID::generateNewPHID( | ||||
NuanceItemPHIDType::TYPECONST); | NuanceItemPHIDType::TYPECONST); | ||||
} | } | ||||
public function save() { | public function save() { | ||||
if (!$this->getMailKey()) { | if (!$this->getMailKey()) { | ||||
$this->setMailKey(Filesystem::readRandomCharacters(20)); | $this->setMailKey(Filesystem::readRandomCharacters(20)); | ||||
} | } | ||||
return parent::save(); | return parent::save(); | ||||
} | } | ||||
public function getURI() { | public function getURI() { | ||||
return '/nuance/item/view/'.$this->getID().'/'; | return '/nuance/item/view/'.$this->getID().'/'; | ||||
} | } | ||||
public function getLabel(PhabricatorUser $viewer) { | public function getLabel(PhabricatorUser $viewer) { | ||||
// this is generated at the time the item is created based on | return pht('TODO: An Item'); | ||||
// the configuration from the item source. It is typically | |||||
// something like 'Twitter'. | |||||
$source_label = $this->getSourceLabel(); | |||||
return pht( | |||||
'Item via %s @ %s.', | |||||
$source_label, | |||||
phabricator_datetime($this->getDateCreated(), $viewer)); | |||||
} | } | ||||
public function getRequestor() { | public function getRequestor() { | ||||
return $this->assertAttached($this->requestor); | return $this->assertAttached($this->requestor); | ||||
} | } | ||||
public function attachRequestor(NuanceRequestor $requestor) { | public function attachRequestor(NuanceRequestor $requestor) { | ||||
return $this->requestor = $requestor; | return $this->requestor = $requestor; | ||||
} | } | ||||
public function getSource() { | public function getSource() { | ||||
return $this->assertAttached($this->source); | return $this->assertAttached($this->source); | ||||
} | } | ||||
public function attachSource(NuanceSource $source) { | public function attachSource(NuanceSource $source) { | ||||
$this->source = $source; | $this->source = $source; | ||||
} | } | ||||
public function getNuanceProperty($key, $default = null) { | public function getItemProperty($key, $default = null) { | ||||
return idx($this->data, $key, $default); | return idx($this->data, $key, $default); | ||||
} | } | ||||
public function setNuanceProperty($key, $value) { | public function setItemProperty($key, $value) { | ||||
$this->data[$key] = $value; | $this->data[$key] = $value; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getCapabilities() { | public function getCapabilities() { | ||||
return array( | return array( | ||||
PhabricatorPolicyCapability::CAN_VIEW, | PhabricatorPolicyCapability::CAN_VIEW, | ||||
PhabricatorPolicyCapability::CAN_EDIT, | PhabricatorPolicyCapability::CAN_EDIT, | ||||
Show All 15 Lines | switch ($capability) { | ||||
case PhabricatorPolicyCapability::CAN_VIEW: | case PhabricatorPolicyCapability::CAN_VIEW: | ||||
return pht('Owners of an item can always view it.'); | return pht('Owners of an item can always view it.'); | ||||
case PhabricatorPolicyCapability::CAN_EDIT: | case PhabricatorPolicyCapability::CAN_EDIT: | ||||
return pht('Owners of an item can always edit it.'); | return pht('Owners of an item can always edit it.'); | ||||
} | } | ||||
return null; | return null; | ||||
} | } | ||||
public function toDictionary() { | public function getDisplayName() { | ||||
return array( | return pht('An Item'); | ||||
'id' => $this->getID(), | |||||
'phid' => $this->getPHID(), | |||||
'ownerPHID' => $this->getOwnerPHID(), | |||||
'requestorPHID' => $this->getRequestorPHID(), | |||||
'sourcePHID' => $this->getSourcePHID(), | |||||
'sourceLabel' => $this->getSourceLabel(), | |||||
'dateCreated' => $this->getDateCreated(), | |||||
'dateModified' => $this->getDateModified(), | |||||
); | |||||
} | } | ||||
/* -( PhabricatorApplicationTransactionInterface )------------------------- */ | /* -( PhabricatorApplicationTransactionInterface )------------------------- */ | ||||
public function getApplicationTransactionEditor() { | public function getApplicationTransactionEditor() { | ||||
return new NuanceItemEditor(); | return new NuanceItemEditor(); | ||||
Show All 17 Lines |