1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-14 19:02:41 +01:00
phorge-phorge/src/applications/pholio/controller/PholioMockCommentController.php

69 lines
1.7 KiB
PHP
Raw Normal View History

<?php
/**
* @group pholio
*/
final class PholioMockCommentController extends PholioController {
private $id;
public function willProcessRequest(array $data) {
$this->id = $data['id'];
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$mock = id(new PholioMockQuery())
->setViewer($user)
->withIDs(array($this->id))
->executeOne();
if (!$mock) {
return new Aphront404Response();
}
$mock_uri = '/M'.$mock->getID();
$comment = $request->getStr('comment');
if (!strlen($comment)) {
$dialog = id(new AphrontDialogView())
->setUser($user)
->setTitle(pht('Empty Comment'))
->appendChild('You did not provide a comment!')
->addCancelButton($mock_uri);
return id(new AphrontDialogResponse())->setDialog($dialog);
}
$content_source = PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_WEB,
array(
'ip' => $request->getRemoteAddr(),
));
$xactions = array();
$xactions[] = id(new PholioTransaction())
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
->attachComment(
id(new PholioTransactionComment())
->setContent($comment));
id(new PholioMockEditor())
->setActor($user)
->setContentSource($content_source)
->applyTransactions($mock, $xactions);
if ($request->isAjax()) {
return id(new PhabricatorApplicationTransactionResponse())
->setViewer($user)
->setTransactions($xactions)
->setAnchorOffset($request->getStr('anchor'));
} else {
return id(new AphrontRedirectResponse())->setURI($mock_uri);
}
}
}