From e389fc70fa22e5dde2e3b9f415ca68ef34d47719 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 21 Nov 2012 17:27:20 -0800 Subject: [PATCH] Allow users to add comments in Pholio Summary: Basic support for adding comments. Missing a lot of frills. Uses new comment/transaction UI. Test Plan: Added some comments. Tried to add an empty comment. Some comments: {F22361} No text provided: {F22362} Reviewers: btrahan, chad Reviewed By: btrahan CC: aran Maniphest Tasks: T2097 Differential Revision: https://secure.phabricator.com/D3834 --- src/__phutil_library_map__.php | 4 + .../PhabricatorApplicationPholio.php | 7 +- .../PholioMockCommentController.php | 78 +++++++++++++++++++ .../controller/PholioMockViewController.php | 41 +++++++++- .../pholio/query/PholioTransactionQuery.php | 64 +++++++++++++++ 5 files changed, 189 insertions(+), 5 deletions(-) create mode 100644 src/applications/pholio/controller/PholioMockCommentController.php create mode 100644 src/applications/pholio/query/PholioTransactionQuery.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index ade3a48d7a..8b9820f21e 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1208,6 +1208,7 @@ phutil_register_library_map(array( 'PholioImage' => 'applications/pholio/storage/PholioImage.php', 'PholioIndexer' => 'applications/pholio/indexer/PholioIndexer.php', 'PholioMock' => 'applications/pholio/storage/PholioMock.php', + 'PholioMockCommentController' => 'applications/pholio/controller/PholioMockCommentController.php', 'PholioMockEditController' => 'applications/pholio/controller/PholioMockEditController.php', 'PholioMockEditor' => 'applications/pholio/editor/PholioMockEditor.php', 'PholioMockListController' => 'applications/pholio/controller/PholioMockListController.php', @@ -1215,6 +1216,7 @@ phutil_register_library_map(array( 'PholioMockViewController' => 'applications/pholio/controller/PholioMockViewController.php', 'PholioPixelComment' => 'applications/pholio/storage/PholioPixelComment.php', 'PholioTransaction' => 'applications/pholio/storage/PholioTransaction.php', + 'PholioTransactionQuery' => 'applications/pholio/query/PholioTransactionQuery.php', 'PhortuneMonthYearExpiryControl' => 'applications/phortune/control/PhortuneMonthYearExpiryControl.php', 'PhortuneStripeBaseController' => 'applications/phortune/stripe/controller/PhortuneStripeBaseController.php', 'PhortuneStripePaymentFormView' => 'applications/phortune/stripe/view/PhortuneStripePaymentFormView.php', @@ -2412,6 +2414,7 @@ phutil_register_library_map(array( 2 => 'PhabricatorPolicyInterface', 3 => 'PhabricatorSubscribableInterface', ), + 'PholioMockCommentController' => 'PholioController', 'PholioMockEditController' => 'PholioController', 'PholioMockEditor' => 'PhabricatorEditor', 'PholioMockListController' => 'PholioController', @@ -2427,6 +2430,7 @@ phutil_register_library_map(array( 0 => 'PholioDAO', 1 => 'PhabricatorMarkupInterface', ), + 'PholioTransactionQuery' => 'PhabricatorOffsetPagedQuery', 'PhortuneMonthYearExpiryControl' => 'AphrontFormControl', 'PhortuneStripeBaseController' => 'PhabricatorController', 'PhortuneStripePaymentFormView' => 'AphrontView', diff --git a/src/applications/pholio/application/PhabricatorApplicationPholio.php b/src/applications/pholio/application/PhabricatorApplicationPholio.php index fdc46cdbc5..83e754ea8d 100644 --- a/src/applications/pholio/application/PhabricatorApplicationPholio.php +++ b/src/applications/pholio/application/PhabricatorApplicationPholio.php @@ -56,9 +56,10 @@ final class PhabricatorApplicationPholio extends PhabricatorApplication { '/M(?P[1-9]\d*)' => 'PholioMockViewController', '/pholio/' => array( '' => 'PholioMockListController', - 'view/(?P\w+)/' => 'PholioMockListController', - 'new/' => 'PholioMockEditController', - 'edit/(?P\d+)/' => 'PholioMockEditController', + 'view/(?P\w+)/' => 'PholioMockListController', + 'new/' => 'PholioMockEditController', + 'edit/(?P\d+)/' => 'PholioMockEditController', + 'comment/(?P\d+)/' => 'PholioMockCommentController', ), ); } diff --git a/src/applications/pholio/controller/PholioMockCommentController.php b/src/applications/pholio/controller/PholioMockCommentController.php new file mode 100644 index 0000000000..a5507848d8 --- /dev/null +++ b/src/applications/pholio/controller/PholioMockCommentController.php @@ -0,0 +1,78 @@ +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(), + )); + + // TODO: Move this to an Editor. + + $xaction = id(new PholioTransaction()) + // TODO: Formalize transaction types. + ->setTransactionType('none') + ->setAuthorPHID($user->getPHID()) + ->setComment($comment) + ->setContentSource($content_source) + ->setMockID($mock->getID()); + + $xaction->save(); + + return id(new AphrontRedirectResponse())->setURI($mock_uri); + } + +} diff --git a/src/applications/pholio/controller/PholioMockViewController.php b/src/applications/pholio/controller/PholioMockViewController.php index 62bb5bad2b..1e280937d5 100644 --- a/src/applications/pholio/controller/PholioMockViewController.php +++ b/src/applications/pholio/controller/PholioMockViewController.php @@ -40,14 +40,25 @@ final class PholioMockViewController extends PholioController { return new Aphront404Response(); } + $xactions = id(new PholioTransactionQuery()) + ->withMockIDs(array($mock->getID())) + ->execute(); + + $phids = array(); $phids[] = $mock->getAuthorPHID(); + foreach ($xactions as $xaction) { + $phids[] = $xaction->getAuthorPHID(); + } $this->loadHandles($phids); $engine = id(new PhabricatorMarkupEngine()) ->setViewer($user); $engine->addObject($mock, PholioMock::MARKUP_FIELD_DESCRIPTION); + foreach ($xactions as $xaction) { + $engine->addObject($xaction, PholioTransaction::MARKUP_FIELD_COMMENT); + } $engine->process(); $title = 'M'.$mock->getID().' '.$mock->getName(); @@ -65,6 +76,9 @@ final class PholioMockViewController extends PholioController { '

'. 'Comments/Transactions Go Here

'; + + $xaction_view = $this->buildTransactionView($xactions, $engine); + $add_comment = $this->buildAddCommentView($mock); $content = array( @@ -72,7 +86,7 @@ final class PholioMockViewController extends PholioController { $actions, $properties, $carousel, - $comments, + $xaction_view, $add_comment, ); @@ -155,7 +169,7 @@ final class PholioMockViewController extends PholioController { $form = id(new AphrontFormView()) ->setUser($user) - ->setAction($this->getApplicationURI('/addcomment/'.$mock->getID().'/')) + ->setAction($this->getApplicationURI('/comment/'.$mock->getID().'/')) ->setWorkflow(true) ->setFlexible(true) ->appendChild( @@ -172,4 +186,27 @@ final class PholioMockViewController extends PholioController { ); } + private function buildTransactionView( + array $xactions, + PhabricatorMarkupEngine $engine) { + assert_instances_of($xactions, 'PholioTransaction'); + + $view = new PhabricatorTimelineView(); + + foreach ($xactions as $xaction) { + $author = $this->getHandle($xaction->getAuthorPHID()); + + $view->addEvent( + id(new PhabricatorTimelineEventView()) + ->setUserHandle($author) + ->setTitle($author->renderLink().' added a comment.') + ->appendChild( + $engine->getOutput( + $xaction, + PholioTransaction::MARKUP_FIELD_COMMENT))); + } + + return $view; + } + } diff --git a/src/applications/pholio/query/PholioTransactionQuery.php b/src/applications/pholio/query/PholioTransactionQuery.php new file mode 100644 index 0000000000..376e49dddd --- /dev/null +++ b/src/applications/pholio/query/PholioTransactionQuery.php @@ -0,0 +1,64 @@ +mockIDs = $ids; + return $this; + } + + public function execute() { + $table = new PholioTransaction(); + $conn_r = $table->establishConnection('r'); + + $data = queryfx_all( + $conn_r, + 'SELECT * FROM %T x %Q %Q %Q', + $table->getTableName(), + $this->buildWhereClause($conn_r), + $this->buildOrderClause($conn_r), + $this->buildLimitClause($conn_r)); + + return $table->loadAllFromArray($data); + } + + private function buildWhereClause(AphrontDatabaseConnection $conn_r) { + $where = array(); + + if ($this->mockIDs) { + $where[] = qsprintf( + $conn_r, + 'mockID IN (%Ld)', + $this->mockIDs); + } + + return $this->formatWhereClause($where); + } + + private function buildOrderClause(AphrontDatabaseConnection $conn_r) { + return 'ORDER BY id ASC'; + } + +}