1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-15 19:32:40 +01:00
phorge-phorge/src/applications/subscriptions/view/SubscriptionListStringBuilder.php
epriestley cebc7f4e8b Show profile pictures in subscribers dialog
Summary: Ref T4400. Also stops rendering "and 1 other" in subscriber lists, since it looks a bit silly in practice (we can just put the other subscriber there instead). Don't do the "and x others" until X is at least 2.

Test Plan: Viewed/clicked subscriber lists and transactions.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4400

Differential Revision: https://secure.phabricator.com/D8573
2014-03-19 19:29:48 -07:00

84 lines
2.1 KiB
PHP

<?php
final class SubscriptionListStringBuilder {
private $handles;
private $objectPHID;
public function setHandles(array $handles) {
assert_instances_of($handles, 'PhabricatorObjectHandle');
$this->handles = $handles;
return $this;
}
public function getHandles() {
return $this->handles;
}
public function setObjectPHID($object_phid) {
$this->objectPHID = $object_phid;
return $this;
}
public function getObjectPHID() {
return $this->objectPHID;
}
public function buildTransactionString($change_type) {
$handles = $this->getHandles();
if (!$handles) {
return;
}
$list_uri = '/subscriptions/transaction/'.
$change_type.'/'.
$this->getObjectPHID().'/';
return $this->buildString($list_uri);
}
public function buildPropertyString() {
$handles = $this->getHandles();
if (!$handles) {
return phutil_tag('em', array(), pht('None'));
}
$list_uri = '/subscriptions/list/'.$this->getObjectPHID().'/';
return $this->buildString($list_uri);
}
private function buildString($list_uri) {
$handles = $this->getHandles();
// Always show this many subscribers.
$show_count = 3;
$subscribers_count = count($handles);
// It looks a bit silly to render "a, b, c, and 1 other", since we could
// have just put that other subscriber there in place of the "1 other"
// link. Instead, render "a, b, c, d" in this case, and then when we get one
// more render "a, b, c, and 2 others".
if ($subscribers_count <= ($show_count + 1)) {
return phutil_implode_html(', ', mpull($handles, 'renderLink'));
}
$show = array_slice($handles, 0, $show_count);
$show = array_values($show);
$not_shown_count = $subscribers_count - $show_count;
$not_shown_txt = pht('%d other(s)', $not_shown_count);
$not_shown_link = javelin_tag(
'a',
array(
'href' => $list_uri,
'sigil' => 'workflow'
),
$not_shown_txt);
return pht(
'%s, %s, %s and %s',
$show[0]->renderLink(),
$show[1]->renderLink(),
$show[2]->renderLink(),
$not_shown_link);
}
}