GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
class-gv-form-join.php
Go to the documentation of this file.
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  */
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  public function __construct( $join, $join_column, $join_on, $join_on_column ) {
47  if ( $join instanceof \GV\Source ) {
48  $this->join = $join;
49  }
50 
51  if ( $join_on instanceof \GV\Source ) {
52  $this->join_on = $join_on;
53  }
54 
55  if ( $join_column instanceof \GV\Field ) {
56  $this->join_column = $join_column;
57  }
58 
59  if ( $join_on_column instanceof \GV\Field ) {
60  $this->join_on_column = $join_on_column;
61  }
62  }
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 }
__construct( $join, $join_column, $join_on, $join_on_column)
Construct a JOIN container.
as_query_join( $query)
Inject this join into the query.
If this file is called directly, abort.
If this file is called directly, abort.
gravityview()
The main GravityView wrapper function.
If this file is called directly, abort.