Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
Handler.inc.php
1 <?php
2 
17 import('lib.pkp.classes.handler.PKPHandler');
18 import('classes.handler.validation.HandlerValidatorPress');
19 
20 class Handler extends PKPHandler {
24  function Handler() {
25  parent::PKPHandler();
26  }
27 
33  function getWorkingContexts($request) {
34  // For installation process
35  if (defined('SESSION_DISABLE_INIT') || !Config::getVar('general', 'installed')) {
36  return null;
37  }
38 
39  // Check for multiple presses.
40  $pressDao = DAORegistry::getDAO('PressDAO');
41 
42  $user = $request->getUser();
43  if (is_a($user, 'User')) {
44  return $pressDao->getAll();
45  } else {
46  return $pressDao->getEnabledPresses();
47  }
48  }
49 
58  function getTargetContext($request, $bestGuess = true) {
59  // Get the requested path.
60  $router = $request->getRouter();
61  $requestedPath = $router->getRequestedContextPath($request);
62  $press = null;
63 
64  if ($requestedPath === 'index' || $requestedPath === '') {
65  // No press requested. Check how many presses has the site.
66  $pressDao = DAORegistry::getDAO('PressDAO'); /* @var $pressDao PressDAO */
67  $presses = $pressDao->getAll();
68  $pressesCount = $presses->getCount();
69  $press = null;
70  if ($pressesCount === 1) {
71  // Return the unique press.
72  $press = $presses->next();
73  }
74  if (!$press && $pressesCount > 1) {
75  // Decide wich press to return.
76  $user = $request->getUser();
77  if ($user && $bestGuess) {
78  // We have a user (private access).
79  $press = $this->getFirstUserContext($user, $presses->toArray());
80  }
81  if (!$press) {
82  // Get the site redirect.
83  $press = $this->getSiteRedirectContext($request);
84  }
85  }
86  } else {
87  // Return the requested press.
88  $press = $router->getContext($request);
89  }
90  if (is_a($press, 'Press')) {
91  return $press;
92  }
93  return null;
94  }
95 
101  function getSiteRedirectContext($request) {
102  $pressDao = DAORegistry::getDAO('PressDAO'); /* @var $pressDao PressDAO */
103  $site = $request->getSite();
104  $press = null;
105  if ($site) {
106  if($site->getRedirect()) {
107  $press = $pressDao->getById($site->getRedirect());
108  }
109  }
110  return $press;
111  }
112 }
113 
114 ?>
static & getDAO($name, $dbconn=null)
getTargetContext($request, $bestGuess=true)
Definition: Handler.inc.php:58
static getVar($section, $key, $default=null)
Definition: Config.inc.php:35
getWorkingContexts($request)
Definition: Handler.inc.php:33
Base request handler application class.
Definition: Handler.inc.php:20
getSiteRedirectContext($request)
getFirstUserContext($user, $contexts)