[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class SubscriptionListStringBuilder { 4 5 private $handles; 6 private $objectPHID; 7 8 public function setHandles(array $handles) { 9 assert_instances_of($handles, 'PhabricatorObjectHandle'); 10 $this->handles = $handles; 11 return $this; 12 } 13 14 public function getHandles() { 15 return $this->handles; 16 } 17 18 public function setObjectPHID($object_phid) { 19 $this->objectPHID = $object_phid; 20 return $this; 21 } 22 23 public function getObjectPHID() { 24 return $this->objectPHID; 25 } 26 27 public function buildTransactionString($change_type) { 28 $handles = $this->getHandles(); 29 if (!$handles) { 30 return; 31 } 32 $list_uri = '/subscriptions/transaction/'. 33 $change_type.'/'. 34 $this->getObjectPHID().'/'; 35 return $this->buildString($list_uri); 36 } 37 38 public function buildPropertyString() { 39 $handles = $this->getHandles(); 40 41 if (!$handles) { 42 return phutil_tag('em', array(), pht('None')); 43 } 44 $list_uri = '/subscriptions/list/'.$this->getObjectPHID().'/'; 45 return $this->buildString($list_uri); 46 } 47 48 private function buildString($list_uri) { 49 $handles = $this->getHandles(); 50 51 // Always show this many subscribers. 52 $show_count = 3; 53 $subscribers_count = count($handles); 54 55 // It looks a bit silly to render "a, b, c, and 1 other", since we could 56 // have just put that other subscriber there in place of the "1 other" 57 // link. Instead, render "a, b, c, d" in this case, and then when we get one 58 // more render "a, b, c, and 2 others". 59 if ($subscribers_count <= ($show_count + 1)) { 60 return phutil_implode_html(', ', mpull($handles, 'renderLink')); 61 } 62 63 $show = array_slice($handles, 0, $show_count); 64 $show = array_values($show); 65 66 $not_shown_count = $subscribers_count - $show_count; 67 $not_shown_txt = pht('%d other(s)', $not_shown_count); 68 $not_shown_link = javelin_tag( 69 'a', 70 array( 71 'href' => $list_uri, 72 'sigil' => 'workflow', 73 ), 74 $not_shown_txt); 75 76 return pht( 77 '%s, %s, %s and %s', 78 $show[0]->renderLink(), 79 $show[1]->renderLink(), 80 $show[2]->renderLink(), 81 $not_shown_link); 82 } 83 84 }
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 |