1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
5
|
|
|
* @license https://flipboxfactory.com/software/force/license |
6
|
|
|
* @link https://www.flipboxfactory.com/software/force/ |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace flipbox\craft\salesforce\models; |
10
|
|
|
|
11
|
|
|
use craft\base\Model; |
12
|
|
|
use flipbox\craft\ember\helpers\ModelHelper; |
13
|
|
|
use flipbox\craft\salesforce\helpers\TransformerHelper; |
14
|
|
|
use flipbox\craft\salesforce\services\Cache; |
15
|
|
|
use flipbox\craft\salesforce\transformers\CreateUpsertPayloadFromElement; |
16
|
|
|
use flipbox\craft\salesforce\transformers\PopulateElementFromResponse; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @author Flipbox Factory <[email protected]> |
20
|
|
|
* @since 1.0.0 |
21
|
|
|
*/ |
22
|
|
|
class Settings extends Model |
23
|
|
|
{ |
24
|
|
|
const DEFAULT_CONNECTION = 'salesforce'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
public $environmentTablePostfix = ''; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
private $defaultCache = Cache::APP_CACHE; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
private $defaultConnection = self::DEFAULT_CONNECTION; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param string $key |
43
|
|
|
* @return $this |
44
|
|
|
*/ |
45
|
|
|
public function setDefaultConnection(string $key) |
46
|
|
|
{ |
47
|
|
|
$this->defaultConnection = $key; |
48
|
|
|
return $this; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return string |
53
|
|
|
*/ |
54
|
|
|
public function getDefaultConnection(): string |
55
|
|
|
{ |
56
|
|
|
return $this->defaultConnection; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param string $key |
61
|
|
|
* @return $this |
62
|
|
|
*/ |
63
|
|
|
public function setDefaultCache(string $key) |
64
|
|
|
{ |
65
|
|
|
$this->defaultCache = $key; |
66
|
|
|
return $this; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return string |
71
|
|
|
*/ |
72
|
|
|
public function getDefaultCache(): string |
73
|
|
|
{ |
74
|
|
|
return $this->defaultCache; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return callable |
79
|
|
|
*/ |
80
|
|
|
public function getSyncUpsertPayloadTransformer(): callable |
81
|
|
|
{ |
82
|
|
|
return TransformerHelper::resolveTransformer([ |
83
|
|
|
'class' => CreateUpsertPayloadFromElement::class, |
84
|
|
|
'action' => 'sync' |
85
|
|
|
]); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return callable |
90
|
|
|
*/ |
91
|
|
|
public function getSyncPopulateElementTransformer(): callable |
92
|
|
|
{ |
93
|
|
|
return TransformerHelper::resolveTransformer([ |
94
|
|
|
'class' => PopulateElementFromResponse::class, |
95
|
|
|
'action' => 'sync' |
96
|
|
|
]); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return array |
101
|
|
|
*/ |
102
|
|
|
public function attributes() |
103
|
|
|
{ |
104
|
|
|
return array_merge( |
105
|
|
|
parent::attributes(), |
106
|
|
|
[ |
107
|
|
|
'defaultConnection', |
108
|
|
|
'defaultCache' |
109
|
|
|
] |
110
|
|
|
); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @return array |
115
|
|
|
*/ |
116
|
|
|
public function rules() |
117
|
|
|
{ |
118
|
|
|
return array_merge( |
119
|
|
|
parent::rules(), |
120
|
|
|
[ |
121
|
|
|
[ |
122
|
|
|
[ |
123
|
|
|
'defaultConnection', |
124
|
|
|
'defaultCache' |
125
|
|
|
], |
126
|
|
|
'safe', |
127
|
|
|
'on' => [ |
128
|
|
|
ModelHelper::SCENARIO_DEFAULT |
129
|
|
|
] |
130
|
|
|
] |
131
|
|
|
] |
132
|
|
|
); |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|