-
Notifications
You must be signed in to change notification settings - Fork 2
/
Plugin.php
163 lines (149 loc) · 5.7 KB
/
Plugin.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
<?php namespace Octobro\Gamify;
use Yaml;
use File;
use Backend;
use System\Classes\PluginBase;
use RainLab\User\Models\User;
use RainLab\User\Controllers\Users as UsersController;
use Octobro\Gamify\Models\LeaderboardLog;
/**
* Gamify Plugin Information File
*/
class Plugin extends PluginBase
{
public $require = ['RainLab.User'];
/**
* Returns information about this plugin.
*
* @return array
*/
public function pluginDetails()
{
return [
'name' => 'Gamify',
'description' => 'No description provided yet...',
'author' => 'Octobro',
'icon' => 'icon-leaf'
];
}
/**
* Boot method, called right before the request route.
*
* @return array
*/
public function boot()
{
User::extend(function($model) {
$model->implement[] = 'Octobro\Gamify\Behaviors\GamifyUser';
});
UsersController::extend(function($controller) {
// Implement behavior if not already implemented
if (!in_array('Backend.Behaviors.RelationController', $controller->implement) && !in_array('Backend\Behaviors\RelationController', $controller->implement)) {
$controller->implement[] = 'Backend.Behaviors.RelationController';
}
// Define property if not already defined
if (!isset($controller->relationConfig)) {
$controller->addDynamicProperty('relationConfig');
}
// Splice in configuration safely
$myConfigPath = '$/octobro/gamify/controllers/users/relationConfig.yaml';
$controller->relationConfig = $controller->mergeConfig(
$controller->relationConfig,
$myConfigPath
);
});
UsersController::extendFormFields(function($form, $model, $context) {
if (!$model instanceof User) return;
$configFile = __DIR__ .'/config/user_fields.yaml';
$config = Yaml::parse(File::get($configFile));
$form->addTabFields($config);
});
}
/**
* Registers any front-end components implemented in this plugin.
*
* @return array
*/
public function registerComponents()
{
return [
'Octobro\Gamify\Components\Leaderboard' => 'leaderboard'
];
}
/**
* Registers back-end navigation items for this plugin.
*
* @return array
*/
public function registerNavigation()
{
return [
'gamify' => [
'label' => 'Gamify',
'url' => Backend::url('octobro/gamify/leaderboardlogs'),
'icon' => 'icon-gamepad',
'permissions' => ['octobro.gamify.*'],
'order' => 500,
'sideMenu' => [
'leaderboardlogs' => [
'label' => 'Leaderboard',
'icon' => 'icon-certificate',
'url' => Backend::url('octobro/gamify/leaderboardlogs'),
'permissions' => ['octobro.gamify.*']
],
'levels' => [
'label' => 'Levels',
'icon' => 'icon-level-up',
'url' => Backend::url('octobro/gamify/levels'),
'permissions' => ['octobro.gamify.*']
],
'achievements' => [
'label' => 'Achievement Logs',
'icon' => 'icon-trophy',
'url' => Backend::url('octobro/gamify/achievements'),
'permissions' => ['octobro.gamify.*']
],
'pointlogs' => [
'label' => 'Point Logs',
'icon' => 'icon-history',
'url' => Backend::url('octobro/gamify/pointlogs'),
'permissions' => ['octobro.gamify.*']
],
'missions' => [
'label' => 'Missions',
'icon' => 'icon-check',
'url' => Backend::url('octobro/gamify/missions'),
'permissions' => ['octobro.gamify.*']
],
'vouchers' => [
'label' => 'Vouchers',
'icon' => 'icon-ticket',
'url' => Backend::url('octobro/gamify/vouchers'),
'permissions' => ['octobro.gamify.*']
],
'rewards' => [
'label' => 'Rewards',
'icon' => 'icon-gift',
'url' => Backend::url('octobro/gamify/rewards'),
'permissions' => ['octobro.gamify.*']
],
'redemptionlogs' => [
'label' => 'Redemption Logs',
'icon' => 'icon-history',
'url' => Backend::url('octobro/gamify/redemptionlogs'),
'permissions' => ['octobro.gamify.*']
],
]
],
];
}
public function registerSchedule($schedule)
{
$schedule->call(function () {
LeaderboardLog::setWeeklyLeaderboard();
})->weekly()->mondays()->at('00:00');
$schedule->call(function () {
LeaderboardLog::setMonthlyLeaderboard();
})->cron('* * 1 * *');
}
}