Skip to content

Commit

Permalink
pkp/pkp-lib#10178 Allow search by DOI in DOI manager
Browse files Browse the repository at this point in the history
  • Loading branch information
taslangraham committed Dec 24, 2024
1 parent 2fb914a commit 3c5e68f
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions classes/submission/Collector.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @file classes/submission/Collector.php
*
Expand All @@ -13,6 +14,7 @@

namespace APP\submission;

use APP\core\Application;
use APP\facades\Repo;
use Illuminate\Database\Query\Builder;

Expand Down Expand Up @@ -101,4 +103,33 @@ protected function addHasDoisFilterToQuery(Builder $q)
});
});
}

/** @copydoc PKP/classes/submission/Collector::addFilterByAssociatedDoiIdsToQuery() */
protected function addFilterByAssociatedDoiIdsToQuery(Builder $q)
{
// Does two things:
// 1 - Defaults to empty result when no DOIs are enabled.
// 2 - Ensures that the union clause can be safely used if a query with a union clause is the only one that is executed.
$q->selectRaw('NULL AS submission_id')->whereRaw('1 = 0');

$q->whereIn('s.submission_id', function (Builder $query) {
$context = Application::get()->getRequest()->getContext();

$query->when($context->isDoiTypeEnabled(Repo::doi()::TYPE_REPRESENTATION), function (Builder $q) {
$q->select('p.submission_id')
->from('publication_galleys AS g')
->join('dois AS d', 'g.doi_id', '=', 'd.doi_id')
->join('publications AS p', 'g.publication_id', '=', 'p.publication_id')
->whereLike('d.doi', "{$this->searchPhrase}%");
})
->when($context->isDoiTypeEnabled(Repo::doi()::TYPE_PUBLICATION), function (Builder $q) {
$q->union(function (Builder $query) {
$query->select('p.submission_id')
->from('publications AS p')
->join('dois AS d', 'p.doi_id', '=', 'd.doi_id')
->whereLike('d.doi', "{$this->searchPhrase}%");
});
});
});
}
}

0 comments on commit 3c5e68f

Please sign in to comment.