|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace NerdsAndCompany\Schematic\Services; |
|
4
|
|
|
|
|
5
|
|
|
use craft\base\Model; |
|
6
|
|
|
use yii\base\Component as BaseComponent; |
|
7
|
|
|
use NerdsAndCompany\Schematic\Behaviors\FieldLayoutBehavior; |
|
8
|
|
|
use NerdsAndCompany\Schematic\Behaviors\SourcesBehavior; |
|
9
|
|
|
use NerdsAndCompany\Schematic\Interfaces\MappingInterface; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Schematic Base Service. |
|
13
|
|
|
* |
|
14
|
|
|
* Sync Craft Setups. |
|
15
|
|
|
* |
|
16
|
|
|
* @author Nerds & Company |
|
17
|
|
|
* @copyright Copyright (c) 2015-2018, Nerds & Company |
|
18
|
|
|
* @license MIT |
|
19
|
|
|
* |
|
20
|
|
|
* @see http://www.nerds.company |
|
21
|
|
|
*/ |
|
22
|
|
|
abstract class Base extends BaseComponent implements MappingInterface |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* Load fieldlayout and sources behaviors |
|
26
|
|
|
* |
|
27
|
|
|
* @return array |
|
28
|
|
|
*/ |
|
29
|
|
|
public function behaviors() |
|
30
|
|
|
{ |
|
31
|
|
|
return [ |
|
32
|
|
|
FieldLayoutBehavior::className(), |
|
|
|
|
|
|
33
|
|
|
SourcesBehavior::className(), |
|
|
|
|
|
|
34
|
|
|
]; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
//============================================================================================================== |
|
38
|
|
|
//================================================ EXPORT ==================================================== |
|
39
|
|
|
//============================================================================================================== |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Get all records |
|
43
|
|
|
* |
|
44
|
|
|
* @return Model[] |
|
45
|
|
|
*/ |
|
46
|
|
|
abstract protected function getRecords(); |
|
47
|
57 |
|
|
|
48
|
|
|
/** |
|
49
|
57 |
|
* Get all record definitions |
|
50
|
57 |
|
* |
|
51
|
|
|
* @return array |
|
52
|
|
|
*/ |
|
53
|
|
|
public function export(array $records = null) |
|
54
|
|
|
{ |
|
55
|
|
|
$records = $records ?: $this->getRecords(); |
|
56
|
|
|
$result = []; |
|
57
|
|
|
foreach ($records as $record) { |
|
58
|
|
|
$result[$record->handle] = $this->getRecordDefinition($record); |
|
59
|
|
|
} |
|
60
|
|
|
return $result; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Get single record definition |
|
65
|
|
|
* |
|
66
|
|
|
* @param Model $record |
|
67
|
|
|
* @return array |
|
68
|
|
|
*/ |
|
69
|
|
|
protected function getRecordDefinition(Model $record) |
|
70
|
|
|
{ |
|
71
|
|
|
$attributes = $record->attributes; |
|
72
|
|
|
unset($attributes['id']); |
|
73
|
|
|
unset($attributes['dateCreated']); |
|
74
|
|
|
unset($attributes['dateUpdated']); |
|
75
|
|
|
|
|
76
|
|
|
if (isset($attributes['sources'])) { |
|
77
|
|
|
$attributes['sources'] = $this->getSources(get_class($record), $attributes['sources'], 'id', 'handle'); |
|
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
if (isset($attributes['source'])) { |
|
81
|
|
|
$attributes['source'] = $this->getSource(get_class($record), $attributes['sources'], 'id', 'handle'); |
|
|
|
|
|
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
if (isset($attributes['fieldLayoutId'])) { |
|
85
|
|
|
$attributes['fieldLayout'] = $this->getFieldLayoutDefinition($record->getFieldLayout()); |
|
|
|
|
|
|
86
|
|
|
unset($attributes['fieldLayoutId']); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
return $attributes; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
//============================================================================================================== |
|
93
|
|
|
//================================================ IMPORT ==================================================== |
|
94
|
|
|
//============================================================================================================== |
|
95
|
|
|
|
|
96
|
|
|
public function import(array $definitions, $force = false) |
|
97
|
|
|
{ |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
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.