[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 abstract class PhabricatorApplicationTransactionComment 4 extends PhabricatorLiskDAO 5 implements 6 PhabricatorMarkupInterface, 7 PhabricatorPolicyInterface, 8 PhabricatorDestructibleInterface { 9 10 const MARKUP_FIELD_COMMENT = 'markup:comment'; 11 12 protected $transactionPHID; 13 protected $commentVersion; 14 protected $authorPHID; 15 protected $viewPolicy; 16 protected $editPolicy; 17 protected $content; 18 protected $contentSource; 19 protected $isDeleted = 0; 20 21 abstract public function getApplicationTransactionObject(); 22 23 public function generatePHID() { 24 return PhabricatorPHID::generateNewPHID( 25 PhabricatorPHIDConstants::PHID_TYPE_XCMT); 26 } 27 28 public function getConfiguration() { 29 return array( 30 self::CONFIG_AUX_PHID => true, 31 self::CONFIG_COLUMN_SCHEMA => array( 32 'transactionPHID' => 'phid?', 33 'commentVersion' => 'uint32', 34 'content' => 'text', 35 'contentSource' => 'text', 36 'isDeleted' => 'bool', 37 ), 38 self::CONFIG_KEY_SCHEMA => array( 39 'key_version' => array( 40 'columns' => array('transactionPHID', 'commentVersion'), 41 'unique' => true, 42 ), 43 ), 44 ) + parent::getConfiguration(); 45 } 46 47 public function getApplicationName() { 48 return $this->getApplicationTransactionObject()->getApplicationName(); 49 } 50 51 public function getTableName() { 52 $xaction = $this->getApplicationTransactionObject(); 53 return self::getTableNameFromTransaction($xaction); 54 } 55 56 public static function getTableNameFromTransaction( 57 PhabricatorApplicationTransaction $xaction) { 58 return $xaction->getTableName().'_comment'; 59 } 60 61 public function setContentSource(PhabricatorContentSource $content_source) { 62 $this->contentSource = $content_source->serialize(); 63 return $this; 64 } 65 66 public function setContentSourceFromRequest(AphrontRequest $request) { 67 return $this->setContentSource( 68 PhabricatorContentSource::newFromRequest($request)); 69 } 70 71 public function getContentSource() { 72 return PhabricatorContentSource::newFromSerialized($this->contentSource); 73 } 74 75 public function getIsRemoved() { 76 return ($this->getIsDeleted() == 2); 77 } 78 79 public function setIsRemoved($removed) { 80 if ($removed) { 81 $this->setIsDeleted(2); 82 } else { 83 $this->setIsDeleted(0); 84 } 85 return $this; 86 } 87 88 89 /* -( PhabricatorMarkupInterface )----------------------------------------- */ 90 91 92 public function getMarkupFieldKey($field) { 93 return PhabricatorPHIDConstants::PHID_TYPE_XCMT.':'.$this->getPHID(); 94 } 95 96 97 public function newMarkupEngine($field) { 98 return PhabricatorMarkupEngine::getEngine(); 99 } 100 101 102 public function getMarkupText($field) { 103 return $this->getContent(); 104 } 105 106 107 public function didMarkupText($field, $output, PhutilMarkupEngine $engine) { 108 require_celerity_resource('phabricator-remarkup-css'); 109 return phutil_tag( 110 'div', 111 array( 112 'class' => 'phabricator-remarkup', 113 ), 114 $output); 115 } 116 117 118 public function shouldUseMarkupCache($field) { 119 return (bool)$this->getPHID(); 120 } 121 122 /* -( PhabricatorPolicyInterface Implementation )-------------------------- */ 123 124 125 public function getCapabilities() { 126 return array( 127 PhabricatorPolicyCapability::CAN_VIEW, 128 PhabricatorPolicyCapability::CAN_EDIT, 129 ); 130 } 131 132 public function getPolicy($capability) { 133 switch ($capability) { 134 case PhabricatorPolicyCapability::CAN_VIEW: 135 return $this->getViewPolicy(); 136 case PhabricatorPolicyCapability::CAN_EDIT: 137 return $this->getEditPolicy(); 138 } 139 } 140 141 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { 142 return ($viewer->getPHID() == $this->getAuthorPHID()); 143 } 144 145 public function describeAutomaticCapability($capability) { 146 // TODO: (T603) Policies are murky. 147 return null; 148 } 149 150 151 /* -( PhabricatorDestructibleInterface )----------------------------------- */ 152 153 public function destroyObjectPermanently( 154 PhabricatorDestructionEngine $engine) { 155 $this->openTransaction(); 156 $this->delete(); 157 $this->saveTransaction(); 158 } 159 160 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |