Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
SalesRightsDAO.inc.php
1 <?php
2 
17 import('classes.publicationFormat.SalesRights');
18 
19 class SalesRightsDAO extends DAO {
23  function SalesRightsDAO() {
24  parent::DAO();
25  }
26 
33  function getById($salesRightsId, $monographId = null){
34  $sqlParams = array((int) $salesRightsId);
35  if ($monographId) {
36  $sqlParams[] = (int) $monographId;
37  }
38 
39  $result = $this->retrieve(
40  'SELECT s.*
41  FROM sales_rights s
42  JOIN publication_formats pf ON (s.publication_format_id = pf.publication_format_id)
43  WHERE s.sales_rights_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 sales_rights WHERE publication_format_id = ?', (int) $publicationFormatId);
64 
65  return new DAOResultFactory($result, $this, '_fromRow');
66  }
67 
73  function getROWByPublicationFormatId($publicationFormatId) {
74  $result = $this->retrieve(
75  'SELECT * FROM sales_rights WHERE row_setting = ? AND publication_format_id = ?',
76  array(1, (int) $publicationFormatId)
77  );
78 
79  $returner = null;
80  if ($result->RecordCount() != 0) {
81  $returner = $this->_fromRow($result->GetRowAssoc(false));
82  }
83  $result->Close();
84  return $returner;
85  }
86 
91  function newDataObject() {
92  return new SalesRights();
93  }
94 
101  function _fromRow($row, $callHooks = true) {
102  $salesRights = $this->newDataObject();
103  $salesRights->setId($row['sales_rights_id']);
104  $salesRights->setType($row['type']);
105  $salesRights->setROWSetting($row['row_setting']);
106  $salesRights->setCountriesIncluded(unserialize($row['countries_included']));
107  $salesRights->setCountriesExcluded(unserialize($row['countries_excluded']));
108  $salesRights->setRegionsIncluded(unserialize($row['regions_included']));
109  $salesRights->setRegionsExcluded(unserialize($row['regions_excluded']));
110 
111  $salesRights->setPublicationFormatId($row['publication_format_id']);
112 
113  if ($callHooks) HookRegistry::call('SalesRightsDAO::_fromRow', array(&$salesRights, &$row));
114 
115  return $salesRights;
116  }
117 
122  function insertObject($salesRights) {
123  $this->update(
124  'INSERT INTO sales_rights
125  (publication_format_id, type, row_setting, countries_included, countries_excluded, regions_included, regions_excluded)
126  VALUES
127  (?, ?, ?, ?, ?, ?, ?)',
128  array(
129  (int) $salesRights->getPublicationFormatId(),
130  $salesRights->getType(),
131  $salesRights->getROWSetting(),
132  serialize($salesRights->getCountriesIncluded() ? $salesRights->getCountriesIncluded() : array()),
133  serialize($salesRights->getCountriesExcluded() ? $salesRights->getCountriesExcluded() : array()),
134  serialize($salesRights->getRegionsIncluded() ? $salesRights->getRegionsIncluded() : array()),
135  serialize($salesRights->getRegionsExcluded() ? $salesRights->getRegionsExcluded() : array())
136  )
137  );
138 
139  $salesRights->setId($this->getInsertId());
140  return $salesRights->getId();
141  }
142 
147  function updateObject($salesRights) {
148  $this->update(
149  'UPDATE sales_rights
150  SET type = ?,
151  row_setting = ?,
152  countries_included = ?,
153  countries_excluded = ?,
154  regions_included = ?,
155  regions_excluded = ?
156  WHERE sales_rights_id = ?',
157  array(
158  $salesRights->getType(),
159  $salesRights->getROWSetting(),
160  serialize($salesRights->getCountriesIncluded() ? $salesRights->getCountriesIncluded() : array()),
161  serialize($salesRights->getCountriesExcluded() ? $salesRights->getCountriesExcluded() : array()),
162  serialize($salesRights->getRegionsIncluded() ? $salesRights->getRegionsIncluded() : array()),
163  serialize($salesRights->getRegionsExcluded() ? $salesRights->getRegionsExcluded() : array()),
164  (int) $salesRights->getId()
165  )
166  );
167  }
168 
173  function deleteObject($salesRights) {
174  return $this->deleteById($salesRights->getId());
175  }
176 
181  function deleteById($entryId) {
182  return $this->update(
183  'DELETE FROM sales_rights WHERE sales_rights_id = ?', array((int) $entryId)
184  );
185  }
186 
191  function getInsertId() {
192  return $this->_getInsertId('sales_rights', 'sales_rights_id');
193  }
194 }
195 
196 ?>
Basic class describing a sales rights composite type (used on the ONIX templates for publication form...
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
getByPublicationFormatId($publicationFormatId)
deleteObject($salesRights)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
_fromRow($row, $callHooks=true)
getROWByPublicationFormatId($publicationFormatId)
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:174
_getInsertId($table= '', $id= '')
Definition: DAO.inc.php:249
static call($hookName, $args=null)
Operations for retrieving and modifying SalesRights objects.
getById($salesRightsId, $monographId=null)
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
updateObject($salesRights)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208
insertObject($salesRights)