Open Preprint 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  );
43  if (isset($journalId)) $params[] = $journalId;
44 
45  $supportedLocales = array();
46  if ($journalId !== null) {
47  $journalDao = DAORegistry::getDAO('JournalDAO'); /* @var $journalDao JournalDAO */
48  $journal = $journalDao->getById($journalId);
49  $supportedLocales = $journal->getSupportedLocales();
50  } else {
51  $site = Application::get()->getRequest()->getSite();
52  $supportedLocales = $site->getSupportedLocales();
53  }
54  $supportedLocalesCount = count($supportedLocales);
55  $sqlJoinAuthorSettings = $sqlColumnsAuthorSettings = $initialSql = '';
56  if (isset($initial)) {
57  $initialSql = ' AND (';
58  }
59  $index = 0;
60  foreach ($supportedLocales as $locale) {
61  $localeStr = str_replace('@', '_', $locale);
62  $sqlColumnsAuthorSettings .= ",
63  COALESCE(asg$index.setting_value, ''), ' ',
64  COALESCE(asf$index.setting_value, ''), ' ',
65  COALESCE(SUBSTRING(asa$index.setting_value FROM 1 FOR 255), ''), ' '
66  ";
67  $sqlJoinAuthorSettings .= "
68  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')
69  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')
70  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')
71  ";
72  if (isset($initial)) {
73  if ($initial == '-') {
74  $initialSql .= "(asf$index.setting_value IS NULL OR asf$index.setting_value = '')";
75  if ($index < $supportedLocalesCount - 1) {
76  $initialSql .= ' AND ';
77  }
78  } else {
79  $params[] = PKPString::strtolower($initial) . '%';
80  $initialSql .= "LOWER(asf$index.setting_value) LIKE LOWER(?)";
81  if ($index < $supportedLocalesCount - 1) {
82  $initialSql .= ' OR ';
83  }
84  }
85  }
86  $index++;
87  }
88  if (isset($initial)) {
89  $initialSql .= ')';
90  }
91 
92  $result = $this->retrieveRange(
93  'SELECT a.*, ug.show_title, p.locale,
94  COALESCE(agl.setting_value, agpl.setting_value) AS author_given,
95  CASE WHEN agl.setting_value <> \'\' THEN afl.setting_value ELSE afpl.setting_value END AS author_family
96  FROM authors a
97  JOIN user_groups ug ON (a.user_group_id = ug.user_group_id)
98  JOIN publications p ON (p.publication_id = a.publication_id)
99  JOIN submissions s ON (s.current_publication_id = p.publication_id)
100  LEFT JOIN author_settings agl ON (a.author_id = agl.author_id AND agl.setting_name = ? AND agl.locale = ?)
101  LEFT JOIN author_settings agpl ON (a.author_id = agpl.author_id AND agpl.setting_name = ? AND agpl.locale = p.locale)
102  LEFT JOIN author_settings afl ON (a.author_id = afl.author_id AND afl.setting_name = ? AND afl.locale = ?)
103  LEFT JOIN author_settings afpl ON (a.author_id = afpl.author_id AND afpl.setting_name = ? AND afpl.locale = p.locale)
104  JOIN (
105  SELECT
106  MIN(aa.author_id) as author_id,
107  CONCAT(
108  ' . ($includeEmail ? 'aa.email,' : 'CAST(\'\' AS CHAR),') . '
109  \' \',
110  ac.setting_value,
111  \' \'
112  ' . $sqlColumnsAuthorSettings . '
113  ) as names
114  FROM authors aa
115  JOIN publications pp ON (pp.publication_id = aa.publication_id)
116  LEFT JOIN publication_settings ppss ON (ppss.publication_id = pp.publication_id)
117  JOIN submissions ss ON (ss.submission_id = pp.submission_id AND ss.current_publication_id = pp.publication_id AND ss.status = ' . STATUS_PUBLISHED . ')
118  JOIN journals j ON (ss.context_id = j.journal_id)
119  LEFT JOIN author_settings ac ON (ac.author_id = aa.author_id AND ac.setting_name = \'country\')
120  ' . $sqlJoinAuthorSettings . '
121  WHERE j.enabled = 1
122  ' . (isset($journalId) ? ' AND j.journal_id = ?' : '')
123  . $initialSql . '
124  GROUP BY names
125  ) as t1 ON (t1.author_id = a.author_id)
126  ORDER BY author_family, author_given',
127  $params,
128  $rangeInfo
129  );
130 
131  return new DAOResultFactory($result, $this, '_fromRow');
132  }
133 }
134 
135 
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