Open Monograph Press  3.3.0
ChapterAuthorDAO.inc.php
1 <?php
2 
20 import('classes.monograph.Chapter');
21 import('classes.monograph.ChapterAuthor');
22 
23 class ChapterAuthorDAO extends DAO {
30  function getAuthors($publicationId = null, $chapterId = null) {
31  $params = array();
32  if (isset($publicationId)) $params[] = (int) $publicationId;
33  if (isset($chapterId)) $params[] = (int) $chapterId;
34  // get all the monograph_author fields,
35  // but replace the primary_contact and seq with submission_chapter_authors.primary_contact
36 
37  $sql = 'SELECT a.*,
38  sca.chapter_id,
39  sca.primary_contact,
40  sca.seq,
41  ug.show_title,
42  p.locale AS submission_locale
43  FROM authors a
44  JOIN publications p ON (p.publication_id = a.publication_id)
45  JOIN submission_chapter_authors sca ON (a.author_id = sca.author_id)
46  JOIN user_groups ug ON (a.user_group_id = ug.user_group_id)' .
47  ( (count($params)> 0)?' WHERE':'' ) .
48  ( isset($publicationId)?' a.publication_id = ?':'' ) .
49  ( (isset($publicationId) && isset($chapterId))?' AND':'' ) .
50  ( isset($chapterId)?' sca.chapter_id = ?':'' ) .
51  ' ORDER BY sca.chapter_id, sca.seq';
52 
53  $result = $this->retrieve($sql, $params);
54  return new DAOResultFactory($result, $this, '_fromRow', array('id'));
55  }
56 
62  function getAuthorIdsByChapterId($chapterId) {
63 
64  $result = $this->retrieve(
65  'SELECT author_id
66  FROM submission_chapter_authors
67  WHERE chapter_id = ?',
68  [(int) $chapterId]
69  );
70 
71  $authorIds = array();
72  while (!$result->EOF) {
73  $authorIds[] = $result->fields[0];
74  $result->MoveNext();
75  }
76 
77  $result->Close();
78  unset($result);
79 
80  return $authorIds;
81  }
82 
89  function insertChapterAuthor($authorId, $chapterId, $isPrimary = false, $sequence = 0) {
90  //FIXME: How to handle sequence?
91  $this->update(
92  'INSERT INTO submission_chapter_authors
93  (author_id, chapter_id, primary_contact, seq)
94  VALUES
95  (?, ?, ?, ?)',
96  array(
97  (int) $authorId,
98  (int) $chapterId,
99  (int) $isPrimary,
100  (int) $sequence
101  )
102  );
103  }
104 
109  function deleteChapterAuthorById($authorId, $chapterId = null) {
110  $params = array((int) $authorId);
111  if ($chapterId) $params[] = (int) $chapterId;
112 
113  $this->update(
114  'DELETE FROM submission_chapter_authors WHERE author_id = ?' .
115  ($chapterId?' AND chapter_id = ?':''),
116  $params
117  );
118  }
119 
124  function deleteChapterAuthorsByChapterId($chapterId) {
125  $this->update(
126  'DELETE FROM submission_chapter_authors WHERE chapter_id = ?',
127  [(int) $chapterId]
128  );
129  }
130 
135  function newDataObject() {
136  return new ChapterAuthor();
137  }
138 
144  function _fromRow($row) {
145  // Start with an Author object and copy the common elements
146  $authorDao = DAORegistry::getDAO('AuthorDAO'); /* @var $authorDao AuthorDAO */
147  $author = $authorDao->_fromRow($row);
148 
149  $chapterAuthor = $this->newDataObject();
150  $chapterAuthor->setId((int) $author->getId());
151  $chapterAuthor->setGivenName($author->getGivenName(null), null);
152  $chapterAuthor->setFamilyName($author->getFamilyName(null), null);
153  $chapterAuthor->setAffiliation($author->getAffiliation(null), null);
154  $chapterAuthor->setCountry($author->getCountry());
155  $chapterAuthor->setEmail($author->getEmail());
156  $chapterAuthor->setUrl($author->getUrl());
157  $chapterAuthor->setUserGroupId($author->getUserGroupId());
158 
159  // Add additional data that is chapter author specific
160  $chapterAuthor->setPrimaryContact($row['primary_contact']);
161  $chapterAuthor->setSequence((int) $row['seq']); ;
162  $chapterAuthor->setChapterId((int) $row['chapter_id']);
163 
164  return $chapterAuthor;
165  }
166 }
167 
168 
ChapterAuthorDAO\_fromRow
_fromRow($row)
Definition: ChapterAuthorDAO.inc.php:144
ChapterAuthorDAO
Definition: ChapterAuthorDAO.inc.php:23
ChapterAuthorDAO\newDataObject
newDataObject()
Definition: ChapterAuthorDAO.inc.php:135
DAOResultFactory
Wrapper around ADORecordSet providing "factory" features for generating objects from DAOs.
Definition: DAOResultFactory.inc.php:21
ChapterAuthorDAO\getAuthors
getAuthors($publicationId=null, $chapterId=null)
Definition: ChapterAuthorDAO.inc.php:30
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
DAO\retrieve
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:85
ChapterAuthorDAO\insertChapterAuthor
insertChapterAuthor($authorId, $chapterId, $isPrimary=false, $sequence=0)
Definition: ChapterAuthorDAO.inc.php:89
ChapterAuthorDAO\deleteChapterAuthorById
deleteChapterAuthorById($authorId, $chapterId=null)
Definition: ChapterAuthorDAO.inc.php:109
DAO\update
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:214
ChapterAuthor
Adds chapterId to an Author.
Definition: ChapterAuthor.inc.php:20
ChapterAuthorDAO\getAuthorIdsByChapterId
getAuthorIdsByChapterId($chapterId)
Definition: ChapterAuthorDAO.inc.php:62
DAO
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:31
ChapterAuthorDAO\deleteChapterAuthorsByChapterId
deleteChapterAuthorsByChapterId($chapterId)
Definition: ChapterAuthorDAO.inc.php:124