Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
PublicationDateDAO.inc.php
1 <?php
2 
17 import('classes.publicationFormat.PublicationDate');
18 
19 class PublicationDateDAO extends DAO {
23  function PublicationDateDAO() {
24  parent::DAO();
25  }
26 
33  function getById($publicationDateId, $monographId = null){
34  $sqlParams = array((int) $publicationDateId);
35  if ($monographId) {
36  $sqlParams[] = (int) $monographId;
37  }
38 
39  $result = $this->retrieve(
40  'SELECT p.*
41  FROM publication_dates p
42  JOIN publication_formats pf ON (p.publication_format_id = pf.publication_format_id)
43  WHERE p.publication_date_id = ?
44  ' . ($monographId?' AND pf.submission_id = ?':''),
45  $sqlParams
46  );
47 
48  $returner = null;
49  if ($result->RecordCount() != 0) {
50  $returner = $this->_fromRow($result->GetRowAssoc(false));
51  }
52  $result->Close();
53  return $returner;
54  }
55 
61  function getByPublicationFormatId($publicationFormatId) {
62  $result = $this->retrieveRange(
63  'SELECT * FROM publication_dates WHERE publication_format_id = ?',
64  (int) $publicationFormatId
65  );
66 
67  return new DAOResultFactory($result, $this, '_fromRow');
68  }
69 
74  function newDataObject() {
75  return new PublicationDate();
76  }
77 
84  function _fromRow($row, $callHooks = true) {
85  $publicationDate = $this->newDataObject();
86  $publicationDate->setId($row['publication_date_id']);
87  $publicationDate->setRole($row['role']);
88  $publicationDate->setDateFormat($row['date_format']);
89  $publicationDate->setDate($row['date']);
90  $publicationDate->setPublicationFormatId($row['publication_format_id']);
91 
92  if ($callHooks) HookRegistry::call('PublicationDateDAO::_fromRow', array(&$publicationDate, &$row));
93 
94  return $publicationDate;
95  }
96 
101  function insertObject($publicationDate) {
102  $this->update(
103  'INSERT INTO publication_dates
104  (publication_format_id, role, date_format, date)
105  VALUES
106  (?, ?, ?, ?)',
107  array(
108  (int) $publicationDate->getPublicationFormatId(),
109  $publicationDate->getRole(),
110  $publicationDate->getDateFormat(),
111  $publicationDate->getDate()
112  )
113  );
114 
115  $publicationDate->setId($this->getInsertId());
116  return $publicationDate->getId();
117  }
118 
123  function updateObject($publicationDate) {
124  $this->update(
125  'UPDATE publication_dates
126  SET role = ?, date_format =?, date = ?
127  WHERE publication_date_id = ?',
128  array(
129  $publicationDate->getRole(),
130  $publicationDate->getDateFormat(),
131  $publicationDate->getDate(),
132  (int) $publicationDate->getId()
133  )
134  );
135  }
136 
141  function deleteObject($publicationDate) {
142  return $this->deleteById($publicationDate->getId());
143  }
144 
149  function deleteById($entryId) {
150  return $this->update(
151  'DELETE FROM publication_dates WHERE publication_date_id = ?', array((int) $entryId)
152  );
153  }
154 
159  function getInsertId() {
160  return $this->_getInsertId('publication_dates', 'publication_date_id');
161  }
162 }
163 
164 ?>
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
updateObject($publicationDate)
insertObject($publicationDate)
deleteObject($publicationDate)
_fromRow($row, $callHooks=true)
Operations for retrieving and modifying PublicationDate objects.
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:174
_getInsertId($table= '', $id= '')
Definition: DAO.inc.php:249
getById($publicationDateId, $monographId=null)
static call($hookName, $args=null)
getByPublicationFormatId($publicationFormatId)
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
Basic class describing a publication date for a format (used on the ONIX templates for publication fo...
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208