forked from AppStateESS/counseling
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Module.php
73 lines (65 loc) · 2.07 KB
/
Module.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
namespace counseling;
/**
* @license http://opensource.org/licenses/lgpl-3.0.html
* @author Matthew McNaney <mcnaney at gmail dot com>
*/
class Module extends \Canopy\Module
{
public function __construct()
{
$autoload = PHPWS_SOURCE_DIR . 'mod/counseling/vendor/autoload.php';
if (!is_file($autoload)) {
exit('Counseling requires "composer install" to be run in module directory');
}
require_once $autoload;
parent::__construct();
$this->setTitle('counseling');
$this->setProperName('Counseling Center Check-In');
}
public function beforeRun(\Canopy\Request $request, \Canopy\Controller $controller)
{
$this->checkDefine();
}
private function checkDefine()
{
static $checked = false;
if ($checked) {
return;
}
$define_file = PHPWS_SOURCE_DIR . 'mod/counseling/conf/defines.php';
if (!is_file($define_file)) {
exit('Counseling requires a copy of conf/defines.php to be created.');
}
$checked = true;
require_once $define_file;
require_once PHPWS_SOURCE_DIR . 'mod/counseling/conf/system_defines.php';
}
public function getController(\Canopy\Request $request)
{
$cmd = $request->shiftCommand();
if ($cmd == 'Admin') {
if (\Current_User::allow('counseling')) {
$admin = new \counseling\Controller\Admin($this);
return $admin;
} else {
\Current_User::requireLogin();
}
} else {
$user = new \counseling\Controller\User($this);
return $user;
}
}
public function runTime(\Canopy\Request $request)
{
$this->checkDefine();
if (\PHPWS_Core::atHome()) {
$user = new \counseling\Controller\User($this);
$content = $user->checkin();
\Layout::add($content);
}
if (\Current_User::allow('counseling')) {
\counseling\Controller\Admin::loadAdminBar();
}
}
}