00001 <?php
00002
00016 import('classes.publicationFormat.SalesRights');
00017
00018 class SalesRightsDAO extends DAO {
00022 function SalesRightsDAO() {
00023 parent::DAO();
00024 }
00025
00032 function &getById($salesRightsId, $monographId = null){
00033 $sqlParams = array((int) $salesRightsId);
00034 if ($monographId) {
00035 $sqlParams[] = (int) $monographId;
00036 }
00037
00038 $result =& $this->retrieve(
00039 'SELECT s.*
00040 FROM sales_rights s
00041 JOIN publication_formats pf ON (s.publication_format_id = pf.publication_format_id)
00042 WHERE s.sales_rights_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 sales_rights WHERE publication_format_id = ?', (int) $publicationFormatId);
00063
00064 $returner = new DAOResultFactory($result, $this, '_fromRow');
00065 return $returner;
00066 }
00067
00073 function &getROWByPublicationFormatId($publicationFormatId) {
00074 $result =& $this->retrieve(
00075 'SELECT * FROM sales_rights WHERE row_setting = ? AND publication_format_id = ?',
00076 array(1, (int) $publicationFormatId)
00077 );
00078
00079 $returner = null;
00080 if ($result->RecordCount() != 0) {
00081 $returner =& $this->_fromRow($result->GetRowAssoc(false));
00082 }
00083 $result->Close();
00084 return $returner;
00085 }
00086
00091 function newDataObject() {
00092 return new SalesRights();
00093 }
00094
00101 function &_fromRow(&$row, $callHooks = true) {
00102 $salesRights = $this->newDataObject();
00103 $salesRights->setId($row['sales_rights_id']);
00104 $salesRights->setType($row['type']);
00105 $salesRights->setROWSetting($row['row_setting']);
00106 $salesRights->setCountriesIncluded(unserialize($row['countries_included']));
00107 $salesRights->setCountriesExcluded(unserialize($row['countries_excluded']));
00108 $salesRights->setRegionsIncluded(unserialize($row['regions_included']));
00109 $salesRights->setRegionsExcluded(unserialize($row['regions_excluded']));
00110
00111 $salesRights->setPublicationFormatId($row['publication_format_id']);
00112
00113 if ($callHooks) HookRegistry::call('SalesRightsDAO::_fromRow', array(&$salesRights, &$row));
00114
00115 return $salesRights;
00116 }
00117
00122 function insertObject(&$salesRights) {
00123 $this->update(
00124 'INSERT INTO sales_rights
00125 (publication_format_id, type, row_setting, countries_included, countries_excluded, regions_included, regions_excluded)
00126 VALUES
00127 (?, ?, ?, ?, ?, ?, ?)',
00128 array(
00129 (int) $salesRights->getPublicationFormatId(),
00130 $salesRights->getType(),
00131 $salesRights->getROWSetting(),
00132 serialize($salesRights->getCountriesIncluded() ? $salesRights->getCountriesIncluded() : array()),
00133 serialize($salesRights->getCountriesExcluded() ? $salesRights->getCountriesExcluded() : array()),
00134 serialize($salesRights->getRegionsIncluded() ? $salesRights->getRegionsIncluded() : array()),
00135 serialize($salesRights->getRegionsExcluded() ? $salesRights->getRegionsExcluded() : array())
00136 )
00137 );
00138
00139 $salesRights->setId($this->getInsertSalesRightsId());
00140 return $salesRights->getId();
00141 }
00142
00147 function updateObject(&$salesRights) {
00148 $this->update(
00149 'UPDATE sales_rights
00150 SET type = ?,
00151 row_setting = ?,
00152 countries_included = ?,
00153 countries_excluded = ?,
00154 regions_included = ?,
00155 regions_excluded = ?
00156 WHERE sales_rights_id = ?',
00157 array(
00158 $salesRights->getType(),
00159 $salesRights->getROWSetting(),
00160 serialize($salesRights->getCountriesIncluded() ? $salesRights->getCountriesIncluded() : array()),
00161 serialize($salesRights->getCountriesExcluded() ? $salesRights->getCountriesExcluded() : array()),
00162 serialize($salesRights->getRegionsIncluded() ? $salesRights->getRegionsIncluded() : array()),
00163 serialize($salesRights->getRegionsExcluded() ? $salesRights->getRegionsExcluded() : array()),
00164 (int) $salesRights->getId()
00165 )
00166 );
00167 }
00168
00173 function deleteObject($salesRights) {
00174 return $this->deleteById($salesRights->getId());
00175 }
00176
00181 function deleteById($entryId) {
00182 return $this->update(
00183 'DELETE FROM sales_rights WHERE sales_rights_id = ?', array((int) $entryId)
00184 );
00185 }
00186
00191 function getInsertSalesRightsId() {
00192 return $this->getInsertId('sales_rights', 'sales_rights_id');
00193 }
00194 }
00195
00196 ?>