ocs  2.3.6
About: OCS (Open Conference System) is a Web publishing tool that will create a complete Web presence for your scholarly conference.
  Fossies Dox: ocs-2.3.6.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

AuthorDAO.inc.php
Go to the documentation of this file.
1 <?php
2 
16 //$Id$
17 
18 import('paper.Author');
19 import('paper.Paper');
20 
21 class AuthorDAO extends DAO {
27  function &getAuthor($authorId) {
28  $result =& $this->retrieve(
29  'SELECT * FROM paper_authors WHERE author_id = ?', $authorId
30  );
31 
32  $returner = null;
33  if ($result->RecordCount() != 0) {
34  $returner =& $this->_returnAuthorFromRow($result->GetRowAssoc(false));
35  }
36 
37  $result->Close();
38  unset($result);
39 
40  return $returner;
41  }
42 
48  function &getAuthorsByPaper($paperId) {
49  $authors = array();
50 
51  $result =& $this->retrieve(
52  'SELECT * FROM paper_authors WHERE paper_id = ? ORDER BY seq',
53  $paperId
54  );
55 
56  while (!$result->EOF) {
57  $authors[] =& $this->_returnAuthorFromRow($result->GetRowAssoc(false));
58  $result->moveNext();
59  }
60 
61  $result->Close();
62  unset($result);
63 
64  return $authors;
65  }
66 
77  function &getPublishedPapersForAuthor($schedConfId, $firstName, $middleName, $lastName, $affiliation, $country) {
78  $publishedPapers = array();
79  $publishedPaperDao =& DAORegistry::getDAO('PublishedPaperDAO');
80  $params = array($firstName, $middleName, $lastName, $affiliation, $country);
81  if ($schedConfId !== null) $params[] = $schedConfId;
82 
83  $result =& $this->retrieve(
84  'SELECT DISTINCT
85  aa.paper_id
86  FROM paper_authors aa
87  LEFT JOIN papers a ON (aa.paper_id = a.paper_id)
88  WHERE aa.first_name = ? AND
89  a.status = ' . STATUS_PUBLISHED . ' AND
90  (aa.middle_name = ?' . (empty($middleName)?' OR aa.middle_name IS NULL':'') . ') AND
91  aa.last_name = ? AND
92  (aa.affiliation = ?' . (empty($affiliation)?' OR aa.affiliation IS NULL':'') . ') AND
93  (aa.country = ?' . (empty($country)?' OR aa.country IS NULL':'') . ')' .
94  ($schedConfId!==null?(' AND a.sched_conf_id = ?'):''),
95  $params
96  );
97 
98  while (!$result->EOF) {
99  $row =& $result->getRowAssoc(false);
100  $publishedPaper =& $publishedPaperDao->getPublishedPaperByPaperId($row['paper_id']);
101  if ($publishedPaper) {
102  $publishedPapers[] =& $publishedPaper;
103  }
104  $result->moveNext();
105  }
106 
107  $result->Close();
108  unset($result);
109 
110  return $publishedPapers;
111  }
112 
123  function &getAuthorsAlphabetizedBySchedConf($schedConfId = null, $initial = null, $rangeInfo = null, $includeEmail = false) {
124  $params = array();
125 
126  if (isset($schedConfId)) $params[] = $schedConfId;
127  if (isset($initial)) {
128  $params[] = String::strtolower($initial) . '%';
129  $initialSql = ' AND LOWER(aa.last_name) LIKE LOWER(?)';
130  } else {
131  $initialSql = '';
132  }
133 
134  $result =& $this->retrieveRange(
135  'SELECT DISTINCT CAST(\'\' AS CHAR) AS url,
136  0 AS author_id,
137  0 AS paper_id,
138  ' . ($includeEmail?'aa.email AS email,':'CAST(\'\' AS CHAR) AS email,') . '
139  0 AS primary_contact,
140  0 AS seq,
141  aa.first_name AS first_name,
142  aa.middle_name AS middle_name,
143  aa.last_name AS last_name,
144  aa.affiliation AS affiliation,
145  aa.country FROM paper_authors aa,
146  papers a,
147  published_papers pa,
148  sched_confs e
149  WHERE e.sched_conf_id = pa.sched_conf_id
150  AND aa.paper_id = a.paper_id
151  ' . (isset($schedConfId)?'AND a.sched_conf_id = ? ':'') . '
152  AND pa.paper_id = a.paper_id
153  AND a.status = ' . STATUS_PUBLISHED . '
154  AND (aa.last_name IS NOT NULL
155  AND aa.last_name <> \'\')' . $initialSql . ' ORDER BY aa.last_name, aa.first_name',
156  empty($params)?false:$params,
157  $rangeInfo
158  );
159 
160  $returner = new DAOResultFactory($result, $this, '_returnAuthorFromRow');
161  return $returner;
162  }
163 
169  function &getAuthorIdsByPaper($paperId) {
170  $authors = array();
171 
172  $result =& $this->retrieve(
173  'SELECT author_id FROM paper_authors WHERE paper_id = ? ORDER BY seq',
174  $paperId
175  );
176 
177  while (!$result->EOF) {
178  $authors[] = $result->fields[0];
179  $result->moveNext();
180  }
181 
182  $result->Close();
183  unset($result);
184 
185  return $authors;
186  }
187 
192  function getLocaleFieldNames() {
193  return array('biography');
194  }
195 
200  function updateLocaleFields(&$author) {
201  $this->updateDataObjectSettings('paper_author_settings', $author, array(
202  'author_id' => $author->getId()
203  ));
204 
205  }
206 
212  function &_returnAuthorFromRow(&$row) {
213  $author = new Author();
214  $author->setId($row['author_id']);
215  $author->setPaperId($row['paper_id']);
216  $author->setFirstName($row['first_name']);
217  $author->setMiddleName($row['middle_name']);
218  $author->setLastName($row['last_name']);
219  $author->setAffiliation($row['affiliation']);
220  $author->setCountry($row['country']);
221  $author->setEmail($row['email']);
222  $author->setUrl($row['url']);
223  $author->setPrimaryContact($row['primary_contact']);
224  $author->setSequence($row['seq']);
225 
226  $this->getDataObjectSettings('paper_author_settings', 'author_id', $row['author_id'], $author);
227 
228  HookRegistry::call('AuthorDAO::_returnAuthorFromRow', array(&$author, &$row));
229 
230  return $author;
231  }
232 
237  function insertAuthor(&$author) {
238  $this->update(
239  'INSERT INTO paper_authors
240  (paper_id, first_name, middle_name, last_name, affiliation, country, email, url, primary_contact, seq)
241  VALUES
242  (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
243  array(
244  $author->getPaperId(),
245  $author->getFirstName(),
246  $author->getMiddleName() . '', // make non-null
247  $author->getLastName(),
248  $author->getAffiliation() . '', // make non-null
249  $author->getCountry(),
250  $author->getEmail(),
251  $author->getUrl(),
252  (int) $author->getPrimaryContact(),
253  (float) $author->getSequence()
254  )
255  );
256 
257  $author->setId($this->getInsertAuthorId());
258  $this->updateLocaleFields($author);
259 
260  return $author->getId();
261  }
262 
267  function updateAuthor(&$author) {
268  $returner = $this->update(
269  'UPDATE paper_authors
270  SET
271  first_name = ?,
272  middle_name = ?,
273  last_name = ?,
274  affiliation = ?,
275  country = ?,
276  email = ?,
277  url = ?,
278  primary_contact = ?,
279  seq = ?
280  WHERE author_id = ?',
281  array(
282  $author->getFirstName(),
283  $author->getMiddleName() . '', // make non-null
284  $author->getLastName(),
285  $author->getAffiliation() . '', // make non-null
286  $author->getCountry(),
287  $author->getEmail(),
288  $author->getUrl(),
289  $author->getPrimaryContact(),
290  $author->getSequence(),
291  $author->getId()
292  )
293  );
294  $this->updateLocaleFields($author);
295  return $returner;
296  }
297 
302  function deleteAuthor(&$author) {
303  return $this->deleteAuthorById($author->getId());
304  }
305 
311  function deleteAuthorById($authorId, $paperId = null) {
312  $params = array($authorId);
313  if ($paperId) $params[] = $paperId;
314  $returner = $this->update(
315  'DELETE FROM paper_authors WHERE author_id = ?' .
316  ($paperId?' AND paper_id = ?':''),
317  $params
318  );
319  if ($returner) $this->update('DELETE FROM paper_author_settings WHERE author_id = ?', array($authorId));
320  }
321 
326  function deleteAuthorsByPaper($paperId) {
327  $authors =& $this->getAuthorsByPaper($paperId);
328  foreach ($authors as $author) {
329  $this->deleteAuthor($author);
330  }
331  }
332 
337  function resequenceAuthors($paperId) {
338  $result =& $this->retrieve(
339  'SELECT author_id FROM paper_authors WHERE paper_id = ? ORDER BY seq', $paperId
340  );
341 
342  for ($i=1; !$result->EOF; $i++) {
343  list($authorId) = $result->fields;
344  $this->update(
345  'UPDATE paper_authors SET seq = ? WHERE author_id = ?',
346  array(
347  $i,
348  $authorId
349  )
350  );
351 
352  $result->moveNext();
353  }
354 
355  $result->close();
356  unset($result);
357  }
358 
363  function getInsertAuthorId() {
364  return $this->getInsertId('paper_authors', 'author_id');
365  }
366 }
367 
368 ?>
deleteAuthorById($authorId, $paperId=null)
config TEMPLATE inc php
Definition: config.inc.php:4
insertAuthor(&$author)
Operations for retrieving and modifying Author objects.
updateAuthor(&$author)
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:62
Paper author metadata class.
Definition: Author.inc.php:21
& getPublishedPapersForAuthor($schedConfId, $firstName, $middleName, $lastName, $affiliation, $country)
getInsertId($table='', $id='', $callHooks=true)
Definition: DAO.inc.php:225
updateDataObjectSettings($tableName, &$dataObject, $idArray)
Definition: DAO.inc.php:412
& _returnAuthorFromRow(&$row)
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:152
& getAuthorsAlphabetizedBySchedConf($schedConfId=null, $initial=null, $rangeInfo=null, $includeEmail=false)
strtolower($string)
Definition: String.inc.php:226
& getAuthorsByPaper($paperId)
updateLocaleFields(&$author)
Wrapper around ADORecordSet providing "factory" features for generating objects from DAOs.
resequenceAuthors($paperId)
& getDAO($name, $dbconn=null)
& getAuthor($authorId)
call($hookName, $args=null)
getDataObjectSettings($tableName, $idFieldName, $idFieldValue, &$dataObject)
Definition: DAO.inc.php:498
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:186
& getAuthorIdsByPaper($paperId)
deleteAuthor(&$author)
const STATUS_PUBLISHED
Definition: Paper.inc.php:27
deleteAuthorsByPaper($paperId)