00001 <?php
00002
00016 import('classes.publicationFormat.IdentificationCode');
00017
00018 class IdentificationCodeDAO extends DAO {
00022 function IdentificationCodeDAO() {
00023 parent::DAO();
00024 }
00025
00032 function &getById($identificationCodeId, $monographId = null){
00033 $sqlParams = array((int) $identificationCodeId);
00034 if ($monographId) {
00035 $sqlParams[] = (int) $monographId;
00036 }
00037
00038 $result =& $this->retrieve(
00039 'SELECT i.*
00040 FROM identification_codes i
00041 JOIN publication_formats pf ON (i.publication_format_id = pf.publication_format_id)
00042 WHERE i.identification_code_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 identification_codes 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 IdentificationCode();
00074 }
00075
00082 function &_fromRow(&$row, $callHooks = true) {
00083 $identificationCode = $this->newDataObject();
00084 $identificationCode->setId($row['identification_code_id']);
00085 $identificationCode->setCode($row['code']);
00086 $identificationCode->setValue($row['value']);
00087 $identificationCode->setPublicationFormatId($row['publication_format_id']);
00088
00089 if ($callHooks) HookRegistry::call('IdentificationCodeDAO::_fromRow', array(&$identificationCode, &$row));
00090
00091 return $identificationCode;
00092 }
00093
00098 function insertObject(&$identificationCode) {
00099 $this->update(
00100 'INSERT INTO identification_codes
00101 (publication_format_id, code, value)
00102 VALUES
00103 (?, ?, ?)',
00104 array(
00105 (int) $identificationCode->getPublicationFormatId(),
00106 $identificationCode->getCode(),
00107 $identificationCode->getValue()
00108 )
00109 );
00110
00111 $identificationCode->setId($this->getInsertIdentificationCodeId());
00112 return $identificationCode->getId();
00113 }
00114
00119 function updateObject(&$identificationCode) {
00120 $this->update(
00121 'UPDATE identification_codes
00122 SET code = ?, value = ?
00123 WHERE identification_code_id = ?',
00124 array(
00125 $identificationCode->getCode(),
00126 $identificationCode->getValue(),
00127 (int) $identificationCode->getId()
00128 )
00129 );
00130 }
00131
00136 function deleteObject($identificationCode) {
00137 return $this->deleteById($identificationCode->getId());
00138 }
00139
00144 function deleteById($entryId) {
00145 return $this->update(
00146 'DELETE FROM identification_codes WHERE identification_code_id = ?', array((int) $entryId)
00147 );
00148 }
00149
00154 function getInsertIdentificationCodeId() {
00155 return $this->getInsertId('identification_codes', 'identification_code_id');
00156 }
00157 }
00158
00159 ?>