Remove product literal strings in "pht()", part 25
[phabricator.git] / src / applications / releeph / field / specification / ReleephDiffChurnFieldSpecification.php
blob3b472bbae7cd735e58e3bf8c948831ce46d7fb0f
1 <?php
3 final class ReleephDiffChurnFieldSpecification
4 extends ReleephFieldSpecification {
6 const REJECTIONS_WEIGHT = 30;
7 const COMMENTS_WEIGHT = 7;
8 const UPDATES_WEIGHT = 10;
9 const MAX_POINTS = 100;
11 public function getFieldKey() {
12 return 'churn';
15 public function getName() {
16 return pht('Churn');
19 public function renderPropertyViewValue(array $handles) {
20 $requested_object = $this->getObject()->getRequestedObject();
21 if (!($requested_object instanceof DifferentialRevision)) {
22 return null;
24 $diff_rev = $requested_object;
26 $xactions = id(new DifferentialTransactionQuery())
27 ->setViewer($this->getViewer())
28 ->withObjectPHIDs(array($diff_rev->getPHID()))
29 ->execute();
31 $rejections = 0;
32 $comments = 0;
33 $updates = 0;
35 foreach ($xactions as $xaction) {
36 switch ($xaction->getTransactionType()) {
37 case PhabricatorTransactions::TYPE_COMMENT:
38 $comments++;
39 break;
40 case DifferentialRevisionUpdateTransaction::TRANSACTIONTYPE:
41 $updates++;
42 break;
43 case DifferentialTransaction::TYPE_ACTION:
44 switch ($xaction->getNewValue()) {
45 case DifferentialAction::ACTION_REJECT:
46 $rejections++;
47 break;
49 break;
53 $points =
54 self::REJECTIONS_WEIGHT * $rejections +
55 self::COMMENTS_WEIGHT * $comments +
56 self::UPDATES_WEIGHT * $updates;
58 if ($points === 0) {
59 $points = 0.15 * self::MAX_POINTS;
60 $blurb = pht('Silent diff');
61 } else {
62 $parts = array();
63 if ($rejections) {
64 $parts[] = pht('%s rejection(s)', new PhutilNumber($rejections));
66 if ($comments) {
67 $parts[] = pht('%s comment(s)', new PhutilNumber($comments));
69 if ($updates) {
70 $parts[] = pht('%s update(s)', new PhutilNumber($updates));
73 if (count($parts) === 0) {
74 $blurb = '';
75 } else if (count($parts) === 1) {
76 $blurb = head($parts);
77 } else {
78 $last = array_pop($parts);
79 $blurb = pht('%s and %s', implode(', ', $parts), $last);
83 return id(new AphrontProgressBarView())
84 ->setValue($points)
85 ->setMax(self::MAX_POINTS)
86 ->setCaption($blurb)
87 ->render();