-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontroller.php
183 lines (156 loc) · 6.71 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php
namespace Concrete\Package\Worldskills;
use \Concrete\Core\Authentication\AuthenticationType;
use \Concrete\Core\Package\Package;
use \Concrete\Core\Page\Theme\Theme;
use \Concrete\Core\Page\Type\PublishTarget\Type\AllType as PageTypePublishTargetAllType;
use \Concrete\Core\Page\Type\PublishTarget\Configuration\AllConfiguration as PageTypePublishTargetAllConfiguration;
use Concrete\Core\Attribute\Key\CollectionKey as CollectionAttributeKey;
use \Concrete\Core\Attribute\Type as AttributeType;
defined('C5_EXECUTE') or die("Access Denied.");
class Controller extends Package
{
protected $pkgHandle = 'worldskills';
protected $appVersionRequired = '5.7.3.1';
protected $pkgVersion = '1.20.0';
protected $pkgAllowsFullContentSwap = true;
protected $pkgAutoloaderMapCoreExtensions = true;
public function getPackageDescription()
{
return t("Theme for WorldSkills Members");
}
public function getPackageName()
{
return t("WorldSkills");
}
public function install()
{
$pkg = parent::install();
$this->configurePackage($pkg);
}
public function upgrade()
{
parent::upgrade();
$pkg = \Package::getByHandle($this->pkgHandle);
$this->configurePackage($pkg);
}
public function configurePackage($pkg)
{
$theme = Theme::getByHandle('worldskills');
if (!is_object($theme)) {
$theme = Theme::add('worldskills', $pkg);
}
// add skill ID attribute
$attributeKey = CollectionAttributeKey::getByHandle('worldskills_skill_id');
if (!is_object($attributeKey)) {
$type = AttributeType::getByHandle('text');
$args = array(
'akHandle' => 'worldskills_skill_id',
'akName' => t('Skill ID'),
'akIsSearchable' => 1,
'akIsSearchableIndexed' => 1,
);
CollectionAttributeKey::add($type, $args, $pkg);
}
// add skill page type
$pageType = \PageType::getByHandle('worldskills_skill');
if (!is_object($pageType)){
$template = \PageTemplate::getByHandle('full');
\PageType::add(array(
'handle' => 'worldskills_skill',
'name' => 'Skill',
'defaultTemplate' => $template,
'allowedTemplates' => 'C',
'templates' => array($template),
'ptLaunchInComposer' => 0,
'ptIsFrequentlyAdded' => 0,
), $pkg)->setConfiguredPageTypePublishTargetObject(new PageTypePublishTargetAllConfiguration(PageTypePublishTargetAllType::getByHandle('all')));
}
// add member ID attribute
$attributeKey = CollectionAttributeKey::getByHandle('worldskills_member_id');
if (!is_object($attributeKey)) {
$type = AttributeType::getByHandle('text');
$args = array(
'akHandle' => 'worldskills_member_id',
'akName' => t('Member ID'),
'akIsSearchable' => 1,
'akIsSearchableIndexed' => 1,
);
CollectionAttributeKey::add($type, $args, $pkg);
}
// add member page type
$pageType = \PageType::getByHandle('worldskills_member');
if (!is_object($pageType)){
$template = \PageTemplate::getByHandle('full');
\PageType::add(array(
'handle' => 'worldskills_member',
'name' => 'Member',
'defaultTemplate' => $template,
'allowedTemplates' => 'C',
'templates' => array($template),
'ptLaunchInComposer' => 0,
'ptIsFrequentlyAdded' => 0,
), $pkg)->setConfiguredPageTypePublishTargetObject(new PageTypePublishTargetAllConfiguration(PageTypePublishTargetAllType::getByHandle('all')));
}
// add skill block
$blockType = \BlockType::getByHandle('worldskills_skill');
if (!is_object($blockType)) {
\BlockType::installBlockTypeFromPackage('worldskills_skill', $pkg);
}
// add skill list block
$blockType = \BlockType::getByHandle('worldskills_skill_list');
if (!is_object($blockType)) {
\BlockType::installBlockTypeFromPackage('worldskills_skill_list', $pkg);
}
// add people block
$blockType = \BlockType::getByHandle('worldskills_people');
if (!is_object($blockType)) {
\BlockType::installBlockTypeFromPackage('worldskills_people', $pkg);
}
// add member block
$blockType = \BlockType::getByHandle('worldskills_member');
if (!is_object($blockType)) {
\BlockType::installBlockTypeFromPackage('worldskills_member', $pkg);
}
// add member list block
$blockType = \BlockType::getByHandle('worldskills_member_list');
if (!is_object($blockType)) {
\BlockType::installBlockTypeFromPackage('worldskills_member_list', $pkg);
}
// add results block
$blockType = \BlockType::getByHandle('worldskills_results');
if (!is_object($blockType)) {
\BlockType::installBlockTypeFromPackage('worldskills_results', $pkg);
}
// add resources block
$blockType = \BlockType::getByHandle('worldskills_resources');
if (!is_object($blockType)) {
\BlockType::installBlockTypeFromPackage('worldskills_resources', $pkg);
}
try {
$authenticationType = AuthenticationType::getByHandle('worldskills');
} catch (\Exception $e) {
$authenticationType = AuthenticationType::add('worldskills', 'WorldSkills Auth', 0, $pkg);
$authenticationType->disable();
}
$page = \SinglePage::add('/dashboard/system/basics/worldskills', $pkg);
if (is_object($page)) {
$page->updateCollectionName('WorldSkills');
}
\Config::save('worldskills.api_url', \Config::get('worldskills.api_url', 'https://api.worldskills.org'));
\Config::save('worldskills.authorize_url', \Config::get('worldskills.authorize_url', 'https://auth.worldskills.org'));
}
public function on_start()
{
$app = \Core::make('app');
$provider = new \Concrete\Package\Worldskills\Authentication\ServiceProvider($app);
$provider->register();
$accessTokenCheck = $app->make('worldskills/accesss_token_check');
\Events::addListener('on_start', array($accessTokenCheck, 'checkAccessToken'));
// grid framework
$manager = $app->make('manager/grid_framework');
$manager->extend('bootstrap4', function($app) {
return new \Concrete\Package\Worldskills\GridFramework\Bootstrap4();
});
}
}