00001 <?php
00002
00015
00016 import('lib.pkp.classes.controllers.grid.CategoryGridHandler');
00017 import('lib.pkp.classes.controllers.grid.DataObjectGridCellProvider');
00018
00019
00020 import('controllers.grid.settings.category.CategoryGridCategoryRow');
00021
00022
00023 import('lib.pkp.classes.linkAction.request.AjaxModal');
00024
00025 class CategoryCategoryGridHandler extends CategoryGridHandler {
00026 var $_pressId;
00027
00031 function CategoryCategoryGridHandler() {
00032 parent::CategoryGridHandler();
00033 $this->addRoleAssignment(
00034 array(ROLE_ID_PRESS_MANAGER),
00035 array(
00036 'fetchGrid',
00037 'fetchCategory',
00038 'fetchRow',
00039 'addCategory',
00040 'editCategory',
00041 'updateCategory',
00042 'deleteCategory',
00043 'uploadImage'
00044 )
00045 );
00046 }
00047
00048
00049
00050
00057 function authorize(&$request, $args, $roleAssignments) {
00058 import('classes.security.authorization.OmpPressAccessPolicy');
00059 $this->addPolicy(new OmpPressAccessPolicy($request, $roleAssignments));
00060 return parent::authorize($request, $args, $roleAssignments);
00061 }
00062
00063
00069 function initialize(&$request) {
00070
00071 parent::initialize($request);
00072
00073 $press =& $request->getPress();
00074 $this->_pressId =& $press->getId();
00075
00076 AppLocale::requireComponents(LOCALE_COMPONENT_OMP_MANAGER);
00077
00078
00079 $this->setTitle('grid.category.categories');
00080
00081 $this->setInstructions('manager.setup.categories.description');
00082
00083
00084 $router =& $request->getRouter();
00085 $this->addAction(
00086 new LinkAction(
00087 'addCategory',
00088 new AjaxModal(
00089 $router->url($request, null, null, 'addCategory'),
00090 __('grid.category.add'),
00091 'modal_manage'
00092 ),
00093 __('grid.category.add'),
00094 'add_category'
00095 )
00096 );
00097
00098
00099 $cellProvider = new DataObjectGridCellProvider();
00100 $cellProvider->setLocale(AppLocale::getLocale());
00101
00102 $this->addColumn(
00103 new GridColumn(
00104 'title',
00105 'grid.category.name',
00106 null,
00107 'controllers/grid/gridCell.tpl',
00108 $cellProvider
00109 )
00110 );
00111 }
00112
00116 function &loadData($request, $filter) {
00117
00118 $categoryDao =& DAORegistry::getDAO('CategoryDAO');
00119 $categoriesIterator =& $categoryDao->getByParentId(null, $this->_getPressId());
00120
00121 $categories = array();
00122 while ($category =& $categoriesIterator->next()) {
00123 $categories[$category->getId()] =& $category;
00124 unset($category);
00125 }
00126
00127 return $categories;
00128 }
00129
00133 function getCategoryRowIdParameterName() {
00134 return 'parentCategoryId';
00135 }
00136
00141 function &getRowInstance() {
00142 import('controllers.grid.settings.category.CategoryGridRow');
00143 $row = new CategoryGridRow();
00144 return $row;
00145 }
00146
00151 function &getCategoryRowInstance() {
00152 $row = new CategoryGridCategoryRow();
00153 return $row;
00154 }
00155
00159 function getCategoryData(&$category) {
00160 $categoryId = $category->getId();
00161 $categoryDao =& DAORegistry::getDAO('CategoryDAO');
00162 $categoriesIterator =& $categoryDao->getByParentId($categoryId, $this->_getPressId());
00163 $categories = $categoriesIterator->toAssociativeArray();
00164 return $categories;
00165 }
00166
00172 function addCategory($args, &$request) {
00173 return $this->editCategory($args, $request);
00174 }
00175
00181 function editCategory($args, &$request) {
00182 $categoryForm = $this->_getCategoryForm($request);
00183
00184 $categoryForm->initData();
00185
00186 $json = new JSONMessage(true, $categoryForm->fetch($request));
00187 return $json->getString();
00188 }
00189
00195 function updateCategory($args, &$request) {
00196 $categoryForm = $this->_getCategoryForm($request);
00197
00198 $categoryForm->readInputData();
00199 if($categoryForm->validate()) {
00200 $category = $categoryForm->execute($request);
00201 return DAO::getDataChangedEvent();
00202 } else {
00203 $json = new JSONMessage(true, $categoryForm->fetch($request));
00204 return $json->getString();
00205 }
00206 }
00207
00214 function deleteCategory($args, &$request) {
00215
00216 $categoryDao =& DAORegistry::getDAO('CategoryDAO');
00217 $press =& $request->getPress();
00218 $category =& $categoryDao->getById(
00219 $request->getUserVar('categoryId'),
00220 $press->getId()
00221 );
00222 $categoryId = $category->getId();
00223
00224
00225
00226
00227 $categoryDao->deleteObject($category);
00228 return DAO::getDataChangedEvent($category->getId(), $category->getParentId());
00229 }
00230
00236 function uploadImage($args, &$request) {
00237 $router =& $request->getRouter();
00238 $context = $request->getContext();
00239 $user =& $request->getUser();
00240
00241 import('classes.file.TemporaryFileManager');
00242 $temporaryFileManager = new TemporaryFileManager();
00243 $temporaryFile = $temporaryFileManager->handleUpload('uploadedFile', $user->getId());
00244 if ($temporaryFile) {
00245 $json = new JSONMessage(true);
00246 $json->setAdditionalAttributes(array(
00247 'temporaryFileId' => $temporaryFile->getId()
00248 ));
00249 } else {
00250 $json = new JSONMessage(false, __('common.uploadFailed'));
00251 }
00252
00253 return $json->getString();
00254 }
00255
00256
00257
00258
00264 function _getCategoryForm(&$request) {
00265
00266 $categoryId = (int) $request->getUserVar('categoryId');
00267
00268
00269 import('controllers.grid.settings.category.form.CategoryForm');
00270 $pressId = $this->_getPressId();
00271 return new CategoryForm($pressId, $categoryId);
00272 }
00273
00278 function _getPressId() {
00279 return $this->_pressId;
00280 }
00281 }
00282
00283 ?>