Open Monograph Press  3.3.0
RepresentativeDAO.inc.php
1 <?php
2 
17 import('classes.monograph.Representative');
18 
19 class RepresentativeDAO extends DAO {
26  function getById($representativeId, $monographId = null){
27  $sqlParams = array((int) $representativeId);
28  if ($monographId) {
29  $sqlParams[] = (int) $monographId;
30  }
31 
32  $result = $this->retrieve(
33  'SELECT r.*
34  FROM representatives r
35  JOIN submissions s ON (r.submission_id = s.submission_id)
36  WHERE r.representative_id = ?
37  ' . ($monographId?' AND s.submission_id = ?':''),
38  $sqlParams
39  );
40 
41  $returner = null;
42  if ($result->RecordCount() != 0) {
43  $returner = $this->_fromRow($result->GetRowAssoc(false));
44  }
45  $result->Close();
46  return $returner;
47  }
48 
54  function getSuppliersByMonographId($monographId) {
55  $result = $this->retrieveRange(
56  'SELECT * FROM representatives WHERE submission_id = ? AND is_supplier = ?', array((int) $monographId, 1));
57 
58  return new DAOResultFactory($result, $this, '_fromRow');
59  }
60 
66  function getAgentsByMonographId($monographId) {
67  $result = $this->retrieveRange(
68  'SELECT * FROM representatives WHERE submission_id = ? AND is_supplier = ?', array((int) $monographId, 0));
69 
70  return new DAOResultFactory($result, $this, '_fromRow');
71  }
72 
77  function newDataObject() {
78  return new Representative();
79  }
80 
87  function _fromRow($row, $callHooks = true) {
88  $representative = $this->newDataObject();
89  $representative->setId($row['representative_id']);
90  $representative->setRole($row['role']);
91  $representative->setRepresentativeIdType($row['representative_id_type']);
92  $representative->setRepresentativeIdValue($row['representative_id_value']);
93  $representative->setName($row['name']);
94  $representative->setPhone($row['phone']);
95  $representative->setEmail($row['email']);
96  $representative->setUrl($row['url']);
97  $representative->setIsSupplier($row['is_supplier']);
98  $representative->setMonographId($row['submission_id']);
99 
100  if ($callHooks) HookRegistry::call('RepresentativeDAO::_fromRow', array(&$representative, &$row));
101 
102  return $representative;
103  }
104 
109  function insertObject($representative) {
110  $this->update(
111  'INSERT INTO representatives
112  (submission_id, role, representative_id_type, representative_id_value, name, phone, email, url, is_supplier)
113  VALUES
114  (?, ?, ?, ?, ?, ?, ?, ?, ?)',
115  array(
116  (int) $representative->getMonographId(),
117  $representative->getRole(),
118  $representative->getRepresentativeIdType(),
119  $representative->getRepresentativeIdValue(),
120  $representative->getName(),
121  $representative->getPhone(),
122  $representative->getEmail(),
123  $representative->getUrl(),
124  (int) $representative->getIsSupplier()
125  )
126  );
127 
128  $representative->setId($this->getInsertId());
129  return $representative->getId();
130  }
131 
136  function updateObject($representative) {
137  $this->update(
138  'UPDATE representatives
139  SET role = ?,
140  representative_id_type = ?,
141  representative_id_value = ?,
142  name = ?,
143  phone = ?,
144  email = ?,
145  url = ?,
146  is_supplier = ?
147  WHERE representative_id = ?',
148  array(
149  $representative->getRole(),
150  $representative->getRepresentativeIdType(),
151  $representative->getRepresentativeIdValue(),
152  $representative->getName(),
153  $representative->getPhone(),
154  $representative->getEmail(),
155  $representative->getUrl(),
156  (int) $representative->getIsSupplier(),
157  (int) $representative->getId()
158  )
159  );
160  }
161 
166  function deleteObject($representative) {
167  return $this->deleteById($representative->getId());
168  }
169 
174  function deleteById($entryId) {
175  return $this->update(
176  'DELETE FROM representatives WHERE representative_id = ?', (int) $entryId
177  );
178  }
179 
184  function getInsertId() {
185  return $this->_getInsertId('representatives', 'representative_id');
186  }
187 }
188 
189 
RepresentativeDAO\getAgentsByMonographId
getAgentsByMonographId($monographId)
Definition: RepresentativeDAO.inc.php:66
DAOResultFactory
Wrapper around ADORecordSet providing "factory" features for generating objects from DAOs.
Definition: DAOResultFactory.inc.php:21
RepresentativeDAO
Operations for retrieving and modifying Representative (suppliers and agents) objects.
Definition: RepresentativeDAO.inc.php:19
DAO\retrieveRange
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:176
RepresentativeDAO\getInsertId
getInsertId()
Definition: RepresentativeDAO.inc.php:184
RepresentativeDAO\getById
getById($representativeId, $monographId=null)
Definition: RepresentativeDAO.inc.php:26
DAO\retrieve
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:85
RepresentativeDAO\deleteObject
deleteObject($representative)
Definition: RepresentativeDAO.inc.php:166
RepresentativeDAO\insertObject
insertObject($representative)
Definition: RepresentativeDAO.inc.php:109
Representative
Basic class describing a representative composite type (used on the ONIX templates for publication fo...
Definition: Representative.inc.php:17
RepresentativeDAO\getSuppliersByMonographId
getSuppliersByMonographId($monographId)
Definition: RepresentativeDAO.inc.php:54
DAO\update
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:214
RepresentativeDAO\_fromRow
_fromRow($row, $callHooks=true)
Definition: RepresentativeDAO.inc.php:87
RepresentativeDAO\newDataObject
newDataObject()
Definition: RepresentativeDAO.inc.php:77
DAO\_getInsertId
_getInsertId($table='', $id='')
Definition: DAO.inc.php:255
RepresentativeDAO\deleteById
deleteById($entryId)
Definition: RepresentativeDAO.inc.php:174
HookRegistry\call
static call($hookName, $args=null)
Definition: HookRegistry.inc.php:86
DAO
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:31
RepresentativeDAO\updateObject
updateObject($representative)
Definition: RepresentativeDAO.inc.php:136