Skip to content

Commit

Permalink
Add imports
Browse files Browse the repository at this point in the history
  • Loading branch information
asmecher committed Jul 8, 2024
1 parent 73e429a commit 9d735da
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 80 deletions.
1 change: 1 addition & 0 deletions classes/monograph/RepresentativeDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

namespace APP\monograph;

use Illuminate\Support\Facades\DB;
use PKP\db\DAOResultFactory;
use PKP\plugins\Hook;

Expand Down
98 changes: 46 additions & 52 deletions classes/press/FeatureDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,35 @@
/**
* @file classes/press/FeatureDAO.php
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2003-2021 John Willinsky
* Copyright (c) 2014-2024 Simon Fraser University
* Copyright (c) 2003-2024 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class FeatureDAO
*
* @ingroup press
*
* @see Feature
*
* @brief Operations for setting Featured status on various items.
*/

namespace APP\press;

use Illuminate\Support\Facades\DB;

class FeatureDAO extends \PKP\db\DAO
{
/**
* Get monograph IDs by association.
*
* @param int $assocType Application::ASSOC_TYPE_...
* @param int $assocId
* @param $assocType \APP\core\Application::ASSOC_TYPE_...
*
* @return array Associative array seq => monograph ID
*/
public function getMonographIdsByAssoc($assocType, $assocId)
public function getMonographIdsByAssoc(int $assocType, int $assocId): array
{
$result = $this->retrieve(
'SELECT submission_id, seq FROM features WHERE assoc_type = ? AND assoc_id = ? ORDER BY seq',
[(int) $assocType, (int) $assocId]
[$assocType, $assocId]
);

$returner = [];
Expand All @@ -45,44 +44,40 @@ public function getMonographIdsByAssoc($assocType, $assocId)
/**
* Get feature sequences by association.
*
* @param int $assocType Application::ASSOC_TYPE_...
* @param int $assocId
* @param $assocType \APP\core\Application::ASSOC_TYPE_...
*
* @return array Associative array monograph ID => seq
*/
public function getSequencesByAssoc($assocType, $assocId)
public function getSequencesByAssoc(int $assocType, int $assocId)
{
return array_flip($this->getMonographIdsByAssoc($assocType, $assocId));
}

/**
* Insert a new feature.
*
* @param int $monographId
* @param int $assocType Application::ASSOC_TYPE_...
* @param int $assocId
* @param int $seq
* @param int $assocType \APP\core\Application::ASSOC_TYPE_...
*/
public function insertFeature($monographId, $assocType, $assocId, $seq)
public function insertFeature(int $monographId, int $assocType, int $assocId, int $seq)
{
$this->update(
'INSERT INTO features
(submission_id, assoc_type, assoc_id, seq)
VALUES
(?, ?, ?, ?)',
[
(int) $monographId,
(int) $assocType,
(int) $assocId,
(int) $seq
$monographId,
$assocType,
$assocId,
$seq
]
);
}

/**
* Delete a feature by ID.
*/
public function deleteByMonographId(int $monographId)
public function deleteByMonographId(int $monographId): int
{
return DB::table('features')
->where('submission_id', '=', $monographId)
Expand All @@ -92,7 +87,7 @@ public function deleteByMonographId(int $monographId)
/**
* Delete a feature by association.
*
* @param $assocType Application::ASSOC_TYPE_...
* @param $assocType \APP\core\Application::ASSOC_TYPE_...
*/
public function deleteByAssoc(int $assocType, int $assocId): int
{
Expand All @@ -105,7 +100,7 @@ public function deleteByAssoc(int $assocType, int $assocId): int
/**
* Delete a feature.
*
* @param int $assocType Application::ASSOC_TYPE_...
* @param int $assocType \APP\core\Application::ASSOC_TYPE_...
*/
public function deleteFeature(int $monographId, int $assocType, int $assocId): int
{
Expand All @@ -120,35 +115,33 @@ public function deleteFeature(int $monographId, int $assocType, int $assocId): i
* Check if the passed monograph id is featured on the
* passed associated object.
*
* @param int $monographId The monograph id to check the feature state.
* @param int $assocType The associated object type that the monograph
* @param $monographId The monograph id to check the feature state.
* @param $assocType The associated object type that the monograph
* is featured.
* @param int $assocId The associated object id that the monograph is
* @param $assocId The associated object id that the monograph is
* featured.
*
* @return bool Whether or not the monograph is featured.
*/
public function isFeatured($monographId, $assocType, $assocId)
public function isFeatured(int $monographId, int $assocType, int $assocId): bool
{
$result = $this->retrieve(
'SELECT submission_id FROM features WHERE submission_id = ? AND assoc_type = ? AND assoc_id = ?',
[(int) $monographId, (int) $assocType, (int) $assocId]
);
return (bool) $result->current();
return DB::table('features')
->where('submission_id', '=', $monographId)
->where('assoc_type', '=', $assocType)
->where('assoc_id', '=', $assicId)
->count() > 0;
}

/**
* Return the monograph's featured settings in all assoc types
*
* @param int $monographId The monograph id to get the feature state.
*
* @return array
* @param $monographId The monograph id to get the feature state.
*/
public function getFeaturedAll($monographId)
public function getFeaturedAll(int $monographId): array
{
$result = $this->retrieve(
'SELECT assoc_type, assoc_id, seq FROM features WHERE submission_id = ?',
[(int) $monographId]
[$monographId]
);

$featured = [];
Expand All @@ -165,44 +158,45 @@ public function getFeaturedAll($monographId)
/**
* Get the current sequence position of the passed monograph id.
*
* @param int $monographId The monograph id to check the sequence position.
* @param int $assocType The monograph associated object type.
* @param int $assocId The monograph associated object id.
* @param $monographId The monograph id to check the sequence position.
* @param $assocType The monograph associated object type.
* @param $assocId The monograph associated object id.
*
* @return int or boolean The monograph sequence position or false if no
* @return int|boolean The monograph sequence position or false if no
* monograph feature is set.
*/
public function getSequencePosition($monographId, $assocType, $assocId)
public function getSequencePosition(int $monographId, int $assocType, int $assocId): int|boolean
{
$result = $this->retrieve(
'SELECT seq FROM features WHERE submission_id = ? AND assoc_type = ? AND assoc_id = ?',
[(int) $monographId, (int) $assocType, (int) $assocId]
[$monographId, $assocType, $assocId]
);
$row = $result->current();
return $row ? $row->seq : false;
}

public function setSequencePosition($monographId, $assocType, $assocId, $sequencePosition)
public function setSequencePosition(int $monographId, int $assocType, int $assocId, int $sequencePosition): void
{
$this->update(
'UPDATE features SET seq = ? WHERE submission_id = ? AND assoc_type = ? AND assoc_id = ?',
[(int) $sequencePosition, (int) $monographId, (int) $assocType, (int) $assocId]
);
DB::table('features')
->where('submission_id', '=', $monographId)
->where('assoc_type', '=', $assocType)
->where('assoc_id', '=', $assocId)
->update(['seq' => $seq]);
}

/**
* Resequence features by association.
*
* @param int $assocType Application::ASSOC_TYPE_...
* @param int $assocId per $assocType
* @param $assocType \APP\core\Application::ASSOC_TYPE_...
* @param $assocId Identifier per $assocType
*
* @return array Associative array of id => seq for resequenced set
*/
public function resequenceByAssoc($assocType, $assocId)
public function resequenceByAssoc(int $assocType, int $assocId): array
{
$result = $this->retrieve(
'SELECT submission_id FROM features WHERE assoc_type = ? AND assoc_id = ? ORDER BY seq',
[(int) $assocType, (int) $assocId]
[$assocType, $assocId]
);

$returner = [];
Expand Down
51 changes: 23 additions & 28 deletions classes/press/NewReleaseDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@
namespace APP\press;

use APP\facades\Repo;
use Illuminate\Support\Facades\DB;
use PKP\submission\PKPSubmission;

class NewReleaseDAO extends \PKP\db\DAO
{
/**
* Get monograph IDs by association.
*
* @param int $assocType Application::ASSOC_TYPE_...
* @param int $assocId
* @param $assocType \APP\core\Application::ASSOC_TYPE_...
*
* @return array [monographId => true]
*/
public function getMonographIdsByAssoc($assocType, $assocId)
public function getMonographIdsByAssoc(int $assocType, int $assocId): array
{
$result = $this->retrieve(
'SELECT submission_id FROM new_releases WHERE assoc_type = ? AND assoc_id = ?',
[(int) $assocType, (int) $assocId]
[$assocType, $assocId]
);

$returner = [];
Expand All @@ -48,12 +48,11 @@ public function getMonographIdsByAssoc($assocType, $assocId)
/**
* Get monographs by association.
*
* @param int $assocType Application::ASSOC_TYPE_...
* @param int $assocId
* @param $assocType \APP\core\Application::ASSOC_TYPE_...
*
* @return array Monograph
* @return Submission[]
*/
public function getMonographsByAssoc($assocType, $assocId)
public function getMonographsByAssoc(int $assocType, int $assocId): array
{
$result = $this->retrieve(
'SELECT n.submission_id AS submission_id
Expand All @@ -65,7 +64,7 @@ public function getMonographsByAssoc($assocType, $assocId)
AND n.assoc_type = ? AND n.assoc_id = ?
AND s.status = ?
ORDER BY p.date_published DESC',
[(int) $assocType, (int) $assocId, PKPSubmission::STATUS_PUBLISHED]
[$assocType, $assocId, PKPSubmission::STATUS_PUBLISHED]
);

$returner = [];
Expand All @@ -76,13 +75,11 @@ public function getMonographsByAssoc($assocType, $assocId)
}

/**
* Insert a new NewRelease.
* Insert a new new release.
*
* @param int $monographId
* @param int $assocType Application::ASSOC_TYPE_...
* @param int $assocId
* @param int $assocType \APP\core\Application::ASSOC_TYPE_...
*/
public function insertNewRelease($monographId, $assocType, $assocId)
public function insertNewRelease(int $monographId, int $assocType, int $assocId): void
{
$this->update(
'INSERT INTO new_releases
Expand Down Expand Up @@ -138,35 +135,33 @@ public function deleteNewRelease(int $monographId, int $assocType, int $assocId)
* Check if the passed monograph id is marked as new release
* on the passed associated object.
*
* @param int $monographId The monograph id to check the new release state.
* @param int $assocType The associated object type that the monograph
* @param $monographId The monograph id to check the new release state.
* @param $assocType The associated object type that the monograph
* is checked for a new release mark.
* @param int $assocId The associated object id that the monograph is
* @param $assocId The associated object id that the monograph is
* checked for a new release mark.
*
* @return bool Whether or not the monograph is marked as a new release.
*/
public function isNewRelease($monographId, $assocType, $assocId)
public function isNewRelease(int $monographId, int $assocType, int $assocId): bool
{
$result = $this->retrieve(
'SELECT submission_id FROM new_releases WHERE submission_id = ? AND assoc_type = ? AND assoc_id = ?',
[(int) $monographId, (int) $assocType, (int) $assocId]
);
return (bool) $result->current();
return DB::table('new_releases')
->where('submission_id', '=', $submissionId)
->where('assoc_type', '=', $assocType)
->where('assoc_id', '=', $assocId)
->count() > 0;
}

/**
* Return the monograph's new release settings in all assoc types
*
* @param int $monographId The monograph ID to get the new release state
*
* @return array
* @param $monographId The monograph ID to get the new release state
*/
public function getNewReleaseAll($monographId)
public function getNewReleaseAll(int $monographId): array
{
$result = $this->retrieve(
'SELECT assoc_type, assoc_id FROM new_releases WHERE submission_id = ?',
[(int) $monographId]
[$monographId]
);

$newRelease = [];
Expand Down
1 change: 1 addition & 0 deletions classes/publicationFormat/IdentificationCodeDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

namespace APP\publicationFormat;

use Illuminate\Support\Facades\DB;
use PKP\db\DAOResultFactory;
use PKP\plugins\Hook;

Expand Down
1 change: 1 addition & 0 deletions classes/publicationFormat/MarketDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

namespace APP\publicationFormat;

use Illuminate\Support\Facades\DB;
use PKP\db\DAOResultFactory;
use PKP\plugins\Hook;

Expand Down
1 change: 1 addition & 0 deletions classes/publicationFormat/PublicationDateDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

namespace APP\publicationFormat;

use Illuminate\Support\Facades\DB;
use PKP\db\DAOResultFactory;
use PKP\plugins\Hook;

Expand Down
1 change: 1 addition & 0 deletions classes/publicationFormat/SalesRightsDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

namespace APP\publicationFormat;

use Illuminate\Support\Facades\DB;
use PKP\db\DAOResultFactory;
use PKP\plugins\Hook;

Expand Down

0 comments on commit 9d735da

Please sign in to comment.