Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkp/pkp-lib#5122 Change naming pattern for methods returning iterators #5221

Merged
merged 1 commit into from
Oct 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions api/v1/_submissions/PKPBackendSubmissionsHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
6 changes: 3 additions & 3 deletions api/v1/contexts/PKPContextHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions api/v1/emailTemplates/PKPEmailTemplateHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions api/v1/stats/publications/PKPStatsPublicationHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
16 changes: 8 additions & 8 deletions api/v1/submissions/PKPSubmissionHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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,
[
Expand Down
6 changes: 3 additions & 3 deletions api/v1/users/PKPUserHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions classes/components/listPanels/PKPSubmissionsListPanel.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}

Expand Down
6 changes: 3 additions & 3 deletions classes/publication/PKPPublicationDAO.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions classes/services/PKPSubmissionService.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
4 changes: 2 additions & 2 deletions classes/submission/PKPSubmissionDAO.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
8 changes: 4 additions & 4 deletions classes/task/PublishSubmissions.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
6 changes: 3 additions & 3 deletions controllers/grid/queries/form/QueryForm.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ 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,
));

return array_map(function($subEditor) {
return (int) $subEditor->getId();
}, iterator_to_array($subEditors));
}, iterator_to_array($subEditorsIterator));
}

/**
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions controllers/grid/users/reviewer/form/ReviewerForm.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions controllers/statistics/ReportGeneratorHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
6 changes: 3 additions & 3 deletions pages/catalog/PKPCatalogHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down