Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
ChapterDAO.inc.php
1 <?php
2 
18 import('classes.monograph.Chapter');
19 import('classes.monograph.ChapterAuthor');
20 
21 class ChapterDAO extends DAO {
25  function ChapterDAO() {
26  parent::DAO();
27  }
28 
36  function getChapter($chapterId, $monographId = null) {
37  $params = array((int) $chapterId);
38  if ($monographId !== null) {
39  $params[] = (int) $monographId;
40  }
41 
42  $result = $this->retrieve(
43  'SELECT * FROM submission_chapters WHERE chapter_id = ?' . ($monographId !== null?' AND submission_id = ? ':''),
44  $params
45  );
46 
47  $returner = null;
48  if ($result->RecordCount() != 0) {
49  $returner = $this->_returnFromRow($result->GetRowAssoc(false));
50  }
51  $result->Close();
52  return $returner;
53  }
54 
61  function getChapters($monographId, $rangeInfo = null) {
62  $result = $this->retrieveRange(
63  'SELECT chapter_id, submission_id, chapter_seq FROM submission_chapters WHERE submission_id = ? ORDER BY chapter_seq',
64  (int) $monographId,
65  $rangeInfo
66  );
67 
68  return new DAOResultFactory($result, $this, '_returnFromRow', array('id'));
69  }
70 
75  function getLocaleFieldNames() {
76  return array('title', 'subtitle');
77  }
78 
83  function newDataObject() {
84  return new Chapter();
85  }
86 
92  function _returnFromRow($row) {
93  $chapter = $this->newDataObject();
94  $chapter->setId($row['chapter_id']);
95  $chapter->setMonographId($row['submission_id']);
96  $chapter->setSequence($row['chapter_seq']);
97  $this->getDataObjectSettings('submission_chapter_settings', 'chapter_id', $row['chapter_id'], $chapter);
98 
99  HookRegistry::call('ChapterDAO::_returnFromRow', array(&$chapter, &$row));
100 
101  return $chapter;
102  }
103 
108  function updateLocaleFields($chapter) {
109  $this->updateDataObjectSettings('submission_chapter_settings', $chapter, array(
110  'chapter_id' => $chapter->getId()
111  ));
112  }
113 
118  function insertChapter($chapter) {
119  $this->update(
120  'INSERT INTO submission_chapters
121  (submission_id, chapter_seq)
122  VALUES
123  (?, ?)',
124  array(
125  (int) $chapter->getMonographId(),
126  (int) $chapter->getSequence()
127  )
128  );
129 
130  $chapter->setId($this->getInsertId());
131  $this->updateLocaleFields($chapter);
132  return $chapter->getId();
133  }
134 
139  function updateObject($chapter) {
140  $this->update(
141  'UPDATE submission_chapters
142  SET submission_id = ?,
143  chapter_seq = ?
144  WHERE
145  chapter_id = ?',
146  array(
147  (int) $chapter->getMonographId(),
148  (int) $chapter->getSequence(),
149  (int) $chapter->getId()
150  )
151  );
152  $this->updateLocaleFields($chapter);
153  }
154 
159  function deleteObject($chapter) {
160  $this->deleteById($chapter->getId());
161  }
162 
167  function deleteById($chapterId) {
168  $this->update('DELETE FROM submission_chapter_authors WHERE chapter_id = ?', (int) $chapterId);
169  $this->update('DELETE FROM submission_chapter_settings WHERE chapter_id = ?', (int) $chapterId);
170  $this->update('DELETE FROM submission_chapters WHERE chapter_id = ?', (int) $chapterId);
171  }
172 
178  function deleteByMonographId($monographId) {
179  $chapters = $this->getChapters($monographId);
180  while ($chapter = $chapters->next()) {
181  $this->deleteObject($chapter);
182  }
183  }
184 
189  function resequenceChapters($monographId = null) {
190  $result = $this->retrieve(
191  'SELECT chapter_id FROM submission_chapters' .
192  ($monographId !== null?' WHERE submission_id = ?':'') .
193  ' ORDER BY seq',
194  ($monographId !== null)?(int) $monographId:null
195  );
196 
197  for ($i=1; !$result->EOF; $i++) {
198  list($chapterId) = $result->fields;
199  $this->update(
200  'UPDATE submission_chapters SET chapter_seq = ? WHERE chapter_id = ?',
201  array(
202  (int) $i,
203  (int) $chapterId
204  )
205  );
206 
207  $result->MoveNext();
208  }
209 
210  $result->Close();
211  }
212 
217  function getInsertId() {
218  return $this->_getInsertId('submission_chapters', 'chapter_id');
219  }
220 }
221 
222 ?>
updateLocaleFields($chapter)
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
resequenceChapters($monographId=null)
updateObject($chapter)
updateDataObjectSettings($tableName, &$dataObject, $idArray)
Definition: DAO.inc.php:457
deleteByMonographId($monographId)
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:174
deleteObject($chapter)
_getInsertId($table= '', $id= '')
Definition: DAO.inc.php:249
static call($hookName, $args=null)
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
getChapter($chapterId, $monographId=null)
deleteById($chapterId)
insertChapter($chapter)
_returnFromRow($row)
Describes a monograph chapter (or section)
Definition: Chapter.inc.php:17
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208
getChapters($monographId, $rangeInfo=null)
Operations for retrieving and modifying ChapterAuthor objects.