Completed
Branch FET/table-schema-dms (6bf39e)
by
unknown
09:25 queued 06:29
created
core/db_models/EEM_Registration_Payment.model.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@
 block discarded – undo
20 20
     {
21 21
 
22 22
         $this->singular_item = __('Registration Payment', 'event_espresso');
23
-        $this->plural_item  = __('Registration Payments', 'event_espresso');
23
+        $this->plural_item = __('Registration Payments', 'event_espresso');
24 24
 
25 25
         $this->_tables = array(
26 26
             'Registration_Payment' => new EE_Primary_Table('esp_registration_payment', 'RPY_ID')
Please login to merge, or discard this patch.
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -13,34 +13,34 @@
 block discarded – undo
13 13
 class EEM_Registration_Payment extends EEM_Base
14 14
 {
15 15
 
16
-    // private instance
17
-    protected static $_instance = null;
16
+	// private instance
17
+	protected static $_instance = null;
18 18
 
19 19
 
20
-    protected function __construct($timezone = null)
21
-    {
20
+	protected function __construct($timezone = null)
21
+	{
22 22
 
23
-        $this->singular_item = __('Registration Payment', 'event_espresso');
24
-        $this->plural_item  = __('Registration Payments', 'event_espresso');
23
+		$this->singular_item = __('Registration Payment', 'event_espresso');
24
+		$this->plural_item  = __('Registration Payments', 'event_espresso');
25 25
 
26
-        $this->_tables = array(
27
-            'Registration_Payment' => new EE_Primary_Table('esp_registration_payment', 'RPY_ID')
28
-        );
26
+		$this->_tables = array(
27
+			'Registration_Payment' => new EE_Primary_Table('esp_registration_payment', 'RPY_ID')
28
+		);
29 29
 
30
-        $this->_fields = array(
31
-            'Registration_Payment' => array(
32
-                'RPY_ID'                => new EE_Primary_Key_Int_Field('RPY_ID', __('Registration Payment ID', 'event_espresso')),
33
-                'REG_ID'                => new EE_Foreign_Key_Int_Field('REG_ID', __('Registration ID', 'event_espresso'), false, 0, 'Registration'),
34
-                'PAY_ID'                => new EE_Foreign_Key_Int_Field('PAY_ID', __('Payment ID', 'event_espresso'), true, null, 'Payment'),
35
-                'RPY_amount'    => new EE_Money_Field('RPY_amount', __('Amount attributed to the registration', 'event_espresso'), false, 0),
36
-            )
37
-        );
30
+		$this->_fields = array(
31
+			'Registration_Payment' => array(
32
+				'RPY_ID'                => new EE_Primary_Key_Int_Field('RPY_ID', __('Registration Payment ID', 'event_espresso')),
33
+				'REG_ID'                => new EE_Foreign_Key_Int_Field('REG_ID', __('Registration ID', 'event_espresso'), false, 0, 'Registration'),
34
+				'PAY_ID'                => new EE_Foreign_Key_Int_Field('PAY_ID', __('Payment ID', 'event_espresso'), true, null, 'Payment'),
35
+				'RPY_amount'    => new EE_Money_Field('RPY_amount', __('Amount attributed to the registration', 'event_espresso'), false, 0),
36
+			)
37
+		);
38 38
 
39
-        $this->_model_relations = array(
40
-            'Registration'  => new EE_Belongs_To_Relation(),
41
-            'Payment'       => new EE_Belongs_To_Relation(),
42
-        );
39
+		$this->_model_relations = array(
40
+			'Registration'  => new EE_Belongs_To_Relation(),
41
+			'Payment'       => new EE_Belongs_To_Relation(),
42
+		);
43 43
 
44
-        parent::__construct($timezone);
45
-    }
44
+		parent::__construct($timezone);
45
+	}
46 46
 }
Please login to merge, or discard this patch.
core/db_models/relations/EE_Belongs_To_Any_Relation.php 2 patches
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -16,94 +16,94 @@
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * get_join_statement
21
-     *
22
-     * @param string $model_relation_chain
23
-     * @return string
24
-     * @throws \EE_Error
25
-     */
26
-    public function get_join_statement($model_relation_chain)
27
-    {
28
-        // create the sql string like
29
-        $this_table_fk_field = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
30
-        // ALSO, need to get the field with the model name
31
-        $field_with_model_name = $this->get_this_model()->get_field_containing_related_model_name();
19
+	/**
20
+	 * get_join_statement
21
+	 *
22
+	 * @param string $model_relation_chain
23
+	 * @return string
24
+	 * @throws \EE_Error
25
+	 */
26
+	public function get_join_statement($model_relation_chain)
27
+	{
28
+		// create the sql string like
29
+		$this_table_fk_field = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
30
+		// ALSO, need to get the field with the model name
31
+		$field_with_model_name = $this->get_this_model()->get_field_containing_related_model_name();
32 32
 
33 33
 
34
-        $other_table_pk_field = $this->get_other_model()->get_primary_key_field();
35
-        $this_table_alias     = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
36
-            $model_relation_chain,
37
-            $this->get_this_model()->get_this_model_name()
38
-        ) . $this_table_fk_field->get_table_alias();
39
-        $other_table_alias    = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
40
-            $model_relation_chain,
41
-            $this->get_other_model()->get_this_model_name()
42
-        ) . $other_table_pk_field->get_table_alias();
43
-        $other_table          = $this->get_other_model()->get_table_for_alias($other_table_alias);
44
-        return $this->_left_join(
45
-            $other_table,
46
-            $other_table_alias,
47
-            $other_table_pk_field->get_table_column(),
48
-            $this_table_alias,
49
-            $this_table_fk_field->get_table_column(),
50
-            $field_with_model_name->get_qualified_column() . "='" . $this->get_other_model()->get_this_model_name() . "'"
51
-        )
52
-               . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
53
-    }
34
+		$other_table_pk_field = $this->get_other_model()->get_primary_key_field();
35
+		$this_table_alias     = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
36
+			$model_relation_chain,
37
+			$this->get_this_model()->get_this_model_name()
38
+		) . $this_table_fk_field->get_table_alias();
39
+		$other_table_alias    = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
40
+			$model_relation_chain,
41
+			$this->get_other_model()->get_this_model_name()
42
+		) . $other_table_pk_field->get_table_alias();
43
+		$other_table          = $this->get_other_model()->get_table_for_alias($other_table_alias);
44
+		return $this->_left_join(
45
+			$other_table,
46
+			$other_table_alias,
47
+			$other_table_pk_field->get_table_column(),
48
+			$this_table_alias,
49
+			$this_table_fk_field->get_table_column(),
50
+			$field_with_model_name->get_qualified_column() . "='" . $this->get_other_model()->get_this_model_name() . "'"
51
+		)
52
+			   . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
53
+	}
54 54
 
55 55
 
56
-    /**
57
-     * Sets this model object's foreign key to the other model object's primary key. Feel free to do this manually if
58
-     * you like.
59
-     *
60
-     * @param EE_Base_Class|int $this_obj_or_id
61
-     * @param EE_Base_Class|int $other_obj_or_id
62
-     * @param array             $extra_join_model_fields_n_values
63
-     * @return \EE_Base_Class
64
-     * @throws \EE_Error
65
-     */
66
-    public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
67
-    {
68
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
69
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
70
-        // find the field on THIS model which a foreign key to the other model
71
-        $fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
72
-        // set that field on the other model to this model's ID
73
-        $this_model_obj->set($fk_on_this_model->get_name(), $other_model_obj->ID());
74
-        // and make sure this model's field with the foreign model name is set to the correct value
75
-        $this_model_obj->set(
76
-            $this->get_this_model()->get_field_containing_related_model_name()->get_name(),
77
-            $this->get_other_model()->get_this_model_name()
78
-        );
79
-        $this_model_obj->save();
80
-        return $other_model_obj;
81
-    }
56
+	/**
57
+	 * Sets this model object's foreign key to the other model object's primary key. Feel free to do this manually if
58
+	 * you like.
59
+	 *
60
+	 * @param EE_Base_Class|int $this_obj_or_id
61
+	 * @param EE_Base_Class|int $other_obj_or_id
62
+	 * @param array             $extra_join_model_fields_n_values
63
+	 * @return \EE_Base_Class
64
+	 * @throws \EE_Error
65
+	 */
66
+	public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
67
+	{
68
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
69
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
70
+		// find the field on THIS model which a foreign key to the other model
71
+		$fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
72
+		// set that field on the other model to this model's ID
73
+		$this_model_obj->set($fk_on_this_model->get_name(), $other_model_obj->ID());
74
+		// and make sure this model's field with the foreign model name is set to the correct value
75
+		$this_model_obj->set(
76
+			$this->get_this_model()->get_field_containing_related_model_name()->get_name(),
77
+			$this->get_other_model()->get_this_model_name()
78
+		);
79
+		$this_model_obj->save();
80
+		return $other_model_obj;
81
+	}
82 82
 
83 83
 
84
-    /**
85
-     * Sets the this model object's foreign key to its default, instead of pointing to the other model object
86
-     *
87
-     * @param EE_Base_Class|int $this_obj_or_id
88
-     * @param EE_Base_Class|int $other_obj_or_id
89
-     * @param array             $where_query
90
-     * @return \EE_Base_Class
91
-     * @throws \EE_Error
92
-     */
93
-    public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
94
-    {
95
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
96
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id);
97
-        // find the field on the other model which is a foreign key to this model
98
-        $fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
99
-        // set that field on the other model to this model's ID
100
-        $this_model_obj->set($fk_on_this_model->get_name(), null, true);
101
-        $this_model_obj->set(
102
-            $this->get_this_model()->get_field_containing_related_model_name()->get_name(),
103
-            null,
104
-            true
105
-        );
106
-        $this_model_obj->save();
107
-        return $other_model_obj;
108
-    }
84
+	/**
85
+	 * Sets the this model object's foreign key to its default, instead of pointing to the other model object
86
+	 *
87
+	 * @param EE_Base_Class|int $this_obj_or_id
88
+	 * @param EE_Base_Class|int $other_obj_or_id
89
+	 * @param array             $where_query
90
+	 * @return \EE_Base_Class
91
+	 * @throws \EE_Error
92
+	 */
93
+	public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
94
+	{
95
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
96
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id);
97
+		// find the field on the other model which is a foreign key to this model
98
+		$fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
99
+		// set that field on the other model to this model's ID
100
+		$this_model_obj->set($fk_on_this_model->get_name(), null, true);
101
+		$this_model_obj->set(
102
+			$this->get_this_model()->get_field_containing_related_model_name()->get_name(),
103
+			null,
104
+			true
105
+		);
106
+		$this_model_obj->save();
107
+		return $other_model_obj;
108
+	}
109 109
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -35,19 +35,19 @@
 block discarded – undo
35 35
         $this_table_alias     = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
36 36
             $model_relation_chain,
37 37
             $this->get_this_model()->get_this_model_name()
38
-        ) . $this_table_fk_field->get_table_alias();
39
-        $other_table_alias    = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
38
+        ).$this_table_fk_field->get_table_alias();
39
+        $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
40 40
             $model_relation_chain,
41 41
             $this->get_other_model()->get_this_model_name()
42
-        ) . $other_table_pk_field->get_table_alias();
43
-        $other_table          = $this->get_other_model()->get_table_for_alias($other_table_alias);
42
+        ).$other_table_pk_field->get_table_alias();
43
+        $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias);
44 44
         return $this->_left_join(
45 45
             $other_table,
46 46
             $other_table_alias,
47 47
             $other_table_pk_field->get_table_column(),
48 48
             $this_table_alias,
49 49
             $this_table_fk_field->get_table_column(),
50
-            $field_with_model_name->get_qualified_column() . "='" . $this->get_other_model()->get_this_model_name() . "'"
50
+            $field_with_model_name->get_qualified_column()."='".$this->get_other_model()->get_this_model_name()."'"
51 51
         )
52 52
                . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
53 53
     }
Please login to merge, or discard this patch.
core/db_models/relations/EE_Has_Many_Relation.php 2 patches
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -11,102 +11,102 @@
 block discarded – undo
11 11
 class EE_Has_Many_Relation extends EE_Model_Relation_Base
12 12
 {
13 13
 
14
-    /**
15
-     * Object representing the relationship between two models. Has_Many_Relations are where the OTHER model has the
16
-     * foreign key this model. IE, there can be many other model objects related to one of this model's objects (but
17
-     * NOT through a JOIN table, which is the case for EE_HABTM_Relations). This knows how to join the models, get
18
-     * related models across the relation, and add-and-remove the relationships.
19
-     *
20
-     * @param boolean $block_deletes                 For this type of r elation, we block by default. If there are
21
-     *                                               related models across this relation, block (prevent and add an
22
-     *                                               error) the deletion of this model
23
-     * @param string  $blocking_delete_error_message a customized error message on blocking deletes instead of the
24
-     *                                               default
25
-     */
26
-    public function __construct($block_deletes = true, $blocking_delete_error_message = null)
27
-    {
28
-        parent::__construct($block_deletes, $blocking_delete_error_message);
29
-    }
14
+	/**
15
+	 * Object representing the relationship between two models. Has_Many_Relations are where the OTHER model has the
16
+	 * foreign key this model. IE, there can be many other model objects related to one of this model's objects (but
17
+	 * NOT through a JOIN table, which is the case for EE_HABTM_Relations). This knows how to join the models, get
18
+	 * related models across the relation, and add-and-remove the relationships.
19
+	 *
20
+	 * @param boolean $block_deletes                 For this type of r elation, we block by default. If there are
21
+	 *                                               related models across this relation, block (prevent and add an
22
+	 *                                               error) the deletion of this model
23
+	 * @param string  $blocking_delete_error_message a customized error message on blocking deletes instead of the
24
+	 *                                               default
25
+	 */
26
+	public function __construct($block_deletes = true, $blocking_delete_error_message = null)
27
+	{
28
+		parent::__construct($block_deletes, $blocking_delete_error_message);
29
+	}
30 30
 
31 31
 
32
-    /**
33
-     * Gets the SQL string for performing the join between this model and the other model.
34
-     *
35
-     * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
36
-     * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk =
37
-     *                other_model_primary_table.fk" etc
38
-     * @throws \EE_Error
39
-     */
40
-    public function get_join_statement($model_relation_chain)
41
-    {
42
-        // create the sql string like
43
-        // LEFT JOIN other_table AS table_alias ON this_table_alias.pk = other_table_alias.fk extra_join_conditions
44
-        $this_table_pk_field  = $this->get_this_model()->get_primary_key_field();
45
-        $other_table_fk_field = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
46
-        $pk_table_alias       = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
47
-            $model_relation_chain,
48
-            $this->get_this_model()->get_this_model_name()
49
-        ) . $this_table_pk_field->get_table_alias();
50
-        $fk_table_alias       = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
51
-            $model_relation_chain,
52
-            $this->get_other_model()->get_this_model_name()
53
-        ) . $other_table_fk_field->get_table_alias();
54
-        $fk_table             = $this->get_other_model()->get_table_for_alias($fk_table_alias);
32
+	/**
33
+	 * Gets the SQL string for performing the join between this model and the other model.
34
+	 *
35
+	 * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
36
+	 * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk =
37
+	 *                other_model_primary_table.fk" etc
38
+	 * @throws \EE_Error
39
+	 */
40
+	public function get_join_statement($model_relation_chain)
41
+	{
42
+		// create the sql string like
43
+		// LEFT JOIN other_table AS table_alias ON this_table_alias.pk = other_table_alias.fk extra_join_conditions
44
+		$this_table_pk_field  = $this->get_this_model()->get_primary_key_field();
45
+		$other_table_fk_field = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
46
+		$pk_table_alias       = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
47
+			$model_relation_chain,
48
+			$this->get_this_model()->get_this_model_name()
49
+		) . $this_table_pk_field->get_table_alias();
50
+		$fk_table_alias       = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
51
+			$model_relation_chain,
52
+			$this->get_other_model()->get_this_model_name()
53
+		) . $other_table_fk_field->get_table_alias();
54
+		$fk_table             = $this->get_other_model()->get_table_for_alias($fk_table_alias);
55 55
 
56
-        return $this->_left_join(
57
-            $fk_table,
58
-            $fk_table_alias,
59
-            $other_table_fk_field->get_table_column(),
60
-            $pk_table_alias,
61
-            $this_table_pk_field->get_table_column()
62
-        ) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias);
63
-    }
56
+		return $this->_left_join(
57
+			$fk_table,
58
+			$fk_table_alias,
59
+			$other_table_fk_field->get_table_column(),
60
+			$pk_table_alias,
61
+			$this_table_pk_field->get_table_column()
62
+		) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias);
63
+	}
64 64
 
65 65
 
66
-    /**
67
-     * Sets the other model object's foreign key to this model object's primary key. Feel free to do this manually if
68
-     * you like.
69
-     *
70
-     * @param EE_Base_Class|int $this_obj_or_id
71
-     * @param EE_Base_Class|int $other_obj_or_id
72
-     * @param array             $extra_join_model_fields_n_values
73
-     * @return \EE_Base_Class
74
-     * @throws \EE_Error
75
-     */
76
-    public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
77
-    {
78
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
79
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
66
+	/**
67
+	 * Sets the other model object's foreign key to this model object's primary key. Feel free to do this manually if
68
+	 * you like.
69
+	 *
70
+	 * @param EE_Base_Class|int $this_obj_or_id
71
+	 * @param EE_Base_Class|int $other_obj_or_id
72
+	 * @param array             $extra_join_model_fields_n_values
73
+	 * @return \EE_Base_Class
74
+	 * @throws \EE_Error
75
+	 */
76
+	public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
77
+	{
78
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
79
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
80 80
 
81
-        // find the field on the other model which is a foreign key to this model
82
-        $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
83
-        if ($other_model_obj->get($fk_field_on_other_model->get_name()) != $this_model_obj->ID()) {
84
-            // set that field on the other model to this model's ID
85
-            $other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID());
86
-            $other_model_obj->save();
87
-        }
88
-        return $other_model_obj;
89
-    }
81
+		// find the field on the other model which is a foreign key to this model
82
+		$fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
83
+		if ($other_model_obj->get($fk_field_on_other_model->get_name()) != $this_model_obj->ID()) {
84
+			// set that field on the other model to this model's ID
85
+			$other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID());
86
+			$other_model_obj->save();
87
+		}
88
+		return $other_model_obj;
89
+	}
90 90
 
91 91
 
92
-    /**
93
-     * Sets the other model object's foreign key to its default, instead of pointing to this model object.
94
-     * If $other_obj_or_id doesn't have any other relations, this function is essentially orphaning it
95
-     *
96
-     * @param EE_Base_Class|int $this_obj_or_id
97
-     * @param EE_Base_Class|int $other_obj_or_id
98
-     * @param array             $where_query
99
-     * @return \EE_Base_Class
100
-     * @throws \EE_Error
101
-     */
102
-    public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
103
-    {
104
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
105
-        // find the field on the other model which is a foreign key to this model
106
-        $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
107
-        // set that field on the other model to this model's ID
108
-        $other_model_obj->set($fk_field_on_other_model->get_name(), null, true);
109
-        $other_model_obj->save();
110
-        return $other_model_obj;
111
-    }
92
+	/**
93
+	 * Sets the other model object's foreign key to its default, instead of pointing to this model object.
94
+	 * If $other_obj_or_id doesn't have any other relations, this function is essentially orphaning it
95
+	 *
96
+	 * @param EE_Base_Class|int $this_obj_or_id
97
+	 * @param EE_Base_Class|int $other_obj_or_id
98
+	 * @param array             $where_query
99
+	 * @return \EE_Base_Class
100
+	 * @throws \EE_Error
101
+	 */
102
+	public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
103
+	{
104
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
105
+		// find the field on the other model which is a foreign key to this model
106
+		$fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
107
+		// set that field on the other model to this model's ID
108
+		$other_model_obj->set($fk_field_on_other_model->get_name(), null, true);
109
+		$other_model_obj->save();
110
+		return $other_model_obj;
111
+	}
112 112
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -46,12 +46,12 @@  discard block
 block discarded – undo
46 46
         $pk_table_alias       = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
47 47
             $model_relation_chain,
48 48
             $this->get_this_model()->get_this_model_name()
49
-        ) . $this_table_pk_field->get_table_alias();
50
-        $fk_table_alias       = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
49
+        ).$this_table_pk_field->get_table_alias();
50
+        $fk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
51 51
             $model_relation_chain,
52 52
             $this->get_other_model()->get_this_model_name()
53
-        ) . $other_table_fk_field->get_table_alias();
54
-        $fk_table             = $this->get_other_model()->get_table_for_alias($fk_table_alias);
53
+        ).$other_table_fk_field->get_table_alias();
54
+        $fk_table = $this->get_other_model()->get_table_for_alias($fk_table_alias);
55 55
 
56 56
         return $this->_left_join(
57 57
             $fk_table,
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
             $other_table_fk_field->get_table_column(),
60 60
             $pk_table_alias,
61 61
             $this_table_pk_field->get_table_column()
62
-        ) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias);
62
+        ).$this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias);
63 63
     }
64 64
 
65 65
 
Please login to merge, or discard this patch.
core/db_models/relations/EE_Belongs_To_Relation.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -45,19 +45,19 @@  discard block
 block discarded – undo
45 45
         $this_table_alias     = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
46 46
             $model_relation_chain,
47 47
             $this->get_this_model()->get_this_model_name()
48
-        ) . $this_table_fk_field->get_table_alias();
49
-        $other_table_alias    = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
48
+        ).$this_table_fk_field->get_table_alias();
49
+        $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
50 50
             $model_relation_chain,
51 51
             $this->get_other_model()->get_this_model_name()
52
-        ) . $other_table_pk_field->get_table_alias();
53
-        $other_table          = $this->get_other_model()->get_table_for_alias($other_table_alias);
52
+        ).$other_table_pk_field->get_table_alias();
53
+        $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias);
54 54
         return $this->_left_join(
55 55
             $other_table,
56 56
             $other_table_alias,
57 57
             $other_table_pk_field->get_table_column(),
58 58
             $this_table_alias,
59 59
             $this_table_fk_field->get_table_column()
60
-        ) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
60
+        ).$this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
61 61
     }
62 62
 
63 63
 
@@ -139,8 +139,8 @@  discard block
 block discarded – undo
139 139
         }
140 140
         $ID_value_on_other_model = $model_obj->get($fk_field_obj->get_name());
141 141
         // get all where their PK matches that value
142
-        $query_params[0][ $this->get_other_model()->get_primary_key_field()->get_name() ] = $ID_value_on_other_model;
143
-        $query_params                                                                   = $this->_disable_default_where_conditions_on_query_param($query_params);
142
+        $query_params[0][$this->get_other_model()->get_primary_key_field()->get_name()] = $ID_value_on_other_model;
143
+        $query_params = $this->_disable_default_where_conditions_on_query_param($query_params);
144 144
 //      echo '$query_params';
145 145
 //      var_dump($query_params);
146 146
         return $this->get_other_model()->get_all($query_params);
Please login to merge, or discard this patch.
Indentation   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -12,137 +12,137 @@
 block discarded – undo
12 12
 class EE_Belongs_To_Relation extends EE_Model_Relation_Base
13 13
 {
14 14
 
15
-    /**
16
-     * Object representing the relationship between two models. Belongs_To means that THIS model has the foreign key
17
-     * to the other model. This knows how to join the models,
18
-     * get related models across the relation, and add-and-remove the relationships.
19
-     *
20
-     * @param boolean $block_deletes                                For Belongs_To relations, this is set to FALSE by
21
-     *                                                              default. if there are related models across this
22
-     *                                                              relation, block (prevent and add an error) the
23
-     *                                                              deletion of this model
24
-     * @param string  $related_model_objects_deletion_error_message a customized error message on blocking deletes
25
-     *                                                              instead of the default
26
-     */
27
-    public function __construct($block_deletes = false, $related_model_objects_deletion_error_message = null)
28
-    {
29
-        parent::__construct($block_deletes, $related_model_objects_deletion_error_message);
30
-    }
15
+	/**
16
+	 * Object representing the relationship between two models. Belongs_To means that THIS model has the foreign key
17
+	 * to the other model. This knows how to join the models,
18
+	 * get related models across the relation, and add-and-remove the relationships.
19
+	 *
20
+	 * @param boolean $block_deletes                                For Belongs_To relations, this is set to FALSE by
21
+	 *                                                              default. if there are related models across this
22
+	 *                                                              relation, block (prevent and add an error) the
23
+	 *                                                              deletion of this model
24
+	 * @param string  $related_model_objects_deletion_error_message a customized error message on blocking deletes
25
+	 *                                                              instead of the default
26
+	 */
27
+	public function __construct($block_deletes = false, $related_model_objects_deletion_error_message = null)
28
+	{
29
+		parent::__construct($block_deletes, $related_model_objects_deletion_error_message);
30
+	}
31 31
 
32 32
 
33
-    /**
34
-     * get_join_statement
35
-     *
36
-     * @param string $model_relation_chain
37
-     * @return string
38
-     * @throws \EE_Error
39
-     */
40
-    public function get_join_statement($model_relation_chain)
41
-    {
42
-        // create the sql string like
43
-        $this_table_fk_field  = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
44
-        $other_table_pk_field = $this->get_other_model()->get_primary_key_field();
45
-        $this_table_alias     = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
46
-            $model_relation_chain,
47
-            $this->get_this_model()->get_this_model_name()
48
-        ) . $this_table_fk_field->get_table_alias();
49
-        $other_table_alias    = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
50
-            $model_relation_chain,
51
-            $this->get_other_model()->get_this_model_name()
52
-        ) . $other_table_pk_field->get_table_alias();
53
-        $other_table          = $this->get_other_model()->get_table_for_alias($other_table_alias);
54
-        return $this->_left_join(
55
-            $other_table,
56
-            $other_table_alias,
57
-            $other_table_pk_field->get_table_column(),
58
-            $this_table_alias,
59
-            $this_table_fk_field->get_table_column()
60
-        ) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
61
-    }
33
+	/**
34
+	 * get_join_statement
35
+	 *
36
+	 * @param string $model_relation_chain
37
+	 * @return string
38
+	 * @throws \EE_Error
39
+	 */
40
+	public function get_join_statement($model_relation_chain)
41
+	{
42
+		// create the sql string like
43
+		$this_table_fk_field  = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
44
+		$other_table_pk_field = $this->get_other_model()->get_primary_key_field();
45
+		$this_table_alias     = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
46
+			$model_relation_chain,
47
+			$this->get_this_model()->get_this_model_name()
48
+		) . $this_table_fk_field->get_table_alias();
49
+		$other_table_alias    = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
50
+			$model_relation_chain,
51
+			$this->get_other_model()->get_this_model_name()
52
+		) . $other_table_pk_field->get_table_alias();
53
+		$other_table          = $this->get_other_model()->get_table_for_alias($other_table_alias);
54
+		return $this->_left_join(
55
+			$other_table,
56
+			$other_table_alias,
57
+			$other_table_pk_field->get_table_column(),
58
+			$this_table_alias,
59
+			$this_table_fk_field->get_table_column()
60
+		) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
61
+	}
62 62
 
63 63
 
64
-    /**
65
-     * Sets this model object's foreign key to the other model object's primary key. Feel free to do this manually if
66
-     * you like.
67
-     *
68
-     * @param EE_Base_Class|int $this_obj_or_id
69
-     * @param EE_Base_Class|int $other_obj_or_id
70
-     * @param array             $extra_join_model_fields_n_values
71
-     * @return \EE_Base_Class
72
-     * @throws \EE_Error
73
-     */
74
-    public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
75
-    {
76
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
77
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
78
-        // find the field on the other model which is a foreign key to this model
79
-        $fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
80
-        if ($this_model_obj->get($fk_on_this_model->get_name()) != $other_model_obj->ID()) {
81
-            // set that field on the other model to this model's ID
82
-            $this_model_obj->set($fk_on_this_model->get_name(), $other_model_obj->ID());
83
-            $this_model_obj->save();
84
-        }
85
-        return $other_model_obj;
86
-    }
64
+	/**
65
+	 * Sets this model object's foreign key to the other model object's primary key. Feel free to do this manually if
66
+	 * you like.
67
+	 *
68
+	 * @param EE_Base_Class|int $this_obj_or_id
69
+	 * @param EE_Base_Class|int $other_obj_or_id
70
+	 * @param array             $extra_join_model_fields_n_values
71
+	 * @return \EE_Base_Class
72
+	 * @throws \EE_Error
73
+	 */
74
+	public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
75
+	{
76
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
77
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
78
+		// find the field on the other model which is a foreign key to this model
79
+		$fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
80
+		if ($this_model_obj->get($fk_on_this_model->get_name()) != $other_model_obj->ID()) {
81
+			// set that field on the other model to this model's ID
82
+			$this_model_obj->set($fk_on_this_model->get_name(), $other_model_obj->ID());
83
+			$this_model_obj->save();
84
+		}
85
+		return $other_model_obj;
86
+	}
87 87
 
88 88
 
89
-    /**
90
-     * Sets the this model object's foreign key to its default, instead of pointing to the other model object
91
-     *
92
-     * @param EE_Base_Class|int $this_obj_or_id
93
-     * @param EE_Base_Class|int $other_obj_or_id
94
-     * @param array             $where_query
95
-     * @return \EE_Base_Class
96
-     * @throws \EE_Error
97
-     */
98
-    public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
99
-    {
100
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
101
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id);
102
-        // find the field on the other model which is a foreign key to this model
103
-        $fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
104
-        // set that field on the other model to this model's ID
105
-        $this_model_obj->set($fk_on_this_model->get_name(), null, true);
106
-        $this_model_obj->save();
107
-        return $other_model_obj;
108
-    }
89
+	/**
90
+	 * Sets the this model object's foreign key to its default, instead of pointing to the other model object
91
+	 *
92
+	 * @param EE_Base_Class|int $this_obj_or_id
93
+	 * @param EE_Base_Class|int $other_obj_or_id
94
+	 * @param array             $where_query
95
+	 * @return \EE_Base_Class
96
+	 * @throws \EE_Error
97
+	 */
98
+	public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
99
+	{
100
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
101
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id);
102
+		// find the field on the other model which is a foreign key to this model
103
+		$fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
104
+		// set that field on the other model to this model's ID
105
+		$this_model_obj->set($fk_on_this_model->get_name(), null, true);
106
+		$this_model_obj->save();
107
+		return $other_model_obj;
108
+	}
109 109
 
110 110
 
111
-    /**
112
-     * Overrides parent so that we don't NEED to save the $model_object before getting the related objects.
113
-     *
114
-     * @param EE_Base_Class $model_obj_or_id
115
-     * @param array         $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
116
-     * @param boolean       $values_already_prepared_by_model_object @deprecated since 4.8.1
117
-     * @return EE_Base_Class[]
118
-     * @throws \EE_Error
119
-     */
120
-    public function get_all_related(
121
-        $model_obj_or_id,
122
-        $query_params = array(),
123
-        $values_already_prepared_by_model_object = false
124
-    ) {
125
-        if ($values_already_prepared_by_model_object !== false) {
126
-            EE_Error::doing_it_wrong(
127
-                'EE_Model_Relation_Base::get_all_related',
128
-                __('The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso'),
129
-                '4.8.1'
130
-            );
131
-        }
132
-        // get column on this model object which is a foreign key to the other model
133
-        $fk_field_obj = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
134
-        // get its value
135
-        if ($model_obj_or_id instanceof EE_Base_Class) {
136
-            $model_obj = $model_obj_or_id;
137
-        } else {
138
-            $model_obj = $this->get_this_model()->ensure_is_obj($model_obj_or_id);
139
-        }
140
-        $ID_value_on_other_model = $model_obj->get($fk_field_obj->get_name());
141
-        // get all where their PK matches that value
142
-        $query_params[0][ $this->get_other_model()->get_primary_key_field()->get_name() ] = $ID_value_on_other_model;
143
-        $query_params                                                                   = $this->_disable_default_where_conditions_on_query_param($query_params);
111
+	/**
112
+	 * Overrides parent so that we don't NEED to save the $model_object before getting the related objects.
113
+	 *
114
+	 * @param EE_Base_Class $model_obj_or_id
115
+	 * @param array         $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
116
+	 * @param boolean       $values_already_prepared_by_model_object @deprecated since 4.8.1
117
+	 * @return EE_Base_Class[]
118
+	 * @throws \EE_Error
119
+	 */
120
+	public function get_all_related(
121
+		$model_obj_or_id,
122
+		$query_params = array(),
123
+		$values_already_prepared_by_model_object = false
124
+	) {
125
+		if ($values_already_prepared_by_model_object !== false) {
126
+			EE_Error::doing_it_wrong(
127
+				'EE_Model_Relation_Base::get_all_related',
128
+				__('The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso'),
129
+				'4.8.1'
130
+			);
131
+		}
132
+		// get column on this model object which is a foreign key to the other model
133
+		$fk_field_obj = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
134
+		// get its value
135
+		if ($model_obj_or_id instanceof EE_Base_Class) {
136
+			$model_obj = $model_obj_or_id;
137
+		} else {
138
+			$model_obj = $this->get_this_model()->ensure_is_obj($model_obj_or_id);
139
+		}
140
+		$ID_value_on_other_model = $model_obj->get($fk_field_obj->get_name());
141
+		// get all where their PK matches that value
142
+		$query_params[0][ $this->get_other_model()->get_primary_key_field()->get_name() ] = $ID_value_on_other_model;
143
+		$query_params                                                                   = $this->_disable_default_where_conditions_on_query_param($query_params);
144 144
 //      echo '$query_params';
145 145
 //      var_dump($query_params);
146
-        return $this->get_other_model()->get_all($query_params);
147
-    }
146
+		return $this->get_other_model()->get_all($query_params);
147
+	}
148 148
 }
Please login to merge, or discard this patch.
core/db_models/relations/EE_HABTM_Any_Relation.php 2 patches
Indentation   +265 added lines, -265 removed lines patch added patch discarded remove patch
@@ -10,294 +10,294 @@
 block discarded – undo
10 10
  */
11 11
 class EE_HABTM_Any_Relation extends EE_HABTM_Relation
12 12
 {
13
-    /**
14
-     * @var string
15
-     */
16
-    protected $_alphabetically_first_model_name;
13
+	/**
14
+	 * @var string
15
+	 */
16
+	protected $_alphabetically_first_model_name;
17 17
 
18
-    /**
19
-     * Object representing the relationship between two models. HasAndBelongsToMany relations always use a join-table
20
-     * (and an ee joining-model.) This knows how to join the models,
21
-     * get related models across the relation, and add-and-remove the relationships.
22
-     *
23
-     * @param boolean $block_deletes                 for this type of relation, we block by default for now. if there
24
-     *                                               are related models across this relation, block (prevent and add an
25
-     *                                               error) the deletion of this model
26
-     * @param string  $blocking_delete_error_message a customized error message on blocking deletes instead of the
27
-     *                                               default
28
-     */
29
-    public function __construct($block_deletes = true, $blocking_delete_error_message = '')
30
-    {
31
-        parent::__construct('Extra_Join', $block_deletes, $blocking_delete_error_message);
32
-    }
18
+	/**
19
+	 * Object representing the relationship between two models. HasAndBelongsToMany relations always use a join-table
20
+	 * (and an ee joining-model.) This knows how to join the models,
21
+	 * get related models across the relation, and add-and-remove the relationships.
22
+	 *
23
+	 * @param boolean $block_deletes                 for this type of relation, we block by default for now. if there
24
+	 *                                               are related models across this relation, block (prevent and add an
25
+	 *                                               error) the deletion of this model
26
+	 * @param string  $blocking_delete_error_message a customized error message on blocking deletes instead of the
27
+	 *                                               default
28
+	 */
29
+	public function __construct($block_deletes = true, $blocking_delete_error_message = '')
30
+	{
31
+		parent::__construct('Extra_Join', $block_deletes, $blocking_delete_error_message);
32
+	}
33 33
 
34 34
 
35
-    /**
36
-     * @param $this_model_name
37
-     * @param $other_model_name
38
-     * @throws EE_Error
39
-     */
40
-    public function _construct_finalize_set_models($this_model_name, $other_model_name)
41
-    {
42
-        if ($this_model_name < $other_model_name) {
43
-            $this->_alphabetically_first_model_name = $this_model_name;
44
-        } else {
45
-            $this->_alphabetically_first_model_name = $other_model_name;
46
-        }
47
-        parent::_construct_finalize_set_models($this_model_name, $other_model_name);
48
-    }
35
+	/**
36
+	 * @param $this_model_name
37
+	 * @param $other_model_name
38
+	 * @throws EE_Error
39
+	 */
40
+	public function _construct_finalize_set_models($this_model_name, $other_model_name)
41
+	{
42
+		if ($this_model_name < $other_model_name) {
43
+			$this->_alphabetically_first_model_name = $this_model_name;
44
+		} else {
45
+			$this->_alphabetically_first_model_name = $other_model_name;
46
+		}
47
+		parent::_construct_finalize_set_models($this_model_name, $other_model_name);
48
+	}
49 49
 
50 50
 
51
-    /**
52
-     * @param string $model_name
53
-     * @param string $id_or_name_field should be the string 'ID' or 'name' only
54
-     * @return EE_Model_Field_Base
55
-     * @throws \EE_Error
56
-     */
57
-    public function get_join_table_fk_field_to($model_name, $id_or_name_field)
58
-    {
59
-        $order = null;
60
-        if ($model_name === $this->_alphabetically_first_model_name) {
61
-            $order = 'first';
62
-        } else {
63
-            $order = 'second';
64
-        }
65
-        return $this->get_join_model()->field_settings_for('EXJ_' . $order . '_model_' . $id_or_name_field);
66
-    }
51
+	/**
52
+	 * @param string $model_name
53
+	 * @param string $id_or_name_field should be the string 'ID' or 'name' only
54
+	 * @return EE_Model_Field_Base
55
+	 * @throws \EE_Error
56
+	 */
57
+	public function get_join_table_fk_field_to($model_name, $id_or_name_field)
58
+	{
59
+		$order = null;
60
+		if ($model_name === $this->_alphabetically_first_model_name) {
61
+			$order = 'first';
62
+		} else {
63
+			$order = 'second';
64
+		}
65
+		return $this->get_join_model()->field_settings_for('EXJ_' . $order . '_model_' . $id_or_name_field);
66
+	}
67 67
 
68 68
 
69
-    /**
70
-     * Gets the SQL string for joining the main model's table containing the pk to the join table. Eg "LEFT JOIN
71
-     * real_join_table AS join_table_alias ON this_table_alias.pk = join_table_alias.fk_to_this_table"
72
-     *
73
-     * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
74
-     * @return string of SQL
75
-     * @throws \EE_Error
76
-     */
77
-    public function get_join_to_intermediate_model_statement($model_relation_chain)
78
-    {
79
-        // create sql like
80
-        // LEFT JOIN join_table AS join_table_alias ON this_table_alias.this_table_pk = join_table_alias.join_table_fk_to_this
81
-        // LEFT JOIN other_table AS other_table_alias ON join_table_alias.join_table_fk_to_other = other_table_alias.other_table_pk
82
-        // remember the model relation chain to the JOIN model, because we'll
83
-        // need it for get_join_statement()
84
-        $this->_model_relation_chain_to_join_model = $model_relation_chain;
85
-        $this_table_pk_field                       = $this->get_this_model()->get_primary_key_field();
86
-        $join_table_fk_field_to_this_table         = $this->get_join_table_fk_field_to(
87
-            $this->get_this_model()->get_this_model_name(),
88
-            'ID'
89
-        );
90
-        $field_with_model_name                     = $this->get_join_table_fk_field_to(
91
-            $this->get_this_model()->get_this_model_name(),
92
-            'name'
93
-        );
94
-        $this_table_alias                          = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
95
-            $model_relation_chain,
96
-            $this->get_this_model()->get_this_model_name()
97
-        ) . $this_table_pk_field->get_table_alias();
98
-        $join_table_alias                          = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
99
-            $model_relation_chain,
100
-            $this->get_join_model()->get_this_model_name()
101
-        ) . $join_table_fk_field_to_this_table->get_table_alias();
102
-        $join_table                                = $this->get_join_model()->get_table_for_alias($join_table_alias);
103
-        // phew! ok, we have all the info we need, now we can create the SQL join string
104
-        $SQL = $this->_left_join(
105
-            $join_table,
106
-            $join_table_alias,
107
-            $join_table_fk_field_to_this_table->get_table_column(),
108
-            $this_table_alias,
109
-            $this_table_pk_field->get_table_column(),
110
-            $field_with_model_name->get_qualified_column() . "='" . $this->get_this_model()->get_this_model_name() . "'"
111
-        ) .
112
-               $this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias);
69
+	/**
70
+	 * Gets the SQL string for joining the main model's table containing the pk to the join table. Eg "LEFT JOIN
71
+	 * real_join_table AS join_table_alias ON this_table_alias.pk = join_table_alias.fk_to_this_table"
72
+	 *
73
+	 * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
74
+	 * @return string of SQL
75
+	 * @throws \EE_Error
76
+	 */
77
+	public function get_join_to_intermediate_model_statement($model_relation_chain)
78
+	{
79
+		// create sql like
80
+		// LEFT JOIN join_table AS join_table_alias ON this_table_alias.this_table_pk = join_table_alias.join_table_fk_to_this
81
+		// LEFT JOIN other_table AS other_table_alias ON join_table_alias.join_table_fk_to_other = other_table_alias.other_table_pk
82
+		// remember the model relation chain to the JOIN model, because we'll
83
+		// need it for get_join_statement()
84
+		$this->_model_relation_chain_to_join_model = $model_relation_chain;
85
+		$this_table_pk_field                       = $this->get_this_model()->get_primary_key_field();
86
+		$join_table_fk_field_to_this_table         = $this->get_join_table_fk_field_to(
87
+			$this->get_this_model()->get_this_model_name(),
88
+			'ID'
89
+		);
90
+		$field_with_model_name                     = $this->get_join_table_fk_field_to(
91
+			$this->get_this_model()->get_this_model_name(),
92
+			'name'
93
+		);
94
+		$this_table_alias                          = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
95
+			$model_relation_chain,
96
+			$this->get_this_model()->get_this_model_name()
97
+		) . $this_table_pk_field->get_table_alias();
98
+		$join_table_alias                          = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
99
+			$model_relation_chain,
100
+			$this->get_join_model()->get_this_model_name()
101
+		) . $join_table_fk_field_to_this_table->get_table_alias();
102
+		$join_table                                = $this->get_join_model()->get_table_for_alias($join_table_alias);
103
+		// phew! ok, we have all the info we need, now we can create the SQL join string
104
+		$SQL = $this->_left_join(
105
+			$join_table,
106
+			$join_table_alias,
107
+			$join_table_fk_field_to_this_table->get_table_column(),
108
+			$this_table_alias,
109
+			$this_table_pk_field->get_table_column(),
110
+			$field_with_model_name->get_qualified_column() . "='" . $this->get_this_model()->get_this_model_name() . "'"
111
+		) .
112
+			   $this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias);
113 113
 
114
-        return $SQL;
115
-    }
114
+		return $SQL;
115
+	}
116 116
 
117 117
 
118
-    /**
119
-     * Gets the SQL string for joining the join table to the other model's pk's table. Eg "LEFT JOIN real_other_table
120
-     * AS other_table_alias ON join_table_alias.fk_to_other_table = other_table_alias.pk" If you want to join between
121
-     * modelA -> joinModelAB -> modelB (eg, Event -> Event_Question_Group -> Question_Group), you should prepend the
122
-     * result of this function with results from get_join_to_intermediate_model_statement(), so that you join first to
123
-     * the intermediate join table, and then to the other model's pk's table
124
-     *
125
-     * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
126
-     * @return string of SQL
127
-     * @throws \EE_Error
128
-     */
129
-    public function get_join_statement($model_relation_chain)
130
-    {
131
-        if ($this->_model_relation_chain_to_join_model === null) {
132
-            throw new EE_Error(sprintf(__(
133
-                'When using EE_HABTM_Relation to create a join, you must call get_join_to_intermediate_model_statement BEFORE get_join_statement',
134
-                'event_espresso'
135
-            )));
136
-        }
137
-        $join_table_fk_field_to_this_table  = $this->get_join_table_fk_field_to(
138
-            $this->get_this_model()->get_this_model_name(),
139
-            'ID'
140
-        );
141
-        $join_table_fk_field_to_other_table = $this->get_join_table_fk_field_to(
142
-            $this->get_other_model()->get_this_model_name(),
143
-            'ID'
144
-        );
145
-        $field_with_other_model_name        = $this->get_join_table_fk_field_to(
146
-            $this->get_other_model()->get_this_model_name(),
147
-            'name'
148
-        );
118
+	/**
119
+	 * Gets the SQL string for joining the join table to the other model's pk's table. Eg "LEFT JOIN real_other_table
120
+	 * AS other_table_alias ON join_table_alias.fk_to_other_table = other_table_alias.pk" If you want to join between
121
+	 * modelA -> joinModelAB -> modelB (eg, Event -> Event_Question_Group -> Question_Group), you should prepend the
122
+	 * result of this function with results from get_join_to_intermediate_model_statement(), so that you join first to
123
+	 * the intermediate join table, and then to the other model's pk's table
124
+	 *
125
+	 * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
126
+	 * @return string of SQL
127
+	 * @throws \EE_Error
128
+	 */
129
+	public function get_join_statement($model_relation_chain)
130
+	{
131
+		if ($this->_model_relation_chain_to_join_model === null) {
132
+			throw new EE_Error(sprintf(__(
133
+				'When using EE_HABTM_Relation to create a join, you must call get_join_to_intermediate_model_statement BEFORE get_join_statement',
134
+				'event_espresso'
135
+			)));
136
+		}
137
+		$join_table_fk_field_to_this_table  = $this->get_join_table_fk_field_to(
138
+			$this->get_this_model()->get_this_model_name(),
139
+			'ID'
140
+		);
141
+		$join_table_fk_field_to_other_table = $this->get_join_table_fk_field_to(
142
+			$this->get_other_model()->get_this_model_name(),
143
+			'ID'
144
+		);
145
+		$field_with_other_model_name        = $this->get_join_table_fk_field_to(
146
+			$this->get_other_model()->get_this_model_name(),
147
+			'name'
148
+		);
149 149
 
150
-        $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
151
-            $this->_model_relation_chain_to_join_model,
152
-            $this->get_join_model()->get_this_model_name()
153
-        ) . $join_table_fk_field_to_this_table->get_table_alias();
150
+		$join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
151
+			$this->_model_relation_chain_to_join_model,
152
+			$this->get_join_model()->get_this_model_name()
153
+		) . $join_table_fk_field_to_this_table->get_table_alias();
154 154
 
155
-        $other_table_pk_field = $this->get_other_model()->get_primary_key_field();
156
-        $other_table_alias    = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
157
-            $model_relation_chain,
158
-            $this->get_other_model()->get_this_model_name()
159
-        ) . $other_table_pk_field->get_table_alias();
160
-        $other_table          = $this->get_other_model()->get_table_for_alias($other_table_alias);
155
+		$other_table_pk_field = $this->get_other_model()->get_primary_key_field();
156
+		$other_table_alias    = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
157
+			$model_relation_chain,
158
+			$this->get_other_model()->get_this_model_name()
159
+		) . $other_table_pk_field->get_table_alias();
160
+		$other_table          = $this->get_other_model()->get_table_for_alias($other_table_alias);
161 161
 
162
-        $SQL = $this->_left_join(
163
-            $other_table,
164
-            $other_table_alias,
165
-            $other_table_pk_field->get_table_column(),
166
-            $join_table_alias,
167
-            $join_table_fk_field_to_other_table->get_table_column(),
168
-            $field_with_other_model_name->get_qualified_column() . "='" . $this->get_other_model()->get_this_model_name() . "'"
169
-        ) .
170
-               $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
171
-        return $SQL;
172
-    }
162
+		$SQL = $this->_left_join(
163
+			$other_table,
164
+			$other_table_alias,
165
+			$other_table_pk_field->get_table_column(),
166
+			$join_table_alias,
167
+			$join_table_fk_field_to_other_table->get_table_column(),
168
+			$field_with_other_model_name->get_qualified_column() . "='" . $this->get_other_model()->get_this_model_name() . "'"
169
+		) .
170
+			   $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
171
+		return $SQL;
172
+	}
173 173
 
174 174
 
175
-    /**
176
-     * Ensures there is an entry in the join table between these two models. Feel free to do this manually if you like.
177
-     *
178
-     * @param EE_Base_Class|int $this_obj_or_id
179
-     * @param EE_Base_Class|int $other_obj_or_id
180
-     * @param array             $extra_join_model_fields_n_values col=>val pairs that are used as extra conditions for
181
-     *                                                            checking existing values and for setting new rows if
182
-     *                                                            no exact matches.
183
-     * @return EE_Base_Class
184
-     * @throws \EE_Error
185
-     */
186
-    public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
187
-    {
188
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
189
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
190
-        // check if such a relationship already exists
191
-        $join_model_fk_to_this_model          = $this->get_join_table_fk_field_to(
192
-            $this->get_this_model()->get_this_model_name(),
193
-            'ID'
194
-        );
195
-        $join_model_name_field_to_this_model  = $this->get_join_table_fk_field_to(
196
-            $this->get_this_model()->get_this_model_name(),
197
-            'name'
198
-        );
199
-        $join_model_fk_to_other_model         = $this->get_join_table_fk_field_to(
200
-            $this->get_other_model()->get_this_model_name(),
201
-            'ID'
202
-        );
203
-        $join_model_name_field_to_other_model = $this->get_join_table_fk_field_to(
204
-            $this->get_other_model()->get_this_model_name(),
205
-            'name'
206
-        );
175
+	/**
176
+	 * Ensures there is an entry in the join table between these two models. Feel free to do this manually if you like.
177
+	 *
178
+	 * @param EE_Base_Class|int $this_obj_or_id
179
+	 * @param EE_Base_Class|int $other_obj_or_id
180
+	 * @param array             $extra_join_model_fields_n_values col=>val pairs that are used as extra conditions for
181
+	 *                                                            checking existing values and for setting new rows if
182
+	 *                                                            no exact matches.
183
+	 * @return EE_Base_Class
184
+	 * @throws \EE_Error
185
+	 */
186
+	public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
187
+	{
188
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
189
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
190
+		// check if such a relationship already exists
191
+		$join_model_fk_to_this_model          = $this->get_join_table_fk_field_to(
192
+			$this->get_this_model()->get_this_model_name(),
193
+			'ID'
194
+		);
195
+		$join_model_name_field_to_this_model  = $this->get_join_table_fk_field_to(
196
+			$this->get_this_model()->get_this_model_name(),
197
+			'name'
198
+		);
199
+		$join_model_fk_to_other_model         = $this->get_join_table_fk_field_to(
200
+			$this->get_other_model()->get_this_model_name(),
201
+			'ID'
202
+		);
203
+		$join_model_name_field_to_other_model = $this->get_join_table_fk_field_to(
204
+			$this->get_other_model()->get_this_model_name(),
205
+			'name'
206
+		);
207 207
 
208
-        $cols_n_values = array(
209
-            $join_model_fk_to_this_model->get_name()          => $this_model_obj->ID(),
210
-            $join_model_name_field_to_this_model->get_name()  => $this_model_obj->get_model()->get_this_model_name(),
211
-            $join_model_fk_to_other_model->get_name()         => $other_model_obj->ID(),
212
-            $join_model_name_field_to_other_model->get_name() => $other_model_obj->get_model()->get_this_model_name(),
213
-        );
208
+		$cols_n_values = array(
209
+			$join_model_fk_to_this_model->get_name()          => $this_model_obj->ID(),
210
+			$join_model_name_field_to_this_model->get_name()  => $this_model_obj->get_model()->get_this_model_name(),
211
+			$join_model_fk_to_other_model->get_name()         => $other_model_obj->ID(),
212
+			$join_model_name_field_to_other_model->get_name() => $other_model_obj->get_model()->get_this_model_name(),
213
+		);
214 214
 
215
-        // if $where_query exists lets add them to the query_params.
216
-        if (! empty($extra_join_model_fields_n_values)) {
217
-            // 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)
218
-            // make sure we strip THIS models name from the query param
219
-            $parsed_query = array();
220
-            foreach ($extra_join_model_fields_n_values as $query_param => $val) {
221
-                $query_param                = str_replace(
222
-                    $this->get_join_model()->get_this_model_name() . ".",
223
-                    "",
224
-                    $query_param
225
-                );
226
-                $parsed_query[ $query_param ] = $val;
227
-            }
228
-            $cols_n_values = array_merge($cols_n_values, $parsed_query);
229
-        }
215
+		// if $where_query exists lets add them to the query_params.
216
+		if (! empty($extra_join_model_fields_n_values)) {
217
+			// 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)
218
+			// make sure we strip THIS models name from the query param
219
+			$parsed_query = array();
220
+			foreach ($extra_join_model_fields_n_values as $query_param => $val) {
221
+				$query_param                = str_replace(
222
+					$this->get_join_model()->get_this_model_name() . ".",
223
+					"",
224
+					$query_param
225
+				);
226
+				$parsed_query[ $query_param ] = $val;
227
+			}
228
+			$cols_n_values = array_merge($cols_n_values, $parsed_query);
229
+		}
230 230
 
231
-        $query_params = array($cols_n_values);
231
+		$query_params = array($cols_n_values);
232 232
 
233 233
 
234
-        $existing_entry_in_join_table = $this->get_join_model()->get_one($query_params);
235
-        // if there is already an entry in the join table, indicating a relationship, we're done
236
-        // again, if you want more sophisticated logic or insertions (handling more columns than just 2 foreign keys to
237
-        // the other tables, use the joining model directly!
238
-        if (! $existing_entry_in_join_table) {
239
-            $this->get_join_model()->insert($cols_n_values);
240
-        }
241
-        return $other_model_obj;
242
-    }
234
+		$existing_entry_in_join_table = $this->get_join_model()->get_one($query_params);
235
+		// if there is already an entry in the join table, indicating a relationship, we're done
236
+		// again, if you want more sophisticated logic or insertions (handling more columns than just 2 foreign keys to
237
+		// the other tables, use the joining model directly!
238
+		if (! $existing_entry_in_join_table) {
239
+			$this->get_join_model()->insert($cols_n_values);
240
+		}
241
+		return $other_model_obj;
242
+	}
243 243
 
244 244
 
245
-    /**
246
-     * Deletes any rows in the join table that have foreign keys matching the other model objects specified
247
-     *
248
-     * @param EE_Base_Class|int $this_obj_or_id
249
-     * @param EE_Base_Class|int $other_obj_or_id
250
-     * @param array             $where_query col=>val pairs that are used as extra conditions for checking existing
251
-     *                                       values and for removing existing rows if exact matches exist.
252
-     * @return EE_Base_Class
253
-     * @throws \EE_Error
254
-     */
255
-    public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
256
-    {
257
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
258
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
259
-        // check if such a relationship already exists
260
-        $join_model_fk_to_this_model          = $this->get_join_table_fk_field_to(
261
-            $this->get_this_model()->get_this_model_name(),
262
-            'ID'
263
-        );
264
-        $join_model_name_field_to_this_model  = $this->get_join_table_fk_field_to(
265
-            $this->get_this_model()->get_this_model_name(),
266
-            'name'
267
-        );
268
-        $join_model_fk_to_other_model         = $this->get_join_table_fk_field_to(
269
-            $this->get_other_model()->get_this_model_name(),
270
-            'ID'
271
-        );
272
-        $join_model_name_field_to_other_model = $this->get_join_table_fk_field_to(
273
-            $this->get_other_model()->get_this_model_name(),
274
-            'name'
275
-        );
245
+	/**
246
+	 * Deletes any rows in the join table that have foreign keys matching the other model objects specified
247
+	 *
248
+	 * @param EE_Base_Class|int $this_obj_or_id
249
+	 * @param EE_Base_Class|int $other_obj_or_id
250
+	 * @param array             $where_query col=>val pairs that are used as extra conditions for checking existing
251
+	 *                                       values and for removing existing rows if exact matches exist.
252
+	 * @return EE_Base_Class
253
+	 * @throws \EE_Error
254
+	 */
255
+	public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
256
+	{
257
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
258
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
259
+		// check if such a relationship already exists
260
+		$join_model_fk_to_this_model          = $this->get_join_table_fk_field_to(
261
+			$this->get_this_model()->get_this_model_name(),
262
+			'ID'
263
+		);
264
+		$join_model_name_field_to_this_model  = $this->get_join_table_fk_field_to(
265
+			$this->get_this_model()->get_this_model_name(),
266
+			'name'
267
+		);
268
+		$join_model_fk_to_other_model         = $this->get_join_table_fk_field_to(
269
+			$this->get_other_model()->get_this_model_name(),
270
+			'ID'
271
+		);
272
+		$join_model_name_field_to_other_model = $this->get_join_table_fk_field_to(
273
+			$this->get_other_model()->get_this_model_name(),
274
+			'name'
275
+		);
276 276
 
277
-        $cols_n_values = array(
278
-            $join_model_fk_to_this_model->get_name()          => $this_model_obj->ID(),
279
-            $join_model_name_field_to_this_model->get_name()  => $this_model_obj->get_model()->get_this_model_name(),
280
-            $join_model_fk_to_other_model->get_name()         => $other_model_obj->ID(),
281
-            $join_model_name_field_to_other_model->get_name() => $other_model_obj->get_model()->get_this_model_name(),
282
-        );
277
+		$cols_n_values = array(
278
+			$join_model_fk_to_this_model->get_name()          => $this_model_obj->ID(),
279
+			$join_model_name_field_to_this_model->get_name()  => $this_model_obj->get_model()->get_this_model_name(),
280
+			$join_model_fk_to_other_model->get_name()         => $other_model_obj->ID(),
281
+			$join_model_name_field_to_other_model->get_name() => $other_model_obj->get_model()->get_this_model_name(),
282
+		);
283 283
 
284
-        // if $where_query exists lets add them to the query_params.
285
-        if (! empty($where_query)) {
286
-            // 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)
287
-            // make sure we strip THIS models name from the query param
288
-            $parsed_query = array();
289
-            foreach ($where_query as $query_param => $val) {
290
-                $query_param                = str_replace(
291
-                    $this->get_join_model()->get_this_model_name() . ".",
292
-                    "",
293
-                    $query_param
294
-                );
295
-                $parsed_query[ $query_param ] = $val;
296
-            }
297
-            $cols_n_values = array_merge($cols_n_values, $parsed_query);
298
-        }
284
+		// if $where_query exists lets add them to the query_params.
285
+		if (! empty($where_query)) {
286
+			// 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)
287
+			// make sure we strip THIS models name from the query param
288
+			$parsed_query = array();
289
+			foreach ($where_query as $query_param => $val) {
290
+				$query_param                = str_replace(
291
+					$this->get_join_model()->get_this_model_name() . ".",
292
+					"",
293
+					$query_param
294
+				);
295
+				$parsed_query[ $query_param ] = $val;
296
+			}
297
+			$cols_n_values = array_merge($cols_n_values, $parsed_query);
298
+		}
299 299
 
300
-        $this->get_join_model()->delete(array($cols_n_values));
301
-        return $other_model_obj;
302
-    }
300
+		$this->get_join_model()->delete(array($cols_n_values));
301
+		return $other_model_obj;
302
+	}
303 303
 }
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
         } else {
63 63
             $order = 'second';
64 64
         }
65
-        return $this->get_join_model()->field_settings_for('EXJ_' . $order . '_model_' . $id_or_name_field);
65
+        return $this->get_join_model()->field_settings_for('EXJ_'.$order.'_model_'.$id_or_name_field);
66 66
     }
67 67
 
68 68
 
@@ -87,19 +87,19 @@  discard block
 block discarded – undo
87 87
             $this->get_this_model()->get_this_model_name(),
88 88
             'ID'
89 89
         );
90
-        $field_with_model_name                     = $this->get_join_table_fk_field_to(
90
+        $field_with_model_name = $this->get_join_table_fk_field_to(
91 91
             $this->get_this_model()->get_this_model_name(),
92 92
             'name'
93 93
         );
94
-        $this_table_alias                          = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
94
+        $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
95 95
             $model_relation_chain,
96 96
             $this->get_this_model()->get_this_model_name()
97
-        ) . $this_table_pk_field->get_table_alias();
98
-        $join_table_alias                          = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
97
+        ).$this_table_pk_field->get_table_alias();
98
+        $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
99 99
             $model_relation_chain,
100 100
             $this->get_join_model()->get_this_model_name()
101
-        ) . $join_table_fk_field_to_this_table->get_table_alias();
102
-        $join_table                                = $this->get_join_model()->get_table_for_alias($join_table_alias);
101
+        ).$join_table_fk_field_to_this_table->get_table_alias();
102
+        $join_table = $this->get_join_model()->get_table_for_alias($join_table_alias);
103 103
         // phew! ok, we have all the info we need, now we can create the SQL join string
104 104
         $SQL = $this->_left_join(
105 105
             $join_table,
@@ -107,8 +107,8 @@  discard block
 block discarded – undo
107 107
             $join_table_fk_field_to_this_table->get_table_column(),
108 108
             $this_table_alias,
109 109
             $this_table_pk_field->get_table_column(),
110
-            $field_with_model_name->get_qualified_column() . "='" . $this->get_this_model()->get_this_model_name() . "'"
111
-        ) .
110
+            $field_with_model_name->get_qualified_column()."='".$this->get_this_model()->get_this_model_name()."'"
111
+        ).
112 112
                $this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias);
113 113
 
114 114
         return $SQL;
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
                 'event_espresso'
135 135
             )));
136 136
         }
137
-        $join_table_fk_field_to_this_table  = $this->get_join_table_fk_field_to(
137
+        $join_table_fk_field_to_this_table = $this->get_join_table_fk_field_to(
138 138
             $this->get_this_model()->get_this_model_name(),
139 139
             'ID'
140 140
         );
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
             $this->get_other_model()->get_this_model_name(),
143 143
             'ID'
144 144
         );
145
-        $field_with_other_model_name        = $this->get_join_table_fk_field_to(
145
+        $field_with_other_model_name = $this->get_join_table_fk_field_to(
146 146
             $this->get_other_model()->get_this_model_name(),
147 147
             'name'
148 148
         );
@@ -150,14 +150,14 @@  discard block
 block discarded – undo
150 150
         $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
151 151
             $this->_model_relation_chain_to_join_model,
152 152
             $this->get_join_model()->get_this_model_name()
153
-        ) . $join_table_fk_field_to_this_table->get_table_alias();
153
+        ).$join_table_fk_field_to_this_table->get_table_alias();
154 154
 
155 155
         $other_table_pk_field = $this->get_other_model()->get_primary_key_field();
156 156
         $other_table_alias    = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
157 157
             $model_relation_chain,
158 158
             $this->get_other_model()->get_this_model_name()
159
-        ) . $other_table_pk_field->get_table_alias();
160
-        $other_table          = $this->get_other_model()->get_table_for_alias($other_table_alias);
159
+        ).$other_table_pk_field->get_table_alias();
160
+        $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias);
161 161
 
162 162
         $SQL = $this->_left_join(
163 163
             $other_table,
@@ -165,8 +165,8 @@  discard block
 block discarded – undo
165 165
             $other_table_pk_field->get_table_column(),
166 166
             $join_table_alias,
167 167
             $join_table_fk_field_to_other_table->get_table_column(),
168
-            $field_with_other_model_name->get_qualified_column() . "='" . $this->get_other_model()->get_this_model_name() . "'"
169
-        ) .
168
+            $field_with_other_model_name->get_qualified_column()."='".$this->get_other_model()->get_this_model_name()."'"
169
+        ).
170 170
                $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
171 171
         return $SQL;
172 172
     }
@@ -188,15 +188,15 @@  discard block
 block discarded – undo
188 188
         $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
189 189
         $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
190 190
         // check if such a relationship already exists
191
-        $join_model_fk_to_this_model          = $this->get_join_table_fk_field_to(
191
+        $join_model_fk_to_this_model = $this->get_join_table_fk_field_to(
192 192
             $this->get_this_model()->get_this_model_name(),
193 193
             'ID'
194 194
         );
195
-        $join_model_name_field_to_this_model  = $this->get_join_table_fk_field_to(
195
+        $join_model_name_field_to_this_model = $this->get_join_table_fk_field_to(
196 196
             $this->get_this_model()->get_this_model_name(),
197 197
             'name'
198 198
         );
199
-        $join_model_fk_to_other_model         = $this->get_join_table_fk_field_to(
199
+        $join_model_fk_to_other_model = $this->get_join_table_fk_field_to(
200 200
             $this->get_other_model()->get_this_model_name(),
201 201
             'ID'
202 202
         );
@@ -213,17 +213,17 @@  discard block
 block discarded – undo
213 213
         );
214 214
 
215 215
         // if $where_query exists lets add them to the query_params.
216
-        if (! empty($extra_join_model_fields_n_values)) {
216
+        if ( ! empty($extra_join_model_fields_n_values)) {
217 217
             // 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)
218 218
             // make sure we strip THIS models name from the query param
219 219
             $parsed_query = array();
220 220
             foreach ($extra_join_model_fields_n_values as $query_param => $val) {
221
-                $query_param                = str_replace(
222
-                    $this->get_join_model()->get_this_model_name() . ".",
221
+                $query_param = str_replace(
222
+                    $this->get_join_model()->get_this_model_name().".",
223 223
                     "",
224 224
                     $query_param
225 225
                 );
226
-                $parsed_query[ $query_param ] = $val;
226
+                $parsed_query[$query_param] = $val;
227 227
             }
228 228
             $cols_n_values = array_merge($cols_n_values, $parsed_query);
229 229
         }
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
         // if there is already an entry in the join table, indicating a relationship, we're done
236 236
         // again, if you want more sophisticated logic or insertions (handling more columns than just 2 foreign keys to
237 237
         // the other tables, use the joining model directly!
238
-        if (! $existing_entry_in_join_table) {
238
+        if ( ! $existing_entry_in_join_table) {
239 239
             $this->get_join_model()->insert($cols_n_values);
240 240
         }
241 241
         return $other_model_obj;
@@ -257,15 +257,15 @@  discard block
 block discarded – undo
257 257
         $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
258 258
         $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
259 259
         // check if such a relationship already exists
260
-        $join_model_fk_to_this_model          = $this->get_join_table_fk_field_to(
260
+        $join_model_fk_to_this_model = $this->get_join_table_fk_field_to(
261 261
             $this->get_this_model()->get_this_model_name(),
262 262
             'ID'
263 263
         );
264
-        $join_model_name_field_to_this_model  = $this->get_join_table_fk_field_to(
264
+        $join_model_name_field_to_this_model = $this->get_join_table_fk_field_to(
265 265
             $this->get_this_model()->get_this_model_name(),
266 266
             'name'
267 267
         );
268
-        $join_model_fk_to_other_model         = $this->get_join_table_fk_field_to(
268
+        $join_model_fk_to_other_model = $this->get_join_table_fk_field_to(
269 269
             $this->get_other_model()->get_this_model_name(),
270 270
             'ID'
271 271
         );
@@ -282,17 +282,17 @@  discard block
 block discarded – undo
282 282
         );
283 283
 
284 284
         // if $where_query exists lets add them to the query_params.
285
-        if (! empty($where_query)) {
285
+        if ( ! empty($where_query)) {
286 286
             // 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)
287 287
             // make sure we strip THIS models name from the query param
288 288
             $parsed_query = array();
289 289
             foreach ($where_query as $query_param => $val) {
290
-                $query_param                = str_replace(
291
-                    $this->get_join_model()->get_this_model_name() . ".",
290
+                $query_param = str_replace(
291
+                    $this->get_join_model()->get_this_model_name().".",
292 292
                     "",
293 293
                     $query_param
294 294
                 );
295
-                $parsed_query[ $query_param ] = $val;
295
+                $parsed_query[$query_param] = $val;
296 296
             }
297 297
             $cols_n_values = array_merge($cols_n_values, $parsed_query);
298 298
         }
Please login to merge, or discard this patch.
core/db_models/relations/EE_Model_Relation_Base.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
         $this_table_join_column,
157 157
         $extra_join_sql = ''
158 158
     ) {
159
-        return " LEFT JOIN " . $other_table . " AS " . $other_table_alias . " ON " . $other_table_alias . "." . $other_table_column . "=" . $this_table_alias . "." . $this_table_join_column . ($extra_join_sql ? " AND $extra_join_sql" : '');
159
+        return " LEFT JOIN ".$other_table." AS ".$other_table_alias." ON ".$other_table_alias.".".$other_table_column."=".$this_table_alias.".".$this_table_join_column.($extra_join_sql ? " AND $extra_join_sql" : '');
160 160
     }
161 161
 
162 162
 
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
                                                              . "."
191 191
                                                              . $this->get_this_model()->get_primary_key_field()->get_name();
192 192
         $model_object_id                                   = $this->_get_model_object_id($model_object_or_id);
193
-        $query_params[0][ $query_param_where_this_model_pk ] = $model_object_id;
193
+        $query_params[0][$query_param_where_this_model_pk] = $model_object_id;
194 194
         return $this->get_other_model()->get_all($query_params);
195 195
     }
196 196
 
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
      */
204 204
     protected function _disable_default_where_conditions_on_query_param($query_params)
205 205
     {
206
-        if (! isset($query_params['default_where_conditions'])) {
206
+        if ( ! isset($query_params['default_where_conditions'])) {
207 207
             $query_params['default_where_conditions'] = 'none';
208 208
         }
209 209
         return $query_params;
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
                 $model_object_or_id
234 234
             );
235 235
             /* @var $model_object_or_id EE_Base_Class */
236
-            if (! $delete_is_blocked) {
236
+            if ( ! $delete_is_blocked) {
237 237
                 $this->remove_relation_to($model_object_or_id, $related_model_object);
238 238
                 $related_model_object->delete();
239 239
                 $deleted_count++;
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
             if ($related_model_object instanceof EE_Soft_Delete_Base_Class) {
270 270
                 $this->remove_relation_to($model_object_or_id, $related_model_object);
271 271
                 $deleted_count++;
272
-                if (! $delete_is_blocked) {
272
+                if ( ! $delete_is_blocked) {
273 273
                     $related_model_object->delete_permanently();
274 274
                 } else {
275 275
                     // delete is blocked
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
                 }
279 279
             } else {
280 280
                 // its not a soft-deletable thing anyways. do the normal logic.
281
-                if (! $delete_is_blocked) {
281
+                if ( ! $delete_is_blocked) {
282 282
                     $this->remove_relation_to($model_object_or_id, $related_model_object);
283 283
                     $related_model_object->delete();
284 284
                     $deleted_count++;
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
         if ($model_object_or_id instanceof EE_Base_Class) {
303 303
             $model_object_id = $model_object_or_id->ID();
304 304
         }
305
-        if (! $model_object_id) {
305
+        if ( ! $model_object_id) {
306 306
             throw new EE_Error(sprintf(
307 307
                 __(
308 308
                     "Sorry, we cant get the related %s model objects to %s model object before it has an ID. You can solve that by just saving it before trying to get its related model objects",
Please login to merge, or discard this patch.
Indentation   +497 added lines, -497 removed lines patch added patch discarded remove patch
@@ -15,502 +15,502 @@
 block discarded – undo
15 15
  */
16 16
 abstract class EE_Model_Relation_Base implements HasSchemaInterface
17 17
 {
18
-    /**
19
-     * The model name of which this relation is a component (ie, the model that called new EE_Model_Relation_Base)
20
-     *
21
-     * @var string eg Event, Question_Group, Registration
22
-     */
23
-    private $_this_model_name;
24
-    /**
25
-     * The model name pointed to by this relation (ie, the model we want to establish a relationship to)
26
-     *
27
-     * @var string eg Event, Question_Group, Registration
28
-     */
29
-    private $_other_model_name;
30
-
31
-    /**
32
-     * this is typically used when calling the relation models to make sure they inherit any set timezone from the
33
-     * initiating model.
34
-     *
35
-     * @var string
36
-     */
37
-    protected $_timezone;
38
-
39
-    /**
40
-     * If you try to delete "this_model", and there are related "other_models",
41
-     * and this isn't null, then abandon the deletion and add this warning.
42
-     * This effectively makes it impossible to delete "this_model" while there are
43
-     * related "other_models" along this relation.
44
-     *
45
-     * @var string (internationalized)
46
-     */
47
-    protected $_blocking_delete_error_message;
48
-
49
-    protected $_blocking_delete = false;
50
-
51
-    /**
52
-     * Object representing the relationship between two models. This knows how to join the models,
53
-     * get related models across the relation, and add-and-remove the relationships.
54
-     *
55
-     * @param boolean $block_deletes                 if there are related models across this relation, block (prevent
56
-     *                                               and add an error) the deletion of this model
57
-     * @param string  $blocking_delete_error_message a customized error message on blocking deletes instead of the
58
-     *                                               default
59
-     */
60
-    public function __construct($block_deletes, $blocking_delete_error_message)
61
-    {
62
-        $this->_blocking_delete               = $block_deletes;
63
-        $this->_blocking_delete_error_message = $blocking_delete_error_message;
64
-    }
65
-
66
-
67
-    /**
68
-     * @param $this_model_name
69
-     * @param $other_model_name
70
-     * @throws EE_Error
71
-     */
72
-    public function _construct_finalize_set_models($this_model_name, $other_model_name)
73
-    {
74
-        $this->_this_model_name  = $this_model_name;
75
-        $this->_other_model_name = $other_model_name;
76
-        if (is_string($this->_blocking_delete)) {
77
-            throw new EE_Error(sprintf(
78
-                __(
79
-                    "When instantiating the relation of type %s from %s to %s, the \$block_deletes argument should be a boolean, not a string (%s)",
80
-                    "event_espresso"
81
-                ),
82
-                get_class($this),
83
-                $this_model_name,
84
-                $other_model_name,
85
-                $this->_blocking_delete
86
-            ));
87
-        }
88
-    }
89
-
90
-
91
-    /**
92
-     * Gets the model where this relation is defined.
93
-     *
94
-     * @return EEM_Base
95
-     */
96
-    public function get_this_model()
97
-    {
98
-        return $this->_get_model($this->_this_model_name);
99
-    }
100
-
101
-
102
-    /**
103
-     * Gets the model which this relation establishes the relation TO (ie,
104
-     * this relation object was defined on get_this_model(), get_other_model() is the other one)
105
-     *
106
-     * @return EEM_Base
107
-     */
108
-    public function get_other_model()
109
-    {
110
-        return $this->_get_model($this->_other_model_name);
111
-    }
112
-
113
-
114
-    /**
115
-     * Internally used by get_this_model() and get_other_model()
116
-     *
117
-     * @param string $model_name like Event, Question_Group, etc. omit the EEM_
118
-     * @return EEM_Base
119
-     */
120
-    protected function _get_model($model_name)
121
-    {
122
-        $modelInstance = EE_Registry::instance()->load_model($model_name);
123
-        $modelInstance->set_timezone($this->_timezone);
124
-        return $modelInstance;
125
-    }
126
-
127
-
128
-    /**
129
-     * entirely possible that relations may be called from a model and we need to make sure those relations have their
130
-     * timezone set correctly.
131
-     *
132
-     * @param string $timezone timezone to set.
133
-     */
134
-    public function set_timezone($timezone)
135
-    {
136
-        if ($timezone !== null) {
137
-            $this->_timezone = $timezone;
138
-        }
139
-    }
140
-
141
-
142
-    /**
143
-     * @param        $other_table
144
-     * @param        $other_table_alias
145
-     * @param        $other_table_column
146
-     * @param        $this_table_alias
147
-     * @param        $this_table_join_column
148
-     * @param string $extra_join_sql
149
-     * @return string
150
-     */
151
-    protected function _left_join(
152
-        $other_table,
153
-        $other_table_alias,
154
-        $other_table_column,
155
-        $this_table_alias,
156
-        $this_table_join_column,
157
-        $extra_join_sql = ''
158
-    ) {
159
-        return " LEFT JOIN " . $other_table . " AS " . $other_table_alias . " ON " . $other_table_alias . "." . $other_table_column . "=" . $this_table_alias . "." . $this_table_join_column . ($extra_join_sql ? " AND $extra_join_sql" : '');
160
-    }
161
-
162
-
163
-    /**
164
-     * Gets all the model objects of type of other model related to $model_object,
165
-     * according to this relation. This is the same code for EE_HABTM_Relation and EE_Has_Many_Relation.
166
-     * For both of those child classes, $model_object must be saved so that it has an ID before querying,
167
-     * otherwise an error will be thrown. Note: by default we disable default_where_conditions
168
-     * EE_Belongs_To_Relation doesn't need to be saved before querying.
169
-     *
170
-     * @param EE_Base_Class|int $model_object_or_id                      or the primary key of this model
171
-     * @param array             $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
172
-     * @param boolean           $values_already_prepared_by_model_object @deprecated since 4.8.1
173
-     * @return EE_Base_Class[]
174
-     * @throws \EE_Error
175
-     */
176
-    public function get_all_related(
177
-        $model_object_or_id,
178
-        $query_params = array(),
179
-        $values_already_prepared_by_model_object = false
180
-    ) {
181
-        if ($values_already_prepared_by_model_object !== false) {
182
-            EE_Error::doing_it_wrong(
183
-                'EE_Model_Relation_Base::get_all_related',
184
-                __('The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso'),
185
-                '4.8.1'
186
-            );
187
-        }
188
-        $query_params                                      = $this->_disable_default_where_conditions_on_query_param($query_params);
189
-        $query_param_where_this_model_pk                   = $this->get_this_model()->get_this_model_name()
190
-                                                             . "."
191
-                                                             . $this->get_this_model()->get_primary_key_field()->get_name();
192
-        $model_object_id                                   = $this->_get_model_object_id($model_object_or_id);
193
-        $query_params[0][ $query_param_where_this_model_pk ] = $model_object_id;
194
-        return $this->get_other_model()->get_all($query_params);
195
-    }
196
-
197
-
198
-    /**
199
-     * Alters the $query_params to disable default where conditions, unless otherwise specified
200
-     *
201
-     * @param string $query_params
202
-     * @return array
203
-     */
204
-    protected function _disable_default_where_conditions_on_query_param($query_params)
205
-    {
206
-        if (! isset($query_params['default_where_conditions'])) {
207
-            $query_params['default_where_conditions'] = 'none';
208
-        }
209
-        return $query_params;
210
-    }
211
-
212
-
213
-    /**
214
-     * Deletes the related model objects which meet the query parameters. If no
215
-     * parameters are specified, then all related model objects will be deleted.
216
-     * Note: If the related model is extends EEM_Soft_Delete_Base, then the related
217
-     * model objects will only be soft-deleted.
218
-     *
219
-     * @param EE_Base_Class|int|string $model_object_or_id
220
-     * @param array                    $query_params
221
-     * @return int of how many related models got deleted
222
-     * @throws \EE_Error
223
-     */
224
-    public function delete_all_related($model_object_or_id, $query_params = array())
225
-    {
226
-        // for each thing we would delete,
227
-        $related_model_objects = $this->get_all_related($model_object_or_id, $query_params);
228
-        // determine if it's blocked by anything else before it can be deleted
229
-        $deleted_count = 0;
230
-        foreach ($related_model_objects as $related_model_object) {
231
-            $delete_is_blocked = $this->get_other_model()->delete_is_blocked_by_related_models(
232
-                $related_model_object,
233
-                $model_object_or_id
234
-            );
235
-            /* @var $model_object_or_id EE_Base_Class */
236
-            if (! $delete_is_blocked) {
237
-                $this->remove_relation_to($model_object_or_id, $related_model_object);
238
-                $related_model_object->delete();
239
-                $deleted_count++;
240
-            }
241
-        }
242
-        return $deleted_count;
243
-    }
244
-
245
-
246
-    /**
247
-     * Deletes the related model objects which meet the query parameters. If no
248
-     * parameters are specified, then all related model objects will be deleted.
249
-     * Note: If the related model is extends EEM_Soft_Delete_Base, then the related
250
-     * model objects will only be soft-deleted.
251
-     *
252
-     * @param EE_Base_Class|int|string $model_object_or_id
253
-     * @param array                    $query_params
254
-     * @return int of how many related models got deleted
255
-     * @throws \EE_Error
256
-     */
257
-    public function delete_related_permanently($model_object_or_id, $query_params = array())
258
-    {
259
-        // for each thing we would delete,
260
-        $related_model_objects = $this->get_all_related($model_object_or_id, $query_params);
261
-        // determine if it's blocked by anything else before it can be deleted
262
-        $deleted_count = 0;
263
-        foreach ($related_model_objects as $related_model_object) {
264
-            $delete_is_blocked = $this->get_other_model()->delete_is_blocked_by_related_models(
265
-                $related_model_object,
266
-                $model_object_or_id
267
-            );
268
-            /* @var $model_object_or_id EE_Base_Class */
269
-            if ($related_model_object instanceof EE_Soft_Delete_Base_Class) {
270
-                $this->remove_relation_to($model_object_or_id, $related_model_object);
271
-                $deleted_count++;
272
-                if (! $delete_is_blocked) {
273
-                    $related_model_object->delete_permanently();
274
-                } else {
275
-                    // delete is blocked
276
-                    // brent and darren, in this case, wanted to just soft delete it then
277
-                    $related_model_object->delete();
278
-                }
279
-            } else {
280
-                // its not a soft-deletable thing anyways. do the normal logic.
281
-                if (! $delete_is_blocked) {
282
-                    $this->remove_relation_to($model_object_or_id, $related_model_object);
283
-                    $related_model_object->delete();
284
-                    $deleted_count++;
285
-                }
286
-            }
287
-        }
288
-        return $deleted_count;
289
-    }
290
-
291
-
292
-    /**
293
-     * this just returns a model_object_id for incoming item that could be an object or id.
294
-     *
295
-     * @param  EE_Base_Class|int $model_object_or_id model object or the primary key of this model
296
-     * @throws EE_Error
297
-     * @return int
298
-     */
299
-    protected function _get_model_object_id($model_object_or_id)
300
-    {
301
-        $model_object_id = $model_object_or_id;
302
-        if ($model_object_or_id instanceof EE_Base_Class) {
303
-            $model_object_id = $model_object_or_id->ID();
304
-        }
305
-        if (! $model_object_id) {
306
-            throw new EE_Error(sprintf(
307
-                __(
308
-                    "Sorry, we cant get the related %s model objects to %s model object before it has an ID. You can solve that by just saving it before trying to get its related model objects",
309
-                    "event_espresso"
310
-                ),
311
-                $this->get_other_model()->get_this_model_name(),
312
-                $this->get_this_model()->get_this_model_name()
313
-            ));
314
-        }
315
-        return $model_object_id;
316
-    }
317
-
318
-
319
-    /**
320
-     * Gets the SQL string for performing the join between this model and the other model.
321
-     *
322
-     * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
323
-     * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk =
324
-     *                other_model_primary_table.fk" etc
325
-     */
326
-    abstract public function get_join_statement($model_relation_chain);
327
-
328
-
329
-    /**
330
-     * Adds a relationships between the two model objects provided. Each type of relationship handles this differently
331
-     * (EE_Belongs_To is a slight exception, it should more accurately be called set_relation_to(...), as this
332
-     * relationship only allows this model to be related to a single other model of this type)
333
-     *
334
-     * @param       $this_obj_or_id
335
-     * @param       $other_obj_or_id
336
-     * @param array $extra_join_model_fields_n_values
337
-     * @return \EE_Base_Class the EE_Base_Class which was added as a relation. (Convenient if you only pass an ID for
338
-     *                        $other_obj_or_id)
339
-     */
340
-    abstract public function add_relation_to(
341
-        $this_obj_or_id,
342
-        $other_obj_or_id,
343
-        $extra_join_model_fields_n_values = array()
344
-    );
345
-
346
-
347
-    /**
348
-     * Similar to 'add_relation_to(...)', performs the opposite action of removing the relationship between the two
349
-     * model objects
350
-     *
351
-     * @param       $this_obj_or_id
352
-     * @param       $other_obj_or_id
353
-     * @param array $where_query
354
-     * @return bool
355
-     */
356
-    abstract public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array());
357
-
358
-
359
-    /**
360
-     * Removes ALL relation instances for this relation obj
361
-     *
362
-     * @param EE_Base_Class|int $this_obj_or_id
363
-     * @param array             $where_query_param @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions
364
-     * @return EE_Base_Class[]
365
-     * @throws \EE_Error
366
-     */
367
-    public function remove_relations($this_obj_or_id, $where_query_param = array())
368
-    {
369
-        $related_things = $this->get_all_related($this_obj_or_id, array($where_query_param));
370
-        $objs_removed   = array();
371
-        foreach ($related_things as $related_thing) {
372
-            $objs_removed[] = $this->remove_relation_to($this_obj_or_id, $related_thing);
373
-        }
374
-        return $objs_removed;
375
-    }
376
-
377
-
378
-    /**
379
-     * If you aren't allowed to delete this model when there are related models across this
380
-     * relation object, return true. Otherwise, if you can delete this model even though
381
-     * related objects exist, returns false.
382
-     *
383
-     * @return boolean
384
-     */
385
-    public function block_delete_if_related_models_exist()
386
-    {
387
-        return $this->_blocking_delete;
388
-    }
389
-
390
-
391
-    /**
392
-     * Gets the error message to show
393
-     *
394
-     * @return string
395
-     */
396
-    public function get_deletion_error_message()
397
-    {
398
-        if ($this->_blocking_delete_error_message) {
399
-            return $this->_blocking_delete_error_message;
400
-        } else {
18
+	/**
19
+	 * The model name of which this relation is a component (ie, the model that called new EE_Model_Relation_Base)
20
+	 *
21
+	 * @var string eg Event, Question_Group, Registration
22
+	 */
23
+	private $_this_model_name;
24
+	/**
25
+	 * The model name pointed to by this relation (ie, the model we want to establish a relationship to)
26
+	 *
27
+	 * @var string eg Event, Question_Group, Registration
28
+	 */
29
+	private $_other_model_name;
30
+
31
+	/**
32
+	 * this is typically used when calling the relation models to make sure they inherit any set timezone from the
33
+	 * initiating model.
34
+	 *
35
+	 * @var string
36
+	 */
37
+	protected $_timezone;
38
+
39
+	/**
40
+	 * If you try to delete "this_model", and there are related "other_models",
41
+	 * and this isn't null, then abandon the deletion and add this warning.
42
+	 * This effectively makes it impossible to delete "this_model" while there are
43
+	 * related "other_models" along this relation.
44
+	 *
45
+	 * @var string (internationalized)
46
+	 */
47
+	protected $_blocking_delete_error_message;
48
+
49
+	protected $_blocking_delete = false;
50
+
51
+	/**
52
+	 * Object representing the relationship between two models. This knows how to join the models,
53
+	 * get related models across the relation, and add-and-remove the relationships.
54
+	 *
55
+	 * @param boolean $block_deletes                 if there are related models across this relation, block (prevent
56
+	 *                                               and add an error) the deletion of this model
57
+	 * @param string  $blocking_delete_error_message a customized error message on blocking deletes instead of the
58
+	 *                                               default
59
+	 */
60
+	public function __construct($block_deletes, $blocking_delete_error_message)
61
+	{
62
+		$this->_blocking_delete               = $block_deletes;
63
+		$this->_blocking_delete_error_message = $blocking_delete_error_message;
64
+	}
65
+
66
+
67
+	/**
68
+	 * @param $this_model_name
69
+	 * @param $other_model_name
70
+	 * @throws EE_Error
71
+	 */
72
+	public function _construct_finalize_set_models($this_model_name, $other_model_name)
73
+	{
74
+		$this->_this_model_name  = $this_model_name;
75
+		$this->_other_model_name = $other_model_name;
76
+		if (is_string($this->_blocking_delete)) {
77
+			throw new EE_Error(sprintf(
78
+				__(
79
+					"When instantiating the relation of type %s from %s to %s, the \$block_deletes argument should be a boolean, not a string (%s)",
80
+					"event_espresso"
81
+				),
82
+				get_class($this),
83
+				$this_model_name,
84
+				$other_model_name,
85
+				$this->_blocking_delete
86
+			));
87
+		}
88
+	}
89
+
90
+
91
+	/**
92
+	 * Gets the model where this relation is defined.
93
+	 *
94
+	 * @return EEM_Base
95
+	 */
96
+	public function get_this_model()
97
+	{
98
+		return $this->_get_model($this->_this_model_name);
99
+	}
100
+
101
+
102
+	/**
103
+	 * Gets the model which this relation establishes the relation TO (ie,
104
+	 * this relation object was defined on get_this_model(), get_other_model() is the other one)
105
+	 *
106
+	 * @return EEM_Base
107
+	 */
108
+	public function get_other_model()
109
+	{
110
+		return $this->_get_model($this->_other_model_name);
111
+	}
112
+
113
+
114
+	/**
115
+	 * Internally used by get_this_model() and get_other_model()
116
+	 *
117
+	 * @param string $model_name like Event, Question_Group, etc. omit the EEM_
118
+	 * @return EEM_Base
119
+	 */
120
+	protected function _get_model($model_name)
121
+	{
122
+		$modelInstance = EE_Registry::instance()->load_model($model_name);
123
+		$modelInstance->set_timezone($this->_timezone);
124
+		return $modelInstance;
125
+	}
126
+
127
+
128
+	/**
129
+	 * entirely possible that relations may be called from a model and we need to make sure those relations have their
130
+	 * timezone set correctly.
131
+	 *
132
+	 * @param string $timezone timezone to set.
133
+	 */
134
+	public function set_timezone($timezone)
135
+	{
136
+		if ($timezone !== null) {
137
+			$this->_timezone = $timezone;
138
+		}
139
+	}
140
+
141
+
142
+	/**
143
+	 * @param        $other_table
144
+	 * @param        $other_table_alias
145
+	 * @param        $other_table_column
146
+	 * @param        $this_table_alias
147
+	 * @param        $this_table_join_column
148
+	 * @param string $extra_join_sql
149
+	 * @return string
150
+	 */
151
+	protected function _left_join(
152
+		$other_table,
153
+		$other_table_alias,
154
+		$other_table_column,
155
+		$this_table_alias,
156
+		$this_table_join_column,
157
+		$extra_join_sql = ''
158
+	) {
159
+		return " LEFT JOIN " . $other_table . " AS " . $other_table_alias . " ON " . $other_table_alias . "." . $other_table_column . "=" . $this_table_alias . "." . $this_table_join_column . ($extra_join_sql ? " AND $extra_join_sql" : '');
160
+	}
161
+
162
+
163
+	/**
164
+	 * Gets all the model objects of type of other model related to $model_object,
165
+	 * according to this relation. This is the same code for EE_HABTM_Relation and EE_Has_Many_Relation.
166
+	 * For both of those child classes, $model_object must be saved so that it has an ID before querying,
167
+	 * otherwise an error will be thrown. Note: by default we disable default_where_conditions
168
+	 * EE_Belongs_To_Relation doesn't need to be saved before querying.
169
+	 *
170
+	 * @param EE_Base_Class|int $model_object_or_id                      or the primary key of this model
171
+	 * @param array             $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
172
+	 * @param boolean           $values_already_prepared_by_model_object @deprecated since 4.8.1
173
+	 * @return EE_Base_Class[]
174
+	 * @throws \EE_Error
175
+	 */
176
+	public function get_all_related(
177
+		$model_object_or_id,
178
+		$query_params = array(),
179
+		$values_already_prepared_by_model_object = false
180
+	) {
181
+		if ($values_already_prepared_by_model_object !== false) {
182
+			EE_Error::doing_it_wrong(
183
+				'EE_Model_Relation_Base::get_all_related',
184
+				__('The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso'),
185
+				'4.8.1'
186
+			);
187
+		}
188
+		$query_params                                      = $this->_disable_default_where_conditions_on_query_param($query_params);
189
+		$query_param_where_this_model_pk                   = $this->get_this_model()->get_this_model_name()
190
+															 . "."
191
+															 . $this->get_this_model()->get_primary_key_field()->get_name();
192
+		$model_object_id                                   = $this->_get_model_object_id($model_object_or_id);
193
+		$query_params[0][ $query_param_where_this_model_pk ] = $model_object_id;
194
+		return $this->get_other_model()->get_all($query_params);
195
+	}
196
+
197
+
198
+	/**
199
+	 * Alters the $query_params to disable default where conditions, unless otherwise specified
200
+	 *
201
+	 * @param string $query_params
202
+	 * @return array
203
+	 */
204
+	protected function _disable_default_where_conditions_on_query_param($query_params)
205
+	{
206
+		if (! isset($query_params['default_where_conditions'])) {
207
+			$query_params['default_where_conditions'] = 'none';
208
+		}
209
+		return $query_params;
210
+	}
211
+
212
+
213
+	/**
214
+	 * Deletes the related model objects which meet the query parameters. If no
215
+	 * parameters are specified, then all related model objects will be deleted.
216
+	 * Note: If the related model is extends EEM_Soft_Delete_Base, then the related
217
+	 * model objects will only be soft-deleted.
218
+	 *
219
+	 * @param EE_Base_Class|int|string $model_object_or_id
220
+	 * @param array                    $query_params
221
+	 * @return int of how many related models got deleted
222
+	 * @throws \EE_Error
223
+	 */
224
+	public function delete_all_related($model_object_or_id, $query_params = array())
225
+	{
226
+		// for each thing we would delete,
227
+		$related_model_objects = $this->get_all_related($model_object_or_id, $query_params);
228
+		// determine if it's blocked by anything else before it can be deleted
229
+		$deleted_count = 0;
230
+		foreach ($related_model_objects as $related_model_object) {
231
+			$delete_is_blocked = $this->get_other_model()->delete_is_blocked_by_related_models(
232
+				$related_model_object,
233
+				$model_object_or_id
234
+			);
235
+			/* @var $model_object_or_id EE_Base_Class */
236
+			if (! $delete_is_blocked) {
237
+				$this->remove_relation_to($model_object_or_id, $related_model_object);
238
+				$related_model_object->delete();
239
+				$deleted_count++;
240
+			}
241
+		}
242
+		return $deleted_count;
243
+	}
244
+
245
+
246
+	/**
247
+	 * Deletes the related model objects which meet the query parameters. If no
248
+	 * parameters are specified, then all related model objects will be deleted.
249
+	 * Note: If the related model is extends EEM_Soft_Delete_Base, then the related
250
+	 * model objects will only be soft-deleted.
251
+	 *
252
+	 * @param EE_Base_Class|int|string $model_object_or_id
253
+	 * @param array                    $query_params
254
+	 * @return int of how many related models got deleted
255
+	 * @throws \EE_Error
256
+	 */
257
+	public function delete_related_permanently($model_object_or_id, $query_params = array())
258
+	{
259
+		// for each thing we would delete,
260
+		$related_model_objects = $this->get_all_related($model_object_or_id, $query_params);
261
+		// determine if it's blocked by anything else before it can be deleted
262
+		$deleted_count = 0;
263
+		foreach ($related_model_objects as $related_model_object) {
264
+			$delete_is_blocked = $this->get_other_model()->delete_is_blocked_by_related_models(
265
+				$related_model_object,
266
+				$model_object_or_id
267
+			);
268
+			/* @var $model_object_or_id EE_Base_Class */
269
+			if ($related_model_object instanceof EE_Soft_Delete_Base_Class) {
270
+				$this->remove_relation_to($model_object_or_id, $related_model_object);
271
+				$deleted_count++;
272
+				if (! $delete_is_blocked) {
273
+					$related_model_object->delete_permanently();
274
+				} else {
275
+					// delete is blocked
276
+					// brent and darren, in this case, wanted to just soft delete it then
277
+					$related_model_object->delete();
278
+				}
279
+			} else {
280
+				// its not a soft-deletable thing anyways. do the normal logic.
281
+				if (! $delete_is_blocked) {
282
+					$this->remove_relation_to($model_object_or_id, $related_model_object);
283
+					$related_model_object->delete();
284
+					$deleted_count++;
285
+				}
286
+			}
287
+		}
288
+		return $deleted_count;
289
+	}
290
+
291
+
292
+	/**
293
+	 * this just returns a model_object_id for incoming item that could be an object or id.
294
+	 *
295
+	 * @param  EE_Base_Class|int $model_object_or_id model object or the primary key of this model
296
+	 * @throws EE_Error
297
+	 * @return int
298
+	 */
299
+	protected function _get_model_object_id($model_object_or_id)
300
+	{
301
+		$model_object_id = $model_object_or_id;
302
+		if ($model_object_or_id instanceof EE_Base_Class) {
303
+			$model_object_id = $model_object_or_id->ID();
304
+		}
305
+		if (! $model_object_id) {
306
+			throw new EE_Error(sprintf(
307
+				__(
308
+					"Sorry, we cant get the related %s model objects to %s model object before it has an ID. You can solve that by just saving it before trying to get its related model objects",
309
+					"event_espresso"
310
+				),
311
+				$this->get_other_model()->get_this_model_name(),
312
+				$this->get_this_model()->get_this_model_name()
313
+			));
314
+		}
315
+		return $model_object_id;
316
+	}
317
+
318
+
319
+	/**
320
+	 * Gets the SQL string for performing the join between this model and the other model.
321
+	 *
322
+	 * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
323
+	 * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk =
324
+	 *                other_model_primary_table.fk" etc
325
+	 */
326
+	abstract public function get_join_statement($model_relation_chain);
327
+
328
+
329
+	/**
330
+	 * Adds a relationships between the two model objects provided. Each type of relationship handles this differently
331
+	 * (EE_Belongs_To is a slight exception, it should more accurately be called set_relation_to(...), as this
332
+	 * relationship only allows this model to be related to a single other model of this type)
333
+	 *
334
+	 * @param       $this_obj_or_id
335
+	 * @param       $other_obj_or_id
336
+	 * @param array $extra_join_model_fields_n_values
337
+	 * @return \EE_Base_Class the EE_Base_Class which was added as a relation. (Convenient if you only pass an ID for
338
+	 *                        $other_obj_or_id)
339
+	 */
340
+	abstract public function add_relation_to(
341
+		$this_obj_or_id,
342
+		$other_obj_or_id,
343
+		$extra_join_model_fields_n_values = array()
344
+	);
345
+
346
+
347
+	/**
348
+	 * Similar to 'add_relation_to(...)', performs the opposite action of removing the relationship between the two
349
+	 * model objects
350
+	 *
351
+	 * @param       $this_obj_or_id
352
+	 * @param       $other_obj_or_id
353
+	 * @param array $where_query
354
+	 * @return bool
355
+	 */
356
+	abstract public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array());
357
+
358
+
359
+	/**
360
+	 * Removes ALL relation instances for this relation obj
361
+	 *
362
+	 * @param EE_Base_Class|int $this_obj_or_id
363
+	 * @param array             $where_query_param @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions
364
+	 * @return EE_Base_Class[]
365
+	 * @throws \EE_Error
366
+	 */
367
+	public function remove_relations($this_obj_or_id, $where_query_param = array())
368
+	{
369
+		$related_things = $this->get_all_related($this_obj_or_id, array($where_query_param));
370
+		$objs_removed   = array();
371
+		foreach ($related_things as $related_thing) {
372
+			$objs_removed[] = $this->remove_relation_to($this_obj_or_id, $related_thing);
373
+		}
374
+		return $objs_removed;
375
+	}
376
+
377
+
378
+	/**
379
+	 * If you aren't allowed to delete this model when there are related models across this
380
+	 * relation object, return true. Otherwise, if you can delete this model even though
381
+	 * related objects exist, returns false.
382
+	 *
383
+	 * @return boolean
384
+	 */
385
+	public function block_delete_if_related_models_exist()
386
+	{
387
+		return $this->_blocking_delete;
388
+	}
389
+
390
+
391
+	/**
392
+	 * Gets the error message to show
393
+	 *
394
+	 * @return string
395
+	 */
396
+	public function get_deletion_error_message()
397
+	{
398
+		if ($this->_blocking_delete_error_message) {
399
+			return $this->_blocking_delete_error_message;
400
+		} else {
401 401
 //          return sprintf(__('Cannot delete %1$s when there are related %2$s', "event_espresso"),$this->get_this_model()->item_name(2),$this->get_other_model()->item_name(2));
402
-            return sprintf(
403
-                __(
404
-                    'This %1$s is currently linked to one or more %2$s records. If this %1$s is incorrect, then please remove it from all %3$s before attempting to delete it.',
405
-                    "event_espresso"
406
-                ),
407
-                $this->get_this_model()->item_name(1),
408
-                $this->get_other_model()->item_name(1),
409
-                $this->get_other_model()->item_name(2)
410
-            );
411
-        }
412
-    }
413
-
414
-    /**
415
-     * Returns whatever is set as the nicename for the object.
416
-     *
417
-     * @return string
418
-     */
419
-    public function getSchemaDescription()
420
-    {
421
-        $description = $this instanceof EE_Belongs_To_Relation
422
-            ? esc_html__('The related %1$s entity to the %2$s.', 'event_espresso')
423
-            : esc_html__('The related %1$s entities to the %2$s.', 'event_espresso');
424
-        return sprintf(
425
-            $description,
426
-            $this->get_other_model()->get_this_model_name(),
427
-            $this->get_this_model()->get_this_model_name()
428
-        );
429
-    }
430
-
431
-    /**
432
-     * Returns whatever is set as the $_schema_type property for the object.
433
-     * Note: this will automatically add 'null' to the schema if the object is_nullable()
434
-     *
435
-     * @return string|array
436
-     */
437
-    public function getSchemaType()
438
-    {
439
-        return $this instanceof EE_Belongs_To_Relation ? 'object' : 'array';
440
-    }
441
-
442
-    /**
443
-     * This is usually present when the $_schema_type property is 'object'.  Any child classes will need to override
444
-     * this method and return the properties for the schema.
445
-     * The reason this is not a property on the class is because there may be filters set on the values for the property
446
-     * that won't be exposed on construct.  For example enum type schemas may have the enum values filtered.
447
-     *
448
-     * @return array
449
-     */
450
-    public function getSchemaProperties()
451
-    {
452
-        return array();
453
-    }
454
-
455
-    /**
456
-     * If a child class has enum values, they should override this method and provide a simple array
457
-     * of the enum values.
458
-     * The reason this is not a property on the class is because there may be filterable enum values that
459
-     * are set on the instantiated object that could be filtered after construct.
460
-     *
461
-     * @return array
462
-     */
463
-    public function getSchemaEnum()
464
-    {
465
-        return array();
466
-    }
467
-
468
-    /**
469
-     * This returns the value of the $_schema_format property on the object.
470
-     *
471
-     * @return string
472
-     */
473
-    public function getSchemaFormat()
474
-    {
475
-        return array();
476
-    }
477
-
478
-    /**
479
-     * This returns the value of the $_schema_readonly property on the object.
480
-     *
481
-     * @return bool
482
-     */
483
-    public function getSchemaReadonly()
484
-    {
485
-        return true;
486
-    }
487
-
488
-    /**
489
-     * This returns elements used to represent this field in the json schema.
490
-     *
491
-     * @link http://json-schema.org/
492
-     * @return array
493
-     */
494
-    public function getSchema()
495
-    {
496
-        $schema = array(
497
-            'description' => $this->getSchemaDescription(),
498
-            'type' => $this->getSchemaType(),
499
-            'relation' => true,
500
-            'relation_type' => get_class($this),
501
-            'readonly' => $this->getSchemaReadonly()
502
-        );
503
-
504
-        if ($this instanceof EE_HABTM_Relation) {
505
-            $schema['joining_model_name'] = $this->get_join_model()->get_this_model_name();
506
-        }
507
-
508
-        if ($this->getSchemaType() === 'array') {
509
-            $schema['items'] = array(
510
-                'type' => 'object'
511
-            );
512
-        }
513
-
514
-        return $schema;
515
-    }
402
+			return sprintf(
403
+				__(
404
+					'This %1$s is currently linked to one or more %2$s records. If this %1$s is incorrect, then please remove it from all %3$s before attempting to delete it.',
405
+					"event_espresso"
406
+				),
407
+				$this->get_this_model()->item_name(1),
408
+				$this->get_other_model()->item_name(1),
409
+				$this->get_other_model()->item_name(2)
410
+			);
411
+		}
412
+	}
413
+
414
+	/**
415
+	 * Returns whatever is set as the nicename for the object.
416
+	 *
417
+	 * @return string
418
+	 */
419
+	public function getSchemaDescription()
420
+	{
421
+		$description = $this instanceof EE_Belongs_To_Relation
422
+			? esc_html__('The related %1$s entity to the %2$s.', 'event_espresso')
423
+			: esc_html__('The related %1$s entities to the %2$s.', 'event_espresso');
424
+		return sprintf(
425
+			$description,
426
+			$this->get_other_model()->get_this_model_name(),
427
+			$this->get_this_model()->get_this_model_name()
428
+		);
429
+	}
430
+
431
+	/**
432
+	 * Returns whatever is set as the $_schema_type property for the object.
433
+	 * Note: this will automatically add 'null' to the schema if the object is_nullable()
434
+	 *
435
+	 * @return string|array
436
+	 */
437
+	public function getSchemaType()
438
+	{
439
+		return $this instanceof EE_Belongs_To_Relation ? 'object' : 'array';
440
+	}
441
+
442
+	/**
443
+	 * This is usually present when the $_schema_type property is 'object'.  Any child classes will need to override
444
+	 * this method and return the properties for the schema.
445
+	 * The reason this is not a property on the class is because there may be filters set on the values for the property
446
+	 * that won't be exposed on construct.  For example enum type schemas may have the enum values filtered.
447
+	 *
448
+	 * @return array
449
+	 */
450
+	public function getSchemaProperties()
451
+	{
452
+		return array();
453
+	}
454
+
455
+	/**
456
+	 * If a child class has enum values, they should override this method and provide a simple array
457
+	 * of the enum values.
458
+	 * The reason this is not a property on the class is because there may be filterable enum values that
459
+	 * are set on the instantiated object that could be filtered after construct.
460
+	 *
461
+	 * @return array
462
+	 */
463
+	public function getSchemaEnum()
464
+	{
465
+		return array();
466
+	}
467
+
468
+	/**
469
+	 * This returns the value of the $_schema_format property on the object.
470
+	 *
471
+	 * @return string
472
+	 */
473
+	public function getSchemaFormat()
474
+	{
475
+		return array();
476
+	}
477
+
478
+	/**
479
+	 * This returns the value of the $_schema_readonly property on the object.
480
+	 *
481
+	 * @return bool
482
+	 */
483
+	public function getSchemaReadonly()
484
+	{
485
+		return true;
486
+	}
487
+
488
+	/**
489
+	 * This returns elements used to represent this field in the json schema.
490
+	 *
491
+	 * @link http://json-schema.org/
492
+	 * @return array
493
+	 */
494
+	public function getSchema()
495
+	{
496
+		$schema = array(
497
+			'description' => $this->getSchemaDescription(),
498
+			'type' => $this->getSchemaType(),
499
+			'relation' => true,
500
+			'relation_type' => get_class($this),
501
+			'readonly' => $this->getSchemaReadonly()
502
+		);
503
+
504
+		if ($this instanceof EE_HABTM_Relation) {
505
+			$schema['joining_model_name'] = $this->get_join_model()->get_this_model_name();
506
+		}
507
+
508
+		if ($this->getSchemaType() === 'array') {
509
+			$schema['items'] = array(
510
+				'type' => 'object'
511
+			);
512
+		}
513
+
514
+		return $schema;
515
+	}
516 516
 }
Please login to merge, or discard this patch.
core/db_models/relations/EE_Has_Many_Revision_Relation.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
         // k this is where things differ because NOW what we're going to do is get the PARENTS for the get all related (and we'll also start setting up the return_objs array containing related that DON'T have parent ids, for those that DON'T have parents to merge with our returned objects);
191 191
         foreach ($autosave_relations as $a_r) {
192 192
             $pid = $a_r->parent();
193
-            if (! empty($pid)) {
193
+            if ( ! empty($pid)) {
194 194
                 $parent_ids[] = $pid;
195 195
             } else {
196 196
                 $return_objs[] = $a_r;
@@ -206,9 +206,9 @@  discard block
 block discarded – undo
206 206
         }
207 207
 
208 208
         // now we setup the query to get all the parents
209
-        if (! empty($parent_ids)) {
210
-            $query_param_where_this_model_pk                  = $this->get_this_model()->get_this_model_name() . "." . $this->get_this_model()->get_primary_key_field()->get_name();
211
-            $query_param[0][ $query_param_where_this_model_pk ] = array('IN', $parent_ids);
209
+        if ( ! empty($parent_ids)) {
210
+            $query_param_where_this_model_pk                  = $this->get_this_model()->get_this_model_name().".".$this->get_this_model()->get_primary_key_field()->get_name();
211
+            $query_param[0][$query_param_where_this_model_pk] = array('IN', $parent_ids);
212 212
             $parents                                          = $this->get_other_model()->get_all($query_params);
213 213
         }
214 214
 
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
             var_dump($this_obj);
244 244
             var_dump($other_obj);/**/
245 245
 
246
-            if (! empty($parent_evt_id) && $parent_evt_id == $other_obj->get($this->_primary_cpt_field)) {
246
+            if ( ! empty($parent_evt_id) && $parent_evt_id == $other_obj->get($this->_primary_cpt_field)) {
247 247
                 // let's do query on this objects model to see if the incoming pk value on the obj matches any parents in this objects table.
248 248
                 $has_parent_obj = $this->get_other_model()->get_one(array(
249 249
                     array(
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
                     $other_obj->set($pk_on_related_model, $has_parent_obj->ID());
260 260
                     $other_obj->set($this->_primary_cpt_field, $this_obj->ID());
261 261
 
262
-                    if (! $remove_relation) {
262
+                    if ( ! $remove_relation) {
263 263
                         $other_obj->save();
264 264
                         return array($other_obj);
265 265
                     } elseif ($remove_relation && ! $this->_blocking_delete) {
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
             // the last possible condition on a revision is that the incoming other_model object has a fk that == $this_obj pk which means we just return the $other obj and let it save as normal so we see the return at the bottom of this method.
288 288
         } else {
289 289
             // we only need to do the below IF this is not a remove relation
290
-            if (! $remove_relation) {
290
+            if ( ! $remove_relation) {
291 291
                 // okay this is is a normal update/save/remove so, let's make sure the other object is not a revision of the current object.
292 292
                 // the other object will likely NOT have the correct fk on it (which is the primary_cpt_field_mame) so we must retrieve from the db to get that first.
293 293
                 $existing_other_obj    = $this->get_other_model()->get_one_by_ID($other_obj->ID());
Please login to merge, or discard this patch.
Indentation   +296 added lines, -296 removed lines patch added patch discarded remove patch
@@ -12,303 +12,303 @@
 block discarded – undo
12 12
 {
13 13
 
14 14
 
15
-    /**
16
-     * The Foreign key on the model that acts as the PRIMARY KEY used in special autosave handling where we query for
17
-     * autosaves (or the Foreign key on other models in relations pointing to this models primary key which is this
18
-     * value).  The _primary_cpt_field is what is equivalent to the post_id field on a cpt join.
19
-     *
20
-     * @var string
21
-     */
22
-    private $_primary_cpt_field;
23
-
24
-
25
-    /**
26
-     * This is what field serves as the "parent" column that is linked with whatever the main model's calling this
27
-     * relation has as a primary key.  In other words EEM_Event has 'Datetime' => new
28
-     * EE_Has_Many_Revision_Relation('EVT_ID', 'DTT_parent').  That means that in the EEM_Datetime model the
29
-     * 'DTT_Parent' field is related to the 'DTT_ID' primary key field (in the same model) because 'DTT_ID' is the
30
-     * primary key in the other model (EEM_Datetime).
31
-     *
32
-     * @var string
33
-     */
34
-    private $_parent_pk_relation_field;
35
-
36
-
37
-    /**
38
-     * Object representing the relationship between two models. Has_Many_Relations are where the OTHER model has the
39
-     * foreign key this model. IE, there can be many other model objects related to one of this model's objects (but
40
-     * NOT through a JOIN table, which is the case for EE_HABTM_Relations). This knows how to join the models, get
41
-     * related models across the relation, and add-and-remove the relationships.
42
-     *
43
-     * @param string  $primary_cpt_field             See property description for details
44
-     * @param string  $parent_pk_relation_field      This is the field that is "connected" to the $primary_cpt_field.
45
-     *                                               See property desc for details.
46
-     * @param boolean $block_deletes                 For this type of relation, we block by default. If there are
47
-     *                                               related models across this relation, block (prevent and add an
48
-     *                                               error) the deletion of this model
49
-     * @param string  $blocking_delete_error_message a customized error message on blocking deletes instead of the
50
-     *                                               default
51
-     */
52
-    public function __construct(
53
-        $primary_cpt_field,
54
-        $parent_pk_relation_field,
55
-        $block_deletes = true,
56
-        $blocking_delete_error_message = null
57
-    ) {
58
-        $this->_primary_cpt_field        = $primary_cpt_field;
59
-        $this->_parent_pk_relation_field = $parent_pk_relation_field;
60
-        parent::__construct($block_deletes, $blocking_delete_error_message);
61
-    }
62
-
63
-
64
-    /**
65
-     * Sets the other model object's foreign key to this model object's primary key. Feel free to do this manually if
66
-     * you like.
67
-     *
68
-     * @param EE_Base_Class|int $this_obj_or_id
69
-     * @param EE_Base_Class|int $other_obj_or_id
70
-     * @param array             $extra_join_model_fields_n_values
71
-     * @return \EE_Base_Class
72
-     * @throws \EE_Error
73
-     */
74
-    public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
75
-    {
76
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
77
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id);
78
-
79
-        // handle possible revisions
80
-        $other_model_obj = $this->_check_for_revision($this_model_obj, $other_model_obj);
81
-
82
-        // if is array, then we've already done the add_relation so let's get out
83
-        if (is_array($other_model_obj)) {
84
-            return $other_model_obj[0];
85
-        }
86
-        // find the field on the other model which is a foreign key to this model
87
-        $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
88
-        // set that field on the other model to this model's ID
89
-        $other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID());
90
-        $other_model_obj->save();
91
-        return $other_model_obj;
92
-    }
93
-
94
-
95
-    /**
96
-     * Sets the other model object's foreign key to its default, instead of pointing to this model object
97
-     *
98
-     * @param EE_Base_Class|int $this_obj_or_id
99
-     * @param EE_Base_Class|int $other_obj_or_id
100
-     * @param array             $where_query
101
-     * @return \EE_Base_Class
102
-     * @throws \EE_Error
103
-     */
104
-    public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
105
-    {
106
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id);
107
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id);
108
-        // handle possible revisions
109
-        $other_model_obj = $this->_check_for_revision($this_model_obj, $other_model_obj, true);
110
-
111
-
112
-        // if is array, then we've already done the add_relation so let's get out
113
-        if (is_array($other_model_obj)) {
114
-            return $other_model_obj[0];
115
-        }
116
-
117
-        // find the field on the other model which is a foreign key to this model
118
-        $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
119
-
120
-
121
-        // set that field on the other model to this model's ID
122
-        if ($this->_blocking_delete) {
123
-            $other_model_obj->set($fk_field_on_other_model->get_name(), null, true);
124
-            $other_model_obj->save();
125
-        } else {
126
-            $other_model_obj->delete();
127
-            $other_model_obj->set($fk_field_on_other_model->get_name(), null, true);
128
-            return $other_model_obj;
129
-        }
130
-        return $other_model_obj;
131
-    }
132
-
133
-
134
-    /**
135
-     * This is identical to EE_Model_Relation->get_all_related() except we're going handle special autosave conditions
136
-     * in here.
137
-     *
138
-     * @param  EE_Base_Class|int $model_object_or_id
139
-     * @param  array             $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
140
-     * @param  boolean           $values_already_prepared_by_model_object @deprecated since 4.8.1
141
-     * @return EE_Base_Class[]
142
-     * @throws \EE_Error
143
-     */
144
-    public function get_all_related(
145
-        $model_object_or_id,
146
-        $query_params = array(),
147
-        $values_already_prepared_by_model_object = false
148
-    ) {
149
-        if ($values_already_prepared_by_model_object !== false) {
150
-            EE_Error::doing_it_wrong(
151
-                'EE_Model_Relation_Base::get_all_related',
152
-                __('The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso'),
153
-                '4.8.1'
154
-            );
155
-        }
156
-
157
-        // if this is an autosave then we're going to get things differently
158
-        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
159
-            return $this->_do_autosave_get_all($model_object_or_id, $query_params);
160
-        }
161
-
162
-        return parent::get_all_related($model_object_or_id, $query_params);
163
-    }
164
-
165
-
166
-    /**
167
-     * If we're in the midst of an autosave then we're going to do things a bit differently than the usual
168
-     * get_all_related (commenting within).  For description of params see the get_all_related() comments
169
-     *
170
-     * @access protected
171
-     * @param      $model_object_or_id
172
-     * @param      $query_params
173
-     * @param bool $deprecated
174
-     * @return \EE_Base_Class[]
175
-     * @throws \EE_Error
176
-     */
177
-    protected function _do_autosave_get_all($model_object_or_id, $query_params, $deprecated = false)
178
-    {
179
-
180
-        // first we check if the post_id for the incoming query is for an autosave.  If it isn't that's what we want!
181
-        $model_object_id = $this->_get_model_object_id($model_object_or_id);
182
-
183
-        $autosave  = wp_get_post_autosave($model_object_id);
184
-        $id_to_use = $autosave ? $autosave->ID : $model_object_id;
185
-
186
-        $autosave_relations = parent::get_all_related($id_to_use, $query_params);
187
-        $parent_ids         = $parents = array();
188
-        $return_objs        = array();
189
-
190
-        // k this is where things differ because NOW what we're going to do is get the PARENTS for the get all related (and we'll also start setting up the return_objs array containing related that DON'T have parent ids, for those that DON'T have parents to merge with our returned objects);
191
-        foreach ($autosave_relations as $a_r) {
192
-            $pid = $a_r->parent();
193
-            if (! empty($pid)) {
194
-                $parent_ids[] = $pid;
195
-            } else {
196
-                $return_objs[] = $a_r;
197
-            }
198
-        }
199
-
200
-        // we have to make sure we also include the ORIGINAL values
201
-        $originals = parent::get_all_related($model_object_or_id, $query_params);
202
-
203
-        // merge $originals with $return_objs
204
-        if ($originals) {
205
-            $return_objs = array_merge($originals, $return_objs);
206
-        }
207
-
208
-        // now we setup the query to get all the parents
209
-        if (! empty($parent_ids)) {
210
-            $query_param_where_this_model_pk                  = $this->get_this_model()->get_this_model_name() . "." . $this->get_this_model()->get_primary_key_field()->get_name();
211
-            $query_param[0][ $query_param_where_this_model_pk ] = array('IN', $parent_ids);
212
-            $parents                                          = $this->get_other_model()->get_all($query_params);
213
-        }
214
-
215
-        // var_dump($parents);
216
-
217
-
218
-        // now merge parents with our current $return_objs and send back
219
-        return array_merge($parents, $return_objs);
220
-    }
221
-
222
-
223
-    /**
224
-     * Basically this method gets called to verify if the incoming object needs to be manipulated somewhat because it
225
-     * is a revision save.  If so, then we change things before sending back.  We also do verifications when this IS
226
-     * NOT an revision because we always need to make sure that the autosave/revision has parent recorded (which is
227
-     * sometime delayed if the object is created/saved first by the autosave)
228
-     *
229
-     * @param  EE_Base_Class $this_obj
230
-     * @param  EE_Base_Class $other_obj
231
-     * @param  boolean       $remove_relation Indicates whether we're doing a remove_relation or add_relation.
232
-     * @return EE_Base_Class. ($other_obj);
233
-     * @throws \EE_Error
234
-     */
235
-    protected function _check_for_revision($this_obj, $other_obj, $remove_relation = false)
236
-    {
237
-        $pk_on_related_model = $this->get_other_model()->get_primary_key_field()->get_name();
238
-        // now we need to determine if we're in a WP revision save cause if we are we need to do some special handling
239
-        if ($this_obj->post_type() === 'revision') {
240
-            // first if $other_obj fk = this_obj pk then we know that this is a pk object, let's make sure there is a matching set for the autosave if there is then we save over it, if there isn't then we need to create a new one.
241
-            $parent_evt_id = $this_obj->parent();
242
-            /*var_dump($parent_evt_id);
15
+	/**
16
+	 * The Foreign key on the model that acts as the PRIMARY KEY used in special autosave handling where we query for
17
+	 * autosaves (or the Foreign key on other models in relations pointing to this models primary key which is this
18
+	 * value).  The _primary_cpt_field is what is equivalent to the post_id field on a cpt join.
19
+	 *
20
+	 * @var string
21
+	 */
22
+	private $_primary_cpt_field;
23
+
24
+
25
+	/**
26
+	 * This is what field serves as the "parent" column that is linked with whatever the main model's calling this
27
+	 * relation has as a primary key.  In other words EEM_Event has 'Datetime' => new
28
+	 * EE_Has_Many_Revision_Relation('EVT_ID', 'DTT_parent').  That means that in the EEM_Datetime model the
29
+	 * 'DTT_Parent' field is related to the 'DTT_ID' primary key field (in the same model) because 'DTT_ID' is the
30
+	 * primary key in the other model (EEM_Datetime).
31
+	 *
32
+	 * @var string
33
+	 */
34
+	private $_parent_pk_relation_field;
35
+
36
+
37
+	/**
38
+	 * Object representing the relationship between two models. Has_Many_Relations are where the OTHER model has the
39
+	 * foreign key this model. IE, there can be many other model objects related to one of this model's objects (but
40
+	 * NOT through a JOIN table, which is the case for EE_HABTM_Relations). This knows how to join the models, get
41
+	 * related models across the relation, and add-and-remove the relationships.
42
+	 *
43
+	 * @param string  $primary_cpt_field             See property description for details
44
+	 * @param string  $parent_pk_relation_field      This is the field that is "connected" to the $primary_cpt_field.
45
+	 *                                               See property desc for details.
46
+	 * @param boolean $block_deletes                 For this type of relation, we block by default. If there are
47
+	 *                                               related models across this relation, block (prevent and add an
48
+	 *                                               error) the deletion of this model
49
+	 * @param string  $blocking_delete_error_message a customized error message on blocking deletes instead of the
50
+	 *                                               default
51
+	 */
52
+	public function __construct(
53
+		$primary_cpt_field,
54
+		$parent_pk_relation_field,
55
+		$block_deletes = true,
56
+		$blocking_delete_error_message = null
57
+	) {
58
+		$this->_primary_cpt_field        = $primary_cpt_field;
59
+		$this->_parent_pk_relation_field = $parent_pk_relation_field;
60
+		parent::__construct($block_deletes, $blocking_delete_error_message);
61
+	}
62
+
63
+
64
+	/**
65
+	 * Sets the other model object's foreign key to this model object's primary key. Feel free to do this manually if
66
+	 * you like.
67
+	 *
68
+	 * @param EE_Base_Class|int $this_obj_or_id
69
+	 * @param EE_Base_Class|int $other_obj_or_id
70
+	 * @param array             $extra_join_model_fields_n_values
71
+	 * @return \EE_Base_Class
72
+	 * @throws \EE_Error
73
+	 */
74
+	public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
75
+	{
76
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
77
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id);
78
+
79
+		// handle possible revisions
80
+		$other_model_obj = $this->_check_for_revision($this_model_obj, $other_model_obj);
81
+
82
+		// if is array, then we've already done the add_relation so let's get out
83
+		if (is_array($other_model_obj)) {
84
+			return $other_model_obj[0];
85
+		}
86
+		// find the field on the other model which is a foreign key to this model
87
+		$fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
88
+		// set that field on the other model to this model's ID
89
+		$other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID());
90
+		$other_model_obj->save();
91
+		return $other_model_obj;
92
+	}
93
+
94
+
95
+	/**
96
+	 * Sets the other model object's foreign key to its default, instead of pointing to this model object
97
+	 *
98
+	 * @param EE_Base_Class|int $this_obj_or_id
99
+	 * @param EE_Base_Class|int $other_obj_or_id
100
+	 * @param array             $where_query
101
+	 * @return \EE_Base_Class
102
+	 * @throws \EE_Error
103
+	 */
104
+	public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
105
+	{
106
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id);
107
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id);
108
+		// handle possible revisions
109
+		$other_model_obj = $this->_check_for_revision($this_model_obj, $other_model_obj, true);
110
+
111
+
112
+		// if is array, then we've already done the add_relation so let's get out
113
+		if (is_array($other_model_obj)) {
114
+			return $other_model_obj[0];
115
+		}
116
+
117
+		// find the field on the other model which is a foreign key to this model
118
+		$fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
119
+
120
+
121
+		// set that field on the other model to this model's ID
122
+		if ($this->_blocking_delete) {
123
+			$other_model_obj->set($fk_field_on_other_model->get_name(), null, true);
124
+			$other_model_obj->save();
125
+		} else {
126
+			$other_model_obj->delete();
127
+			$other_model_obj->set($fk_field_on_other_model->get_name(), null, true);
128
+			return $other_model_obj;
129
+		}
130
+		return $other_model_obj;
131
+	}
132
+
133
+
134
+	/**
135
+	 * This is identical to EE_Model_Relation->get_all_related() except we're going handle special autosave conditions
136
+	 * in here.
137
+	 *
138
+	 * @param  EE_Base_Class|int $model_object_or_id
139
+	 * @param  array             $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
140
+	 * @param  boolean           $values_already_prepared_by_model_object @deprecated since 4.8.1
141
+	 * @return EE_Base_Class[]
142
+	 * @throws \EE_Error
143
+	 */
144
+	public function get_all_related(
145
+		$model_object_or_id,
146
+		$query_params = array(),
147
+		$values_already_prepared_by_model_object = false
148
+	) {
149
+		if ($values_already_prepared_by_model_object !== false) {
150
+			EE_Error::doing_it_wrong(
151
+				'EE_Model_Relation_Base::get_all_related',
152
+				__('The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso'),
153
+				'4.8.1'
154
+			);
155
+		}
156
+
157
+		// if this is an autosave then we're going to get things differently
158
+		if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
159
+			return $this->_do_autosave_get_all($model_object_or_id, $query_params);
160
+		}
161
+
162
+		return parent::get_all_related($model_object_or_id, $query_params);
163
+	}
164
+
165
+
166
+	/**
167
+	 * If we're in the midst of an autosave then we're going to do things a bit differently than the usual
168
+	 * get_all_related (commenting within).  For description of params see the get_all_related() comments
169
+	 *
170
+	 * @access protected
171
+	 * @param      $model_object_or_id
172
+	 * @param      $query_params
173
+	 * @param bool $deprecated
174
+	 * @return \EE_Base_Class[]
175
+	 * @throws \EE_Error
176
+	 */
177
+	protected function _do_autosave_get_all($model_object_or_id, $query_params, $deprecated = false)
178
+	{
179
+
180
+		// first we check if the post_id for the incoming query is for an autosave.  If it isn't that's what we want!
181
+		$model_object_id = $this->_get_model_object_id($model_object_or_id);
182
+
183
+		$autosave  = wp_get_post_autosave($model_object_id);
184
+		$id_to_use = $autosave ? $autosave->ID : $model_object_id;
185
+
186
+		$autosave_relations = parent::get_all_related($id_to_use, $query_params);
187
+		$parent_ids         = $parents = array();
188
+		$return_objs        = array();
189
+
190
+		// k this is where things differ because NOW what we're going to do is get the PARENTS for the get all related (and we'll also start setting up the return_objs array containing related that DON'T have parent ids, for those that DON'T have parents to merge with our returned objects);
191
+		foreach ($autosave_relations as $a_r) {
192
+			$pid = $a_r->parent();
193
+			if (! empty($pid)) {
194
+				$parent_ids[] = $pid;
195
+			} else {
196
+				$return_objs[] = $a_r;
197
+			}
198
+		}
199
+
200
+		// we have to make sure we also include the ORIGINAL values
201
+		$originals = parent::get_all_related($model_object_or_id, $query_params);
202
+
203
+		// merge $originals with $return_objs
204
+		if ($originals) {
205
+			$return_objs = array_merge($originals, $return_objs);
206
+		}
207
+
208
+		// now we setup the query to get all the parents
209
+		if (! empty($parent_ids)) {
210
+			$query_param_where_this_model_pk                  = $this->get_this_model()->get_this_model_name() . "." . $this->get_this_model()->get_primary_key_field()->get_name();
211
+			$query_param[0][ $query_param_where_this_model_pk ] = array('IN', $parent_ids);
212
+			$parents                                          = $this->get_other_model()->get_all($query_params);
213
+		}
214
+
215
+		// var_dump($parents);
216
+
217
+
218
+		// now merge parents with our current $return_objs and send back
219
+		return array_merge($parents, $return_objs);
220
+	}
221
+
222
+
223
+	/**
224
+	 * Basically this method gets called to verify if the incoming object needs to be manipulated somewhat because it
225
+	 * is a revision save.  If so, then we change things before sending back.  We also do verifications when this IS
226
+	 * NOT an revision because we always need to make sure that the autosave/revision has parent recorded (which is
227
+	 * sometime delayed if the object is created/saved first by the autosave)
228
+	 *
229
+	 * @param  EE_Base_Class $this_obj
230
+	 * @param  EE_Base_Class $other_obj
231
+	 * @param  boolean       $remove_relation Indicates whether we're doing a remove_relation or add_relation.
232
+	 * @return EE_Base_Class. ($other_obj);
233
+	 * @throws \EE_Error
234
+	 */
235
+	protected function _check_for_revision($this_obj, $other_obj, $remove_relation = false)
236
+	{
237
+		$pk_on_related_model = $this->get_other_model()->get_primary_key_field()->get_name();
238
+		// now we need to determine if we're in a WP revision save cause if we are we need to do some special handling
239
+		if ($this_obj->post_type() === 'revision') {
240
+			// first if $other_obj fk = this_obj pk then we know that this is a pk object, let's make sure there is a matching set for the autosave if there is then we save over it, if there isn't then we need to create a new one.
241
+			$parent_evt_id = $this_obj->parent();
242
+			/*var_dump($parent_evt_id);
243 243
             var_dump($this_obj);
244 244
             var_dump($other_obj);/**/
245 245
 
246
-            if (! empty($parent_evt_id) && $parent_evt_id == $other_obj->get($this->_primary_cpt_field)) {
247
-                // let's do query on this objects model to see if the incoming pk value on the obj matches any parents in this objects table.
248
-                $has_parent_obj = $this->get_other_model()->get_one(array(
249
-                    array(
250
-                        $this->_parent_pk_relation_field => $other_obj->ID(),
251
-                        $this->_primary_cpt_field        => $this_obj->ID(),
252
-                    ),
253
-                ));
254
-
255
-                if ($has_parent_obj) {
256
-                    // this makes sure the update on the current obj happens to the revision's row NOT the parent row.
257
-
258
-                    $other_obj->set($this->_parent_pk_relation_field, $other_obj->ID());
259
-                    $other_obj->set($pk_on_related_model, $has_parent_obj->ID());
260
-                    $other_obj->set($this->_primary_cpt_field, $this_obj->ID());
261
-
262
-                    if (! $remove_relation) {
263
-                        $other_obj->save();
264
-                        return array($other_obj);
265
-                    } elseif ($remove_relation && ! $this->_blocking_delete) {
266
-                        $other_obj->delete();
267
-                        $other_obj->set($this->_parent_pk_relation_field, null, true);
268
-                        return array($other_obj);
269
-                    }
270
-                } else {
271
-                    $other_obj->set($this->_parent_pk_relation_field, $other_obj->ID());
272
-                    $other_obj->set($this->_primary_cpt_field, $this_obj->ID());
273
-                    $other_obj->set(
274
-                        $pk_on_related_model,
275
-                        null,
276
-                        true
277
-                    ); // ensure we create a new row for the autosave with parent id the same as the incoming ID.
278
-                    $other_obj->save(); // make sure we insert.
279
-                    return array($other_obj);
280
-                }
281
-            }
282
-
283
-            // var_dump('what makes it here');
284
-            // var_dump($other_obj);
285
-            // the next possible condition is that the incoming other_model obj has a NULL pk which means it just gets saved (which in turn creates it)
286
-
287
-            // the last possible condition on a revision is that the incoming other_model object has a fk that == $this_obj pk which means we just return the $other obj and let it save as normal so we see the return at the bottom of this method.
288
-        } else {
289
-            // we only need to do the below IF this is not a remove relation
290
-            if (! $remove_relation) {
291
-                // okay this is is a normal update/save/remove so, let's make sure the other object is not a revision of the current object.
292
-                // the other object will likely NOT have the correct fk on it (which is the primary_cpt_field_mame) so we must retrieve from the db to get that first.
293
-                $existing_other_obj    = $this->get_other_model()->get_one_by_ID($other_obj->ID());
294
-                $potential_revision_id = is_object($existing_other_obj) ? $existing_other_obj->get($this->_primary_cpt_field) : null;
295
-
296
-                if ($parent_this_obj_id = wp_is_post_revision($potential_revision_id)) {
297
-                    // yes the OTHER object is linked to the revision of the parent, not the parent itself. That means we need to make the other_object an attachment of this_obj and then duplicate other_obj for the revision.
298
-                    $other_obj->set($this->_primary_cpt_field, $this_obj->ID());
299
-                    $other_obj->save();
300
-
301
-                    // now create a new other_obj and fill with details from existing object
302
-                    $new_obj = $other_obj;
303
-                    $new_obj->set($this->_primary_cpt_field, $potential_revision_id);
304
-                    $new_obj->set($this->_parent_pk_relation_field, $other_obj->ID());
305
-                    $new_obj->set($pk_on_related_model, null);
306
-                    $new_obj->save();
307
-                    return array($new_obj);
308
-                }
309
-            }
310
-        }
311
-
312
-        return $other_obj;
313
-    }
246
+			if (! empty($parent_evt_id) && $parent_evt_id == $other_obj->get($this->_primary_cpt_field)) {
247
+				// let's do query on this objects model to see if the incoming pk value on the obj matches any parents in this objects table.
248
+				$has_parent_obj = $this->get_other_model()->get_one(array(
249
+					array(
250
+						$this->_parent_pk_relation_field => $other_obj->ID(),
251
+						$this->_primary_cpt_field        => $this_obj->ID(),
252
+					),
253
+				));
254
+
255
+				if ($has_parent_obj) {
256
+					// this makes sure the update on the current obj happens to the revision's row NOT the parent row.
257
+
258
+					$other_obj->set($this->_parent_pk_relation_field, $other_obj->ID());
259
+					$other_obj->set($pk_on_related_model, $has_parent_obj->ID());
260
+					$other_obj->set($this->_primary_cpt_field, $this_obj->ID());
261
+
262
+					if (! $remove_relation) {
263
+						$other_obj->save();
264
+						return array($other_obj);
265
+					} elseif ($remove_relation && ! $this->_blocking_delete) {
266
+						$other_obj->delete();
267
+						$other_obj->set($this->_parent_pk_relation_field, null, true);
268
+						return array($other_obj);
269
+					}
270
+				} else {
271
+					$other_obj->set($this->_parent_pk_relation_field, $other_obj->ID());
272
+					$other_obj->set($this->_primary_cpt_field, $this_obj->ID());
273
+					$other_obj->set(
274
+						$pk_on_related_model,
275
+						null,
276
+						true
277
+					); // ensure we create a new row for the autosave with parent id the same as the incoming ID.
278
+					$other_obj->save(); // make sure we insert.
279
+					return array($other_obj);
280
+				}
281
+			}
282
+
283
+			// var_dump('what makes it here');
284
+			// var_dump($other_obj);
285
+			// the next possible condition is that the incoming other_model obj has a NULL pk which means it just gets saved (which in turn creates it)
286
+
287
+			// the last possible condition on a revision is that the incoming other_model object has a fk that == $this_obj pk which means we just return the $other obj and let it save as normal so we see the return at the bottom of this method.
288
+		} else {
289
+			// we only need to do the below IF this is not a remove relation
290
+			if (! $remove_relation) {
291
+				// okay this is is a normal update/save/remove so, let's make sure the other object is not a revision of the current object.
292
+				// the other object will likely NOT have the correct fk on it (which is the primary_cpt_field_mame) so we must retrieve from the db to get that first.
293
+				$existing_other_obj    = $this->get_other_model()->get_one_by_ID($other_obj->ID());
294
+				$potential_revision_id = is_object($existing_other_obj) ? $existing_other_obj->get($this->_primary_cpt_field) : null;
295
+
296
+				if ($parent_this_obj_id = wp_is_post_revision($potential_revision_id)) {
297
+					// yes the OTHER object is linked to the revision of the parent, not the parent itself. That means we need to make the other_object an attachment of this_obj and then duplicate other_obj for the revision.
298
+					$other_obj->set($this->_primary_cpt_field, $this_obj->ID());
299
+					$other_obj->save();
300
+
301
+					// now create a new other_obj and fill with details from existing object
302
+					$new_obj = $other_obj;
303
+					$new_obj->set($this->_primary_cpt_field, $potential_revision_id);
304
+					$new_obj->set($this->_parent_pk_relation_field, $other_obj->ID());
305
+					$new_obj->set($pk_on_related_model, null);
306
+					$new_obj->save();
307
+					return array($new_obj);
308
+				}
309
+			}
310
+		}
311
+
312
+		return $other_obj;
313
+	}
314 314
 }
Please login to merge, or discard this patch.
core/db_models/relations/EE_Has_Many_Any_Relation.php 2 patches
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -15,94 +15,94 @@
 block discarded – undo
15 15
 class EE_Has_Many_Any_Relation extends EE_Has_Many_Relation
16 16
 {
17 17
 
18
-    /**
19
-     * Gets the SQL string for performing the join between this model and the other model.
20
-     *
21
-     * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
22
-     * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk =
23
-     *                other_model_primary_table.fk" etc
24
-     * @throws \EE_Error
25
-     */
26
-    public function get_join_statement($model_relation_chain)
27
-    {
28
-        // create the sql string like
29
-        // LEFT JOIN other_table AS table_alias ON this_table_alias.pk = other_table_alias.fk extra_join_conditions
30
-        $this_table_pk_field   = $this->get_this_model()->get_primary_key_field();
31
-        $other_table_fk_field  = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
32
-        $pk_table_alias        = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
33
-            $model_relation_chain,
34
-            $this->get_this_model()->get_this_model_name()
35
-        ) . $this_table_pk_field->get_table_alias();
36
-        $fk_table_alias        = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
37
-            $model_relation_chain,
38
-            $this->get_other_model()->get_this_model_name()
39
-        ) . $other_table_fk_field->get_table_alias();
40
-        $fk_table              = $this->get_other_model()->get_table_for_alias($fk_table_alias);
41
-        $field_with_model_name = $this->get_other_model()->get_field_containing_related_model_name();
18
+	/**
19
+	 * Gets the SQL string for performing the join between this model and the other model.
20
+	 *
21
+	 * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
22
+	 * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk =
23
+	 *                other_model_primary_table.fk" etc
24
+	 * @throws \EE_Error
25
+	 */
26
+	public function get_join_statement($model_relation_chain)
27
+	{
28
+		// create the sql string like
29
+		// LEFT JOIN other_table AS table_alias ON this_table_alias.pk = other_table_alias.fk extra_join_conditions
30
+		$this_table_pk_field   = $this->get_this_model()->get_primary_key_field();
31
+		$other_table_fk_field  = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
32
+		$pk_table_alias        = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
33
+			$model_relation_chain,
34
+			$this->get_this_model()->get_this_model_name()
35
+		) . $this_table_pk_field->get_table_alias();
36
+		$fk_table_alias        = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
37
+			$model_relation_chain,
38
+			$this->get_other_model()->get_this_model_name()
39
+		) . $other_table_fk_field->get_table_alias();
40
+		$fk_table              = $this->get_other_model()->get_table_for_alias($fk_table_alias);
41
+		$field_with_model_name = $this->get_other_model()->get_field_containing_related_model_name();
42 42
 
43
-        return $this->_left_join(
44
-            $fk_table,
45
-            $fk_table_alias,
46
-            $other_table_fk_field->get_table_column(),
47
-            $pk_table_alias,
48
-            $this_table_pk_field->get_table_column(),
49
-            $fk_table_alias . '.' . $field_with_model_name->get_table_column() . "='" . $this->get_this_model()->get_this_model_name() . "'"
50
-        )
51
-               . $this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias);
52
-    }
43
+		return $this->_left_join(
44
+			$fk_table,
45
+			$fk_table_alias,
46
+			$other_table_fk_field->get_table_column(),
47
+			$pk_table_alias,
48
+			$this_table_pk_field->get_table_column(),
49
+			$fk_table_alias . '.' . $field_with_model_name->get_table_column() . "='" . $this->get_this_model()->get_this_model_name() . "'"
50
+		)
51
+			   . $this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias);
52
+	}
53 53
 
54 54
 
55
-    /**
56
-     * Sets the other model object's foreign key to this model object's primary key. Feel free to do this manually if
57
-     * you like.
58
-     *
59
-     * @param EE_Base_Class|int $this_obj_or_id
60
-     * @param EE_Base_Class|int $other_obj_or_id
61
-     * @param array             $extra_join_model_fields_n_values
62
-     * @return \EE_Base_Class
63
-     * @throws \EE_Error
64
-     */
65
-    public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
66
-    {
67
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
68
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
55
+	/**
56
+	 * Sets the other model object's foreign key to this model object's primary key. Feel free to do this manually if
57
+	 * you like.
58
+	 *
59
+	 * @param EE_Base_Class|int $this_obj_or_id
60
+	 * @param EE_Base_Class|int $other_obj_or_id
61
+	 * @param array             $extra_join_model_fields_n_values
62
+	 * @return \EE_Base_Class
63
+	 * @throws \EE_Error
64
+	 */
65
+	public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
66
+	{
67
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
68
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
69 69
 
70
-        // find the field on the other model which is a foreign key to this model
71
-        $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
72
-        // set that field on the other model to this model's ID
73
-        $other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID());
74
-        $other_model_obj->set(
75
-            $this->get_other_model()->get_field_containing_related_model_name()->get_name(),
76
-            $this->get_this_model()->get_this_model_name()
77
-        );
78
-        $other_model_obj->save();
79
-        return $other_model_obj;
80
-    }
70
+		// find the field on the other model which is a foreign key to this model
71
+		$fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
72
+		// set that field on the other model to this model's ID
73
+		$other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID());
74
+		$other_model_obj->set(
75
+			$this->get_other_model()->get_field_containing_related_model_name()->get_name(),
76
+			$this->get_this_model()->get_this_model_name()
77
+		);
78
+		$other_model_obj->save();
79
+		return $other_model_obj;
80
+	}
81 81
 
82 82
 
83
-    /**
84
-     * Sets the other model object's foreign key to its default, instead of pointing to this model object.
85
-     * If $other_obj_or_id doesn't have any other relations, this function is essentially orphaning it
86
-     *
87
-     * @param EE_Base_Class|int $this_obj_or_id
88
-     * @param EE_Base_Class|int $other_obj_or_id
89
-     * @param array             $where_query
90
-     * @return \EE_Base_Class
91
-     * @throws \EE_Error
92
-     */
93
-    public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
94
-    {
95
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
96
-        // find the field on the other model which is a foreign key to this model
97
-        $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
98
-        // set that field on the other model to this model's ID
99
-        $other_model_obj->set($fk_field_on_other_model->get_name(), null, true);
100
-        $other_model_obj->set(
101
-            $this->get_other_model()->get_field_containing_related_model_name()->get_name(),
102
-            null,
103
-            true
104
-        );
105
-        $other_model_obj->save();
106
-        return $other_model_obj;
107
-    }
83
+	/**
84
+	 * Sets the other model object's foreign key to its default, instead of pointing to this model object.
85
+	 * If $other_obj_or_id doesn't have any other relations, this function is essentially orphaning it
86
+	 *
87
+	 * @param EE_Base_Class|int $this_obj_or_id
88
+	 * @param EE_Base_Class|int $other_obj_or_id
89
+	 * @param array             $where_query
90
+	 * @return \EE_Base_Class
91
+	 * @throws \EE_Error
92
+	 */
93
+	public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
94
+	{
95
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
96
+		// find the field on the other model which is a foreign key to this model
97
+		$fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
98
+		// set that field on the other model to this model's ID
99
+		$other_model_obj->set($fk_field_on_other_model->get_name(), null, true);
100
+		$other_model_obj->set(
101
+			$this->get_other_model()->get_field_containing_related_model_name()->get_name(),
102
+			null,
103
+			true
104
+		);
105
+		$other_model_obj->save();
106
+		return $other_model_obj;
107
+	}
108 108
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -32,11 +32,11 @@  discard block
 block discarded – undo
32 32
         $pk_table_alias        = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
33 33
             $model_relation_chain,
34 34
             $this->get_this_model()->get_this_model_name()
35
-        ) . $this_table_pk_field->get_table_alias();
36
-        $fk_table_alias        = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
35
+        ).$this_table_pk_field->get_table_alias();
36
+        $fk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
37 37
             $model_relation_chain,
38 38
             $this->get_other_model()->get_this_model_name()
39
-        ) . $other_table_fk_field->get_table_alias();
39
+        ).$other_table_fk_field->get_table_alias();
40 40
         $fk_table              = $this->get_other_model()->get_table_for_alias($fk_table_alias);
41 41
         $field_with_model_name = $this->get_other_model()->get_field_containing_related_model_name();
42 42
 
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
             $other_table_fk_field->get_table_column(),
47 47
             $pk_table_alias,
48 48
             $this_table_pk_field->get_table_column(),
49
-            $fk_table_alias . '.' . $field_with_model_name->get_table_column() . "='" . $this->get_this_model()->get_this_model_name() . "'"
49
+            $fk_table_alias.'.'.$field_with_model_name->get_table_column()."='".$this->get_this_model()->get_this_model_name()."'"
50 50
         )
51 51
                . $this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias);
52 52
     }
Please login to merge, or discard this patch.
core/db_models/EEM_Status.model.php 2 patches
Indentation   +277 added lines, -277 removed lines patch added patch discarded remove patch
@@ -11,292 +11,292 @@
 block discarded – undo
11 11
 class EEM_Status extends EEM_Base
12 12
 {
13 13
 
14
-    // private instance of the Attendee object
15
-    protected static $_instance = null;
14
+	// private instance of the Attendee object
15
+	protected static $_instance = null;
16 16
 
17 17
 
18
-    /**
19
-     * @return EEM_Status
20
-     */
21
-    protected function __construct($timezone = null)
22
-    {
23
-        $this->singular_item    = __('Status', 'event_espresso');
24
-        $this->plural_item      = __('Stati', 'event_espresso');
25
-        $this->_tables          = array(
26
-            'StatusTable' => new EE_Primary_Table('esp_status', 'STS_ID'),
27
-        );
28
-        $this->_fields          = array(
29
-            'StatusTable' => array(
30
-                'STS_ID'       => new EE_Primary_Key_String_Field('STS_ID', __('Status ID', 'event_espresso')),
31
-                'STS_code'     => new EE_Plain_Text_Field('STS_code', __('Status Code', 'event_espresso'), false, ''),
32
-                'STS_type'     => new EE_Enum_Text_Field(
33
-                    'STS_type',
34
-                    __("Type", "event_espresso"),
35
-                    false,
36
-                    'event',
37
-                    array(
38
-                        'event'        => __("Event", "event_espresso"),// deprecated
39
-                        'registration' => __("Registration", "event_espresso"),
40
-                        'transaction'  => __("Transaction", "event_espresso"),
41
-                        'payment'      => __("Payment", "event_espresso"),
42
-                        'email'        => __("Email", "event_espresso"),
43
-                        'message'      => __("Message", "event_espresso"),
44
-                    )
45
-                ),
46
-                'STS_can_edit' => new EE_Boolean_Field('STS_can_edit', __('Editable?', 'event_espresso'), false, false),
47
-                'STS_desc'     => new EE_Simple_HTML_Field('STS_desc', __("Description", "event_espresso"), false, ''),
48
-                'STS_open'     => new EE_Boolean_Field('STS_open', __("Open?", "event_espresso"), false, false),
49
-            ),
50
-        );
51
-        $this->_model_relations = array(
52
-            'Registration' => new EE_Has_Many_Relation(),
53
-            'Transaction'  => new EE_Has_Many_Relation(),
54
-            'Payment'      => new EE_Has_Many_Relation(),
55
-        );
56
-        // this model is generally available for reading
57
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
18
+	/**
19
+	 * @return EEM_Status
20
+	 */
21
+	protected function __construct($timezone = null)
22
+	{
23
+		$this->singular_item    = __('Status', 'event_espresso');
24
+		$this->plural_item      = __('Stati', 'event_espresso');
25
+		$this->_tables          = array(
26
+			'StatusTable' => new EE_Primary_Table('esp_status', 'STS_ID'),
27
+		);
28
+		$this->_fields          = array(
29
+			'StatusTable' => array(
30
+				'STS_ID'       => new EE_Primary_Key_String_Field('STS_ID', __('Status ID', 'event_espresso')),
31
+				'STS_code'     => new EE_Plain_Text_Field('STS_code', __('Status Code', 'event_espresso'), false, ''),
32
+				'STS_type'     => new EE_Enum_Text_Field(
33
+					'STS_type',
34
+					__("Type", "event_espresso"),
35
+					false,
36
+					'event',
37
+					array(
38
+						'event'        => __("Event", "event_espresso"),// deprecated
39
+						'registration' => __("Registration", "event_espresso"),
40
+						'transaction'  => __("Transaction", "event_espresso"),
41
+						'payment'      => __("Payment", "event_espresso"),
42
+						'email'        => __("Email", "event_espresso"),
43
+						'message'      => __("Message", "event_espresso"),
44
+					)
45
+				),
46
+				'STS_can_edit' => new EE_Boolean_Field('STS_can_edit', __('Editable?', 'event_espresso'), false, false),
47
+				'STS_desc'     => new EE_Simple_HTML_Field('STS_desc', __("Description", "event_espresso"), false, ''),
48
+				'STS_open'     => new EE_Boolean_Field('STS_open', __("Open?", "event_espresso"), false, false),
49
+			),
50
+		);
51
+		$this->_model_relations = array(
52
+			'Registration' => new EE_Has_Many_Relation(),
53
+			'Transaction'  => new EE_Has_Many_Relation(),
54
+			'Payment'      => new EE_Has_Many_Relation(),
55
+		);
56
+		// this model is generally available for reading
57
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
58 58
 
59
-        parent::__construct($timezone);
60
-    }
59
+		parent::__construct($timezone);
60
+	}
61 61
 
62 62
 
63
-    /**
64
-     * This method provides the localized singular or plural string for a given status id
65
-     *
66
-     * @param  array   $statuses This should be an array of statuses in the format array( $status_id, $status_code ).
67
-     *                           That way if there isn't a translation in the index we'll return the default code.
68
-     * @param  boolean $plural   Whether to return plural string or not. Note, nearly all of the plural strings are the
69
-     *                           same as the singular (in English), however, this may NOT be the case with other
70
-     *                           languages
71
-     * @param  string  $schema   This can be either 'upper', 'lower', or 'sentence'.  Basically indicates how we want
72
-     *                           the status string returned ( UPPER, lower, Sentence)
73
-     * @throws EE_Error
74
-     * @return array             an array of translated strings for the incoming status id.
75
-     */
76
-    public function localized_status($statuses, $plural = false, $schema = 'upper')
77
-    {
78
-        // note these are all in lower case because ucwords() on upper case will NOT convert.
79
-        $translation_array = array(
80
-            EEM_Registration::status_id_pending_payment => array(
81
-                __('pending payment', 'event_espresso'), // singular
82
-                __('pending payments', 'event_espresso') // plural
83
-            ),
84
-            EEM_Registration::status_id_approved        => array(
85
-                __('approved', 'event_espresso'), // singular
86
-                __('approved', 'event_espresso') // plural
87
-            ),
88
-            EEM_Registration::status_id_not_approved    => array(
89
-                __('not approved', 'event_espresso'),
90
-                __('not approved', 'event_espresso'),
91
-            ),
92
-            EEM_Registration::status_id_cancelled       => array(
93
-                __('cancelled', 'event_espresso'),
94
-                __('cancelled', 'event_espresso'),
95
-            ),
96
-            EEM_Registration::status_id_incomplete      => array(
97
-                __('incomplete', 'event_espresso'),
98
-                __('incomplete', 'event_espresso'),
99
-            ),
100
-            EEM_Registration::status_id_declined        => array(
101
-                __('declined', 'event_espresso'),
102
-                __('declined', 'event_espresso'),
103
-            ),
104
-            EEM_Registration::status_id_wait_list       => array(
105
-                __('wait list', 'event_espresso'),
106
-                __('wait list', 'event_espresso'),
107
-            ),
108
-            EEM_Transaction::overpaid_status_code       => array(
109
-                __('overpaid', 'event_espresso'),
110
-                __('overpaid', 'event_espresso'),
111
-            ),
112
-            EEM_Transaction::complete_status_code       => array(
113
-                __('complete', 'event_espresso'),
114
-                __('complete', 'event_espresso'),
115
-            ),
116
-            EEM_Transaction::incomplete_status_code     => array(
117
-                __('incomplete', 'event_espresso'),
118
-                __('incomplete', 'event_espresso'),
119
-            ),
120
-            EEM_Transaction::failed_status_code         => array(
121
-                __('failed', 'event_espresso'),
122
-                __('failed', 'event_espresso'),
123
-            ),
124
-            EEM_Transaction::abandoned_status_code      => array(
125
-                __('abandoned', 'event_espresso'),
126
-                __('abandoned', 'event_espresso'),
127
-            ),
128
-            EEM_Payment::status_id_approved             => array(
129
-                __('accepted', 'event_espresso'),
130
-                __('accepted', 'event_espresso'),
131
-            ),
132
-            EEM_Payment::status_id_pending              => array(
133
-                __('pending', 'event_espresso'),
134
-                __('pending', 'event_espresso'),
135
-            ),
136
-            EEM_Payment::status_id_cancelled            => array(
137
-                __('cancelled', 'event_espresso'),
138
-                __('cancelled', 'event_espresso'),
139
-            ),
140
-            EEM_Payment::status_id_declined             => array(
141
-                __('declined', 'event_espresso'),
142
-                __('declined', 'event_espresso'),
143
-            ),
144
-            EEM_Payment::status_id_failed               => array(
145
-                __('failed', 'event_espresso'),
146
-                __('failed', 'event_espresso'),
147
-            ),
148
-            // following statuses are NOT part of the EEM_Status but to keep things centralized we include in here.
149
-            EEM_Event::sold_out                         => array(
150
-                __('sold out', 'event_espresso'),
151
-                __('sold out', 'event_espresso'),
152
-            ),
153
-            EEM_Event::postponed                        => array(
154
-                __('postponed', 'event_espresso'),
155
-                __('Postponed', 'event_espresso'),
156
-            ),
157
-            EEM_Event::cancelled                        => array(
158
-                __('cancelled', 'event_espresso'),
159
-                __('cancelled', 'event_espresso'),
160
-            ),
161
-            EE_Ticket::archived                         => array(
162
-                __('archived', 'event_espresso'),
163
-                __('archived', 'event_espresso'),
164
-            ),
165
-            EE_Ticket::expired                          => array(
166
-                __('expired', 'event_espresso'),
167
-                __('expired', 'event_espresso'),
168
-            ),
169
-            EE_Ticket::sold_out                         => array(
170
-                __('sold out', 'event_espresso'),
171
-                __('sold out', 'event_espresso'),
172
-            ),
173
-            EE_Ticket::pending                          => array(
174
-                __('upcoming', 'event_espresso'),
175
-                __('upcoming', 'event_espresso'),
176
-            ),
177
-            EE_Ticket::onsale                           => array(
178
-                __('on sale', 'event_espresso'),
179
-                __('on sale', 'event_espresso'),
180
-            ),
181
-            EE_Datetime::cancelled                      => array(
182
-                __('cancelled', 'event_espresso'),
183
-                __('cancelled', 'event_espresso'),
184
-            ),
185
-            EE_Datetime::sold_out                       => array(
186
-                __('sold out', 'event_espresso'),
187
-                __('sold out', 'event_espresso'),
188
-            ),
189
-            EE_Datetime::expired                        => array(
190
-                __('expired', 'event_espresso'),
191
-                __('expired', 'event_espresso'),
192
-            ),
193
-            EE_Datetime::inactive                       => array(
194
-                __('inactive', 'event_espresso'),
195
-                __('inactive', 'event_espresso'),
196
-            ),
197
-            EE_Datetime::upcoming                       => array(
198
-                __('upcoming', 'event_espresso'),
199
-                __('upcoming', 'event_espresso'),
200
-            ),
201
-            EE_Datetime::active                         => array(
202
-                __('active', 'event_espresso'),
203
-                __('active', 'event_espresso'),
204
-            ),
205
-            EE_Datetime::postponed                      => array(
206
-                __('postponed', 'event_espresso'),
207
-                __('postponed', 'event_espresso'),
208
-            ),
209
-            // messages related
210
-            EEM_Message::status_sent                    => array(
211
-                __('sent', 'event_espresso'),
212
-                __('sent', 'event_espresso'),
213
-            ),
214
-            EEM_Message::status_idle                    => array(
215
-                __('queued for sending', 'event_espresso'),
216
-                __('queued for sending', 'event_espresso'),
217
-            ),
218
-            EEM_Message::status_failed                  => array(
219
-                __('failed', 'event_espresso'),
220
-                __('failed', 'event_espresso'),
221
-            ),
222
-            EEM_Message::status_debug_only              => array(
223
-                __('debug only', 'event_espresso'),
224
-                __('debug only', 'event_espresso'),
225
-            ),
226
-            EEM_Message::status_messenger_executing     => array(
227
-                __('messenger is executing', 'event_espresso'),
228
-                __('messenger is executing', 'event_espresso'),
229
-            ),
230
-            EEM_Message::status_resend                  => array(
231
-                __('queued for resending', 'event_espresso'),
232
-                __('queued for resending', 'event_espresso'),
233
-            ),
234
-            EEM_Message::status_incomplete              => array(
235
-                __('queued for generating', 'event_espresso'),
236
-                __('queued for generating', 'event_espresso'),
237
-            ),
238
-            EEM_Message::status_retry                   => array(
239
-                __('failed sending, can be retried', 'event_espresso'),
240
-                __('failed sending, can be retried', 'event_espresso'),
241
-            ),
242
-            EEM_CPT_Base::post_status_publish           => array(
243
-                __('published', 'event_espresso'),
244
-                __('published', 'event_espresso'),
245
-            ),
246
-            EEM_CPT_Base::post_status_future            => array(
247
-                __('scheduled', 'event_espresso'),
248
-                __('scheduled', 'event_espresso'),
249
-            ),
250
-            EEM_CPT_Base::post_status_draft             => array(
251
-                __('draft', 'event_espresso'),
252
-                __('draft', 'event_espresso'),
253
-            ),
254
-            EEM_CPT_Base::post_status_pending           => array(
255
-                __('pending', 'event_espresso'),
256
-                __('pending', 'event_espresso'),
257
-            ),
258
-            EEM_CPT_Base::post_status_private           => array(
259
-                __('private', 'event_espresso'),
260
-                __('private', 'event_espresso'),
261
-            ),
262
-            EEM_CPT_Base::post_status_trashed           => array(
263
-                __('trashed', 'event_espresso'),
264
-                __('trashed', 'event_espresso'),
265
-            ),
266
-        );
63
+	/**
64
+	 * This method provides the localized singular or plural string for a given status id
65
+	 *
66
+	 * @param  array   $statuses This should be an array of statuses in the format array( $status_id, $status_code ).
67
+	 *                           That way if there isn't a translation in the index we'll return the default code.
68
+	 * @param  boolean $plural   Whether to return plural string or not. Note, nearly all of the plural strings are the
69
+	 *                           same as the singular (in English), however, this may NOT be the case with other
70
+	 *                           languages
71
+	 * @param  string  $schema   This can be either 'upper', 'lower', or 'sentence'.  Basically indicates how we want
72
+	 *                           the status string returned ( UPPER, lower, Sentence)
73
+	 * @throws EE_Error
74
+	 * @return array             an array of translated strings for the incoming status id.
75
+	 */
76
+	public function localized_status($statuses, $plural = false, $schema = 'upper')
77
+	{
78
+		// note these are all in lower case because ucwords() on upper case will NOT convert.
79
+		$translation_array = array(
80
+			EEM_Registration::status_id_pending_payment => array(
81
+				__('pending payment', 'event_espresso'), // singular
82
+				__('pending payments', 'event_espresso') // plural
83
+			),
84
+			EEM_Registration::status_id_approved        => array(
85
+				__('approved', 'event_espresso'), // singular
86
+				__('approved', 'event_espresso') // plural
87
+			),
88
+			EEM_Registration::status_id_not_approved    => array(
89
+				__('not approved', 'event_espresso'),
90
+				__('not approved', 'event_espresso'),
91
+			),
92
+			EEM_Registration::status_id_cancelled       => array(
93
+				__('cancelled', 'event_espresso'),
94
+				__('cancelled', 'event_espresso'),
95
+			),
96
+			EEM_Registration::status_id_incomplete      => array(
97
+				__('incomplete', 'event_espresso'),
98
+				__('incomplete', 'event_espresso'),
99
+			),
100
+			EEM_Registration::status_id_declined        => array(
101
+				__('declined', 'event_espresso'),
102
+				__('declined', 'event_espresso'),
103
+			),
104
+			EEM_Registration::status_id_wait_list       => array(
105
+				__('wait list', 'event_espresso'),
106
+				__('wait list', 'event_espresso'),
107
+			),
108
+			EEM_Transaction::overpaid_status_code       => array(
109
+				__('overpaid', 'event_espresso'),
110
+				__('overpaid', 'event_espresso'),
111
+			),
112
+			EEM_Transaction::complete_status_code       => array(
113
+				__('complete', 'event_espresso'),
114
+				__('complete', 'event_espresso'),
115
+			),
116
+			EEM_Transaction::incomplete_status_code     => array(
117
+				__('incomplete', 'event_espresso'),
118
+				__('incomplete', 'event_espresso'),
119
+			),
120
+			EEM_Transaction::failed_status_code         => array(
121
+				__('failed', 'event_espresso'),
122
+				__('failed', 'event_espresso'),
123
+			),
124
+			EEM_Transaction::abandoned_status_code      => array(
125
+				__('abandoned', 'event_espresso'),
126
+				__('abandoned', 'event_espresso'),
127
+			),
128
+			EEM_Payment::status_id_approved             => array(
129
+				__('accepted', 'event_espresso'),
130
+				__('accepted', 'event_espresso'),
131
+			),
132
+			EEM_Payment::status_id_pending              => array(
133
+				__('pending', 'event_espresso'),
134
+				__('pending', 'event_espresso'),
135
+			),
136
+			EEM_Payment::status_id_cancelled            => array(
137
+				__('cancelled', 'event_espresso'),
138
+				__('cancelled', 'event_espresso'),
139
+			),
140
+			EEM_Payment::status_id_declined             => array(
141
+				__('declined', 'event_espresso'),
142
+				__('declined', 'event_espresso'),
143
+			),
144
+			EEM_Payment::status_id_failed               => array(
145
+				__('failed', 'event_espresso'),
146
+				__('failed', 'event_espresso'),
147
+			),
148
+			// following statuses are NOT part of the EEM_Status but to keep things centralized we include in here.
149
+			EEM_Event::sold_out                         => array(
150
+				__('sold out', 'event_espresso'),
151
+				__('sold out', 'event_espresso'),
152
+			),
153
+			EEM_Event::postponed                        => array(
154
+				__('postponed', 'event_espresso'),
155
+				__('Postponed', 'event_espresso'),
156
+			),
157
+			EEM_Event::cancelled                        => array(
158
+				__('cancelled', 'event_espresso'),
159
+				__('cancelled', 'event_espresso'),
160
+			),
161
+			EE_Ticket::archived                         => array(
162
+				__('archived', 'event_espresso'),
163
+				__('archived', 'event_espresso'),
164
+			),
165
+			EE_Ticket::expired                          => array(
166
+				__('expired', 'event_espresso'),
167
+				__('expired', 'event_espresso'),
168
+			),
169
+			EE_Ticket::sold_out                         => array(
170
+				__('sold out', 'event_espresso'),
171
+				__('sold out', 'event_espresso'),
172
+			),
173
+			EE_Ticket::pending                          => array(
174
+				__('upcoming', 'event_espresso'),
175
+				__('upcoming', 'event_espresso'),
176
+			),
177
+			EE_Ticket::onsale                           => array(
178
+				__('on sale', 'event_espresso'),
179
+				__('on sale', 'event_espresso'),
180
+			),
181
+			EE_Datetime::cancelled                      => array(
182
+				__('cancelled', 'event_espresso'),
183
+				__('cancelled', 'event_espresso'),
184
+			),
185
+			EE_Datetime::sold_out                       => array(
186
+				__('sold out', 'event_espresso'),
187
+				__('sold out', 'event_espresso'),
188
+			),
189
+			EE_Datetime::expired                        => array(
190
+				__('expired', 'event_espresso'),
191
+				__('expired', 'event_espresso'),
192
+			),
193
+			EE_Datetime::inactive                       => array(
194
+				__('inactive', 'event_espresso'),
195
+				__('inactive', 'event_espresso'),
196
+			),
197
+			EE_Datetime::upcoming                       => array(
198
+				__('upcoming', 'event_espresso'),
199
+				__('upcoming', 'event_espresso'),
200
+			),
201
+			EE_Datetime::active                         => array(
202
+				__('active', 'event_espresso'),
203
+				__('active', 'event_espresso'),
204
+			),
205
+			EE_Datetime::postponed                      => array(
206
+				__('postponed', 'event_espresso'),
207
+				__('postponed', 'event_espresso'),
208
+			),
209
+			// messages related
210
+			EEM_Message::status_sent                    => array(
211
+				__('sent', 'event_espresso'),
212
+				__('sent', 'event_espresso'),
213
+			),
214
+			EEM_Message::status_idle                    => array(
215
+				__('queued for sending', 'event_espresso'),
216
+				__('queued for sending', 'event_espresso'),
217
+			),
218
+			EEM_Message::status_failed                  => array(
219
+				__('failed', 'event_espresso'),
220
+				__('failed', 'event_espresso'),
221
+			),
222
+			EEM_Message::status_debug_only              => array(
223
+				__('debug only', 'event_espresso'),
224
+				__('debug only', 'event_espresso'),
225
+			),
226
+			EEM_Message::status_messenger_executing     => array(
227
+				__('messenger is executing', 'event_espresso'),
228
+				__('messenger is executing', 'event_espresso'),
229
+			),
230
+			EEM_Message::status_resend                  => array(
231
+				__('queued for resending', 'event_espresso'),
232
+				__('queued for resending', 'event_espresso'),
233
+			),
234
+			EEM_Message::status_incomplete              => array(
235
+				__('queued for generating', 'event_espresso'),
236
+				__('queued for generating', 'event_espresso'),
237
+			),
238
+			EEM_Message::status_retry                   => array(
239
+				__('failed sending, can be retried', 'event_espresso'),
240
+				__('failed sending, can be retried', 'event_espresso'),
241
+			),
242
+			EEM_CPT_Base::post_status_publish           => array(
243
+				__('published', 'event_espresso'),
244
+				__('published', 'event_espresso'),
245
+			),
246
+			EEM_CPT_Base::post_status_future            => array(
247
+				__('scheduled', 'event_espresso'),
248
+				__('scheduled', 'event_espresso'),
249
+			),
250
+			EEM_CPT_Base::post_status_draft             => array(
251
+				__('draft', 'event_espresso'),
252
+				__('draft', 'event_espresso'),
253
+			),
254
+			EEM_CPT_Base::post_status_pending           => array(
255
+				__('pending', 'event_espresso'),
256
+				__('pending', 'event_espresso'),
257
+			),
258
+			EEM_CPT_Base::post_status_private           => array(
259
+				__('private', 'event_espresso'),
260
+				__('private', 'event_espresso'),
261
+			),
262
+			EEM_CPT_Base::post_status_trashed           => array(
263
+				__('trashed', 'event_espresso'),
264
+				__('trashed', 'event_espresso'),
265
+			),
266
+		);
267 267
 
268
-        $translation_array = apply_filters('FHEE__EEM_Status__localized_status__translation_array', $translation_array);
268
+		$translation_array = apply_filters('FHEE__EEM_Status__localized_status__translation_array', $translation_array);
269 269
 
270
-        if (! is_array($statuses)) {
271
-            throw new EE_Error(__(
272
-                'The incoming statuses argument must be an array with keys as the $status_id and values as the $status_code',
273
-                'event_espresso'
274
-            ));
275
-        }
270
+		if (! is_array($statuses)) {
271
+			throw new EE_Error(__(
272
+				'The incoming statuses argument must be an array with keys as the $status_id and values as the $status_code',
273
+				'event_espresso'
274
+			));
275
+		}
276 276
 
277
-        $translation = array();
277
+		$translation = array();
278 278
 
279
-        foreach ($statuses as $id => $code) {
280
-            if (isset($translation_array[ $id ])) {
281
-                $translation[ $id ] = $plural ? $translation_array[ $id ][1] : $translation_array[ $id ][0];
282
-            } else {
283
-                $translation[ $id ] = $code;
284
-            }
279
+		foreach ($statuses as $id => $code) {
280
+			if (isset($translation_array[ $id ])) {
281
+				$translation[ $id ] = $plural ? $translation_array[ $id ][1] : $translation_array[ $id ][0];
282
+			} else {
283
+				$translation[ $id ] = $code;
284
+			}
285 285
 
286
-            // schema
287
-            switch ($schema) {
288
-                case 'lower':
289
-                    $translation[ $id ] = strtolower($translation[ $id ]); // even though these start in lower case, this will catch any statuses added via filter.
290
-                    break;
291
-                case 'sentence':
292
-                    $translation[ $id ] = ucwords($translation[ $id ]);
293
-                    break;
294
-                case 'upper':
295
-                    $translation[ $id ] = strtoupper($translation[ $id ]);
296
-                    break;
297
-            }
298
-        }
286
+			// schema
287
+			switch ($schema) {
288
+				case 'lower':
289
+					$translation[ $id ] = strtolower($translation[ $id ]); // even though these start in lower case, this will catch any statuses added via filter.
290
+					break;
291
+				case 'sentence':
292
+					$translation[ $id ] = ucwords($translation[ $id ]);
293
+					break;
294
+				case 'upper':
295
+					$translation[ $id ] = strtoupper($translation[ $id ]);
296
+					break;
297
+			}
298
+		}
299 299
 
300
-        return $translation;
301
-    }
300
+		return $translation;
301
+	}
302 302
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
                     false,
36 36
                     'event',
37 37
                     array(
38
-                        'event'        => __("Event", "event_espresso"),// deprecated
38
+                        'event'        => __("Event", "event_espresso"), // deprecated
39 39
                         'registration' => __("Registration", "event_espresso"),
40 40
                         'transaction'  => __("Transaction", "event_espresso"),
41 41
                         'payment'      => __("Payment", "event_espresso"),
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
             'Payment'      => new EE_Has_Many_Relation(),
55 55
         );
56 56
         // this model is generally available for reading
57
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
57
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
58 58
 
59 59
         parent::__construct($timezone);
60 60
     }
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 
268 268
         $translation_array = apply_filters('FHEE__EEM_Status__localized_status__translation_array', $translation_array);
269 269
 
270
-        if (! is_array($statuses)) {
270
+        if ( ! is_array($statuses)) {
271 271
             throw new EE_Error(__(
272 272
                 'The incoming statuses argument must be an array with keys as the $status_id and values as the $status_code',
273 273
                 'event_espresso'
@@ -277,22 +277,22 @@  discard block
 block discarded – undo
277 277
         $translation = array();
278 278
 
279 279
         foreach ($statuses as $id => $code) {
280
-            if (isset($translation_array[ $id ])) {
281
-                $translation[ $id ] = $plural ? $translation_array[ $id ][1] : $translation_array[ $id ][0];
280
+            if (isset($translation_array[$id])) {
281
+                $translation[$id] = $plural ? $translation_array[$id][1] : $translation_array[$id][0];
282 282
             } else {
283
-                $translation[ $id ] = $code;
283
+                $translation[$id] = $code;
284 284
             }
285 285
 
286 286
             // schema
287 287
             switch ($schema) {
288 288
                 case 'lower':
289
-                    $translation[ $id ] = strtolower($translation[ $id ]); // even though these start in lower case, this will catch any statuses added via filter.
289
+                    $translation[$id] = strtolower($translation[$id]); // even though these start in lower case, this will catch any statuses added via filter.
290 290
                     break;
291 291
                 case 'sentence':
292
-                    $translation[ $id ] = ucwords($translation[ $id ]);
292
+                    $translation[$id] = ucwords($translation[$id]);
293 293
                     break;
294 294
                 case 'upper':
295
-                    $translation[ $id ] = strtoupper($translation[ $id ]);
295
+                    $translation[$id] = strtoupper($translation[$id]);
296 296
                     break;
297 297
             }
298 298
         }
Please login to merge, or discard this patch.