Changeset View
Changeset View
Standalone View
Standalone View
src/applications/pholio/editor/PholioMockEditor.php
<?php | <?php | ||||
final class PholioMockEditor extends PhabricatorApplicationTransactionEditor { | final class PholioMockEditor extends PhabricatorApplicationTransactionEditor { | ||||
private $newImages = array(); | |||||
private $images = array(); | private $images = array(); | ||||
public function getEditorApplicationClass() { | public function getEditorApplicationClass() { | ||||
return 'PhabricatorPholioApplication'; | return 'PhabricatorPholioApplication'; | ||||
} | } | ||||
public function getEditorObjectsDescription() { | public function getEditorObjectsDescription() { | ||||
return pht('Pholio Mocks'); | return pht('Pholio Mocks'); | ||||
} | } | ||||
private function setNewImages(array $new_images) { | |||||
assert_instances_of($new_images, 'PholioImage'); | |||||
$this->newImages = $new_images; | |||||
return $this; | |||||
} | |||||
public function getNewImages() { | |||||
return $this->newImages; | |||||
} | |||||
public function getCreateObjectTitle($author, $object) { | public function getCreateObjectTitle($author, $object) { | ||||
return pht('%s created this mock.', $author); | return pht('%s created this mock.', $author); | ||||
} | } | ||||
public function getCreateObjectTitleForFeed($author, $object) { | public function getCreateObjectTitleForFeed($author, $object) { | ||||
return pht('%s created %s.', $author, $object); | return pht('%s created %s.', $author, $object); | ||||
} | } | ||||
public function getTransactionTypes() { | public function getTransactionTypes() { | ||||
$types = parent::getTransactionTypes(); | $types = parent::getTransactionTypes(); | ||||
$types[] = PhabricatorTransactions::TYPE_EDGE; | $types[] = PhabricatorTransactions::TYPE_EDGE; | ||||
$types[] = PhabricatorTransactions::TYPE_COMMENT; | $types[] = PhabricatorTransactions::TYPE_COMMENT; | ||||
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; | $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; | ||||
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY; | $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY; | ||||
return $types; | return $types; | ||||
} | } | ||||
protected function shouldApplyInitialEffects( | |||||
PhabricatorLiskDAO $object, | |||||
array $xactions) { | |||||
foreach ($xactions as $xaction) { | |||||
switch ($xaction->getTransactionType()) { | |||||
case PholioImageFileTransaction::TRANSACTIONTYPE: | |||||
return true; | |||||
} | |||||
} | |||||
return false; | |||||
} | |||||
protected function applyInitialEffects( | |||||
PhabricatorLiskDAO $object, | |||||
array $xactions) { | |||||
$new_images = array(); | |||||
foreach ($xactions as $xaction) { | |||||
switch ($xaction->getTransactionType()) { | |||||
case PholioImageFileTransaction::TRANSACTIONTYPE: | |||||
$new_value = $xaction->getNewValue(); | |||||
foreach ($new_value as $key => $txn_images) { | |||||
if ($key != '+') { | |||||
continue; | |||||
} | |||||
foreach ($txn_images as $image) { | |||||
$image->save(); | |||||
$new_images[] = $image; | |||||
} | |||||
} | |||||
break; | |||||
} | |||||
} | |||||
$this->setNewImages($new_images); | |||||
} | |||||
protected function applyFinalEffects( | |||||
PhabricatorLiskDAO $object, | |||||
array $xactions) { | |||||
$images = $this->getNewImages(); | |||||
foreach ($images as $image) { | |||||
$image->setMockPHID($object->getPHID()); | |||||
$image->save(); | |||||
} | |||||
return $xactions; | |||||
} | |||||
protected function shouldSendMail( | protected function shouldSendMail( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
array $xactions) { | array $xactions) { | ||||
return true; | return true; | ||||
} | } | ||||
protected function buildReplyHandler(PhabricatorLiskDAO $object) { | protected function buildReplyHandler(PhabricatorLiskDAO $object) { | ||||
return id(new PholioReplyHandler()) | return id(new PholioReplyHandler()) | ||||
->setMailReceiver($object); | ->setMailReceiver($object); | ||||
} | } | ||||
protected function buildMailTemplate(PhabricatorLiskDAO $object) { | protected function buildMailTemplate(PhabricatorLiskDAO $object) { | ||||
$id = $object->getID(); | $monogram = $object->getMonogram(); | ||||
$name = $object->getName(); | $name = $object->getName(); | ||||
return id(new PhabricatorMetaMTAMail()) | return id(new PhabricatorMetaMTAMail()) | ||||
->setSubject("M{$id}: {$name}"); | ->setSubject("{$monogram}: {$name}"); | ||||
} | } | ||||
protected function getMailTo(PhabricatorLiskDAO $object) { | protected function getMailTo(PhabricatorLiskDAO $object) { | ||||
return array( | return array( | ||||
$object->getAuthorPHID(), | $object->getAuthorPHID(), | ||||
$this->requireActor()->getPHID(), | $this->requireActor()->getPHID(), | ||||
); | ); | ||||
} | } | ||||
Show All 24 Lines | foreach ($xactions as $xaction) { | ||||
$inlines[] = $xaction; | $inlines[] = $xaction; | ||||
} | } | ||||
} | } | ||||
$this->appendInlineCommentsForMail($object, $inlines, $body); | $this->appendInlineCommentsForMail($object, $inlines, $body); | ||||
$body->addLinkSection( | $body->addLinkSection( | ||||
pht('MOCK DETAIL'), | pht('MOCK DETAIL'), | ||||
PhabricatorEnv::getProductionURI('/M'.$object->getID())); | PhabricatorEnv::getProductionURI($object->getURI())); | ||||
return $body; | return $body; | ||||
} | } | ||||
private function appendInlineCommentsForMail( | private function appendInlineCommentsForMail( | ||||
$object, | $object, | ||||
array $inlines, | array $inlines, | ||||
PhabricatorMetaMTAMailBody $body) { | PhabricatorMetaMTAMailBody $body) { | ||||
▲ Show 20 Lines • Show All 145 Lines • Show Last 20 Lines |