2013-05-20 19:18:26 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class DivinerLiveBook extends DivinerDAO
|
2015-02-11 20:55:07 +01:00
|
|
|
implements
|
|
|
|
PhabricatorPolicyInterface,
|
2015-06-16 23:09:53 +02:00
|
|
|
PhabricatorProjectInterface,
|
|
|
|
PhabricatorDestructibleInterface,
|
|
|
|
PhabricatorApplicationTransactionInterface {
|
2013-05-20 19:18:26 +02:00
|
|
|
|
|
|
|
protected $name;
|
|
|
|
protected $viewPolicy;
|
2015-06-16 23:09:53 +02:00
|
|
|
protected $editPolicy;
|
2013-06-04 20:15:34 +02:00
|
|
|
protected $configurationData = array();
|
2013-05-20 19:18:26 +02:00
|
|
|
|
2015-06-16 23:09:53 +02:00
|
|
|
private $projectPHIDs = self::ATTACHABLE;
|
|
|
|
|
2015-01-13 20:47:05 +01:00
|
|
|
protected function getConfiguration() {
|
2013-05-20 19:18:26 +02:00
|
|
|
return array(
|
|
|
|
self::CONFIG_AUX_PHID => true,
|
2013-06-04 20:15:34 +02:00
|
|
|
self::CONFIG_SERIALIZATION => array(
|
|
|
|
'configurationData' => self::SERIALIZATION_JSON,
|
|
|
|
),
|
2014-10-01 16:53:12 +02:00
|
|
|
self::CONFIG_COLUMN_SCHEMA => array(
|
|
|
|
'name' => 'text64',
|
|
|
|
),
|
|
|
|
self::CONFIG_KEY_SCHEMA => array(
|
|
|
|
'key_phid' => null,
|
|
|
|
'phid' => array(
|
|
|
|
'columns' => array('phid'),
|
|
|
|
'unique' => true,
|
|
|
|
),
|
|
|
|
'name' => array(
|
|
|
|
'columns' => array('name'),
|
|
|
|
'unique' => true,
|
|
|
|
),
|
|
|
|
),
|
2013-05-20 19:18:26 +02:00
|
|
|
) + parent::getConfiguration();
|
|
|
|
}
|
|
|
|
|
2013-06-04 20:15:34 +02:00
|
|
|
public function getConfig($key, $default = null) {
|
|
|
|
return idx($this->configurationData, $key, $default);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setConfig($key, $value) {
|
|
|
|
$this->configurationData[$key] = $value;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-05-20 19:18:26 +02:00
|
|
|
public function generatePHID() {
|
2015-06-04 23:27:48 +02:00
|
|
|
return PhabricatorPHID::generateNewPHID(DivinerBookPHIDType::TYPECONST);
|
2013-05-20 19:18:26 +02:00
|
|
|
}
|
|
|
|
|
2013-06-04 20:15:34 +02:00
|
|
|
public function getTitle() {
|
|
|
|
return $this->getConfig('title', $this->getName());
|
|
|
|
}
|
|
|
|
|
2013-06-06 17:36:51 +02:00
|
|
|
public function getShortTitle() {
|
|
|
|
return $this->getConfig('short', $this->getTitle());
|
|
|
|
}
|
|
|
|
|
2014-03-05 21:08:01 +01:00
|
|
|
public function getPreface() {
|
|
|
|
return $this->getConfig('preface');
|
|
|
|
}
|
|
|
|
|
2013-06-06 17:36:51 +02:00
|
|
|
public function getGroupName($group) {
|
2014-12-17 04:34:55 +01:00
|
|
|
$groups = $this->getConfig('groups', array());
|
2013-06-06 17:36:51 +02:00
|
|
|
$spec = idx($groups, $group, array());
|
2013-07-28 22:07:30 +02:00
|
|
|
return idx($spec, 'name', $group);
|
2013-06-06 17:36:51 +02:00
|
|
|
}
|
|
|
|
|
2015-06-16 23:09:53 +02:00
|
|
|
public function attachProjectPHIDs(array $project_phids) {
|
|
|
|
$this->projectPHIDs = $project_phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getProjectPHIDs() {
|
|
|
|
return $this->assertAttached($this->projectPHIDs);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-20 19:18:26 +02:00
|
|
|
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
|
|
|
|
2015-06-16 23:09:53 +02:00
|
|
|
|
2013-05-20 19:18:26 +02:00
|
|
|
public function getCapabilities() {
|
|
|
|
return array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
2015-06-16 23:09:53 +02:00
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
2013-05-20 19:18:26 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPolicy($capability) {
|
2015-06-16 23:09:53 +02:00
|
|
|
switch ($capability) {
|
|
|
|
case PhabricatorPolicyCapability::CAN_VIEW:
|
|
|
|
return $this->getViewPolicy();
|
|
|
|
case PhabricatorPolicyCapability::CAN_EDIT:
|
|
|
|
return $this->getEditPolicy();
|
|
|
|
}
|
2013-05-20 19:18:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
|
2015-06-16 23:09:53 +02:00
|
|
|
return false;
|
2013-05-20 19:18:26 +02:00
|
|
|
}
|
|
|
|
|
2013-09-27 17:43:41 +02:00
|
|
|
public function describeAutomaticCapability($capability) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-06-16 23:09:53 +02:00
|
|
|
|
2015-02-11 20:55:07 +01:00
|
|
|
/* -( PhabricatorDestructibleInterface )----------------------------------- */
|
|
|
|
|
2015-06-16 23:09:53 +02:00
|
|
|
|
2015-02-11 20:55:07 +01:00
|
|
|
public function destroyObjectPermanently(
|
|
|
|
PhabricatorDestructionEngine $engine) {
|
|
|
|
|
|
|
|
$this->openTransaction();
|
|
|
|
$atoms = id(new DivinerAtomQuery())
|
2015-05-15 23:07:17 +02:00
|
|
|
->setViewer($engine->getViewer())
|
2015-02-11 20:55:07 +01:00
|
|
|
->withBookPHIDs(array($this->getPHID()))
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
foreach ($atoms as $atom) {
|
|
|
|
$engine->destroyObject($atom);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->delete();
|
|
|
|
$this->saveTransaction();
|
|
|
|
}
|
|
|
|
|
2015-06-16 23:09:53 +02:00
|
|
|
|
|
|
|
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
public function getApplicationTransactionEditor() {
|
|
|
|
return new DivinerLiveBookEditor();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getApplicationTransactionObject() {
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getApplicationTransactionTemplate() {
|
|
|
|
return new DivinerLiveBookTransaction();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function willRenderTimeline(
|
|
|
|
PhabricatorApplicationTransactionView $timeline,
|
|
|
|
AphrontRequest $request) {
|
|
|
|
|
|
|
|
return $timeline;
|
|
|
|
}
|
|
|
|
|
2013-05-20 19:18:26 +02:00
|
|
|
}
|