00001 <?php
00002
00015 import('lib.pkp.classes.form.Form');
00016
00017 class RepresentativeForm extends Form {
00019 var $_monograph;
00020
00022 var $_representative;
00023
00027 function RepresentativeForm($monograph, $representative) {
00028 parent::Form('controllers/grid/catalogEntry/form/representativeForm.tpl');
00029 $this->setMonograph($monograph);
00030 $this->setRepresentative($representative);
00031
00032
00033 $this->addCheck(new FormValidatorCustom(
00034 $this, 'isSupplier', 'required', 'grid.catalogEntry.roleRequired',
00035 create_function(
00036 '$isSupplier, $form, $onixDao, $agentRole, $supplierRole',
00037 'return (!$isSupplier && $onixDao->codeExistsInList($agentRole, \'List69\')) || ($isSupplier && $onixDao->codeExistsInList($supplierRole, \'List93\'));'
00038 ), array(&$this, DAORegistry::getDAO('ONIXCodelistItemDAO'), Request::getUserVar('agentRole'), Request::getUserVar('supplierRole'))
00039 ));
00040 $this->addCheck(new FormValidatorPost($this));
00041 }
00042
00043
00044
00045
00050 function &getRepresentative() {
00051 return $this->_representative;
00052 }
00053
00058 function setRepresentative($representative) {
00059 $this->_representative =& $representative;
00060 }
00061
00066 function &getMonograph() {
00067 return $this->_monograph;
00068 }
00069
00074 function setMonograph($monograph) {
00075 $this->_monograph =& $monograph;
00076 }
00077
00078
00079
00080
00081
00085 function initData() {
00086 $representative =& $this->getRepresentative();
00087
00088 if ($representative) {
00089 $this->_data = array(
00090 'representativeId' => $representative->getId(),
00091 'role' => $representative->getRole(),
00092 'representativeIdType' => $representative->getRepresentativeIdType(),
00093 'representativeIdValue' => $representative->getRepresentativeIdValue(),
00094 'name' => $representative->getName(),
00095 'phone' => $representative->getPhone(),
00096 'fax' => $representative->getFax(),
00097 'email' => $representative->getEmail(),
00098 'url' =>$representative->getUrl(),
00099 'isSupplier' => $representative->getIsSupplier(),
00100 );
00101 }
00102 }
00103
00108 function fetch(&$request) {
00109
00110 $templateMgr =& TemplateManager::getManager();
00111
00112 $monograph =& $this->getMonograph();
00113 $templateMgr->assign('monographId', $monograph->getId());
00114 $representative =& $this->getRepresentative();
00115 $onixCodelistItemDao =& DAORegistry::getDAO('ONIXCodelistItemDAO');
00116 $templateMgr->assign('idTypeCodes', $onixCodelistItemDao->getCodes('List92'));
00117 $templateMgr->assign('agentRoleCodes', $onixCodelistItemDao->getCodes('List69'));
00118 $templateMgr->assign('supplierRoleCodes', $onixCodelistItemDao->getCodes('List93'));
00119 $templateMgr->assign('isSupplier', true);
00120
00121 if ($representative) {
00122 $templateMgr->assign('representativeId', $representative->getId());
00123 $templateMgr->assign('role', $representative->getRole());
00124 $templateMgr->assign('representativeIdType', $representative->getRepresentativeIdType());
00125 $templateMgr->assign('representativeIdValue', $representative->getRepresentativeIdValue());
00126 $templateMgr->assign('name', $representative->getName());
00127 $templateMgr->assign('phone', $representative->getPhone());
00128 $templateMgr->assign('fax', $representative->getFax());
00129 $templateMgr->assign('email', $representative->getEmail());
00130 $templateMgr->assign('url', $representative->getUrl());
00131 $templateMgr->assign('isSupplier', $representative->getIsSupplier() ? true : false);
00132 } else {
00133 $templateMgr->assign('representativeIdType', '06');
00134 }
00135
00136 return parent::fetch($request);
00137 }
00138
00143 function readInputData() {
00144 $this->readUserVars(array(
00145 'representativeId',
00146 'agentRole',
00147 'supplierRole',
00148 'representativeIdType',
00149 'representativeIdValue',
00150 'name',
00151 'phone',
00152 'fax',
00153 'email',
00154 'url',
00155 'isSupplier',
00156 ));
00157 }
00158
00163 function execute() {
00164 $representativeDao =& DAORegistry::getDAO('RepresentativeDAO');
00165 $monograph = $this->getMonograph();
00166 $representative =& $this->getRepresentative();
00167
00168 if (!$representative) {
00169
00170 $representative = $representativeDao->newDataObject();
00171 $representative->setMonographId($monograph->getId());
00172 $existingRepresentative = false;
00173
00174 } else {
00175 $existingRepresentative = true;
00176
00177 if ($representativeDao->getById($representative->getId(), $monograph->getId()) == null) fatalError('Invalid representative!');
00178 }
00179
00180 if ($this->getData('isSupplier')) {
00181 $representative->setRole($this->getData('supplierRole'));
00182 } else {
00183 $representative->setRole($this->getData('agentRole'));
00184 }
00185
00186 $representative->setRepresentativeIdType($this->getData('representativeIdType'));
00187 $representative->setRepresentativeIdValue($this->getData('representativeIdValue'));
00188 $representative->setName($this->getData('name'));
00189 $representative->setPhone($this->getData('phone'));
00190 $representative->setFax($this->getData('fax'));
00191 $representative->setEmail($this->getData('email'));
00192 $representative->setUrl($this->getData('url'));
00193 $representative->setIsSupplier($this->getData('isSupplier') ? true : false);
00194
00195 if ($existingRepresentative) {
00196 $representativeDao->updateObject($representative);
00197 $representativeId = $representative->getId();
00198 } else {
00199 $representativeId = $representativeDao->insertObject($representative);
00200 }
00201
00202 return $representativeId;
00203 }
00204 }
00205 ?>