1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
5
|
|
|
* @license https://flipboxfactory.com/software/hubspot/license |
6
|
|
|
* @link https://www.flipboxfactory.com/software/hubspot/ |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace flipbox\hubspot\fields; |
10
|
|
|
|
11
|
|
|
use Craft; |
12
|
|
|
use flipbox\craft\integration\fields\Integrations; |
13
|
|
|
use flipbox\craft\integration\services\IntegrationAssociations; |
14
|
|
|
use flipbox\craft\integration\services\IntegrationField; |
15
|
|
|
use flipbox\hubspot\connections\ConnectionInterface; |
16
|
|
|
use flipbox\hubspot\HubSpot; |
17
|
|
|
use flipbox\hubspot\services\ObjectAssociations; |
18
|
|
|
use flipbox\hubspot\services\ObjectsField; |
19
|
|
|
use flipbox\hubspot\services\resources\CRUDInterface; |
20
|
|
|
use Psr\SimpleCache\CacheInterface; |
21
|
|
|
use yii\base\InvalidConfigException; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @author Flipbox Factory <[email protected]> |
25
|
|
|
* @since 1.0.0 |
26
|
|
|
*/ |
27
|
|
|
class Objects extends Integrations |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @inheritdoc |
31
|
|
|
*/ |
32
|
|
|
const TRANSLATION_CATEGORY = 'hubspot'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @inheritdoc |
36
|
|
|
*/ |
37
|
|
|
const INPUT_TEMPLATE_PATH = 'hubspot/_components/fieldtypes/Objects/input'; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @inheritdoc |
41
|
|
|
*/ |
42
|
|
|
const INPUT_ITEM_TEMPLATE_PATH = 'hubspot/_components/fieldtypes/Objects/_inputItem'; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @inheritdoc |
46
|
|
|
*/ |
47
|
|
|
const SETTINGS_TEMPLATE_PATH = 'hubspot/_components/fieldtypes/Objects/settings'; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @inheritdoc |
51
|
|
|
*/ |
52
|
|
|
const ACTION_PREFORM_ACTION_PATH = 'hubspot/cp/fields/perform-action'; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @inheritdoc |
56
|
|
|
*/ |
57
|
|
|
const ACTION_CREATE_ITEM_PATH = 'hubspot/cp/fields/create-item'; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @inheritdoc |
61
|
|
|
*/ |
62
|
|
|
const ACTION_ASSOCIATION_ITEM_PATH = 'hubspot/cp/objects/associate'; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @inheritdoc |
66
|
|
|
*/ |
67
|
|
|
const ACTION_DISSOCIATION_ITEM_PATH = 'hubspot/cp/objects/dissociate'; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @inheritdoc |
71
|
|
|
*/ |
72
|
|
|
const ACTION_PREFORM_ITEM_ACTION_PATH = 'hubspot/cp/fields/perform-item-action'; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Indicates whether the full sync operation should be preformed if a matching HubSpot Object was found but not |
76
|
|
|
* currently associated to the element. For example, when attempting to Sync a Craft User to a HubSpot Contact, if |
77
|
|
|
* the HubSpot Contact already exists; true would override data in HubSpot while false would just perform |
78
|
|
|
* an association (note, a subsequent sync operation could be preformed) |
79
|
|
|
* @var bool |
80
|
|
|
*/ |
81
|
|
|
public $syncToHubSpotOnMatch = false; |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @inheritdoc |
85
|
|
|
* @return ObjectsField |
86
|
|
|
*/ |
87
|
|
|
protected function fieldService(): IntegrationField |
88
|
|
|
{ |
89
|
|
|
return HubSpot::getInstance()->getObjectsField(); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @inheritdoc |
94
|
|
|
* @return ObjectAssociations |
95
|
|
|
*/ |
96
|
|
|
protected function associationService(): IntegrationAssociations |
97
|
|
|
{ |
98
|
|
|
return HubSpot::getInstance()->getObjectAssociations(); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @inheritdoc |
103
|
|
|
*/ |
104
|
|
|
public static function displayName(): string |
105
|
|
|
{ |
106
|
|
|
return Craft::t('hubspot', 'HubSpot Objects'); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @inheritdoc |
111
|
|
|
*/ |
112
|
|
|
public static function defaultSelectionLabel(): string |
113
|
|
|
{ |
114
|
|
|
return Craft::t('hubspot', 'Add a HubSpot Objects'); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/******************************************* |
118
|
|
|
* CONNECTION |
119
|
|
|
*******************************************/ |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @return ConnectionInterface |
123
|
|
|
* @throws \yii\base\InvalidConfigException |
124
|
|
|
*/ |
125
|
|
|
public function getConnection(): ConnectionInterface |
126
|
|
|
{ |
127
|
|
|
$service = HubSpot::getInstance()->getConnections(); |
128
|
|
|
return $service->get($service::DEFAULT_CONNECTION); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/******************************************* |
132
|
|
|
* CACHE |
133
|
|
|
*******************************************/ |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @return CacheInterface |
137
|
|
|
* @throws \yii\base\InvalidConfigException |
138
|
|
|
*/ |
139
|
|
|
public function getCache(): CacheInterface |
140
|
|
|
{ |
141
|
|
|
$service = HubSpot::getInstance()->getCache(); |
142
|
|
|
return $service->get($service::DEFAULT_CACHE); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/******************************************* |
146
|
|
|
* CRUD |
147
|
|
|
*******************************************/ |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @return CRUDInterface |
151
|
|
|
* @throws InvalidConfigException |
152
|
|
|
*/ |
153
|
|
|
public function getResource(): CRUDInterface |
154
|
|
|
{ |
155
|
|
|
$service = HubSpot::getInstance()->getResources()->get($this->object); |
156
|
|
|
|
157
|
|
|
if (!$service instanceof CRUDInterface) { |
158
|
|
|
throw new InvalidConfigException(sprintf( |
159
|
|
|
"Resource must be an instance of '%s', '%s' given", |
160
|
|
|
CRUDInterface::class, |
161
|
|
|
get_class($service) |
162
|
|
|
)); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
return $service; |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
|