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\db; |
10
|
|
|
|
11
|
|
|
use Craft; |
12
|
|
|
use craft\db\QueryAbortedException; |
13
|
|
|
use craft\helpers\Db; |
14
|
|
|
use flipbox\craft\sortable\associations\db\SortableAssociationQuery; |
15
|
|
|
use flipbox\craft\sortable\associations\db\traits\SiteAttribute; |
16
|
|
|
use flipbox\ember\db\traits\ElementAttribute; |
17
|
|
|
use flipbox\hubspot\records\ObjectAssociation; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Flipbox Factory <[email protected]> |
21
|
|
|
* @since 1.0.0 |
22
|
|
|
* |
23
|
|
|
* @method ObjectAssociation[] all() |
24
|
|
|
* @method ObjectAssociation one() |
25
|
|
|
*/ |
26
|
|
|
class ObjectAssociationQuery extends SortableAssociationQuery |
27
|
|
|
{ |
28
|
|
|
use traits\FieldAttribute, |
29
|
|
|
traits\ObjectIdAttribute, |
30
|
|
|
ElementAttribute, |
31
|
|
|
SiteAttribute; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @inheritdoc |
35
|
|
|
*/ |
36
|
|
|
protected function fixedOrderColumn(): string |
37
|
|
|
{ |
38
|
|
|
return ObjectAssociation::TARGET_ATTRIBUTE; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param array $config |
43
|
|
|
* @return $this |
44
|
|
|
*/ |
45
|
|
|
public function configure(array $config) |
46
|
|
|
{ |
47
|
|
|
Craft::configure( |
48
|
|
|
$this, |
49
|
|
|
$config |
50
|
|
|
); |
51
|
|
|
|
52
|
|
|
return $this; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @inheritdoc |
57
|
|
|
* |
58
|
|
|
* @throws QueryAbortedException if it can be determined that there won’t be any results |
59
|
|
|
*/ |
60
|
|
|
public function prepare($builder) |
61
|
|
|
{ |
62
|
|
|
// Is the query already doomed? |
63
|
|
|
if (($this->field !== null && empty($this->field)) || |
64
|
|
|
($this->{ObjectAssociation::TARGET_ATTRIBUTE} !== null && |
65
|
|
|
empty($this->{ObjectAssociation::TARGET_ATTRIBUTE}) |
66
|
|
|
) || |
67
|
|
|
($this->element !== null && empty($this->element)) |
68
|
|
|
) { |
69
|
|
|
throw new QueryAbortedException(); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
$this->applyConditions(); |
73
|
|
|
$this->applySiteConditions(); |
74
|
|
|
$this->applyObjectIdConditions(); |
75
|
|
|
$this->applyFieldConditions(); |
76
|
|
|
|
77
|
|
|
return parent::prepare($builder); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Apply query specific conditions |
82
|
|
|
*/ |
83
|
|
|
protected function applyConditions() |
84
|
|
|
{ |
85
|
|
|
if ($this->element !== null) { |
86
|
|
|
$this->andWhere(Db::parseParam('elementId', $this->parseElementValue($this->element))); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|