|
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\craft\hubspot\records; |
|
10
|
|
|
|
|
11
|
|
|
use Craft; |
|
12
|
|
|
use flipbox\craft\hubspot\fields\ObjectsFieldInterface; |
|
13
|
|
|
use flipbox\craft\hubspot\HubSpot; |
|
14
|
|
|
use flipbox\craft\hubspot\migrations\ObjectAssociations; |
|
15
|
|
|
use flipbox\craft\integration\records\EnvironmentalTableTrait; |
|
16
|
|
|
use flipbox\craft\integration\records\IntegrationAssociation; |
|
17
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @author Flipbox Factory <[email protected]> |
|
21
|
|
|
* @since 1.0.0 |
|
22
|
|
|
* |
|
23
|
|
|
* @property int $fieldId |
|
24
|
|
|
* @property string $objectId |
|
25
|
|
|
*/ |
|
26
|
|
|
class ObjectAssociation extends IntegrationAssociation |
|
27
|
|
|
{ |
|
28
|
|
|
use EnvironmentalTableTrait; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* The table alias |
|
32
|
|
|
*/ |
|
33
|
|
|
const TABLE_ALIAS = 'hubspot_objects'; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @inheritdoc |
|
37
|
|
|
* @throws \Throwable |
|
38
|
|
|
*/ |
|
39
|
|
|
public static function tableAlias() |
|
40
|
|
|
{ |
|
41
|
|
|
return static::environmentTableAlias(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @inheritdoc |
|
46
|
|
|
*/ |
|
47
|
|
|
protected static function environmentTableAlias() |
|
48
|
|
|
{ |
|
49
|
|
|
return static::TABLE_ALIAS . HubSpot::getInstance()->getSettings()->environmentTableSuffix; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @inheritdoc |
|
54
|
|
|
*/ |
|
55
|
|
|
protected static function createEnvironmentTableMigration() |
|
56
|
|
|
{ |
|
57
|
|
|
return new ObjectAssociations(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @return ResponseInterface |
|
62
|
|
|
*/ |
|
63
|
|
|
public function getObject(): ResponseInterface |
|
64
|
|
|
{ |
|
65
|
|
|
if (null === ($field = $this->getField())) { |
|
66
|
|
|
return null; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
if (!$field instanceof ObjectsFieldInterface) { |
|
70
|
|
|
return null; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$id = $this->objectId ?: self::DEFAULT_ID; |
|
74
|
|
|
|
|
75
|
|
|
return $field->readFromHubSpot($id); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|