Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
IdentificationCodeDAO.inc.php
1 <?php
2 
17 import('classes.publicationFormat.IdentificationCode');
18 
19 class IdentificationCodeDAO extends DAO {
23  function IdentificationCodeDAO() {
24  parent::DAO();
25  }
26 
33  function getById($identificationCodeId, $monographId = null){
34  $sqlParams = array((int) $identificationCodeId);
35  if ($monographId) {
36  $sqlParams[] = (int) $monographId;
37  }
38 
39  $result = $this->retrieve(
40  'SELECT i.*
41  FROM identification_codes i
42  JOIN publication_formats pf ON (i.publication_format_id = pf.publication_format_id)
43  WHERE i.identification_code_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 identification_codes WHERE publication_format_id = ?', (int) $publicationFormatId);
64 
65  return new DAOResultFactory($result, $this, '_fromRow');
66  }
67 
72  function newDataObject() {
73  return new IdentificationCode();
74  }
75 
82  function _fromRow($row, $callHooks = true) {
83  $identificationCode = $this->newDataObject();
84  $identificationCode->setId($row['identification_code_id']);
85  $identificationCode->setCode($row['code']);
86  $identificationCode->setValue($row['value']);
87  $identificationCode->setPublicationFormatId($row['publication_format_id']);
88 
89  if ($callHooks) HookRegistry::call('IdentificationCodeDAO::_fromRow', array(&$identificationCode, &$row));
90 
91  return $identificationCode;
92  }
93 
98  function insertObject($identificationCode) {
99  $this->update(
100  'INSERT INTO identification_codes
101  (publication_format_id, code, value)
102  VALUES
103  (?, ?, ?)',
104  array(
105  (int) $identificationCode->getPublicationFormatId(),
106  $identificationCode->getCode(),
107  $identificationCode->getValue()
108  )
109  );
110 
111  $identificationCode->setId($this->getInsertId());
112  return $identificationCode->getId();
113  }
114 
119  function updateObject($identificationCode) {
120  $this->update(
121  'UPDATE identification_codes
122  SET code = ?, value = ?
123  WHERE identification_code_id = ?',
124  array(
125  $identificationCode->getCode(),
126  $identificationCode->getValue(),
127  (int) $identificationCode->getId()
128  )
129  );
130  }
131 
136  function deleteObject($identificationCode) {
137  return $this->deleteById($identificationCode->getId());
138  }
139 
144  function deleteById($entryId) {
145  return $this->update(
146  'DELETE FROM identification_codes WHERE identification_code_id = ?', array((int) $entryId)
147  );
148  }
149 
154  function getInsertId() {
155  return $this->_getInsertId('identification_codes', 'identification_code_id');
156  }
157 }
158 
159 ?>
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:174
deleteObject($identificationCode)
_getInsertId($table= '', $id= '')
Definition: DAO.inc.php:249
Basic class describing an identification code (used on the ONIX templates for publication formats) ...
getByPublicationFormatId($publicationFormatId)
static call($hookName, $args=null)
getById($identificationCodeId, $monographId=null)
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
Operations for retrieving and modifying IdentificationCode objects.
updateObject($identificationCode)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208
insertObject($identificationCode)
_fromRow($row, $callHooks=true)