Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/diviner/storage/DivinerLiveBook.php
12256 views
1
<?php
2
3
final class DivinerLiveBook extends DivinerDAO
4
implements
5
PhabricatorPolicyInterface,
6
PhabricatorProjectInterface,
7
PhabricatorDestructibleInterface,
8
PhabricatorApplicationTransactionInterface,
9
PhabricatorFulltextInterface {
10
11
protected $name;
12
protected $repositoryPHID;
13
protected $viewPolicy;
14
protected $editPolicy;
15
protected $configurationData = array();
16
17
private $projectPHIDs = self::ATTACHABLE;
18
private $repository = self::ATTACHABLE;
19
20
protected function getConfiguration() {
21
return array(
22
self::CONFIG_AUX_PHID => true,
23
self::CONFIG_SERIALIZATION => array(
24
'configurationData' => self::SERIALIZATION_JSON,
25
),
26
self::CONFIG_COLUMN_SCHEMA => array(
27
'name' => 'text64',
28
'repositoryPHID' => 'phid?',
29
),
30
self::CONFIG_KEY_SCHEMA => array(
31
'key_phid' => null,
32
'phid' => array(
33
'columns' => array('phid'),
34
'unique' => true,
35
),
36
'name' => array(
37
'columns' => array('name'),
38
'unique' => true,
39
),
40
),
41
) + parent::getConfiguration();
42
}
43
44
public function getConfig($key, $default = null) {
45
return idx($this->configurationData, $key, $default);
46
}
47
48
public function setConfig($key, $value) {
49
$this->configurationData[$key] = $value;
50
return $this;
51
}
52
53
public function generatePHID() {
54
return PhabricatorPHID::generateNewPHID(DivinerBookPHIDType::TYPECONST);
55
}
56
57
public function getTitle() {
58
return $this->getConfig('title', $this->getName());
59
}
60
61
public function getShortTitle() {
62
return $this->getConfig('short', $this->getTitle());
63
}
64
65
public function getPreface() {
66
return $this->getConfig('preface');
67
}
68
69
public function getGroupName($group) {
70
$groups = $this->getConfig('groups', array());
71
$spec = idx($groups, $group, array());
72
return idx($spec, 'name', $group);
73
}
74
75
public function attachRepository(PhabricatorRepository $repository = null) {
76
$this->repository = $repository;
77
return $this;
78
}
79
80
public function getRepository() {
81
return $this->assertAttached($this->repository);
82
}
83
84
public function attachProjectPHIDs(array $project_phids) {
85
$this->projectPHIDs = $project_phids;
86
return $this;
87
}
88
89
public function getProjectPHIDs() {
90
return $this->assertAttached($this->projectPHIDs);
91
}
92
93
94
/* -( PhabricatorPolicyInterface )----------------------------------------- */
95
96
97
public function getCapabilities() {
98
return array(
99
PhabricatorPolicyCapability::CAN_VIEW,
100
PhabricatorPolicyCapability::CAN_EDIT,
101
);
102
}
103
104
public function getPolicy($capability) {
105
switch ($capability) {
106
case PhabricatorPolicyCapability::CAN_VIEW:
107
return $this->getViewPolicy();
108
case PhabricatorPolicyCapability::CAN_EDIT:
109
return $this->getEditPolicy();
110
}
111
}
112
113
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
114
return false;
115
}
116
117
118
/* -( PhabricatorDestructibleInterface )----------------------------------- */
119
120
121
public function destroyObjectPermanently(
122
PhabricatorDestructionEngine $engine) {
123
124
$this->openTransaction();
125
$atoms = id(new DivinerAtomQuery())
126
->setViewer($engine->getViewer())
127
->withBookPHIDs(array($this->getPHID()))
128
->execute();
129
130
foreach ($atoms as $atom) {
131
$engine->destroyObject($atom);
132
}
133
134
$this->delete();
135
$this->saveTransaction();
136
}
137
138
139
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
140
141
142
public function getApplicationTransactionEditor() {
143
return new DivinerLiveBookEditor();
144
}
145
146
public function getApplicationTransactionTemplate() {
147
return new DivinerLiveBookTransaction();
148
}
149
150
/* -( PhabricatorFulltextInterface )--------------------------------------- */
151
152
153
public function newFulltextEngine() {
154
return new DivinerLiveBookFulltextEngine();
155
}
156
157
158
}
159
160