00001 <?php
00002
00015
00016 import('lib.pkp.classes.controllers.grid.CategoryGridHandler');
00017
00018
00019
00020 import('controllers.grid.content.navigation.FooterGridCellProvider');
00021 import('controllers.grid.content.navigation.FooterGridCategoryRow');
00022 import('controllers.grid.content.navigation.form.FooterCategoryForm');
00023
00024
00025 import('lib.pkp.classes.linkAction.request.AjaxModal');
00026
00027 class ManageFooterGridHandler extends CategoryGridHandler {
00031 var $_press;
00032
00036 function ManageFooterGridHandler() {
00037 parent::CategoryGridHandler();
00038 $this->addRoleAssignment(
00039 array(ROLE_ID_PRESS_MANAGER),
00040 array('fetchGrid', 'fetchCategory', 'fetchRow', 'addFooterCategory',
00041 'editFooterCategory', 'updateFooterCategory', 'deleteFooterCategory'));
00042 }
00043
00044
00045
00046
00051 function &getPress() {
00052 return $this->_press;
00053 }
00054
00059 function setPress($press) {
00060 $this->_press =& $press;
00061 }
00062
00063
00064
00065
00072 function authorize(&$request, $args, $roleAssignments) {
00073 import('classes.security.authorization.OmpPressAccessPolicy');
00074 $this->addPolicy(new OmpPressAccessPolicy($request, $roleAssignments));
00075 $returner = parent::authorize($request, $args, $roleAssignments);
00076
00077 $footerLinkId = $request->getUserVar('footerLinkId');
00078 if ($footerLinkId) {
00079 $press =& $request->getPress();
00080 $footerLinkDao =& DAORegistry::getDAO('FooterLinkDAO');
00081 $footerLink =& $footerLinkDao->getById($footerLinkId, $press->getId());
00082 if (!isset($footerLink)) {
00083 return false;
00084 }
00085 }
00086
00087 return $returner;
00088 }
00089
00090
00091
00092
00093
00094 function initialize(&$request) {
00095 parent::initialize($request);
00096
00097
00098 $this->setTitle('grid.content.navigation.footer');
00099
00100
00101 $this->setEmptyRowText('grid.content.navigation.footer.noneExist');
00102
00103 $press =& $request->getPress();
00104 $this->setPress($press);
00105
00106
00107 import('controllers.grid.content.navigation.FooterGridCellProvider');
00108 $footerLinksGridCellProvider = new FooterGridCellProvider();
00109
00110 $gridColumn = new GridColumn(
00111 'title',
00112 'common.title',
00113 null,
00114 'controllers/grid/gridCell.tpl',
00115 $footerLinksGridCellProvider,
00116 array()
00117 );
00118
00119 $gridColumn->addFlag('html', true);
00120 $this->addColumn($gridColumn);
00121
00122
00123 $router =& $request->getRouter();
00124 import('lib.pkp.classes.linkAction.request.AjaxModal');
00125 $this->addAction(
00126 new LinkAction(
00127 'addFooterCategoryLink',
00128 new AjaxModal(
00129 $router->url($request, null, null, 'addFooterCategory', null, null),
00130 __('grid.content.navigation.footer.addCategory'),
00131 'modal_add_item',
00132 true
00133 ),
00134 __('grid.content.navigation.footer.addCategory'),
00135 'add_item')
00136 );
00137 }
00138
00139
00140
00141
00142
00143
00148 function &getCategoryRowInstance() {
00149 $row = new FooterGridCategoryRow();
00150 return $row;
00151 }
00152
00156 function getCategoryData($category) {
00157
00158 $footerLinkDao =& DAORegistry::getDAO('FooterLinkDAO');
00159 $press =& $this->getPress();
00160 $footerLinks =& $footerLinkDao->getByCategoryId($category->getId(), $press->getId());
00161 return $footerLinks->toArray();
00162 }
00163
00167 function getCategoryRowIdParameterName() {
00168 return 'footerCategoryId';
00169 }
00170
00176 function getRequestArgs() {
00177 $press =& $this->getPress();
00178 return array_merge(
00179 parent::getRequestArgs(),
00180 array('pressId' => $press->getId())
00181 );
00182 }
00183
00187 function loadData($request, $filter = null) {
00188
00189 $footerCategoryDao =& DAORegistry::getDAO('FooterCategoryDAO');
00190 $press =& $this->getPress();
00191 $categories =& $footerCategoryDao->getByPressId($press->getId());
00192 $data = array();
00193 while ($category =& $categories->next()) {
00194 $data[ $category->getId() ] = $category;
00195 }
00196
00197 return $data;
00198 }
00199
00200
00201
00202
00203
00204
00211 function addFooterCategory($args, &$request) {
00212 return $this->editFooterCategory($args, $request);
00213 }
00214
00221 function editFooterCategory($args, &$request) {
00222 $footerCategoryId = $request->getUserVar('footerCategoryId');
00223 $footerCategoryDao =& DAORegistry::getDAO('FooterCategoryDAO');
00224 $press =& $request->getPress();
00225
00226 $footerCategory =& $footerCategoryDao->getById($footerCategoryId, $press->getId());
00227 $footerCategoryForm = new FooterCategoryForm($press->getId(), $footerCategory);
00228 $footerCategoryForm->initData($args, $request);
00229
00230 $json = new JSONMessage(true, $footerCategoryForm->fetch($request));
00231 return $json->getString();
00232 }
00233
00240 function updateFooterCategory($args, &$request) {
00241
00242 $footerCategoryId = $request->getUserVar('footerCategoryId');
00243
00244 $press =& $this->getPress();
00245
00246 $footerCategoryDao =& DAORegistry::getDAO('FooterCategoryDAO');
00247 $footerCategory =& $footerCategoryDao->getById($footerCategoryId, $press->getId());
00248
00249
00250 $footerCategoryForm = new FooterCategoryForm($press->getId(), $footerCategory);
00251 $footerCategoryForm->readInputData();
00252 if ($footerCategoryForm->validate()) {
00253 $footerCategoryId = $footerCategoryForm->execute($request);
00254
00255 if(!isset($footerCategory)) {
00256
00257 $footerCategory =& $footerCategoryDao->getById($footerCategoryId, $press->getId());
00258 $notificationContent = __('notification.addedFooterCategory');
00259
00260
00261 $row =& $this->getRowInstance();
00262 $row->setGridId($this->getId());
00263 $row->setId($footerCategoryId);
00264 $row->setData($footerCategory);
00265 $row->initialize($request);
00266 } else {
00267 $notificationContent = __('notification.editedFooterCategory');
00268 }
00269
00270
00271 $currentUser =& $request->getUser();
00272 $notificationMgr = new NotificationManager();
00273 $notificationMgr->createTrivialNotification($currentUser->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => $notificationContent));
00274
00275
00276 return DAO::getDataChangedEvent($footerCategoryId);
00277
00278 } else {
00279 $json = new JSONMessage(true, $footerCategoryForm->fetch($request));
00280 return $json->getString();
00281 }
00282 }
00283
00290 function deleteFooterCategory($args, &$request) {
00291
00292
00293 $footerCategoryId = $request->getUserVar('footerCategoryId');
00294
00295 $footerCategoryDao =& DAORegistry::getDAO('FooterCategoryDAO');
00296 $press =& $this->getPress();
00297 $footerCategory =& $footerCategoryDao->getById($footerCategoryId, $press->getId());
00298 if (isset($footerCategory)) {
00299
00300
00301 $footerLinkDao =& DAORegistry::getDAO('FooterLinkDAO');
00302 $footerLinks =& $footerLinkDao->getByCategoryId($footerCategoryId, $press->getId());
00303 while ($footerLink =& $footerLinks->next()) {
00304 $footerLinkDao->deleteObject($footerLink);
00305 }
00306
00307 $result = $footerCategoryDao->deleteObject($footerCategory);
00308
00309 if ($result) {
00310 $currentUser =& $request->getUser();
00311 $notificationMgr = new NotificationManager();
00312 $notificationMgr->createTrivialNotification($currentUser->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('notification.removedFooterCategory')));
00313 return DAO::getDataChangedEvent($footerCategoryId);
00314 } else {
00315 $json = new JSONMessage(false, __('manager.setup.errorDeletingItem'));
00316 return $json->getString();
00317 }
00318 }
00319 }
00320 }
00321 ?>