Remove product literal strings in "pht()", part 6
[phabricator.git] / src / applications / subscriptions / view / SubscriptionListStringBuilder.php
blob7ccc72924197cf7e7dc7cf79de6e49bd9d7d5036
1 <?php
3 final class SubscriptionListStringBuilder extends Phobject {
5 private $handles;
6 private $objectPHID;
8 public function setHandles(array $handles) {
9 assert_instances_of($handles, 'PhabricatorObjectHandle');
10 $this->handles = $handles;
11 return $this;
14 public function getHandles() {
15 return $this->handles;
18 public function setObjectPHID($object_phid) {
19 $this->objectPHID = $object_phid;
20 return $this;
23 public function getObjectPHID() {
24 return $this->objectPHID;
27 public function buildTransactionString($change_type) {
28 $handles = $this->getHandles();
29 if (!$handles) {
30 return;
32 $list_uri = '/subscriptions/transaction/'.
33 $change_type.'/'.
34 $this->getObjectPHID().'/';
35 return $this->buildString($list_uri);
38 public function buildPropertyString() {
39 $handles = $this->getHandles();
41 if (!$handles) {
42 return phutil_tag('em', array(), pht('None'));
44 $list_uri = '/subscriptions/list/'.$this->getObjectPHID().'/';
45 return $this->buildString($list_uri);
48 private function buildString($list_uri) {
49 $handles = $this->getHandles();
51 // Always show this many subscribers.
52 $show_count = 3;
53 $subscribers_count = count($handles);
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, 'renderHovercardLink'));
63 $show = array_slice($handles, 0, $show_count);
64 $show = array_values($show);
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',
74 $not_shown_txt);
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);