Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
MarketDAO.inc.php
1 <?php
2 
17 import('classes.publicationFormat.Market');
18 
19 class MarketDAO extends DAO {
23  function MarketDAO() {
24  parent::DAO();
25  }
26 
33  function getById($marketId, $monographId = null){
34  $sqlParams = array((int) $marketId);
35  if ($monographId) {
36  $sqlParams[] = (int) $monographId;
37  }
38 
39  $result = $this->retrieve(
40  'SELECT m.*
41  FROM markets m
42  JOIN publication_formats pf ON (m.publication_format_id = pf.publication_format_id)
43  WHERE m.market_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 markets WHERE publication_format_id = ?', (int) $publicationFormatId);
64 
65  return new DAOResultFactory($result, $this, '_fromRow');
66  }
67 
72  function newDataObject() {
73  return new Market();
74  }
75 
82  function _fromRow($row, $callHooks = true) {
83  $market = $this->newDataObject();
84  $market->setId($row['market_id']);
85  $market->setCountriesIncluded(unserialize($row['countries_included']));
86  $market->setCountriesExcluded(unserialize($row['countries_excluded']));
87  $market->setRegionsIncluded(unserialize($row['regions_included']));
88  $market->setRegionsExcluded(unserialize($row['regions_excluded']));
89  $market->setDateRole($row['market_date_role']);
90  $market->setDateFormat($row['market_date_format']);
91  $market->setDate($row['market_date']);
92  $market->setDiscount($row['discount']);
93  $market->setPrice($row['price']);
94  $market->setPriceTypeCode($row['price_type_code']);
95  $market->setCurrencyCode($row['currency_code']);
96  $market->setTaxRateCode($row['tax_rate_code']);
97  $market->setTaxTypeCode($row['tax_type_code']);
98  $market->setAgentId($row['agent_id']);
99  $market->setSupplierId($row['supplier_id']);
100  $market->setPublicationFormatId($row['publication_format_id']);
101 
102  if ($callHooks) HookRegistry::call('MarketDAO::_fromRow', array(&$market, &$row));
103 
104  return $market;
105  }
106 
111  function insertObject($market) {
112  $this->update(
113  'INSERT INTO markets
114  (publication_format_id, countries_included, countries_excluded, regions_included, regions_excluded, market_date_role, market_date_format, market_date, price, discount, price_type_code, currency_code, tax_rate_code, tax_type_code, agent_id, supplier_id)
115  VALUES
116  (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
117  array(
118  (int) $market->getPublicationFormatId(),
119  serialize($market->getCountriesIncluded() ? $market->getCountriesIncluded() : array()),
120  serialize($market->getCountriesExcluded() ? $market->getCountriesExcluded() : array()),
121  serialize($market->getRegionsIncluded() ? $market->getRegionsIncluded() : array()),
122  serialize($market->getRegionsExcluded() ? $market->getRegionsExcluded() : array()),
123  $market->getDateRole(),
124  $market->getDateFormat(),
125  $market->getDate(),
126  $market->getPrice(),
127  $market->getDiscount(),
128  $market->getPriceTypeCode(),
129  $market->getCurrencyCode(),
130  $market->getTaxRateCode(),
131  $market->getTaxTypeCode(),
132  (int) $market->getAgentId(),
133  (int) $market->getSupplierId()
134  )
135  );
136 
137  $market->setId($this->getInsertId());
138  return $market->getId();
139  }
140 
145  function updateObject($market) {
146  $this->update(
147  'UPDATE markets
148  SET countries_included = ?,
149  countries_excluded = ?,
150  regions_included = ?,
151  regions_excluded = ?,
152  market_date_role = ?,
153  market_date_format = ?,
154  market_date = ?,
155  price = ?,
156  discount = ?,
157  price_type_code = ?,
158  currency_code = ?,
159  tax_rate_code = ?,
160  tax_type_code = ?,
161  agent_id = ?,
162  supplier_id = ?
163  WHERE market_id = ?',
164  array(
165  serialize($market->getCountriesIncluded() ? $market->getCountriesIncluded() : array()),
166  serialize($market->getCountriesExcluded() ? $market->getCountriesExcluded() : array()),
167  serialize($market->getRegionsIncluded() ? $market->getRegionsIncluded() : array()),
168  serialize($market->getRegionsExcluded() ? $market->getRegionsExcluded() : array()),
169  $market->getDateRole(),
170  $market->getDateFormat(),
171  $market->getDate(),
172  $market->getPrice(),
173  $market->getDiscount(),
174  $market->getPriceTypeCode(),
175  $market->getCurrencyCode(),
176  $market->getTaxRateCode(),
177  $market->getTaxTypeCode(),
178  (int) $market->getAgentId(),
179  (int) $market->getSupplierId(),
180  (int) $market->getId()
181  )
182  );
183  }
184 
189  function deleteObject($market) {
190  return $this->deleteById($market->getId());
191  }
192 
197  function deleteById($entryId) {
198  return $this->update(
199  'DELETE FROM markets WHERE market_id = ?', array((int) $entryId)
200  );
201  }
202 
207  function getInsertId() {
208  return $this->_getInsertId('markets', 'market_id');
209  }
210 }
211 
212 ?>
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
getByPublicationFormatId($publicationFormatId)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
Basic class describing a Market composite type (used on the ONIX templates for publication formats) ...
Definition: Market.inc.php:17
updateObject($market)
_fromRow($row, $callHooks=true)
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:174
_getInsertId($table= '', $id= '')
Definition: DAO.inc.php:249
getById($marketId, $monographId=null)
deleteObject($market)
static call($hookName, $args=null)
Operations for retrieving and modifying Market objects.
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
deleteById($entryId)
insertObject($market)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208