00001 <?php
00002
00015
00016 import('lib.pkp.classes.controllers.grid.GridHandler');
00017
00018
00019
00020 import('controllers.grid.content.navigation.SocialMediaGridCellProvider');
00021 import('controllers.grid.content.navigation.SocialMediaGridRow');
00022
00023
00024 import('lib.pkp.classes.linkAction.request.AjaxModal');
00025
00026 class ManageSocialMediaGridHandler extends GridHandler {
00028 var $_press;
00029
00033 function ManageSocialMediaGridHandler() {
00034 parent::GridHandler();
00035 $this->addRoleAssignment(
00036 array(ROLE_ID_PRESS_MANAGER),
00037 array(
00038 'fetchGrid', 'fetchRow', 'addMedia',
00039 'editMedia', 'updateMedia', 'deleteMedia'
00040 )
00041 );
00042 }
00043
00044
00045
00046
00047
00052 function &getPress() {
00053 return $this->_press;
00054 }
00055
00060 function setPress($press) {
00061 $this->_press =& $press;
00062 }
00063
00064
00065
00066
00067
00074 function authorize(&$request, $args, $roleAssignments) {
00075 import('classes.security.authorization.OmpPressAccessPolicy');
00076 $this->addPolicy(new OmpPressAccessPolicy($request, $roleAssignments));
00077 return parent::authorize($request, $args, $roleAssignments);
00078 }
00079
00080
00081
00082
00083
00084 function initialize(&$request) {
00085 parent::initialize($request);
00086
00087
00088 $this->setPress($request->getPress());
00089
00090
00091 AppLocale::requireComponents(
00092 LOCALE_COMPONENT_PKP_USER,
00093 LOCALE_COMPONENT_OMP_DEFAULT_SETTINGS
00094 );
00095
00096
00097 $this->setTitle('grid.content.navigation.socialMedia');
00098
00099
00100 $router =& $request->getRouter();
00101 $actionArgs = $this->getRequestArgs();
00102 $this->addAction(
00103 new LinkAction(
00104 'addMedia',
00105 new AjaxModal(
00106 $router->url($request, null, null, 'addMedia', null, $actionArgs),
00107 __('grid.content.navigation.socialMedia.addSocialLink'),
00108 'modal_add_item'
00109 ),
00110 __('grid.content.navigation.socialMedia.addSocialLink'),
00111 'add_item'
00112 )
00113 );
00114
00115
00116 $cellProvider = new SocialMediaGridCellProvider();
00117 $this->addColumn(
00118 new GridColumn(
00119 'platform',
00120 'grid.content.navigation.socialMedia.platform',
00121 null,
00122 'controllers/grid/gridCell.tpl',
00123 $cellProvider,
00124 array('width' => 50, 'alignment' => COLUMN_ALIGNMENT_LEFT)
00125 )
00126 );
00127 $this->addColumn(
00128 new GridColumn(
00129 'inCatalog',
00130 'grid.content.navigation.socialMedia.inCatalog',
00131 null,
00132 'controllers/grid/common/cell/checkMarkCell.tpl',
00133 $cellProvider
00134 )
00135 );
00136 }
00137
00138
00139
00140
00141
00146 function &getRowInstance() {
00147 $press =& $this->getPress();
00148 $row = new SocialMediaGridRow($press);
00149 return $row;
00150 }
00151
00156 function getRequestArgs() {
00157 $press =& $this->getPress();
00158 return array(
00159 'pressId' => $press->getId()
00160 );
00161 }
00162
00166 function &loadData($request, $filter = null) {
00167 $press =& $this->getPress();
00168 $socialMediaDao =& DAORegistry::getDAO('SocialMediaDAO');
00169 $data =& $socialMediaDao->getByPressId($press->getId());
00170 return $data->toArray();
00171 }
00172
00173
00174
00175
00176
00177
00178 function addMedia($args, $request) {
00179 return $this->editMedia($args, $request);
00180 }
00181
00188 function editMedia($args, &$request) {
00189
00190 $socialMediaId = (int) $request->getUserVar('socialMediaId');
00191 $press =& $this->getPress();
00192
00193 $socialMediaDao =& DAORegistry::getDAO('SocialMediaDAO');
00194 $socialMedia =& $socialMediaDao->getById($socialMediaId, $press->getId());
00195
00196
00197 import('controllers.grid.content.navigation.form.SocialMediaForm');
00198 $socialMediaForm = new SocialMediaForm($press->getId(), $socialMedia);
00199 $socialMediaForm->initData();
00200
00201 $json = new JSONMessage(true, $socialMediaForm->fetch($request));
00202 return $json->getString();
00203 }
00204
00211 function updateMedia($args, &$request) {
00212
00213 $socialMediaId = (int) $request->getUserVar('socialMediaId');
00214 $press =& $this->getPress();
00215
00216 $socialMediaDao =& DAORegistry::getDAO('SocialMediaDAO');
00217 $socialMedia = $socialMediaDao->getById($socialMediaId, $press->getId());
00218
00219
00220 import('controllers.grid.content.navigation.form.SocialMediaForm');
00221 $socialMediaForm = new SocialMediaForm($press->getId(), $socialMedia);
00222 $socialMediaForm->readInputData();
00223 if ($socialMediaForm->validate()) {
00224 $socialMediaId = $socialMediaForm->execute($request);
00225
00226 if(!isset($socialMedia)) {
00227
00228 $socialMedia =& $socialMediaDao->getById($socialMediaId, $press->getId());
00229
00230 $notificationContent = __('notification.addedSocialMedia');
00231 } else {
00232
00233 $notificationContent = __('notification.editedSocialMedia');
00234 }
00235
00236
00237 $currentUser =& $request->getUser();
00238 $notificationMgr = new NotificationManager();
00239 $notificationMgr->createTrivialNotification($currentUser->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => $notificationContent));
00240
00241
00242 $row =& $this->getRowInstance();
00243 $row->setGridId($this->getId());
00244 $row->setId($socialMediaId);
00245 $row->setData($socialMedia);
00246 $row->initialize($request);
00247
00248
00249 return DAO::getDataChangedEvent();
00250
00251 } else {
00252 $json = new JSONMessage(true, $socialMediaForm->fetch($request));
00253 return $json->getString();
00254 }
00255 }
00256
00263 function deleteMedia($args, &$request) {
00264
00265
00266 $socialMediaId = (int) $request->getUserVar('socialMediaId');
00267
00268 $press =& $this->getPress();
00269
00270 $socialMediaDao =& DAORegistry::getDAO('SocialMediaDAO');
00271 $socialMedia =& $socialMediaDao->getById($socialMediaId, $press->getId());
00272 if (isset($socialMedia)) {
00273 $result = $socialMediaDao->deleteObject($socialMedia);
00274 if ($result) {
00275 $currentUser =& $request->getUser();
00276 $notificationMgr = new NotificationManager();
00277 $notificationMgr->createTrivialNotification($currentUser->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('notification.removedSocialMedia')));
00278 return DAO::getDataChangedEvent();
00279 } else {
00280 $json = new JSONMessage(false, __('manager.setup.errorDeletingItem'));
00281 return $json->getString();
00282 }
00283 } else {
00284 fatalError('Social Media not in current press context.');
00285 }
00286 }
00287 }
00288
00289 ?>