00001 <?php
00002
00015 import('lib.pkp.classes.controllers.grid.CategoryGridHandler');
00016 import('controllers.grid.files.LibraryFileGridRow');
00017 import('controllers.grid.files.LibraryFileGridCategoryRow');
00018 import('classes.file.LibraryFileManager');
00019
00020
00021 import('classes.press.LibraryFile');
00022
00023
00024 import('lib.pkp.classes.linkAction.request.AjaxModal');
00025
00026 class LibraryFileGridHandler extends CategoryGridHandler {
00028 var $_context;
00029
00031 var $_canEdit;
00032
00036 function LibraryFileGridHandler($dataProvider) {
00037 parent::CategoryGridHandler($dataProvider);
00038 $this->addRoleAssignment(
00039 array(ROLE_ID_PRESS_MANAGER, ROLE_ID_SERIES_EDITOR, ROLE_ID_PRESS_ASSISTANT, ROLE_ID_AUTHOR),
00040 array(
00041 'fetchGrid', 'fetchCategory', 'fetchRow',
00042 )
00043 );
00044 }
00045
00046
00047
00048
00049
00054 function getContext() {
00055 return $this->_context;
00056 }
00057
00062 function canEdit() {
00063 return $this->_canEdit;
00064 }
00065
00070 function setCanEdit($canEdit) {
00071 $this->_canEdit = $canEdit;
00072 }
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 function initialize(&$request) {
00083 parent::initialize($request);
00084
00085 $router =& $request->getRouter();
00086 $this->_context =& $router->getContext($request);
00087
00088
00089 $this->setTitle('manager.setup.submissionDocuments');
00090
00091 AppLocale::requireComponents(
00092 LOCALE_COMPONENT_PKP_COMMON,
00093 LOCALE_COMPONENT_APPLICATION_COMMON,
00094 LOCALE_COMPONENT_PKP_SUBMISSION,
00095 LOCALE_COMPONENT_OMP_MANAGER,
00096 LOCALE_COMPONENT_OMP_SUBMISSION
00097 );
00098
00099
00100
00101 $this->addColumn($this->getFileNameColumn());
00102
00103 $router =& $request->getRouter();
00104
00105
00106 if ($this->canEdit()) {
00107 $this->addAction(
00108 new LinkAction(
00109 'addFile',
00110 new AjaxModal(
00111 $router->url($request, null, null, 'addFile', null, $this->getActionArgs()),
00112 __('grid.action.addFile'),
00113 'modal_add_file'
00114 ),
00115 __('grid.action.addFile'),
00116 'add'
00117 )
00118 );
00119 }
00120 }
00121
00122
00123
00124
00128 function &getCategoryRowInstance() {
00129 $row = new LibraryFileGridCategoryRow($this->getContext());
00130 return $row;
00131 }
00132
00136 function loadData($request, $filter) {
00137
00138 $context = $this->getContext();
00139 $libraryFileManager = new LibraryFileManager($context->getId());
00140 $fileTypeKeys = $libraryFileManager->getTypeSuffixMap();
00141 foreach (array_keys($fileTypeKeys) as $key) {
00142 $data[$key] = $key;
00143 }
00144 return $data;
00145 }
00146
00147
00148
00149
00154 function &getRowInstance() {
00155 $row = new LibraryFileGridRow($this->canEdit());
00156 return $row;
00157 }
00158
00163 function &getFileNameColumn() {
00164 import('controllers.grid.files.LibraryFileGridCellProvider');
00165 $column = new GridColumn(
00166 'files',
00167 'grid.libraryFiles.column.files',
00168 null,
00169 'controllers/grid/gridCell.tpl',
00170 new LibraryFileGridCellProvider()
00171 );
00172
00173 return $column;
00174 }
00175
00176
00177
00178
00184 function addFile($args, &$request) {
00185 $this->initialize($request);
00186 $router = $request->getRouter();
00187 $context = $request->getContext();
00188
00189 $fileForm = $this->_getNewFileForm($context);
00190 $fileForm->initData();
00191
00192 $json = new JSONMessage(true, $fileForm->fetch($request));
00193 return $json->getString();
00194 }
00195
00202 function saveFile($args, &$request) {
00203 $router =& $request->getRouter();
00204 $context = $request->getContext();
00205 $user =& $request->getUser();
00206
00207 $fileForm = $this->_getNewFileForm($context);
00208 $fileForm->readInputData();
00209
00210 if ($fileForm->validate()) {
00211 $fileId = $fileForm->execute($user->getId());
00212
00213
00214 return DAO::getDataChangedEvent();
00215 }
00216
00217 $json = new JSONMessage(false);
00218 return $json->getString();
00219 }
00220
00227 function editFile($args, &$request) {
00228 $this->initialize($request);
00229 assert(isset($args['fileId']));
00230 $fileId = (int) $args['fileId'];
00231
00232 $router = $request->getRouter();
00233 $context = $request->getContext();
00234
00235 $fileForm = $this->_getEditFileForm($context, $fileId);
00236 $fileForm->initData();
00237
00238 $json = new JSONMessage(true, $fileForm->fetch($request));
00239 return $json->getString();
00240 }
00241
00248 function updateFile($args, &$request) {
00249 assert(isset($args['fileId']));
00250 $fileId = (int) $args['fileId'];
00251
00252 $router =& $request->getRouter();
00253 $context = $request->getContext();
00254
00255 $fileForm = $this->_getEditFileForm($context, $fileId);
00256 $fileForm->readInputData();
00257
00258 if ($fileForm->validate()) {
00259 $fileForm->execute();
00260
00261
00262 return DAO::getDataChangedEvent();
00263 }
00264
00265 $json = new JSONMessage(false);
00266 return $json->getString();
00267 }
00268
00275 function deleteFile($args, &$request) {
00276 $fileId = isset($args['fileId']) ? $args['fileId'] : null;
00277 $router =& $request->getRouter();
00278 $press =& $router->getContext($request);
00279
00280 if ($fileId) {
00281 import('classes.file.LibraryFileManager');
00282 $libraryFileManager = new LibraryFileManager($press->getId());
00283 $libraryFileManager->deleteFile($fileId);
00284
00285 return DAO::getDataChangedEvent();
00286 }
00287
00288 $json = new JSONMessage(false);
00289 return $json->getString();
00290 }
00291
00298 function uploadFile($args, &$request) {
00299 $router =& $request->getRouter();
00300 $context = $request->getContext();
00301 $user =& $request->getUser();
00302
00303 import('classes.file.TemporaryFileManager');
00304 $temporaryFileManager = new TemporaryFileManager();
00305 $temporaryFile = $temporaryFileManager->handleUpload('uploadedFile', $user->getId());
00306 if ($temporaryFile) {
00307 $json = new JSONMessage(true);
00308 $json->setAdditionalAttributes(array(
00309 'temporaryFileId' => $temporaryFile->getId()
00310 ));
00311 } else {
00312 $json = new JSONMessage(false, __('common.uploadFailed'));
00313 }
00314
00315 return $json->getString();
00316 }
00317
00323 function &_getNewFileForm($context){
00324 assert(false);
00325 }
00326
00333 function &_getEditFileForm($context, $fileId){
00334 assert(false);
00335 }
00336
00341 function getActionArgs() {
00342 return array();
00343 }
00344 }
00345
00346 ?>