17 import(
'lib.pkp.classes.controllers.grid.CategoryGridHandler');
21 import(
'controllers.grid.catalogEntry.RepresentativesGridCellProvider');
22 import(
'controllers.grid.catalogEntry.RepresentativesGridCategoryRow');
23 import(
'controllers.grid.catalogEntry.RepresentativesGridRow');
26 import(
'lib.pkp.classes.linkAction.request.AjaxModal');
36 parent::__construct();
38 array(ROLE_ID_MANAGER, ROLE_ID_SUB_EDITOR, ROLE_ID_ASSISTANT),
39 array(
'fetchGrid',
'fetchCategory',
'fetchRow',
'addRepresentative',
'editRepresentative',
40 'updateRepresentative',
'deleteRepresentative'));
60 $this->_monograph = $monograph;
73 function authorize($request, &$args, $roleAssignments) {
74 import(
'lib.pkp.classes.security.authorization.SubmissionAccessPolicy');
76 return parent::authorize($request, $args, $roleAssignments);
83 parent::initialize($request, $args);
88 $representativeId = (int) $request->getUserVar(
'representativeId');
90 if ($representativeId !=
'') {
92 $representative = $representativeDao->getById($representativeId, $this->
getMonograph()->
getId());
93 if (!isset($representative)) {
94 fatalError(
'Representative referenced outside of authorized monograph context!');
100 LOCALE_COMPONENT_APP_SUBMISSION,
101 LOCALE_COMPONENT_PKP_SUBMISSION,
102 LOCALE_COMPONENT_PKP_USER,
103 LOCALE_COMPONENT_APP_DEFAULT,
104 LOCALE_COMPONENT_PKP_DEFAULT
108 $this->
setTitle(
'grid.catalogEntry.representatives');
111 $router = $request->getRouter();
117 $router->url($request,
null,
null,
'addRepresentative',
null, $actionArgs),
118 __(
'grid.action.addRepresentative'),
121 __(
'grid.action.addRepresentative'),
131 'grid.catalogEntry.representativeName',
140 'grid.catalogEntry.representativeRole',
173 if ($category[
'isSupplier']) {
174 $representatives = $representativeDao->getSuppliersByMonographId($this->
getMonograph()->
getId());
176 $representatives = $representativeDao->getAgentsByMonographId($this->
getMonograph()->
getId());
178 return $representatives->toAssociativeArray();
185 return 'representativeCategoryId';
194 parent::getRequestArgs(),
195 array(
'submissionId' => $monograph->getId())
202 function loadData($request, $filter =
null) {
205 array(
'name' =>
'grid.catalogEntry.agentsCategory',
'isSupplier' =>
false),
206 array(
'name' =>
'grid.catalogEntry.suppliersCategory',
'isSupplier' =>
true)
229 $representativeId = (int) $request->getUserVar(
'representativeId');
233 $representative = $representativeDao->getById($representativeId, $monograph->getId());
236 import(
'controllers.grid.catalogEntry.form.RepresentativeForm');
238 $representativeForm->initData();
240 return new JSONMessage(
true, $representativeForm->fetch($request));
251 $representativeId = $request->getUserVar(
'representativeId');
255 $representative = $representativeDao->getById($representativeId, $monograph->getId());
258 import(
'controllers.grid.catalogEntry.form.RepresentativeForm');
260 $representativeForm->readInputData();
261 if ($representativeForm->validate()) {
262 $representativeId = $representativeForm->execute();
264 if(!isset($representative)) {
266 $representative = $representativeDao->getById($representativeId, $monograph->getId());
268 $notificationContent = __(
'notification.addedRepresentative');
271 $notificationContent = __(
'notification.editedRepresentative');
275 $currentUser = $request->getUser();
277 $notificationMgr->createTrivialNotification($currentUser->getId(), NOTIFICATION_TYPE_SUCCESS, array(
'contents' => $notificationContent));
281 $row->setGridId($this->
getId());
282 $row->setId($representativeId);
283 $row->setData($representative);
284 $row->initialize($request);
290 return new JSONMessage(
true, $representativeForm->fetch($request));
304 $representativeId = $request->getUserVar(
'representativeId');
307 $representative = $representativeDao->getById($representativeId, $this->
getMonograph()->
getId());
309 if (!$representative) {
310 return new JSONMessage(
false, __(
'api.404.resourceNotFound'));
316 foreach ($submission->getData(
'publications') as $publication) {
317 foreach ($publication->getData(
'publicationFormats') as $publicationFormat) {
318 $markets =
DAORegistry::getDAO(
'MarketDAO')->getByPublicationFormatId($publicationFormat->getId())->toArray();
319 foreach ($markets as $market) {
320 if (in_array($representative->getId(), [$market->getAgentId(), $market->getSupplierId()])) {
321 return new JSONMessage(
false, __(
'manager.representative.inUse'));
327 $result = $representativeDao->deleteObject($representative);
330 $currentUser = $request->getUser();
332 $notificationMgr->createTrivialNotification($currentUser->getId(), NOTIFICATION_TYPE_SUCCESS, array(
'contents' => __(
'notification.removedRepresentative')));
335 return new JSONMessage(
false, __(
'manager.setup.errorDeletingItem'));