From b3a87236519f229180d52561ceea9745e20b717f Mon Sep 17 00:00:00 2001 From: Nate Wright Date: Thu, 24 Oct 2019 11:29:04 +0100 Subject: [PATCH] pkp/pkp-lib#5122 Change naming pattern for methods returning iterators --- .../PKPBackendSubmissionsHandler.inc.php | 6 +++--- api/v1/contexts/PKPContextHandler.inc.php | 6 +++--- .../PKPEmailTemplateHandler.inc.php | 4 ++-- .../PKPStatsPublicationHandler.inc.php | 4 ++-- api/v1/submissions/PKPSubmissionHandler.inc.php | 16 ++++++++-------- api/v1/users/PKPUserHandler.inc.php | 6 +++--- .../listPanels/PKPSubmissionsListPanel.inc.php | 4 ++-- classes/publication/PKPPublicationDAO.inc.php | 6 +++--- classes/services/PKPSubmissionService.inc.php | 6 +++--- classes/submission/PKPSubmissionDAO.inc.php | 4 ++-- classes/task/PublishSubmissions.inc.php | 8 ++++---- controllers/grid/queries/form/QueryForm.inc.php | 6 +++--- .../sections/form/PKPSectionForm.inc.php | 8 ++++---- .../users/reviewer/form/ReviewerForm.inc.php | 4 ++-- .../form/PKPStageParticipantNotifyForm.inc.php | 4 ++-- .../statistics/ReportGeneratorHandler.inc.php | 5 ++--- pages/catalog/PKPCatalogHandler.inc.php | 6 +++--- 17 files changed, 51 insertions(+), 52 deletions(-) diff --git a/api/v1/_submissions/PKPBackendSubmissionsHandler.inc.php b/api/v1/_submissions/PKPBackendSubmissionsHandler.inc.php index 8ab39fe55f2..c8fda121219 100644 --- a/api/v1/_submissions/PKPBackendSubmissionsHandler.inc.php +++ b/api/v1/_submissions/PKPBackendSubmissionsHandler.inc.php @@ -148,14 +148,14 @@ public function getMany($slimRequest, $response, $args) { } $submissionService = Services::get('submission'); - $result = $submissionService->getMany($params); + $submissionsIterator = $submissionService->getMany($params); $items = array(); - if (count($result)) { + if (count($submissionsIterator)) { $propertyArgs = array( 'request' => $request, 'slimRequest' => $slimRequest, ); - foreach ($result as $submission) { + foreach ($submissionsIterator as $submission) { $items[] = $submissionService->getBackendListProperties($submission, $propertyArgs); } } diff --git a/api/v1/contexts/PKPContextHandler.inc.php b/api/v1/contexts/PKPContextHandler.inc.php index d3afbd47207..9eca69deb3d 100644 --- a/api/v1/contexts/PKPContextHandler.inc.php +++ b/api/v1/contexts/PKPContextHandler.inc.php @@ -143,13 +143,13 @@ public function getMany($slimRequest, $response, $args) { } $items = array(); - $result = $contextService->getMany($allowedParams); - if (count($result)) { + $contextsIterator = $contextService->getMany($allowedParams); + if (count($contextsIterator)) { $propertyArgs = array( 'request' => $request, 'slimRequest' => $slimRequest, ); - foreach ($result as $context) { + foreach ($contextsIterator as $context) { $items[] = $contextService->getSummaryProperties($context, $propertyArgs); } } diff --git a/api/v1/emailTemplates/PKPEmailTemplateHandler.inc.php b/api/v1/emailTemplates/PKPEmailTemplateHandler.inc.php index 0fdc3dc9ef5..64390a90fde 100644 --- a/api/v1/emailTemplates/PKPEmailTemplateHandler.inc.php +++ b/api/v1/emailTemplates/PKPEmailTemplateHandler.inc.php @@ -143,8 +143,8 @@ public function getMany($slimRequest, $response, $args) { $allowedParams['contextId'] = $request->getContext()->getId(); $items = array(); - $result = $emailTemplateService->getMany($allowedParams); - foreach ($result as $emailTemplate) { + $emailTemplatesIterator = $emailTemplateService->getMany($allowedParams); + foreach ($emailTemplatesIterator as $emailTemplate) { $items[] = $emailTemplateService->getSummaryProperties($emailTemplate, [ 'slimRequest' => $slimRequest, 'request' => $request, diff --git a/api/v1/stats/publications/PKPStatsPublicationHandler.inc.php b/api/v1/stats/publications/PKPStatsPublicationHandler.inc.php index 0734a5bc29b..d997defcdc0 100644 --- a/api/v1/stats/publications/PKPStatsPublicationHandler.inc.php +++ b/api/v1/stats/publications/PKPStatsPublicationHandler.inc.php @@ -662,14 +662,14 @@ protected function _validateDates($params) { * @return array submission ids */ protected function _processSearchPhrase($searchPhrase, $submissionIds = []) { - $result = \Services::get('submission')->getMany([ + $submissionsIterator = \Services::get('submission')->getMany([ 'contextId' => \Application::get()->getRequest()->getContext()->getId(), 'searchPhrase' => $searchPhrase, 'status' => STATUS_PUBLISHED, ]); $searchPhraseSubmissionIds = []; - foreach ($result as $submission) { + foreach ($submissionsIterator as $submission) { $searchPhraseSubmissionIds[] = $submission->getId(); } diff --git a/api/v1/submissions/PKPSubmissionHandler.inc.php b/api/v1/submissions/PKPSubmissionHandler.inc.php index c05dc5d1c77..0c5d19ff8c1 100644 --- a/api/v1/submissions/PKPSubmissionHandler.inc.php +++ b/api/v1/submissions/PKPSubmissionHandler.inc.php @@ -199,14 +199,14 @@ public function getMany($slimRequest, $response, $args) { } $items = array(); - $result = $submissionService->getMany($params); - if (count($result)) { + $submissionsIterator = $submissionService->getMany($params); + if (count($submissionsIterator)) { $propertyArgs = array( 'request' => $request, 'slimRequest' => $slimRequest, 'userGroups' => DAORegistry::getDAO('UserGroupDAO')->getByContextId($context->getId())->toArray() ); - foreach ($result as $submission) { + foreach ($submissionsIterator as $submission) { $items[] = $submissionService->getSummaryProperties($submission, $propertyArgs); } } @@ -466,18 +466,18 @@ public function getParticipants($slimRequest, $response, $args) { $userService = Services::get('user'); - $result = $userService->getMany(array( + $usersIterator = $userService->getMany(array( 'contextId' => $context->getId(), 'count' => 100, // high upper-limit 'assignedToSubmission' => $submission->getId(), 'assignedToSubmissionStage' => $stageId, )); - if (count($result)) { + if (count($usersIterator)) { $args = array( 'request' => $request, 'slimRequest' => $slimRequest, ); - foreach ($result as $user) { + foreach ($usersIterator as $user) { $data[] = $userService->getSummaryProperties($user, $args); } } @@ -503,8 +503,8 @@ public function getPublications($slimRequest, $response, $args) { $userGroups = DAORegistry::getDAO('UserGroupDAO')->getByContextId($submission->getData('contextId'))->toArray(); $items = []; - $result = Services::get('publication')->getMany($allowedParams); - foreach ($result as $publication) { + $publicationsIterator = Services::get('publication')->getMany($allowedParams); + foreach ($publicationsIterator as $publication) { $items[] = Services::get('publication')->getSummaryProperties( $publication, [ diff --git a/api/v1/users/PKPUserHandler.inc.php b/api/v1/users/PKPUserHandler.inc.php index 7f57a5de160..ba0a29686ea 100644 --- a/api/v1/users/PKPUserHandler.inc.php +++ b/api/v1/users/PKPUserHandler.inc.php @@ -76,13 +76,13 @@ public function getMany($slimRequest, $response, $args) { $params = $this->_buildListRequestParams($slimRequest); $items = array(); - $result = $userService->getMany($params); - if (count($result)) { + $usersItereator = $userService->getMany($params); + if (count($usersItereator)) { $propertyArgs = array( 'request' => $request, 'slimRequest' => $slimRequest, ); - foreach ($result as $user) { + foreach ($usersItereator as $user) { $items[] = $userService->getSummaryProperties($user, $propertyArgs); } } diff --git a/classes/components/listPanels/PKPSubmissionsListPanel.inc.php b/classes/components/listPanels/PKPSubmissionsListPanel.inc.php index 3b31e30e003..c836b5062f9 100644 --- a/classes/components/listPanels/PKPSubmissionsListPanel.inc.php +++ b/classes/components/listPanels/PKPSubmissionsListPanel.inc.php @@ -177,9 +177,9 @@ public function getConfig() { */ public function getItems($request) { $submissionService = \Services::get('submission'); - $result = $submissionService->getMany($this->_getItemsParams()); + $submissionsIterator = $submissionService->getMany($this->_getItemsParams()); $items = []; - foreach ($result as $submission) { + foreach ($submissionsIterator as $submission) { $items[] = $submissionService->getBackendListProperties($submission, ['request' => $request]); } diff --git a/classes/publication/PKPPublicationDAO.inc.php b/classes/publication/PKPPublicationDAO.inc.php index f78ffd7d7e8..7110837bff8 100644 --- a/classes/publication/PKPPublicationDAO.inc.php +++ b/classes/publication/PKPPublicationDAO.inc.php @@ -185,9 +185,9 @@ public function deleteById($publicationId) { parent::deleteById($publicationId); // Delete authors - $result = Services::get('author')->getMany(['publicationIds' => $publicationId]); - foreach ($result as $contributor) { - Services::get('author')->delete($contributor); + $authorsIterator = Services::get('author')->getMany(['publicationIds' => $publicationId]); + foreach ($authorsIterator as $author) { + Services::get('author')->delete($author); } // Delete the controlled vocabulary diff --git a/classes/services/PKPSubmissionService.inc.php b/classes/services/PKPSubmissionService.inc.php index ecfe8d7eece..225c714f77d 100644 --- a/classes/services/PKPSubmissionService.inc.php +++ b/classes/services/PKPSubmissionService.inc.php @@ -729,9 +729,9 @@ public function delete($submission) { Application::get()->getSubmissionDAO()->deleteObject($submission); - $result = Services::get('author')->getMany(['publicationIds' => $submission->getId()]); - foreach ($result as $contributor) { - Services::get('author')->delete($contributor); + $authorsIterator = Services::get('author')->getMany(['publicationIds' => $submission->getId()]); + foreach ($authorsIterator as $author) { + Services::get('author')->delete($author); } \HookRegistry::call('Submission::delete', [$submission]); diff --git a/classes/submission/PKPSubmissionDAO.inc.php b/classes/submission/PKPSubmissionDAO.inc.php index bd8a337fa9d..ef6bd01c1c6 100644 --- a/classes/submission/PKPSubmissionDAO.inc.php +++ b/classes/submission/PKPSubmissionDAO.inc.php @@ -121,8 +121,8 @@ function deleteById($submissionId) { parent::deleteById($submissionId); // Delete publications - $result = Services::get('publication')->getMany(['submissionIds' => $submissionId]); - foreach ($result as $publication) { + $publicationsIterator = Services::get('publication')->getMany(['submissionIds' => $submissionId]); + foreach ($publicationsIterator as $publication) { DAORegistry::getDAO('PublicationDAO')->deleteObject($publication); } diff --git a/classes/task/PublishSubmissions.inc.php b/classes/task/PublishSubmissions.inc.php index e3e538ceb4d..dc51bc46c19 100644 --- a/classes/task/PublishSubmissions.inc.php +++ b/classes/task/PublishSubmissions.inc.php @@ -30,15 +30,15 @@ public function getName() { public function executeActions() { import('classes.submission.Submission'); // import constants - $contextResult = Services::get('context')->getMany([ + $contextsIterator = Services::get('context')->getMany([ 'isEnabled' => true, ]); - foreach ($contextResult as $context) { - $submissionResult = Services::get('submission')->getMany([ + foreach ($contextsIterator as $context) { + $submissionsIterator = Services::get('submission')->getMany([ 'contextId' => $context->getID(), 'status' => STATUS_SCHEDULED, ]); - foreach ($submissionResult as $submission) { + foreach ($submissionsIterator as $submission) { $datePublished = $submission->getCurrentPublication()->getData('datePublished'); if ($datePublished && strtotime($datePublished) <= strtotime(Core::getCurrentDate())) { Services::get('publication')->publish($submission->getCurrentPublication()); diff --git a/controllers/grid/queries/form/QueryForm.inc.php b/controllers/grid/queries/form/QueryForm.inc.php index babc84d5b9b..7afd937cda8 100644 --- a/controllers/grid/queries/form/QueryForm.inc.php +++ b/controllers/grid/queries/form/QueryForm.inc.php @@ -272,12 +272,12 @@ function fetch($request, $template = null, $display = false, $actionArgs = array ]; $userService = Services::get('user'); - $result = $userService->getMany($params); + $usersIterator = $userService->getMany($params); $items = []; $itemsMax = 0; - if (count($result)) { - foreach ($result as $user) { + if (count($usersIterator)) { + foreach ($usersIterator as $user) { $allUserGroups = DAORegistry::getDAO('UserGroupDAO')->getByUserId($user->getId(), $context->getId())->toArray(); $userRoles = array(); diff --git a/controllers/grid/settings/sections/form/PKPSectionForm.inc.php b/controllers/grid/settings/sections/form/PKPSectionForm.inc.php index 6091ddaa148..3ebefcf0e6d 100644 --- a/controllers/grid/settings/sections/form/PKPSectionForm.inc.php +++ b/controllers/grid/settings/sections/form/PKPSectionForm.inc.php @@ -81,7 +81,7 @@ function setSectionId($sectionId) { */ public function _getAssignedSubEditorIds($sectionId, $contextId) { import('classes.core.Services'); - $subEditors = Services::get('user')->getMany(array( + $subEditorsIterator = Services::get('user')->getMany(array( 'contextId' => $contextId, 'roleIds' => ROLE_ID_SUB_EDITOR, 'assignedToSection' => $sectionId, @@ -89,7 +89,7 @@ public function _getAssignedSubEditorIds($sectionId, $contextId) { return array_map(function($subEditor) { return (int) $subEditor->getId(); - }, iterator_to_array($subEditors)); + }, iterator_to_array($subEditorsIterator)); } /** @@ -108,9 +108,9 @@ public function _getSubEditorsListPanel($contextId, $request) { import('classes.core.Services'); $userService = Services::get('user'); - $result = $userService->getMany($params); + $usersIterator = $userService->getMany($params); $items = []; - foreach ($result as $user) { + foreach ($usersIterator as $user) { $items[] = [ 'id' => (int) $user->getId(), 'title' => $user->getFullName() diff --git a/controllers/grid/users/reviewer/form/ReviewerForm.inc.php b/controllers/grid/users/reviewer/form/ReviewerForm.inc.php index 2a7cb71abe0..9970201487f 100644 --- a/controllers/grid/users/reviewer/form/ReviewerForm.inc.php +++ b/controllers/grid/users/reviewer/form/ReviewerForm.inc.php @@ -257,12 +257,12 @@ function fetch($request, $template = null, $display = false) { $userRoles = $roleDao->getByUserId($user->getId(), $submission->getContextId()); foreach ($userRoles as $userRole) { if (in_array($userRole->getId(), array(ROLE_ID_MANAGER, ROLE_ID_SUB_EDITOR, ROLE_ID_ASSISTANT))) { - $result = Services::get('emailTemplate')->getMany([ + $emailTemplatesIterator = Services::get('emailTemplate')->getMany([ 'contextId' => $submission->getContextId(), 'isCustom' => true, ]); $customTemplateKeys = []; - foreach ($result as $emailTemplate) { + foreach ($emailTemplatesIterator as $emailTemplate) { $customTemplateKeys[] = $emailTemplate->getData('key'); }; $templateKeys = array_merge($templateKeys, $customTemplateKeys); diff --git a/controllers/grid/users/stageParticipant/form/PKPStageParticipantNotifyForm.inc.php b/controllers/grid/users/stageParticipant/form/PKPStageParticipantNotifyForm.inc.php index a37659c8576..dfc1c8d1a5d 100644 --- a/controllers/grid/users/stageParticipant/form/PKPStageParticipantNotifyForm.inc.php +++ b/controllers/grid/users/stageParticipant/form/PKPStageParticipantNotifyForm.inc.php @@ -73,12 +73,12 @@ function fetch($request, $template = null, $display = false) { $userRoles = $roleDao->getByUserId($user->getId(), $submission->getContextId()); foreach ($userRoles as $userRole) { if (in_array($userRole->getId(), array(ROLE_ID_MANAGER, ROLE_ID_SUB_EDITOR, ROLE_ID_ASSISTANT))) { - $result = Services::get('emailTemplate')->getMany([ + $emailTemplatesIterator = Services::get('emailTemplate')->getMany([ 'contextId' => $submission->getContextId(), 'isCustom' => true, ]); $customTemplateKeys = []; - foreach ($result as $emailTemplate) { + foreach ($emailTemplatesIterator as $emailTemplate) { $customTemplateKeys[] = $emailTemplate->getData('key'); } $templateKeys = array_merge($templateKeys, $customTemplateKeys); diff --git a/controllers/statistics/ReportGeneratorHandler.inc.php b/controllers/statistics/ReportGeneratorHandler.inc.php index ed97a2c3417..64d983abb2c 100644 --- a/controllers/statistics/ReportGeneratorHandler.inc.php +++ b/controllers/statistics/ReportGeneratorHandler.inc.php @@ -98,13 +98,12 @@ function fetchArticlesInfo($args, $request) { if (!$issueId) { return new JSONMessage(false); } else { - $result = Services::get('submission')->getMany([ + $submissionsIterator = Services::get('submission')->getMany([ 'contextId' => $request->getContext()->getId(), 'issueIds' => $issueId, - 'count' => 5000, // large upper limit ]); $articlesInfo = array(); - foreach ($result as $submission) { + foreach ($submissionsIterator as $submission) { $articlesInfo[] = array('id' => $submission->getId(), 'title' => $submission->getLocalizedTitle()); } diff --git a/pages/catalog/PKPCatalogHandler.inc.php b/pages/catalog/PKPCatalogHandler.inc.php index 340cc72286a..039286ed5ba 100644 --- a/pages/catalog/PKPCatalogHandler.inc.php +++ b/pages/catalog/PKPCatalogHandler.inc.php @@ -72,20 +72,20 @@ function category($args, $request) { 'offset' => $offset, 'status' => STATUS_PUBLISHED, ); - $submissionsResult = $submissionService->getMany($params); + $submissionsIterator = $submissionService->getMany($params); $total = $submissionService->getMax($params); // Provide the parent category and a list of subcategories $parentCategory = $categoryDao->getById($category->getParentId()); $subcategories = $categoryDao->getByParentId($category->getId()); - $this->_setupPaginationTemplate($request, count($submissionsResult), $page, $count, $offset, $total); + $this->_setupPaginationTemplate($request, count($submissionsIterator), $page, $count, $offset, $total); $templateMgr->assign(array( 'category' => $category, 'parentCategory' => $parentCategory, 'subcategories' => $subcategories, - 'publishedSubmissions' => iterator_to_array($submissionsResult), + 'publishedSubmissions' => iterator_to_array($submissionsIterator), )); return $templateMgr->display('frontend/pages/catalogCategory.tpl');