-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.php
144 lines (132 loc) · 4.35 KB
/
controller.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
namespace Concrete\Package\Ht7C5Base;
use \Concrete\Core\Application\Application;
use \Concrete\Core\Asset\AssetList;
use \Concrete\Core\Foundation\Service\ProviderList;
use \Concrete\Core\Package\Package;
use \Concrete\Core\Package\PackageService;
use \Concrete\Core\User\Group\Group;
use \Concrete\Package\Ht7C5Base\ServiceProvider;
use \Concrete\Package\Ht7C5Base\Ht7Tools\Tabs\ServiceProvider as TabsToolServiceProvider;
defined('C5_EXECUTE') or die('Access Denied.');
class Controller extends Package
{
protected $appVersionRequired = '8.5';
protected $pkgAutoloaderMapCoreExtensions = true;
protected $pkgHandle = 'ht7_c5_base';
protected $pkgVersion = '0.3.0';
/**
* @var \Concrete\Core\Entity\Package
*/
private $pkg;
public function __construct(Application $app)
{
parent::__construct($app);
// On installation, this one will be null, but parent::install() will
// return the current package entity.
$this->pkg = $app->make(PackageService::class)
->getByHandle($this->pkgHandle);
}
public function getPackageDescription()
{
return tc(
'ht7_c5_base',
'Ht7 Starter package which installs some new dashboard pages and more.'
);
}
public function getPackageName()
{
return tc('ht7_c5_base', 'Ht7 c5 Starter');
}
public function install()
{
// Install the current package and create the defined db entities.
$this->pkg = parent::install();
$this->setupAutoloader();
// Make sure the package helper can be accessed by later installation
// process' of this package.
$this->registerServices();
// Create all pages through the content XML.
$this->installContentFile('install.xml');
// If the path uses "-" to separate words and the filename
// uses "_", the cFilename on the Pages table is empty.
// Therefor we need to update this field.
$this->fixFilenames();
$this->installUserGroups();
}
public function on_start()
{
$this->setupAutoloader();
$this->registerAssets();
$this->registerServices();
}
/**
* Make sure the c5 knows the the filenames belonging to the paths defined
* by this package.
*/
private function fixFilenames()
{
$this->app->make('helper/ht7/file/namefixer')
->fixFilenames('/dashboard/ht7', $this->pkg);
}
public function upgrade()
{
parent::upgrade();
// Create all missing pages through the content XML.
$this->installContentFile('install.xml');
}
private function installUserGroups()
{
$gName = tc('ht7_c5_base-group_name', 'ht7');
if (!is_object(Group::getByName($gName))) {
Group::add(
$gName,
tc('ht7_c5_base-group_name', 'Base Group for ht7 applications.'),
false,
$this->pkg
);
}
}
protected function registerAssets(
string $ns = 'assets',
string $keySingle = 'single',
string $keyGroup = 'group'
)
{
$al = AssetList::getInstance();
$assets = $this->getFileConfig()->get($ns);
if (!empty($assets[$keySingle])) {
foreach ($assets[$keySingle] as $asset) {
$al->register(
$asset[0],
$asset[1],
$asset[2],
$asset[3],
$this
);
}
}
if (!empty($assets[$keyGroup])) {
foreach ($assets[$keyGroup] as $name => $assetGroup) {
$al->registerGroup($name, $assetGroup);
}
}
}
/**
* Register the package services, register the package specific ErrorHandler.
*/
private function registerServices()
{
$list = new ProviderList($this->app);
$list->registerProvider(ServiceProvider::class);
$list->registerProvider(TabsToolServiceProvider::class);
}
private function setupAutoloader()
{
if (file_exists($this->getPackagePath() . '/vendor/autoload.php')) {
// Only for development to make sure the package dependencies are
// accessable.
require_once $this->getPackagePath() . '/vendor/autoload.php';
}
}
}