first commit
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* @file classes/services/QueryBuilders/ContextQueryBuilder.php
|
||||
*
|
||||
* Copyright (c) 2014-2021 Simon Fraser University
|
||||
* Copyright (c) 2000-2021 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class ContextQueryBuilder
|
||||
*
|
||||
* @ingroup query_builders
|
||||
*
|
||||
* @brief Journal list query builder
|
||||
*/
|
||||
|
||||
namespace APP\services\queryBuilders;
|
||||
|
||||
class ContextQueryBuilder extends \PKP\services\queryBuilders\PKPContextQueryBuilder
|
||||
{
|
||||
/** @copydoc \PKP\services\queryBuilders\PKPContextQueryBuilder::$db */
|
||||
protected $db = 'journals';
|
||||
|
||||
/** @copydoc \PKP\services\queryBuilders\PKPContextQueryBuilder::$dbSettings */
|
||||
protected $dbSettings = 'journal_settings';
|
||||
|
||||
/** @copydoc \PKP\services\queryBuilders\PKPContextQueryBuilder::$dbIdColumn */
|
||||
protected $dbIdColumn = 'journal_id';
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
/**
|
||||
* @file classes/services/QueryBuilders/GalleyQueryBuilder.php
|
||||
*
|
||||
* Copyright (c) 2014-2021 Simon Fraser University
|
||||
* Copyright (c) 2000-2021 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class GalleyQueryBuilder
|
||||
*
|
||||
* @ingroup query_builders
|
||||
*
|
||||
* @brief Class for building database queries for galleys
|
||||
*/
|
||||
|
||||
namespace APP\services\queryBuilders;
|
||||
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use PKP\plugins\Hook;
|
||||
use PKP\services\queryBuilders\interfaces\EntityQueryBuilderInterface;
|
||||
|
||||
class GalleyQueryBuilder implements EntityQueryBuilderInterface
|
||||
{
|
||||
/** @var array List of columns (see getQuery) */
|
||||
public $columns;
|
||||
|
||||
/** @var array get authors for one or more publications */
|
||||
protected $publicationIds = [];
|
||||
|
||||
public ?array $contextIds = null;
|
||||
|
||||
/**
|
||||
* Set publicationIds filter
|
||||
*
|
||||
* @param array|int $publicationIds
|
||||
*
|
||||
* @return \APP\services\queryBuilders\GalleyQueryBuilder
|
||||
*/
|
||||
public function filterByPublicationIds($publicationIds)
|
||||
{
|
||||
$this->publicationIds = is_array($publicationIds) ? $publicationIds : [$publicationIds];
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function filterByContexts(array $contextIds): self
|
||||
{
|
||||
$this->contextIds = $contextIds;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc PKP\services\queryBuilders\interfaces\EntityQueryBuilderInterface::getCount()
|
||||
*/
|
||||
public function getCount()
|
||||
{
|
||||
return $this
|
||||
->getQuery()
|
||||
->select('g.galley_id')
|
||||
->get()
|
||||
->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc PKP\services\queryBuilders\interfaces\EntityQueryBuilderInterface::getCount()
|
||||
*/
|
||||
public function getIds()
|
||||
{
|
||||
return $this
|
||||
->getQuery()
|
||||
->select('g.galley_id')
|
||||
->pluck('g.galley_id')
|
||||
->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc PKP\services\queryBuilders\interfaces\EntityQueryBuilderInterface::getCount()
|
||||
*/
|
||||
public function getQuery()
|
||||
{
|
||||
$this->columns = ['*'];
|
||||
$q = DB::table('publication_galleys as g');
|
||||
|
||||
if (!empty($this->publicationIds)) {
|
||||
$q->whereIn('g.publication_id', $this->publicationIds);
|
||||
}
|
||||
|
||||
// Contexts
|
||||
$q->when($this->contextIds !== null, function (Builder $q) {
|
||||
$q->whereIn('g.galley_id', function (Builder $q) {
|
||||
$q->select('g.galley_id')
|
||||
->from('publication_galleys as g')
|
||||
->leftJoin('publications as p', 'p.publication_id', '=', 'g.publication_id')
|
||||
->leftJoin('submissions as s', 's.submission_id', '=', 'p.submission_id')
|
||||
->whereIn('s.context_id', $this->contextIds);
|
||||
});
|
||||
});
|
||||
|
||||
$q->orderBy('g.seq', 'asc');
|
||||
|
||||
// Add app-specific query statements
|
||||
Hook::call('Galley::getMany::queryObject', [&$q, $this]);
|
||||
|
||||
$q->select($this->columns);
|
||||
|
||||
return $q;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file classes/services/QueryBuilders/StatsEditorialQueryBuilder.php
|
||||
*
|
||||
* Copyright (c) 2014-2021 Simon Fraser University
|
||||
* Copyright (c) 2000-2021 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class StatsEditorialQueryBuilder
|
||||
*
|
||||
* @ingroup query_builders
|
||||
*
|
||||
* @brief Editorial statistics list query builder
|
||||
*/
|
||||
|
||||
namespace APP\services\queryBuilders;
|
||||
|
||||
use PKP\services\queryBuilders\PKPStatsEditorialQueryBuilder;
|
||||
|
||||
class StatsEditorialQueryBuilder extends PKPStatsEditorialQueryBuilder
|
||||
{
|
||||
/** @var string The table column name for section IDs */
|
||||
public $sectionIdsColumn = 'section_id';
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file classes/services/queryBuilders/StatsGeoQueryBuilder.php
|
||||
*
|
||||
* Copyright (c) 2022 Simon Fraser University
|
||||
* Copyright (c) 2022 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class StatsGeoQueryBuilder
|
||||
*
|
||||
* @ingroup query_builders
|
||||
*
|
||||
* @brief Helper class to construct a query to fetch geographic stats records from the
|
||||
* metrics_submission_geo_monthly table.
|
||||
*/
|
||||
|
||||
namespace APP\services\queryBuilders;
|
||||
|
||||
use APP\submission\Submission;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use PKP\services\queryBuilders\PKPStatsGeoQueryBuilder;
|
||||
use PKP\statistics\PKPStatisticsHelper;
|
||||
|
||||
class StatsGeoQueryBuilder extends PKPStatsGeoQueryBuilder
|
||||
{
|
||||
/** Include records for these issues */
|
||||
protected array $issueIds = [];
|
||||
|
||||
public function getSectionColumn(): string
|
||||
{
|
||||
return 'section_id';
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the issues to get records for
|
||||
*/
|
||||
public function filterByIssues(array $issueIds): self
|
||||
{
|
||||
$this->issueIds = $issueIds;
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _getAppSpecificQuery(Builder &$q): void
|
||||
{
|
||||
if (!empty($this->issueIds)) {
|
||||
$issueSubmissionIds = DB::table('publications as p')->select('p.submission_id')->distinct()
|
||||
->from('publications as p')
|
||||
->leftJoin('publication_settings as ps', 'ps.setting_name', '=', DB::raw('\'issueId\''))
|
||||
->where('p.status', Submission::STATUS_PUBLISHED)
|
||||
->whereIn('ps.setting_value', $this->issueIds);
|
||||
$q->joinSub($issueSubmissionIds, 'is', function ($join) {
|
||||
$join->on('metrics_submission_geo_monthly.' . PKPStatisticsHelper::STATISTICS_DIMENSION_SUBMISSION_ID, '=', 'is.submission_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file classes/services/queryBuilders/StatsIssueQueryBuilder.php
|
||||
*
|
||||
* Copyright (c) 2022 Simon Fraser University
|
||||
* Copyright (c) 2022 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class StatsIssueQueryBuilder
|
||||
*
|
||||
* @ingroup query_builders
|
||||
*
|
||||
* @brief Helper class to construct a query to fetch issue stats records from the
|
||||
* metrics_issue table.
|
||||
*/
|
||||
|
||||
namespace APP\services\queryBuilders;
|
||||
|
||||
use APP\core\Application;
|
||||
use APP\statistics\StatisticsHelper;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use PKP\plugins\Hook;
|
||||
use PKP\services\queryBuilders\PKPStatsQueryBuilder;
|
||||
|
||||
class StatsIssueQueryBuilder extends PKPStatsQueryBuilder
|
||||
{
|
||||
/** Include records for one of these object types: Application::ASSOC_TYPE_ISSUE, Application::ASSOC_TYPE_ISSUE_GALLEY */
|
||||
protected array $assocTypes = [];
|
||||
|
||||
/** Include records for these issues */
|
||||
protected array $issueIds = [];
|
||||
|
||||
/** Include records for these issues galleys */
|
||||
protected array $issueGalleyIds = [];
|
||||
|
||||
/**
|
||||
* Set the issues to get records for
|
||||
*/
|
||||
public function filterByIssues(array $issueIds): self
|
||||
{
|
||||
$this->issueIds = $issueIds;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the issues to get records for
|
||||
*/
|
||||
public function filterByIssueGalleys(array $issueGalleyIds): self
|
||||
{
|
||||
$this->issueGalleyIds = $issueGalleyIds;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the assocTypes to get records for
|
||||
*/
|
||||
public function filterByAssocTypes(array $assocTypes): self
|
||||
{
|
||||
$this->assocTypes = $assocTypes;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get issue IDs
|
||||
*/
|
||||
public function getIssueIds(): Builder
|
||||
{
|
||||
return $this->_getObject()
|
||||
->select([StatisticsHelper::STATISTICS_DIMENSION_ISSUE_ID])
|
||||
->distinct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc PKPStatsQueryBuilder::getSelectColumns()
|
||||
*/
|
||||
protected function getSelectColumns(array $selectColumns): array
|
||||
{
|
||||
$selectColumns = parent::getSelectColumns($selectColumns);
|
||||
|
||||
// consider PKPStatisticsHelper::STATISTICS_DIMENSION_ASSOC_TYPE because it can be used in reports
|
||||
if (in_array(StatisticsHelper::STATISTICS_DIMENSION_ASSOC_TYPE, $selectColumns)) {
|
||||
foreach ($selectColumns as $i => $selectColumn) {
|
||||
if ($selectColumn == StatisticsHelper::STATISTICS_DIMENSION_ASSOC_TYPE) {
|
||||
$assocTypeIssue = Application::ASSOC_TYPE_ISSUE;
|
||||
$assocTypeIssueGalley = Application::ASSOC_TYPE_ISSUE_GALLEY;
|
||||
$selectColumns[$i] = DB::raw("CASE WHEN issue_galley_id IS NULL THEN '{$assocTypeIssue}' ELSE '{$assocTypeIssueGalley}' END AS assoc_type");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $selectColumns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc PKPStatsQueryBuilder::_getObject()
|
||||
*/
|
||||
protected function _getObject(): Builder
|
||||
{
|
||||
$q = DB::table('metrics_issue');
|
||||
|
||||
if (!empty($this->contextIds)) {
|
||||
$q->whereIn(StatisticsHelper::STATISTICS_DIMENSION_CONTEXT_ID, $this->contextIds);
|
||||
}
|
||||
|
||||
if (!empty($this->issueIds)) {
|
||||
$q->whereIn(StatisticsHelper::STATISTICS_DIMENSION_ISSUE_ID, $this->issueIds);
|
||||
}
|
||||
|
||||
if (!empty($this->issueGalleyIds)) {
|
||||
$q->whereIn(StatisticsHelper::STATISTICS_DIMENSION_ISSUE_GALLEY_ID, $this->issueGalleyIds);
|
||||
}
|
||||
|
||||
if (!empty($this->assocTypes)) {
|
||||
if (in_array(Application::ASSOC_TYPE_ISSUE, $this->assocTypes)) {
|
||||
$q->whereNull(StatisticsHelper::STATISTICS_DIMENSION_ISSUE_GALLEY_ID);
|
||||
} elseif (in_array(Application::ASSOC_TYPE_ISSUE_GALLEY, $this->assocTypes)) {
|
||||
$q->whereNotNull(StatisticsHelper::STATISTICS_DIMENSION_ISSUE_GALLEY_ID);
|
||||
}
|
||||
}
|
||||
|
||||
$q->whereBetween(StatisticsHelper::STATISTICS_DIMENSION_DATE, [$this->dateStart, $this->dateEnd]);
|
||||
|
||||
if ($this->limit > 0) {
|
||||
$q->limit($this->limit);
|
||||
if ($this->offset > 0) {
|
||||
$q->offset($this->offset);
|
||||
}
|
||||
}
|
||||
|
||||
Hook::call('StatsIssue::queryObject', [&$q, $this]);
|
||||
|
||||
return $q;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file classes/services/queryBuilders/StatsPublicationQueryBuilder.php
|
||||
*
|
||||
* Copyright (c) 2022 Simon Fraser University
|
||||
* Copyright (c) 2022 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class StatsPublicationQueryBuilder
|
||||
*
|
||||
* @ingroup query_builders
|
||||
*
|
||||
* @brief Helper class to construct a query to fetch stats records from the
|
||||
* metrics_submission table.
|
||||
*/
|
||||
|
||||
namespace APP\services\queryBuilders;
|
||||
|
||||
use APP\submission\Submission;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use PKP\services\queryBuilders\PKPStatsPublicationQueryBuilder;
|
||||
use PKP\statistics\PKPStatisticsHelper;
|
||||
|
||||
class StatsPublicationQueryBuilder extends PKPStatsPublicationQueryBuilder
|
||||
{
|
||||
/** Include records for these issues */
|
||||
protected array $issueIds = [];
|
||||
|
||||
public function getSectionColumn(): string
|
||||
{
|
||||
return 'section_id';
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the issues to get records for
|
||||
*/
|
||||
public function filterByIssues(array $issueIds): self
|
||||
{
|
||||
$this->issueIds = $issueIds;
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _getAppSpecificQuery(Builder &$q): void
|
||||
{
|
||||
if (!empty($this->issueIds)) {
|
||||
$issueSubmissionIds = DB::table('publications as p')->select('p.submission_id')->distinct()
|
||||
->from('publications as p')
|
||||
->leftJoin('publication_settings as ps', 'ps.setting_name', '=', DB::raw('\'issueId\''))
|
||||
->where('p.status', Submission::STATUS_PUBLISHED)
|
||||
->whereIn('ps.setting_value', $this->issueIds);
|
||||
$q->joinSub($issueSubmissionIds, 'is', function ($join) {
|
||||
$join->on('metrics_submission.' . PKPStatisticsHelper::STATISTICS_DIMENSION_SUBMISSION_ID, '=', 'is.submission_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user