Open Journal Systems  2.4.4
 All Classes Namespaces Functions Variables Groups Pages
BookForReviewAuthorDAO.inc.php
1 <?php
2 
17 class BookForReviewAuthorDAO extends DAO {
19  var $parentPluginName;
20 
24  function BookForReviewAuthorDAO($parentPluginName){
25  $this->parentPluginName = $parentPluginName;
26  parent::DAO();
27  }
28 
34  function &getAuthor($authorId) {
35  $result =& $this->retrieve(
36  'SELECT * FROM books_for_review_authors WHERE author_id = ?', $authorId
37  );
38 
39  $returner = null;
40  if ($result->RecordCount() != 0) {
41  $returner =& $this->_returnAuthorFromRow($result->GetRowAssoc(false));
42  }
43 
44  $result->Close();
45  unset($result);
46 
47  return $returner;
48  }
49 
55  function &getAuthorsByBookForReview($bookId) {
56  $authors = array();
57 
58  $result =& $this->retrieve(
59  'SELECT * FROM books_for_review_authors WHERE book_id = ? ORDER BY seq',
60  $bookId
61  );
62 
63  while (!$result->EOF) {
64  $authors[] =& $this->_returnAuthorFromRow($result->GetRowAssoc(false));
65  $result->moveNext();
66  }
67 
68  $result->Close();
69  unset($result);
70 
71  return $authors;
72  }
73 
79  function &getAuthorIdsByBookForReview($bookId) {
80  $authors = array();
81 
82  $result =& $this->retrieve(
83  'SELECT author_id FROM books_for_review_authors WHERE book_id = ? ORDER BY seq',
84  $articleId
85  );
86 
87  while (!$result->EOF) {
88  $authors[] = $result->fields[0];
89  $result->moveNext();
90  }
91 
92  $result->Close();
93  unset($result);
94 
95  return $authors;
96  }
97 
103  function &_returnAuthorFromRow(&$row) {
104  $bfrPlugin =& PluginRegistry::getPlugin('generic', $this->parentPluginName);
105  $bfrPlugin->import('classes.BookForReviewAuthor');
106 
107  $author = new BookForReviewAuthor();
108  $author->setId($row['author_id']);
109  $author->setBookId($row['book_id']);
110  $author->setFirstName($row['first_name']);
111  $author->setMiddleName($row['middle_name']);
112  $author->setLastName($row['last_name']);
113  $author->setSequence($row['seq']);
114 
115  HookRegistry::call('BookForReviewAuthorDAO::_returnAuthorFromRow', array(&$author, &$row));
116 
117  return $author;
118  }
119 
124  function insertAuthor(&$author) {
125  $this->update(
126  'INSERT INTO books_for_review_authors
127  (book_id, first_name, middle_name, last_name, seq)
128  VALUES
129  (?, ?, ?, ?, ?)',
130  array(
131  $author->getBookId(),
132  $author->getFirstName(),
133  $author->getMiddleName() . '', // make non-null
134  $author->getLastName(),
135  $author->getSequence()
136  )
137  );
138 
139  $author->setId($this->getInsertAuthorId());
140  return $author->getId();
141  }
142 
147  function updateAuthor(&$author) {
148  $returner = $this->update(
149  'UPDATE books_for_review_authors
150  SET
151  first_name = ?,
152  middle_name = ?,
153  last_name = ?,
154  seq = ?
155  WHERE author_id = ?',
156  array(
157  $author->getFirstName(),
158  $author->getMiddleName() . '', // make non-null
159  $author->getLastName(),
160  $author->getSequence(),
161  $author->getId()
162  )
163  );
164  return $returner;
165  }
166 
171  function deleteAuthor(&$author) {
172  return $this->deleteAuthorById($author->getId());
173  }
174 
180  function deleteAuthorById($authorId, $bookId = null) {
181  $params = array($authorId);
182  if ($bookId) $params[] = $bookId;
183  $returner = $this->update(
184  'DELETE FROM books_for_review_authors WHERE author_id = ?' .
185  ($bookId?' AND book_id = ?':''),
186  $params
187  );
188  }
189 
194  function deleteAuthorsByBookForReview($bookId) {
195  $authors =& $this->getAuthorsByBookForReview($bookId);
196  foreach ($authors as $author) {
197  $this->deleteAuthor($author);
198  }
199  }
200 
205  function resequenceAuthors($bookId) {
206  $result =& $this->retrieve(
207  'SELECT author_id FROM books_for_review_authors WHERE book_id = ? ORDER BY seq', $bookId
208  );
209 
210  for ($i=1; !$result->EOF; $i++) {
211  list($authorId) = $result->fields;
212  $this->update(
213  'UPDATE books_for_review_authors SET seq = ? WHERE author_id = ?',
214  array(
215  $i,
216  $authorId
217  )
218  );
219 
220  $result->moveNext();
221  }
222 
223  $result->close();
224  unset($result);
225  }
226 
231  function getInsertAuthorId() {
232  return $this->getInsertId('books_for_review_authors', 'author_id');
233  }
234 }
235 
236 ?>
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:29
& getPlugin($category, $name)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:83
getInsertId($table= '', $id= '', $callHooks=true)
Definition: DAO.inc.php:252
BookForReviewAuthorDAO($parentPluginName)
deleteAuthorById($authorId, $bookId=null)
call($hookName, $args=null)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:211
Book for review author metadata class.
Operations for retrieving and modifying BookForReviewAuthor objects.