diff --git a/src/applications/legalpad/query/LegalpadDocumentQuery.php b/src/applications/legalpad/query/LegalpadDocumentQuery.php --- a/src/applications/legalpad/query/LegalpadDocumentQuery.php +++ b/src/applications/legalpad/query/LegalpadDocumentQuery.php @@ -14,6 +14,7 @@ private $needDocumentBodies; private $needContributors; private $needSignatures; + private $needViewerSignatures; public function withIDs(array $ids) { $this->ids = $ids; @@ -65,6 +66,11 @@ return $this; } + public function needViewerSignatures($need) { + $this->needViewerSignatures = $need; + return $this; + } + protected function loadPage() { $table = new LegalpadDocument(); $conn_r = $table->establishConnection('r'); @@ -118,6 +124,29 @@ $documents = $this->loadSignatures($documents); } + if ($this->needViewerSignatures) { + if ($documents) { + + if ($this->getViewer()->getPHID()) { + $signatures = id(new LegalpadDocumentSignatureQuery()) + ->setViewer($this->getViewer()) + ->withSignerPHIDs(array($this->getViewer()->getPHID())) + ->withDocumentPHIDs(mpull($documents, 'getPHID')) + ->execute(); + $signatures = mpull($signatures, null, 'getDocumentPHID'); + } else { + $signatures = array(); + } + + foreach ($documents as $document) { + $signature = idx($signatures, $document->getPHID()); + $document->attachUserSignature( + $this->getViewer()->getPHID(), + $signature); + } + } + } + return $documents; } diff --git a/src/applications/legalpad/query/LegalpadDocumentSearchEngine.php b/src/applications/legalpad/query/LegalpadDocumentSearchEngine.php --- a/src/applications/legalpad/query/LegalpadDocumentSearchEngine.php +++ b/src/applications/legalpad/query/LegalpadDocumentSearchEngine.php @@ -29,6 +29,7 @@ public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { $query = id(new LegalpadDocumentQuery()) + ->needViewerSignatures(true) ->withCreatorPHIDs($saved->getParameter('creatorPHIDs', array())) ->withContributorPHIDs($saved->getParameter('contributorPHIDs', array())); @@ -111,7 +112,7 @@ protected function getRequiredHandlePHIDsForResultList( array $documents, PhabricatorSavedQuery $query) { - return array_mergev(mpull($documents, 'getRecentContributorPHIDs')); + return array(); } protected function renderResultList( @@ -126,8 +127,6 @@ $list->setUser($viewer); foreach ($documents as $document) { $last_updated = phabricator_date($document->getDateModified(), $viewer); - $recent_contributors = $document->getRecentContributorPHIDs(); - $updater = $handles[reset($recent_contributors)]->renderLink(); $title = $document->getTitle(); @@ -136,9 +135,32 @@ ->setHeader($title) ->setHref('/'.$document->getMonogram()) ->setObject($document) - ->addIcon('none', pht('Last updated: %s', $last_updated)) - ->addByline(pht('Updated by: %s', $updater)) - ->addAttribute(pht('Versions: %d', $document->getVersions())); + ->addIcon('none', pht('Version %d', $document->getVersions())) + ->addIcon('none', pht('Updated %s', $last_updated)); + + if ($viewer->getPHID()) { + $signature = $document->getUserSignature($viewer->getPHID()); + } else { + $signature = null; + } + + if ($signature) { + $item->addAttribute( + array( + id(new PHUIIconView())->setIconFont('fa-check-square-o', 'green'), + ' ', + pht( + 'Signed on %s', + phabricator_date($signature->getDateCreated(), $viewer)), + )); + } else { + $item->addAttribute( + array( + id(new PHUIIconView())->setIconFont('fa-square-o', 'grey'), + ' ', + pht('Not Signed'), + )); + } $list->addItem($item); } diff --git a/src/applications/legalpad/storage/LegalpadDocument.php b/src/applications/legalpad/storage/LegalpadDocument.php --- a/src/applications/legalpad/storage/LegalpadDocument.php +++ b/src/applications/legalpad/storage/LegalpadDocument.php @@ -18,7 +18,8 @@ private $documentBody = self::ATTACHABLE; private $contributors = self::ATTACHABLE; - private $signatures = self::ATTACHABLE; + private $signatures = self::ATTACHABLE; + private $userSignatures = array(); public static function initializeNewDocument(PhabricatorUser $actor) { $app = id(new PhabricatorApplicationQuery()) @@ -91,6 +92,17 @@ return 'L'.$this->getID(); } + public function getUserSignature($phid) { + return $this->assertAttachedKey($this->userSignatures, $phid); + } + + public function attachUserSignature( + $user_phid, + LegalpadDocumentSignature $signature = null) { + $this->userSignatures[$user_phid] = $signature; + return $this; + } + /* -( PhabricatorSubscribableInterface )----------------------------------- */