[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PholioTransaction extends PhabricatorApplicationTransaction { 4 5 public function getApplicationName() { 6 return 'pholio'; 7 } 8 9 public function getApplicationTransactionType() { 10 return PholioMockPHIDType::TYPECONST; 11 } 12 13 public function getApplicationTransactionCommentObject() { 14 return new PholioTransactionComment(); 15 } 16 17 public function getApplicationTransactionViewObject() { 18 return new PholioTransactionView(); 19 } 20 21 public function getRequiredHandlePHIDs() { 22 $phids = parent::getRequiredHandlePHIDs(); 23 $phids[] = $this->getObjectPHID(); 24 25 $new = $this->getNewValue(); 26 $old = $this->getOldValue(); 27 28 switch ($this->getTransactionType()) { 29 case PholioTransactionType::TYPE_IMAGE_FILE: 30 $phids = array_merge($phids, $new, $old); 31 break; 32 case PholioTransactionType::TYPE_IMAGE_REPLACE: 33 $phids[] = $new; 34 $phids[] = $old; 35 break; 36 case PholioTransactionType::TYPE_IMAGE_DESCRIPTION: 37 case PholioTransactionType::TYPE_IMAGE_NAME: 38 case PholioTransactionType::TYPE_IMAGE_SEQUENCE: 39 $phids[] = key($new); 40 break; 41 } 42 43 return $phids; 44 } 45 46 public function shouldHide() { 47 $old = $this->getOldValue(); 48 49 switch ($this->getTransactionType()) { 50 case PholioTransactionType::TYPE_DESCRIPTION: 51 return ($old === null); 52 case PholioTransactionType::TYPE_IMAGE_NAME: 53 case PholioTransactionType::TYPE_IMAGE_DESCRIPTION: 54 return ($old === array(null => null)); 55 // this is boring / silly to surface; changing sequence is NBD 56 case PholioTransactionType::TYPE_IMAGE_SEQUENCE: 57 return true; 58 } 59 60 return parent::shouldHide(); 61 } 62 63 public function getIcon() { 64 switch ($this->getTransactionType()) { 65 case PholioTransactionType::TYPE_INLINE: 66 return 'fa-comment'; 67 case PholioTransactionType::TYPE_NAME: 68 case PholioTransactionType::TYPE_DESCRIPTION: 69 case PholioTransactionType::TYPE_STATUS: 70 case PholioTransactionType::TYPE_IMAGE_NAME: 71 case PholioTransactionType::TYPE_IMAGE_DESCRIPTION: 72 case PholioTransactionType::TYPE_IMAGE_SEQUENCE: 73 return 'fa-pencil'; 74 case PholioTransactionType::TYPE_IMAGE_FILE: 75 case PholioTransactionType::TYPE_IMAGE_REPLACE: 76 return 'fa-picture-o'; 77 } 78 79 return parent::getIcon(); 80 } 81 82 public function getMailTags() { 83 $tags = array(); 84 switch ($this->getTransactionType()) { 85 case PholioTransactionType::TYPE_INLINE: 86 case PhabricatorTransactions::TYPE_COMMENT: 87 $tags[] = MetaMTANotificationType::TYPE_PHOLIO_COMMENT; 88 break; 89 case PholioTransactionType::TYPE_STATUS: 90 $tags[] = MetaMTANotificationType::TYPE_PHOLIO_STATUS; 91 break; 92 case PholioTransactionType::TYPE_NAME: 93 case PholioTransactionType::TYPE_DESCRIPTION: 94 case PholioTransactionType::TYPE_IMAGE_NAME: 95 case PholioTransactionType::TYPE_IMAGE_DESCRIPTION: 96 case PholioTransactionType::TYPE_IMAGE_SEQUENCE: 97 case PholioTransactionType::TYPE_IMAGE_FILE: 98 case PholioTransactionType::TYPE_IMAGE_REPLACE: 99 $tags[] = MetaMTANotificationType::TYPE_PHOLIO_UPDATED; 100 break; 101 default: 102 $tags[] = MetaMTANotificationType::TYPE_PHOLIO_OTHER; 103 break; 104 } 105 return $tags; 106 } 107 108 public function getTitle() { 109 $author_phid = $this->getAuthorPHID(); 110 111 $old = $this->getOldValue(); 112 $new = $this->getNewValue(); 113 114 $type = $this->getTransactionType(); 115 switch ($type) { 116 case PholioTransactionType::TYPE_NAME: 117 if ($old === null) { 118 return pht( 119 '%s created "%s".', 120 $this->renderHandleLink($author_phid), 121 $new); 122 } else { 123 return pht( 124 '%s renamed this mock from "%s" to "%s".', 125 $this->renderHandleLink($author_phid), 126 $old, 127 $new); 128 } 129 break; 130 case PholioTransactionType::TYPE_DESCRIPTION: 131 return pht( 132 "%s updated the mock's description.", 133 $this->renderHandleLink($author_phid)); 134 break; 135 case PholioTransactionType::TYPE_STATUS: 136 return pht( 137 "%s updated the mock's status.", 138 $this->renderHandleLink($author_phid)); 139 break; 140 case PholioTransactionType::TYPE_INLINE: 141 $count = 1; 142 foreach ($this->getTransactionGroup() as $xaction) { 143 if ($xaction->getTransactionType() == $type) { 144 $count++; 145 } 146 } 147 148 return pht( 149 '%s added %d inline comment(s).', 150 $this->renderHandleLink($author_phid), 151 $count); 152 break; 153 case PholioTransactionType::TYPE_IMAGE_REPLACE: 154 return pht( 155 '%s replaced %s with %s.', 156 $this->renderHandleLink($author_phid), 157 $this->renderHandleLink($old), 158 $this->renderHandleLink($new)); 159 break; 160 case PholioTransactionType::TYPE_IMAGE_FILE: 161 $add = array_diff($new, $old); 162 $rem = array_diff($old, $new); 163 164 if ($add && $rem) { 165 return pht( 166 '%s edited image(s), added %d: %s; removed %d: %s.', 167 $this->renderHandleLink($author_phid), 168 count($add), 169 $this->renderHandleList($add), 170 count($rem), 171 $this->renderHandleList($rem)); 172 } else if ($add) { 173 return pht( 174 '%s added %d image(s): %s.', 175 $this->renderHandleLink($author_phid), 176 count($add), 177 $this->renderHandleList($add)); 178 } else { 179 return pht( 180 '%s removed %d image(s): %s.', 181 $this->renderHandleLink($author_phid), 182 count($rem), 183 $this->renderHandleList($rem)); 184 } 185 break; 186 187 case PholioTransactionType::TYPE_IMAGE_NAME: 188 return pht( 189 '%s renamed an image (%s) from "%s" to "%s".', 190 $this->renderHandleLink($author_phid), 191 $this->renderHandleLink(key($new)), 192 reset($old), 193 reset($new)); 194 break; 195 case PholioTransactionType::TYPE_IMAGE_DESCRIPTION: 196 return pht( 197 '%s updated an image\'s (%s) description.', 198 $this->renderHandleLink($author_phid), 199 $this->renderHandleLink(key($new))); 200 break; 201 case PholioTransactionType::TYPE_IMAGE_SEQUENCE: 202 return pht( 203 '%s updated an image\'s (%s) sequence.', 204 $this->renderHandleLink($author_phid), 205 $this->renderHandleLink(key($new))); 206 break; 207 } 208 209 return parent::getTitle(); 210 } 211 212 public function getTitleForFeed(PhabricatorFeedStory $story) { 213 $author_phid = $this->getAuthorPHID(); 214 $object_phid = $this->getObjectPHID(); 215 216 $old = $this->getOldValue(); 217 $new = $this->getNewValue(); 218 219 $type = $this->getTransactionType(); 220 switch ($type) { 221 case PholioTransactionType::TYPE_NAME: 222 if ($old === null) { 223 return pht( 224 '%s created %s.', 225 $this->renderHandleLink($author_phid), 226 $this->renderHandleLink($object_phid)); 227 } else { 228 return pht( 229 '%s renamed %s from "%s" to "%s".', 230 $this->renderHandleLink($author_phid), 231 $this->renderHandleLink($object_phid), 232 $old, 233 $new); 234 } 235 break; 236 case PholioTransactionType::TYPE_DESCRIPTION: 237 return pht( 238 '%s updated the description for %s.', 239 $this->renderHandleLink($author_phid), 240 $this->renderHandleLink($object_phid)); 241 break; 242 case PholioTransactionType::TYPE_STATUS: 243 return pht( 244 '%s updated the status for %s.', 245 $this->renderHandleLink($author_phid), 246 $this->renderHandleLink($object_phid)); 247 break; 248 case PholioTransactionType::TYPE_INLINE: 249 return pht( 250 '%s added an inline comment to %s.', 251 $this->renderHandleLink($author_phid), 252 $this->renderHandleLink($object_phid)); 253 break; 254 case PholioTransactionType::TYPE_IMAGE_REPLACE: 255 case PholioTransactionType::TYPE_IMAGE_FILE: 256 return pht( 257 '%s updated images of %s.', 258 $this->renderHandleLink($author_phid), 259 $this->renderHandleLink($object_phid)); 260 break; 261 case PholioTransactionType::TYPE_IMAGE_NAME: 262 return pht( 263 '%s updated the image names of %s.', 264 $this->renderHandleLink($author_phid), 265 $this->renderHandleLink($object_phid)); 266 break; 267 case PholioTransactionType::TYPE_IMAGE_DESCRIPTION: 268 return pht( 269 '%s updated image descriptions of %s.', 270 $this->renderHandleLink($author_phid), 271 $this->renderHandleLink($object_phid)); 272 break; 273 case PholioTransactionType::TYPE_IMAGE_SEQUENCE: 274 return pht( 275 '%s updated image sequence of %s.', 276 $this->renderHandleLink($author_phid), 277 $this->renderHandleLink($object_phid)); 278 break; 279 } 280 281 return parent::getTitleForFeed($story); 282 } 283 284 public function getBodyForFeed(PhabricatorFeedStory $story) { 285 $text = null; 286 switch ($this->getTransactionType()) { 287 case PholioTransactionType::TYPE_NAME: 288 if ($this->getOldValue() === null) { 289 $mock = $story->getPrimaryObject(); 290 $text = $mock->getDescription(); 291 } 292 break; 293 case PholioTransactionType::TYPE_INLINE: 294 $text = $this->getComment()->getContent(); 295 break; 296 } 297 298 if ($text) { 299 return phutil_escape_html_newlines( 300 id(new PhutilUTF8StringTruncator()) 301 ->setMaximumGlyphs(128) 302 ->truncateString($text)); 303 } 304 305 return parent::getBodyForFeed($story); 306 } 307 308 public function hasChangeDetails() { 309 switch ($this->getTransactionType()) { 310 case PholioTransactionType::TYPE_DESCRIPTION: 311 case PholioTransactionType::TYPE_IMAGE_DESCRIPTION: 312 return true; 313 } 314 return parent::hasChangeDetails(); 315 } 316 317 public function renderChangeDetails(PhabricatorUser $viewer) { 318 $old = $this->getOldValue(); 319 $new = $this->getNewValue(); 320 if ($this->getTransactionType() == 321 PholioTransactionType::TYPE_IMAGE_DESCRIPTION) { 322 $old = reset($old); 323 $new = reset($new); 324 } 325 326 return $this->renderTextCorpusChangeDetails( 327 $viewer, 328 $old, 329 $new); 330 } 331 332 public function getColor() { 333 $old = $this->getOldValue(); 334 $new = $this->getNewValue(); 335 336 switch ($this->getTransactionType()) { 337 case PholioTransactionType::TYPE_NAME: 338 if ($old === null) { 339 return PhabricatorTransactions::COLOR_GREEN; 340 } 341 case PholioTransactionType::TYPE_DESCRIPTION: 342 case PholioTransactionType::TYPE_STATUS: 343 case PholioTransactionType::TYPE_IMAGE_NAME: 344 case PholioTransactionType::TYPE_IMAGE_DESCRIPTION: 345 case PholioTransactionType::TYPE_IMAGE_SEQUENCE: 346 return PhabricatorTransactions::COLOR_BLUE; 347 case PholioTransactionType::TYPE_IMAGE_REPLACE: 348 return PhabricatorTransactions::COLOR_YELLOW; 349 case PholioTransactionType::TYPE_IMAGE_FILE: 350 $add = array_diff($new, $old); 351 $rem = array_diff($old, $new); 352 if ($add && $rem) { 353 return PhabricatorTransactions::COLOR_YELLOW; 354 } else if ($add) { 355 return PhabricatorTransactions::COLOR_GREEN; 356 } else { 357 return PhabricatorTransactions::COLOR_RED; 358 } 359 } 360 361 return parent::getColor(); 362 } 363 364 public function getNoEffectDescription() { 365 switch ($this->getTransactionType()) { 366 case PholioTransactionType::TYPE_IMAGE_NAME: 367 return pht('The image title was not updated.'); 368 case PholioTransactionType::TYPE_IMAGE_DESCRIPTION: 369 return pht('The image description was not updated.'); 370 case PholioTransactionType::TYPE_IMAGE_SEQUENCE: 371 return pht('The image sequence was not updated.'); 372 } 373 374 return parent::getNoEffectDescription(); 375 } 376 }
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 |