|
1
|
|
|
<?php |
|
2
|
|
|
namespace GV; |
|
3
|
|
|
|
|
4
|
|
|
/** If this file is called directly, abort. */ |
|
5
|
|
|
if ( ! defined( 'GRAVITYVIEW_DIR' ) ) { |
|
6
|
|
|
die(); |
|
7
|
|
|
} |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* The \GV\Join class. |
|
11
|
|
|
* |
|
12
|
|
|
* Contains a join between two Sources on two Fields. |
|
13
|
|
|
*/ |
|
14
|
|
|
class Join { |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var GF_Form|Source|Form |
|
18
|
|
|
* @since 2.2 Made private property public |
|
19
|
|
|
*/ |
|
20
|
|
|
public $join; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var GF_Form|Source|Form |
|
24
|
|
|
* @since 2.2 Made private property public |
|
25
|
|
|
*/ |
|
26
|
|
|
public $join_on; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var Field |
|
30
|
|
|
*/ |
|
31
|
|
|
public $join_column; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var Field |
|
35
|
|
|
*/ |
|
36
|
|
|
public $join_on_column; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Construct a JOIN container. |
|
40
|
|
|
* |
|
41
|
|
|
* @param \GV\Source $join The form we're joining to. |
|
42
|
|
|
* @param \GV\Field $join_column Its column. |
|
43
|
|
|
* @param \GV\Source $join_on The form we're joining on. |
|
44
|
|
|
* @param \GV\Field $join_on_column Its column. |
|
45
|
|
|
*/ |
|
46
|
9 |
|
public function __construct( $join, $join_column, $join_on, $join_on_column ) { |
|
47
|
9 |
|
if ( $join instanceof \GV\Source ) { |
|
48
|
9 |
|
$this->join = $join; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
9 |
|
if ( $join_on instanceof \GV\Source ) { |
|
52
|
9 |
|
$this->join_on = $join_on; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
9 |
|
if ( $join_column instanceof \GV\Field ) { |
|
56
|
9 |
|
$this->join_column = $join_column; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
9 |
|
if ( $join_on_column instanceof \GV\Field ) { |
|
60
|
9 |
|
$this->join_on_column = $join_on_column; |
|
61
|
|
|
} |
|
62
|
9 |
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Inject this join into the query. |
|
66
|
|
|
* |
|
67
|
|
|
* @param \GF_Query $query The \GF_Query instance. |
|
68
|
|
|
* |
|
69
|
|
|
* @return \GF_Query The $query |
|
70
|
|
|
*/ |
|
71
|
|
|
public function as_query_join( $query ) { |
|
72
|
|
|
|
|
73
|
|
|
if ( ! gravityview()->plugin->supports( Plugin::FEATURE_JOINS ) ) { |
|
74
|
|
|
return null; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
if ( ! $query instanceof \GF_Query ) { |
|
|
|
|
|
|
78
|
|
|
gravityview()->log->error( 'Query not instance of \GF_Query.' ); |
|
79
|
|
|
return null; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
$join_id = intval( $this->join->ID ); |
|
|
|
|
|
|
83
|
|
|
$join_on_id = intval( $this->join_on->ID ); |
|
84
|
|
|
|
|
85
|
|
|
if ( empty( $join_id ) || empty( $join_on_id ) ) { |
|
86
|
|
|
gravityview()->log->error( 'Query join form not an integer.', array( 'data' => $this ) ); |
|
87
|
|
|
return null; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
return $query->join( |
|
91
|
|
|
new \GF_Query_Column( $this->join_on_column->ID, $join_on_id ), |
|
92
|
|
|
new \GF_Query_Column( $this->join_column->ID, $join_id ) |
|
93
|
|
|
); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.jsonfile (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.jsonto be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
requireorrequire-devsection?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceofchecks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.