Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
PressGridHandler.inc.php
1 <?php
2 
16 import('lib.pkp.controllers.grid.admin.context.ContextGridHandler');
17 import('controllers.grid.admin.press.form.PressSiteSettingsForm');
18 
23  function PressGridHandler() {
24  parent::ContextGridHandler();
25  }
26 
27 
28  //
29  // Public grid actions.
30  //
37  function editContext($args, $request) {
38 
39  // Identify the press Id.
40  $pressId = $request->getUserVar('rowId');
41 
42  // Form handling.
43  $settingsForm = new PressSiteSettingsForm(!isset($pressId) || empty($pressId) ? null : $pressId);
44  $settingsForm->initData();
45  $json = new JSONMessage(true, $settingsForm->fetch($args, $request));
46 
47  return $json->getString();
48  }
49 
56  function updateContext($args, $request) {
57  // Identify the press Id.
58  $pressId = $request->getUserVar('contextId');
59 
60  // Form handling.
61  $settingsForm = new PressSiteSettingsForm($pressId);
62  $settingsForm->readInputData();
63 
64  if ($settingsForm->validate()) {
66 
67  // The press settings form will return a press path in two cases:
68  // 1 - if a new press was created;
69  // 2 - if a press path of an existing press was edited.
70  $newPressPath = $settingsForm->execute($request);
71 
72  // Create the notification.
73  $notificationMgr = new NotificationManager();
74  $user = $request->getUser();
75  $notificationMgr->createTrivialNotification($user->getId());
76 
77  // Check for the two cases above.
78  if ($newPressPath) {
79  $context = $request->getContext();
80 
81  if (is_null($pressId)) {
82  // CASE 1: new press created.
83  // Create notification related to payment method configuration.
84  $pressDao = DAORegistry::getDAO('PressDAO');
85  $newPress =& $pressDao->getByPath($newPressPath);
86  $notificationMgr->createNotification($request, null, NOTIFICATION_TYPE_CONFIGURE_PAYMENT_METHOD,
87  $newPress->getId(), ASSOC_TYPE_PRESS, $newPress->getId(), NOTIFICATION_LEVEL_NORMAL);
88 
89  // redirect and set the parameter to open the press
90  // setting wizard modal after redirection.
91  return $this->_getRedirectEvent($request, $newPressPath, true);
92  } else {
93  // CASE 2: check if user is in the context of
94  // the press being edited.
95  if ($context->getId() == $pressId) {
96  return $this->_getRedirectEvent($request, $newPressPath, false);
97  }
98  }
99  }
100  return DAO::getDataChangedEvent($pressId);
101  } else {
102  $json = new JSONMessage(false);
103  }
104  return $json->getString();
105  }
106 
113  function deleteContext($args, $request) {
114  // Identify the current context.
115  $context = $request->getContext();
116 
117  // Identify the press Id.
118  $pressId = $request->getUserVar('rowId');
119  $pressDao = DAORegistry::getDAO('PressDAO');
120  $press = $pressDao->getById($pressId);
121 
122  $json = new JSONMessage();
123 
124  if ($pressId) {
125  $pressDao->deleteById($pressId);
126  // Add publication formats tombstones for all press published monographs.
127  import('classes.publicationFormat.PublicationFormatTombstoneManager');
128  $publicationFormatTombstoneMgr = new PublicationFormatTombstoneManager();
129  $publicationFormatTombstoneMgr->insertTombstonesByPress($press);
130 
131  // Delete press file tree
132  // FIXME move this somewhere better.
133  import('lib.pkp.classes.file.ContextFileManager');
134  $pressFileManager = new ContextFileManager($pressId);
135  $pressFileManager->rmtree($pressFileManager->getBasePath());
136 
137  import('classes.file.PublicFileManager');
138  $publicFileManager = new PublicFileManager();
139  $publicFileManager->rmtree($publicFileManager->getPressFilesPath($pressId));
140 
141  // If user is deleting the same press where he is...
142  if($context && $context->getId() == $pressId) {
143  // return a redirect js event to index handler.
144  $dispatcher = $request->getDispatcher();
145  $url = $dispatcher->url($request, ROUTE_PAGE, null, 'index');
146  return $request->redirectUrlJson($url);
147  }
148 
149  return DAO::getDataChangedEvent($pressId);
150  }
151 
152  return $json->getString();
153  }
154 }
155 
156 ?>
static & getDAO($name, $dbconn=null)
Wrapper class for uploading files to a site/press&#39; public directory.
Class defining operations for private context file management.
static & loadCategory($category, $enabledOnly=false, $mainContextId=null)
Handle press grid requests.
Class to represent a JSON (Javascript Object Notation) message.
Class defining basic operations for publication format tombstones.
static getDataChangedEvent($elementId=null, $parentElementId=null)
Definition: DAO.inc.php:606
_getRedirectEvent($request, $newContextPath, $openWizard)
editContext($args, $request)
Form for site administrator to edit basic press settings.
Handle context grid requests.
updateContext($args, $request)
deleteContext($args, $request)