• Main Page
  • Modules
  • Classes
  • Files
  • File List

classes/monograph/ChapterDAO.inc.php

00001 <?php
00002 
00017 import('classes.monograph.Chapter');
00018 import('classes.monograph.ChapterAuthor');
00019 
00020 class ChapterDAO extends DAO {
00024    function ChapterDAO() {
00025       parent::DAO();
00026    }
00027 
00035    function &getChapter($chapterId, $monographId = null) {
00036       $params = array((int) $chapterId);
00037       if ($monographId !== null) {
00038          $params[] = (int) $monographId;
00039       }
00040 
00041       $result =& $this->retrieve(
00042          'SELECT * FROM monograph_chapters WHERE chapter_id = ?' . ($monographId !== null?' AND monograph_id = ? ':''),
00043          $params
00044       );
00045 
00046       $returner = null;
00047       if ($result->RecordCount() != 0) {
00048          $returner =& $this->_returnFromRow($result->GetRowAssoc(false));
00049       }
00050       $result->Close();
00051       unset($result);
00052       return $returner;
00053    }
00054 
00061    function &getChapters($monographId, $rangeInfo = null) {
00062       $result =& $this->retrieveRange(
00063          'SELECT chapter_id, monograph_id, chapter_seq FROM monograph_chapters WHERE monograph_id = ? ORDER BY chapter_seq',
00064          (int) $monographId,
00065          $rangeInfo
00066       );
00067 
00068       $returner = new DAOResultFactory($result, $this, '_returnFromRow', array('id'));
00069       return $returner;
00070    }
00071 
00076    function getLocaleFieldNames() {
00077       return array('title', 'subtitle');
00078    }
00079 
00084    function newDataObject() {
00085       return new Chapter();
00086    }
00087 
00093    function &_returnFromRow(&$row) {
00094       $chapter = $this->newDataObject();
00095       $chapter->setId($row['chapter_id']);
00096       $chapter->setMonographId($row['monograph_id']);
00097       $chapter->setSequence($row['chapter_seq']);
00098       $this->getDataObjectSettings('monograph_chapter_settings', 'chapter_id', $row['chapter_id'], $chapter);
00099 
00100       HookRegistry::call('ChapterDAO::_returnFromRow', array(&$chapter, &$row));
00101 
00102       return $chapter;
00103    }
00104 
00109    function updateLocaleFields(&$chapter) {
00110       $this->updateDataObjectSettings('monograph_chapter_settings', $chapter, array(
00111          'chapter_id' => $chapter->getId()
00112       ));
00113    }
00114 
00119    function insertChapter(&$chapter) {
00120       $this->update(
00121          'INSERT INTO monograph_chapters
00122             (monograph_id, chapter_seq)
00123             VALUES
00124             (?, ?)',
00125          array(
00126             (int) $chapter->getMonographId(),
00127             (int) $chapter->getSequence()
00128          )
00129       );
00130 
00131       $chapter->setId($this->getInsertChapterId());
00132       $this->updateLocaleFields($chapter);
00133       return $chapter->getId();
00134    }
00135 
00140    function updateObject(&$chapter) {
00141       $returner = $this->update(
00142          'UPDATE monograph_chapters
00143             SET   monograph_id = ?,
00144                chapter_seq = ?
00145             WHERE
00146                chapter_id = ?',
00147          array(
00148             (int) $chapter->getMonographId(),
00149             (int) $chapter->getSequence(),
00150             (int) $chapter->getId()
00151          )
00152       );
00153       $this->updateLocaleFields($chapter);
00154       return $returner;
00155    }
00156 
00161    function deleteObject(&$chapter) {
00162       return $this->deleteById($chapter->getId());
00163    }
00164 
00169    function deleteById($chapterId) {
00170       $returner1 = $this->update('DELETE FROM monograph_chapter_authors WHERE chapter_id = ?', (int) $chapterId);
00171       $returner2 = $this->update('DELETE FROM monograph_chapter_settings WHERE chapter_id = ?', (int) $chapterId);
00172       $returner3 = $this->update('DELETE FROM monograph_chapters WHERE chapter_id = ?', (int) $chapterId);
00173       return ($returner1 && $returner2 && $returner3);
00174    }
00175 
00181    function deleteByMonographId($monographId) {
00182       $chapters =& $this->getChapters($monographId);
00183       while ($chapter =& $chapters->next()) {
00184          $this->deleteObject($chapter);
00185          unset($chapter);
00186       }
00187    }
00188 
00193    function resequenceChapters($monographId = null) {
00194       $result =& $this->retrieve(
00195          'SELECT chapter_id FROM monograph_chapters' .
00196          ($monographId !== null?' WHERE monograph_id = ?':'') .
00197          ' ORDER BY seq',
00198          ($monographId !== null)?(int) $monographId:null
00199       );
00200 
00201       for ($i=1; !$result->EOF; $i++) {
00202          list($chapterId) = $result->fields;
00203          $this->update(
00204             'UPDATE monograph_chapters SET chapter_seq = ? WHERE chapter_id = ?',
00205             array(
00206                (int) $i,
00207                (int) $chapterId
00208             )
00209          );
00210 
00211          $result->MoveNext();
00212       }
00213 
00214       $result->Close();
00215       unset($result);
00216    }
00217 
00222    function getInsertChapterId() {
00223       return $this->getInsertId('chapters', 'chapter_id');
00224    }
00225 }
00226 
00227 ?>

Generated on Mon Sep 17 2012 13:58:55 for Open Monograph Press by  doxygen 1.7.1