3 final class NuanceSource
extends NuanceDAO
5 PhabricatorApplicationTransactionInterface
,
6 PhabricatorPolicyInterface
,
7 PhabricatorNgramsInterface
{
11 protected $data = array();
13 protected $viewPolicy;
14 protected $editPolicy;
15 protected $defaultQueuePHID;
16 protected $isDisabled;
18 private $definition = self
::ATTACHABLE
;
20 protected function getConfiguration() {
22 self
::CONFIG_AUX_PHID
=> true,
23 self
::CONFIG_SERIALIZATION
=> array(
24 'data' => self
::SERIALIZATION_JSON
,
26 self
::CONFIG_COLUMN_SCHEMA
=> array(
29 'mailKey' => 'bytes20',
30 'isDisabled' => 'bool',
32 self
::CONFIG_KEY_SCHEMA
=> array(
34 'columns' => array('type', 'dateModified'),
37 ) + parent
::getConfiguration();
40 public function generatePHID() {
41 return PhabricatorPHID
::generateNewPHID(NuanceSourcePHIDType
::TYPECONST
);
44 public function save() {
45 if (!$this->getMailKey()) {
46 $this->setMailKey(Filesystem
::readRandomCharacters(20));
48 return parent
::save();
51 public function getURI() {
52 return '/nuance/source/view/'.$this->getID().'/';
55 public static function initializeNewSource(
56 PhabricatorUser
$actor,
57 NuanceSourceDefinition
$definition) {
58 $app = id(new PhabricatorApplicationQuery())
60 ->withClasses(array('PhabricatorNuanceApplication'))
63 $view_policy = $app->getPolicy(
64 NuanceSourceDefaultViewCapability
::CAPABILITY
);
65 $edit_policy = $app->getPolicy(
66 NuanceSourceDefaultEditCapability
::CAPABILITY
);
68 return id(new NuanceSource())
69 ->setViewPolicy($view_policy)
70 ->setEditPolicy($edit_policy)
71 ->setType($definition->getSourceTypeConstant())
72 ->attachDefinition($definition)
76 public function getDefinition() {
77 return $this->assertAttached($this->definition
);
80 public function attachDefinition(NuanceSourceDefinition
$definition) {
81 $this->definition
= $definition;
85 public function getSourceProperty($key, $default = null) {
86 return idx($this->data
, $key, $default);
89 public function setSourceProperty($key, $value) {
90 $this->data
[$key] = $value;
95 /* -( PhabricatorApplicationTransactionInterface )------------------------- */
98 public function getApplicationTransactionEditor() {
99 return new NuanceSourceEditor();
102 public function getApplicationTransactionTemplate() {
103 return new NuanceSourceTransaction();
107 /* -( PhabricatorPolicyInterface )----------------------------------------- */
110 public function getCapabilities() {
112 PhabricatorPolicyCapability
::CAN_VIEW
,
113 PhabricatorPolicyCapability
::CAN_EDIT
,
117 public function getPolicy($capability) {
118 switch ($capability) {
119 case PhabricatorPolicyCapability
::CAN_VIEW
:
120 return $this->getViewPolicy();
121 case PhabricatorPolicyCapability
::CAN_EDIT
:
122 return $this->getEditPolicy();
126 public function hasAutomaticCapability($capability, PhabricatorUser
$viewer) {
131 /* -( PhabricatorNgramsInterface )----------------------------------------- */
134 public function newNgrams() {
136 id(new NuanceSourceNameNgrams())
137 ->setValue($this->getName()),