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