00001 <?php
00002
00015
00016 import('classes.handler.Handler');
00017
00018
00019 import('classes.log.MonographLog');
00020 import('classes.log.MonographEventLogEntry');
00021
00022 class CatalogEntryTabHandler extends Handler {
00023
00024
00026 var $_currentTab;
00027
00029 var $_monograph;
00030
00032 var $_stageId;
00033
00035 var $_tabPosition;
00036
00040 function CatalogEntryTabHandler() {
00041 parent::Handler();
00042 $this->addRoleAssignment(
00043 array(ROLE_ID_SERIES_EDITOR, ROLE_ID_PRESS_MANAGER),
00044 array(
00045 'submissionMetadata',
00046 'catalogMetadata',
00047 'publicationMetadata',
00048 'saveForm',
00049 'uploadCoverImage',
00050 )
00051 );
00052 }
00053
00054
00055
00056
00057
00062 function getCurrentTab() {
00063 return $this->_currentTab;
00064 }
00065
00070 function setCurrentTab($currentTab) {
00071 $this->_currentTab = $currentTab;
00072 }
00073
00074
00075
00076
00077
00081 function initialize(&$request) {
00082 $this->setCurrentTab($request->getUserVar('tab'));
00083 $this->_monograph =& $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH);
00084 $this->_stageId =& $this->getAuthorizedContextObject(ASSOC_TYPE_WORKFLOW_STAGE);
00085 $this->_tabPosition = (int) $request->getUserVar('tabPos');
00086
00087 AppLocale::requireComponents(LOCALE_COMPONENT_APPLICATION_COMMON, LOCALE_COMPONENT_OMP_SUBMISSION);
00088 $this->setupTemplate();
00089 }
00090
00094 function authorize(&$request, $args, $roleAssignments) {
00095 $stageId = (int) $request->getUserVar('stageId');
00096 import('classes.security.authorization.OmpWorkflowStageAccessPolicy');
00097 $this->addPolicy(new OmpWorkflowStageAccessPolicy($request, $args, $roleAssignments, 'monographId', $stageId));
00098 return parent::authorize($request, $args, $roleAssignments);
00099 }
00100
00101
00102
00103
00104
00111 function submissionMetadata($args, &$request) {
00112
00113 import('controllers.modals.submissionMetadata.form.CatalogEntrySubmissionReviewForm');
00114
00115 $monograph =& $this->getMonograph();
00116 $stageId =& $this->getStageId();
00117
00118 $catalogEntrySubmissionReviewForm = new CatalogEntrySubmissionReviewForm($monograph->getId(), $stageId, array('displayedInContainer' => true));
00119
00120 $catalogEntrySubmissionReviewForm->initData($args, $request);
00121 $json = new JSONMessage(true, $catalogEntrySubmissionReviewForm->fetch($request));
00122 return $json->getString();
00123 }
00124
00128 function getMonograph() {
00129 return $this->_monograph;
00130 }
00131
00135 function getStageId() {
00136 return $this->_stageId;
00137 }
00138
00142 function getTabPosition() {
00143 return $this->_tabPosition;
00144 }
00145
00152 function catalogMetadata($args, &$request) {
00153 import('controllers.tab.catalogEntry.form.CatalogEntryCatalogMetadataForm');
00154
00155 $monograph =& $this->getMonograph();
00156 $stageId =& $this->getStageId();
00157 $user =& $request->getUser();
00158
00159 $catalogEntryCatalogMetadataForm = new CatalogEntryCatalogMetadataForm($monograph->getId(), $user->getId(), $stageId, array('displayedInContainer' => true));
00160
00161 $catalogEntryCatalogMetadataForm->initData($args, $request);
00162 $json = new JSONMessage(true, $catalogEntryCatalogMetadataForm->fetch($request));
00163 return $json->getString();
00164 }
00165
00172 function publicationMetadata($args, &$request) {
00173
00174 $publicationFormatId = (int) $request->getUserVar('publicationFormatId');
00175 $publicationFormatDao =& DAORegistry::getDAO('PublicationFormatDAO');
00176
00177 $monograph =& $this->getMonograph();
00178 $stageId =& $this->getStageId();
00179
00180 $publicationFormat =& $publicationFormatDao->getById($publicationFormatId, $monograph->getId());
00181
00182 if (!$publicationFormat) {
00183 $json = new JSONMessage(false, __('monograph.publicationFormat.formatDoesNotExist'));
00184 return $json->getString();
00185 }
00186
00187 import('controllers.tab.catalogEntry.form.CatalogEntryPublicationMetadataForm');
00188 $catalogEntryPublicationMetadataForm = new CatalogEntryPublicationMetadataForm($monograph->getId(), $publicationFormatId, $publicationFormat->getPhysicalFormat(), $stageId, array('displayedInContainer' => true, 'tabPos' => $this->getTabPosition()));
00189 $catalogEntryPublicationMetadataForm->initData($args, $request);
00190 $json = new JSONMessage(true, $catalogEntryPublicationMetadataForm->fetch($request));
00191 return $json->getString();
00192 }
00193
00200 function saveForm($args, &$request) {
00201 $json = new JSONMessage();
00202 $form = null;
00203
00204 $monograph =& $this->getMonograph();
00205 $stageId =& $this->getStageId();
00206 $notificationKey = null;
00207
00208 switch ($this->getCurrentTab()) {
00209
00210 case 'submission':
00211 import('controllers.modals.submissionMetadata.form.CatalogEntrySubmissionReviewForm');
00212 $form = new CatalogEntrySubmissionReviewForm($monograph->getId(), $stageId, array('displayedInContainer' => true));
00213 $notificationKey = 'notification.savedSubmissionMetadata';
00214 break;
00215 case 'catalog':
00216 import('controllers.tab.catalogEntry.form.CatalogEntryCatalogMetadataForm');
00217 $user =& $request->getUser();
00218 $form = new CatalogEntryCatalogMetadataForm($monograph->getId(), $user->getId(), $stageId, array('displayedInContainer' => true, 'tabPos' => $this->getTabPosition()));
00219 $notificationKey = 'notification.savedCatalogMetadata';
00220 MonographLog::logEvent($request, $monograph, MONOGRAPH_LOG_CATALOG_METADATA_UPDATE, 'submission.event.catalogMetadataUpdated');
00221 break;
00222 default:
00223 import('controllers.tab.catalogEntry.form.CatalogEntryPublicationMetadataForm');
00224 $publicationFormatId =& $request->getUserVar('publicationFormatId');
00225
00226
00227 $publishedMonographDao =& DAORegistry::getDAO('PublishedMonographDAO');
00228 $publicationFormatDao =& DAORegistry::getDAO('PublicationFormatDAO');
00229 $publishedMonograph =& $publishedMonographDao->getById($monograph->getId());
00230 $formats =& $publicationFormatDao->getByMonographId($monograph->getId());
00231 $form = null;
00232 while ($format =& $formats->next()) {
00233 if ($format->getId() == $publicationFormatId) {
00234 $form = new CatalogEntryPublicationMetadataForm($monograph->getId(), $publicationFormatId, $format->getId(), $stageId, array('displayedInContainer' => true, 'tabPos' => $this->getTabPosition()));
00235 $notificationKey = 'notification.savedPublicationFormatMetadata';
00236 MonographLog::logEvent($request, $monograph, MONOGRAPH_LOG_PUBLICATION_FORMAT_METADATA_UPDATE, 'submission.event.publicationMetadataUpdated', array('formatName' => $format->getLocalizedName()));
00237 break;
00238 }
00239 }
00240 break;
00241 }
00242
00243 if ($form) {
00244 $form->readInputData($request);
00245 if($form->validate()) {
00246 $form->execute($request);
00247
00248 $notificationManager = new NotificationManager();
00249 $user =& $request->getUser();
00250 $notificationManager->createTrivialNotification($user->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __($notificationKey)));
00251 } else {
00252
00253 $json->setStatus(true);
00254 $json->setContent($form->fetch($request));
00255 }
00256
00257 if ($request->getUserVar('displayedInContainer')) {
00258 $router =& $request->getRouter();
00259 $dispatcher =& $router->getDispatcher();
00260 $url = $dispatcher->url($request, ROUTE_COMPONENT, null, 'modals.submissionMetadata.CatalogEntryHandler', 'fetch', null, array('monographId' => $monograph->getId(), 'stageId' => $stageId, 'tabPos' => $this->getTabPosition()));
00261 $json->setAdditionalAttributes(array('reloadContainer' => true, 'tabsUrl' => $url));
00262 $json->setContent(true);
00263 return $json->getString();
00264 } else {
00265 return $json->getString();
00266 }
00267 } else {
00268 fatalError('Unknown or unassigned format id!');
00269 }
00270 }
00271
00278 function uploadCoverImage($args, &$request) {
00279 $router =& $request->getRouter();
00280 $context = $request->getContext();
00281 $user =& $request->getUser();
00282
00283 $monograph =& $this->getMonograph();
00284
00285 import('classes.file.TemporaryFileManager');
00286 $temporaryFileManager = new TemporaryFileManager();
00287 $temporaryFile = $temporaryFileManager->handleUpload('uploadedFile', $user->getId());
00288 if ($temporaryFile) {
00289 $json = new JSONMessage(true);
00290 $json->setAdditionalAttributes(array(
00291 'temporaryFileId' => $temporaryFile->getId()
00292 ));
00293 } else {
00294 $json = new JSONMessage(false, __('common.uploadFailed'));
00295 }
00296
00297 return $json->getString();
00298 }
00299 }
00300
00301 ?>