@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
1<?php
2
3final class PhorgeApplicationMentionsListView extends Phobject {
4
5 private $edgeQuery;
6 private $viewer;
7 private $hasMentions = false;
8
9 public function setEdgeQuery(
10 PhabricatorEdgeQuery $edge_query): self {
11 $this->edgeQuery = $edge_query;
12 return $this;
13 }
14
15 public function setViewer(
16 PhabricatorUser $viewer): self {
17 $this->viewer = $viewer;
18 return $this;
19 }
20
21 public function getMentionsView(): ?PHUIPropertyListView {
22
23 $in_type = PhabricatorObjectMentionedByObjectEdgeType::EDGECONST;
24 $out_type = PhabricatorObjectMentionsObjectEdgeType::EDGECONST;
25
26 $in_phids = $this->edgeQuery->getDestinationPHIDs(
27 array(),
28 array($in_type));
29 $out_phids = $this->edgeQuery->getDestinationPHIDs(
30 array(),
31 array($out_type));
32
33 // Filter out any mentioned users from the list. These are not generally
34 // very interesting to show in a relationship summary since they usually
35 // end up as subscribers anyway.
36
37 $user_type = PhabricatorPeopleUserPHIDType::TYPECONST;
38
39 foreach ($out_phids as $key => $out_phid) {
40 if (phid_get_type($out_phid) == $user_type) {
41 unset($out_phids[$key]);
42 }
43 }
44
45 if (!$in_phids && !$out_phids) {
46 return null;
47 }
48
49 $in_handles = $this->viewer->loadHandles($in_phids);
50 $out_handles = $this->viewer->loadHandles($out_phids);
51
52 $in_handles = $this->getCompleteHandles($in_handles);
53 $out_handles = $this->getCompleteHandles($out_handles);
54
55 if (!count($in_handles) && !count($out_handles)) {
56 return null;
57 }
58
59 $view = new PHUIPropertyListView();
60
61 if (count($in_handles)) {
62 $view->addProperty(
63 pht('Mentioned In'), $in_handles->renderList());
64 }
65
66 if (count($out_handles)) {
67 $view->addProperty(
68 pht('Mentioned Here'), $out_handles->renderList());
69 }
70
71 $this->hasMentions = true;
72
73 return $view;
74
75 }
76
77 public function hasMentions(): bool {
78 return $this->hasMentions;
79 }
80
81
82 private function getCompleteHandles(
83 PhabricatorHandleList $handles): PhabricatorHandleList {
84 $phids = array();
85
86 foreach ($handles as $phid => $handle) {
87 if (!$handle->isComplete()) {
88 continue;
89 }
90 $phids[] = $phid;
91 }
92
93 return $handles->newSublist($phids);
94 }
95
96
97}