@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
3abstract class PhabricatorProjectColumnOrder
4 extends Phobject {
5
6 private $viewer;
7
8 final public function setViewer(PhabricatorUser $viewer) {
9 $this->viewer = $viewer;
10 return $this;
11 }
12
13 final public function getViewer() {
14 return $this->viewer;
15 }
16
17 final public function getColumnOrderKey() {
18 return $this->getPhobjectClassConstant('ORDERKEY');
19 }
20
21 final public static function getAllOrders() {
22 return id(new PhutilClassMapQuery())
23 ->setAncestorClass(self::class)
24 ->setUniqueMethod('getColumnOrderKey')
25 ->setSortMethod('getMenuOrder')
26 ->execute();
27 }
28
29 final public static function getEnabledOrders() {
30 $map = self::getAllOrders();
31
32 foreach ($map as $key => $order) {
33 if (!$order->isEnabled()) {
34 unset($map[$key]);
35 }
36 }
37
38 return $map;
39 }
40
41 final public static function getOrderByKey($key) {
42 $map = self::getAllOrders();
43
44 if (!isset($map[$key])) {
45 throw new Exception(
46 pht(
47 'No column ordering exists with key "%s".',
48 $key));
49 }
50
51 return $map[$key];
52 }
53
54 final public function getColumnTransactions($object, array $header) {
55 $result = $this->newColumnTransactions($object, $header);
56
57 if (!is_array($result) && !is_null($result)) {
58 throw new Exception(
59 pht(
60 'Expected "newColumnTransactions()" on "%s" to return "null" or a '.
61 'list of transactions, but got "%s".',
62 get_class($this),
63 phutil_describe_type($result)));
64 }
65
66 if ($result === null) {
67 $result = array();
68 }
69
70 assert_instances_of($result, PhabricatorApplicationTransaction::class);
71
72 return $result;
73 }
74
75 final public function getMenuIconIcon() {
76 return $this->newMenuIconIcon();
77 }
78
79 protected function newMenuIconIcon() {
80 return 'fa-sort-amount-asc';
81 }
82
83 abstract public function getDisplayName();
84 abstract public function getHasHeaders();
85 abstract public function getCanReorder();
86
87 public function getMenuOrder() {
88 return 9000;
89 }
90
91 public function isEnabled() {
92 return true;
93 }
94
95 protected function newColumnTransactions($object, array $header) {
96 return array();
97 }
98
99 final public function getHeadersForObjects(array $objects) {
100 $headers = $this->newHeadersForObjects($objects);
101
102 if (!is_array($headers)) {
103 throw new Exception(
104 pht(
105 'Expected "newHeadersForObjects()" on "%s" to return a list '.
106 'of headers, but got "%s".',
107 get_class($this),
108 phutil_describe_type($headers)));
109 }
110
111 assert_instances_of($headers, PhabricatorProjectColumnHeader::class);
112
113 // Add a "0" to the end of each header. This makes them sort above object
114 // cards in the same group.
115 foreach ($headers as $header) {
116 $vector = $header->getSortVector();
117 $vector[] = 0;
118 $header->setSortVector($vector);
119 }
120
121 return $headers;
122 }
123
124 protected function newHeadersForObjects(array $objects) {
125 return array();
126 }
127
128 final public function getSortVectorsForObjects(array $objects) {
129 $vectors = $this->newSortVectorsForObjects($objects);
130
131 if (!is_array($vectors)) {
132 throw new Exception(
133 pht(
134 'Expected "newSortVectorsForObjects()" on "%s" to return a '.
135 'map of vectors, but got "%s".',
136 get_class($this),
137 phutil_describe_type($vectors)));
138 }
139
140 assert_same_keys($objects, $vectors);
141
142 return $vectors;
143 }
144
145 protected function newSortVectorsForObjects(array $objects) {
146 $vectors = array();
147
148 foreach ($objects as $key => $object) {
149 $vectors[$key] = $this->newSortVectorForObject($object);
150 }
151
152 return $vectors;
153 }
154
155 protected function newSortVectorForObject($object) {
156 return array();
157 }
158
159 final public function getHeaderKeysForObjects(array $objects) {
160 $header_keys = $this->newHeaderKeysForObjects($objects);
161
162 if (!is_array($header_keys)) {
163 throw new Exception(
164 pht(
165 'Expected "newHeaderKeysForObject()" on "%s" to return a '.
166 'map of header keys, but got "%s".',
167 get_class($this),
168 phutil_describe_type($header_keys)));
169 }
170
171 assert_same_keys($objects, $header_keys);
172
173 return $header_keys;
174 }
175
176 protected function newHeaderKeysForObjects(array $objects) {
177 $header_keys = array();
178
179 foreach ($objects as $key => $object) {
180 $header_keys[$key] = $this->newHeaderKeyForObject($object);
181 }
182
183 return $header_keys;
184 }
185
186 protected function newHeaderKeyForObject($object) {
187 return null;
188 }
189
190 final protected function newTransaction($object) {
191 return $object->getApplicationTransactionTemplate();
192 }
193
194 final protected function newHeader() {
195 return id(new PhabricatorProjectColumnHeader())
196 ->setOrderKey($this->getColumnOrderKey());
197 }
198
199 final protected function newEffect() {
200 return new PhabricatorProjectDropEffect();
201 }
202
203 final public function toDictionary() {
204 return array(
205 'orderKey' => $this->getColumnOrderKey(),
206 'hasHeaders' => $this->getHasHeaders(),
207 'canReorder' => $this->getCanReorder(),
208 );
209 }
210
211}