00001 <?php
00002
00016 import('classes.publicationFormat.Market');
00017
00018 class MarketDAO extends DAO {
00022 function MarketDAO() {
00023 parent::DAO();
00024 }
00025
00032 function &getById($marketId, $monographId = null){
00033 $sqlParams = array((int) $marketId);
00034 if ($monographId) {
00035 $sqlParams[] = (int) $monographId;
00036 }
00037
00038 $result =& $this->retrieve(
00039 'SELECT m.*
00040 FROM markets m
00041 JOIN publication_formats pf ON (m.publication_format_id = pf.publication_format_id)
00042 WHERE m.market_id = ?
00043 ' . ($monographId?' AND pf.monograph_id = ?':''),
00044 $sqlParams
00045 );
00046
00047 $returner = null;
00048 if ($result->RecordCount() != 0) {
00049 $returner =& $this->_fromRow($result->GetRowAssoc(false));
00050 }
00051 $result->Close();
00052 return $returner;
00053 }
00054
00060 function &getByPublicationFormatId($publicationFormatId) {
00061 $result =& $this->retrieveRange(
00062 'SELECT * FROM markets WHERE publication_format_id = ?', (int) $publicationFormatId);
00063
00064 $returner = new DAOResultFactory($result, $this, '_fromRow');
00065 return $returner;
00066 }
00067
00072 function newDataObject() {
00073 return new Market();
00074 }
00075
00082 function &_fromRow(&$row, $callHooks = true) {
00083 $market = $this->newDataObject();
00084 $market->setId($row['market_id']);
00085 $market->setCountriesIncluded(unserialize($row['countries_included']));
00086 $market->setCountriesExcluded(unserialize($row['countries_excluded']));
00087 $market->setRegionsIncluded(unserialize($row['regions_included']));
00088 $market->setRegionsExcluded(unserialize($row['regions_excluded']));
00089 $market->setDateRole($row['market_date_role']);
00090 $market->setDateFormat($row['market_date_format']);
00091 $market->setDate($row['market_date']);
00092 $market->setDiscount($row['discount']);
00093 $market->setPrice($row['price']);
00094 $market->setPriceTypeCode($row['price_type_code']);
00095 $market->setCurrencyCode($row['currency_code']);
00096 $market->setTaxRateCode($row['tax_rate_code']);
00097 $market->setTaxTypeCode($row['tax_type_code']);
00098 $market->setAgentId($row['agent_id']);
00099 $market->setSupplierId($row['supplier_id']);
00100 $market->setPublicationFormatId($row['publication_format_id']);
00101
00102 if ($callHooks) HookRegistry::call('MarketDAO::_fromRow', array(&$market, &$row));
00103
00104 return $market;
00105 }
00106
00111 function insertObject(&$market) {
00112 $this->update(
00113 'INSERT INTO markets
00114 (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)
00115 VALUES
00116 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
00117 array(
00118 (int) $market->getPublicationFormatId(),
00119 serialize($market->getCountriesIncluded() ? $market->getCountriesIncluded() : array()),
00120 serialize($market->getCountriesExcluded() ? $market->getCountriesExcluded() : array()),
00121 serialize($market->getRegionsIncluded() ? $market->getRegionsIncluded() : array()),
00122 serialize($market->getRegionsExcluded() ? $market->getRegionsExcluded() : array()),
00123 $market->getDateRole(),
00124 $market->getDateFormat(),
00125 $market->getDate(),
00126 $market->getPrice(),
00127 $market->getDiscount(),
00128 $market->getPriceTypeCode(),
00129 $market->getCurrencyCode(),
00130 $market->getTaxRateCode(),
00131 $market->getTaxTypeCode(),
00132 (int) $market->getAgentId(),
00133 (int) $market->getSupplierId()
00134 )
00135 );
00136
00137 $market->setId($this->getInsertMarketId());
00138 return $market->getId();
00139 }
00140
00145 function updateObject(&$market) {
00146 $this->update(
00147 'UPDATE markets
00148 SET countries_included = ?,
00149 countries_excluded = ?,
00150 regions_included = ?,
00151 regions_excluded = ?,
00152 market_date_role = ?,
00153 market_date_format = ?,
00154 market_date = ?,
00155 price = ?,
00156 discount = ?,
00157 price_type_code = ?,
00158 currency_code = ?,
00159 tax_rate_code = ?,
00160 tax_type_code = ?,
00161 agent_id = ?,
00162 supplier_id = ?
00163 WHERE market_id = ?',
00164 array(
00165 serialize($market->getCountriesIncluded() ? $market->getCountriesIncluded() : array()),
00166 serialize($market->getCountriesExcluded() ? $market->getCountriesExcluded() : array()),
00167 serialize($market->getRegionsIncluded() ? $market->getRegionsIncluded() : array()),
00168 serialize($market->getRegionsExcluded() ? $market->getRegionsExcluded() : array()),
00169 $market->getDateRole(),
00170 $market->getDateFormat(),
00171 $market->getDate(),
00172 $market->getPrice(),
00173 $market->getDiscount(),
00174 $market->getPriceTypeCode(),
00175 $market->getCurrencyCode(),
00176 $market->getTaxRateCode(),
00177 $market->getTaxTypeCode(),
00178 (int) $market->getAgentId(),
00179 (int) $market->getSupplierId(),
00180 (int) $market->getId()
00181 )
00182 );
00183 }
00184
00189 function deleteObject($market) {
00190 return $this->deleteById($market->getId());
00191 }
00192
00197 function deleteById($entryId) {
00198 return $this->update(
00199 'DELETE FROM markets WHERE market_id = ?', array((int) $entryId)
00200 );
00201 }
00202
00207 function getInsertMarketId() {
00208 return $this->getInsertId('markets', 'market_id');
00209 }
00210 }
00211
00212 ?>