Open Journal Systems  2.4.3
 All Classes Namespaces Functions Variables Groups Pages
PKPAuthorDAO.inc.php
1 <?php
2 
18 import('lib.pkp.classes.submission.PKPAuthor');
19 
20 class PKPAuthorDAO extends DAO {
24  function PKPAuthorDAO() {
25  parent::DAO();
26  }
27 
34  function &getAuthor($authorId, $submissionId = null) {
35  $params = array((int) $authorId);
36  if ($submissionId !== null) $params[] = (int) $submissionId;
37  $result =& $this->retrieve(
38  'SELECT * FROM authors WHERE author_id = ?'
39  . ($submissionId !== null?' AND submission_id = ?':''),
40  $params
41  );
42 
43  $returner = null;
44  if ($result->RecordCount() != 0) {
45  $returner =& $this->_returnAuthorFromRow($result->GetRowAssoc(false));
46  }
47 
48  $result->Close();
49  unset($result);
50 
51  return $returner;
52  }
53 
60  function &getAuthorsBySubmissionId($submissionId, $sortByAuthorId = false) {
61  $authors = array();
62 
63  $result =& $this->retrieve(
64  'SELECT * FROM authors WHERE submission_id = ? ORDER BY seq',
65  (int) $submissionId
66  );
67 
68  while (!$result->EOF) {
69  $row =& $result->getRowAssoc(false);
70  if ($sortByAuthorId) {
71  $authorId = $row['author_id'];
72  $authors[$authorId] =& $this->_returnAuthorFromRow($row);
73  } else {
74  $authors[] =& $this->_returnAuthorFromRow($row);
75  }
76  unset($row);
77  $result->MoveNext();
78  }
79 
80  $result->Close();
81  unset($result);
82 
83  return $authors;
84  }
85 
91  function getAuthorCountBySubmissionId($submissionId) {
92  $result =& $this->retrieve(
93  'SELECT count(*) FROM authors WHERE submission_id = ?',
94  (int) $submissionId
95  );
96 
97  $returner = $result->fields[0];
98 
99  $result->Close();
100  unset($result);
101 
102  return $returner;
103  }
104 
109  function updateLocaleFields(&$author) {
111  'author_settings',
112  $author,
113  array(
114  'author_id' => $author->getId()
115  )
116  );
117  }
118 
124  function &_returnAuthorFromRow(&$row) {
125  $author = $this->newDataObject();
126  $author->setId($row['author_id']);
127  $author->setSubmissionId($row['submission_id']);
128  $author->setFirstName($row['first_name']);
129  $author->setMiddleName($row['middle_name']);
130  $author->setLastName($row['last_name']);
131  $author->setSuffix($row['suffix']);
132  $author->setCountry($row['country']);
133  $author->setEmail($row['email']);
134  $author->setUrl($row['url']);
135  $author->setUserGroupId($row['user_group_id']);
136  $author->setPrimaryContact($row['primary_contact']);
137  $author->setSequence($row['seq']);
138 
139  $this->getDataObjectSettings('author_settings', 'author_id', $row['author_id'], $author);
140 
141  HookRegistry::call('AuthorDAO::_returnAuthorFromRow', array(&$author, &$row));
142  return $author;
143  }
144 
151  function &_returnSimpleAuthorFromRow(&$row) {
152  $author = $this->newDataObject();
153  $author->setId($row['author_id']);
154  $author->setSubmissionId($row['submission_id']);
155  $author->setFirstName($row['first_name']);
156  $author->setMiddleName($row['middle_name']);
157  $author->setLastName($row['last_name']);
158  $author->setSuffix($row['suffix']);
159  $author->setCountry($row['country']);
160  $author->setEmail($row['email']);
161  $author->setUrl($row['url']);
162  $author->setUserGroupId($row['user_group_id']);
163  $author->setPrimaryContact($row['primary_contact']);
164  $author->setSequence($row['seq']);
165 
166  $author->setAffiliation($row['affiliation_l'], $row['locale']);
167  $author->setAffiliation($row['affiliation_pl'], $row['primary_locale']);
168 
169  HookRegistry::call('AuthorDAO::_returnSimpleAuthorFromRow', array(&$author, &$row));
170  return $author;
171  }
172 
177  function newDataObject() {
178  assert(false); // Should be overridden by child classes
179  }
180 
185  function getLocaleFieldNames() {
186  return array('biography', 'competingInterests', 'affiliation');
187  }
188 
193  function deleteAuthor(&$author) {
194  return $this->deleteAuthorById($author->getId());
195  }
196 
202  function deleteAuthorById($authorId, $submissionId = null) {
203  $params = array((int) $authorId);
204  if ($submissionId) $params[] = (int) $submissionId;
205  $returner = $this->update(
206  'DELETE FROM authors WHERE author_id = ?' .
207  ($submissionId?' AND submission_id = ?':''),
208  $params
209  );
210  if ($returner) $this->update('DELETE FROM author_settings WHERE author_id = ?', array((int) $authorId));
211 
212  return $returner;
213  }
214 
219  function resequenceAuthors($submissionId) {
220  $result =& $this->retrieve(
221  'SELECT author_id FROM authors WHERE submission_id = ? ORDER BY seq',
222  (int) $submissionId
223  );
224 
225  for ($i=1; !$result->EOF; $i++) {
226  list($authorId) = $result->fields;
227  $this->update(
228  'UPDATE authors SET seq = ? WHERE author_id = ?',
229  array(
230  $i,
231  $authorId
232  )
233  );
234 
235  $result->MoveNext();
236  }
237 
238  $result->Close();
239  unset($result);
240  }
241 
247  function &getPrimaryContact($submissionId) {
248  $result =& $this->retrieve(
249  'SELECT * FROM authors WHERE submission_id = ? AND primary_contact = 1',
250  (int) $submissionId
251  );
252 
253  $returner = null;
254  if ($result->RecordCount() != 0) {
255  $returner = $this->_returnAuthorFromRow($result->GetRowAssoc(false));
256  }
257  $result->Close();
258  return $returner;
259  }
260 
266  function resetPrimaryContact($authorId, $submissionId) {
267  $this->update(
268  'UPDATE authors SET primary_contact = 0 WHERE primary_contact = 1 AND submission_id = ?',
269  (int) $submissionId
270  );
271  $this->update(
272  'UPDATE authors SET primary_contact = 1 WHERE author_id = ? AND submission_id = ?',
273  array((int) $authorId, (int) $submissionId)
274  );
275  }
276 
281  function getInsertAuthorId() {
282  return $this->getInsertId('authors', 'author_id');
283  }
284 }
285 
286 ?>
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:29
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:83
getInsertId($table= '', $id= '', $callHooks=true)
Definition: DAO.inc.php:252
resequenceAuthors($submissionId)
& getAuthor($authorId, $submissionId=null)
Operations for retrieving and modifying PKPAuthor objects.
updateDataObjectSettings($tableName, &$dataObject, $idArray)
Definition: DAO.inc.php:460
updateLocaleFields(&$author)
resetPrimaryContact($authorId, $submissionId)
& _returnSimpleAuthorFromRow(&$row)
& _returnAuthorFromRow(&$row)
deleteAuthorById($authorId, $submissionId=null)
call($hookName, $args=null)
getAuthorCountBySubmissionId($submissionId)
& getAuthorsBySubmissionId($submissionId, $sortByAuthorId=false)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:211
& getPrimaryContact($submissionId)
deleteAuthor(&$author)