diff --git a/classes/article/ArticleGalleyDAO.inc.php b/classes/article/ArticleGalleyDAO.inc.php index 706dbb2f9d7..bf03dee6e51 100644 --- a/classes/article/ArticleGalleyDAO.inc.php +++ b/classes/article/ArticleGalleyDAO.inc.php @@ -310,20 +310,19 @@ function getExportable($contextId, $pubIdType = null, $title = null, $author = n $params[] = $pubIdSettingValue; } - $result = $this->retrieveRange( - $sql = 'SELECT g.* - FROM publication_galleys g - LEFT JOIN publications p ON (p.publication_id = g.publication_id) - LEFT JOIN publication_settings ps ON (ps.publication_id = p.publication_id) - LEFT JOIN submissions s ON (s.submission_id = p.submission_id) - LEFT JOIN submission_files sf ON (g.submission_file_id = sf.submission_file_id) - ' . ($pubIdType != null?' LEFT JOIN publication_galley_settings gs ON (g.galley_id = gs.galley_id)':'') - . ($title != null?' LEFT JOIN publication_settings pst ON (p.publication_id = pst.publication_id)':'') - . ($author != null?' LEFT JOIN authors au ON (p.publication_id = au.publication_id) - LEFT JOIN author_settings asgs ON (asgs.author_id = au.author_id AND asgs.setting_name = \''.IDENTITY_SETTING_GIVENNAME.'\') - LEFT JOIN author_settings asfs ON (asfs.author_id = au.author_id AND asfs.setting_name = \''.IDENTITY_SETTING_FAMILYNAME.'\') - ':'') - . ($pubIdSettingName != null?' LEFT JOIN publication_galley_settings gss ON (g.galley_id = gss.galley_id AND gss.setting_name = ?)':'') .' + $baseSql = ' + FROM publication_galleys g + LEFT JOIN publications p ON (p.publication_id = g.publication_id) + LEFT JOIN publication_settings ps ON (ps.publication_id = p.publication_id) + LEFT JOIN submissions s ON (s.submission_id = p.submission_id) + LEFT JOIN submission_files sf ON (g.submission_file_id = sf.submission_file_id) + ' . ($pubIdType != null?' LEFT JOIN publication_galley_settings gs ON (g.galley_id = gs.galley_id)':'') + . ($title != null?' LEFT JOIN publication_settings pst ON (p.publication_id = pst.publication_id)':'') + . ($author != null?' LEFT JOIN authors au ON (p.publication_id = au.publication_id) + LEFT JOIN author_settings asgs ON (asgs.author_id = au.author_id AND asgs.setting_name = \''.IDENTITY_SETTING_GIVENNAME.'\') + LEFT JOIN author_settings asfs ON (asfs.author_id = au.author_id AND asfs.setting_name = \''.IDENTITY_SETTING_FAMILYNAME.'\') + ':'') + . ($pubIdSettingName != null?' LEFT JOIN publication_galley_settings gss ON (g.galley_id = gss.galley_id AND gss.setting_name = ?)':'') .' WHERE s.status = ? AND s.context_id = ? ' . ($pubIdType != null?' AND gs.setting_name = ? AND gs.setting_value IS NOT NULL':'') @@ -333,12 +332,15 @@ function getExportable($contextId, $pubIdType = null, $title = null, $author = n . (($pubIdSettingName != null && $pubIdSettingValue != null && $pubIdSettingValue == EXPORT_STATUS_NOT_DEPOSITED)?' AND gss.setting_value IS NULL':'') . (($pubIdSettingName != null && $pubIdSettingValue != null && $pubIdSettingValue != EXPORT_STATUS_NOT_DEPOSITED)?' AND gss.setting_value = ?':'') . (($pubIdSettingName != null && is_null($pubIdSettingValue))?' AND (gss.setting_value IS NULL OR gss.setting_value = \'\')':'') .' - GROUP BY g.galley_id - ORDER BY p.date_published DESC, p.publication_id DESC, g.galley_id DESC', + GROUP BY g.galley_id + '; + + $result = $this->retrieveRange( + "SELECT g.* {$baseSql} ORDER BY p.date_published DESC, p.publication_id DESC, g.galley_id DESC", $params, $rangeInfo ); - return new DAOResultFactory($result, $this, '_fromRow', [], $sql, $params, $rangeInfo); + return new DAOResultFactory($result, $this, '_fromRow', [], "SELECT 0 {$baseSql}", $params, $rangeInfo); } } diff --git a/classes/article/AuthorDAO.inc.php b/classes/article/AuthorDAO.inc.php index 235c7fecae0..724967a5315 100644 --- a/classes/article/AuthorDAO.inc.php +++ b/classes/article/AuthorDAO.inc.php @@ -90,46 +90,52 @@ function getAuthorsAlphabetizedByJournal($journalId = null, $initial = null, $ra $initialSql .= ')'; } + $baseSql = ' + FROM authors a + JOIN user_groups ug ON (a.user_group_id = ug.user_group_id) + JOIN publications p ON (p.publication_id = a.publication_id) + JOIN submissions s ON (s.current_publication_id = p.publication_id) + LEFT JOIN author_settings agl ON (a.author_id = agl.author_id AND agl.setting_name = ? AND agl.locale = ?) + LEFT JOIN author_settings agpl ON (a.author_id = agpl.author_id AND agpl.setting_name = ? AND agpl.locale = s.locale) + LEFT JOIN author_settings afl ON (a.author_id = afl.author_id AND afl.setting_name = ? AND afl.locale = ?) + LEFT JOIN author_settings afpl ON (a.author_id = afpl.author_id AND afpl.setting_name = ? AND afpl.locale = s.locale) + JOIN ( + SELECT + MIN(aa.author_id) as author_id, + CONCAT( + ' . ($includeEmail ? 'aa.email, \' \', ' : '') . ' + ac.setting_value, + \' \' + ' . $sqlColumnsAuthorSettings . ' + ) as names + FROM authors aa + JOIN publications pp ON (pp.publication_id = aa.publication_id) + LEFT JOIN publication_settings ppss ON (ppss.publication_id = pp.publication_id) + JOIN submissions ss ON (ss.submission_id = pp.submission_id AND ss.current_publication_id = pp.publication_id AND ss.status = ' . STATUS_PUBLISHED . ') + JOIN journals j ON (ss.context_id = j.journal_id) + JOIN issues i ON (ppss.setting_name = ? AND ppss.setting_value = CAST(i.issue_id AS CHAR(20)) AND i.published = 1) + LEFT JOIN author_settings ac ON (ac.author_id = aa.author_id AND ac.setting_name = \'country\') + ' . $sqlJoinAuthorSettings . ' + WHERE j.enabled = 1 + ' . (isset($journalId) ? ' AND j.journal_id = ?' : '') + . $initialSql . ' + GROUP BY names + ) as t1 ON (t1.author_id = a.author_id) + '; + $result = $this->retrieveRange( - $sql = 'SELECT a.*, ug.show_title, s.locale, + "SELECT + a.*, ug.show_title, s.locale, COALESCE(agl.setting_value, agpl.setting_value) AS author_given, - CASE WHEN agl.setting_value <> \'\' THEN afl.setting_value ELSE afpl.setting_value END AS author_family - FROM authors a - JOIN user_groups ug ON (a.user_group_id = ug.user_group_id) - JOIN publications p ON (p.publication_id = a.publication_id) - JOIN submissions s ON (s.current_publication_id = p.publication_id) - LEFT JOIN author_settings agl ON (a.author_id = agl.author_id AND agl.setting_name = ? AND agl.locale = ?) - LEFT JOIN author_settings agpl ON (a.author_id = agpl.author_id AND agpl.setting_name = ? AND agpl.locale = s.locale) - LEFT JOIN author_settings afl ON (a.author_id = afl.author_id AND afl.setting_name = ? AND afl.locale = ?) - LEFT JOIN author_settings afpl ON (a.author_id = afpl.author_id AND afpl.setting_name = ? AND afpl.locale = s.locale) - JOIN ( - SELECT - MIN(aa.author_id) as author_id, - CONCAT( - ' . ($includeEmail ? 'aa.email, \' \', ' : '') . ' - ac.setting_value, - \' \' - ' . $sqlColumnsAuthorSettings . ' - ) as names - FROM authors aa - JOIN publications pp ON (pp.publication_id = aa.publication_id) - LEFT JOIN publication_settings ppss ON (ppss.publication_id = pp.publication_id) - JOIN submissions ss ON (ss.submission_id = pp.submission_id AND ss.current_publication_id = pp.publication_id AND ss.status = ' . STATUS_PUBLISHED . ') - JOIN journals j ON (ss.context_id = j.journal_id) - JOIN issues i ON (ppss.setting_name = ? AND ppss.setting_value = CAST(i.issue_id AS CHAR(20)) AND i.published = 1) - LEFT JOIN author_settings ac ON (ac.author_id = aa.author_id AND ac.setting_name = \'country\') - ' . $sqlJoinAuthorSettings . ' - WHERE j.enabled = 1 - ' . (isset($journalId) ? ' AND j.journal_id = ?' : '') - . $initialSql . ' - GROUP BY names - ) as t1 ON (t1.author_id = a.author_id) - ORDER BY author_family, author_given', + CASE WHEN agl.setting_value <> '' THEN afl.setting_value ELSE afpl.setting_value END AS author_family + {$baseSql} + ORDER BY + author_family, author_given", $params, $rangeInfo ); - return new DAOResultFactory($result, $this, '_fromRow', [], $sql, $params, $rangeInfo); + return new DAOResultFactory($result, $this, '_fromRow', [], "SELECT 0 {$baseSql}", $params, $rangeInfo); } } diff --git a/classes/issue/IssueDAO.inc.php b/classes/issue/IssueDAO.inc.php index 43702ea1cb5..2edf3a986c9 100644 --- a/classes/issue/IssueDAO.inc.php +++ b/classes/issue/IssueDAO.inc.php @@ -567,12 +567,15 @@ function getBySubmissionId($articleId, $journalId = null) { * @return DAOResultFactory */ function getIssues($journalId, $rangeInfo = null) { + $baseSql = ' + FROM issues i WHERE journal_id = ? + '; $result = $this->retrieveRange( - $sql = 'SELECT i.* FROM issues i WHERE journal_id = ? ORDER BY current DESC, date_published DESC', + "SELECT i.* {$baseSql} ORDER BY current DESC, date_published DESC", $params = [(int) $journalId], $rangeInfo ); - return new DAOResultFactory($result, $this, '_returnIssueFromRow', [], $sql, $params, $rangeInfo); // Counted in ExportableIssuesListGridHandler + return new DAOResultFactory($result, $this, '_returnIssueFromRow', [], "SELECT 0 {$baseSql}", $params, $rangeInfo); // Counted in ExportableIssuesListGridHandler } /** @@ -626,24 +629,26 @@ function getExportable($contextId, $pubIdType = null, $pubIdSettingName = null, $params[] = $pubIdSettingValue; } - $result = $this->retrieveRange( - $sql = 'SELECT i.* + $baseSql = ' FROM issues i - LEFT JOIN custom_issue_orders o ON (o.issue_id = i.issue_id) - ' . ($pubIdType != null?' LEFT JOIN issue_settings ist ON (i.issue_id = ist.issue_id)':'') - . ($pubIdSettingName != null?' LEFT JOIN issue_settings iss ON (i.issue_id = iss.issue_id AND iss.setting_name = ?)':'') .' + LEFT JOIN custom_issue_orders o ON (o.issue_id = i.issue_id) + ' . ($pubIdType != null?' LEFT JOIN issue_settings ist ON (i.issue_id = ist.issue_id)':'') + . ($pubIdSettingName != null?' LEFT JOIN issue_settings iss ON (i.issue_id = iss.issue_id AND iss.setting_name = ?)':'') .' WHERE i.published = 1 AND i.journal_id = ? ' . ($pubIdType != null?' AND ist.setting_name = ? AND ist.setting_value IS NOT NULL':'') . (($pubIdSettingName != null && $pubIdSettingValue != null && $pubIdSettingValue == EXPORT_STATUS_NOT_DEPOSITED)?' AND iss.setting_value IS NULL':'') . (($pubIdSettingName != null && $pubIdSettingValue != null && $pubIdSettingValue != EXPORT_STATUS_NOT_DEPOSITED)?' AND iss.setting_value = ?':'') - . (($pubIdSettingName != null && is_null($pubIdSettingValue))?' AND (iss.setting_value IS NULL OR iss.setting_value = \'\')':'') - .' ORDER BY i.date_published DESC', + . (($pubIdSettingName != null && is_null($pubIdSettingValue))?' AND (iss.setting_value IS NULL OR iss.setting_value = \'\')':'') . ' + '; + + $result = $this->retrieveRange( + "SELECT i.* {$baseSql} ORDER BY i.date_published DESC", $params, $rangeInfo ); - return new DAOResultFactory($result, $this, '_returnIssueFromRow', [], $sql, $params, $rangeInfo); + return new DAOResultFactory($result, $this, '_returnIssueFromRow', [], "SELECT 0 {$baseSql}", $params, $rangeInfo); } /** diff --git a/classes/submission/SubmissionDAO.inc.php b/classes/submission/SubmissionDAO.inc.php index 9c50cfe43ec..08f594c71c5 100644 --- a/classes/submission/SubmissionDAO.inc.php +++ b/classes/submission/SubmissionDAO.inc.php @@ -117,34 +117,36 @@ function getExportable($contextId, $pubIdType = null, $title = null, $author = n $params[] = $pubIdSettingValue; } + $baseSql = ' + FROM submissions s + LEFT JOIN publications p ON s.current_publication_id = p.publication_id + LEFT JOIN publication_settings ps ON p.publication_id = ps.publication_id' + . ($issueId ? ' LEFT JOIN publication_settings psi ON p.publication_id = psi.publication_id AND psi.setting_name = \'issueId\' AND psi.locale = \'\'' : '') + . ($pubIdType != null?' LEFT JOIN publication_settings pspidt ON (p.publication_id = pspidt.publication_id)':'') + . ($title != null?' LEFT JOIN publication_settings pst ON (p.publication_id = pst.publication_id)':'') + . ($author != null?' LEFT JOIN authors au ON (p.publication_id = au.publication_id) + LEFT JOIN author_settings asgs ON (asgs.author_id = au.author_id AND asgs.setting_name = \''.IDENTITY_SETTING_GIVENNAME.'\') + LEFT JOIN author_settings asfs ON (asfs.author_id = au.author_id AND asfs.setting_name = \''.IDENTITY_SETTING_FAMILYNAME.'\') + ':'') + . ($pubIdSettingName != null?' LEFT JOIN submission_settings pss ON (s.submission_id = pss.submission_id AND pss.setting_name = ?)':'') . ' + WHERE s.status = ? + AND s.context_id = ?' + . ($pubIdType != null?' AND pspidt.setting_name = ? AND pspidt.setting_value IS NOT NULL':'') + . ($title != null?' AND (pst.setting_name = ? AND pst.setting_value LIKE ?)':'') + . ($author != null?' AND (asgs.setting_value LIKE ? OR asfs.setting_value LIKE ?)':'') + . ($issueId != null?' AND psi.setting_value = ?':'') + . (($pubIdSettingName != null && $pubIdSettingValue != null && $pubIdSettingValue == EXPORT_STATUS_NOT_DEPOSITED)?' AND pss.setting_value IS NULL':'') + . (($pubIdSettingName != null && $pubIdSettingValue != null && $pubIdSettingValue != EXPORT_STATUS_NOT_DEPOSITED)?' AND pss.setting_value = ?':'') + . (($pubIdSettingName != null && is_null($pubIdSettingValue))?' AND (pss.setting_value IS NULL OR pss.setting_value = \'\')':'') . ' + GROUP BY s.submission_id + '; + $result = $this->retrieveRange( - $sql = 'SELECT s.* - FROM submissions s - LEFT JOIN publications p ON s.current_publication_id = p.publication_id - LEFT JOIN publication_settings ps ON p.publication_id = ps.publication_id' - . ($issueId ? ' LEFT JOIN publication_settings psi ON p.publication_id = psi.publication_id AND psi.setting_name = \'issueId\' AND psi.locale = \'\'' : '') - . ($pubIdType != null?' LEFT JOIN publication_settings pspidt ON (p.publication_id = pspidt.publication_id)':'') - . ($title != null?' LEFT JOIN publication_settings pst ON (p.publication_id = pst.publication_id)':'') - . ($author != null?' LEFT JOIN authors au ON (p.publication_id = au.publication_id) - LEFT JOIN author_settings asgs ON (asgs.author_id = au.author_id AND asgs.setting_name = \''.IDENTITY_SETTING_GIVENNAME.'\') - LEFT JOIN author_settings asfs ON (asfs.author_id = au.author_id AND asfs.setting_name = \''.IDENTITY_SETTING_FAMILYNAME.'\') - ':'') - . ($pubIdSettingName != null?' LEFT JOIN submission_settings pss ON (s.submission_id = pss.submission_id AND pss.setting_name = ?)':'') - . ' WHERE s.status = ? - AND s.context_id = ?' - . ($pubIdType != null?' AND pspidt.setting_name = ? AND pspidt.setting_value IS NOT NULL':'') - . ($title != null?' AND (pst.setting_name = ? AND pst.setting_value LIKE ?)':'') - . ($author != null?' AND (asgs.setting_value LIKE ? OR asfs.setting_value LIKE ?)':'') - . ($issueId != null?' AND psi.setting_value = ?':'') - . (($pubIdSettingName != null && $pubIdSettingValue != null && $pubIdSettingValue == EXPORT_STATUS_NOT_DEPOSITED)?' AND pss.setting_value IS NULL':'') - . (($pubIdSettingName != null && $pubIdSettingValue != null && $pubIdSettingValue != EXPORT_STATUS_NOT_DEPOSITED)?' AND pss.setting_value = ?':'') - . (($pubIdSettingName != null && is_null($pubIdSettingValue))?' AND (pss.setting_value IS NULL OR pss.setting_value = \'\')':'') - . ' GROUP BY s.submission_id - ORDER BY MAX(p.date_published) DESC, s.submission_id DESC', + "SELECT s.* {$baseSql} ORDER BY MAX(p.date_published) DESC, s.submission_id DESC", $params, $rangeInfo ); - return new DAOResultFactory($result, $this, '_fromRow', [], $sql, $params, $rangeInfo); // Counted via paging in CrossRef export + return new DAOResultFactory($result, $this, '_fromRow', [], "SELECT 0 {$baseSql}", $params, $rangeInfo); // Counted via paging in CrossRef export } } diff --git a/classes/subscription/IndividualSubscriptionDAO.inc.php b/classes/subscription/IndividualSubscriptionDAO.inc.php index 7284655bcdf..e77c878faf9 100644 --- a/classes/subscription/IndividualSubscriptionDAO.inc.php +++ b/classes/subscription/IndividualSubscriptionDAO.inc.php @@ -337,21 +337,21 @@ function getAll($rangeInfo = null) { function getByJournalId($journalId, $status = null, $searchField = null, $searchMatch = null, $search = null, $dateField = null, $dateFrom = null, $dateTo = null, $rangeInfo = null) { $userDao = DAORegistry::getDAO('UserDAO'); /* @var $userDao UserDAO */ $params = array_merge($userDao->getFetchParameters(), [(int) $journalId]); - $result = $this->retrieveRange( - $sql = 'SELECT s.*, - ' . $userDao->getFetchColumns() . ' + $baseSql = ' FROM subscriptions s - JOIN subscription_types st ON (s.type_id = st.type_id) - JOIN users u ON (s.user_id = u.user_id) - ' . $userDao->getFetchJoins() . ' + JOIN subscription_types st ON (s.type_id = st.type_id) + JOIN users u ON (s.user_id = u.user_id) + ' . $userDao->getFetchJoins() . ' WHERE st.institutional = 0 AND s.journal_id = ? ' . - parent::_generateSearchSQL($status, $searchField, $searchMatch, $search, $dateField, $dateFrom, $dateTo, $params) . ' ' . - $userDao->getOrderBy() .', s.subscription_id', + parent::_generateSearchSQL($status, $searchField, $searchMatch, $search, $dateField, $dateFrom, $dateTo, $params) . ' + '; + $result = $this->retrieveRange( + 'SELECT s.*, ' . $userDao->getFetchColumns() . $baseSql . $userDao->getOrderBy() . ', s.subscription_id', $params, $rangeInfo ); - return new DAOResultFactory($result, $this, '_fromRow', [], $sql, $params, $rangeInfo); // Counted in subscription grid paging + return new DAOResultFactory($result, $this, '_fromRow', [], "SELECT 0 {$baseSql}", $params, $rangeInfo); // Counted in subscription grid paging } /** diff --git a/classes/subscription/InstitutionalSubscriptionDAO.inc.php b/classes/subscription/InstitutionalSubscriptionDAO.inc.php index a56326feaf0..7eee3ae80aa 100644 --- a/classes/subscription/InstitutionalSubscriptionDAO.inc.php +++ b/classes/subscription/InstitutionalSubscriptionDAO.inc.php @@ -415,25 +415,28 @@ function getByJournalId($journalId, $status = null, $searchField = null, $search break; } - - $result = $this->retrieveRange( - $sql = 'SELECT DISTINCT s.*, iss.institution_name, iss.mailing_address, iss.domain, - ' . $userDao->getFetchColumns() .' - FROM subscriptions s - JOIN subscription_types st ON (s.type_id = st.type_id) - JOIN users u ON (s.user_id = u.user_id) - JOIN institutional_subscriptions iss ON (s.subscription_id = iss.subscription_id) - ' . $userDao->getFetchJoins() . ' - ' . $ipRangeSql1 . ' - WHERE st.institutional = 1 + $baseSql = ' + FROM subscriptions s + JOIN subscription_types st ON (s.type_id = st.type_id) + JOIN users u ON (s.user_id = u.user_id) + JOIN institutional_subscriptions iss ON (s.subscription_id = iss.subscription_id) + ' . $userDao->getFetchJoins() . ' + ' . $ipRangeSql1 . ' + WHERE st.institutional = 1 ' . $ipRangeSql2 . ' AND s.journal_id = ? - ' . $searchSql . ' ORDER BY iss.institution_name ASC, s.subscription_id', + ' . $searchSql . ' + '; + + $result = $this->retrieveRange( + 'SELECT DISTINCT s.*, iss.institution_name, iss.mailing_address, iss.domain, ' . $userDao->getFetchColumns() . " + {$baseSql} + ORDER BY iss.institution_name ASC, s.subscription_id", $params, $rangeInfo ); - return new DAOResultFactory($result, $this, '_fromRow', [], $sql, $params, $rangeInfo); // Counted in subscription grid paging + return new DAOResultFactory($result, $this, '_fromRow', [], "SELECT 0 {$baseSql}", $params, $rangeInfo); // Counted in subscription grid paging } /** diff --git a/classes/subscription/SubscriptionTypeDAO.inc.php b/classes/subscription/SubscriptionTypeDAO.inc.php index a8e069c90cf..b416ac64ac0 100644 --- a/classes/subscription/SubscriptionTypeDAO.inc.php +++ b/classes/subscription/SubscriptionTypeDAO.inc.php @@ -266,11 +266,14 @@ function deleteByJournal($journalId) { * @return object DAOResultFactory containing matching SubscriptionTypes */ function getByJournalId($journalId, $rangeInfo = null) { + $baseSql = ' + FROM subscription_types WHERE journal_id = ? + '; $result = $this->retrieveRange( - $sql = 'SELECT * FROM subscription_types WHERE journal_id = ? ORDER BY seq', + "SELECT * {$baseSql} ORDER BY seq", $params = [(int) $journalId], $rangeInfo); - return new DAOResultFactory($result, $this, '_fromRow', [], $sql, $params, $rangeInfo); // Counted in subscription type grid paging + return new DAOResultFactory($result, $this, '_fromRow', [], "SELECT 0 {$baseSql}", $params, $rangeInfo); // Counted in subscription type grid paging } /**