[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorTransactionView extends AphrontView { 4 5 private $imageURI; 6 private $actions = array(); 7 private $epoch; 8 private $contentSource; 9 private $anchorName; 10 private $anchorText; 11 private $isPreview; 12 private $classes = array(); 13 14 public function setImageURI($uri) { 15 $this->imageURI = $uri; 16 return $this; 17 } 18 19 public function setActions(array $actions) { 20 $this->actions = $actions; 21 return $this; 22 } 23 24 public function setEpoch($epoch) { 25 $this->epoch = $epoch; 26 return $this; 27 } 28 29 public function setContentSource(PhabricatorContentSource $source) { 30 $this->contentSource = $source; 31 return $this; 32 } 33 34 public function setAnchor($anchor_name, $anchor_text) { 35 $this->anchorName = $anchor_name; 36 $this->anchorText = $anchor_text; 37 return $this; 38 } 39 40 public function addClass($class) { 41 $this->classes[] = $class; 42 return $this; 43 } 44 45 public function setIsPreview($preview) { 46 $this->isPreview = $preview; 47 return $this; 48 } 49 50 public function render() { 51 if (!$this->user) { 52 throw new Exception(pht('Call setUser() before render()!')); 53 } 54 55 require_celerity_resource('phabricator-transaction-view-css'); 56 57 $info = $this->renderTransactionInfo(); 58 $actions = $this->renderTransactionActions(); 59 $style = $this->renderTransactionStyle(); 60 $content = $this->renderTransactionContent(); 61 $classes = implode(' ', $this->classes); 62 63 $transaction_id = $this->anchorName ? 'anchor-'.$this->anchorName : null; 64 65 $header = phutil_tag_div( 66 'phabricator-transaction-header', 67 array($info, $actions)); 68 69 return phutil_tag( 70 'div', 71 array( 72 'class' => 'phabricator-transaction-view', 73 'id' => $transaction_id, 74 'style' => $style, 75 ), 76 phutil_tag_div( 77 'phabricator-transaction-detail '.$classes, 78 array($header, $content))); 79 80 } 81 82 private function renderTransactionInfo() { 83 $info = array(); 84 85 if ($this->contentSource) { 86 $content_source = new PhabricatorContentSourceView(); 87 $content_source->setContentSource($this->contentSource); 88 $content_source->setUser($this->user); 89 $source = $content_source->render(); 90 if ($source) { 91 $info[] = $source; 92 } 93 } 94 95 if ($this->isPreview) { 96 $info[] = 'PREVIEW'; 97 } else if ($this->epoch) { 98 $info[] = phabricator_datetime($this->epoch, $this->user); 99 } 100 101 if ($this->anchorName) { 102 Javelin::initBehavior('phabricator-watch-anchor'); 103 104 $anchor = id(new PhabricatorAnchorView()) 105 ->setAnchorName($this->anchorName) 106 ->render(); 107 108 $info[] = hsprintf( 109 '%s%s', 110 $anchor, 111 phutil_tag( 112 'a', 113 array('href' => '#'.$this->anchorName), 114 $this->anchorText)); 115 } 116 117 $info = phutil_implode_html(" \xC2\xB7 ", $info); 118 119 return phutil_tag( 120 'span', 121 array('class' => 'phabricator-transaction-info'), 122 $info); 123 } 124 125 private function renderTransactionActions() { 126 return $this->actions; 127 } 128 129 private function renderTransactionStyle() { 130 if ($this->imageURI) { 131 return 'background-image: url('.$this->imageURI.');'; 132 } else { 133 return null; 134 } 135 } 136 137 private function renderTransactionContent() { 138 if (!$this->hasChildren()) { 139 return null; 140 } 141 return phutil_tag_div( 142 'phabricator-transaction-content', 143 $this->renderChildren()); 144 } 145 146 }
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 |