• Main Page
  • Modules
  • Classes
  • Files
  • File List

classes/monograph/RepresentativeDAO.inc.php

00001 <?php
00002 
00016 import('classes.monograph.Representative');
00017 
00018 class RepresentativeDAO extends DAO {
00022    function RepresentativeDAO() {
00023       parent::DAO();
00024    }
00025 
00032    function &getById($representativeId, $monographId = null){
00033       $sqlParams = array((int) $representativeId);
00034       if ($monographId) {
00035          $sqlParams[] = (int) $monographId;
00036       }
00037 
00038       $result =& $this->retrieve(
00039          'SELECT r.*
00040             FROM representatives r
00041          JOIN published_monographs pm ON (r.monograph_id = pm.monograph_id)
00042          WHERE r.representative_id = ?
00043             ' . ($monographId?' AND pm.monograph_id = ?':''),
00044          $sqlParams);
00045 
00046       $returner = null;
00047       if ($result->RecordCount() != 0) {
00048          $returner =& $this->_fromRow($result->GetRowAssoc(false));
00049       }
00050       $result->Close();
00051       return $returner;
00052    }
00053 
00059    function &getSuppliersByMonographId($monographId) {
00060       $result =& $this->retrieveRange(
00061          'SELECT * FROM representatives WHERE monograph_id = ? AND is_supplier = ?', array((int) $monographId, 1));
00062 
00063       $returner = new DAOResultFactory($result, $this, '_fromRow');
00064       return $returner;
00065    }
00066 
00072    function &getAgentsByMonographId($monographId) {
00073       $result =& $this->retrieveRange(
00074             'SELECT * FROM representatives WHERE monograph_id = ? AND is_supplier = ?', array((int) $monographId, 0));
00075 
00076       $returner = new DAOResultFactory($result, $this, '_fromRow');
00077       return $returner;
00078    }
00079 
00084    function newDataObject() {
00085       return new Representative();
00086    }
00087 
00094    function &_fromRow(&$row, $callHooks = true) {
00095       $representative = $this->newDataObject();
00096       $representative->setId($row['representative_id']);
00097       $representative->setRole($row['role']);
00098       $representative->setRepresentativeIdType($row['representative_id_type']);
00099       $representative->setRepresentativeIdValue($row['representative_id_value']);
00100       $representative->setName($row['name']);
00101       $representative->setPhone($row['phone']);
00102       $representative->setFax($row['fax']);
00103       $representative->setEmail($row['email']);
00104       $representative->setUrl($row['url']);
00105       $representative->setIsSupplier($row['is_supplier']);
00106       $representative->setMonographId($row['monograph_id']);
00107 
00108       if ($callHooks) HookRegistry::call('RepresentativeDAO::_fromRow', array(&$representative, &$row));
00109 
00110       return $representative;
00111    }
00112 
00117    function insertObject(&$representative) {
00118       $this->update(
00119          'INSERT INTO representatives
00120             (monograph_id, role, representative_id_type, representative_id_value, name, phone, fax, email, url, is_supplier)
00121          VALUES
00122             (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
00123          array(
00124             (int) $representative->getMonographId(),
00125             $representative->getRole(),
00126             $representative->getRepresentativeIdType(),
00127             $representative->getRepresentativeIdValue(),
00128             $representative->getName(),
00129             $representative->getPhone(),
00130             $representative->getFax(),
00131             $representative->getEmail(),
00132             $representative->getUrl(),
00133             (int) $representative->getIsSupplier()
00134          )
00135       );
00136 
00137       $representative->setId($this->getInsertRepresentativeId());
00138       return $representative->getId();
00139    }
00140 
00145    function updateObject(&$representative) {
00146       $this->update(
00147          'UPDATE representatives
00148             SET role = ?,
00149             representative_id_type = ?,
00150             representative_id_value = ?,
00151             name = ?,
00152             phone = ?,
00153             fax = ?,
00154             email = ?,
00155             url = ?,
00156             is_supplier = ?
00157          WHERE representative_id = ?',
00158          array(
00159             $representative->getRole(),
00160             $representative->getRepresentativeIdType(),
00161             $representative->getRepresentativeIdValue(),
00162             $representative->getName(),
00163             $representative->getPhone(),
00164             $representative->getFax(),
00165             $representative->getEmail(),
00166             $representative->getUrl(),
00167             (int) $representative->getIsSupplier(),
00168             (int) $representative->getId()
00169          )
00170       );
00171    }
00172 
00177    function deleteObject($representative) {
00178       return $this->deleteById($representative->getId());
00179    }
00180 
00185    function deleteById($entryId) {
00186       return $this->update(
00187          'DELETE FROM representatives WHERE representative_id = ?', array((int) $entryId)
00188       );
00189    }
00190 
00195    function getInsertRepresentativeId() {
00196       return $this->getInsertId('representatives', 'representative_id');
00197    }
00198 }
00199 
00200 ?>

Generated on Mon Sep 17 2012 13:58:55 for Open Monograph Press by  doxygen 1.7.1