00001 <?php
00002
00016
00017
00018
00019 import('article.Author');
00020 import('article.Article');
00021
00022 class AuthorDAO extends DAO {
00028 function &getAuthor($authorId) {
00029 $result = &$this->retrieve(
00030 'SELECT * FROM article_authors WHERE author_id = ?', $authorId
00031 );
00032
00033 $returner = null;
00034 if ($result->RecordCount() != 0) {
00035 $returner = &$this->_returnAuthorFromRow($result->GetRowAssoc(false));
00036 }
00037
00038 $result->Close();
00039 unset($result);
00040
00041 return $returner;
00042 }
00043
00049 function &getAuthorsByArticle($articleId) {
00050 $authors = array();
00051
00052 $result = &$this->retrieve(
00053 'SELECT * FROM article_authors WHERE article_id = ? ORDER BY seq',
00054 $articleId
00055 );
00056
00057 while (!$result->EOF) {
00058 $authors[] = &$this->_returnAuthorFromRow($result->GetRowAssoc(false));
00059 $result->moveNext();
00060 }
00061
00062 $result->Close();
00063 unset($result);
00064
00065 return $authors;
00066 }
00067
00078 function &getPublishedArticlesForAuthor($journalId, $firstName, $middleName, $lastName, $affiliation, $country) {
00079 $publishedArticles = array();
00080 $publishedArticleDao = &DAORegistry::getDAO('PublishedArticleDAO');
00081 $params = array($firstName, $middleName, $lastName, $affiliation, $country);
00082 if ($journalId !== null) $params[] = $journalId;
00083
00084 $result = &$this->retrieve(
00085 'SELECT DISTINCT
00086 aa.article_id
00087 FROM article_authors aa
00088 LEFT JOIN articles a ON (aa.article_id = a.article_id)
00089 WHERE aa.first_name = ?
00090 AND a.status = ' . STATUS_PUBLISHED . '
00091 AND (aa.middle_name = ?' . (empty($middleName)?' OR aa.middle_name IS NULL':'') . ')
00092 AND aa.last_name = ?
00093 AND (aa.affiliation = ?' . (empty($affiliation)?' OR aa.affiliation IS NULL':'') . ')
00094 AND (aa.country = ?' . (empty($country)?' OR aa.country IS NULL':'') . ') ' .
00095 ($journalId!==null?(' AND a.journal_id = ?'):''),
00096 $params
00097 );
00098
00099 while (!$result->EOF) {
00100 $row = &$result->getRowAssoc(false);
00101 $publishedArticle = &$publishedArticleDao->getPublishedArticleByArticleId($row['article_id']);
00102 if ($publishedArticle) {
00103 $publishedArticles[] = &$publishedArticle;
00104 }
00105 $result->moveNext();
00106 }
00107
00108 $result->Close();
00109 unset($result);
00110
00111 return $publishedArticles;
00112 }
00113
00124 function &getAuthorsAlphabetizedByJournal($journalId = null, $initial = null, $rangeInfo = null) {
00125 $authors = array();
00126 $params = array();
00127
00128 if (isset($journalId)) $params[] = $journalId;
00129 if (isset($initial)) {
00130 $params[] = String::strtolower($initial) . '%';
00131 $initialSql = ' AND LOWER(aa.last_name) LIKE LOWER(?)';
00132 } else {
00133 $initialSql = '';
00134 }
00135
00136 $result = &$this->retrieveRange(
00137 'SELECT DISTINCT
00138 CAST(\'\' AS CHAR) AS url,
00139 0 AS author_id,
00140 0 AS article_id,
00141 CAST(\'\' AS CHAR) AS email,
00142 0 AS primary_contact,
00143 0 AS seq,
00144 aa.first_name AS first_name,
00145 aa.middle_name AS middle_name,
00146 aa.last_name AS last_name,
00147 aa.affiliation AS affiliation,
00148 aa.country
00149 FROM article_authors aa,
00150 articles a,
00151 published_articles pa,
00152 issues i
00153 WHERE i.issue_id = pa.issue_id
00154 AND i.published = 1
00155 AND aa.article_id = a.article_id ' .
00156 (isset($journalId)?'AND a.journal_id = ? ':'') . '
00157 AND pa.article_id = a.article_id
00158 AND a.status = ' . STATUS_PUBLISHED . '
00159 AND (aa.last_name IS NOT NULL AND aa.last_name <> \'\')' .
00160 $initialSql . '
00161 ORDER BY aa.last_name, aa.first_name',
00162 empty($params)?false:$params,
00163 $rangeInfo
00164 );
00165
00166 $returner = &new DAOResultFactory($result, $this, '_returnAuthorFromRow');
00167 return $returner;
00168 }
00169
00175 function &getAuthorIdsByArticle($articleId) {
00176 $authors = array();
00177
00178 $result = &$this->retrieve(
00179 'SELECT author_id FROM article_authors WHERE article_id = ? ORDER BY seq',
00180 $articleId
00181 );
00182
00183 while (!$result->EOF) {
00184 $authors[] = $result->fields[0];
00185 $result->moveNext();
00186 }
00187
00188 $result->Close();
00189 unset($result);
00190
00191 return $authors;
00192 }
00193
00198 function getLocaleFieldNames() {
00199 return array('biography', 'competingInterests');
00200 }
00201
00206 function updateLocaleFields(&$author) {
00207 $this->updateDataObjectSettings('article_author_settings', $author, array(
00208 'author_id' => $author->getAuthorId()
00209 ));
00210
00211 }
00212
00218 function &_returnAuthorFromRow(&$row) {
00219 $author = &new Author();
00220 $author->setAuthorId($row['author_id']);
00221 $author->setArticleId($row['article_id']);
00222 $author->setFirstName($row['first_name']);
00223 $author->setMiddleName($row['middle_name']);
00224 $author->setLastName($row['last_name']);
00225 $author->setAffiliation($row['affiliation']);
00226 $author->setCountry($row['country']);
00227 $author->setEmail($row['email']);
00228 $author->setUrl($row['url']);
00229 $author->setPrimaryContact($row['primary_contact']);
00230 $author->setSequence($row['seq']);
00231
00232 $this->getDataObjectSettings('article_author_settings', 'author_id', $row['author_id'], $author);
00233
00234 HookRegistry::call('AuthorDAO::_returnAuthorFromRow', array(&$author, &$row));
00235
00236 return $author;
00237 }
00238
00243 function insertAuthor(&$author) {
00244 $this->update(
00245 'INSERT INTO article_authors
00246 (article_id, first_name, middle_name, last_name, affiliation, country, email, url, primary_contact, seq)
00247 VALUES
00248 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
00249 array(
00250 $author->getArticleId(),
00251 $author->getFirstName(),
00252 $author->getMiddleName() . '',
00253 $author->getLastName(),
00254 $author->getAffiliation() . '',
00255 $author->getCountry(),
00256 $author->getEmail(),
00257 $author->getUrl(),
00258 $author->getPrimaryContact(),
00259 $author->getSequence()
00260 )
00261 );
00262
00263 $author->setAuthorId($this->getInsertAuthorId());
00264 $this->updateLocaleFields($author);
00265
00266 return $author->getAuthorId();
00267 }
00268
00273 function updateAuthor(&$author) {
00274 $returner = $this->update(
00275 'UPDATE article_authors
00276 SET
00277 first_name = ?,
00278 middle_name = ?,
00279 last_name = ?,
00280 affiliation = ?,
00281 country = ?,
00282 email = ?,
00283 url = ?,
00284 primary_contact = ?,
00285 seq = ?
00286 WHERE author_id = ?',
00287 array(
00288 $author->getFirstName(),
00289 $author->getMiddleName() . '',
00290 $author->getLastName(),
00291 $author->getAffiliation() . '',
00292 $author->getCountry(),
00293 $author->getEmail(),
00294 $author->getUrl(),
00295 $author->getPrimaryContact(),
00296 $author->getSequence(),
00297 $author->getAuthorId()
00298 )
00299 );
00300 $this->updateLocaleFields($author);
00301 return $returner;
00302 }
00303
00308 function deleteAuthor(&$author) {
00309 return $this->deleteAuthorById($author->getAuthorId());
00310 }
00311
00317 function deleteAuthorById($authorId, $articleId = null) {
00318 $params = array($authorId);
00319 if ($articleId) $params[] = $articleId;
00320 $returner = $this->update(
00321 'DELETE FROM article_authors WHERE author_id = ?' .
00322 ($articleId?' AND article_id = ?':''),
00323 $params
00324 );
00325 if ($returner) $this->update('DELETE FROM article_author_settings WHERE author_id = ?', array($authorId));
00326 }
00327
00332 function deleteAuthorsByArticle($articleId) {
00333 $authors =& $this->getAuthorsByArticle($articleId);
00334 foreach ($authors as $author) {
00335 $this->deleteAuthor($author);
00336 }
00337 }
00338
00343 function resequenceAuthors($articleId) {
00344 $result = &$this->retrieve(
00345 'SELECT author_id FROM article_authors WHERE article_id = ? ORDER BY seq', $articleId
00346 );
00347
00348 for ($i=1; !$result->EOF; $i++) {
00349 list($authorId) = $result->fields;
00350 $this->update(
00351 'UPDATE article_authors SET seq = ? WHERE author_id = ?',
00352 array(
00353 $i,
00354 $authorId
00355 )
00356 );
00357
00358 $result->moveNext();
00359 }
00360
00361 $result->close();
00362 unset($result);
00363 }
00364
00369 function getInsertAuthorId() {
00370 return $this->getInsertId('article_authors', 'author_id');
00371 }
00372 }
00373
00374 ?>