Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
RepresentativeDAO.inc.php
1 <?php
2 
17 import('classes.monograph.Representative');
18 
19 class RepresentativeDAO extends DAO {
23  function RepresentativeDAO() {
24  parent::DAO();
25  }
26 
33  function getById($representativeId, $monographId = null){
34  $sqlParams = array((int) $representativeId);
35  if ($monographId) {
36  $sqlParams[] = (int) $monographId;
37  }
38 
39  $result = $this->retrieve(
40  'SELECT r.*
41  FROM representatives r
42  JOIN published_submissions ps ON (r.submission_id = ps.submission_id)
43  WHERE r.representative_id = ?
44  ' . ($monographId?' AND ps.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 getSuppliersByMonographId($monographId) {
62  $result = $this->retrieveRange(
63  'SELECT * FROM representatives WHERE submission_id = ? AND is_supplier = ?', array((int) $monographId, 1));
64 
65  return new DAOResultFactory($result, $this, '_fromRow');
66  }
67 
73  function getAgentsByMonographId($monographId) {
74  $result = $this->retrieveRange(
75  'SELECT * FROM representatives WHERE submission_id = ? AND is_supplier = ?', array((int) $monographId, 0));
76 
77  return new DAOResultFactory($result, $this, '_fromRow');
78  }
79 
84  function newDataObject() {
85  return new Representative();
86  }
87 
94  function _fromRow($row, $callHooks = true) {
95  $representative = $this->newDataObject();
96  $representative->setId($row['representative_id']);
97  $representative->setRole($row['role']);
98  $representative->setRepresentativeIdType($row['representative_id_type']);
99  $representative->setRepresentativeIdValue($row['representative_id_value']);
100  $representative->setName($row['name']);
101  $representative->setPhone($row['phone']);
102  $representative->setFax($row['fax']);
103  $representative->setEmail($row['email']);
104  $representative->setUrl($row['url']);
105  $representative->setIsSupplier($row['is_supplier']);
106  $representative->setMonographId($row['submission_id']);
107 
108  if ($callHooks) HookRegistry::call('RepresentativeDAO::_fromRow', array(&$representative, &$row));
109 
110  return $representative;
111  }
112 
117  function insertObject($representative) {
118  $this->update(
119  'INSERT INTO representatives
120  (submission_id, role, representative_id_type, representative_id_value, name, phone, fax, email, url, is_supplier)
121  VALUES
122  (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
123  array(
124  (int) $representative->getMonographId(),
125  $representative->getRole(),
126  $representative->getRepresentativeIdType(),
127  $representative->getRepresentativeIdValue(),
128  $representative->getName(),
129  $representative->getPhone(),
130  $representative->getFax(),
131  $representative->getEmail(),
132  $representative->getUrl(),
133  (int) $representative->getIsSupplier()
134  )
135  );
136 
137  $representative->setId($this->getInsertId());
138  return $representative->getId();
139  }
140 
145  function updateObject($representative) {
146  $this->update(
147  'UPDATE representatives
148  SET role = ?,
149  representative_id_type = ?,
150  representative_id_value = ?,
151  name = ?,
152  phone = ?,
153  fax = ?,
154  email = ?,
155  url = ?,
156  is_supplier = ?
157  WHERE representative_id = ?',
158  array(
159  $representative->getRole(),
160  $representative->getRepresentativeIdType(),
161  $representative->getRepresentativeIdValue(),
162  $representative->getName(),
163  $representative->getPhone(),
164  $representative->getFax(),
165  $representative->getEmail(),
166  $representative->getUrl(),
167  (int) $representative->getIsSupplier(),
168  (int) $representative->getId()
169  )
170  );
171  }
172 
177  function deleteObject($representative) {
178  return $this->deleteById($representative->getId());
179  }
180 
185  function deleteById($entryId) {
186  return $this->update(
187  'DELETE FROM representatives WHERE representative_id = ?', (int) $entryId
188  );
189  }
190 
195  function getInsertId() {
196  return $this->_getInsertId('representatives', 'representative_id');
197  }
198 }
199 
200 ?>
updateObject($representative)
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
getById($representativeId, $monographId=null)
deleteObject($representative)
_getInsertId($table= '', $id= '')
Definition: DAO.inc.php:249
_fromRow($row, $callHooks=true)
static call($hookName, $args=null)
insertObject($representative)
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
getSuppliersByMonographId($monographId)
Operations for retrieving and modifying Representative (suppliers and agents) objects.
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208
getAgentsByMonographId($monographId)
Basic class describing a representative composite type (used on the ONIX templates for publication fo...