[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PholioMock extends PholioDAO 4 implements 5 PhabricatorMarkupInterface, 6 PhabricatorPolicyInterface, 7 PhabricatorSubscribableInterface, 8 PhabricatorTokenReceiverInterface, 9 PhabricatorFlaggableInterface, 10 PhabricatorApplicationTransactionInterface, 11 PhabricatorProjectInterface, 12 PhabricatorDestructibleInterface { 13 14 const MARKUP_FIELD_DESCRIPTION = 'markup:description'; 15 16 protected $authorPHID; 17 protected $viewPolicy; 18 protected $editPolicy; 19 20 protected $name; 21 protected $originalName; 22 protected $description; 23 protected $coverPHID; 24 protected $mailKey; 25 protected $status; 26 27 private $images = self::ATTACHABLE; 28 private $allImages = self::ATTACHABLE; 29 private $coverFile = self::ATTACHABLE; 30 private $tokenCount = self::ATTACHABLE; 31 32 public static function initializeNewMock(PhabricatorUser $actor) { 33 $app = id(new PhabricatorApplicationQuery()) 34 ->setViewer($actor) 35 ->withClasses(array('PhabricatorPholioApplication')) 36 ->executeOne(); 37 38 $view_policy = $app->getPolicy(PholioDefaultViewCapability::CAPABILITY); 39 $edit_policy = $app->getPolicy(PholioDefaultEditCapability::CAPABILITY); 40 41 return id(new PholioMock()) 42 ->setAuthorPHID($actor->getPHID()) 43 ->attachImages(array()) 44 ->setViewPolicy($view_policy) 45 ->setEditPolicy($edit_policy); 46 } 47 48 public function getMonogram() { 49 return 'M'.$this->getID(); 50 } 51 52 public function getConfiguration() { 53 return array( 54 self::CONFIG_AUX_PHID => true, 55 self::CONFIG_COLUMN_SCHEMA => array( 56 'name' => 'text128', 57 'description' => 'text', 58 'originalName' => 'text128', 59 'mailKey' => 'bytes20', 60 'status' => 'text12', 61 ), 62 self::CONFIG_KEY_SCHEMA => array( 63 'key_phid' => null, 64 'phid' => array( 65 'columns' => array('phid'), 66 'unique' => true, 67 ), 68 'authorPHID' => array( 69 'columns' => array('authorPHID'), 70 ), 71 ), 72 ) + parent::getConfiguration(); 73 } 74 75 public function generatePHID() { 76 return PhabricatorPHID::generateNewPHID('MOCK'); 77 } 78 79 public function save() { 80 if (!$this->getMailKey()) { 81 $this->setMailKey(Filesystem::readRandomCharacters(20)); 82 } 83 return parent::save(); 84 } 85 86 /** 87 * These should be the images currently associated with the Mock. 88 */ 89 public function attachImages(array $images) { 90 assert_instances_of($images, 'PholioImage'); 91 $this->images = $images; 92 return $this; 93 } 94 95 public function getImages() { 96 $this->assertAttached($this->images); 97 return $this->images; 98 } 99 100 /** 101 * These should be *all* images associated with the Mock. This includes 102 * images which have been removed and / or replaced from the Mock. 103 */ 104 public function attachAllImages(array $images) { 105 assert_instances_of($images, 'PholioImage'); 106 $this->allImages = $images; 107 return $this; 108 } 109 110 public function getAllImages() { 111 $this->assertAttached($this->images); 112 return $this->allImages; 113 } 114 115 public function attachCoverFile(PhabricatorFile $file) { 116 $this->coverFile = $file; 117 return $this; 118 } 119 120 public function getCoverFile() { 121 $this->assertAttached($this->coverFile); 122 return $this->coverFile; 123 } 124 125 public function getTokenCount() { 126 $this->assertAttached($this->tokenCount); 127 return $this->tokenCount; 128 } 129 130 public function attachTokenCount($count) { 131 $this->tokenCount = $count; 132 return $this; 133 } 134 135 public function getImageHistorySet($image_id) { 136 $images = $this->getAllImages(); 137 $images = mpull($images, null, 'getID'); 138 $selected_image = $images[$image_id]; 139 140 $replace_map = mpull($images, null, 'getReplacesImagePHID'); 141 $phid_map = mpull($images, null, 'getPHID'); 142 143 // find the earliest image 144 $image = $selected_image; 145 while (isset($phid_map[$image->getReplacesImagePHID()])) { 146 $image = $phid_map[$image->getReplacesImagePHID()]; 147 } 148 149 // now build history moving forward 150 $history = array($image->getID() => $image); 151 while (isset($replace_map[$image->getPHID()])) { 152 $image = $replace_map[$image->getPHID()]; 153 $history[$image->getID()] = $image; 154 } 155 156 return $history; 157 } 158 159 public function getStatuses() { 160 $options = array(); 161 $options['open'] = pht('Open'); 162 $options['closed'] = pht('Closed'); 163 return $options; 164 } 165 166 public function isClosed() { 167 return ($this->getStatus() == 'closed'); 168 } 169 170 171 /* -( PhabricatorSubscribableInterface Implementation )-------------------- */ 172 173 174 public function isAutomaticallySubscribed($phid) { 175 return ($this->authorPHID == $phid); 176 } 177 178 public function shouldShowSubscribersProperty() { 179 return true; 180 } 181 182 public function shouldAllowSubscription($phid) { 183 return true; 184 } 185 186 187 /* -( PhabricatorPolicyInterface Implementation )-------------------------- */ 188 189 190 public function getCapabilities() { 191 return array( 192 PhabricatorPolicyCapability::CAN_VIEW, 193 PhabricatorPolicyCapability::CAN_EDIT, 194 ); 195 } 196 197 public function getPolicy($capability) { 198 switch ($capability) { 199 case PhabricatorPolicyCapability::CAN_VIEW: 200 return $this->getViewPolicy(); 201 case PhabricatorPolicyCapability::CAN_EDIT: 202 return $this->getEditPolicy(); 203 } 204 } 205 206 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { 207 return ($viewer->getPHID() == $this->getAuthorPHID()); 208 } 209 210 public function describeAutomaticCapability($capability) { 211 return pht("A mock's owner can always view and edit it."); 212 } 213 214 215 /* -( PhabricatorMarkupInterface )----------------------------------------- */ 216 217 218 public function getMarkupFieldKey($field) { 219 $hash = PhabricatorHash::digest($this->getMarkupText($field)); 220 return 'M:'.$hash; 221 } 222 223 public function newMarkupEngine($field) { 224 return PhabricatorMarkupEngine::newMarkupEngine(array()); 225 } 226 227 public function getMarkupText($field) { 228 if ($this->getDescription()) { 229 $description = $this->getDescription(); 230 } else { 231 $description = pht('No Description Given'); 232 } 233 234 return $description; 235 } 236 237 public function didMarkupText($field, $output, PhutilMarkupEngine $engine) { 238 require_celerity_resource('phabricator-remarkup-css'); 239 return phutil_tag( 240 'div', 241 array( 242 'class' => 'phabricator-remarkup', 243 ), 244 $output); 245 } 246 247 public function shouldUseMarkupCache($field) { 248 return (bool)$this->getID(); 249 } 250 251 252 /* -( PhabricatorApplicationTransactionInterface )------------------------- */ 253 254 255 public function getApplicationTransactionEditor() { 256 return new PholioMockEditor(); 257 } 258 259 public function getApplicationTransactionObject() { 260 return $this; 261 } 262 263 public function getApplicationTransactionTemplate() { 264 return new PholioTransaction(); 265 } 266 267 268 /* -( PhabricatorTokenReceiverInterface )---------------------------------- */ 269 270 271 public function getUsersToNotifyOfTokenGiven() { 272 return array( 273 $this->getAuthorPHID(), 274 ); 275 } 276 277 278 /* -( PhabricatorDestructibleInterface )----------------------------------- */ 279 280 281 public function destroyObjectPermanently( 282 PhabricatorDestructionEngine $engine) { 283 284 $this->openTransaction(); 285 $images = id(new PholioImage())->loadAllWhere( 286 'mockID = %d', 287 $this->getID()); 288 foreach ($images as $image) { 289 $image->delete(); 290 } 291 292 $this->delete(); 293 $this->saveTransaction(); 294 } 295 296 }
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 |