3 final class PholioMockEditor
extends PhabricatorApplicationTransactionEditor
{
5 private $images = array();
7 public function getEditorApplicationClass() {
8 return 'PhabricatorPholioApplication';
11 public function getEditorObjectsDescription() {
12 return pht('Pholio Mocks');
15 public function getCreateObjectTitle($author, $object) {
16 return pht('%s created this mock.', $author);
19 public function getCreateObjectTitleForFeed($author, $object) {
20 return pht('%s created %s.', $author, $object);
23 public function getTransactionTypes() {
24 $types = parent
::getTransactionTypes();
26 $types[] = PhabricatorTransactions
::TYPE_EDGE
;
27 $types[] = PhabricatorTransactions
::TYPE_COMMENT
;
28 $types[] = PhabricatorTransactions
::TYPE_VIEW_POLICY
;
29 $types[] = PhabricatorTransactions
::TYPE_EDIT_POLICY
;
34 protected function shouldSendMail(
35 PhabricatorLiskDAO
$object,
40 protected function buildReplyHandler(PhabricatorLiskDAO
$object) {
41 return id(new PholioReplyHandler())
42 ->setMailReceiver($object);
45 protected function buildMailTemplate(PhabricatorLiskDAO
$object) {
46 $monogram = $object->getMonogram();
47 $name = $object->getName();
49 return id(new PhabricatorMetaMTAMail())
50 ->setSubject("{$monogram}: {$name}");
53 protected function getMailTo(PhabricatorLiskDAO
$object) {
55 $object->getAuthorPHID(),
56 $this->requireActor()->getPHID(),
60 protected function buildMailBody(
61 PhabricatorLiskDAO
$object,
64 $viewer = $this->requireActor();
66 $body = id(new PhabricatorMetaMTAMailBody())
69 $mock_uri = $object->getURI();
70 $mock_uri = PhabricatorEnv
::getProductionURI($mock_uri);
72 $this->addHeadersAndCommentsToMailBody(
78 $type_inline = PholioMockInlineTransaction
::TRANSACTIONTYPE
;
81 foreach ($xactions as $xaction) {
82 if ($xaction->getTransactionType() == $type_inline) {
83 $inlines[] = $xaction;
87 $this->appendInlineCommentsForMail($object, $inlines, $body);
89 $body->addLinkSection(
91 PhabricatorEnv
::getProductionURI($object->getURI()));
96 private function appendInlineCommentsForMail(
99 PhabricatorMetaMTAMailBody
$body) {
105 $viewer = $this->requireActor();
107 $header = pht('INLINE COMMENTS');
108 $body->addRawPlaintextSection($header);
109 $body->addRawHTMLSection(phutil_tag('strong', array(), $header));
111 $image_ids = array();
112 foreach ($inlines as $inline) {
113 $comment = $inline->getComment();
114 $image_id = $comment->getImageID();
115 $image_ids[$image_id] = $image_id;
118 $images = id(new PholioImageQuery())
120 ->withIDs($image_ids)
122 $images = mpull($images, null, 'getID');
124 foreach ($inlines as $inline) {
125 $comment = $inline->getComment();
126 $content = $comment->getContent();
127 $image_id = $comment->getImageID();
128 $image = idx($images, $image_id);
130 $image_name = $image->getName();
132 $image_name = pht('Unknown (ID %d)', $image_id);
135 $body->addRemarkupSection(
136 pht('Image "%s":', $image_name),
141 protected function getMailSubjectPrefix() {
142 return pht('[Pholio]');
145 public function getMailTagsMap() {
147 PholioTransaction
::MAILTAG_STATUS
=>
148 pht("A mock's status changes."),
149 PholioTransaction
::MAILTAG_COMMENT
=>
150 pht('Someone comments on a mock.'),
151 PholioTransaction
::MAILTAG_UPDATED
=>
152 pht('Mock images or descriptions change.'),
153 PholioTransaction
::MAILTAG_OTHER
=>
154 pht('Other mock activity not listed above occurs.'),
158 protected function shouldPublishFeedStory(
159 PhabricatorLiskDAO
$object,
164 protected function supportsSearch() {
168 protected function shouldApplyHeraldRules(
169 PhabricatorLiskDAO
$object,
174 protected function buildHeraldAdapter(
175 PhabricatorLiskDAO
$object,
178 return id(new HeraldPholioMockAdapter())
182 protected function sortTransactions(array $xactions) {
186 // Move inline comments to the end, so the comments precede them.
187 foreach ($xactions as $xaction) {
188 $type = $xaction->getTransactionType();
189 if ($type == PholioMockInlineTransaction
::TRANSACTIONTYPE
) {
196 return array_values(array_merge($head, $tail));
199 protected function shouldImplyCC(
200 PhabricatorLiskDAO
$object,
201 PhabricatorApplicationTransaction
$xaction) {
203 switch ($xaction->getTransactionType()) {
204 case PholioMockInlineTransaction
::TRANSACTIONTYPE
:
208 return parent
::shouldImplyCC($object, $xaction);
211 public function loadPholioImage($object, $phid) {
212 if (!isset($this->images
[$phid])) {
214 $image = id(new PholioImageQuery())
215 ->setViewer($this->getActor())
216 ->withPHIDs(array($phid))
222 'No image exists with PHID "%s".',
226 $mock_phid = $image->getMockPHID();
228 if ($mock_phid !== $object->getPHID()) {
231 'Image ("%s") belongs to the wrong object ("%s", expected "%s").',
234 $object->getPHID()));
238 $this->images
[$phid] = $image;
241 return $this->images
[$phid];