-
Notifications
You must be signed in to change notification settings - Fork 1
/
controller.php
125 lines (111 loc) · 2.86 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
<?php
/**
* Class Controller.
*
* @author: Biplob Hossain <[email protected]>
*
* @license MIT
*/
namespace Concrete\Package\C5jRatings;
use C5jRatings\EventListener\PageEventListener;
use C5jRatings\EventListener\UserEventListener;
use Concrete\Core\Asset\Asset;
use Concrete\Core\Asset\AssetList;
use Concrete\Core\Backup\ContentImporter;
use Concrete\Core\Package\Package;
class Controller extends Package
{
/**
* @var string package handle
*/
protected $pkgHandle = 'c5j_ratings';
/**
* @var string required concrete5 version
*/
protected $appVersionRequired = '8.5.0';
/**
* @var string package version
*/
protected $pkgVersion = '1.0.2';
protected $pkgAutoloaderRegistries = [
'src' => '\C5jRatings',
];
/**
* @return string Package name
*/
public function getPackageName(): string
{
return t('Macareux Ratings');
}
/**
* @return string Package description
*/
public function getPackageDescription(): string
{
return t('Adds a rating button block');
}
/**
* Package installation process.
*/
public function install()
{
parent::install();
$this->installXml();
}
/**
* Package upgrade process.
*/
public function upgrade()
{
parent::upgrade();
$this->installXml();
}
public function on_start(): void
{
$this->registerAssets();
$director = $this->app->make('director');
$director->addListener('on_page_delete', function ($e) {
$ratingPageEvent = $this->app->make(PageEventListener::class);
$ratingPageEvent->onPageDelete($e);
});
$director->addListener('on_user_delete', function ($e) {
$ratingUserEvent = $this->app->make(UserEventListener::class);
$ratingUserEvent->onUserDelete($e);
});
}
private function installXml(): void
{
$ci = new ContentImporter();
$ci->importContentFile($this->getPackagePath() . '/config/install.xml');
}
private function registerAssets(): void
{
$al = AssetList::getInstance();
$al->register(
'css',
'c5j_ratings',
'css/c5j_ratings.css',
['position' => Asset::ASSET_POSITION_HEADER],
'c5j_ratings'
);
$al->register(
'javascript',
'client',
'js/client.base.min.js',
['position' => Asset::ASSET_POSITION_FOOTER],
'c5j_ratings'
);
$al->register(
'javascript',
'c5j_ratings',
'js/c5j_ratings.js',
['position' => Asset::ASSET_POSITION_FOOTER],
'c5j_ratings'
);
$al->registerGroup('c5j_ratings', [
['css', 'c5j_ratings'],
['javascript', 'client'],
['javascript', 'c5j_ratings'],
]);
}
}