Open Journal Systems  3.3.0
AuthorDAO.inc.php
1 <?php
2 
17 import('classes.article.Author');
18 import('classes.submission.Submission');
19 import('lib.pkp.classes.submission.PKPAuthorDAO');
20 
21 class AuthorDAO extends PKPAuthorDAO {
22 
35  function getAuthorsAlphabetizedByJournal($journalId = null, $initial = null, $rangeInfo = null, $includeEmail = false) {
36  $locale = AppLocale::getLocale();
37  $params = array(
38  IDENTITY_SETTING_GIVENNAME, $locale,
39  IDENTITY_SETTING_GIVENNAME,
40  IDENTITY_SETTING_FAMILYNAME, $locale,
41  IDENTITY_SETTING_FAMILYNAME,
42  'issueId',
43  );
44  if (isset($journalId)) $params[] = $journalId;
45 
46  $supportedLocales = array();
47  if ($journalId !== null) {
48  $journalDao = DAORegistry::getDAO('JournalDAO'); /* @var $journalDao JournalDAO */
49  $journal = $journalDao->getById($journalId);
50  $supportedLocales = $journal->getSupportedLocales();
51  } else {
52  $site = Application::get()->getRequest()->getSite();
53  $supportedLocales = $site->getSupportedLocales();
54  }
55  $supportedLocalesCount = count($supportedLocales);
56  $sqlJoinAuthorSettings = $sqlColumnsAuthorSettings = $initialSql = '';
57  if (isset($initial)) {
58  $initialSql = ' AND (';
59  }
60  $index = 0;
61  foreach ($supportedLocales as $locale) {
62  $localeStr = str_replace('@', '_', $locale);
63  $sqlColumnsAuthorSettings .= ",
64  COALESCE(asg$index.setting_value, ''), ' ',
65  COALESCE(asf$index.setting_value, ''), ' ',
66  COALESCE(SUBSTRING(asa$index.setting_value FROM 1 FOR 255), ''), ' '
67  ";
68  $sqlJoinAuthorSettings .= "
69  LEFT JOIN author_settings asg$index ON (asg$index.author_id = aa.author_id AND asg$index.setting_name = '" . IDENTITY_SETTING_GIVENNAME . "' AND asg$index.locale = '$locale')
70  LEFT JOIN author_settings asf$index ON (asf$index.author_id = aa.author_id AND asf$index.setting_name = '" . IDENTITY_SETTING_FAMILYNAME . "' AND asf$index.locale = '$locale')
71  LEFT JOIN author_settings asa$index ON (asa$index.author_id = aa.author_id AND asa$index.setting_name = 'affiliation' AND asa$index.locale = '$locale')
72  ";
73  if (isset($initial)) {
74  if ($initial == '-') {
75  $initialSql .= "(asf$index.setting_value IS NULL OR asf$index.setting_value = '')";
76  if ($index < $supportedLocalesCount - 1) {
77  $initialSql .= ' AND ';
78  }
79  } else {
80  $params[] = PKPString::strtolower($initial) . '%';
81  $initialSql .= "LOWER(asf$index.setting_value) LIKE LOWER(?)";
82  if ($index < $supportedLocalesCount - 1) {
83  $initialSql .= ' OR ';
84  }
85  }
86  }
87  $index++;
88  }
89  if (isset($initial)) {
90  $initialSql .= ')';
91  }
92 
93  $result = $this->retrieveRange(
94  'SELECT a.*, ug.show_title, p.locale,
95  COALESCE(agl.setting_value, agpl.setting_value) AS author_given,
96  CASE WHEN agl.setting_value <> \'\' THEN afl.setting_value ELSE afpl.setting_value END AS author_family
97  FROM authors a
98  JOIN user_groups ug ON (a.user_group_id = ug.user_group_id)
99  JOIN publications p ON (p.publication_id = a.publication_id)
100  JOIN submissions s ON (s.current_publication_id = p.publication_id)
101  LEFT JOIN author_settings agl ON (a.author_id = agl.author_id AND agl.setting_name = ? AND agl.locale = ?)
102  LEFT JOIN author_settings agpl ON (a.author_id = agpl.author_id AND agpl.setting_name = ? AND agpl.locale = p.locale)
103  LEFT JOIN author_settings afl ON (a.author_id = afl.author_id AND afl.setting_name = ? AND afl.locale = ?)
104  LEFT JOIN author_settings afpl ON (a.author_id = afpl.author_id AND afpl.setting_name = ? AND afpl.locale = p.locale)
105  JOIN (
106  SELECT
107  MIN(aa.author_id) as author_id,
108  CONCAT(
109  ' . ($includeEmail ? 'aa.email,' : 'CAST(\'\' AS CHAR),') . '
110  \' \',
111  ac.setting_value,
112  \' \'
113  ' . $sqlColumnsAuthorSettings . '
114  ) as names
115  FROM authors aa
116  JOIN publications pp ON (pp.publication_id = aa.publication_id)
117  LEFT JOIN publication_settings ppss ON (ppss.publication_id = pp.publication_id)
118  JOIN submissions ss ON (ss.submission_id = pp.submission_id AND ss.current_publication_id = pp.publication_id AND ss.status = ' . STATUS_PUBLISHED . ')
119  JOIN journals j ON (ss.context_id = j.journal_id)
120  JOIN issues i ON (ppss.setting_name = ? AND ppss.setting_value = CAST(i.issue_id AS CHAR) AND i.published = 1)
121  LEFT JOIN author_settings ac ON (ac.author_id = aa.author_id AND ac.setting_name = \'country\')
122  ' . $sqlJoinAuthorSettings . '
123  WHERE j.enabled = 1
124  ' . (isset($journalId) ? ' AND j.journal_id = ?' : '')
125  . $initialSql . '
126  GROUP BY names
127  ) as t1 ON (t1.author_id = a.author_id)
128  ORDER BY author_family, author_given',
129  $params,
130  $rangeInfo
131  );
132 
133  return new DAOResultFactory($result, $this, '_fromRow');
134  }
135 }
136 
137 
AuthorDAO\getAuthorsAlphabetizedByJournal
getAuthorsAlphabetizedByJournal($journalId=null, $initial=null, $rangeInfo=null, $includeEmail=false)
Definition: AuthorDAO.inc.php:35
DAOResultFactory
Wrapper around ADORecordSet providing "factory" features for generating objects from DAOs.
Definition: DAOResultFactory.inc.php:21
AuthorDAO
Operations for retrieving and modifying Author objects.
Definition: AuthorDAO.inc.php:21
DAO\retrieveRange
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:176
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
PKPAuthorDAO
Operations for retrieving and modifying PKPAuthor objects.
Definition: PKPAuthorDAO.inc.php:20
PKPString\strtolower
static strtolower($string)
Definition: PKPString.inc.php:169
PKPApplication\get
static get()
Definition: PKPApplication.inc.php:235
AppLocale\getLocale
static getLocale()
Definition: env1/MockAppLocale.inc.php:40