[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhrictionTransaction 4 extends PhabricatorApplicationTransaction { 5 6 const TYPE_TITLE = 'title'; 7 const TYPE_CONTENT = 'content'; 8 const TYPE_DELETE = 'delete'; 9 const TYPE_MOVE_TO = 'move-to'; 10 const TYPE_MOVE_AWAY = 'move-away'; 11 12 const MAILTAG_TITLE = 'phriction-title'; 13 const MAILTAG_CONTENT = 'phriction-content'; 14 const MAILTAG_DELETE = 'phriction-delete'; 15 16 public function getApplicationName() { 17 return 'phriction'; 18 } 19 20 public function getApplicationTransactionType() { 21 return PhrictionDocumentPHIDType::TYPECONST; 22 } 23 24 public function getApplicationTransactionCommentObject() { 25 return new PhrictionTransactionComment(); 26 } 27 28 public function getRequiredHandlePHIDs() { 29 $phids = parent::getRequiredHandlePHIDs(); 30 $new = $this->getNewValue(); 31 switch ($this->getTransactionType()) { 32 case self::TYPE_MOVE_TO: 33 case self::TYPE_MOVE_AWAY: 34 $phids[] = $new['phid']; 35 break; 36 case self::TYPE_TITLE: 37 if ($this->getMetadataValue('stub:create:phid')) { 38 $phids[] = $this->getMetadataValue('stub:create:phid'); 39 } 40 break; 41 } 42 43 44 return $phids; 45 } 46 47 public function getRemarkupBlocks() { 48 $blocks = parent::getRemarkupBlocks(); 49 50 switch ($this->getTransactionType()) { 51 case self::TYPE_CONTENT: 52 $blocks[] = $this->getNewValue(); 53 break; 54 } 55 56 return $blocks; 57 } 58 59 public function shouldHide() { 60 switch ($this->getTransactionType()) { 61 case self::TYPE_CONTENT: 62 if ($this->getOldValue() === null) { 63 return true; 64 } else { 65 return false; 66 } 67 break; 68 } 69 70 return parent::shouldHide(); 71 } 72 73 public function shouldHideForMail(array $xactions) { 74 switch ($this->getTransactionType()) { 75 case self::TYPE_MOVE_TO: 76 case self::TYPE_MOVE_AWAY: 77 return true; 78 case self::TYPE_TITLE: 79 return $this->getMetadataValue('stub:create:phid', false); 80 } 81 return parent::shouldHideForMail($xactions); 82 } 83 84 public function shouldHideForFeed() { 85 switch ($this->getTransactionType()) { 86 case self::TYPE_MOVE_TO: 87 case self::TYPE_MOVE_AWAY: 88 return true; 89 case self::TYPE_TITLE: 90 return $this->getMetadataValue('stub:create:phid', false); 91 } 92 return parent::shouldHideForFeed(); 93 } 94 95 public function getActionStrength() { 96 switch ($this->getTransactionType()) { 97 case self::TYPE_TITLE: 98 return 1.4; 99 case self::TYPE_CONTENT: 100 return 1.3; 101 case self::TYPE_DELETE: 102 return 1.5; 103 case self::TYPE_MOVE_TO: 104 case self::TYPE_MOVE_AWAY: 105 return 1.0; 106 } 107 108 return parent::getActionStrength(); 109 } 110 111 public function getActionName() { 112 $old = $this->getOldValue(); 113 $new = $this->getNewValue(); 114 115 switch ($this->getTransactionType()) { 116 case self::TYPE_TITLE: 117 if ($old === null) { 118 if ($this->getMetadataValue('stub:create:phid')) { 119 return pht('Stubbed'); 120 } else { 121 return pht('Created'); 122 } 123 } 124 125 return pht('Retitled'); 126 127 case self::TYPE_CONTENT: 128 return pht('Edited'); 129 130 case self::TYPE_DELETE: 131 return pht('Deleted'); 132 133 case self::TYPE_MOVE_TO: 134 return pht('Moved'); 135 136 case self::TYPE_MOVE_AWAY: 137 return pht('Moved Away'); 138 139 } 140 141 return parent::getActionName(); 142 } 143 144 public function getIcon() { 145 $old = $this->getOldValue(); 146 $new = $this->getNewValue(); 147 148 switch ($this->getTransactionType()) { 149 case self::TYPE_TITLE: 150 case self::TYPE_CONTENT: 151 return 'fa-pencil'; 152 case self::TYPE_DELETE: 153 return 'fa-times'; 154 case self::TYPE_MOVE_TO: 155 case self::TYPE_MOVE_AWAY: 156 return 'fa-arrows'; 157 } 158 159 return parent::getIcon(); 160 } 161 162 163 public function getTitle() { 164 $author_phid = $this->getAuthorPHID(); 165 166 $old = $this->getOldValue(); 167 $new = $this->getNewValue(); 168 169 switch ($this->getTransactionType()) { 170 case self::TYPE_TITLE: 171 if ($old === null) { 172 if ($this->getMetadataValue('stub:create:phid')) { 173 return pht( 174 '%s stubbed out this document when creating %s.', 175 $this->renderHandleLink($author_phid), 176 $this->renderHandleLink( 177 $this->getMetadataValue('stub:create:phid'))); 178 } else { 179 return pht( 180 '%s created this document.', 181 $this->renderHandleLink($author_phid)); 182 } 183 } 184 return pht( 185 '%s changed the title from "%s" to "%s".', 186 $this->renderHandleLink($author_phid), 187 $old, 188 $new); 189 190 case self::TYPE_CONTENT: 191 return pht( 192 '%s edited the document content.', 193 $this->renderHandleLink($author_phid)); 194 195 case self::TYPE_DELETE: 196 return pht( 197 '%s deleted this document.', 198 $this->renderHandleLink($author_phid)); 199 200 case self::TYPE_MOVE_TO: 201 return pht( 202 '%s moved this document from %s', 203 $this->renderHandleLink($author_phid), 204 $this->renderHandleLink($new['phid'])); 205 206 case self::TYPE_MOVE_AWAY: 207 return pht( 208 '%s moved this document to %s', 209 $this->renderHandleLink($author_phid), 210 $this->renderHandleLink($new['phid'])); 211 212 } 213 214 return parent::getTitle(); 215 } 216 217 public function getTitleForFeed(PhabricatorFeedStory $story) { 218 $author_phid = $this->getAuthorPHID(); 219 $object_phid = $this->getObjectPHID(); 220 221 $old = $this->getOldValue(); 222 $new = $this->getNewValue(); 223 224 switch ($this->getTransactionType()) { 225 case self::TYPE_TITLE: 226 if ($old === null) { 227 return pht( 228 '%s created %s.', 229 $this->renderHandleLink($author_phid), 230 $this->renderHandleLink($object_phid)); 231 } 232 233 return pht( 234 '%s renamed %s from "%s" to "%s".', 235 $this->renderHandleLink($author_phid), 236 $this->renderHandleLink($object_phid), 237 $old, 238 $new); 239 240 case self::TYPE_CONTENT: 241 return pht( 242 '%s edited the content of %s.', 243 $this->renderHandleLink($author_phid), 244 $this->renderHandleLink($object_phid)); 245 246 case self::TYPE_DELETE: 247 return pht( 248 '%s deleted %s.', 249 $this->renderHandleLink($author_phid), 250 $this->renderHandleLink($object_phid)); 251 252 } 253 return parent::getTitleForFeed($story); 254 } 255 256 public function hasChangeDetails() { 257 switch ($this->getTransactionType()) { 258 case self::TYPE_CONTENT: 259 return true; 260 } 261 return parent::hasChangeDetails(); 262 } 263 264 public function renderChangeDetails(PhabricatorUser $viewer) { 265 return $this->renderTextCorpusChangeDetails( 266 $viewer, 267 $this->getOldValue(), 268 $this->getNewValue()); 269 } 270 271 public function getMailTags() { 272 $tags = array(); 273 switch ($this->getTransactionType()) { 274 case self::TYPE_TITLE: 275 $tags[] = self::MAILTAG_TITLE; 276 break; 277 case self::TYPE_CONTENT: 278 $tags[] = self::MAILTAG_CONTENT; 279 break; 280 case self::TYPE_DELETE: 281 $tags[] = self::MAILTAG_DELETE; 282 break; 283 284 } 285 return $tags; 286 } 287 288 }
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 |