00001 <?php
00002
00015
00016 import('lib.pkp.classes.controllers.grid.GridHandler');
00017
00018
00019
00020 import('controllers.grid.catalogEntry.IdentificationCodeGridCellProvider');
00021 import('controllers.grid.catalogEntry.IdentificationCodeGridRow');
00022
00023
00024 import('lib.pkp.classes.linkAction.request.AjaxModal');
00025
00026 class IdentificationCodeGridHandler extends GridHandler {
00028 var $_monograph;
00029
00031 var $_publicationFormat;
00032
00036 function IdentificationCodeGridHandler() {
00037 parent::GridHandler();
00038 $this->addRoleAssignment(
00039 array(ROLE_ID_PRESS_MANAGER),
00040 array('fetchGrid', 'fetchRow', 'addCode', 'editCode',
00041 'updateCode', 'deleteCode'));
00042 }
00043
00044
00045
00046
00047
00052 function &getMonograph() {
00053 return $this->_monograph;
00054 }
00055
00060 function setMonograph($monograph) {
00061 $this->_monograph =& $monograph;
00062 }
00063
00068 function &getPublicationFormat() {
00069 return $this->_publicationFormat;
00070 }
00071
00076 function setPublicationFormat($publicationFormat) {
00077 $this->_publicationFormat =& $publicationFormat;
00078 }
00079
00080
00081
00082
00089 function authorize(&$request, $args, $roleAssignments) {
00090 import('classes.security.authorization.OmpSubmissionAccessPolicy');
00091 $this->addPolicy(new OmpSubmissionAccessPolicy($request, $args, $roleAssignments));
00092 return parent::authorize($request, $args, $roleAssignments);
00093 }
00094
00095
00096
00097
00098
00099 function initialize(&$request) {
00100 parent::initialize($request);
00101
00102
00103 $this->setMonograph($this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH));
00104 $publicationFormatDao =& DAORegistry::getDAO('PublicationFormatDAO');
00105 $publicationFormatId = null;
00106
00107
00108 $identificationCodeId = (int) $request->getUserVar('identificationCodeId');
00109
00110 if ($identificationCodeId != '') {
00111 $identificationCodeDao =& DAORegistry::getDAO('IdentificationCodeDAO');
00112 $identificationCode =& $identificationCodeDao->getById($identificationCodeId, $this->getMonograph()->getId());
00113 if ($identificationCode) {
00114 $publicationFormatId =& $identificationCode->getPublicationFormatId();
00115 }
00116 } else {
00117 $publicationFormatId = (int) $request->getUserVar('publicationFormatId');
00118 }
00119
00120 $publicationFormat =& $publicationFormatDao->getById($publicationFormatId, $this->getMonograph()->getId());
00121
00122 if ($publicationFormat) {
00123 $this->setPublicationFormat($publicationFormat);
00124 } else {
00125 fatalError('The publication format is not assigned to authorized monograph!');
00126 }
00127
00128
00129 AppLocale::requireComponents(
00130 LOCALE_COMPONENT_OMP_SUBMISSION,
00131 LOCALE_COMPONENT_PKP_SUBMISSION,
00132 LOCALE_COMPONENT_PKP_USER,
00133 LOCALE_COMPONENT_OMP_DEFAULT_SETTINGS
00134 );
00135
00136
00137 $this->setTitle('monograph.publicationFormat.productIdentifierType');
00138
00139
00140 $router =& $request->getRouter();
00141 $actionArgs = $this->getRequestArgs();
00142 $this->addAction(
00143 new LinkAction(
00144 'addCode',
00145 new AjaxModal(
00146 $router->url($request, null, null, 'addCode', null, $actionArgs),
00147 __('grid.action.addCode'),
00148 'modal_add_item'
00149 ),
00150 __('grid.action.addCode'),
00151 'add_item'
00152 )
00153 );
00154
00155
00156 $cellProvider = new IdentificationCodeGridCellProvider();
00157 $this->addColumn(
00158 new GridColumn(
00159 'value',
00160 'grid.catalogEntry.identificationCodeValue',
00161 null,
00162 'controllers/grid/gridCell.tpl',
00163 $cellProvider,
00164 array('width' => 50, 'alignment' => COLUMN_ALIGNMENT_LEFT)
00165 )
00166 );
00167 $this->addColumn(
00168 new GridColumn(
00169 'code',
00170 'grid.catalogEntry.identificationCodeType',
00171 null,
00172 'controllers/grid/gridCell.tpl',
00173 $cellProvider
00174 )
00175 );
00176 }
00177
00178
00179
00180
00181
00186 function &getRowInstance() {
00187 $row = new IdentificationCodeGridRow($this->getMonograph());
00188 return $row;
00189 }
00190
00196 function getRequestArgs() {
00197 $monograph =& $this->getMonograph();
00198 $publicationFormat =& $this->getPublicationFormat();
00199
00200 return array(
00201 'monographId' => $monograph->getId(),
00202 'publicationFormatId' => $publicationFormat->getId()
00203 );
00204 }
00205
00209 function &loadData($request, $filter = null) {
00210 $publicationFormat =& $this->getPublicationFormat();
00211 $identificationCodeDao =& DAORegistry::getDAO('IdentificationCodeDAO');
00212 $data =& $identificationCodeDao->getByPublicationFormatId($publicationFormat->getId());
00213 return $data->toArray();
00214 }
00215
00216
00217
00218
00219
00220
00221 function addCode($args, $request) {
00222 return $this->editCode($args, $request);
00223 }
00224
00231 function editCode($args, &$request) {
00232
00233 $identificationCodeId = (int) $request->getUserVar('identificationCodeId');
00234 $monograph =& $this->getMonograph();
00235
00236 $identificationCodeDao =& DAORegistry::getDAO('IdentificationCodeDAO');
00237 $identificationCode = $identificationCodeDao->getById($identificationCodeId, $monograph->getId());
00238
00239
00240 import('controllers.grid.catalogEntry.form.IdentificationCodeForm');
00241 $identificationCodeForm = new IdentificationCodeForm($monograph, $identificationCode);
00242 $identificationCodeForm->initData();
00243
00244 $json = new JSONMessage(true, $identificationCodeForm->fetch($request));
00245 return $json->getString();
00246 }
00247
00254 function updateCode($args, &$request) {
00255
00256 $identificationCodeId = $request->getUserVar('identificationCodeId');
00257 $monograph =& $this->getMonograph();
00258
00259 $identificationCodeDao =& DAORegistry::getDAO('IdentificationCodeDAO');
00260 $identificationCode = $identificationCodeDao->getById($identificationCodeId, $monograph->getId());
00261
00262
00263 import('controllers.grid.catalogEntry.form.IdentificationCodeForm');
00264 $identificationCodeForm = new IdentificationCodeForm($monograph, $identificationCode);
00265 $identificationCodeForm->readInputData();
00266 if ($identificationCodeForm->validate()) {
00267 $identificationCodeId = $identificationCodeForm->execute();
00268
00269 if(!isset($identificationCode)) {
00270
00271 $identificationCode =& $identificationCodeDao->getById($identificationCodeId, $monograph->getId());
00272
00273 $notificationContent = __('notification.addedIdentificationCode');
00274 } else {
00275
00276 $notificationContent = __('notification.editedIdentificationCode');
00277 }
00278
00279
00280 $currentUser =& $request->getUser();
00281 $notificationMgr = new NotificationManager();
00282 $notificationMgr->createTrivialNotification($currentUser->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => $notificationContent));
00283
00284
00285 $row =& $this->getRowInstance();
00286 $row->setGridId($this->getId());
00287 $row->setId($identificationCodeId);
00288 $row->setData($identificationCode);
00289 $row->initialize($request);
00290
00291
00292 return DAO::getDataChangedEvent();
00293
00294 } else {
00295 $json = new JSONMessage(true, $identificationCodeForm->fetch($request));
00296 return $json->getString();
00297 }
00298 }
00299
00306 function deleteCode($args, &$request) {
00307
00308
00309 $identificationCodeId = $request->getUserVar('identificationCodeId');
00310
00311 $identificationCodeDao =& DAORegistry::getDAO('IdentificationCodeDAO');
00312 $identificationCode =& $identificationCodeDao->getById($identificationCodeId, $this->getMonograph()->getId());
00313 if ($identificationCode != null) {
00314
00315 $result = $identificationCodeDao->deleteObject($identificationCode);
00316
00317 if ($result) {
00318 $currentUser =& $request->getUser();
00319 $notificationMgr = new NotificationManager();
00320 $notificationMgr->createTrivialNotification($currentUser->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('notification.removedIdentificationCode')));
00321 return DAO::getDataChangedEvent();
00322 } else {
00323 $json = new JSONMessage(false, __('manager.setup.errorDeletingItem'));
00324 return $json->getString();
00325 }
00326 }
00327 }
00328 }
00329
00330 ?>