Path: blob/master/src/applications/diviner/storage/DivinerLiveBook.php
12256 views
<?php12final class DivinerLiveBook extends DivinerDAO3implements4PhabricatorPolicyInterface,5PhabricatorProjectInterface,6PhabricatorDestructibleInterface,7PhabricatorApplicationTransactionInterface,8PhabricatorFulltextInterface {910protected $name;11protected $repositoryPHID;12protected $viewPolicy;13protected $editPolicy;14protected $configurationData = array();1516private $projectPHIDs = self::ATTACHABLE;17private $repository = self::ATTACHABLE;1819protected function getConfiguration() {20return array(21self::CONFIG_AUX_PHID => true,22self::CONFIG_SERIALIZATION => array(23'configurationData' => self::SERIALIZATION_JSON,24),25self::CONFIG_COLUMN_SCHEMA => array(26'name' => 'text64',27'repositoryPHID' => 'phid?',28),29self::CONFIG_KEY_SCHEMA => array(30'key_phid' => null,31'phid' => array(32'columns' => array('phid'),33'unique' => true,34),35'name' => array(36'columns' => array('name'),37'unique' => true,38),39),40) + parent::getConfiguration();41}4243public function getConfig($key, $default = null) {44return idx($this->configurationData, $key, $default);45}4647public function setConfig($key, $value) {48$this->configurationData[$key] = $value;49return $this;50}5152public function generatePHID() {53return PhabricatorPHID::generateNewPHID(DivinerBookPHIDType::TYPECONST);54}5556public function getTitle() {57return $this->getConfig('title', $this->getName());58}5960public function getShortTitle() {61return $this->getConfig('short', $this->getTitle());62}6364public function getPreface() {65return $this->getConfig('preface');66}6768public function getGroupName($group) {69$groups = $this->getConfig('groups', array());70$spec = idx($groups, $group, array());71return idx($spec, 'name', $group);72}7374public function attachRepository(PhabricatorRepository $repository = null) {75$this->repository = $repository;76return $this;77}7879public function getRepository() {80return $this->assertAttached($this->repository);81}8283public function attachProjectPHIDs(array $project_phids) {84$this->projectPHIDs = $project_phids;85return $this;86}8788public function getProjectPHIDs() {89return $this->assertAttached($this->projectPHIDs);90}919293/* -( PhabricatorPolicyInterface )----------------------------------------- */949596public function getCapabilities() {97return array(98PhabricatorPolicyCapability::CAN_VIEW,99PhabricatorPolicyCapability::CAN_EDIT,100);101}102103public function getPolicy($capability) {104switch ($capability) {105case PhabricatorPolicyCapability::CAN_VIEW:106return $this->getViewPolicy();107case PhabricatorPolicyCapability::CAN_EDIT:108return $this->getEditPolicy();109}110}111112public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {113return false;114}115116117/* -( PhabricatorDestructibleInterface )----------------------------------- */118119120public function destroyObjectPermanently(121PhabricatorDestructionEngine $engine) {122123$this->openTransaction();124$atoms = id(new DivinerAtomQuery())125->setViewer($engine->getViewer())126->withBookPHIDs(array($this->getPHID()))127->execute();128129foreach ($atoms as $atom) {130$engine->destroyObject($atom);131}132133$this->delete();134$this->saveTransaction();135}136137138/* -( PhabricatorApplicationTransactionInterface )------------------------- */139140141public function getApplicationTransactionEditor() {142return new DivinerLiveBookEditor();143}144145public function getApplicationTransactionTemplate() {146return new DivinerLiveBookTransaction();147}148149/* -( PhabricatorFulltextInterface )--------------------------------------- */150151152public function newFulltextEngine() {153return new DivinerLiveBookFulltextEngine();154}155156157}158159160