-
Notifications
You must be signed in to change notification settings - Fork 12
/
Module.php
355 lines (317 loc) · 11 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
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
<?php namespace Clake\UserExtended;
use Clake\UserExtended\Classes\Helpers;
use Clake\UserExtended\Classes\UserGroupManager;
use Clake\UserExtended\Classes\UserManager;
use Clake\UserExtended\Classes\UserRoleManager;
use Clake\UserExtended\Classes\UserSettingsManager;
use Clake\UserExtended\Classes\UserUtil;
use Clake\Userextended\Models\Friend;
use Clake\UserExtended\Traits\StaticFactoryTrait;
use Clake\UserExtended\Classes\UserExtended;
use Backend;
/**
* User Extended Core by Shawn Clake
* Class Module
* User Extended is licensed under the MIT license.
*
* @author Shawn Clake <shawn.clake@gmail.com>
* @link https://github.com/ShawnClake/UserExtended
*
* @license https://github.com/ShawnClake/UserExtended/blob/master/LICENSE MIT
* @package Clake\UserExtended
*/
class Module extends UserExtended
{
use StaticFactoryTrait;
public $name = "clakeUserExtended";
public $author = "Shawn Clake";
public $description = "User Extended Core contains all of the components, navigation, assets, utility functions, and documentation which User Extended depends on.";
public $version = "2.2.00";
public function initialize() {}
public function injectComponents()
{
return [
'Clake\UserExtended\Components\Account' => 'account',
'Clake\UserExtended\Components\Friends' => 'friends',
'Clake\UserExtended\Components\User' => 'ueuser',
//'Clake\UserExtended\Components\ThirdParty' => 'thirdparty',
'Clake\UserExtended\Components\Routes' => 'routes',
];
}
public function injectNavigation()
{
return [
'users-side' => [
'label' => 'Users',
'url' => Backend::url('rainlab/user/users'),
'icon' => 'icon-user',
'order' => 100
],
'routes' => [
'label' => 'Routes',
'url' => Backend::url('clake/userextended/routes/index'),
'icon' => 'icon-eye-slash',
'order' => 200
],
'fields' => [
'label' => 'Field Manager',
'url' => Backend::url('clake/userextended/fields/manage'),
'icon' => 'icon-pencil-square-o',
'order' => 300
],
'roles' => [
'label' => 'Role Manager',
'url' => Backend::url('clake/userextended/roles/manage'),
'icon' => 'icon-pencil',
'order' => 400
],
'friends' => [
'label' => 'Friends',
'url' => Backend::url('clake/userextended/friends/index'),
'icon' => 'icon-users',
'order' => 500
],
'timezones' => [
'label' => 'Timezones',
'url' => Backend::url('clake/userextended/timezones/index'),
'icon' => 'icon-clock-o',
'order' => 600
],
'comments' => [
'label' => 'Comments',
'url' => Backend::url('clake/userextended/comments/index'),
'icon' => 'icon-comments-o',
'order' => 700
],
'modules' => [
'label' => 'Modules',
'url' => Backend::url('clake/userextended/modules/index'),
'icon' => 'icon-puzzle-piece',
'order' => 800
],
];
}
public function injectLang()
{
return [];
}
public function injectAssets()
{
return [
'ueJS' => '/plugins/clake/userextended/assets/js/frontend.js',
'ueCSS' => '/plugins/clake/userextended/assets/css/frontend.css'
];
}
public function injectBonds()
{
return [];
}
/**
* Returns the plugin version notes for display in the Module Manager
* @return array
*/
public function getUpdateNotes()
{
return [
'2.2.00' => [Helpers::file(plugins_path('clake/userextended/help/Updates/2.2.00.md')), 'md' => true],
];
}
/**
* Returns the plugin documentation for display in the Module Manager
* @return array
*/
public function getDocumentation()
{
$home = Helpers::file(plugins_path('clake/userextended/readme.md'));
$apis = Helpers::file(plugins_path('clake/userextended/help/APIs/Helpers.md')) .
Helpers::file(plugins_path('clake/userextended/help/APIs/Module.md')) .
Helpers::file(plugins_path('clake/userextended/help/APIs/UserUtil.md'));
$backend = Helpers::file(plugins_path('clake/userextended/help/Backend/FieldManager.md')) .
Helpers::file(plugins_path('clake/userextended/help/Backend/RoleManager.md')) .
Helpers::file(plugins_path('clake/userextended/help/Backend/Routes.md')) .
Helpers::file(plugins_path('clake/userextended/help/Backend/Timezones.md'));
$components = Helpers::file(plugins_path('clake/userextended/help/Components/3rdParty.md')) .
Helpers::file(plugins_path('clake/userextended/help/Components/Account.md')) .
Helpers::file(plugins_path('clake/userextended/help/Components/Friends.md')) .
Helpers::file(plugins_path('clake/userextended/help/Components/User.md'));
$traits = Helpers::file(plugins_path('clake/userextended/help/Traits/Searchable.md')) .
Helpers::file(plugins_path('clake/userextended/help/Traits/Timezonable.md'));
return [
'home' => [$home, 'md' => true],
'apis' => [$apis, 'md' => true],
'backend' => [$backend, 'md' => true],
'components' => [$components, 'md' => true],
'traits' => [$traits, 'md' => true],
];
}
/**
* Returns users with $property col = $value
* @param $value
* @param string $property
* @return \Rainlab\User\Models\User
*/
public function getUsers($value, $property = "name")
{
return UserUtil::getUsers($value, $property);
}
/**
* Returns a user with $property col = $value
* @param $value
* @param string $property
* @return \Clake\Userextended\Models\UserExtended
*/
public function getUser($value, $property = "id")
{
return UserUtil::getUser($value, $property);
}
/**
* Returns the logged in user. Optional param $return_type is a flag for which type of user object to return
* @param string $return_type
* @return \Clake\Userextended\Models\UserExtended|\Rainlab\User\Models\User
*/
public function getLoggedInUser($return_type = "ue")
{
if($return_type == "ue")
{
return UserUtil::getLoggedInUserExtendedUser();
} else {
return UserUtil::getLoggedInUser();
}
}
/**
* Returns the timezone code for the logged in user
* @return string|null
*/
public function getLoggedInUsersTimezone()
{
return UserUtil::getLoggedInUsersTimezone();
}
/**
* Returns the timezone code for a user who's $property col = $value
* @param $value
* @param string $property
* @return null|string
*/
public function getUserTimezone($value, $property = "id")
{
return UserUtil::getUserTimezone($value, $property);
}
/**
* Returns a set of UserExtended models from users found with username, surname, firstname, or email containing $phrase
* @param $phrase
* @return \Clake\Userextended\Models\UserExtended
*/
public function searchUsers($phrase)
{
return UserUtil::searchUsers($phrase);
}
/**
* Returns whether or not a user is logged in
* @param $userId
* @return bool
*/
public function isLoggedIn($userId)
{
return UserUtil::idIsLoggedIn($userId);
}
/**
* Programmatically registers a user.
* The $data array requires the following indices: email, password, password_confirmation
* The $data array can optional have the following indices: username, name
* The $data array also supports dynamic user settings. The index names are the same as the setting code found in user_settings.yaml
* @param array $data
* @return bool|mixed
*/
public function registerUser(array $data)
{
return UserManager::registerUser($data);
}
/**
* Programmatically update a user. Defaults to logged in user if a UserExtended object isn't passed in.
* The $data array can contain the following indices: email, password, password_confirmation, username, name
* The $data array also supports dynamic user settings. The index names are the same as the setting code found in user_settings.yaml
* @param array $data
* @param UserExtended|null $user
* @return bool|\Illuminate\Support\Facades\Validator\
*/
public function updateUser(array $data, UserExtended $user = null)
{
return UserManager::updateUser($data, $user);
}
/**
* Programmatically logs in a user
* The $data array requires the following indices: password, email or username (Depends on the default login field)
* @param array $data
* @return mixed
*/
public function loginUser(array $data)
{
return UserManager::loginUser($data);
}
/**
* Programmatically logs out the currently logged in user
* @return mixed
*/
public function logoutUser()
{
return UserManager::logoutUser();
}
/**
* Returns an array of UserSettings
* @return array
*/
public function getUserSettings()
{
return UserSettingsManager::init()->all();
}
/**
* Programmatically adds a user to a group
* @param $groupCode
* @param null $user
* @return bool
*/
public function addUserToGroup($groupCode, $user = null)
{
return UserGroupManager::with($user)->addGroup($groupCode);
}
/**
* Programmatically removes a user from a group
* @param $groupCode
* @param null $user
* @return bool
*/
public function removeUserFromGroup($groupCode, $user = null)
{
return UserGroupManager::with($user)->removeGroup($groupCode);
}
/**
* Programmatically adds a user to a role
* @param $roleCode
* @param null $user
* @return bool
*/
public function addUserToRole($roleCode, $user = null)
{
return UserRoleManager::with($user)->addRole($roleCode);
}
/**
* Programmatically removes a user from a role.
* @param $roleCode
* @param null $user
* @return bool
*/
public function removeUserFromRole($roleCode, $user = null)
{
return UserRoleManager::with($user)->removeRole($roleCode);
}
/**
* Checks whether a bond state exists between the logged in user and the user specified by $userId
* @param $bond
* @param $userId
* @return bool
*/
public function bondExists($bond, $userId)
{
return Friend::isBond($bond, $userId);
}
}