diff --git a/classes/monograph/RepresentativeDAO.php b/classes/monograph/RepresentativeDAO.php index 282d2ee60d8..10b0f9f4238 100644 --- a/classes/monograph/RepresentativeDAO.php +++ b/classes/monograph/RepresentativeDAO.php @@ -18,6 +18,7 @@ namespace APP\monograph; +use Illuminate\Support\Facades\DB; use PKP\db\DAOResultFactory; use PKP\plugins\Hook; diff --git a/classes/press/FeatureDAO.php b/classes/press/FeatureDAO.php index 90dc7013a71..b957d596623 100644 --- a/classes/press/FeatureDAO.php +++ b/classes/press/FeatureDAO.php @@ -3,14 +3,12 @@ /** * @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. @@ -18,21 +16,22 @@ 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 = []; @@ -45,12 +44,11 @@ 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)); } @@ -58,12 +56,9 @@ public function getSequencesByAssoc($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 @@ -71,10 +66,10 @@ public function insertFeature($monographId, $assocType, $assocId, $seq) VALUES (?, ?, ?, ?)', [ - (int) $monographId, - (int) $assocType, - (int) $assocId, - (int) $seq + $monographId, + $assocType, + $assocId, + $seq ] ); } @@ -82,7 +77,7 @@ public function insertFeature($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) @@ -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 { @@ -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 { @@ -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 = []; @@ -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 = []; diff --git a/classes/press/NewReleaseDAO.php b/classes/press/NewReleaseDAO.php index 57be2bacffa..8ceb7f5d3eb 100644 --- a/classes/press/NewReleaseDAO.php +++ b/classes/press/NewReleaseDAO.php @@ -19,6 +19,7 @@ namespace APP\press; use APP\facades\Repo; +use Illuminate\Support\Facades\DB; use PKP\submission\PKPSubmission; class NewReleaseDAO extends \PKP\db\DAO @@ -26,16 +27,15 @@ 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 = []; @@ -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 @@ -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 = []; @@ -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 @@ -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 = []; diff --git a/classes/publicationFormat/IdentificationCodeDAO.php b/classes/publicationFormat/IdentificationCodeDAO.php index e642a020497..27d75b138a3 100644 --- a/classes/publicationFormat/IdentificationCodeDAO.php +++ b/classes/publicationFormat/IdentificationCodeDAO.php @@ -18,6 +18,7 @@ namespace APP\publicationFormat; +use Illuminate\Support\Facades\DB; use PKP\db\DAOResultFactory; use PKP\plugins\Hook; diff --git a/classes/publicationFormat/MarketDAO.php b/classes/publicationFormat/MarketDAO.php index 5f2eb527f2f..ed15baed05f 100644 --- a/classes/publicationFormat/MarketDAO.php +++ b/classes/publicationFormat/MarketDAO.php @@ -18,6 +18,7 @@ namespace APP\publicationFormat; +use Illuminate\Support\Facades\DB; use PKP\db\DAOResultFactory; use PKP\plugins\Hook; diff --git a/classes/publicationFormat/PublicationDateDAO.php b/classes/publicationFormat/PublicationDateDAO.php index 3a0f817ae6b..01eb360c0ef 100644 --- a/classes/publicationFormat/PublicationDateDAO.php +++ b/classes/publicationFormat/PublicationDateDAO.php @@ -18,6 +18,7 @@ namespace APP\publicationFormat; +use Illuminate\Support\Facades\DB; use PKP\db\DAOResultFactory; use PKP\plugins\Hook; diff --git a/classes/publicationFormat/SalesRightsDAO.php b/classes/publicationFormat/SalesRightsDAO.php index f50f67ed8cb..76ce2733ca4 100644 --- a/classes/publicationFormat/SalesRightsDAO.php +++ b/classes/publicationFormat/SalesRightsDAO.php @@ -18,6 +18,7 @@ namespace APP\publicationFormat; +use Illuminate\Support\Facades\DB; use PKP\db\DAOResultFactory; use PKP\plugins\Hook;