Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/legalpad/query/LegalpadDocumentQuery.php b/src/applications/legalpad/query/LegalpadDocumentQuery.php
index cca501c1eb..264bf3e018 100644
--- a/src/applications/legalpad/query/LegalpadDocumentQuery.php
+++ b/src/applications/legalpad/query/LegalpadDocumentQuery.php
@@ -1,168 +1,189 @@
<?php
/**
* @group legalpad
*/
final class LegalpadDocumentQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $ids;
private $phids;
private $creatorPHIDs;
- private $contributorPHIDs; // TODO - T3479
+ private $contributorPHIDs;
private $dateCreatedAfter;
private $dateCreatedBefore;
private $needDocumentBodies;
private $needContributors;
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
}
public function withPHIDs(array $phids) {
$this->phids = $phids;
return $this;
}
public function withCreatorPHIDs(array $phids) {
$this->creatorPHIDs = $phids;
return $this;
}
public function withContributorPHIDs(array $phids) {
$this->contributorPHIDs = $phids;
return $this;
}
public function needDocumentBodies($need_bodies) {
$this->needDocumentBodies = $need_bodies;
return $this;
}
public function needContributors($need_contributors) {
$this->needContributors = $need_contributors;
return $this;
}
public function withDateCreatedBefore($date_created_before) {
$this->dateCreatedBefore = $date_created_before;
return $this;
}
public function withDateCreatedAfter($date_created_after) {
$this->dateCreatedAfter = $date_created_after;
return $this;
}
protected function loadPage() {
$table = new LegalpadDocument();
$conn_r = $table->establishConnection('r');
$data = queryfx_all(
$conn_r,
- 'SELECT legalpad_document.* FROM %T legalpad_document %Q %Q %Q',
+ 'SELECT d.* FROM %T d %Q %Q %Q %Q',
$table->getTableName(),
+ $this->buildJoinClause($conn_r),
$this->buildWhereClause($conn_r),
$this->buildOrderClause($conn_r),
$this->buildLimitClause($conn_r));
$documents = $table->loadAllFromArray($data);
return $documents;
}
protected function willFilterPage(array $documents) {
if (!$documents) {
return $documents;
}
if ($this->needDocumentBodies) {
$documents = $this->loadDocumentBodies($documents);
}
if ($this->needContributors) {
$documents = $this->loadContributors($documents);
}
return $documents;
}
+ private function buildJoinClause($conn_r) {
+ $joins = array();
+
+ if ($this->contributorPHIDs) {
+ $joins[] = qsprintf(
+ $conn_r,
+ 'JOIN edge e ON e.src = d.phid');
+ }
+
+ return implode(' ', $joins);
+ }
+
protected function buildWhereClause($conn_r) {
$where = array();
$where[] = $this->buildPagingClause($conn_r);
if ($this->ids) {
$where[] = qsprintf(
$conn_r,
- 'id IN (%Ld)',
+ 'd.id IN (%Ld)',
$this->ids);
}
if ($this->phids) {
$where[] = qsprintf(
$conn_r,
- 'phid IN (%Ls)',
+ 'd.phid IN (%Ls)',
$this->phids);
}
if ($this->creatorPHIDs) {
$where[] = qsprintf(
$conn_r,
- 'creatorPHID IN (%Ls)',
+ 'd.creatorPHID IN (%Ls)',
$this->creatorPHIDs);
}
if ($this->dateCreatedAfter) {
$where[] = qsprintf(
$conn_r,
- 'dateCreated >= %d',
+ 'd.dateCreated >= %d',
$this->dateCreatedAfter);
}
if ($this->dateCreatedBefore) {
$where[] = qsprintf(
$conn_r,
- 'dateCreated <= %d',
+ 'd.dateCreated <= %d',
$this->dateCreatedBefore);
}
+ if ($this->contributorPHIDs) {
+ $where[] = qsprintf(
+ $conn_r,
+ 'e.type = %s AND e.dst IN (%Ls)',
+ PhabricatorEdgeConfig::TYPE_OBJECT_HAS_CONTRIBUTOR,
+ $this->contributorPHIDs);
+ }
+
return $this->formatWhereClause($where);
}
private function loadDocumentBodies(array $documents) {
$body_phids = mpull($documents, 'getDocumentBodyPHID');
$bodies = id(new LegalpadDocumentBody())->loadAllWhere(
'phid IN (%Ls)',
$body_phids);
$bodies = mpull($bodies, null, 'getPHID');
foreach ($documents as $document) {
$body = idx($bodies, $document->getDocumentBodyPHID());
$document->attachDocumentBody($body);
}
return $documents;
}
private function loadContributors(array $documents) {
$document_map = mpull($documents, null, 'getPHID');
$edge_type = PhabricatorEdgeConfig::TYPE_OBJECT_HAS_CONTRIBUTOR;
$contributor_data = id(new PhabricatorEdgeQuery())
->withSourcePHIDs(array_keys($document_map))
->withEdgeTypes(array($edge_type))
->execute();
foreach ($document_map as $document_phid => $document) {
$data = $contributor_data[$document_phid];
$contributors = array_keys(idx($data, $edge_type, array()));
$document->attachContributors($contributors);
}
return $documents;
}
}
diff --git a/src/applications/legalpad/query/LegalpadDocumentSearchEngine.php b/src/applications/legalpad/query/LegalpadDocumentSearchEngine.php
index 1d6a817b22..ae14b8387a 100644
--- a/src/applications/legalpad/query/LegalpadDocumentSearchEngine.php
+++ b/src/applications/legalpad/query/LegalpadDocumentSearchEngine.php
@@ -1,93 +1,108 @@
<?php
/**
* @group legalpad
*/
final class LegalpadDocumentSearchEngine
extends PhabricatorApplicationSearchEngine {
public function buildSavedQueryFromRequest(AphrontRequest $request) {
$saved = new PhabricatorSavedQuery();
$saved->setParameter(
'creatorPHIDs',
array_values($request->getArr('creators')));
+ $saved->setParameter(
+ 'contributorPHIDs',
+ array_values($request->getArr('contributors')));
+
$saved->setParameter('createdStart', $request->getStr('createdStart'));
$saved->setParameter('createdEnd', $request->getStr('createdEnd'));
return $saved;
}
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
$query = id(new LegalpadDocumentQuery())
->needDocumentBodies(true)
->needContributors(true)
- ->withCreatorPHIDs($saved->getParameter('creatorPHIDs', array()));
+ ->withCreatorPHIDs($saved->getParameter('creatorPHIDs', array()))
+ ->withContributorPHIDs($saved->getParameter('contributorPHIDs', array()));
$start = $this->parseDateTime($saved->getParameter('createdStart'));
$end = $this->parseDateTime($saved->getParameter('createdEnd'));
if ($start) {
$query->withDateCreatedAfter($start);
}
if ($end) {
$query->withDateCreatedBefore($end);
}
return $query;
}
public function buildSearchForm(
AphrontFormView $form,
PhabricatorSavedQuery $saved_query) {
- $phids = $saved_query->getParameter('creatorPHIDs', array());
+
+ $creator_phids = $saved_query->getParameter('creatorPHIDs', array());
+ $contributor_phids = $saved_query->getParameter(
+ 'contributorPHIDs', array());
+ $phids = array_merge($creator_phids, $contributor_phids);
$handles = id(new PhabricatorObjectHandleData($phids))
->setViewer($this->requireViewer())
->loadHandles();
- $creator_tokens = mpull($handles, 'getFullName', 'getPHID');
+ $tokens = mpull($handles, 'getFullName', 'getPHID');
$form
->appendChild(
id(new AphrontFormTokenizerControl())
->setDatasource('/typeahead/common/users/')
->setName('creators')
->setLabel(pht('Creators'))
- ->setValue($creator_tokens));
+ ->setValue(array_select_keys($tokens, $creator_phids)))
+ ->appendChild(
+ id(new AphrontFormTokenizerControl())
+ ->setDatasource('/typeahead/common/users/')
+ ->setName('contributors')
+ ->setLabel(pht('Contributors'))
+ ->setValue(array_select_keys($tokens, $contributor_phids)));
$this->buildDateRange(
$form,
$saved_query,
'createdStart',
pht('Created After'),
'createdEnd',
pht('Created Before'));
}
protected function getURI($path) {
return '/legalpad/'.$path;
}
public function getBuiltinQueryNames() {
$names = array(
'all' => pht('All Documents'),
);
return $names;
}
public function buildSavedQueryFromBuiltin($query_key) {
$query = $this->newSavedQuery();
$query->setQueryKey($query_key);
switch ($query_key) {
case 'all':
return $query;
}
return parent::buildSavedQueryFromBuiltin($query_key);
}
}

File Metadata

Mime Type
text/x-diff
Expires
Fri, Nov 14, 9:36 AM (1 d, 9 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
336918
Default Alt Text
(8 KB)

Event Timeline