[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PholioTransactionView 4 extends PhabricatorApplicationTransactionView { 5 6 private $mock; 7 8 public function setMock($mock) { 9 $this->mock = $mock; 10 return $this; 11 } 12 13 public function getMock() { 14 return $this->mock; 15 } 16 17 protected function shouldGroupTransactions( 18 PhabricatorApplicationTransaction $u, 19 PhabricatorApplicationTransaction $v) { 20 21 if ($u->getAuthorPHID() != $v->getAuthorPHID()) { 22 // Don't group transactions by different authors. 23 return false; 24 } 25 26 if (($v->getDateCreated() - $u->getDateCreated()) > 60) { 27 // Don't group if transactions happened more than 60s apart. 28 return false; 29 } 30 31 switch ($u->getTransactionType()) { 32 case PhabricatorTransactions::TYPE_COMMENT: 33 case PholioTransactionType::TYPE_INLINE: 34 break; 35 default: 36 return false; 37 } 38 39 switch ($v->getTransactionType()) { 40 case PholioTransactionType::TYPE_INLINE: 41 return true; 42 } 43 44 return parent::shouldGroupTransactions($u, $v); 45 } 46 47 protected function renderTransactionContent( 48 PhabricatorApplicationTransaction $xaction) { 49 50 $out = array(); 51 52 $group = $xaction->getTransactionGroup(); 53 if ($xaction->getTransactionType() == PholioTransactionType::TYPE_INLINE) { 54 array_unshift($group, $xaction); 55 } else { 56 $out[] = parent::renderTransactionContent($xaction); 57 } 58 59 if (!$group) { 60 return $out; 61 } 62 63 $inlines = array(); 64 foreach ($group as $xaction) { 65 switch ($xaction->getTransactionType()) { 66 case PholioTransactionType::TYPE_INLINE: 67 $inlines[] = $xaction; 68 break; 69 default: 70 throw new Exception('Unknown grouped transaction type!'); 71 } 72 } 73 74 if ($inlines) { 75 $icon = id(new PHUIIconView()) 76 ->setIconFont('fa-comment bluegrey msr'); 77 $header = phutil_tag( 78 'div', 79 array( 80 'class' => 'phabricator-transaction-subheader', 81 ), 82 array($icon, pht('Inline Comments'))); 83 84 $out[] = $header; 85 foreach ($inlines as $inline) { 86 if (!$inline->getComment()) { 87 continue; 88 } 89 $out[] = $this->renderInlineContent($inline); 90 } 91 } 92 93 return $out; 94 } 95 96 private function renderInlineContent(PholioTransaction $inline) { 97 $comment = $inline->getComment(); 98 $mock = $this->getMock(); 99 $images = $mock->getAllImages(); 100 $images = mpull($images, null, 'getID'); 101 102 $image = idx($images, $comment->getImageID()); 103 if (!$image) { 104 throw new Exception('No image attached!'); 105 } 106 107 $file = $image->getFile(); 108 if (!$file->isViewableImage()) { 109 throw new Exception('File is not viewable.'); 110 } 111 112 $image_uri = $file->getBestURI(); 113 114 $thumb = id(new PHUIImageMaskView()) 115 ->addClass('mrl') 116 ->setImage($image_uri) 117 ->setDisplayHeight(100) 118 ->setDisplayWidth(200) 119 ->withMask(true) 120 ->centerViewOnPoint( 121 $comment->getX(), $comment->getY(), 122 $comment->getHeight(), $comment->getWidth()); 123 124 $link = phutil_tag( 125 'a', 126 array( 127 'href' => '#', 128 'class' => 'pholio-transaction-inline-image-anchor', 129 ), 130 $thumb); 131 132 $inline_comment = parent::renderTransactionContent($inline); 133 134 return phutil_tag( 135 'div', 136 array('class' => 'pholio-transaction-inline-comment'), 137 array($link, $inline_comment)); 138 } 139 140 }
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 |