Open Journal Systems  2.4.8
 All Classes Namespaces Functions Variables Groups Pages
AuthorDAO.inc.php
1 <?php
2 
17 import('classes.article.Author');
18 import('classes.article.Article');
19 import('lib.pkp.classes.submission.PKPAuthorDAO');
20 
21 class AuthorDAO extends PKPAuthorDAO {
25  function AuthorDAO() {
26  parent::PKPAuthorDAO();
27  }
28 
39  function &getPublishedArticlesForAuthor($journalId, $firstName, $middleName, $lastName, $affiliation, $country) {
40  $publishedArticles = array();
41  $publishedArticleDao =& DAORegistry::getDAO('PublishedArticleDAO');
42  $params = array(
43  'affiliation',
44  $firstName, $middleName, $lastName,
45  $affiliation, $country
46  );
47  if ($journalId !== null) $params[] = (int) $journalId;
48 
49  $result =& $this->retrieve(
50  'SELECT DISTINCT
51  aa.submission_id
52  FROM authors aa
53  LEFT JOIN articles a ON (aa.submission_id = a.article_id)
54  LEFT JOIN author_settings asl ON (asl.author_id = aa.author_id AND asl.setting_name = ?)
55  WHERE aa.first_name = ?
56  AND a.status = ' . STATUS_PUBLISHED . '
57  AND (aa.middle_name = ?' . (empty($middleName)?' OR aa.middle_name IS NULL':'') . ')
58  AND aa.last_name = ?
59  AND (asl.setting_value = ?' . (empty($affiliation)?' OR asl.setting_value IS NULL':'') . ')
60  AND (aa.country = ?' . (empty($country)?' OR aa.country IS NULL':'') . ') ' .
61  ($journalId!==null?(' AND a.journal_id = ?'):''),
62  $params
63  );
64 
65  while (!$result->EOF) {
66  $row =& $result->getRowAssoc(false);
67  $publishedArticle =& $publishedArticleDao->getPublishedArticleByArticleId($row['submission_id']);
68  if ($publishedArticle) {
69  $publishedArticles[] =& $publishedArticle;
70  }
71  $result->moveNext();
72  unset($publishedArticle);
73  }
74 
75  $result->Close();
76  unset($result);
77 
78  return $publishedArticles;
79  }
80 
94  function &getAuthorsAlphabetizedByJournal($journalId = null, $initial = null, $rangeInfo = null, $includeEmail = false, $disallowRepeatedEmail = false) {
95  $authors = array();
96  $params = array(
97  'affiliation', AppLocale::getPrimaryLocale(),
98  'affiliation', AppLocale::getLocale()
99  );
100 
101  if (isset($journalId)) $params[] = $journalId;
102  $params[] = AUTHOR_TOC_DEFAULT;
103  $params[] = AUTHOR_TOC_SHOW;
104  if (isset($initial)) {
105  $params[] = String::strtolower($initial) . '%';
106  $initialSql = ' AND LOWER(aa.last_name) LIKE LOWER(?)';
107  } else {
108  $initialSql = '';
109  }
110 
111  $result =& $this->retrieveRange(
112  'SELECT DISTINCT
113  CAST(\'\' AS CHAR) AS url,
114  0 AS author_id,
115  0 AS submission_id,
116  ' . ($includeEmail?'aa.email AS email,':'CAST(\'\' AS CHAR) AS email,') . '
117  0 AS primary_contact,
118  0 AS seq,
119  aa.first_name,
120  aa.middle_name,
121  aa.last_name,
122  CASE WHEN asl.setting_value = \'\' THEN NULL ELSE SUBSTRING(asl.setting_value FROM 1 FOR 255) END AS affiliation_l,
123  CASE WHEN asl.setting_value = \'\' THEN NULL ELSE asl.locale END AS locale,
124  CASE WHEN aspl.setting_value = \'\' THEN NULL ELSE SUBSTRING(aspl.setting_value FROM 1 FOR 255) END AS affiliation_pl,
125  CASE WHEN aspl.setting_value = \'\' THEN NULL ELSE aspl.locale END AS primary_locale,
126  CASE WHEN aa.country = \'\' THEN NULL ELSE aa.country END AS country
127  FROM authors aa
128  LEFT JOIN author_settings aspl ON (aa.author_id = aspl.author_id AND aspl.setting_name = ? AND aspl.locale = ?)
129  LEFT JOIN author_settings asl ON (aa.author_id = asl.author_id AND asl.setting_name = ? AND asl.locale = ?)
130  '.($disallowRepeatedEmail?" LEFT JOIN authors aa2 ON (aa.email=aa2.email AND aa.author_id < aa2.author_id) ":"").'
131  JOIN articles a ON (a.article_id = aa.submission_id AND a.status = ' . STATUS_PUBLISHED . ')
132  JOIN published_articles pa ON (pa.article_id = a.article_id)
133  JOIN issues i ON (pa.issue_id = i.issue_id AND i.published = 1)
134  JOIN sections s ON (a.section_id = s.section_id)
135  JOIN journals j ON (a.journal_id = j.journal_id)
136  WHERE ' . (isset($journalId)?'a.journal_id = ?':'j.enabled = 1') . '
137  AND (aa.last_name IS NOT NULL AND aa.last_name <> \'\')
138  AND ((s.hide_author = 0 AND a.hide_author = ?) OR a.hide_author = ?)
139  ' . ($disallowRepeatedEmail?' AND aa2.email IS NULL ':'')
140  . $initialSql . '
141  ORDER BY aa.last_name, aa.first_name',
142  $params,
143  $rangeInfo
144  );
145 
146  $returner = new DAOResultFactory($result, $this, '_returnSimpleAuthorFromRow');
147  return $returner;
148  }
149 
154  function newDataObject() {
155  return new Author();
156  }
157 
162  function insertAuthor(&$author) {
163  $this->update(
164  'INSERT INTO authors
165  (submission_id, first_name, middle_name, last_name, country, email, url, primary_contact, seq)
166  VALUES
167  (?, ?, ?, ?, ?, ?, ?, ?, ?)',
168  array(
169  $author->getSubmissionId(),
170  $author->getFirstName(),
171  $author->getMiddleName() . '', // make non-null
172  $author->getLastName(),
173  $author->getCountry(),
174  $author->getEmail(),
175  $author->getUrl(),
176  (int) $author->getPrimaryContact(),
177  (float) $author->getSequence()
178  )
179  );
180 
181  $author->setId($this->getInsertAuthorId());
182  $this->updateLocaleFields($author);
183 
184  return $author->getId();
185  }
186 
191  function updateAuthor(&$author) {
192  $returner = $this->update(
193  'UPDATE authors
194  SET first_name = ?,
195  middle_name = ?,
196  last_name = ?,
197  country = ?,
198  email = ?,
199  url = ?,
200  primary_contact = ?,
201  seq = ?
202  WHERE author_id = ?',
203  array(
204  $author->getFirstName(),
205  $author->getMiddleName() . '', // make non-null
206  $author->getLastName(),
207  $author->getCountry(),
208  $author->getEmail(),
209  $author->getUrl(),
210  (int) $author->getPrimaryContact(),
211  (float) $author->getSequence(),
212  (int) $author->getId()
213  )
214  );
215  $this->updateLocaleFields($author);
216  return $returner;
217  }
218 
223  function deleteAuthorsByArticle($submissionId) {
224  $authors =& $this->getAuthorsBySubmissionId($submissionId);
225  foreach ($authors as $author) {
226  $this->deleteAuthor($author);
227  }
228  }
229 
230  function getAdditionalFieldNames() {
231  $additionalFields = parent::getAdditionalFieldNames();
232  $additionalFields[] = 'orcid';
233  return $additionalFields;
234  }
235 }
236 
237 ?>
insertAuthor(&$author)
Operations for retrieving and modifying Author objects.
updateAuthor(&$author)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:83
Article author metadata class.
Definition: Author.inc.php:20
Operations for retrieving and modifying PKPAuthor objects.
updateLocaleFields(&$author)
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:176
deleteAuthorsByArticle($submissionId)
strtolower($string)
Definition: String.inc.php:229
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
& getDAO($name, $dbconn=null)
& getAuthorsAlphabetizedByJournal($journalId=null, $initial=null, $rangeInfo=null, $includeEmail=false, $disallowRepeatedEmail=false)
& getPublishedArticlesForAuthor($journalId, $firstName, $middleName, $lastName, $affiliation, $country)
& getAuthorsBySubmissionId($submissionId, $sortByAuthorId=false)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:211
deleteAuthor(&$author)