Open Journal Systems  2.4.4
 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 
93  function &getAuthorsAlphabetizedByJournal($journalId = null, $initial = null, $rangeInfo = null, $includeEmail = false) {
94  $authors = array();
95  $params = array(
96  'affiliation', AppLocale::getPrimaryLocale(),
97  'affiliation', AppLocale::getLocale()
98  );
99 
100  if (isset($journalId)) $params[] = $journalId;
101  if (isset($initial)) {
102  $params[] = String::strtolower($initial) . '%';
103  $initialSql = ' AND LOWER(aa.last_name) LIKE LOWER(?)';
104  } else {
105  $initialSql = '';
106  }
107 
108  $result =& $this->retrieveRange(
109  'SELECT DISTINCT
110  CAST(\'\' AS CHAR) AS url,
111  0 AS author_id,
112  0 AS submission_id,
113  ' . ($includeEmail?'aa.email AS email,':'CAST(\'\' AS CHAR) AS email,') . '
114  0 AS primary_contact,
115  0 AS seq,
116  aa.first_name,
117  aa.middle_name,
118  aa.last_name,
119  CASE WHEN asl.setting_value = \'\' THEN NULL ELSE SUBSTRING(asl.setting_value FROM 1 FOR 255) END AS affiliation_l,
120  asl.locale,
121  CASE WHEN aspl.setting_value = \'\' THEN NULL ELSE SUBSTRING(aspl.setting_value FROM 1 FOR 255) END AS affiliation_pl,
122  aspl.locale AS primary_locale,
123  CASE WHEN aa.country = \'\' THEN NULL ELSE aa.country END AS country
124  FROM authors aa
125  LEFT JOIN author_settings aspl ON (aa.author_id = aspl.author_id AND aspl.setting_name = ? AND aspl.locale = ?)
126  LEFT JOIN author_settings asl ON (aa.author_id = asl.author_id AND asl.setting_name = ? AND asl.locale = ?)
127  JOIN articles a ON (a.article_id = aa.submission_id AND a.status = ' . STATUS_PUBLISHED . ')
128  JOIN published_articles pa ON (pa.article_id = a.article_id)
129  JOIN issues i ON (pa.issue_id = i.issue_id AND i.published = 1)
130  WHERE ' . (isset($journalId)?'a.journal_id = ? AND ':'') . '
131  (aa.last_name IS NOT NULL AND aa.last_name <> \'\')' .
132  $initialSql . '
133  ORDER BY aa.last_name, aa.first_name',
134  $params,
135  $rangeInfo
136  );
137 
138  $returner = new DAOResultFactory($result, $this, '_returnSimpleAuthorFromRow');
139  return $returner;
140  }
141 
146  function newDataObject() {
147  return new Author();
148  }
149 
154  function insertAuthor(&$author) {
155  $this->update(
156  'INSERT INTO authors
157  (submission_id, first_name, middle_name, last_name, country, email, url, primary_contact, seq)
158  VALUES
159  (?, ?, ?, ?, ?, ?, ?, ?, ?)',
160  array(
161  $author->getSubmissionId(),
162  $author->getFirstName(),
163  $author->getMiddleName() . '', // make non-null
164  $author->getLastName(),
165  $author->getCountry(),
166  $author->getEmail(),
167  $author->getUrl(),
168  (int) $author->getPrimaryContact(),
169  (float) $author->getSequence()
170  )
171  );
172 
173  $author->setId($this->getInsertAuthorId());
174  $this->updateLocaleFields($author);
175 
176  return $author->getId();
177  }
178 
183  function updateAuthor(&$author) {
184  $returner = $this->update(
185  'UPDATE authors
186  SET first_name = ?,
187  middle_name = ?,
188  last_name = ?,
189  country = ?,
190  email = ?,
191  url = ?,
192  primary_contact = ?,
193  seq = ?
194  WHERE author_id = ?',
195  array(
196  $author->getFirstName(),
197  $author->getMiddleName() . '', // make non-null
198  $author->getLastName(),
199  $author->getCountry(),
200  $author->getEmail(),
201  $author->getUrl(),
202  (int) $author->getPrimaryContact(),
203  (float) $author->getSequence(),
204  (int) $author->getId()
205  )
206  );
207  $this->updateLocaleFields($author);
208  return $returner;
209  }
210 
215  function deleteAuthorsByArticle($submissionId) {
216  $authors =& $this->getAuthorsBySubmissionId($submissionId);
217  foreach ($authors as $author) {
218  $this->deleteAuthor($author);
219  }
220  }
221 
222  function getAdditionalFieldNames() {
223  return array('orcid');
224  }
225 }
226 
227 ?>
insertAuthor(&$author)
Operations for retrieving and modifying Author objects.
& getAuthorsAlphabetizedByJournal($journalId=null, $initial=null, $rangeInfo=null, $includeEmail=false)
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)
& 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)