Open Journal Systems  3.3.0
PKPAuthorDAO.inc.php
1 <?php
2 
17 import('lib.pkp.classes.db.SchemaDAO');
18 import('lib.pkp.classes.submission.PKPAuthor');
19 
20 abstract class PKPAuthorDAO extends SchemaDAO {
22  public $schemaName = SCHEMA_AUTHOR;
23 
25  public $tableName = 'authors';
26 
28  public $settingsTableName = 'author_settings';
29 
31  public $primaryKeyColumn = 'author_id';
32 
35  'id' => 'author_id',
36  'email' => 'email',
37  'includeInBrowse' => 'include_in_browse',
38  'publicationId' => 'publication_id',
39  'seq' => 'seq',
40  'userGroupId' => 'user_group_id',
41  ];
42 
47  function newDataObject() {
48  return new Author();
49  }
50 
55  public function getById($objectId) {
56  $result = $this->retrieve(
57  'SELECT a.*, p.locale AS submission_locale FROM authors a JOIN publications p ON (a.publication_id = p.publication_id) WHERE author_id = ?',
58  (int) $objectId
59  );
60 
61  $returner = null;
62  if ($result->RecordCount() != 0) {
63  $returner = $this->_fromRow($result->GetRowAssoc(false));
64  }
65  $result->Close();
66  return $returner;
67  }
68 
76  function getByPublicationId($publicationId, $sortByAuthorId = false, $useIncludeInBrowse = false) {
77  $authors = array();
78  $params = array((int) $publicationId);
79  if ($useIncludeInBrowse) $params[] = 1;
80 
81  $result = $this->retrieve(
82  'SELECT DISTINCT a.*, ug.show_title, p.locale AS submission_locale
83  FROM authors a
84  JOIN user_groups ug ON (a.user_group_id=ug.user_group_id)
85  JOIN publications p ON (p.publication_id = a.publication_id)
86  LEFT JOIN author_settings au ON (au.author_id = a.author_id)
87  WHERE a.publication_id = ? ' .
88  ($useIncludeInBrowse ? ' AND a.include_in_browse = ?' : '')
89  . ' ORDER BY seq',
90  $params
91  );
92 
93  while (!$result->EOF) {
94  $row = $result->getRowAssoc(false);
95  if ($sortByAuthorId) {
96  $authorId = $row['author_id'];
97  $authors[$authorId] = $this->_fromRow($row);
98  } else {
99  $authors[] = $this->_fromRow($row);
100  }
101  $result->MoveNext();
102  }
103 
104  $result->Close();
105  return $authors;
106  }
107 
114  function changePublicationLocale($publicationId, $oldLocale, $newLocale) {
115  $authors = $this->getByPublicationId($publicationId);
116  foreach ($authors as $author) {
117  if (empty($author->getGivenName($newLocale))) {
118  if (empty($author->getFamilyName($newLocale)) && empty($author->getPreferredPublicName($newLocale))) {
119  // if no name exists for the new locale
120  // copy all names with the old locale to the new locale
121  $author->setGivenName($author->getGivenName($oldLocale), $newLocale);
122  $author->setFamilyName($author->getFamilyName($oldLocale), $newLocale);
123  $author->setPreferredPublicName($author->getPreferredPublicName($oldLocale), $newLocale);
124  } else {
125  // if the given name does not exist, but one of the other names do exist
126  // copy only the given name with the old locale to the new locale, because the given name is required
127  $author->setGivenName($author->getGivenName($oldLocale), $newLocale);
128  }
129  $this->updateObject($author);
130  }
131  }
132  }
133 
134 
138  public function _fromRow($primaryRow) {
139  $author = parent::_fromRow($primaryRow);
140  $author->setSubmissionLocale($primaryRow['submission_locale']);
141  return $author;
142  }
143 
148  function getInsertId() {
149  return $this->_getInsertId('authors', 'author_id');
150  }
151 
156  function deleteBySubmissionId($submissionId) {
157  $submissionDao = DAORegistry::getDAO('SubmissionDAO');
158  $submission = $submissionDao->getById($submissionId);
159  if ($submission) foreach ($submission->getData('publications') as $publication) {
160  $authors = $this->getByPublicationId($publication->getId());
161  foreach ($authors as $author) {
162  $this->deleteObject($author);
163  }
164  }
165  }
166 }
PKPAuthorDAO\$settingsTableName
$settingsTableName
Definition: PKPAuthorDAO.inc.php:28
SchemaDAO\updateObject
updateObject($object)
Definition: SchemaDAO.inc.php:145
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
PKPAuthorDAO\_fromRow
_fromRow($primaryRow)
Definition: PKPAuthorDAO.inc.php:138
PKPAuthorDAO\changePublicationLocale
changePublicationLocale($publicationId, $oldLocale, $newLocale)
Definition: PKPAuthorDAO.inc.php:114
DAO\retrieve
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:85
Author
Article author metadata class.
Definition: Author.inc.php:20
PKPAuthorDAO\$tableName
$tableName
Definition: PKPAuthorDAO.inc.php:25
PKPAuthorDAO\$schemaName
$schemaName
Definition: PKPAuthorDAO.inc.php:22
PKPAuthorDAO\getInsertId
getInsertId()
Definition: PKPAuthorDAO.inc.php:148
PKPAuthorDAO\$primaryTableColumns
$primaryTableColumns
Definition: PKPAuthorDAO.inc.php:34
PKPAuthorDAO\getByPublicationId
getByPublicationId($publicationId, $sortByAuthorId=false, $useIncludeInBrowse=false)
Definition: PKPAuthorDAO.inc.php:76
DAO\_getInsertId
_getInsertId($table='', $id='')
Definition: DAO.inc.php:255
PKPAuthorDAO\getById
getById($objectId)
Definition: PKPAuthorDAO.inc.php:55
SchemaDAO\deleteObject
deleteObject($object)
Definition: SchemaDAO.inc.php:214
PKPAuthorDAO\newDataObject
newDataObject()
Definition: PKPAuthorDAO.inc.php:47
PKPAuthorDAO\deleteBySubmissionId
deleteBySubmissionId($submissionId)
Definition: PKPAuthorDAO.inc.php:156
SchemaDAO
A base class for DAOs which rely on a json-schema file to define the data object.
Definition: SchemaDAO.inc.php:18
PKPAuthorDAO\$primaryKeyColumn
$primaryKeyColumn
Definition: PKPAuthorDAO.inc.php:31