|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace NerdsAndCompany\Schematic\Services; |
|
4
|
|
|
|
|
5
|
|
|
use Craft; |
|
6
|
|
|
use craft\elements\User; |
|
7
|
|
|
use yii\base\Component as BaseComponent; |
|
8
|
|
|
use NerdsAndCompany\Schematic\Behaviors\FieldLayoutBehavior; |
|
9
|
|
|
use NerdsAndCompany\Schematic\Interfaces\MappingInterface; |
|
10
|
|
|
use NerdsAndCompany\Schematic\Schematic; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Schematic Users Service. |
|
14
|
|
|
* |
|
15
|
|
|
* Sync Craft Setups. |
|
16
|
|
|
* |
|
17
|
|
|
* @author Nerds & Company |
|
18
|
|
|
* @copyright Copyright (c) 2015-2018, Nerds & Company |
|
19
|
|
|
* @license MIT |
|
20
|
|
|
* |
|
21
|
|
|
* @see http://www.nerds.company |
|
22
|
|
|
*/ |
|
23
|
|
|
class Users extends BaseComponent implements MappingInterface |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* Load fieldlayout behavior |
|
27
|
|
|
* |
|
28
|
|
|
* @return array |
|
29
|
1 |
|
*/ |
|
30
|
|
|
public function behaviors() |
|
31
|
1 |
|
{ |
|
32
|
|
|
return [ |
|
33
|
1 |
|
FieldLayoutBehavior::className(), |
|
|
|
|
|
|
34
|
|
|
]; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Export user settings |
|
39
|
|
|
* |
|
40
|
|
|
* @return array |
|
41
|
|
|
*/ |
|
42
|
|
|
public function export() |
|
43
|
1 |
|
{ |
|
44
|
|
|
$settings = Craft::$app->systemSettings->getSettings('users'); |
|
45
|
|
|
$photoVolumeId = (int)$settings['photoVolumeId']; |
|
46
|
1 |
|
$volume = Craft::$app->volumes->getVolumeById($photoVolumeId); |
|
47
|
1 |
|
unset($settings['photoVolumeId']); |
|
48
|
|
|
|
|
49
|
|
|
$fieldLayout = Craft::$app->getFields()->getLayoutByType(User::class); |
|
50
|
|
|
return [ |
|
51
|
|
|
'settings' => $settings, |
|
52
|
|
|
'photoVolume' => $volume ? $volume->handle : null, |
|
53
|
|
|
'fieldLayout' => $this->getFieldLayoutDefinition($fieldLayout), |
|
|
|
|
|
|
54
|
|
|
]; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
3 |
|
* Import user settings. |
|
59
|
|
|
* |
|
60
|
3 |
|
* @param array $userSettings |
|
61
|
|
|
*/ |
|
62
|
|
|
public function import(array $userSettings) |
|
63
|
3 |
|
{ |
|
64
|
|
|
$photoVolumeId = null; |
|
65
|
3 |
|
if (array_key_exists('photoVolume', $userSettings) && $userSettings['photoVolume'] != null) { |
|
66
|
1 |
|
$volume = Craft::$app->volumes->getVolumeByHandle($userSettings['photoVolume']); |
|
67
|
1 |
|
$photoVolumeId = $volume ? $volume->id : null; |
|
68
|
2 |
|
} |
|
69
|
|
|
if (array_key_exists('settings', $userSettings)) { |
|
70
|
|
|
Schematic::info('- Saving user settings'); |
|
71
|
3 |
|
$userSettings['photoVolumeId'] = $photoVolumeId; |
|
72
|
3 |
|
if (!Craft::$app->systemSettings->saveSettings('users', $userSettings['settings'])) { |
|
73
|
|
|
Schematic::warning('- Couldn’t save user settings.'); |
|
74
|
3 |
|
} |
|
75
|
|
|
} |
|
76
|
1 |
|
|
|
77
|
1 |
|
if (array_key_exists('fieldLayout', $userSettings)) { |
|
78
|
|
|
Schematic::info('- Saving user field layout'); |
|
79
|
3 |
|
$fieldLayout = $this->getFieldLayout($userSettings['fieldLayout']); |
|
|
|
|
|
|
80
|
|
|
$fieldLayout->type = User::class; |
|
81
|
|
|
|
|
82
|
|
|
Craft::$app->fields->deleteLayoutsByType(User::class); |
|
83
|
|
|
if (!Craft::$app->fields->saveLayout($fieldLayout)) { |
|
84
|
|
|
Schematic::warning('- Couldn’t save user field layout.'); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.