Completed
Branch FET-9113-extra-joins-table (dff12c)
by
unknown
630:44 queued 613:03
created
core/data_migration_scripts/EE_DMS_Core_4_8_0.dms.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -715,7 +715,7 @@
 block discarded – undo
715 715
 				}
716 716
 			}
717 717
 		}
718
-        }
718
+		}
719 719
 	/**
720 720
 	 * addresses https://events.codebasehq.com/projects/event-espresso/tickets/8731
721 721
 	 * which should just be a temporary issue for folks who installed 4.8.0-4.8.5;
Please login to merge, or discard this patch.
core/db_models/relations/EE_HABTM_Any_Relation.php 3 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -32,7 +32,6 @@
 block discarded – undo
32 32
 	/**
33 33
 	 * 
34 34
 	 * @param string $model_name
35
-	 * @param string $comparison_model_name
36 35
 	 * @param string $id_or_name_field should be the string 'ID' or 'name' only
37 36
 	 * @return EE_Model_Field_Base
38 37
 	 */
Please login to merge, or discard this patch.
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Joins any two models together via a has-and-belongs-to-many relation, using 
4
- * the esp_extra_join table.
5
- */
3
+	  * Joins any two models together via a has-and-belongs-to-many relation, using 
4
+	  * the esp_extra_join table.
5
+	  */
6 6
 class EE_HABTM_Any_Relation extends EE_HABTM_Relation{	
7 7
 	/**
8 8
 	 *
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Joins any two models together via a has-and-belongs-to-many relation, using 
4 4
  * the esp_extra_join table.
5 5
  */
6
-class EE_HABTM_Any_Relation extends EE_HABTM_Relation{	
6
+class EE_HABTM_Any_Relation extends EE_HABTM_Relation {	
7 7
 	/**
8 8
 	 *
9 9
 	 * @var string
@@ -17,16 +17,16 @@  discard block
 block discarded – undo
17 17
 	 * @param boolean $block_deletes for this type of relation, we block by default for now. if there are related models across this relation, block (prevent and add an error) the deletion of this model
18 18
 	 * @param type $blocking_delete_error_message a customized error message on blocking deletes instead of the default
19 19
 	 */
20
-	function __construct( $block_deletes = true, $blocking_delete_error_message =''){
21
-		parent::__construct( 'Extra_Join', $block_deletes, $blocking_delete_error_message);
20
+	function __construct($block_deletes = true, $blocking_delete_error_message = '') {
21
+		parent::__construct('Extra_Join', $block_deletes, $blocking_delete_error_message);
22 22
 	}
23
-	function _construct_finalize_set_models($this_model_name, $other_model_name){
24
-		if( $this_model_name < $other_model_name ) {
23
+	function _construct_finalize_set_models($this_model_name, $other_model_name) {
24
+		if ($this_model_name < $other_model_name) {
25 25
 			$this->_alphabetically_first_model_name = $this_model_name;
26
-		} else{
26
+		} else {
27 27
 			$this->_alphabetically_first_model_name = $other_model_name;
28 28
 		}
29
-		return parent::_construct_finalize_set_models( $this_model_name, $other_model_name );
29
+		return parent::_construct_finalize_set_models($this_model_name, $other_model_name);
30 30
 	}
31 31
 	
32 32
 	/**
@@ -36,21 +36,21 @@  discard block
 block discarded – undo
36 36
 	 * @param string $id_or_name_field should be the string 'ID' or 'name' only
37 37
 	 * @return EE_Model_Field_Base
38 38
 	 */
39
-	function get_join_table_fk_field_to( $model_name, $id_or_name_field ) {
39
+	function get_join_table_fk_field_to($model_name, $id_or_name_field) {
40 40
 		$order = null;
41
-		if( $model_name === $this->_alphabetically_first_model_name ) {
41
+		if ($model_name === $this->_alphabetically_first_model_name) {
42 42
 			$order = 'first';
43 43
 		} else {
44 44
 			$order = 'second';
45 45
 		}
46
-		return $this->get_join_model()->field_settings_for( 'EXJ_' . $order . '_model_' . $id_or_name_field );
46
+		return $this->get_join_model()->field_settings_for('EXJ_'.$order.'_model_'.$id_or_name_field);
47 47
 	}
48 48
 	/**
49 49
 	 * Gets the SQL string for joining the main model's table containing the pk to the join table. Eg "LEFT JOIN real_join_table AS join_table_alias ON this_table_alias.pk = join_table_alias.fk_to_this_table"
50 50
 	 * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
51 51
 	 * @return string of SQL
52 52
 	 */
53
-	function get_join_to_intermediate_model_statement($model_relation_chain){
53
+	function get_join_to_intermediate_model_statement($model_relation_chain) {
54 54
 		//create sql like
55 55
 		//LEFT JOIN join_table AS join_table_alias ON this_table_alias.this_table_pk = join_table_alias.join_table_fk_to_this
56 56
 		//LEFT JOIN other_table AS other_table_alias ON join_table_alias.join_table_fk_to_other = other_table_alias.other_table_pk
@@ -64,8 +64,8 @@  discard block
 block discarded – undo
64 64
 		$field_with_model_name = $this->get_join_table_fk_field_to( 
65 65
 				$this->get_this_model()->get_this_model_name(), 
66 66
 				'name' );
67
-		$this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_this_model()->get_this_model_name()) . $this_table_pk_field->get_table_alias();
68
-		$join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_join_model()->get_this_model_name()) . $join_table_fk_field_to_this_table->get_table_alias();
67
+		$this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_this_model()->get_this_model_name()).$this_table_pk_field->get_table_alias();
68
+		$join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_join_model()->get_this_model_name()).$join_table_fk_field_to_this_table->get_table_alias();
69 69
 		$join_table = $this->get_join_model()->get_table_for_alias($join_table_alias);
70 70
 		//phew! ok, we have all the info we need, now we can create the SQL join string
71 71
 		$SQL = $this->_left_join(
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 					$join_table_fk_field_to_this_table->get_table_column(), 
75 75
 					$this_table_alias, 
76 76
 					$this_table_pk_field->get_table_column(),
77
-					$field_with_model_name->get_qualified_column()."='".$this->get_this_model()->get_this_model_name()."'" ) .
77
+					$field_with_model_name->get_qualified_column()."='".$this->get_this_model()->get_this_model_name()."'" ).
78 78
 				$this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias);
79 79
 
80 80
 		return $SQL;
@@ -87,9 +87,9 @@  discard block
 block discarded – undo
87 87
 	 * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
88 88
 	 * @return string of SQL
89 89
 	 */
90
-	function get_join_statement($model_relation_chain){
91
-		if( $this->_model_relation_chain_to_join_model === NULL ){
92
-			throw new EE_Error( sprintf( __( 'When using EE_HABTM_Relation to create a join, you must call get_join_to_intermediate_model_statement BEFORE get_join_statement', 'event_espresso' )));
90
+	function get_join_statement($model_relation_chain) {
91
+		if ($this->_model_relation_chain_to_join_model === NULL) {
92
+			throw new EE_Error(sprintf(__('When using EE_HABTM_Relation to create a join, you must call get_join_to_intermediate_model_statement BEFORE get_join_statement', 'event_espresso')));
93 93
 		}
94 94
 		$join_table_fk_field_to_this_table = $this->get_join_table_fk_field_to( 
95 95
 				$this->get_this_model()->get_this_model_name(), 
@@ -101,10 +101,10 @@  discard block
 block discarded – undo
101 101
 				$this->get_other_model()->get_this_model_name(), 
102 102
 				'name' );
103 103
 		
104
-		$join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($this->_model_relation_chain_to_join_model, $this->get_join_model()->get_this_model_name()) . $join_table_fk_field_to_this_table->get_table_alias();
104
+		$join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($this->_model_relation_chain_to_join_model, $this->get_join_model()->get_this_model_name()).$join_table_fk_field_to_this_table->get_table_alias();
105 105
 		
106 106
 		$other_table_pk_field = $this->get_other_model()->get_primary_key_field();
107
-		$other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_other_model()->get_this_model_name()) . $other_table_pk_field->get_table_alias();
107
+		$other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_other_model()->get_this_model_name()).$other_table_pk_field->get_table_alias();
108 108
 		$other_table = $this->get_other_model()->get_table_for_alias($other_table_alias);
109 109
 
110 110
 		$SQL = $this->_left_join(
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 					$join_table_alias, 
115 115
 					$join_table_fk_field_to_other_table->get_table_column(),
116 116
 					$field_with_other_model_name->get_qualified_column()."='".$this->get_other_model()->get_this_model_name()."'" 
117
-				) . 
117
+				). 
118 118
 				$this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
119 119
 		return $SQL;
120 120
 	}
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 	 * @param array             $extra_join_model_fields_n_values col=>val pairs that are used as extra conditions for checking existing values and for setting new rows if no exact matches.
127 127
 	 * @return EE_Base_Class
128 128
 	 */
129
-	 function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array() ){
129
+	 function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) {
130 130
 		 $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
131 131
 		 $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
132 132
 		//check if such a relationship already exists
@@ -143,31 +143,31 @@  discard block
 block discarded – undo
143 143
 				$this->get_other_model()->get_this_model_name(),
144 144
 				'name' );
145 145
 
146
-		$cols_n_values =  array(
146
+		$cols_n_values = array(
147 147
 				$join_model_fk_to_this_model->get_name() => $this_model_obj->ID(),
148 148
 				$join_model_name_field_to_this_model->get_name() => $this_model_obj->get_model()->get_this_model_name(),
149 149
 				$join_model_fk_to_other_model->get_name() => $other_model_obj->ID(),
150 150
 				$join_model_name_field_to_other_model->get_name() => $other_model_obj->get_model()->get_this_model_name() );
151 151
 
152 152
 		//if $where_query exists lets add them to the query_params.
153
-		if ( !empty( $extra_join_model_fields_n_values ) ) {
153
+		if ( ! empty($extra_join_model_fields_n_values)) {
154 154
 		   //make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name)
155 155
 		   //make sure we strip THIS models name from the query param
156
-		   foreach ( $extra_join_model_fields_n_values as $query_param => $val ) {
157
-			   $query_param = str_replace($this->get_join_model()->get_this_model_name().".","", $query_param);
156
+		   foreach ($extra_join_model_fields_n_values as $query_param => $val) {
157
+			   $query_param = str_replace($this->get_join_model()->get_this_model_name().".", "", $query_param);
158 158
 			   $parsed_query[$query_param] = $val;
159 159
 		   }
160
-		   $cols_n_values = array_merge( $cols_n_values, $parsed_query );
160
+		   $cols_n_values = array_merge($cols_n_values, $parsed_query);
161 161
 		}
162 162
 
163
-		$query_params = array( $cols_n_values );
163
+		$query_params = array($cols_n_values);
164 164
 
165 165
 
166 166
 		$existing_entry_in_join_table = $this->get_join_model()->get_one($query_params);
167 167
 		//if there is already an entry in the join table, indicating a relationship, we're done
168 168
 		 //again, if you want more sophisticated logic or insertions (handling more columns than just 2 foreign keys to
169 169
 		 //the other tables, use the joining model directly!
170
-		if( ! $existing_entry_in_join_table ){
170
+		if ( ! $existing_entry_in_join_table) {
171 171
 			$this->get_join_model()->insert($cols_n_values);
172 172
 		}
173 173
 		return $other_model_obj;
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 	 * * @param array           $where_query col=>val pairs that are used as extra conditions for checking existing values and for removing existing rows if exact matches exist.
180 180
 	 * @return EE_Base_Class
181 181
 	 */
182
-	 function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array() ){
182
+	 function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) {
183 183
 		 $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
184 184
 		 $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
185 185
 		//check if such a relationship already exists
@@ -196,24 +196,24 @@  discard block
 block discarded – undo
196 196
 				$this->get_other_model()->get_this_model_name(), 
197 197
 				'name' );
198 198
 
199
-		$cols_n_values =  array(
199
+		$cols_n_values = array(
200 200
 				$join_model_fk_to_this_model->get_name() => $this_model_obj->ID(),
201 201
 				$join_model_name_field_to_this_model->get_name() => $this_model_obj->get_model()->get_this_model_name(),
202 202
 				$join_model_fk_to_other_model->get_name() => $other_model_obj->ID(),
203 203
 				$join_model_name_field_to_other_model->get_name() => $other_model_obj->get_model()->get_this_model_name() );
204 204
 
205 205
 		//if $where_query exists lets add them to the query_params.
206
-		if ( !empty( $where_query ) ) {
206
+		if ( ! empty($where_query)) {
207 207
 		 	//make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name)
208 208
 		 	//make sure we strip THIS models name from the query param
209
-		 	foreach ( $where_query as $query_param => $val ) {
210
-				$query_param = str_replace($this->get_join_model()->get_this_model_name().".","", $query_param);
209
+		 	foreach ($where_query as $query_param => $val) {
210
+				$query_param = str_replace($this->get_join_model()->get_this_model_name().".", "", $query_param);
211 211
 				$parsed_query[$query_param] = $val;
212 212
 			}
213
-		 	$cols_n_values = array_merge( $cols_n_values, $parsed_query );
213
+		 	$cols_n_values = array_merge($cols_n_values, $parsed_query);
214 214
 		}
215 215
 
216
-		$existing_entry_in_join_table = $this->get_join_model()->delete( array($cols_n_values) );
216
+		$existing_entry_in_join_table = $this->get_join_model()->delete(array($cols_n_values));
217 217
 		return $other_model_obj;
218 218
 	 }
219 219
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Extra_Join.model.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -12,30 +12,30 @@
 block discarded – undo
12 12
  * @since		 	   $VID:$
13 13
  *
14 14
  */
15
-if (!defined('EVENT_ESPRESSO_VERSION')) {
15
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
16 16
 	exit('No direct script access allowed');
17 17
 }
18 18
 
19
-class EEM_Extra_Join extends EEM_Base{
19
+class EEM_Extra_Join extends EEM_Base {
20 20
 	// private instance of the Extra Join object
21 21
 	protected static $_instance = NULL;
22 22
 	
23 23
 	public function __construct($timezone = NULL) {
24
-		$models_this_can_join = array_keys( EE_Registry::instance()->non_abstract_db_models );
24
+		$models_this_can_join = array_keys(EE_Registry::instance()->non_abstract_db_models);
25 25
 		$this->_tables = array(
26
-			'Extra_Join' => new EE_Primary_Table( 'esp_extra_join', 'EXJ_ID' ),
26
+			'Extra_Join' => new EE_Primary_Table('esp_extra_join', 'EXJ_ID'),
27 27
 		);
28 28
 		$this->_fields = array(
29 29
 			'Extra_Join' => array(
30
-				'EXJ_ID' => new EE_Primary_Key_Int_Field( 'EXJ_ID', __( 'Extra Join ID', 'event_espresso' ) ),
31
-				'EXJ_first_model_ID' => new EE_Foreign_Key_String_Field( 'EXJ_first_model_ID', __( 'First Model ID', 'event_espresso' ), true, 0, $models_this_can_join ),
32
-				'EXJ_first_model_name' => new EE_Any_Foreign_Model_Name_Field( 'EXJ_first_model_name', __( 'First Model Name', 'event_espresso'), true, '', $models_this_can_join ),
33
-				'EXJ_second_model_ID' => new EE_Foreign_Key_String_Field( 'EXJ_second_model_ID', __( 'Second Model ID', 'event_espresso' ), true, 0, $models_this_can_join ),
34
-				'EXJ_second_model_name' => new EE_Any_Foreign_Model_Name_Field( 'EXJ_second_model_name', __( 'Second Model Name', 'event_espresso'), true, '', $models_this_can_join ),
30
+				'EXJ_ID' => new EE_Primary_Key_Int_Field('EXJ_ID', __('Extra Join ID', 'event_espresso')),
31
+				'EXJ_first_model_ID' => new EE_Foreign_Key_String_Field('EXJ_first_model_ID', __('First Model ID', 'event_espresso'), true, 0, $models_this_can_join),
32
+				'EXJ_first_model_name' => new EE_Any_Foreign_Model_Name_Field('EXJ_first_model_name', __('First Model Name', 'event_espresso'), true, '', $models_this_can_join),
33
+				'EXJ_second_model_ID' => new EE_Foreign_Key_String_Field('EXJ_second_model_ID', __('Second Model ID', 'event_espresso'), true, 0, $models_this_can_join),
34
+				'EXJ_second_model_name' => new EE_Any_Foreign_Model_Name_Field('EXJ_second_model_name', __('Second Model Name', 'event_espresso'), true, '', $models_this_can_join),
35 35
 				
36 36
 			)
37 37
 		);
38
-		foreach($models_this_can_join as $model){
38
+		foreach ($models_this_can_join as $model) {
39 39
 			$this->_model_relations[$model] = new EE_Belongs_To_Any_Relation();
40 40
 		}
41 41
 		parent::__construct($timezone);
Please login to merge, or discard this patch.
core/db_classes/EE_Extra_Join.class.php 3 patches
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,10 +1,10 @@
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
2 2
 /**
3
- * Contains definition for EE_Extra_Join model object
4
- * @package 		Event Espresso
5
- * @subpackage 	models
6
- * @since 			$VID$
7
- */
3
+	 * Contains definition for EE_Extra_Join model object
4
+	 * @package 		Event Espresso
5
+	 * @subpackage 	models
6
+	 * @since 			$VID$
7
+	 */
8 8
 
9 9
 /**
10 10
  * EE_Extra_Join
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -22,9 +22,9 @@  discard block
 block discarded – undo
22 22
 	 * @param null  $timezone
23 23
 	 * @return EE_Event_Message_Template|mixed
24 24
 	 */
25
-	public static function new_instance( $props_n_values = array(), $timezone = NULL ) {
26
-		$has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone );
27
-		return $has_object ? $has_object : new self( $props_n_values, FALSE, $timezone );
25
+	public static function new_instance($props_n_values = array(), $timezone = NULL) {
26
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone);
27
+		return $has_object ? $has_object : new self($props_n_values, FALSE, $timezone);
28 28
 	}
29 29
 
30 30
 
@@ -34,8 +34,8 @@  discard block
 block discarded – undo
34 34
 	 * @param null  $timezone
35 35
 	 * @return EE_Event_Message_Template
36 36
 	 */
37
-	public static function new_instance_from_db ( $props_n_values = array(), $timezone = NULL ) {
38
-		return new self( $props_n_values, TRUE, $timezone );
37
+	public static function new_instance_from_db($props_n_values = array(), $timezone = NULL) {
38
+		return new self($props_n_values, TRUE, $timezone);
39 39
 	}
40 40
 
41 41
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,4 +1,6 @@
 block discarded – undo
1
-<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
+	exit('No direct script access allowed');
3
+}
2 4
 /**
3 5
  * Event Espresso
4 6
  *
Please login to merge, or discard this patch.