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\services; |
10
|
|
|
|
11
|
|
|
use Craft; |
12
|
|
|
use flipbox\craft\integration\services\IntegrationAssociations; |
13
|
|
|
use flipbox\craft\integration\services\IntegrationField; |
14
|
|
|
use flipbox\hubspot\db\ObjectAssociationQuery; |
15
|
|
|
use flipbox\hubspot\HubSpot; |
16
|
|
|
use flipbox\hubspot\migrations\ObjectAssociation as ObjectAssociationMigration; |
17
|
|
|
use flipbox\hubspot\records\ObjectAssociation; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Flipbox Factory <[email protected]> |
21
|
|
|
* @since 1.0.0 |
22
|
|
|
* |
23
|
|
|
* @method ObjectAssociationQuery parentGetQuery($config = []) |
24
|
|
|
* @method ObjectAssociation create(array $attributes = []) |
25
|
|
|
* @method ObjectAssociation find($identifier) |
26
|
|
|
* @method ObjectAssociation get($identifier) |
27
|
|
|
* @method ObjectAssociation findByCondition($condition = []) |
28
|
|
|
* @method ObjectAssociation getByCondition($condition = []) |
29
|
|
|
* @method ObjectAssociation findByCriteria($criteria = []) |
30
|
|
|
* @method ObjectAssociation getByCriteria($criteria = []) |
31
|
|
|
* @method ObjectAssociation[] findAllByCondition($condition = []) |
32
|
|
|
* @method ObjectAssociation[] getAllByCondition($condition = []) |
33
|
|
|
* @method ObjectAssociation[] findAllByCriteria($criteria = []) |
34
|
|
|
* @method ObjectAssociation[] getAllByCriteria($criteria = []) |
35
|
|
|
*/ |
36
|
|
|
class ObjectAssociations extends IntegrationAssociations |
37
|
|
|
{ |
38
|
|
|
/** |
39
|
|
|
* @inheritdoc |
40
|
|
|
* @throws \Throwable |
41
|
|
|
*/ |
42
|
3 |
|
public function init() |
43
|
|
|
{ |
44
|
3 |
|
$settings = HubSpot::getInstance()->getSettings(); |
45
|
3 |
|
$this->cacheDuration = $settings->associationsCacheDuration; |
46
|
3 |
|
$this->cacheDependency = $settings->associationsCacheDependency; |
47
|
|
|
|
48
|
3 |
|
parent::init(); |
49
|
|
|
|
50
|
3 |
|
$this->ensureTableExists(); |
51
|
3 |
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @inheritdoc |
55
|
|
|
* @return ObjectsField |
56
|
|
|
*/ |
57
|
|
|
protected function fieldService(): IntegrationField |
58
|
|
|
{ |
59
|
|
|
return HubSpot::getInstance()->getObjectsField(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @inheritdoc |
64
|
|
|
*/ |
65
|
|
|
protected static function tableAlias(): string |
66
|
|
|
{ |
67
|
|
|
return ObjectAssociation::tableAlias(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @inheritdoc |
72
|
|
|
*/ |
73
|
|
|
public static function recordClass(): string |
74
|
|
|
{ |
75
|
|
|
return ObjectAssociation::class; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @throws \Throwable |
80
|
|
|
*/ |
81
|
3 |
|
public function ensureTableExists() |
82
|
|
|
{ |
83
|
3 |
|
if (!in_array( |
84
|
3 |
|
Craft::$app->getDb()->tablePrefix . ObjectAssociation::tableAlias(), |
85
|
3 |
|
Craft::$app->getDb()->getSchema()->tableNames, |
86
|
3 |
|
true |
87
|
|
|
)) { |
88
|
3 |
|
$this->createTable(); |
89
|
|
|
} |
90
|
3 |
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return bool |
94
|
|
|
* @throws \Throwable |
95
|
|
|
*/ |
96
|
3 |
|
private function createTable(): bool |
97
|
|
|
{ |
98
|
3 |
|
ob_start(); |
99
|
3 |
|
(new ObjectAssociationMigration())->up(); |
100
|
3 |
|
ob_end_clean(); |
101
|
|
|
|
102
|
3 |
|
return true; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|