1 | <?php |
||
35 | abstract class Objects extends Integrations implements ObjectsFieldInterface |
||
36 | { |
||
37 | /** |
||
38 | * @inheritdoc |
||
39 | */ |
||
40 | const TRANSLATION_CATEGORY = 'hubspot'; |
||
41 | |||
42 | /** |
||
43 | * @inheritdoc |
||
44 | */ |
||
45 | const INPUT_TEMPLATE_PATH = 'hubspot/_components/fieldtypes/Objects/input'; |
||
46 | |||
47 | /** |
||
48 | * @inheritdoc |
||
49 | */ |
||
50 | const INPUT_ITEM_TEMPLATE_PATH = 'hubspot/_components/fieldtypes/Objects/_inputItem'; |
||
51 | |||
52 | /** |
||
53 | * @inheritdoc |
||
54 | */ |
||
55 | const SETTINGS_TEMPLATE_PATH = 'hubspot/_components/fieldtypes/Objects/settings'; |
||
56 | |||
57 | /** |
||
58 | * @inheritdoc |
||
59 | */ |
||
60 | const ACTION_PREFORM_ACTION_PATH = 'hubspot/cp/fields/perform-action'; |
||
61 | |||
62 | /** |
||
63 | * @inheritdoc |
||
64 | */ |
||
65 | const ACTION_CREATE_ITEM_PATH = 'hubspot/cp/fields/create-item'; |
||
66 | |||
67 | /** |
||
68 | * @inheritdoc |
||
69 | */ |
||
70 | const ACTION_ASSOCIATION_ITEM_PATH = 'hubspot/cp/objects/associate'; |
||
71 | |||
72 | /** |
||
73 | * @inheritdoc |
||
74 | */ |
||
75 | const ACTION_DISSOCIATION_ITEM_PATH = 'hubspot/cp/objects/dissociate'; |
||
76 | |||
77 | /** |
||
78 | * @inheritdoc |
||
79 | */ |
||
80 | const ACTION_PREFORM_ITEM_ACTION_PATH = 'hubspot/cp/fields/perform-item-action'; |
||
81 | |||
82 | /** |
||
83 | * Indicates whether the full sync operation should be preformed if a matching HubSpot Object was found but not |
||
84 | * currently associated to the element. For example, when attempting to Sync a Craft User to a HubSpot Contact, if |
||
85 | * the HubSpot Contact already exists; true would override data in HubSpot while false would just perform |
||
86 | * an association (note, a subsequent sync operation could be preformed) |
||
87 | * @var bool |
||
88 | * |
||
89 | * @deprecated |
||
90 | */ |
||
91 | public $syncToHubSpotOnMatch = false; |
||
92 | |||
93 | /** |
||
94 | * @inheritdoc |
||
95 | */ |
||
96 | protected $defaultAvailableActions = [ |
||
97 | SyncTo::class |
||
98 | ]; |
||
99 | |||
100 | /** |
||
101 | * @inheritdoc |
||
102 | */ |
||
103 | protected $defaultAvailableItemActions = [ |
||
104 | SyncItemFrom::class, |
||
105 | SyncItemTo::class, |
||
106 | ]; |
||
107 | |||
108 | /** |
||
109 | * @param array $payload |
||
110 | * @param string|null $id |
||
111 | * @return ResponseInterface |
||
112 | */ |
||
113 | abstract protected function upsertToHubSpot( |
||
117 | |||
118 | /** |
||
119 | * @param ResponseInterface $response |
||
120 | * @return string|null |
||
121 | */ |
||
122 | abstract protected function getObjectIdFromResponse(ResponseInterface $response); |
||
123 | |||
124 | /** |
||
125 | * @inheritdoc |
||
126 | */ |
||
127 | public static function recordClass(): string |
||
131 | |||
132 | /******************************************* |
||
133 | * CONNECTION |
||
134 | *******************************************/ |
||
135 | |||
136 | /** |
||
137 | * @return ConnectionInterface |
||
138 | * @throws \flipbox\craft\integration\exceptions\ConnectionNotFound |
||
139 | */ |
||
140 | public function getConnection(): ConnectionInterface |
||
144 | |||
145 | /******************************************* |
||
146 | * CACHE |
||
147 | *******************************************/ |
||
148 | |||
149 | /** |
||
150 | * @return CacheInterface |
||
151 | */ |
||
152 | public function getCache(): CacheInterface |
||
156 | |||
157 | |||
158 | /******************************************* |
||
159 | * SYNC TO |
||
160 | *******************************************/ |
||
161 | |||
162 | /** |
||
163 | * @inheritdoc |
||
164 | * @throws \Throwable |
||
165 | */ |
||
166 | public function syncToHubSpot( |
||
198 | |||
199 | /******************************************* |
||
200 | * SYNC FROM |
||
201 | *******************************************/ |
||
202 | |||
203 | /** |
||
204 | * @@inheritdoc |
||
205 | * @throws \Throwable |
||
206 | * @throws \craft\errors\ElementNotFoundException |
||
207 | * @throws \yii\base\Exception |
||
208 | */ |
||
209 | public function syncFromHubSpot( |
||
261 | |||
262 | |||
263 | /** |
||
264 | * @param ElementInterface|Element $element |
||
265 | * @param string $id |
||
266 | * @return bool |
||
267 | * @throws \Throwable |
||
268 | */ |
||
269 | protected function addAssociation( |
||
296 | |||
297 | /** |
||
298 | * @param ResponseInterface $response |
||
299 | * @param ElementInterface $element |
||
300 | * @param string|null $objectId |
||
301 | * @return bool |
||
302 | * @throws \Throwable |
||
303 | */ |
||
304 | protected function handleSyncToHubSpotResponse( |
||
336 | |||
337 | /** |
||
338 | * @param ElementInterface|Element $element |
||
339 | * @return null|string |
||
340 | */ |
||
341 | protected function resolveObjectIdFromElement( |
||
368 | } |
||
369 |