@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 PonderQuestionEditor
4 extends PonderEditor {
5
6 private $answer;
7
8 public function getEditorObjectsDescription() {
9 return pht('Ponder Questions');
10 }
11
12 public function getCreateObjectTitle($author, $object) {
13 return pht('%s asked this question.', $author);
14 }
15
16 public function getCreateObjectTitleForFeed($author, $object) {
17 return pht('%s asked %s.', $author, $object);
18 }
19
20 /**
21 * This is used internally on @{method:applyInitialEffects} if a transaction
22 * of type PonderQuestionTransaction::TYPE_ANSWERS is in the mix. The value
23 * is set to the //last// answer in the transactions. Practically, one
24 * answer is given at a time in the application, though theoretically
25 * this is buggy.
26 *
27 * The answer is used in emails to generate proper links.
28 */
29 private function setAnswer(PonderAnswer $answer) {
30 $this->answer = $answer;
31 return $this;
32 }
33 private function getAnswer() {
34 return $this->answer;
35 }
36
37 protected function shouldApplyInitialEffects(
38 PhabricatorLiskDAO $object,
39 array $xactions) {
40
41 foreach ($xactions as $xaction) {
42 switch ($xaction->getTransactionType()) {
43 case PonderQuestionAnswerTransaction::TRANSACTIONTYPE:
44 return true;
45 }
46 }
47
48 return false;
49 }
50
51 protected function applyInitialEffects(
52 PhabricatorLiskDAO $object,
53 array $xactions) {
54
55 foreach ($xactions as $xaction) {
56 switch ($xaction->getTransactionType()) {
57 case PonderQuestionAnswerTransaction::TRANSACTIONTYPE:
58 $new_value = $xaction->getNewValue();
59 $new = idx($new_value, '+', array());
60 foreach ($new as $new_answer) {
61 $answer = idx($new_answer, 'answer');
62 if (!$answer) {
63 continue;
64 }
65 $answer->save();
66 $this->setAnswer($answer);
67 }
68 break;
69 }
70 }
71 }
72
73 public function getTransactionTypes() {
74 $types = parent::getTransactionTypes();
75 $types[] = PhabricatorTransactions::TYPE_COMMENT;
76 $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
77
78 return $types;
79 }
80
81 protected function supportsSearch() {
82 return true;
83 }
84
85 protected function shouldImplyCC(
86 PhabricatorLiskDAO $object,
87 PhabricatorApplicationTransaction $xaction) {
88
89 switch ($xaction->getTransactionType()) {
90 case PonderQuestionAnswerTransaction::TRANSACTIONTYPE:
91 return false;
92 }
93
94 return parent::shouldImplyCC($object, $xaction);
95 }
96
97 protected function shouldSendMail(
98 PhabricatorLiskDAO $object,
99 array $xactions) {
100 foreach ($xactions as $xaction) {
101 switch ($xaction->getTransactionType()) {
102 case PonderQuestionAnswerTransaction::TRANSACTIONTYPE:
103 return false;
104 }
105 }
106 return true;
107 }
108
109 protected function getMailTo(PhabricatorLiskDAO $object) {
110 return array(
111 $object->getAuthorPHID(),
112 $this->requireActor()->getPHID(),
113 );
114 }
115
116 protected function shouldPublishFeedStory(
117 PhabricatorLiskDAO $object,
118 array $xactions) {
119 foreach ($xactions as $xaction) {
120 switch ($xaction->getTransactionType()) {
121 case PonderQuestionAnswerTransaction::TRANSACTIONTYPE:
122 return false;
123 }
124 }
125 return true;
126 }
127
128 public function getMailTagsMap() {
129 return array(
130 PonderQuestionTransaction::MAILTAG_DETAILS =>
131 pht('Someone changes the questions details.'),
132 PonderQuestionTransaction::MAILTAG_ANSWERS =>
133 pht('Someone adds a new answer.'),
134 PonderQuestionTransaction::MAILTAG_COMMENT =>
135 pht('Someone comments on the question.'),
136 PonderQuestionTransaction::MAILTAG_OTHER =>
137 pht('Other question activity not listed above occurs.'),
138 );
139 }
140
141 protected function buildReplyHandler(PhabricatorLiskDAO $object) {
142 return id(new PonderQuestionReplyHandler())
143 ->setMailReceiver($object);
144 }
145
146 protected function buildMailTemplate(PhabricatorLiskDAO $object) {
147 $id = $object->getID();
148 $title = $object->getTitle();
149
150 return id(new PhabricatorMetaMTAMail())
151 ->setSubject("Q{$id}: {$title}");
152 }
153
154 protected function buildMailBody(
155 PhabricatorLiskDAO $object,
156 array $xactions) {
157
158 $body = parent::buildMailBody($object, $xactions);
159
160 $header = pht('QUESTION DETAIL');
161 $uri = '/Q'.$object->getID();
162 foreach ($xactions as $xaction) {
163 $type = $xaction->getTransactionType();
164 $old = $xaction->getOldValue();
165 $new = $xaction->getNewValue();
166 // If the user just asked the question, add the question text.
167 if ($type == PonderQuestionContentTransaction::TRANSACTIONTYPE) {
168 if ($old === null) {
169 $body->addRawSection($new);
170 }
171 }
172 }
173
174 $body->addLinkSection(
175 $header,
176 PhabricatorEnv::getProductionURI($uri));
177
178 return $body;
179 }
180
181 protected function shouldApplyHeraldRules(
182 PhabricatorLiskDAO $object,
183 array $xactions) {
184 return true;
185 }
186
187 protected function buildHeraldAdapter(
188 PhabricatorLiskDAO $object,
189 array $xactions) {
190
191 return id(new HeraldPonderQuestionAdapter())
192 ->setQuestion($object);
193 }
194
195}