1 | <?php |
||
27 | use Psr\Http\Message\ResponseInterface; |
||
28 | use Psr\SimpleCache\CacheInterface; |
||
29 | |||
30 | /** |
||
31 | * @author Flipbox Factory <[email protected]> |
||
32 | * @since 1.0.0 |
||
33 | */ |
||
34 | abstract class Objects extends Integrations implements ObjectsFieldInterface |
||
35 | { |
||
36 | /** |
||
37 | * @inheritdoc |
||
38 | */ |
||
39 | const TRANSLATION_CATEGORY = 'hubspot'; |
||
40 | |||
41 | /** |
||
42 | * @inheritdoc |
||
43 | */ |
||
44 | const INPUT_TEMPLATE_PATH = 'hubspot/_components/fieldtypes/Objects/input'; |
||
45 | |||
46 | /** |
||
47 | * @inheritdoc |
||
48 | */ |
||
49 | const INPUT_ITEM_TEMPLATE_PATH = 'hubspot/_components/fieldtypes/Objects/_inputItem'; |
||
50 | |||
51 | /** |
||
52 | * @inheritdoc |
||
53 | */ |
||
54 | const SETTINGS_TEMPLATE_PATH = 'hubspot/_components/fieldtypes/Objects/settings'; |
||
55 | |||
56 | /** |
||
57 | * @inheritdoc |
||
58 | */ |
||
59 | const ACTION_PREFORM_ACTION_PATH = 'hubspot/cp/fields/perform-action'; |
||
60 | |||
61 | /** |
||
62 | * @inheritdoc |
||
63 | */ |
||
64 | const ACTION_CREATE_ITEM_PATH = 'hubspot/cp/fields/create-item'; |
||
65 | |||
66 | /** |
||
67 | * @inheritdoc |
||
68 | */ |
||
69 | const ACTION_ASSOCIATION_ITEM_PATH = 'hubspot/cp/objects/associate'; |
||
70 | |||
71 | /** |
||
72 | * @inheritdoc |
||
73 | */ |
||
74 | const ACTION_DISSOCIATION_ITEM_PATH = 'hubspot/cp/objects/dissociate'; |
||
75 | |||
76 | /** |
||
77 | * @inheritdoc |
||
78 | */ |
||
79 | const ACTION_PREFORM_ITEM_ACTION_PATH = 'hubspot/cp/fields/perform-item-action'; |
||
80 | |||
81 | /** |
||
82 | * Indicates whether the full sync operation should be preformed if a matching HubSpot Object was found but not |
||
83 | * currently associated to the element. For example, when attempting to Sync a Craft User to a HubSpot Contact, if |
||
84 | * the HubSpot Contact already exists; true would override data in HubSpot while false would just perform |
||
85 | * an association (note, a subsequent sync operation could be preformed) |
||
86 | * @var bool |
||
87 | * |
||
88 | * @deprecated |
||
89 | */ |
||
90 | public $syncToHubSpotOnMatch = false; |
||
91 | |||
92 | /** |
||
93 | * @inheritdoc |
||
94 | */ |
||
95 | protected $defaultAvailableActions = [ |
||
96 | SyncTo::class |
||
97 | ]; |
||
98 | |||
99 | /** |
||
100 | * @inheritdoc |
||
101 | */ |
||
102 | protected $defaultAvailableItemActions = [ |
||
103 | SyncItemFrom::class, |
||
104 | SyncItemTo::class, |
||
105 | ]; |
||
106 | |||
107 | /** |
||
108 | * @param array $payload |
||
109 | * @param string|null $id |
||
110 | * @return ResponseInterface |
||
111 | */ |
||
112 | abstract protected function upsertToHubSpot( |
||
116 | |||
117 | /** |
||
118 | * @param ResponseInterface $response |
||
119 | * @return string|null |
||
120 | */ |
||
121 | abstract protected function getObjectIdFromResponse(ResponseInterface $response); |
||
122 | |||
123 | /** |
||
124 | * @inheritdoc |
||
125 | */ |
||
126 | public static function recordClass(): string |
||
130 | |||
131 | /******************************************* |
||
132 | * CONNECTION |
||
133 | *******************************************/ |
||
134 | |||
135 | /** |
||
136 | * @return ConnectionInterface |
||
137 | * @throws \flipbox\craft\integration\exceptions\ConnectionNotFound |
||
138 | */ |
||
139 | public function getConnection(): ConnectionInterface |
||
143 | |||
144 | /******************************************* |
||
145 | * CACHE |
||
146 | *******************************************/ |
||
147 | |||
148 | /** |
||
149 | * @return CacheInterface |
||
150 | */ |
||
151 | public function getCache(): CacheInterface |
||
155 | |||
156 | |||
157 | /******************************************* |
||
158 | * SYNC TO |
||
159 | *******************************************/ |
||
160 | |||
161 | /** |
||
162 | * @inheritdoc |
||
163 | * @throws \Throwable |
||
164 | */ |
||
165 | public function syncToHubSpot( |
||
166 | ElementInterface $element, |
||
167 | string $objectId = null, |
||
168 | $transformer = null |
||
368 |