Completed
Branch FET/asset-manager (433489)
by
unknown
32:42 queued 18:11
created
core/db_models/relations/EE_Belongs_To_Any_Relation.php 2 patches
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -18,83 +18,83 @@
 block discarded – undo
18 18
 {
19 19
 
20 20
 
21
-    /**
22
-     * get_join_statement
23
-     *
24
-     * @param string $model_relation_chain
25
-     * @return string
26
-     * @throws \EE_Error
27
-     */
28
-    public function get_join_statement($model_relation_chain)
29
-    {
30
-        //create the sql string like
31
-        $this_table_fk_field = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
32
-        //ALSO, need to get the field with the model name
33
-        $field_with_model_name = $this->get_this_model()->get_field_containing_related_model_name();
21
+	/**
22
+	 * get_join_statement
23
+	 *
24
+	 * @param string $model_relation_chain
25
+	 * @return string
26
+	 * @throws \EE_Error
27
+	 */
28
+	public function get_join_statement($model_relation_chain)
29
+	{
30
+		//create the sql string like
31
+		$this_table_fk_field = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
32
+		//ALSO, need to get the field with the model name
33
+		$field_with_model_name = $this->get_this_model()->get_field_containing_related_model_name();
34 34
 
35 35
 
36
-        $other_table_pk_field = $this->get_other_model()->get_primary_key_field();
37
-        $this_table_alias     = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain,
38
-                $this->get_this_model()->get_this_model_name()) . $this_table_fk_field->get_table_alias();
39
-        $other_table_alias    = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain,
40
-                $this->get_other_model()->get_this_model_name()) . $other_table_pk_field->get_table_alias();
41
-        $other_table          = $this->get_other_model()->get_table_for_alias($other_table_alias);
42
-        return $this->_left_join($other_table,
43
-                $other_table_alias,
44
-                $other_table_pk_field->get_table_column(),
45
-                $this_table_alias,
46
-                $this_table_fk_field->get_table_column(),
47
-                $field_with_model_name->get_qualified_column() . "='" . $this->get_other_model()->get_this_model_name() . "'")
48
-               . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
49
-    }
36
+		$other_table_pk_field = $this->get_other_model()->get_primary_key_field();
37
+		$this_table_alias     = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain,
38
+				$this->get_this_model()->get_this_model_name()) . $this_table_fk_field->get_table_alias();
39
+		$other_table_alias    = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain,
40
+				$this->get_other_model()->get_this_model_name()) . $other_table_pk_field->get_table_alias();
41
+		$other_table          = $this->get_other_model()->get_table_for_alias($other_table_alias);
42
+		return $this->_left_join($other_table,
43
+				$other_table_alias,
44
+				$other_table_pk_field->get_table_column(),
45
+				$this_table_alias,
46
+				$this_table_fk_field->get_table_column(),
47
+				$field_with_model_name->get_qualified_column() . "='" . $this->get_other_model()->get_this_model_name() . "'")
48
+			   . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
49
+	}
50 50
 
51 51
 
52
-    /**
53
-     * Sets this model object's foreign key to the other model object's primary key. Feel free to do this manually if
54
-     * you like.
55
-     *
56
-     * @param EE_Base_Class|int $this_obj_or_id
57
-     * @param EE_Base_Class|int $other_obj_or_id
58
-     * @param array             $extra_join_model_fields_n_values
59
-     * @return \EE_Base_Class
60
-     * @throws \EE_Error
61
-     */
62
-    public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
63
-    {
64
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
65
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
66
-        //find the field on THIS model which a foreign key to the other model
67
-        $fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
68
-        //set that field on the other model to this model's ID
69
-        $this_model_obj->set($fk_on_this_model->get_name(), $other_model_obj->ID());
70
-        //and make sure this model's field with the foreign model name is set to the correct value
71
-        $this_model_obj->set($this->get_this_model()->get_field_containing_related_model_name()->get_name(),
72
-            $this->get_other_model()->get_this_model_name());
73
-        $this_model_obj->save();
74
-        return $other_model_obj;
75
-    }
52
+	/**
53
+	 * Sets this model object's foreign key to the other model object's primary key. Feel free to do this manually if
54
+	 * you like.
55
+	 *
56
+	 * @param EE_Base_Class|int $this_obj_or_id
57
+	 * @param EE_Base_Class|int $other_obj_or_id
58
+	 * @param array             $extra_join_model_fields_n_values
59
+	 * @return \EE_Base_Class
60
+	 * @throws \EE_Error
61
+	 */
62
+	public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
63
+	{
64
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
65
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
66
+		//find the field on THIS model which a foreign key to the other model
67
+		$fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
68
+		//set that field on the other model to this model's ID
69
+		$this_model_obj->set($fk_on_this_model->get_name(), $other_model_obj->ID());
70
+		//and make sure this model's field with the foreign model name is set to the correct value
71
+		$this_model_obj->set($this->get_this_model()->get_field_containing_related_model_name()->get_name(),
72
+			$this->get_other_model()->get_this_model_name());
73
+		$this_model_obj->save();
74
+		return $other_model_obj;
75
+	}
76 76
 
77 77
 
78
-    /**
79
-     * Sets the this model object's foreign key to its default, instead of pointing to the other model object
80
-     *
81
-     * @param EE_Base_Class|int $this_obj_or_id
82
-     * @param EE_Base_Class|int $other_obj_or_id
83
-     * @param array             $where_query
84
-     * @return \EE_Base_Class
85
-     * @throws \EE_Error
86
-     */
87
-    public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
88
-    {
89
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
90
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id);
91
-        //find the field on the other model which is a foreign key to this model
92
-        $fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
93
-        //set that field on the other model to this model's ID
94
-        $this_model_obj->set($fk_on_this_model->get_name(), null, true);
95
-        $this_model_obj->set($this->get_this_model()->get_field_containing_related_model_name()->get_name(), null,
96
-            true);
97
-        $this_model_obj->save();
98
-        return $other_model_obj;
99
-    }
78
+	/**
79
+	 * Sets the this model object's foreign key to its default, instead of pointing to the other model object
80
+	 *
81
+	 * @param EE_Base_Class|int $this_obj_or_id
82
+	 * @param EE_Base_Class|int $other_obj_or_id
83
+	 * @param array             $where_query
84
+	 * @return \EE_Base_Class
85
+	 * @throws \EE_Error
86
+	 */
87
+	public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
88
+	{
89
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
90
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id);
91
+		//find the field on the other model which is a foreign key to this model
92
+		$fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
93
+		//set that field on the other model to this model's ID
94
+		$this_model_obj->set($fk_on_this_model->get_name(), null, true);
95
+		$this_model_obj->set($this->get_this_model()->get_field_containing_related_model_name()->get_name(), null,
96
+			true);
97
+		$this_model_obj->save();
98
+		return $other_model_obj;
99
+	}
100 100
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-require_once(EE_MODELS . 'relations/EE_Belongs_To_Relation.php');
2
+require_once(EE_MODELS.'relations/EE_Belongs_To_Relation.php');
3 3
 
4 4
 
5 5
 /**
@@ -35,16 +35,16 @@  discard block
 block discarded – undo
35 35
 
36 36
         $other_table_pk_field = $this->get_other_model()->get_primary_key_field();
37 37
         $this_table_alias     = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain,
38
-                $this->get_this_model()->get_this_model_name()) . $this_table_fk_field->get_table_alias();
38
+                $this->get_this_model()->get_this_model_name()).$this_table_fk_field->get_table_alias();
39 39
         $other_table_alias    = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain,
40
-                $this->get_other_model()->get_this_model_name()) . $other_table_pk_field->get_table_alias();
40
+                $this->get_other_model()->get_this_model_name()).$other_table_pk_field->get_table_alias();
41 41
         $other_table          = $this->get_other_model()->get_table_for_alias($other_table_alias);
42 42
         return $this->_left_join($other_table,
43 43
                 $other_table_alias,
44 44
                 $other_table_pk_field->get_table_column(),
45 45
                 $this_table_alias,
46 46
                 $this_table_fk_field->get_table_column(),
47
-                $field_with_model_name->get_qualified_column() . "='" . $this->get_other_model()->get_this_model_name() . "'")
47
+                $field_with_model_name->get_qualified_column()."='".$this->get_other_model()->get_this_model_name()."'")
48 48
                . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
49 49
     }
50 50
 
Please login to merge, or discard this patch.
core/db_models/relations/EE_HABTM_Relation.php 2 patches
Indentation   +199 added lines, -199 removed lines patch added patch discarded remove patch
@@ -12,203 +12,203 @@
 block discarded – undo
12 12
  */
13 13
 class EE_HABTM_Relation extends EE_Model_Relation_Base
14 14
 {
15
-    /**
16
-     * Model which defines the relation between two other models. Eg, the EE_Event_Question_Group model,
17
-     * which joins EE_Event and EE_Question_Group
18
-     *
19
-     * @var EEM_Base
20
-     */
21
-    protected $_joining_model_name;
22
-
23
-    protected $_model_relation_chain_to_join_model;
24
-
25
-
26
-    /**
27
-     * Object representing the relationship between two models. HasAndBelongsToMany relations always use a join-table
28
-     * (and an ee joining-model.) This knows how to join the models,
29
-     * get related models across the relation, and add-and-remove the relationships.
30
-     *
31
-     * @param bool    $joining_model_name
32
-     * @param boolean $block_deletes                 for this type of relation, we block by default for now. if there
33
-     *                                               are related models across this relation, block (prevent and add an
34
-     *                                               error) the deletion of this model
35
-     * @param string  $blocking_delete_error_message a customized error message on blocking deletes instead of the
36
-     *                                               default
37
-     */
38
-    public function __construct($joining_model_name, $block_deletes = true, $blocking_delete_error_message = '')
39
-    {
40
-        $this->_joining_model_name = $joining_model_name;
41
-        parent::__construct($block_deletes, $blocking_delete_error_message);
42
-    }
43
-
44
-    /**
45
-     * Gets the joining model's object
46
-     *
47
-     * @return EEM_Base
48
-     */
49
-    public function get_join_model()
50
-    {
51
-        return $this->_get_model($this->_joining_model_name);
52
-    }
53
-
54
-
55
-    /**
56
-     * Gets the SQL string for joining the main model's table containing the pk to the join table. Eg "LEFT JOIN
57
-     * real_join_table AS join_table_alias ON this_table_alias.pk = join_table_alias.fk_to_this_table"
58
-     *
59
-     * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
60
-     * @return string of SQL
61
-     * @throws \EE_Error
62
-     */
63
-    public function get_join_to_intermediate_model_statement($model_relation_chain)
64
-    {
65
-        //create sql like
66
-        //LEFT JOIN join_table AS join_table_alias ON this_table_alias.this_table_pk = join_table_alias.join_table_fk_to_this
67
-        //LEFT JOIN other_table AS other_table_alias ON join_table_alias.join_table_fk_to_other = other_table_alias.other_table_pk
68
-        //remember the model relation chain to the JOIN model, because we'll
69
-        //need it for get_join_statement()
70
-        $this->_model_relation_chain_to_join_model = $model_relation_chain;
71
-        $this_table_pk_field                       = $this->get_this_model()->get_primary_key_field();//get_foreign_key_to($this->get_other_model()->get_this_model_name());
72
-        $join_table_fk_field_to_this_table         = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
73
-        $this_table_alias                          = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain,
74
-                $this->get_this_model()->get_this_model_name()) . $this_table_pk_field->get_table_alias();
75
-
76
-        $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain,
77
-                $this->get_join_model()->get_this_model_name()) . $join_table_fk_field_to_this_table->get_table_alias();
78
-        $join_table       = $this->get_join_model()->get_table_for_alias($join_table_alias);
79
-        //phew! ok, we have all the info we need, now we can create the SQL join string
80
-        $SQL = $this->_left_join($join_table, $join_table_alias, $join_table_fk_field_to_this_table->get_table_column(),
81
-                $this_table_alias,
82
-                $this_table_pk_field->get_table_column()) . $this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias);
83
-
84
-        return $SQL;
85
-    }
86
-
87
-
88
-    /**
89
-     * Gets the SQL string for joining the join table to the other model's pk's table. Eg "LEFT JOIN real_other_table
90
-     * AS other_table_alias ON join_table_alias.fk_to_other_table = other_table_alias.pk" If you want to join between
91
-     * modelA -> joinModelAB -> modelB (eg, Event -> Event_Question_Group -> Question_Group), you should prepend the
92
-     * result of this function with results from get_join_to_intermediate_model_statement(), so that you join first to
93
-     * the intermediate join table, and then to the other model's pk's table
94
-     *
95
-     * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
96
-     * @return string of SQL
97
-     * @throws \EE_Error
98
-     */
99
-    public function get_join_statement($model_relation_chain)
100
-    {
101
-        if ($this->_model_relation_chain_to_join_model === null) {
102
-            throw new EE_Error(sprintf(__('When using EE_HABTM_Relation to create a join, you must call get_join_to_intermediate_model_statement BEFORE get_join_statement',
103
-                'event_espresso')));
104
-        }
105
-        $join_table_fk_field_to_this_table  = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
106
-        $join_table_alias                   = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($this->_model_relation_chain_to_join_model,
107
-                $this->get_join_model()->get_this_model_name()) . $join_table_fk_field_to_this_table->get_table_alias();
108
-        $other_table_pk_field               = $this->get_other_model()->get_primary_key_field();
109
-        $join_table_fk_field_to_other_table = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
110
-        $other_table_alias                  = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain,
111
-                $this->get_other_model()->get_this_model_name()) . $other_table_pk_field->get_table_alias();
112
-        $other_table                        = $this->get_other_model()->get_table_for_alias($other_table_alias);
113
-
114
-        $SQL = $this->_left_join($other_table, $other_table_alias, $other_table_pk_field->get_table_column(),
115
-                $join_table_alias,
116
-                $join_table_fk_field_to_other_table->get_table_column()) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
117
-        return $SQL;
118
-    }
119
-
120
-
121
-    /**
122
-     * Ensures there is an entry in the join table between these two models. Feel free to do this manually if you like.
123
-     * If the join table has additional columns (eg, the Event_Question_Group table has a is_primary column), then
124
-     * you'll want to directly use the EEM_Event_Question_Group model to add the entry to the table and set those extra
125
-     * columns' values
126
-     *
127
-     * @param EE_Base_Class|int $this_obj_or_id
128
-     * @param EE_Base_Class|int $other_obj_or_id
129
-     * @param array             $extra_join_model_fields_n_values col=>val pairs that are used as extra conditions for
130
-     *                                                            checking existing values and for setting new rows if
131
-     *                                                            no exact matches.
132
-     * @return EE_Base_Class
133
-     * @throws \EE_Error
134
-     */
135
-    public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
136
-    {
137
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
138
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
139
-        //check if such a relationship already exists
140
-        $join_model_fk_to_this_model  = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
141
-        $join_model_fk_to_other_model = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
142
-
143
-        $cols_n_values = array(
144
-            $join_model_fk_to_this_model->get_name()  => $this_model_obj->ID(),
145
-            $join_model_fk_to_other_model->get_name() => $other_model_obj->ID(),
146
-        );
147
-
148
-        //if $where_query exists lets add them to the query_params.
149
-        if (! empty($extra_join_model_fields_n_values)) {
150
-            //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)
151
-            //make sure we strip THIS models name from the query param
152
-            $parsed_query = array();
153
-            foreach ($extra_join_model_fields_n_values as $query_param => $val) {
154
-                $query_param                = str_replace($this->get_join_model()->get_this_model_name() . ".", "",
155
-                    $query_param);
156
-                $parsed_query[$query_param] = $val;
157
-            }
158
-            $cols_n_values = array_merge($cols_n_values, $parsed_query);
159
-        }
160
-
161
-        $query_params = array($cols_n_values);
162
-
163
-
164
-        $existing_entry_in_join_table = $this->get_join_model()->get_one($query_params);
165
-        //if there is already an entry in the join table, indicating a relationship, we're done
166
-        //again, if you want more sophisticated logic or insertions (handling more columns than just 2 foreign keys to
167
-        //the other tables, use the joining model directly!
168
-        if (! $existing_entry_in_join_table) {
169
-            $this->get_join_model()->insert($cols_n_values);
170
-        }
171
-        return $other_model_obj;
172
-    }
173
-
174
-
175
-    /**
176
-     * Deletes any rows in the join table that have foreign keys matching the other model objects specified
177
-     *
178
-     * @param EE_Base_Class|int $this_obj_or_id
179
-     * @param EE_Base_Class|int $other_obj_or_id
180
-     * @param array             $where_query col=>val pairs that are used as extra conditions for checking existing
181
-     *                                       values and for removing existing rows if exact matches exist.
182
-     * @return EE_Base_Class
183
-     * @throws \EE_Error
184
-     */
185
-    public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
186
-    {
187
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
188
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
189
-        //check if such a relationship already exists
190
-        $join_model_fk_to_this_model  = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
191
-        $join_model_fk_to_other_model = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
192
-
193
-        $cols_n_values = array(
194
-            $join_model_fk_to_this_model->get_name()  => $this_model_obj->ID(),
195
-            $join_model_fk_to_other_model->get_name() => $other_model_obj->ID(),
196
-        );
197
-
198
-        //if $where_query exists lets add them to the query_params.
199
-        if (! empty($where_query)) {
200
-            //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)
201
-            //make sure we strip THIS models name from the query param
202
-            $parsed_query = array();
203
-            foreach ($where_query as $query_param => $val) {
204
-                $query_param                = str_replace($this->get_join_model()->get_this_model_name() . ".", "",
205
-                    $query_param);
206
-                $parsed_query[$query_param] = $val;
207
-            }
208
-            $cols_n_values = array_merge($cols_n_values, $parsed_query);
209
-        }
210
-
211
-        $this->get_join_model()->delete(array($cols_n_values));
212
-        return $other_model_obj;
213
-    }
15
+	/**
16
+	 * Model which defines the relation between two other models. Eg, the EE_Event_Question_Group model,
17
+	 * which joins EE_Event and EE_Question_Group
18
+	 *
19
+	 * @var EEM_Base
20
+	 */
21
+	protected $_joining_model_name;
22
+
23
+	protected $_model_relation_chain_to_join_model;
24
+
25
+
26
+	/**
27
+	 * Object representing the relationship between two models. HasAndBelongsToMany relations always use a join-table
28
+	 * (and an ee joining-model.) This knows how to join the models,
29
+	 * get related models across the relation, and add-and-remove the relationships.
30
+	 *
31
+	 * @param bool    $joining_model_name
32
+	 * @param boolean $block_deletes                 for this type of relation, we block by default for now. if there
33
+	 *                                               are related models across this relation, block (prevent and add an
34
+	 *                                               error) the deletion of this model
35
+	 * @param string  $blocking_delete_error_message a customized error message on blocking deletes instead of the
36
+	 *                                               default
37
+	 */
38
+	public function __construct($joining_model_name, $block_deletes = true, $blocking_delete_error_message = '')
39
+	{
40
+		$this->_joining_model_name = $joining_model_name;
41
+		parent::__construct($block_deletes, $blocking_delete_error_message);
42
+	}
43
+
44
+	/**
45
+	 * Gets the joining model's object
46
+	 *
47
+	 * @return EEM_Base
48
+	 */
49
+	public function get_join_model()
50
+	{
51
+		return $this->_get_model($this->_joining_model_name);
52
+	}
53
+
54
+
55
+	/**
56
+	 * Gets the SQL string for joining the main model's table containing the pk to the join table. Eg "LEFT JOIN
57
+	 * real_join_table AS join_table_alias ON this_table_alias.pk = join_table_alias.fk_to_this_table"
58
+	 *
59
+	 * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
60
+	 * @return string of SQL
61
+	 * @throws \EE_Error
62
+	 */
63
+	public function get_join_to_intermediate_model_statement($model_relation_chain)
64
+	{
65
+		//create sql like
66
+		//LEFT JOIN join_table AS join_table_alias ON this_table_alias.this_table_pk = join_table_alias.join_table_fk_to_this
67
+		//LEFT JOIN other_table AS other_table_alias ON join_table_alias.join_table_fk_to_other = other_table_alias.other_table_pk
68
+		//remember the model relation chain to the JOIN model, because we'll
69
+		//need it for get_join_statement()
70
+		$this->_model_relation_chain_to_join_model = $model_relation_chain;
71
+		$this_table_pk_field                       = $this->get_this_model()->get_primary_key_field();//get_foreign_key_to($this->get_other_model()->get_this_model_name());
72
+		$join_table_fk_field_to_this_table         = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
73
+		$this_table_alias                          = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain,
74
+				$this->get_this_model()->get_this_model_name()) . $this_table_pk_field->get_table_alias();
75
+
76
+		$join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain,
77
+				$this->get_join_model()->get_this_model_name()) . $join_table_fk_field_to_this_table->get_table_alias();
78
+		$join_table       = $this->get_join_model()->get_table_for_alias($join_table_alias);
79
+		//phew! ok, we have all the info we need, now we can create the SQL join string
80
+		$SQL = $this->_left_join($join_table, $join_table_alias, $join_table_fk_field_to_this_table->get_table_column(),
81
+				$this_table_alias,
82
+				$this_table_pk_field->get_table_column()) . $this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias);
83
+
84
+		return $SQL;
85
+	}
86
+
87
+
88
+	/**
89
+	 * Gets the SQL string for joining the join table to the other model's pk's table. Eg "LEFT JOIN real_other_table
90
+	 * AS other_table_alias ON join_table_alias.fk_to_other_table = other_table_alias.pk" If you want to join between
91
+	 * modelA -> joinModelAB -> modelB (eg, Event -> Event_Question_Group -> Question_Group), you should prepend the
92
+	 * result of this function with results from get_join_to_intermediate_model_statement(), so that you join first to
93
+	 * the intermediate join table, and then to the other model's pk's table
94
+	 *
95
+	 * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
96
+	 * @return string of SQL
97
+	 * @throws \EE_Error
98
+	 */
99
+	public function get_join_statement($model_relation_chain)
100
+	{
101
+		if ($this->_model_relation_chain_to_join_model === null) {
102
+			throw new EE_Error(sprintf(__('When using EE_HABTM_Relation to create a join, you must call get_join_to_intermediate_model_statement BEFORE get_join_statement',
103
+				'event_espresso')));
104
+		}
105
+		$join_table_fk_field_to_this_table  = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
106
+		$join_table_alias                   = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($this->_model_relation_chain_to_join_model,
107
+				$this->get_join_model()->get_this_model_name()) . $join_table_fk_field_to_this_table->get_table_alias();
108
+		$other_table_pk_field               = $this->get_other_model()->get_primary_key_field();
109
+		$join_table_fk_field_to_other_table = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
110
+		$other_table_alias                  = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain,
111
+				$this->get_other_model()->get_this_model_name()) . $other_table_pk_field->get_table_alias();
112
+		$other_table                        = $this->get_other_model()->get_table_for_alias($other_table_alias);
113
+
114
+		$SQL = $this->_left_join($other_table, $other_table_alias, $other_table_pk_field->get_table_column(),
115
+				$join_table_alias,
116
+				$join_table_fk_field_to_other_table->get_table_column()) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
117
+		return $SQL;
118
+	}
119
+
120
+
121
+	/**
122
+	 * Ensures there is an entry in the join table between these two models. Feel free to do this manually if you like.
123
+	 * If the join table has additional columns (eg, the Event_Question_Group table has a is_primary column), then
124
+	 * you'll want to directly use the EEM_Event_Question_Group model to add the entry to the table and set those extra
125
+	 * columns' values
126
+	 *
127
+	 * @param EE_Base_Class|int $this_obj_or_id
128
+	 * @param EE_Base_Class|int $other_obj_or_id
129
+	 * @param array             $extra_join_model_fields_n_values col=>val pairs that are used as extra conditions for
130
+	 *                                                            checking existing values and for setting new rows if
131
+	 *                                                            no exact matches.
132
+	 * @return EE_Base_Class
133
+	 * @throws \EE_Error
134
+	 */
135
+	public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
136
+	{
137
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
138
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
139
+		//check if such a relationship already exists
140
+		$join_model_fk_to_this_model  = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
141
+		$join_model_fk_to_other_model = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
142
+
143
+		$cols_n_values = array(
144
+			$join_model_fk_to_this_model->get_name()  => $this_model_obj->ID(),
145
+			$join_model_fk_to_other_model->get_name() => $other_model_obj->ID(),
146
+		);
147
+
148
+		//if $where_query exists lets add them to the query_params.
149
+		if (! empty($extra_join_model_fields_n_values)) {
150
+			//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)
151
+			//make sure we strip THIS models name from the query param
152
+			$parsed_query = array();
153
+			foreach ($extra_join_model_fields_n_values as $query_param => $val) {
154
+				$query_param                = str_replace($this->get_join_model()->get_this_model_name() . ".", "",
155
+					$query_param);
156
+				$parsed_query[$query_param] = $val;
157
+			}
158
+			$cols_n_values = array_merge($cols_n_values, $parsed_query);
159
+		}
160
+
161
+		$query_params = array($cols_n_values);
162
+
163
+
164
+		$existing_entry_in_join_table = $this->get_join_model()->get_one($query_params);
165
+		//if there is already an entry in the join table, indicating a relationship, we're done
166
+		//again, if you want more sophisticated logic or insertions (handling more columns than just 2 foreign keys to
167
+		//the other tables, use the joining model directly!
168
+		if (! $existing_entry_in_join_table) {
169
+			$this->get_join_model()->insert($cols_n_values);
170
+		}
171
+		return $other_model_obj;
172
+	}
173
+
174
+
175
+	/**
176
+	 * Deletes any rows in the join table that have foreign keys matching the other model objects specified
177
+	 *
178
+	 * @param EE_Base_Class|int $this_obj_or_id
179
+	 * @param EE_Base_Class|int $other_obj_or_id
180
+	 * @param array             $where_query col=>val pairs that are used as extra conditions for checking existing
181
+	 *                                       values and for removing existing rows if exact matches exist.
182
+	 * @return EE_Base_Class
183
+	 * @throws \EE_Error
184
+	 */
185
+	public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
186
+	{
187
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
188
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
189
+		//check if such a relationship already exists
190
+		$join_model_fk_to_this_model  = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
191
+		$join_model_fk_to_other_model = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
192
+
193
+		$cols_n_values = array(
194
+			$join_model_fk_to_this_model->get_name()  => $this_model_obj->ID(),
195
+			$join_model_fk_to_other_model->get_name() => $other_model_obj->ID(),
196
+		);
197
+
198
+		//if $where_query exists lets add them to the query_params.
199
+		if (! empty($where_query)) {
200
+			//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)
201
+			//make sure we strip THIS models name from the query param
202
+			$parsed_query = array();
203
+			foreach ($where_query as $query_param => $val) {
204
+				$query_param                = str_replace($this->get_join_model()->get_this_model_name() . ".", "",
205
+					$query_param);
206
+				$parsed_query[$query_param] = $val;
207
+			}
208
+			$cols_n_values = array_merge($cols_n_values, $parsed_query);
209
+		}
210
+
211
+		$this->get_join_model()->delete(array($cols_n_values));
212
+		return $other_model_obj;
213
+	}
214 214
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-require_once(EE_MODELS . 'relations/EE_Model_Relation_Base.php');
3
+require_once(EE_MODELS.'relations/EE_Model_Relation_Base.php');
4 4
 
5 5
 
6 6
 /**
@@ -68,18 +68,18 @@  discard block
 block discarded – undo
68 68
         //remember the model relation chain to the JOIN model, because we'll
69 69
         //need it for get_join_statement()
70 70
         $this->_model_relation_chain_to_join_model = $model_relation_chain;
71
-        $this_table_pk_field                       = $this->get_this_model()->get_primary_key_field();//get_foreign_key_to($this->get_other_model()->get_this_model_name());
71
+        $this_table_pk_field                       = $this->get_this_model()->get_primary_key_field(); //get_foreign_key_to($this->get_other_model()->get_this_model_name());
72 72
         $join_table_fk_field_to_this_table         = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
73 73
         $this_table_alias                          = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain,
74
-                $this->get_this_model()->get_this_model_name()) . $this_table_pk_field->get_table_alias();
74
+                $this->get_this_model()->get_this_model_name()).$this_table_pk_field->get_table_alias();
75 75
 
76 76
         $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain,
77
-                $this->get_join_model()->get_this_model_name()) . $join_table_fk_field_to_this_table->get_table_alias();
77
+                $this->get_join_model()->get_this_model_name()).$join_table_fk_field_to_this_table->get_table_alias();
78 78
         $join_table       = $this->get_join_model()->get_table_for_alias($join_table_alias);
79 79
         //phew! ok, we have all the info we need, now we can create the SQL join string
80 80
         $SQL = $this->_left_join($join_table, $join_table_alias, $join_table_fk_field_to_this_table->get_table_column(),
81 81
                 $this_table_alias,
82
-                $this_table_pk_field->get_table_column()) . $this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias);
82
+                $this_table_pk_field->get_table_column()).$this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias);
83 83
 
84 84
         return $SQL;
85 85
     }
@@ -104,16 +104,16 @@  discard block
 block discarded – undo
104 104
         }
105 105
         $join_table_fk_field_to_this_table  = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
106 106
         $join_table_alias                   = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($this->_model_relation_chain_to_join_model,
107
-                $this->get_join_model()->get_this_model_name()) . $join_table_fk_field_to_this_table->get_table_alias();
107
+                $this->get_join_model()->get_this_model_name()).$join_table_fk_field_to_this_table->get_table_alias();
108 108
         $other_table_pk_field               = $this->get_other_model()->get_primary_key_field();
109 109
         $join_table_fk_field_to_other_table = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
110 110
         $other_table_alias                  = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain,
111
-                $this->get_other_model()->get_this_model_name()) . $other_table_pk_field->get_table_alias();
111
+                $this->get_other_model()->get_this_model_name()).$other_table_pk_field->get_table_alias();
112 112
         $other_table                        = $this->get_other_model()->get_table_for_alias($other_table_alias);
113 113
 
114 114
         $SQL = $this->_left_join($other_table, $other_table_alias, $other_table_pk_field->get_table_column(),
115 115
                 $join_table_alias,
116
-                $join_table_fk_field_to_other_table->get_table_column()) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
116
+                $join_table_fk_field_to_other_table->get_table_column()).$this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
117 117
         return $SQL;
118 118
     }
119 119
 
@@ -146,12 +146,12 @@  discard block
 block discarded – undo
146 146
         );
147 147
 
148 148
         //if $where_query exists lets add them to the query_params.
149
-        if (! empty($extra_join_model_fields_n_values)) {
149
+        if ( ! empty($extra_join_model_fields_n_values)) {
150 150
             //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)
151 151
             //make sure we strip THIS models name from the query param
152 152
             $parsed_query = array();
153 153
             foreach ($extra_join_model_fields_n_values as $query_param => $val) {
154
-                $query_param                = str_replace($this->get_join_model()->get_this_model_name() . ".", "",
154
+                $query_param                = str_replace($this->get_join_model()->get_this_model_name().".", "",
155 155
                     $query_param);
156 156
                 $parsed_query[$query_param] = $val;
157 157
             }
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
         //if there is already an entry in the join table, indicating a relationship, we're done
166 166
         //again, if you want more sophisticated logic or insertions (handling more columns than just 2 foreign keys to
167 167
         //the other tables, use the joining model directly!
168
-        if (! $existing_entry_in_join_table) {
168
+        if ( ! $existing_entry_in_join_table) {
169 169
             $this->get_join_model()->insert($cols_n_values);
170 170
         }
171 171
         return $other_model_obj;
@@ -196,12 +196,12 @@  discard block
 block discarded – undo
196 196
         );
197 197
 
198 198
         //if $where_query exists lets add them to the query_params.
199
-        if (! empty($where_query)) {
199
+        if ( ! empty($where_query)) {
200 200
             //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)
201 201
             //make sure we strip THIS models name from the query param
202 202
             $parsed_query = array();
203 203
             foreach ($where_query as $query_param => $val) {
204
-                $query_param                = str_replace($this->get_join_model()->get_this_model_name() . ".", "",
204
+                $query_param                = str_replace($this->get_join_model()->get_this_model_name().".", "",
205 205
                     $query_param);
206 206
                 $parsed_query[$query_param] = $val;
207 207
             }
Please login to merge, or discard this patch.
core/db_models/relations/EE_Belongs_To_Relation.php 2 patches
Indentation   +113 added lines, -113 removed lines patch added patch discarded remove patch
@@ -13,128 +13,128 @@
 block discarded – undo
13 13
 class EE_Belongs_To_Relation extends EE_Model_Relation_Base
14 14
 {
15 15
 
16
-    /**
17
-     * Object representing the relationship between two models. Belongs_To means that THIS model has the foreign key
18
-     * to the other model. This knows how to join the models,
19
-     * get related models across the relation, and add-and-remove the relationships.
20
-     *
21
-     * @param boolean $block_deletes                                For Belongs_To relations, this is set to FALSE by
22
-     *                                                              default. if there are related models across this
23
-     *                                                              relation, block (prevent and add an error) the
24
-     *                                                              deletion of this model
25
-     * @param string  $related_model_objects_deletion_error_message a customized error message on blocking deletes
26
-     *                                                              instead of the default
27
-     */
28
-    public function __construct($block_deletes = false, $related_model_objects_deletion_error_message = null)
29
-    {
30
-        parent::__construct($block_deletes, $related_model_objects_deletion_error_message);
31
-    }
16
+	/**
17
+	 * Object representing the relationship between two models. Belongs_To means that THIS model has the foreign key
18
+	 * to the other model. This knows how to join the models,
19
+	 * get related models across the relation, and add-and-remove the relationships.
20
+	 *
21
+	 * @param boolean $block_deletes                                For Belongs_To relations, this is set to FALSE by
22
+	 *                                                              default. if there are related models across this
23
+	 *                                                              relation, block (prevent and add an error) the
24
+	 *                                                              deletion of this model
25
+	 * @param string  $related_model_objects_deletion_error_message a customized error message on blocking deletes
26
+	 *                                                              instead of the default
27
+	 */
28
+	public function __construct($block_deletes = false, $related_model_objects_deletion_error_message = null)
29
+	{
30
+		parent::__construct($block_deletes, $related_model_objects_deletion_error_message);
31
+	}
32 32
 
33 33
 
34
-    /**
35
-     * get_join_statement
36
-     *
37
-     * @param string $model_relation_chain
38
-     * @return string
39
-     * @throws \EE_Error
40
-     */
41
-    public function get_join_statement($model_relation_chain)
42
-    {
43
-        //create the sql string like
44
-        $this_table_fk_field  = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
45
-        $other_table_pk_field = $this->get_other_model()->get_primary_key_field();
46
-        $this_table_alias     = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain,
47
-                $this->get_this_model()->get_this_model_name()) . $this_table_fk_field->get_table_alias();
48
-        $other_table_alias    = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain,
49
-                $this->get_other_model()->get_this_model_name()) . $other_table_pk_field->get_table_alias();
50
-        $other_table          = $this->get_other_model()->get_table_for_alias($other_table_alias);
51
-        return $this->_left_join($other_table, $other_table_alias, $other_table_pk_field->get_table_column(),
52
-                $this_table_alias,
53
-                $this_table_fk_field->get_table_column()) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
54
-    }
34
+	/**
35
+	 * get_join_statement
36
+	 *
37
+	 * @param string $model_relation_chain
38
+	 * @return string
39
+	 * @throws \EE_Error
40
+	 */
41
+	public function get_join_statement($model_relation_chain)
42
+	{
43
+		//create the sql string like
44
+		$this_table_fk_field  = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
45
+		$other_table_pk_field = $this->get_other_model()->get_primary_key_field();
46
+		$this_table_alias     = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain,
47
+				$this->get_this_model()->get_this_model_name()) . $this_table_fk_field->get_table_alias();
48
+		$other_table_alias    = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain,
49
+				$this->get_other_model()->get_this_model_name()) . $other_table_pk_field->get_table_alias();
50
+		$other_table          = $this->get_other_model()->get_table_for_alias($other_table_alias);
51
+		return $this->_left_join($other_table, $other_table_alias, $other_table_pk_field->get_table_column(),
52
+				$this_table_alias,
53
+				$this_table_fk_field->get_table_column()) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
54
+	}
55 55
 
56 56
 
57
-    /**
58
-     * Sets this model object's foreign key to the other model object's primary key. Feel free to do this manually if
59
-     * you like.
60
-     *
61
-     * @param EE_Base_Class|int $this_obj_or_id
62
-     * @param EE_Base_Class|int $other_obj_or_id
63
-     * @param array             $extra_join_model_fields_n_values
64
-     * @return \EE_Base_Class
65
-     * @throws \EE_Error
66
-     */
67
-    public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
68
-    {
69
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
70
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
71
-        //find the field on the other model which is a foreign key to this model
72
-        $fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
73
-        if ($this_model_obj->get($fk_on_this_model->get_name()) != $other_model_obj->ID()) {
74
-            //set that field on the other model to this model's ID
75
-            $this_model_obj->set($fk_on_this_model->get_name(), $other_model_obj->ID());
76
-            $this_model_obj->save();
77
-        }
78
-        return $other_model_obj;
79
-    }
57
+	/**
58
+	 * Sets this model object's foreign key to the other model object's primary key. Feel free to do this manually if
59
+	 * you like.
60
+	 *
61
+	 * @param EE_Base_Class|int $this_obj_or_id
62
+	 * @param EE_Base_Class|int $other_obj_or_id
63
+	 * @param array             $extra_join_model_fields_n_values
64
+	 * @return \EE_Base_Class
65
+	 * @throws \EE_Error
66
+	 */
67
+	public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
68
+	{
69
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
70
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
71
+		//find the field on the other model which is a foreign key to this model
72
+		$fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
73
+		if ($this_model_obj->get($fk_on_this_model->get_name()) != $other_model_obj->ID()) {
74
+			//set that field on the other model to this model's ID
75
+			$this_model_obj->set($fk_on_this_model->get_name(), $other_model_obj->ID());
76
+			$this_model_obj->save();
77
+		}
78
+		return $other_model_obj;
79
+	}
80 80
 
81 81
 
82
-    /**
83
-     * Sets the this model object's foreign key to its default, instead of pointing to the other model object
84
-     *
85
-     * @param EE_Base_Class|int $this_obj_or_id
86
-     * @param EE_Base_Class|int $other_obj_or_id
87
-     * @param array             $where_query
88
-     * @return \EE_Base_Class
89
-     * @throws \EE_Error
90
-     */
91
-    public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
92
-    {
93
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
94
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id);
95
-        //find the field on the other model which is a foreign key to this model
96
-        $fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
97
-        //set that field on the other model to this model's ID
98
-        $this_model_obj->set($fk_on_this_model->get_name(), null, true);
99
-        $this_model_obj->save();
100
-        return $other_model_obj;
101
-    }
82
+	/**
83
+	 * Sets the this model object's foreign key to its default, instead of pointing to the other model object
84
+	 *
85
+	 * @param EE_Base_Class|int $this_obj_or_id
86
+	 * @param EE_Base_Class|int $other_obj_or_id
87
+	 * @param array             $where_query
88
+	 * @return \EE_Base_Class
89
+	 * @throws \EE_Error
90
+	 */
91
+	public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
92
+	{
93
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
94
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id);
95
+		//find the field on the other model which is a foreign key to this model
96
+		$fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
97
+		//set that field on the other model to this model's ID
98
+		$this_model_obj->set($fk_on_this_model->get_name(), null, true);
99
+		$this_model_obj->save();
100
+		return $other_model_obj;
101
+	}
102 102
 
103 103
 
104
-    /**
105
-     * Overrides parent so that we don't NEED to save the $model_object before getting the related objects.
106
-     *
107
-     * @param EE_Base_Class $model_obj_or_id
108
-     * @param array         $query_params                            like EEM_Base::get_all's $query_params
109
-     * @param boolean       $values_already_prepared_by_model_object @deprecated since 4.8.1
110
-     * @return EE_Base_Class[]
111
-     * @throws \EE_Error
112
-     */
113
-    public function get_all_related(
114
-        $model_obj_or_id,
115
-        $query_params = array(),
116
-        $values_already_prepared_by_model_object = false
117
-    ) {
118
-        if ($values_already_prepared_by_model_object !== false) {
119
-            EE_Error::doing_it_wrong('EE_Model_Relation_Base::get_all_related',
120
-                __('The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso'),
121
-                '4.8.1');
122
-        }
123
-        //get column on this model object which is a foreign key to the other model
124
-        $fk_field_obj = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
125
-        //get its value
126
-        if ($model_obj_or_id instanceof EE_Base_Class) {
127
-            $model_obj = $model_obj_or_id;
128
-        } else {
129
-            $model_obj = $this->get_this_model()->ensure_is_obj($model_obj_or_id);
130
-        }
131
-        $ID_value_on_other_model = $model_obj->get($fk_field_obj->get_name());
132
-        //get all where their PK matches that value
133
-        $query_params[0][$this->get_other_model()->get_primary_key_field()->get_name()] = $ID_value_on_other_model;
134
-        $query_params                                                                   = $this->_disable_default_where_conditions_on_query_param($query_params);
104
+	/**
105
+	 * Overrides parent so that we don't NEED to save the $model_object before getting the related objects.
106
+	 *
107
+	 * @param EE_Base_Class $model_obj_or_id
108
+	 * @param array         $query_params                            like EEM_Base::get_all's $query_params
109
+	 * @param boolean       $values_already_prepared_by_model_object @deprecated since 4.8.1
110
+	 * @return EE_Base_Class[]
111
+	 * @throws \EE_Error
112
+	 */
113
+	public function get_all_related(
114
+		$model_obj_or_id,
115
+		$query_params = array(),
116
+		$values_already_prepared_by_model_object = false
117
+	) {
118
+		if ($values_already_prepared_by_model_object !== false) {
119
+			EE_Error::doing_it_wrong('EE_Model_Relation_Base::get_all_related',
120
+				__('The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso'),
121
+				'4.8.1');
122
+		}
123
+		//get column on this model object which is a foreign key to the other model
124
+		$fk_field_obj = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
125
+		//get its value
126
+		if ($model_obj_or_id instanceof EE_Base_Class) {
127
+			$model_obj = $model_obj_or_id;
128
+		} else {
129
+			$model_obj = $this->get_this_model()->ensure_is_obj($model_obj_or_id);
130
+		}
131
+		$ID_value_on_other_model = $model_obj->get($fk_field_obj->get_name());
132
+		//get all where their PK matches that value
133
+		$query_params[0][$this->get_other_model()->get_primary_key_field()->get_name()] = $ID_value_on_other_model;
134
+		$query_params                                                                   = $this->_disable_default_where_conditions_on_query_param($query_params);
135 135
 //		echo '$query_params';
136 136
 //		var_dump($query_params);
137
-        return $this->get_other_model()->get_all($query_params);
138
-    }
137
+		return $this->get_other_model()->get_all($query_params);
138
+	}
139 139
 
140 140
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-require_once(EE_MODELS . 'relations/EE_Model_Relation_Base.php');
2
+require_once(EE_MODELS.'relations/EE_Model_Relation_Base.php');
3 3
 
4 4
 /**
5 5
  * Class EE_Belongs_To_Relation
@@ -44,13 +44,13 @@  discard block
 block discarded – undo
44 44
         $this_table_fk_field  = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
45 45
         $other_table_pk_field = $this->get_other_model()->get_primary_key_field();
46 46
         $this_table_alias     = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain,
47
-                $this->get_this_model()->get_this_model_name()) . $this_table_fk_field->get_table_alias();
47
+                $this->get_this_model()->get_this_model_name()).$this_table_fk_field->get_table_alias();
48 48
         $other_table_alias    = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain,
49
-                $this->get_other_model()->get_this_model_name()) . $other_table_pk_field->get_table_alias();
49
+                $this->get_other_model()->get_this_model_name()).$other_table_pk_field->get_table_alias();
50 50
         $other_table          = $this->get_other_model()->get_table_for_alias($other_table_alias);
51 51
         return $this->_left_join($other_table, $other_table_alias, $other_table_pk_field->get_table_column(),
52 52
                 $this_table_alias,
53
-                $this_table_fk_field->get_table_column()) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
53
+                $this_table_fk_field->get_table_column()).$this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
54 54
     }
55 55
 
56 56
 
Please login to merge, or discard this patch.
core/db_models/fields/EE_Datetime_Field.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -567,7 +567,7 @@  discard block
 block discarded – undo
567 567
      * allowed)
568 568
      *
569 569
      * @param string $datetime_string mysql timestamp in UTC
570
-     * @return  mixed null | DateTime
570
+     * @return  null|DbSafeDateTime null | DateTime
571 571
      * @throws \EE_Error
572 572
      */
573 573
     public function prepare_for_set_from_db($datetime_string)
@@ -724,7 +724,7 @@  discard block
 block discarded – undo
724 724
      *
725 725
      * @param \DateTimeZone $DateTimeZone
726 726
      * @param int           $time
727
-     * @return mixed
727
+     * @return integer
728 728
      * @throws \DomainException
729 729
      */
730 730
     public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null)
Please login to merge, or discard this patch.
Indentation   +742 added lines, -742 removed lines patch added patch discarded remove patch
@@ -17,747 +17,747 @@
 block discarded – undo
17 17
 class EE_Datetime_Field extends EE_Model_Field_Base
18 18
 {
19 19
 
20
-    /**
21
-     * The pattern we're looking for is if only the characters 0-9 are found and there are only
22
-     * 10 or more numbers (because 9 numbers even with all 9's would be sometime in 2001 )
23
-     *
24
-     * @type string unix_timestamp_regex
25
-     */
26
-    const unix_timestamp_regex = '/[0-9]{10,}/';
27
-
28
-    /**
29
-     * @type string mysql_timestamp_format
30
-     */
31
-    const mysql_timestamp_format = 'Y-m-d H:i:s';
32
-
33
-    /**
34
-     * @type string mysql_date_format
35
-     */
36
-    const mysql_date_format = 'Y-m-d';
37
-
38
-    /**
39
-     * @type string mysql_time_format
40
-     */
41
-    const mysql_time_format = 'H:i:s';
42
-
43
-    /**
44
-     * Const for using in the default value. If the field's default is set to this,
45
-     * then we will return the time of calling `get_default_value()`, not
46
-     * just the current time at construction
47
-     */
48
-    const now = 'now';
49
-
50
-    /**
51
-     * The following properties hold the default formats for date and time.
52
-     * Defaults are set via the constructor and can be overridden on class instantiation.
53
-     * However they can also be overridden later by the set_format() method
54
-     * (and corresponding set_date_format, set_time_format methods);
55
-     */
56
-    /**
57
-     * @type string $_date_format
58
-     */
59
-    protected $_date_format = '';
60
-
61
-    /**
62
-     * @type string $_time_format
63
-     */
64
-    protected $_time_format = '';
65
-
66
-    /**
67
-     * @type string $_pretty_date_format
68
-     */
69
-    protected $_pretty_date_format = '';
70
-
71
-    /**
72
-     * @type string $_pretty_time_format
73
-     */
74
-    protected $_pretty_time_format = '';
75
-
76
-    /**
77
-     * @type DateTimeZone $_DateTimeZone
78
-     */
79
-    protected $_DateTimeZone;
80
-
81
-    /**
82
-     * @type DateTimeZone $_UTC_DateTimeZone
83
-     */
84
-    protected $_UTC_DateTimeZone;
85
-
86
-    /**
87
-     * @type DateTimeZone $_blog_DateTimeZone
88
-     */
89
-    protected $_blog_DateTimeZone;
90
-
91
-
92
-    /**
93
-     * This property holds how we want the output returned when getting a datetime string.  It is set for the
94
-     * set_date_time_output() method.  By default this is empty.  When empty, we are assuming that we want both date
95
-     * and time returned via getters.
96
-     *
97
-     * @var mixed (null|string)
98
-     */
99
-    protected $_date_time_output;
100
-
101
-
102
-    /**
103
-     * timezone string
104
-     * This gets set by the constructor and can be changed by the "set_timezone()" method so that we know what timezone
105
-     * incoming strings|timestamps are in.  This can also be used before a get to set what timezone you want strings
106
-     * coming out of the object to be in.  Default timezone is the current WP timezone option setting
107
-     *
108
-     * @var string
109
-     */
110
-    protected $_timezone_string;
111
-
112
-
113
-    /**
114
-     * This holds whatever UTC offset for the blog (we automatically convert timezone strings into their related
115
-     * offsets for comparison purposes).
116
-     *
117
-     * @var int
118
-     */
119
-    protected $_blog_offset;
120
-
121
-
122
-
123
-    /**
124
-     * @param string $table_column
125
-     * @param string $nice_name
126
-     * @param bool   $nullable
127
-     * @param string $default_value
128
-     * @param string $timezone_string
129
-     * @param string $date_format
130
-     * @param string $time_format
131
-     * @param string $pretty_date_format
132
-     * @param string $pretty_time_format
133
-     * @throws EE_Error
134
-     * @throws InvalidArgumentException
135
-     */
136
-    public function __construct(
137
-        $table_column,
138
-        $nice_name,
139
-        $nullable,
140
-        $default_value,
141
-        $timezone_string = '',
142
-        $date_format = '',
143
-        $time_format = '',
144
-        $pretty_date_format = '',
145
-        $pretty_time_format = ''
146
-    ) {
147
-
148
-        $this->_date_format        = ! empty($date_format) ? $date_format : get_option('date_format');
149
-        $this->_time_format        = ! empty($time_format) ? $time_format : get_option('time_format');
150
-        $this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format');
151
-        $this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format');
152
-
153
-        parent::__construct($table_column, $nice_name, $nullable, $default_value);
154
-        $this->set_timezone($timezone_string);
155
-        $this->setSchemaFormat('date-time');
156
-    }
157
-
158
-
159
-    /**
160
-     * @return DateTimeZone
161
-     * @throws \EE_Error
162
-     */
163
-    public function get_UTC_DateTimeZone()
164
-    {
165
-        return $this->_UTC_DateTimeZone instanceof DateTimeZone
166
-            ? $this->_UTC_DateTimeZone
167
-            : $this->_create_timezone_object_from_timezone_string('UTC');
168
-    }
169
-
170
-
171
-    /**
172
-     * @return DateTimeZone
173
-     * @throws \EE_Error
174
-     */
175
-    public function get_blog_DateTimeZone()
176
-    {
177
-        return $this->_blog_DateTimeZone instanceof DateTimeZone
178
-            ? $this->_blog_DateTimeZone
179
-            : $this->_create_timezone_object_from_timezone_string('');
180
-    }
181
-
182
-
183
-    /**
184
-     * this prepares any incoming date data and make sure its converted to a utc unix timestamp
185
-     *
186
-     * @param  string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix
187
-     *                                                              timestamp
188
-     * @return DateTime
189
-     */
190
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
191
-    {
192
-        return $this->_get_date_object($value_inputted_for_field_on_model_object);
193
-    }
194
-
195
-
196
-    /**
197
-     * This returns the format string to be used by getters depending on what the $_date_time_output property is set at.
198
-     * getters need to know whether we're just returning the date or the time or both.  By default we return both.
199
-     *
200
-     * @param bool $pretty If we're returning the pretty formats or standard format string.
201
-     * @return string    The final assembled format string.
202
-     */
203
-    protected function _get_date_time_output($pretty = false)
204
-    {
205
-
206
-        switch ($this->_date_time_output) {
207
-            case 'time' :
208
-                return $pretty ? $this->_pretty_time_format : $this->_time_format;
209
-                break;
210
-
211
-            case 'date' :
212
-                return $pretty ? $this->_pretty_date_format : $this->_date_format;
213
-                break;
214
-
215
-            default :
216
-                return $pretty
217
-                    ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format
218
-                    : $this->_date_format . ' ' . $this->_time_format;
219
-        }
220
-    }
221
-
222
-
223
-    /**
224
-     * This just sets the $_date_time_output property so we can flag how date and times are formatted before being
225
-     * returned (using the format properties)
226
-     *
227
-     * @param string $what acceptable values are 'time' or 'date'.
228
-     *                     Any other value will be set but will always result
229
-     *                     in both 'date' and 'time' being returned.
230
-     * @return void
231
-     */
232
-    public function set_date_time_output($what = null)
233
-    {
234
-        $this->_date_time_output = $what;
235
-    }
236
-
237
-
238
-    /**
239
-     * See $_timezone property for description of what the timezone property is for.  This SETS the timezone internally
240
-     * for being able to reference what timezone we are running conversions on when converting TO the internal timezone
241
-     * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp).
242
-     * We also set some other properties in this method.
243
-     *
244
-     * @param string $timezone_string A valid timezone string as described by @link
245
-     *                                http://www.php.net/manual/en/timezones.php
246
-     * @return void
247
-     * @throws InvalidArgumentException
248
-     * @throws InvalidDataTypeException
249
-     * @throws InvalidInterfaceException
250
-     */
251
-    public function set_timezone($timezone_string)
252
-    {
253
-        if (empty($timezone_string) && $this->_timezone_string !== null) {
254
-            // leave the timezone AS-IS if we already have one and
255
-            // the function arg didn't provide one
256
-            return;
257
-        }
258
-        $timezone_string        = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
259
-        $this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC';
260
-        $this->_DateTimeZone    = $this->_create_timezone_object_from_timezone_string($this->_timezone_string);
261
-    }
262
-
263
-
264
-    /**
265
-     * _create_timezone_object_from_timezone_name
266
-     *
267
-     * @access protected
268
-     * @param string $timezone_string
269
-     * @return \DateTimeZone
270
-     * @throws InvalidArgumentException
271
-     * @throws InvalidDataTypeException
272
-     * @throws InvalidInterfaceException
273
-     */
274
-    protected function _create_timezone_object_from_timezone_string($timezone_string = '')
275
-    {
276
-        return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string));
277
-    }
278
-
279
-
280
-    /**
281
-     * This just returns whatever is set for the current timezone.
282
-     *
283
-     * @access public
284
-     * @return string timezone string
285
-     */
286
-    public function get_timezone()
287
-    {
288
-        return $this->_timezone_string;
289
-    }
290
-
291
-
292
-    /**
293
-     * set the $_date_format property
294
-     *
295
-     * @access public
296
-     * @param string $format a new date format (corresponding to formats accepted by PHP date() function)
297
-     * @param bool   $pretty Whether to set pretty format or not.
298
-     * @return void
299
-     */
300
-    public function set_date_format($format, $pretty = false)
301
-    {
302
-        if ($pretty) {
303
-            $this->_pretty_date_format = $format;
304
-        } else {
305
-            $this->_date_format = $format;
306
-        }
307
-    }
308
-
309
-
310
-    /**
311
-     * return the $_date_format property value.
312
-     *
313
-     * @param bool $pretty Whether to get pretty format or not.
314
-     * @return string
315
-     */
316
-    public function get_date_format($pretty = false)
317
-    {
318
-        return $pretty ? $this->_pretty_date_format : $this->_date_format;
319
-    }
320
-
321
-
322
-    /**
323
-     * set the $_time_format property
324
-     *
325
-     * @access public
326
-     * @param string $format a new time format (corresponding to formats accepted by PHP date() function)
327
-     * @param bool   $pretty Whether to set pretty format or not.
328
-     * @return void
329
-     */
330
-    public function set_time_format($format, $pretty = false)
331
-    {
332
-        if ($pretty) {
333
-            $this->_pretty_time_format = $format;
334
-        } else {
335
-            $this->_time_format = $format;
336
-        }
337
-    }
338
-
339
-
340
-    /**
341
-     * return the $_time_format property value.
342
-     *
343
-     * @param bool $pretty Whether to get pretty format or not.
344
-     * @return string
345
-     */
346
-    public function get_time_format($pretty = false)
347
-    {
348
-        return $pretty ? $this->_pretty_time_format : $this->_time_format;
349
-    }
350
-
351
-
352
-    /**
353
-     * set the $_pretty_date_format property
354
-     *
355
-     * @access public
356
-     * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function)
357
-     * @return void
358
-     */
359
-    public function set_pretty_date_format($format)
360
-    {
361
-        $this->_pretty_date_format = $format;
362
-    }
363
-
364
-
365
-    /**
366
-     * set the $_pretty_time_format property
367
-     *
368
-     * @access public
369
-     * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function)
370
-     * @return void
371
-     */
372
-    public function set_pretty_time_format($format)
373
-    {
374
-        $this->_pretty_time_format = $format;
375
-    }
376
-
377
-
378
-    /**
379
-     * Only sets the time portion of the datetime.
380
-     *
381
-     * @param string|DateTime $time_to_set_string like 8am OR a DateTime object.
382
-     * @param DateTime        $current            current DateTime object for the datetime field
383
-     * @return DateTime
384
-     */
385
-    public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current)
386
-    {
387
-        // if $time_to_set_string is datetime object, then let's use it to set the parse array.
388
-        // Otherwise parse the string.
389
-        if ($time_to_set_string instanceof DateTime) {
390
-            $parsed = array(
391
-                'hour'   => $time_to_set_string->format('H'),
392
-                'minute' => $time_to_set_string->format('i'),
393
-                'second' => $time_to_set_string->format('s'),
394
-            );
395
-        } else {
396
-            //parse incoming string
397
-            $parsed = date_parse_from_format($this->_time_format, $time_to_set_string);
398
-        }
399
-        EEH_DTT_Helper::setTimezone($current, $this->_DateTimeZone);
400
-        return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']);
401
-    }
402
-
403
-
404
-    /**
405
-     * Only sets the date portion of the datetime.
406
-     *
407
-     * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object.
408
-     * @param DateTime        $current            current DateTime object for the datetime field
409
-     * @return DateTime
410
-     */
411
-    public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current)
412
-    {
413
-        // if $time_to_set_string is datetime object, then let's use it to set the parse array.
414
-        // Otherwise parse the string.
415
-        if ($date_to_set_string instanceof DateTime) {
416
-            $parsed = array(
417
-                'year'  => $date_to_set_string->format('Y'),
418
-                'month' => $date_to_set_string->format('m'),
419
-                'day'   => $date_to_set_string->format('d'),
420
-            );
421
-        } else {
422
-            //parse incoming string
423
-            $parsed = date_parse_from_format($this->_date_format, $date_to_set_string);
424
-        }
425
-        EEH_DTT_Helper::setTimezone($current, $this->_DateTimeZone);
426
-        return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']);
427
-    }
428
-
429
-
430
-    /**
431
-     * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 timezone).  When the
432
-     * datetime gets to this stage it should ALREADY be in UTC time
433
-     *
434
-     * @param  DateTime $DateTime
435
-     * @return string formatted date time for given timezone
436
-     * @throws \EE_Error
437
-     */
438
-    public function prepare_for_get($DateTime)
439
-    {
440
-        return $this->_prepare_for_display($DateTime);
441
-    }
442
-
443
-
444
-    /**
445
-     * This differs from prepare_for_get in that it considers whether the internal $_timezone differs
446
-     * from the set wp timezone.  If so, then it returns the datetime string formatted via
447
-     * _pretty_date_format, and _pretty_time_format.  However, it also appends a timezone
448
-     * abbreviation to the date_string.
449
-     *
450
-     * @param mixed $DateTime
451
-     * @param null  $schema
452
-     * @return string
453
-     * @throws \EE_Error
454
-     */
455
-    public function prepare_for_pretty_echoing($DateTime, $schema = null)
456
-    {
457
-        return $this->_prepare_for_display($DateTime, $schema ? $schema : true);
458
-    }
459
-
460
-
461
-    /**
462
-     * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
463
-     * timezone).
464
-     *
465
-     * @param DateTime    $DateTime
466
-     * @param bool|string $schema
467
-     * @return string
468
-     * @throws \EE_Error
469
-     */
470
-    protected function _prepare_for_display($DateTime, $schema = false)
471
-    {
472
-        if (! $DateTime instanceof DateTime) {
473
-            if ($this->_nullable) {
474
-                return '';
475
-            } else {
476
-                if (WP_DEBUG) {
477
-                    throw new EE_Error(
478
-                        sprintf(
479
-                            __(
480
-                                'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.',
481
-                                'event_espresso'
482
-                            ),
483
-                            $this->_nicename
484
-                        )
485
-                    );
486
-                } else {
487
-                    $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now);
488
-                    EE_Error::add_error(
489
-                        sprintf(
490
-                            __(
491
-                                'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.  When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.',
492
-                                'event_espresso'
493
-                            ),
494
-                            $this->_nicename
495
-                        )
496
-                    );
497
-                }
498
-            }
499
-        }
500
-        $format_string = $this->_get_date_time_output($schema);
501
-        EEH_DTT_Helper::setTimezone($DateTime, $this->_DateTimeZone);
502
-        if ($schema) {
503
-            if ($this->_display_timezone()) {
504
-                //must be explicit because schema could equal true.
505
-                if ($schema === 'no_html') {
506
-                    $timezone_string = ' (' . $DateTime->format('T') . ')';
507
-                } else {
508
-                    $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>';
509
-                }
510
-            } else {
511
-                $timezone_string = '';
512
-            }
513
-
514
-            return $DateTime->format($format_string) . $timezone_string;
515
-        }
516
-        return $DateTime->format($format_string);
517
-    }
518
-
519
-
520
-    /**
521
-     * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
522
-     * timezone).
523
-     *
524
-     * @param  mixed $datetime_value u
525
-     * @return string mysql timestamp in UTC
526
-     * @throws \EE_Error
527
-     */
528
-    public function prepare_for_use_in_db($datetime_value)
529
-    {
530
-        //we allow an empty value or DateTime object, but nothing else.
531
-        if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) {
532
-            throw new EE_Error(
533
-            	sprintf(
534
-            	    __(
535
-            		    'The incoming value being prepared for setting in the database must either be empty or a php 
20
+	/**
21
+	 * The pattern we're looking for is if only the characters 0-9 are found and there are only
22
+	 * 10 or more numbers (because 9 numbers even with all 9's would be sometime in 2001 )
23
+	 *
24
+	 * @type string unix_timestamp_regex
25
+	 */
26
+	const unix_timestamp_regex = '/[0-9]{10,}/';
27
+
28
+	/**
29
+	 * @type string mysql_timestamp_format
30
+	 */
31
+	const mysql_timestamp_format = 'Y-m-d H:i:s';
32
+
33
+	/**
34
+	 * @type string mysql_date_format
35
+	 */
36
+	const mysql_date_format = 'Y-m-d';
37
+
38
+	/**
39
+	 * @type string mysql_time_format
40
+	 */
41
+	const mysql_time_format = 'H:i:s';
42
+
43
+	/**
44
+	 * Const for using in the default value. If the field's default is set to this,
45
+	 * then we will return the time of calling `get_default_value()`, not
46
+	 * just the current time at construction
47
+	 */
48
+	const now = 'now';
49
+
50
+	/**
51
+	 * The following properties hold the default formats for date and time.
52
+	 * Defaults are set via the constructor and can be overridden on class instantiation.
53
+	 * However they can also be overridden later by the set_format() method
54
+	 * (and corresponding set_date_format, set_time_format methods);
55
+	 */
56
+	/**
57
+	 * @type string $_date_format
58
+	 */
59
+	protected $_date_format = '';
60
+
61
+	/**
62
+	 * @type string $_time_format
63
+	 */
64
+	protected $_time_format = '';
65
+
66
+	/**
67
+	 * @type string $_pretty_date_format
68
+	 */
69
+	protected $_pretty_date_format = '';
70
+
71
+	/**
72
+	 * @type string $_pretty_time_format
73
+	 */
74
+	protected $_pretty_time_format = '';
75
+
76
+	/**
77
+	 * @type DateTimeZone $_DateTimeZone
78
+	 */
79
+	protected $_DateTimeZone;
80
+
81
+	/**
82
+	 * @type DateTimeZone $_UTC_DateTimeZone
83
+	 */
84
+	protected $_UTC_DateTimeZone;
85
+
86
+	/**
87
+	 * @type DateTimeZone $_blog_DateTimeZone
88
+	 */
89
+	protected $_blog_DateTimeZone;
90
+
91
+
92
+	/**
93
+	 * This property holds how we want the output returned when getting a datetime string.  It is set for the
94
+	 * set_date_time_output() method.  By default this is empty.  When empty, we are assuming that we want both date
95
+	 * and time returned via getters.
96
+	 *
97
+	 * @var mixed (null|string)
98
+	 */
99
+	protected $_date_time_output;
100
+
101
+
102
+	/**
103
+	 * timezone string
104
+	 * This gets set by the constructor and can be changed by the "set_timezone()" method so that we know what timezone
105
+	 * incoming strings|timestamps are in.  This can also be used before a get to set what timezone you want strings
106
+	 * coming out of the object to be in.  Default timezone is the current WP timezone option setting
107
+	 *
108
+	 * @var string
109
+	 */
110
+	protected $_timezone_string;
111
+
112
+
113
+	/**
114
+	 * This holds whatever UTC offset for the blog (we automatically convert timezone strings into their related
115
+	 * offsets for comparison purposes).
116
+	 *
117
+	 * @var int
118
+	 */
119
+	protected $_blog_offset;
120
+
121
+
122
+
123
+	/**
124
+	 * @param string $table_column
125
+	 * @param string $nice_name
126
+	 * @param bool   $nullable
127
+	 * @param string $default_value
128
+	 * @param string $timezone_string
129
+	 * @param string $date_format
130
+	 * @param string $time_format
131
+	 * @param string $pretty_date_format
132
+	 * @param string $pretty_time_format
133
+	 * @throws EE_Error
134
+	 * @throws InvalidArgumentException
135
+	 */
136
+	public function __construct(
137
+		$table_column,
138
+		$nice_name,
139
+		$nullable,
140
+		$default_value,
141
+		$timezone_string = '',
142
+		$date_format = '',
143
+		$time_format = '',
144
+		$pretty_date_format = '',
145
+		$pretty_time_format = ''
146
+	) {
147
+
148
+		$this->_date_format        = ! empty($date_format) ? $date_format : get_option('date_format');
149
+		$this->_time_format        = ! empty($time_format) ? $time_format : get_option('time_format');
150
+		$this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format');
151
+		$this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format');
152
+
153
+		parent::__construct($table_column, $nice_name, $nullable, $default_value);
154
+		$this->set_timezone($timezone_string);
155
+		$this->setSchemaFormat('date-time');
156
+	}
157
+
158
+
159
+	/**
160
+	 * @return DateTimeZone
161
+	 * @throws \EE_Error
162
+	 */
163
+	public function get_UTC_DateTimeZone()
164
+	{
165
+		return $this->_UTC_DateTimeZone instanceof DateTimeZone
166
+			? $this->_UTC_DateTimeZone
167
+			: $this->_create_timezone_object_from_timezone_string('UTC');
168
+	}
169
+
170
+
171
+	/**
172
+	 * @return DateTimeZone
173
+	 * @throws \EE_Error
174
+	 */
175
+	public function get_blog_DateTimeZone()
176
+	{
177
+		return $this->_blog_DateTimeZone instanceof DateTimeZone
178
+			? $this->_blog_DateTimeZone
179
+			: $this->_create_timezone_object_from_timezone_string('');
180
+	}
181
+
182
+
183
+	/**
184
+	 * this prepares any incoming date data and make sure its converted to a utc unix timestamp
185
+	 *
186
+	 * @param  string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix
187
+	 *                                                              timestamp
188
+	 * @return DateTime
189
+	 */
190
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
191
+	{
192
+		return $this->_get_date_object($value_inputted_for_field_on_model_object);
193
+	}
194
+
195
+
196
+	/**
197
+	 * This returns the format string to be used by getters depending on what the $_date_time_output property is set at.
198
+	 * getters need to know whether we're just returning the date or the time or both.  By default we return both.
199
+	 *
200
+	 * @param bool $pretty If we're returning the pretty formats or standard format string.
201
+	 * @return string    The final assembled format string.
202
+	 */
203
+	protected function _get_date_time_output($pretty = false)
204
+	{
205
+
206
+		switch ($this->_date_time_output) {
207
+			case 'time' :
208
+				return $pretty ? $this->_pretty_time_format : $this->_time_format;
209
+				break;
210
+
211
+			case 'date' :
212
+				return $pretty ? $this->_pretty_date_format : $this->_date_format;
213
+				break;
214
+
215
+			default :
216
+				return $pretty
217
+					? $this->_pretty_date_format . ' ' . $this->_pretty_time_format
218
+					: $this->_date_format . ' ' . $this->_time_format;
219
+		}
220
+	}
221
+
222
+
223
+	/**
224
+	 * This just sets the $_date_time_output property so we can flag how date and times are formatted before being
225
+	 * returned (using the format properties)
226
+	 *
227
+	 * @param string $what acceptable values are 'time' or 'date'.
228
+	 *                     Any other value will be set but will always result
229
+	 *                     in both 'date' and 'time' being returned.
230
+	 * @return void
231
+	 */
232
+	public function set_date_time_output($what = null)
233
+	{
234
+		$this->_date_time_output = $what;
235
+	}
236
+
237
+
238
+	/**
239
+	 * See $_timezone property for description of what the timezone property is for.  This SETS the timezone internally
240
+	 * for being able to reference what timezone we are running conversions on when converting TO the internal timezone
241
+	 * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp).
242
+	 * We also set some other properties in this method.
243
+	 *
244
+	 * @param string $timezone_string A valid timezone string as described by @link
245
+	 *                                http://www.php.net/manual/en/timezones.php
246
+	 * @return void
247
+	 * @throws InvalidArgumentException
248
+	 * @throws InvalidDataTypeException
249
+	 * @throws InvalidInterfaceException
250
+	 */
251
+	public function set_timezone($timezone_string)
252
+	{
253
+		if (empty($timezone_string) && $this->_timezone_string !== null) {
254
+			// leave the timezone AS-IS if we already have one and
255
+			// the function arg didn't provide one
256
+			return;
257
+		}
258
+		$timezone_string        = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
259
+		$this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC';
260
+		$this->_DateTimeZone    = $this->_create_timezone_object_from_timezone_string($this->_timezone_string);
261
+	}
262
+
263
+
264
+	/**
265
+	 * _create_timezone_object_from_timezone_name
266
+	 *
267
+	 * @access protected
268
+	 * @param string $timezone_string
269
+	 * @return \DateTimeZone
270
+	 * @throws InvalidArgumentException
271
+	 * @throws InvalidDataTypeException
272
+	 * @throws InvalidInterfaceException
273
+	 */
274
+	protected function _create_timezone_object_from_timezone_string($timezone_string = '')
275
+	{
276
+		return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string));
277
+	}
278
+
279
+
280
+	/**
281
+	 * This just returns whatever is set for the current timezone.
282
+	 *
283
+	 * @access public
284
+	 * @return string timezone string
285
+	 */
286
+	public function get_timezone()
287
+	{
288
+		return $this->_timezone_string;
289
+	}
290
+
291
+
292
+	/**
293
+	 * set the $_date_format property
294
+	 *
295
+	 * @access public
296
+	 * @param string $format a new date format (corresponding to formats accepted by PHP date() function)
297
+	 * @param bool   $pretty Whether to set pretty format or not.
298
+	 * @return void
299
+	 */
300
+	public function set_date_format($format, $pretty = false)
301
+	{
302
+		if ($pretty) {
303
+			$this->_pretty_date_format = $format;
304
+		} else {
305
+			$this->_date_format = $format;
306
+		}
307
+	}
308
+
309
+
310
+	/**
311
+	 * return the $_date_format property value.
312
+	 *
313
+	 * @param bool $pretty Whether to get pretty format or not.
314
+	 * @return string
315
+	 */
316
+	public function get_date_format($pretty = false)
317
+	{
318
+		return $pretty ? $this->_pretty_date_format : $this->_date_format;
319
+	}
320
+
321
+
322
+	/**
323
+	 * set the $_time_format property
324
+	 *
325
+	 * @access public
326
+	 * @param string $format a new time format (corresponding to formats accepted by PHP date() function)
327
+	 * @param bool   $pretty Whether to set pretty format or not.
328
+	 * @return void
329
+	 */
330
+	public function set_time_format($format, $pretty = false)
331
+	{
332
+		if ($pretty) {
333
+			$this->_pretty_time_format = $format;
334
+		} else {
335
+			$this->_time_format = $format;
336
+		}
337
+	}
338
+
339
+
340
+	/**
341
+	 * return the $_time_format property value.
342
+	 *
343
+	 * @param bool $pretty Whether to get pretty format or not.
344
+	 * @return string
345
+	 */
346
+	public function get_time_format($pretty = false)
347
+	{
348
+		return $pretty ? $this->_pretty_time_format : $this->_time_format;
349
+	}
350
+
351
+
352
+	/**
353
+	 * set the $_pretty_date_format property
354
+	 *
355
+	 * @access public
356
+	 * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function)
357
+	 * @return void
358
+	 */
359
+	public function set_pretty_date_format($format)
360
+	{
361
+		$this->_pretty_date_format = $format;
362
+	}
363
+
364
+
365
+	/**
366
+	 * set the $_pretty_time_format property
367
+	 *
368
+	 * @access public
369
+	 * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function)
370
+	 * @return void
371
+	 */
372
+	public function set_pretty_time_format($format)
373
+	{
374
+		$this->_pretty_time_format = $format;
375
+	}
376
+
377
+
378
+	/**
379
+	 * Only sets the time portion of the datetime.
380
+	 *
381
+	 * @param string|DateTime $time_to_set_string like 8am OR a DateTime object.
382
+	 * @param DateTime        $current            current DateTime object for the datetime field
383
+	 * @return DateTime
384
+	 */
385
+	public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current)
386
+	{
387
+		// if $time_to_set_string is datetime object, then let's use it to set the parse array.
388
+		// Otherwise parse the string.
389
+		if ($time_to_set_string instanceof DateTime) {
390
+			$parsed = array(
391
+				'hour'   => $time_to_set_string->format('H'),
392
+				'minute' => $time_to_set_string->format('i'),
393
+				'second' => $time_to_set_string->format('s'),
394
+			);
395
+		} else {
396
+			//parse incoming string
397
+			$parsed = date_parse_from_format($this->_time_format, $time_to_set_string);
398
+		}
399
+		EEH_DTT_Helper::setTimezone($current, $this->_DateTimeZone);
400
+		return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']);
401
+	}
402
+
403
+
404
+	/**
405
+	 * Only sets the date portion of the datetime.
406
+	 *
407
+	 * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object.
408
+	 * @param DateTime        $current            current DateTime object for the datetime field
409
+	 * @return DateTime
410
+	 */
411
+	public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current)
412
+	{
413
+		// if $time_to_set_string is datetime object, then let's use it to set the parse array.
414
+		// Otherwise parse the string.
415
+		if ($date_to_set_string instanceof DateTime) {
416
+			$parsed = array(
417
+				'year'  => $date_to_set_string->format('Y'),
418
+				'month' => $date_to_set_string->format('m'),
419
+				'day'   => $date_to_set_string->format('d'),
420
+			);
421
+		} else {
422
+			//parse incoming string
423
+			$parsed = date_parse_from_format($this->_date_format, $date_to_set_string);
424
+		}
425
+		EEH_DTT_Helper::setTimezone($current, $this->_DateTimeZone);
426
+		return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']);
427
+	}
428
+
429
+
430
+	/**
431
+	 * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 timezone).  When the
432
+	 * datetime gets to this stage it should ALREADY be in UTC time
433
+	 *
434
+	 * @param  DateTime $DateTime
435
+	 * @return string formatted date time for given timezone
436
+	 * @throws \EE_Error
437
+	 */
438
+	public function prepare_for_get($DateTime)
439
+	{
440
+		return $this->_prepare_for_display($DateTime);
441
+	}
442
+
443
+
444
+	/**
445
+	 * This differs from prepare_for_get in that it considers whether the internal $_timezone differs
446
+	 * from the set wp timezone.  If so, then it returns the datetime string formatted via
447
+	 * _pretty_date_format, and _pretty_time_format.  However, it also appends a timezone
448
+	 * abbreviation to the date_string.
449
+	 *
450
+	 * @param mixed $DateTime
451
+	 * @param null  $schema
452
+	 * @return string
453
+	 * @throws \EE_Error
454
+	 */
455
+	public function prepare_for_pretty_echoing($DateTime, $schema = null)
456
+	{
457
+		return $this->_prepare_for_display($DateTime, $schema ? $schema : true);
458
+	}
459
+
460
+
461
+	/**
462
+	 * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
463
+	 * timezone).
464
+	 *
465
+	 * @param DateTime    $DateTime
466
+	 * @param bool|string $schema
467
+	 * @return string
468
+	 * @throws \EE_Error
469
+	 */
470
+	protected function _prepare_for_display($DateTime, $schema = false)
471
+	{
472
+		if (! $DateTime instanceof DateTime) {
473
+			if ($this->_nullable) {
474
+				return '';
475
+			} else {
476
+				if (WP_DEBUG) {
477
+					throw new EE_Error(
478
+						sprintf(
479
+							__(
480
+								'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.',
481
+								'event_espresso'
482
+							),
483
+							$this->_nicename
484
+						)
485
+					);
486
+				} else {
487
+					$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now);
488
+					EE_Error::add_error(
489
+						sprintf(
490
+							__(
491
+								'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.  When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.',
492
+								'event_espresso'
493
+							),
494
+							$this->_nicename
495
+						)
496
+					);
497
+				}
498
+			}
499
+		}
500
+		$format_string = $this->_get_date_time_output($schema);
501
+		EEH_DTT_Helper::setTimezone($DateTime, $this->_DateTimeZone);
502
+		if ($schema) {
503
+			if ($this->_display_timezone()) {
504
+				//must be explicit because schema could equal true.
505
+				if ($schema === 'no_html') {
506
+					$timezone_string = ' (' . $DateTime->format('T') . ')';
507
+				} else {
508
+					$timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>';
509
+				}
510
+			} else {
511
+				$timezone_string = '';
512
+			}
513
+
514
+			return $DateTime->format($format_string) . $timezone_string;
515
+		}
516
+		return $DateTime->format($format_string);
517
+	}
518
+
519
+
520
+	/**
521
+	 * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
522
+	 * timezone).
523
+	 *
524
+	 * @param  mixed $datetime_value u
525
+	 * @return string mysql timestamp in UTC
526
+	 * @throws \EE_Error
527
+	 */
528
+	public function prepare_for_use_in_db($datetime_value)
529
+	{
530
+		//we allow an empty value or DateTime object, but nothing else.
531
+		if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) {
532
+			throw new EE_Error(
533
+				sprintf(
534
+					__(
535
+						'The incoming value being prepared for setting in the database must either be empty or a php 
536 536
             		    DateTime object, instead of: %1$s %2$s',
537
-                        'event_espresso'
538
-	                ),
539
-                    '<br />',
540
-                    print_r($datetime_value, true)
541
-                )
542
-            );
543
-        }
544
-
545
-        if ($datetime_value instanceof DateTime) {
546
-            if (! $datetime_value instanceof DbSafeDateTime) {
547
-                $datetime_value = DbSafeDateTime::createFromDateTime($datetime_value);
548
-            }
549
-            EEH_DTT_Helper::setTimezone($datetime_value, $this->get_UTC_DateTimeZone());
550
-            return $datetime_value->format(
551
-                EE_Datetime_Field::mysql_timestamp_format
552
-            );
553
-        }
554
-
555
-        // if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true
556
-        return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null;
557
-    }
558
-
559
-
560
-    /**
561
-     * This prepares the datetime for internal usage as a PHP DateTime object OR null (if nullable is
562
-     * allowed)
563
-     *
564
-     * @param string $datetime_string mysql timestamp in UTC
565
-     * @return  mixed null | DateTime
566
-     * @throws \EE_Error
567
-     */
568
-    public function prepare_for_set_from_db($datetime_string)
569
-    {
570
-        //if $datetime_value is empty, and ! $this->_nullable, just use time()
571
-        if (empty($datetime_string) && $this->_nullable) {
572
-            return null;
573
-        }
574
-        // datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating
575
-        if (empty($datetime_string)) {
576
-            $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
577
-        } else {
578
-            $DateTime = DateTime::createFromFormat(
579
-                EE_Datetime_Field::mysql_timestamp_format,
580
-                $datetime_string,
581
-                $this->get_UTC_DateTimeZone()
582
-            );
583
-            if ($DateTime instanceof \DateTime) {
584
-                $DateTime = new DbSafeDateTime(
585
-                    $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format),
586
-                    $this->get_UTC_DateTimeZone()
587
-                );
588
-            }
589
-        }
590
-
591
-        if (! $DateTime instanceof DbSafeDateTime) {
592
-            // if still no datetime object, then let's just use now
593
-            $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
594
-        }
595
-        // THEN apply the field's set DateTimeZone
596
-        EEH_DTT_Helper::setTimezone($DateTime, $this->_DateTimeZone);
597
-        return $DateTime;
598
-    }
599
-
600
-
601
-    /**
602
-     * All this method does is determine if we're going to display the timezone string or not on any output.
603
-     * To determine this we check if the set timezone offset is different than the blog's set timezone offset.
604
-     * If so, then true.
605
-     *
606
-     * @return bool true for yes false for no
607
-     * @throws \EE_Error
608
-     */
609
-    protected function _display_timezone()
610
-    {
611
-
612
-        // first let's do a comparison of timezone strings.
613
-        // If they match then we can get out without any further calculations
614
-        $blog_string = get_option('timezone_string');
615
-        if ($blog_string === $this->_timezone_string) {
616
-            return false;
617
-        }
618
-        // now we need to calc the offset for the timezone string so we can compare with the blog offset.
619
-        $this_offset = $this->get_timezone_offset($this->_DateTimeZone);
620
-        $blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone());
621
-        // now compare
622
-        return $blog_offset !== $this_offset;
623
-    }
624
-
625
-
626
-    /**
627
-     * This method returns a php DateTime object for setting on the EE_Base_Class model.
628
-     * EE passes around DateTime objects because they are MUCH easier to manipulate and deal
629
-     * with.
630
-     *
631
-     * @param int|string|DateTime $date_string            This should be the incoming date string.  It's assumed to be
632
-     *                                                    in the format that is set on the date_field (or DateTime
633
-     *                                                    object)!
634
-     * @return DateTime
635
-     */
636
-    protected function _get_date_object($date_string)
637
-    {
638
-        //first if this is an empty date_string and nullable is allowed, just return null.
639
-        if ($this->_nullable && empty($date_string)) {
640
-            return null;
641
-        }
642
-
643
-        // if incoming date
644
-        if ($date_string instanceof DateTime) {
645
-            EEH_DTT_Helper::setTimezone($date_string, $this->_DateTimeZone);
646
-            return $date_string;
647
-        }
648
-        // if empty date_string and made it here.
649
-        // Return a datetime object for now in the given timezone.
650
-        if (empty($date_string)) {
651
-            return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
652
-        }
653
-        // if $date_string is matches something that looks like a Unix timestamp let's just use it.
654
-        if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) {
655
-            try {
656
-                // This is operating under the assumption that the incoming Unix timestamp
657
-                // is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp');
658
-                $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
659
-                $DateTime->setTimestamp($date_string);
660
-
661
-                return $DateTime;
662
-            } catch (Exception $e) {
663
-                // should be rare, but if things got fooled then let's just continue
664
-            }
665
-        }
666
-        //not a unix timestamp.  So we will use the set format on this object and set timezone to
667
-        //create the DateTime object.
668
-        $format = $this->_date_format . ' ' . $this->_time_format;
669
-        try {
670
-            $DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone);
671
-            if ($DateTime instanceof DateTime) {
672
-                $DateTime = new DbSafeDateTime(
673
-                    $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format),
674
-                    $this->_DateTimeZone
675
-                );
676
-            }
677
-            if (! $DateTime instanceof DbSafeDateTime) {
678
-                throw new EE_Error(
679
-                    sprintf(
680
-                        __('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'),
681
-                        $date_string,
682
-                        $format
683
-                    )
684
-                );
685
-            }
686
-        } catch (Exception $e) {
687
-            // if we made it here then likely then something went really wrong.
688
-            // Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone.
689
-            $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
690
-        }
691
-
692
-        return $DateTime;
693
-    }
694
-
695
-
696
-
697
-    /**
698
-     * get_timezone_transitions
699
-     *
700
-     * @param \DateTimeZone $DateTimeZone
701
-     * @param int           $time
702
-     * @param bool          $first_only
703
-     * @return mixed
704
-     */
705
-    public function get_timezone_transitions(DateTimeZone $DateTimeZone, $time = null, $first_only = true)
706
-    {
707
-        return EEH_DTT_Helper::get_timezone_transitions($DateTimeZone, $time, $first_only);
708
-    }
709
-
710
-
711
-
712
-    /**
713
-     * get_timezone_offset
714
-     *
715
-     * @param \DateTimeZone $DateTimeZone
716
-     * @param int           $time
717
-     * @return mixed
718
-     * @throws \DomainException
719
-     */
720
-    public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null)
721
-    {
722
-        return EEH_DTT_Helper::get_timezone_offset($DateTimeZone, $time);
723
-    }
724
-
725
-
726
-    /**
727
-     * This will take an incoming timezone string and return the abbreviation for that timezone
728
-     *
729
-     * @param  string $timezone_string
730
-     * @return string           abbreviation
731
-     * @throws \EE_Error
732
-     */
733
-    public function get_timezone_abbrev($timezone_string)
734
-    {
735
-        $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
736
-        $dateTime        = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string));
737
-
738
-        return $dateTime->format('T');
739
-    }
740
-
741
-    /**
742
-     * Overrides the parent to allow for having a dynamic "now" value
743
-     *
744
-     * @return mixed
745
-     */
746
-    public function get_default_value()
747
-    {
748
-        if ($this->_default_value === EE_Datetime_Field::now) {
749
-            return time();
750
-        } else {
751
-            return parent::get_default_value();
752
-        }
753
-    }
754
-
755
-
756
-    public function getSchemaDescription()
757
-    {
758
-        return sprintf(
759
-            esc_html__('%s - the value for this field is in the timezone of the site.', 'event_espresso'),
760
-            $this->get_nicename()
761
-        );
762
-    }
537
+						'event_espresso'
538
+					),
539
+					'<br />',
540
+					print_r($datetime_value, true)
541
+				)
542
+			);
543
+		}
544
+
545
+		if ($datetime_value instanceof DateTime) {
546
+			if (! $datetime_value instanceof DbSafeDateTime) {
547
+				$datetime_value = DbSafeDateTime::createFromDateTime($datetime_value);
548
+			}
549
+			EEH_DTT_Helper::setTimezone($datetime_value, $this->get_UTC_DateTimeZone());
550
+			return $datetime_value->format(
551
+				EE_Datetime_Field::mysql_timestamp_format
552
+			);
553
+		}
554
+
555
+		// if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true
556
+		return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null;
557
+	}
558
+
559
+
560
+	/**
561
+	 * This prepares the datetime for internal usage as a PHP DateTime object OR null (if nullable is
562
+	 * allowed)
563
+	 *
564
+	 * @param string $datetime_string mysql timestamp in UTC
565
+	 * @return  mixed null | DateTime
566
+	 * @throws \EE_Error
567
+	 */
568
+	public function prepare_for_set_from_db($datetime_string)
569
+	{
570
+		//if $datetime_value is empty, and ! $this->_nullable, just use time()
571
+		if (empty($datetime_string) && $this->_nullable) {
572
+			return null;
573
+		}
574
+		// datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating
575
+		if (empty($datetime_string)) {
576
+			$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
577
+		} else {
578
+			$DateTime = DateTime::createFromFormat(
579
+				EE_Datetime_Field::mysql_timestamp_format,
580
+				$datetime_string,
581
+				$this->get_UTC_DateTimeZone()
582
+			);
583
+			if ($DateTime instanceof \DateTime) {
584
+				$DateTime = new DbSafeDateTime(
585
+					$DateTime->format(\EE_Datetime_Field::mysql_timestamp_format),
586
+					$this->get_UTC_DateTimeZone()
587
+				);
588
+			}
589
+		}
590
+
591
+		if (! $DateTime instanceof DbSafeDateTime) {
592
+			// if still no datetime object, then let's just use now
593
+			$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
594
+		}
595
+		// THEN apply the field's set DateTimeZone
596
+		EEH_DTT_Helper::setTimezone($DateTime, $this->_DateTimeZone);
597
+		return $DateTime;
598
+	}
599
+
600
+
601
+	/**
602
+	 * All this method does is determine if we're going to display the timezone string or not on any output.
603
+	 * To determine this we check if the set timezone offset is different than the blog's set timezone offset.
604
+	 * If so, then true.
605
+	 *
606
+	 * @return bool true for yes false for no
607
+	 * @throws \EE_Error
608
+	 */
609
+	protected function _display_timezone()
610
+	{
611
+
612
+		// first let's do a comparison of timezone strings.
613
+		// If they match then we can get out without any further calculations
614
+		$blog_string = get_option('timezone_string');
615
+		if ($blog_string === $this->_timezone_string) {
616
+			return false;
617
+		}
618
+		// now we need to calc the offset for the timezone string so we can compare with the blog offset.
619
+		$this_offset = $this->get_timezone_offset($this->_DateTimeZone);
620
+		$blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone());
621
+		// now compare
622
+		return $blog_offset !== $this_offset;
623
+	}
624
+
625
+
626
+	/**
627
+	 * This method returns a php DateTime object for setting on the EE_Base_Class model.
628
+	 * EE passes around DateTime objects because they are MUCH easier to manipulate and deal
629
+	 * with.
630
+	 *
631
+	 * @param int|string|DateTime $date_string            This should be the incoming date string.  It's assumed to be
632
+	 *                                                    in the format that is set on the date_field (or DateTime
633
+	 *                                                    object)!
634
+	 * @return DateTime
635
+	 */
636
+	protected function _get_date_object($date_string)
637
+	{
638
+		//first if this is an empty date_string and nullable is allowed, just return null.
639
+		if ($this->_nullable && empty($date_string)) {
640
+			return null;
641
+		}
642
+
643
+		// if incoming date
644
+		if ($date_string instanceof DateTime) {
645
+			EEH_DTT_Helper::setTimezone($date_string, $this->_DateTimeZone);
646
+			return $date_string;
647
+		}
648
+		// if empty date_string and made it here.
649
+		// Return a datetime object for now in the given timezone.
650
+		if (empty($date_string)) {
651
+			return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
652
+		}
653
+		// if $date_string is matches something that looks like a Unix timestamp let's just use it.
654
+		if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) {
655
+			try {
656
+				// This is operating under the assumption that the incoming Unix timestamp
657
+				// is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp');
658
+				$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
659
+				$DateTime->setTimestamp($date_string);
660
+
661
+				return $DateTime;
662
+			} catch (Exception $e) {
663
+				// should be rare, but if things got fooled then let's just continue
664
+			}
665
+		}
666
+		//not a unix timestamp.  So we will use the set format on this object and set timezone to
667
+		//create the DateTime object.
668
+		$format = $this->_date_format . ' ' . $this->_time_format;
669
+		try {
670
+			$DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone);
671
+			if ($DateTime instanceof DateTime) {
672
+				$DateTime = new DbSafeDateTime(
673
+					$DateTime->format(\EE_Datetime_Field::mysql_timestamp_format),
674
+					$this->_DateTimeZone
675
+				);
676
+			}
677
+			if (! $DateTime instanceof DbSafeDateTime) {
678
+				throw new EE_Error(
679
+					sprintf(
680
+						__('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'),
681
+						$date_string,
682
+						$format
683
+					)
684
+				);
685
+			}
686
+		} catch (Exception $e) {
687
+			// if we made it here then likely then something went really wrong.
688
+			// Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone.
689
+			$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
690
+		}
691
+
692
+		return $DateTime;
693
+	}
694
+
695
+
696
+
697
+	/**
698
+	 * get_timezone_transitions
699
+	 *
700
+	 * @param \DateTimeZone $DateTimeZone
701
+	 * @param int           $time
702
+	 * @param bool          $first_only
703
+	 * @return mixed
704
+	 */
705
+	public function get_timezone_transitions(DateTimeZone $DateTimeZone, $time = null, $first_only = true)
706
+	{
707
+		return EEH_DTT_Helper::get_timezone_transitions($DateTimeZone, $time, $first_only);
708
+	}
709
+
710
+
711
+
712
+	/**
713
+	 * get_timezone_offset
714
+	 *
715
+	 * @param \DateTimeZone $DateTimeZone
716
+	 * @param int           $time
717
+	 * @return mixed
718
+	 * @throws \DomainException
719
+	 */
720
+	public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null)
721
+	{
722
+		return EEH_DTT_Helper::get_timezone_offset($DateTimeZone, $time);
723
+	}
724
+
725
+
726
+	/**
727
+	 * This will take an incoming timezone string and return the abbreviation for that timezone
728
+	 *
729
+	 * @param  string $timezone_string
730
+	 * @return string           abbreviation
731
+	 * @throws \EE_Error
732
+	 */
733
+	public function get_timezone_abbrev($timezone_string)
734
+	{
735
+		$timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
736
+		$dateTime        = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string));
737
+
738
+		return $dateTime->format('T');
739
+	}
740
+
741
+	/**
742
+	 * Overrides the parent to allow for having a dynamic "now" value
743
+	 *
744
+	 * @return mixed
745
+	 */
746
+	public function get_default_value()
747
+	{
748
+		if ($this->_default_value === EE_Datetime_Field::now) {
749
+			return time();
750
+		} else {
751
+			return parent::get_default_value();
752
+		}
753
+	}
754
+
755
+
756
+	public function getSchemaDescription()
757
+	{
758
+		return sprintf(
759
+			esc_html__('%s - the value for this field is in the timezone of the site.', 'event_espresso'),
760
+			$this->get_nicename()
761
+		);
762
+	}
763 763
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -214,8 +214,8 @@  discard block
 block discarded – undo
214 214
 
215 215
             default :
216 216
                 return $pretty
217
-                    ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format
218
-                    : $this->_date_format . ' ' . $this->_time_format;
217
+                    ? $this->_pretty_date_format.' '.$this->_pretty_time_format
218
+                    : $this->_date_format.' '.$this->_time_format;
219 219
         }
220 220
     }
221 221
 
@@ -469,7 +469,7 @@  discard block
 block discarded – undo
469 469
      */
470 470
     protected function _prepare_for_display($DateTime, $schema = false)
471 471
     {
472
-        if (! $DateTime instanceof DateTime) {
472
+        if ( ! $DateTime instanceof DateTime) {
473 473
             if ($this->_nullable) {
474 474
                 return '';
475 475
             } else {
@@ -503,15 +503,15 @@  discard block
 block discarded – undo
503 503
             if ($this->_display_timezone()) {
504 504
                 //must be explicit because schema could equal true.
505 505
                 if ($schema === 'no_html') {
506
-                    $timezone_string = ' (' . $DateTime->format('T') . ')';
506
+                    $timezone_string = ' ('.$DateTime->format('T').')';
507 507
                 } else {
508
-                    $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>';
508
+                    $timezone_string = ' <span class="ee_dtt_timezone_string">('.$DateTime->format('T').')</span>';
509 509
                 }
510 510
             } else {
511 511
                 $timezone_string = '';
512 512
             }
513 513
 
514
-            return $DateTime->format($format_string) . $timezone_string;
514
+            return $DateTime->format($format_string).$timezone_string;
515 515
         }
516 516
         return $DateTime->format($format_string);
517 517
     }
@@ -528,7 +528,7 @@  discard block
 block discarded – undo
528 528
     public function prepare_for_use_in_db($datetime_value)
529 529
     {
530 530
         //we allow an empty value or DateTime object, but nothing else.
531
-        if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) {
531
+        if ( ! empty($datetime_value) && ! $datetime_value instanceof DateTime) {
532 532
             throw new EE_Error(
533 533
             	sprintf(
534 534
             	    __(
@@ -543,7 +543,7 @@  discard block
 block discarded – undo
543 543
         }
544 544
 
545 545
         if ($datetime_value instanceof DateTime) {
546
-            if (! $datetime_value instanceof DbSafeDateTime) {
546
+            if ( ! $datetime_value instanceof DbSafeDateTime) {
547 547
                 $datetime_value = DbSafeDateTime::createFromDateTime($datetime_value);
548 548
             }
549 549
             EEH_DTT_Helper::setTimezone($datetime_value, $this->get_UTC_DateTimeZone());
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
             }
589 589
         }
590 590
 
591
-        if (! $DateTime instanceof DbSafeDateTime) {
591
+        if ( ! $DateTime instanceof DbSafeDateTime) {
592 592
             // if still no datetime object, then let's just use now
593 593
             $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
594 594
         }
@@ -665,7 +665,7 @@  discard block
 block discarded – undo
665 665
         }
666 666
         //not a unix timestamp.  So we will use the set format on this object and set timezone to
667 667
         //create the DateTime object.
668
-        $format = $this->_date_format . ' ' . $this->_time_format;
668
+        $format = $this->_date_format.' '.$this->_time_format;
669 669
         try {
670 670
             $DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone);
671 671
             if ($DateTime instanceof DateTime) {
@@ -674,7 +674,7 @@  discard block
 block discarded – undo
674 674
                     $this->_DateTimeZone
675 675
                 );
676 676
             }
677
-            if (! $DateTime instanceof DbSafeDateTime) {
677
+            if ( ! $DateTime instanceof DbSafeDateTime) {
678 678
                 throw new EE_Error(
679 679
                     sprintf(
680 680
                         __('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'),
Please login to merge, or discard this patch.
core/business/EE_Transaction_Processor.class.php 3 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -187,6 +187,7 @@
 block discarded – undo
187 187
      *                                                         when retrieving cached registrations from a transaction
188 188
      * @param bool $trigger_notifications                      whether or not to call
189 189
      *                                                         \EE_Registration_Processor::trigger_registration_update_notifications()
190
+     * @param EE_Payment $payment
190 191
      * @return array
191 192
      * @throws \EE_Error
192 193
      */
Please login to merge, or discard this patch.
Indentation   +45 added lines, -46 removed lines patch added patch discarded remove patch
@@ -7,8 +7,7 @@  discard block
 block discarded – undo
7 7
  * the interaction of EE_Transaction and EE_Registration model objects
8 8
  * Provides methods for manipulating and processing changes to an EE_Transaction
9 9
  * and it's related EE_Registrations with regards to the checkout/registration process
10
-
11
-*
10
+ *
12 11
 *@package     Event Espresso
13 12
  * @subpackage 	core
14 13
  * @author      Brent Christensen
@@ -177,24 +176,24 @@  discard block
 block discarded – undo
177 176
 
178 177
 
179 178
 
180
-    /**
181
-     * update_transaction_and_registrations_after_checkout_or_payment
182
-     * cycles thru related registrations and calls update_registration_after_checkout_or_payment() on each
183
-     *
184
-     * @param EE_Transaction $transaction
185
-     * @param \EE_Payment | NULL $payment
186
-     * @param array              $registration_query_params    array of query WHERE params to use
187
-     *                                                         when retrieving cached registrations from a transaction
188
-     * @param bool $trigger_notifications                      whether or not to call
189
-     *                                                         \EE_Registration_Processor::trigger_registration_update_notifications()
190
-     * @return array
191
-     * @throws \EE_Error
192
-     */
179
+	/**
180
+	 * update_transaction_and_registrations_after_checkout_or_payment
181
+	 * cycles thru related registrations and calls update_registration_after_checkout_or_payment() on each
182
+	 *
183
+	 * @param EE_Transaction $transaction
184
+	 * @param \EE_Payment | NULL $payment
185
+	 * @param array              $registration_query_params    array of query WHERE params to use
186
+	 *                                                         when retrieving cached registrations from a transaction
187
+	 * @param bool $trigger_notifications                      whether or not to call
188
+	 *                                                         \EE_Registration_Processor::trigger_registration_update_notifications()
189
+	 * @return array
190
+	 * @throws \EE_Error
191
+	 */
193 192
 	public function update_transaction_and_registrations_after_checkout_or_payment(
194 193
 		EE_Transaction $transaction,
195 194
 		$payment = null,
196 195
 		$registration_query_params = array(),
197
-        $trigger_notifications = true
196
+		$trigger_notifications = true
198 197
 	) {
199 198
 		// make sure some query params are set for retrieving registrations
200 199
 		$this->_set_registration_query_params( $registration_query_params );
@@ -224,15 +223,15 @@  discard block
 block discarded – undo
224 223
 			$update_params
225 224
 		);
226 225
 		if ($trigger_notifications) {
227
-            // send messages
228
-            /** @type EE_Registration_Processor $registration_processor */
229
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
230
-            $registration_processor->trigger_registration_update_notifications(
231
-                $transaction->primary_registration(),
232
-                $update_params
233
-            );
234
-        }
235
-        do_action(
226
+			// send messages
227
+			/** @type EE_Registration_Processor $registration_processor */
228
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
229
+			$registration_processor->trigger_registration_update_notifications(
230
+				$transaction->primary_registration(),
231
+				$update_params
232
+			);
233
+		}
234
+		do_action(
236 235
 			'AHEE__EE_Transaction_Processor__update_transaction_and_registrations_after_checkout_or_payment',
237 236
 			$transaction,
238 237
 			$update_params
@@ -242,17 +241,17 @@  discard block
 block discarded – undo
242 241
 
243 242
 
244 243
 
245
-    /**
246
-     * update_transaction_after_registration_reopened
247
-     * readjusts TXN and Line Item totals after a registration is changed from
248
-     * cancelled or declined to another reg status such as pending payment or approved
249
-     *
250
-     * @param \EE_Registration $registration
251
-     * @param array            $closed_reg_statuses
252
-     * @param bool             $update_txn
253
-     * @return bool
254
-     * @throws \EE_Error
255
-     */
244
+	/**
245
+	 * update_transaction_after_registration_reopened
246
+	 * readjusts TXN and Line Item totals after a registration is changed from
247
+	 * cancelled or declined to another reg status such as pending payment or approved
248
+	 *
249
+	 * @param \EE_Registration $registration
250
+	 * @param array            $closed_reg_statuses
251
+	 * @param bool             $update_txn
252
+	 * @return bool
253
+	 * @throws \EE_Error
254
+	 */
256 255
 	public function update_transaction_after_reinstating_canceled_registration(
257 256
 		EE_Registration $registration,
258 257
 		$closed_reg_statuses = array(),
@@ -314,15 +313,15 @@  discard block
 block discarded – undo
314 313
 		try {
315 314
 			$transaction = $this->get_transaction_for_registration( $registration );
316 315
 			if (
317
-			    apply_filters(
318
-                    'FHEE__EE_Transaction_Processor__update_transaction_after_canceled_or_declined_registration__cancel_ticket_line_item',
319
-                    true,
320
-                    $registration,
321
-                    $transaction
322
-                )
323
-            ){
324
-                $ticket_line_item = $this->get_ticket_line_item_for_transaction_registration( $transaction, $registration );
325
-                EEH_Line_Item::cancel_ticket_line_item( $ticket_line_item );
316
+				apply_filters(
317
+					'FHEE__EE_Transaction_Processor__update_transaction_after_canceled_or_declined_registration__cancel_ticket_line_item',
318
+					true,
319
+					$registration,
320
+					$transaction
321
+				)
322
+			){
323
+				$ticket_line_item = $this->get_ticket_line_item_for_transaction_registration( $transaction, $registration );
324
+				EEH_Line_Item::cancel_ticket_line_item( $ticket_line_item );
326 325
 			}
327 326
 		} catch ( EE_Error $e ) {
328 327
 			EE_Error::add_error(
@@ -532,7 +531,7 @@  discard block
 block discarded – undo
532 531
 						foreach ( $available_payment_methods as $available_payment_method ) {
533 532
 							if (
534 533
 								$available_payment_method instanceof EE_Payment_Method
535
-							    && $available_payment_method->open_by_default()
534
+								&& $available_payment_method->open_by_default()
536 535
 							) {
537 536
 								$PMD_ID = $available_payment_method->ID();
538 537
 								break;
Please login to merge, or discard this patch.
Spacing   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); }
2
-EE_Registry::instance()->load_class( 'Processor_Base' );
2
+EE_Registry::instance()->load_class('Processor_Base');
3 3
 
4 4
 /**
5 5
  * Class EE_Transaction_Processor
@@ -50,10 +50,10 @@  discard block
 block discarded – undo
50 50
 	 * @param array $registration_query_params
51 51
 	 *@return EE_Transaction_Processor instance
52 52
 	 */
53
-	public static function instance( $registration_query_params = array() ) {
53
+	public static function instance($registration_query_params = array()) {
54 54
 		// check if class object is instantiated
55
-		if ( ! self::$_instance instanceof EE_Transaction_Processor ) {
56
-			self::$_instance = new self( $registration_query_params );
55
+		if ( ! self::$_instance instanceof EE_Transaction_Processor) {
56
+			self::$_instance = new self($registration_query_params);
57 57
 		}
58 58
 		return self::$_instance;
59 59
 	}
@@ -63,9 +63,9 @@  discard block
 block discarded – undo
63 63
 	/**
64 64
 	 * @param array $registration_query_params
65 65
 	 */
66
-	private function __construct( $registration_query_params = array() ) {
66
+	private function __construct($registration_query_params = array()) {
67 67
 		// make sure some query params are set for retrieving registrations
68
-		$this->_set_registration_query_params( $registration_query_params );
68
+		$this->_set_registration_query_params($registration_query_params);
69 69
 	}
70 70
 
71 71
 
@@ -74,8 +74,8 @@  discard block
 block discarded – undo
74 74
 	 * @access private
75 75
 	 * @param array $registration_query_params
76 76
 	 */
77
-	private function _set_registration_query_params( $registration_query_params ) {
78
-		$this->_registration_query_params = ! empty( $registration_query_params ) ? $registration_query_params : array( 'order_by' => array( 'REG_count' => 'ASC' ));
77
+	private function _set_registration_query_params($registration_query_params) {
78
+		$this->_registration_query_params = ! empty($registration_query_params) ? $registration_query_params : array('order_by' => array('REG_count' => 'ASC'));
79 79
 	}
80 80
 
81 81
 
@@ -104,10 +104,10 @@  discard block
 block discarded – undo
104 104
 		);
105 105
 		// send messages
106 106
 		/** @type EE_Registration_Processor $registration_processor */
107
-		$registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' );
107
+		$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
108 108
 		$registration_processor->trigger_registration_update_notifications(
109 109
 			$transaction->primary_registration(),
110
-			array( 'manually_updated' 	=> true )
110
+			array('manually_updated' 	=> true)
111 111
 		);
112 112
 		do_action(
113 113
 			'AHEE__EE_Transaction_Processor__manually_update_registration_statuses',
@@ -197,13 +197,13 @@  discard block
 block discarded – undo
197 197
         $trigger_notifications = true
198 198
 	) {
199 199
 		// make sure some query params are set for retrieving registrations
200
-		$this->_set_registration_query_params( $registration_query_params );
200
+		$this->_set_registration_query_params($registration_query_params);
201 201
 		// get final reg step status
202 202
 		$finalized = $transaction->final_reg_step_completed();
203 203
 		// if the 'finalize_registration' step has been initiated (has a timestamp)
204 204
 		// but has not yet been fully completed (TRUE)
205
-		if ( is_int( $finalized ) && $finalized !== false && $finalized !== true ) {
206
-			$transaction->set_reg_step_completed( 'finalize_registration' );
205
+		if (is_int($finalized) && $finalized !== false && $finalized !== true) {
206
+			$transaction->set_reg_step_completed('finalize_registration');
207 207
 			$finalized = true;
208 208
 		}
209 209
 		$transaction->save();
@@ -259,22 +259,22 @@  discard block
 block discarded – undo
259 259
 		$update_txn = true
260 260
 	) {
261 261
 		// these reg statuses should not be considered in any calculations involving monies owing
262
-		$closed_reg_statuses = ! empty( $closed_reg_statuses ) ? $closed_reg_statuses : EEM_Registration::closed_reg_statuses();
263
-		if ( in_array( $registration->status_ID(), $closed_reg_statuses, true ) ) {
262
+		$closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses : EEM_Registration::closed_reg_statuses();
263
+		if (in_array($registration->status_ID(), $closed_reg_statuses, true)) {
264 264
 			return false;
265 265
 		}
266 266
 		try {
267
-			$transaction = $this->get_transaction_for_registration( $registration );
267
+			$transaction = $this->get_transaction_for_registration($registration);
268 268
 			$ticket_line_item = $this->get_ticket_line_item_for_transaction_registration(
269 269
 				$transaction,
270 270
 				$registration
271 271
 			);
272 272
 			// un-cancel the ticket
273
-			$success = EEH_Line_Item::reinstate_canceled_ticket_line_item( $ticket_line_item );
274
-		} catch ( EE_Error $e ) {
273
+			$success = EEH_Line_Item::reinstate_canceled_ticket_line_item($ticket_line_item);
274
+		} catch (EE_Error $e) {
275 275
 			EE_Error::add_error(
276 276
 				sprintf(
277
-					__( 'The Ticket Line Item for Registration %1$d could not be reinstated because :%2$s%3$s', 'event_espresso' ),
277
+					__('The Ticket Line Item for Registration %1$d could not be reinstated because :%2$s%3$s', 'event_espresso'),
278 278
 					$registration->ID(),
279 279
 					'<br />',
280 280
 					$e->getMessage()
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
 			);
284 284
 			return false;
285 285
 		}
286
-		if ( $update_txn ) {
286
+		if ($update_txn) {
287 287
 			return $transaction->save() ? $success : false;
288 288
 		}
289 289
 		return $success;
@@ -307,12 +307,12 @@  discard block
 block discarded – undo
307 307
 		$update_txn = true
308 308
 	) {
309 309
 		// these reg statuses should not be considered in any calculations involving monies owing
310
-		$closed_reg_statuses = ! empty( $closed_reg_statuses ) ? $closed_reg_statuses : EEM_Registration::closed_reg_statuses();
311
-		if ( ! in_array( $registration->status_ID(), $closed_reg_statuses, true ) ) {
310
+		$closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses : EEM_Registration::closed_reg_statuses();
311
+		if ( ! in_array($registration->status_ID(), $closed_reg_statuses, true)) {
312 312
 			return false;
313 313
 		}
314 314
 		try {
315
-			$transaction = $this->get_transaction_for_registration( $registration );
315
+			$transaction = $this->get_transaction_for_registration($registration);
316 316
 			if (
317 317
 			    apply_filters(
318 318
                     'FHEE__EE_Transaction_Processor__update_transaction_after_canceled_or_declined_registration__cancel_ticket_line_item',
@@ -320,14 +320,14 @@  discard block
 block discarded – undo
320 320
                     $registration,
321 321
                     $transaction
322 322
                 )
323
-            ){
324
-                $ticket_line_item = $this->get_ticket_line_item_for_transaction_registration( $transaction, $registration );
325
-                EEH_Line_Item::cancel_ticket_line_item( $ticket_line_item );
323
+            ) {
324
+                $ticket_line_item = $this->get_ticket_line_item_for_transaction_registration($transaction, $registration);
325
+                EEH_Line_Item::cancel_ticket_line_item($ticket_line_item);
326 326
 			}
327
-		} catch ( EE_Error $e ) {
327
+		} catch (EE_Error $e) {
328 328
 			EE_Error::add_error(
329 329
 				sprintf(
330
-					__( 'The Ticket Line Item for Registration %1$d could not be cancelled because :%2$s%3$s', 'event_espresso' ),
330
+					__('The Ticket Line Item for Registration %1$d could not be cancelled because :%2$s%3$s', 'event_espresso'),
331 331
 					$registration->ID(),
332 332
 					'<br />',
333 333
 					$e->getMessage()
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
 			);
337 337
 			return false;
338 338
 		}
339
-		if ( $update_txn ) {
339
+		if ($update_txn) {
340 340
 			return $transaction->save() ? true : false;
341 341
 		}
342 342
 		return true;
@@ -352,12 +352,12 @@  discard block
 block discarded – undo
352 352
 	 * @return 	EE_Transaction
353 353
 	 * @throws 	EE_Error
354 354
 	 */
355
-	public function get_transaction_for_registration( EE_Registration $registration ) {
355
+	public function get_transaction_for_registration(EE_Registration $registration) {
356 356
 		$transaction = $registration->transaction();
357
-		if ( ! $transaction instanceof EE_Transaction ) {
357
+		if ( ! $transaction instanceof EE_Transaction) {
358 358
 			throw new EE_Error(
359 359
 				sprintf(
360
-					__( 'The Transaction for Registration %1$d was not found or is invalid.', 'event_espresso' ),
360
+					__('The Transaction for Registration %1$d was not found or is invalid.', 'event_espresso'),
361 361
 					$registration->ID()
362 362
 				)
363 363
 			);
@@ -380,16 +380,16 @@  discard block
 block discarded – undo
380 380
 		EE_Transaction $transaction,
381 381
 		EE_Registration $registration
382 382
 	) {
383
-		EE_Registry::instance()->load_helper( 'Line_Item' );
383
+		EE_Registry::instance()->load_helper('Line_Item');
384 384
 		$ticket_line_item = EEM_Line_Item::instance()->get_ticket_line_item_for_transaction(
385 385
 			$transaction->ID(),
386 386
 			$registration->ticket_ID()
387 387
 		);
388
-		if ( ! $ticket_line_item instanceof EE_Line_Item ) {
388
+		if ( ! $ticket_line_item instanceof EE_Line_Item) {
389 389
 			throw new EE_Error(
390 390
 				sprintf(
391
-					__( 'The Line Item for Transaction %1$d and Ticket %2$d was not found or is invalid.',
392
-						'event_espresso' ),
391
+					__('The Line Item for Transaction %1$d and Ticket %2$d was not found or is invalid.',
392
+						'event_espresso'),
393 393
 					$transaction->ID(),
394 394
 					$registration->ticket_ID()
395 395
 				)
@@ -422,22 +422,22 @@  discard block
 block discarded – undo
422 422
 		$update_txn = true
423 423
 	) {
424 424
 		// make sure some query params are set for retrieving registrations
425
-		$this->_set_registration_query_params( $registration_query_params );
425
+		$this->_set_registration_query_params($registration_query_params);
426 426
 		// these reg statuses should not be considered in any calculations involving monies owing
427
-		$closed_reg_statuses = ! empty( $closed_reg_statuses ) ? $closed_reg_statuses : EEM_Registration::closed_reg_statuses();
427
+		$closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses : EEM_Registration::closed_reg_statuses();
428 428
 		// loop through cached registrations
429
-		foreach ( $transaction->registrations( $this->_registration_query_params ) as $registration ) {
429
+		foreach ($transaction->registrations($this->_registration_query_params) as $registration) {
430 430
 			if (
431 431
 				$registration instanceof EE_Registration
432
-				&& ! in_array( $registration->status_ID(), $closed_reg_statuses )
432
+				&& ! in_array($registration->status_ID(), $closed_reg_statuses)
433 433
 			) {
434 434
 				return false;
435 435
 			}
436 436
 		}
437
-		if ( in_array( $new_TXN_status, EEM_Transaction::txn_status_array() ) ) {
438
-			$transaction->set_status( $new_TXN_status );
437
+		if (in_array($new_TXN_status, EEM_Transaction::txn_status_array())) {
438
+			$transaction->set_status($new_TXN_status);
439 439
 		}
440
-		if ( $update_txn ) {
440
+		if ($update_txn) {
441 441
 			return $transaction->save() ? true : false;
442 442
 		}
443 443
 		return true;
@@ -466,22 +466,22 @@  discard block
 block discarded – undo
466 466
 	) {
467 467
 		$response = false;
468 468
 		/** @type EE_Registration_Processor $registration_processor */
469
-		$registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' );
469
+		$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
470 470
 		// check that method exists
471
-		if ( ! method_exists( $registration_processor, $method_name )) {
472
-			throw new EE_Error( __( 'Method does not exist.', 'event_espresso' ));
471
+		if ( ! method_exists($registration_processor, $method_name)) {
472
+			throw new EE_Error(__('Method does not exist.', 'event_espresso'));
473 473
 		}
474 474
 		// make sure some query params are set for retrieving registrations
475
-		$this->_set_registration_query_params( $registration_query_params );
475
+		$this->_set_registration_query_params($registration_query_params);
476 476
 		// loop through cached registrations
477
-		foreach ( $transaction->registrations( $this->_registration_query_params ) as $registration ) {
478
-			if ( $registration instanceof EE_Registration ) {
479
-				if ( $additional_param ) {
480
-					$response = $registration_processor->{$method_name}( $registration, $additional_param )
477
+		foreach ($transaction->registrations($this->_registration_query_params) as $registration) {
478
+			if ($registration instanceof EE_Registration) {
479
+				if ($additional_param) {
480
+					$response = $registration_processor->{$method_name}($registration, $additional_param)
481 481
 						? true
482 482
 						: $response;
483 483
 				} else {
484
-					$response = $registration_processor->{$method_name}( $registration )
484
+					$response = $registration_processor->{$method_name}($registration)
485 485
 						? true
486 486
 						: $response;
487 487
 				}
@@ -508,28 +508,28 @@  discard block
 block discarded – undo
508 508
 	public function set_transaction_payment_method_based_on_registration_statuses(
509 509
 		EE_Registration $edited_registration
510 510
 	) {
511
-		if ( $edited_registration instanceof EE_Registration ) {
511
+		if ($edited_registration instanceof EE_Registration) {
512 512
 			$transaction = $edited_registration->transaction();
513
-			if ( $transaction instanceof EE_Transaction ) {
513
+			if ($transaction instanceof EE_Transaction) {
514 514
 				$all_not_approved = true;
515
-				foreach ( $transaction->registrations() as $registration ) {
516
-					if ( $registration instanceof EE_Registration ) {
515
+				foreach ($transaction->registrations() as $registration) {
516
+					if ($registration instanceof EE_Registration) {
517 517
 						// if any REG != "Not Approved" then toggle to false
518 518
 						$all_not_approved = $registration->is_not_approved() ? $all_not_approved : false;
519 519
 					}
520 520
 				}
521 521
 				// if ALL Registrations are "Not Approved"
522
-				if ( $all_not_approved ) {
523
-					$transaction->set_payment_method_ID( null );
522
+				if ($all_not_approved) {
523
+					$transaction->set_payment_method_ID(null);
524 524
 					$transaction->save();
525 525
 				} else {
526 526
 					$available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction(
527 527
 						$transaction,
528 528
 						EEM_Payment_Method::scope_cart
529 529
 					);
530
-					if ( ! empty( $available_payment_methods ) ) {
530
+					if ( ! empty($available_payment_methods)) {
531 531
 						$PMD_ID = 0;
532
-						foreach ( $available_payment_methods as $available_payment_method ) {
532
+						foreach ($available_payment_methods as $available_payment_method) {
533 533
 							if (
534 534
 								$available_payment_method instanceof EE_Payment_Method
535 535
 							    && $available_payment_method->open_by_default()
@@ -538,22 +538,22 @@  discard block
 block discarded – undo
538 538
 								break;
539 539
 							}
540 540
 						}
541
-						if ( ! $PMD_ID ) {
542
-							$first_payment_method = reset( $available_payment_methods );
543
-							if ( $first_payment_method instanceof EE_Payment_Method ) {
541
+						if ( ! $PMD_ID) {
542
+							$first_payment_method = reset($available_payment_methods);
543
+							if ($first_payment_method instanceof EE_Payment_Method) {
544 544
 								$PMD_ID = $first_payment_method->ID();
545 545
 							} else {
546 546
 								EE_Error::add_error(
547
-									__( 'A valid Payment Method could not be determined. Please ensure that at least one Payment Method is activated.', 'event_espresso' ),
547
+									__('A valid Payment Method could not be determined. Please ensure that at least one Payment Method is activated.', 'event_espresso'),
548 548
 									__FILE__, __LINE__, __FUNCTION__
549 549
 								);
550 550
 							}
551 551
 						}
552
-						$transaction->set_payment_method_ID( $PMD_ID );
552
+						$transaction->set_payment_method_ID($PMD_ID);
553 553
 						$transaction->save();
554 554
 					} else {
555 555
 						EE_Error::add_error(
556
-							__( 'Please activate at least one Payment Method in order for things to operate correctly.', 'event_espresso' ),
556
+							__('Please activate at least one Payment Method in order for things to operate correctly.', 'event_espresso'),
557 557
 							__FILE__, __LINE__, __FUNCTION__
558 558
 						);
559 559
 					}
@@ -590,7 +590,7 @@  discard block
 block discarded – undo
590 590
 	 * @deprecated 4.9.12
591 591
 	 * @param string $old_txn_status
592 592
 	 */
593
-	public function set_old_txn_status( $old_txn_status ) {
593
+	public function set_old_txn_status($old_txn_status) {
594 594
 		EE_Error::doing_it_wrong(
595 595
 			__METHOD__,
596 596
 			esc_html__(
@@ -600,7 +600,7 @@  discard block
 block discarded – undo
600 600
 			'4.9.12'
601 601
 		);
602 602
 		// only set the first time
603
-		if ( $this->_old_txn_status === null ) {
603
+		if ($this->_old_txn_status === null) {
604 604
 			$this->_old_txn_status = $old_txn_status;
605 605
 		}
606 606
 	}
@@ -629,7 +629,7 @@  discard block
 block discarded – undo
629 629
 	 * @deprecated 4.9.12
630 630
 	 * @param string $new_txn_status
631 631
 	 */
632
-	public function set_new_txn_status( $new_txn_status ) {
632
+	public function set_new_txn_status($new_txn_status) {
633 633
 		EE_Error::doing_it_wrong(
634 634
 			__METHOD__,
635 635
 			esc_html__(
@@ -673,7 +673,7 @@  discard block
 block discarded – undo
673 673
 	 * @param EE_Transaction $transaction
674 674
 	 * @return boolean
675 675
 	 */
676
-	public function all_reg_steps_completed( EE_Transaction $transaction ) {
676
+	public function all_reg_steps_completed(EE_Transaction $transaction) {
677 677
 		EE_Error::doing_it_wrong(
678 678
 			__METHOD__,
679 679
 			esc_html__(
@@ -700,7 +700,7 @@  discard block
 block discarded – undo
700 700
 	 * @param string         $exception
701 701
 	 * @return boolean
702 702
 	 */
703
-	public function all_reg_steps_completed_except( EE_Transaction $transaction, $exception = '' ) {
703
+	public function all_reg_steps_completed_except(EE_Transaction $transaction, $exception = '') {
704 704
 		EE_Error::doing_it_wrong(
705 705
 			__METHOD__,
706 706
 			esc_html__(
@@ -710,7 +710,7 @@  discard block
 block discarded – undo
710 710
 			'4.9.12',
711 711
 			'5.0.0'
712 712
 		);
713
-		return $transaction->all_reg_steps_completed_except( $exception );
713
+		return $transaction->all_reg_steps_completed_except($exception);
714 714
 	}
715 715
 
716 716
 
@@ -726,7 +726,7 @@  discard block
 block discarded – undo
726 726
 	 * @param EE_Transaction $transaction
727 727
 	 * @return boolean
728 728
 	 */
729
-	public function all_reg_steps_completed_except_final_step( EE_Transaction $transaction ) {
729
+	public function all_reg_steps_completed_except_final_step(EE_Transaction $transaction) {
730 730
 		EE_Error::doing_it_wrong(
731 731
 			__METHOD__,
732 732
 			esc_html__(
@@ -753,7 +753,7 @@  discard block
 block discarded – undo
753 753
 	 * @param string         $reg_step_slug
754 754
 	 * @return boolean | int
755 755
 	 */
756
-	public function reg_step_completed( EE_Transaction $transaction, $reg_step_slug ) {
756
+	public function reg_step_completed(EE_Transaction $transaction, $reg_step_slug) {
757 757
 		EE_Error::doing_it_wrong(
758 758
 			__METHOD__,
759 759
 			esc_html__(
@@ -763,7 +763,7 @@  discard block
 block discarded – undo
763 763
 			'4.9.12',
764 764
 			'5.0.0'
765 765
 		);
766
-		return $transaction->reg_step_completed( $reg_step_slug );
766
+		return $transaction->reg_step_completed($reg_step_slug);
767 767
 	}
768 768
 
769 769
 
@@ -779,7 +779,7 @@  discard block
 block discarded – undo
779 779
 	 * @param EE_Transaction $transaction
780 780
 	 * @return boolean | int
781 781
 	 */
782
-	public function final_reg_step_completed( EE_Transaction $transaction ) {
782
+	public function final_reg_step_completed(EE_Transaction $transaction) {
783 783
 		EE_Error::doing_it_wrong(
784 784
 			__METHOD__,
785 785
 			esc_html__(
@@ -805,7 +805,7 @@  discard block
 block discarded – undo
805 805
 	 * @return boolean
806 806
 	 * @throws \EE_Error
807 807
 	 */
808
-	public function set_reg_step_initiated( EE_Transaction $transaction, $reg_step_slug ) {
808
+	public function set_reg_step_initiated(EE_Transaction $transaction, $reg_step_slug) {
809 809
 		EE_Error::doing_it_wrong(
810 810
 			__METHOD__,
811 811
 			esc_html__(
@@ -815,7 +815,7 @@  discard block
 block discarded – undo
815 815
 			'4.9.12',
816 816
 			'5.0.0'
817 817
 		);
818
-		return $transaction->set_reg_step_initiated( $reg_step_slug );
818
+		return $transaction->set_reg_step_initiated($reg_step_slug);
819 819
 	}
820 820
 
821 821
 
@@ -831,7 +831,7 @@  discard block
 block discarded – undo
831 831
 	 * @return boolean
832 832
 	 * @throws \EE_Error
833 833
 	 */
834
-	public function set_reg_step_completed( EE_Transaction $transaction, $reg_step_slug ) {
834
+	public function set_reg_step_completed(EE_Transaction $transaction, $reg_step_slug) {
835 835
 		EE_Error::doing_it_wrong(
836 836
 			__METHOD__,
837 837
 			esc_html__(
@@ -841,7 +841,7 @@  discard block
 block discarded – undo
841 841
 			'4.9.12',
842 842
 			'5.0.0'
843 843
 		);
844
-		return $transaction->set_reg_step_completed( $reg_step_slug );
844
+		return $transaction->set_reg_step_completed($reg_step_slug);
845 845
 	}
846 846
 
847 847
 
@@ -857,7 +857,7 @@  discard block
 block discarded – undo
857 857
 	 * @return boolean
858 858
 	 * @throws \EE_Error
859 859
 	 */
860
-	public function set_reg_step_not_completed( EE_Transaction $transaction, $reg_step_slug ) {
860
+	public function set_reg_step_not_completed(EE_Transaction $transaction, $reg_step_slug) {
861 861
 		EE_Error::doing_it_wrong(
862 862
 			__METHOD__,
863 863
 			esc_html__(
@@ -867,7 +867,7 @@  discard block
 block discarded – undo
867 867
 			'4.9.12',
868 868
 			'5.0.0'
869 869
 		);
870
-		return $transaction->set_reg_step_not_completed( $reg_step_slug );
870
+		return $transaction->set_reg_step_not_completed($reg_step_slug);
871 871
 	}
872 872
 
873 873
 
@@ -884,7 +884,7 @@  discard block
 block discarded – undo
884 884
 	 * @param string          $reg_step_slug
885 885
 	 * @return void
886 886
 	 */
887
-	public function remove_reg_step( EE_Transaction $transaction, $reg_step_slug ) {
887
+	public function remove_reg_step(EE_Transaction $transaction, $reg_step_slug) {
888 888
 		EE_Error::doing_it_wrong(
889 889
 			__METHOD__,
890 890
 			esc_html__(
@@ -894,7 +894,7 @@  discard block
 block discarded – undo
894 894
 			'4.9.12',
895 895
 			'5.0.0'
896 896
 		);
897
-		$transaction->remove_reg_step( $reg_step_slug );
897
+		$transaction->remove_reg_step($reg_step_slug);
898 898
 	}
899 899
 
900 900
 
@@ -910,7 +910,7 @@  discard block
 block discarded – undo
910 910
 	 * @return    boolean
911 911
 	 * @throws \EE_Error
912 912
 	 */
913
-	public function toggle_failed_transaction_status( EE_Transaction $transaction ) {
913
+	public function toggle_failed_transaction_status(EE_Transaction $transaction) {
914 914
 		EE_Error::doing_it_wrong(
915 915
 			__METHOD__,
916 916
 			esc_html__(
@@ -934,7 +934,7 @@  discard block
 block discarded – undo
934 934
 	 * @param  EE_Transaction $transaction
935 935
 	 * @return boolean
936 936
 	 */
937
-	public function toggle_abandoned_transaction_status( EE_Transaction $transaction ) {
937
+	public function toggle_abandoned_transaction_status(EE_Transaction $transaction) {
938 938
 		EE_Error::doing_it_wrong(
939 939
 			__METHOD__,
940 940
 			esc_html__(
Please login to merge, or discard this patch.
finalize_registration/EE_SPCO_Reg_Step_Finalize_Registration.class.php 2 patches
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -56,10 +56,10 @@  discard block
 block discarded – undo
56 56
 
57 57
 
58 58
 
59
-    /**
60
-     * @return string
61
-     * @throws \EE_Error
62
-     */
59
+	/**
60
+	 * @return string
61
+	 * @throws \EE_Error
62
+	 */
63 63
 	public function generate_reg_form() {
64 64
 		// create empty form so that things don't break
65 65
 		$this->reg_form = new EE_Form_Section_Proper();
@@ -68,26 +68,26 @@  discard block
 block discarded – undo
68 68
 
69 69
 
70 70
 
71
-    /**
72
-     * @return boolean
73
-     * @throws \RuntimeException
74
-     * @throws \EE_Error
75
-     */
71
+	/**
72
+	 * @return boolean
73
+	 * @throws \RuntimeException
74
+	 * @throws \EE_Error
75
+	 */
76 76
 	public function process_reg_step() {
77
-        // ensure all data gets refreshed from the db
77
+		// ensure all data gets refreshed from the db
78 78
 		$this->checkout->refresh_all_entities( true );
79 79
 		// ensures that all details and statuses for transaction, registration, and payments are updated
80 80
 		$txn_update_params = $this->_finalize_transaction();
81
-        // maybe send messages
82
-        $this->_set_notification_triggers();
83
-        // send messages
84
-        /** @type EE_Registration_Processor $registration_processor */
85
-        $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
86
-        $registration_processor->trigger_registration_update_notifications(
87
-            $this->checkout->transaction->primary_registration(),
88
-            $txn_update_params
89
-        );
90
-        // set a hook point
81
+		// maybe send messages
82
+		$this->_set_notification_triggers();
83
+		// send messages
84
+		/** @type EE_Registration_Processor $registration_processor */
85
+		$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
86
+		$registration_processor->trigger_registration_update_notifications(
87
+			$this->checkout->transaction->primary_registration(),
88
+			$txn_update_params
89
+		);
90
+		// set a hook point
91 91
 		do_action(
92 92
 			'AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed',
93 93
 			$this->checkout,
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 		if (
105 105
 			! (
106 106
 				$this->checkout->payment_method instanceof EE_Payment_Method
107
-		        && $this->checkout->payment_method->is_off_site()
107
+				&& $this->checkout->payment_method->is_off_site()
108 108
 			)
109 109
 		) {
110 110
 			// mark this reg step as completed
@@ -116,14 +116,14 @@  discard block
 block discarded – undo
116 116
 
117 117
 
118 118
 
119
-    /**
120
-     * _finalize_transaction
121
-     * ensures that all details and statuses for transaction, registration, and payments are updated
122
-     *
123
-     * @return array
124
-     * @throws \RuntimeException
125
-     * @throws \EE_Error
126
-     */
119
+	/**
120
+	 * _finalize_transaction
121
+	 * ensures that all details and statuses for transaction, registration, and payments are updated
122
+	 *
123
+	 * @return array
124
+	 * @throws \RuntimeException
125
+	 * @throws \EE_Error
126
+	 */
127 127
 	protected function _finalize_transaction() {
128 128
 		/** @type EE_Transaction_Processor $transaction_processor */
129 129
 		$transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' );
@@ -139,17 +139,17 @@  discard block
 block discarded – undo
139 139
 		}
140 140
 		// maybe update status, but don't save transaction just yet
141 141
 		$this->checkout->transaction->update_status_based_on_total_paid( false );
142
-        // this will result in the base session properties getting saved to the TXN_Session_data field
142
+		// this will result in the base session properties getting saved to the TXN_Session_data field
143 143
 		$this->checkout->transaction->set_txn_session_data(
144 144
 			EE_Registry::instance()->SSN->get_session_data( null, true )
145 145
 		);
146
-        // update the TXN if payment conditions have changed, but do NOT trigger notifications,
147
-        // because we will do that in process_reg_step() after setting some more triggers
146
+		// update the TXN if payment conditions have changed, but do NOT trigger notifications,
147
+		// because we will do that in process_reg_step() after setting some more triggers
148 148
 		return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment(
149 149
 			$this->checkout->transaction,
150 150
 			$this->checkout->payment,
151 151
 			$this->checkout->reg_cache_where_params,
152
-            false
152
+			false
153 153
 		);
154 154
 	}
155 155
 
@@ -167,43 +167,43 @@  discard block
 block discarded – undo
167 167
 	protected function _set_notification_triggers() {
168 168
 
169 169
 		if ( $this->checkout->payment_method instanceof EE_Payment_Method ) {
170
-		    // let's start with the assumption that we need to trigger notifications
171
-            // then toggle this to false for conditions where we know we don't need to
172
-		    $deliver_notifications = true;
173
-            if (
174
-                // if SPCO revisit
175
-                filter_var($this->checkout->revisit, FILTER_VALIDATE_BOOLEAN)
176
-                // and TXN or REG statuses have NOT changed due to a payment
177
-                && ! (
178
-                    $this->checkout->transaction->txn_status_updated()
179
-                    || $this->checkout->any_reg_status_updated()
180
-                )
181
-            ) {
182
-                $deliver_notifications = false;
183
-            }
184
-            if ($this->checkout->payment_method->is_off_site()) {
185
-                /** @var EE_Gateway $gateway */
186
-                $gateway = $this->checkout->payment_method->type_obj()->get_gateway();
187
-                // and the gateway uses a separate request to process the IPN
188
-                if (
189
-                    $gateway instanceof EE_Offsite_Gateway
190
-                    && $gateway->handle_IPN_in_this_request(\EE_Registry::instance()->REQ->params(), true)
191
-                ) {
192
-                    // IPN request will handle triggering notifications
193
-                    $deliver_notifications = false;
194
-                    // no really... don't send any notices in this request
195
-                    remove_all_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications');
196
-                    add_filter(
197
-                        'FHEE__EED_Messages___maybe_registration__deliver_notifications',
198
-                        '__return_false',
199
-                        15
200
-                    );
201
-                }
202
-            }
203
-            if ($deliver_notifications) {
204
-                // send out notifications
205
-                add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
206
-            }
170
+			// let's start with the assumption that we need to trigger notifications
171
+			// then toggle this to false for conditions where we know we don't need to
172
+			$deliver_notifications = true;
173
+			if (
174
+				// if SPCO revisit
175
+				filter_var($this->checkout->revisit, FILTER_VALIDATE_BOOLEAN)
176
+				// and TXN or REG statuses have NOT changed due to a payment
177
+				&& ! (
178
+					$this->checkout->transaction->txn_status_updated()
179
+					|| $this->checkout->any_reg_status_updated()
180
+				)
181
+			) {
182
+				$deliver_notifications = false;
183
+			}
184
+			if ($this->checkout->payment_method->is_off_site()) {
185
+				/** @var EE_Gateway $gateway */
186
+				$gateway = $this->checkout->payment_method->type_obj()->get_gateway();
187
+				// and the gateway uses a separate request to process the IPN
188
+				if (
189
+					$gateway instanceof EE_Offsite_Gateway
190
+					&& $gateway->handle_IPN_in_this_request(\EE_Registry::instance()->REQ->params(), true)
191
+				) {
192
+					// IPN request will handle triggering notifications
193
+					$deliver_notifications = false;
194
+					// no really... don't send any notices in this request
195
+					remove_all_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications');
196
+					add_filter(
197
+						'FHEE__EED_Messages___maybe_registration__deliver_notifications',
198
+						'__return_false',
199
+						15
200
+					);
201
+				}
202
+			}
203
+			if ($deliver_notifications) {
204
+				// send out notifications
205
+				add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
206
+			}
207 207
 		}
208 208
 	}
209 209
 
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1
-<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
2
-	exit( 'No direct script access allowed' );
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -21,9 +21,9 @@  discard block
 block discarded – undo
21 21
 	 * @access    public
22 22
 	 * @param    EE_Checkout $checkout
23 23
 	 */
24
-	public function __construct( EE_Checkout $checkout ) {
24
+	public function __construct(EE_Checkout $checkout) {
25 25
 		$this->_slug = 'finalize_registration';
26
-		$this->_name = __( 'Finalize Registration', 'event_espresso' );
26
+		$this->_name = __('Finalize Registration', 'event_espresso');
27 27
 		$this->_submit_button_text = $this->_name;
28 28
 		$this->_template = '';
29 29
 		$this->checkout = $checkout;
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 	 */
47 47
 	public function initialize_reg_step() {
48 48
 		// there's actually no reg form to process if this is the final step
49
-		if ( $this->is_current_step() ) {
49
+		if ($this->is_current_step()) {
50 50
 			$this->checkout->step = $_REQUEST['step'] = $this->slug();
51 51
 			$this->checkout->action = $_REQUEST['action'] = 'process_reg_step';
52 52
 			$this->checkout->generate_reg_form = false;
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
      */
76 76
 	public function process_reg_step() {
77 77
         // ensure all data gets refreshed from the db
78
-		$this->checkout->refresh_all_entities( true );
78
+		$this->checkout->refresh_all_entities(true);
79 79
 		// ensures that all details and statuses for transaction, registration, and payments are updated
80 80
 		$txn_update_params = $this->_finalize_transaction();
81 81
         // maybe send messages
@@ -94,13 +94,13 @@  discard block
 block discarded – undo
94 94
 			$txn_update_params
95 95
 		);
96 96
 		// check if transaction has a primary registrant and that it has a related Attendee object
97
-		if ( ! $this->_validate_primary_registrant() ) {
97
+		if ( ! $this->_validate_primary_registrant()) {
98 98
 			return false;
99 99
 		}
100 100
 		// you don't have to go home but you can't stay here !
101 101
 		$this->checkout->redirect = true;
102 102
 		$this->checkout->continue_reg = true;
103
-		$this->checkout->json_response->set_redirect_url( $this->checkout->redirect_url );
103
+		$this->checkout->json_response->set_redirect_url($this->checkout->redirect_url);
104 104
 		if (
105 105
 			! (
106 106
 				$this->checkout->payment_method instanceof EE_Payment_Method
@@ -126,22 +126,22 @@  discard block
 block discarded – undo
126 126
      */
127 127
 	protected function _finalize_transaction() {
128 128
 		/** @type EE_Transaction_Processor $transaction_processor */
129
-		$transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' );
129
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
130 130
 		//set revisit flag in txn processor
131
-		$transaction_processor->set_revisit( $this->checkout->revisit );
131
+		$transaction_processor->set_revisit($this->checkout->revisit);
132 132
 		// at this point we'll consider a TXN to not have been abandoned
133 133
 		$this->checkout->transaction->toggle_abandoned_transaction_status();
134
-		if ( $this->checkout->cart instanceof EE_Cart ) {
134
+		if ($this->checkout->cart instanceof EE_Cart) {
135 135
 			// save TXN data to the cart
136 136
 			$this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn(
137 137
 				$this->checkout->transaction->ID()
138 138
 			);
139 139
 		}
140 140
 		// maybe update status, but don't save transaction just yet
141
-		$this->checkout->transaction->update_status_based_on_total_paid( false );
141
+		$this->checkout->transaction->update_status_based_on_total_paid(false);
142 142
         // this will result in the base session properties getting saved to the TXN_Session_data field
143 143
 		$this->checkout->transaction->set_txn_session_data(
144
-			EE_Registry::instance()->SSN->get_session_data( null, true )
144
+			EE_Registry::instance()->SSN->get_session_data(null, true)
145 145
 		);
146 146
         // update the TXN if payment conditions have changed, but do NOT trigger notifications,
147 147
         // because we will do that in process_reg_step() after setting some more triggers
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 	 */
167 167
 	protected function _set_notification_triggers() {
168 168
 
169
-		if ( $this->checkout->payment_method instanceof EE_Payment_Method ) {
169
+		if ($this->checkout->payment_method instanceof EE_Payment_Method) {
170 170
 		    // let's start with the assumption that we need to trigger notifications
171 171
             // then toggle this to false for conditions where we know we don't need to
172 172
 		    $deliver_notifications = true;
@@ -216,9 +216,9 @@  discard block
 block discarded – undo
216 216
 	 * @throws \EE_Error
217 217
 	 */
218 218
 	protected function _validate_primary_registrant() {
219
-		if ( ! $this->checkout->transaction_has_primary_registrant() ) {
219
+		if ( ! $this->checkout->transaction_has_primary_registrant()) {
220 220
 			EE_Error::add_error(
221
-				__( 'A valid Primary Registration for this Transaction could not be found.', 'event_espresso' ),
221
+				__('A valid Primary Registration for this Transaction could not be found.', 'event_espresso'),
222 222
 				__FILE__,
223 223
 				__FUNCTION__,
224 224
 				__LINE__
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 		}
230 230
 		// setup URL for redirect
231 231
 		$this->checkout->redirect_url = add_query_arg(
232
-			array( 'e_reg_url_link' => $this->checkout->transaction->primary_registration()->reg_url_link() ),
232
+			array('e_reg_url_link' => $this->checkout->transaction->primary_registration()->reg_url_link()),
233 233
 			$this->checkout->thank_you_page_url
234 234
 		);
235 235
 		return true;
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
 	 */
243 243
 	public function update_reg_step() {
244 244
 		EE_Error::doing_it_wrong(
245
-			__CLASS__ . '::' . __FILE__,
245
+			__CLASS__.'::'.__FILE__,
246 246
 			__(
247 247
 				'Can not call update_reg_step() on the Finalize Registration reg step.',
248 248
 				'event_espresso'
Please login to merge, or discard this patch.
core/db_models/fields/EE_Primary_Key_String_Field.php 2 patches
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -4,22 +4,22 @@
 block discarded – undo
4 4
 class EE_Primary_Key_String_Field extends EE_Primary_Key_Field_Base
5 5
 {
6 6
 
7
-    public function __construct($table_column, $nicename)
8
-    {
9
-        parent::__construct($table_column, $nicename, null);
10
-    }
7
+	public function __construct($table_column, $nicename)
8
+	{
9
+		parent::__construct($table_column, $nicename, null);
10
+	}
11 11
 
12
-    /**
13
-     * removes all tags when setting
14
-     *
15
-     * @param string $value_inputted_for_field_on_model_object
16
-     * @return string
17
-     */
18
-    function prepare_for_set($value_inputted_for_field_on_model_object)
19
-    {
20
-        if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) {
21
-            $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID();
22
-        }
23
-        return wp_strip_all_tags($value_inputted_for_field_on_model_object);
24
-    }
12
+	/**
13
+	 * removes all tags when setting
14
+	 *
15
+	 * @param string $value_inputted_for_field_on_model_object
16
+	 * @return string
17
+	 */
18
+	function prepare_for_set($value_inputted_for_field_on_model_object)
19
+	{
20
+		if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) {
21
+			$value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID();
22
+		}
23
+		return wp_strip_all_tags($value_inputted_for_field_on_model_object);
24
+	}
25 25
 }
26 26
\ No newline at end of file
Please login to merge, or discard this patch.
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -4,6 +4,9 @@
 block discarded – undo
4 4
 class EE_Primary_Key_String_Field extends EE_Primary_Key_Field_Base
5 5
 {
6 6
 
7
+    /**
8
+     * @param string $table_column
9
+     */
7 10
     public function __construct($table_column, $nicename)
8 11
     {
9 12
         parent::__construct($table_column, $nicename, null);
Please login to merge, or discard this patch.
core/db_models/fields/EE_All_Caps_Text_Field.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -6,14 +6,14 @@
 block discarded – undo
6 6
  */
7 7
 class EE_All_Caps_Text_Field extends EE_Text_Field_Base
8 8
 {
9
-    /**
10
-     * makes it all upper case, and key-like
11
-     *
12
-     * @param string $value_inputted_for_field_on_model_object
13
-     * @return string
14
-     */
15
-    function prepare_for_set($value_inputted_for_field_on_model_object)
16
-    {
17
-        return strtoupper(sanitize_key($value_inputted_for_field_on_model_object));
18
-    }
9
+	/**
10
+	 * makes it all upper case, and key-like
11
+	 *
12
+	 * @param string $value_inputted_for_field_on_model_object
13
+	 * @return string
14
+	 */
15
+	function prepare_for_set($value_inputted_for_field_on_model_object)
16
+	{
17
+		return strtoupper(sanitize_key($value_inputted_for_field_on_model_object));
18
+	}
19 19
 }
20 20
\ No newline at end of file
Please login to merge, or discard this patch.
reg_steps/attendee_information/attendee_info_main.template.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 /** @var string $default_hidden_inputs */
5 5
 ?>
6 6
 	<p id="spco-attendee_information-pg" class="spco-steps-pg small-text drk-grey-text">
7
-		<?php echo apply_filters( 'FHEE__registration_page_attendee_information__attendee_information_pg', sprintf( __('In order to process your registration, we ask you to provide the following information.%1$sPlease note that all fields marked with an asterisk (%2$s) are required.', 'event_espresso'), '<br />', '<span class="asterisk">*</span>' )); ?>
7
+		<?php echo apply_filters('FHEE__registration_page_attendee_information__attendee_information_pg', sprintf(__('In order to process your registration, we ask you to provide the following information.%1$sPlease note that all fields marked with an asterisk (%2$s) are required.', 'event_espresso'), '<br />', '<span class="asterisk">*</span>')); ?>
8 8
 	</p>
9 9
 
10 10
 <?php
@@ -12,34 +12,34 @@  discard block
 block discarded – undo
12 12
 $prev_event = 0;
13 13
 $prev_ticket = 0;
14 14
 
15
-if ( count( $registrations ) > 0 ) {
16
-	foreach ( $registrations as $registration ) {
17
-		if ( $registration instanceof EE_Registration ) {
15
+if (count($registrations) > 0) {
16
+	foreach ($registrations as $registration) {
17
+		if ($registration instanceof EE_Registration) {
18 18
 			$att_nmbr++;
19 19
 ?>
20 20
 
21
-		<div id="spco-attendee-panel-dv-<?php echo $registration->reg_url_link();?>" class="spco-attendee-panel-dv spco-attendee-ticket-<?php echo $registration->ticket()->ID();?>">
21
+		<div id="spco-attendee-panel-dv-<?php echo $registration->reg_url_link(); ?>" class="spco-attendee-panel-dv spco-attendee-ticket-<?php echo $registration->ticket()->ID(); ?>">
22 22
 
23
-			<?php if ( $registration->event()->ID() !== $prev_event ) { ?>
23
+			<?php if ($registration->event()->ID() !== $prev_event) { ?>
24 24
 			<h4 id="event_title-<?php echo $registration->event()->ID() ?>" class="big-event-title-hdr">
25 25
 				<?php echo $registration->event()->name(); ?>
26 26
 			</h4>
27 27
 			<?php } ?>
28
-			<?php if ( $registration->ticket()->ID() !== $prev_ticket ) { ?>
29
-				<?php if ( ! $revisit ) { ?>
28
+			<?php if ($registration->ticket()->ID() !== $prev_ticket) { ?>
29
+				<?php if ( ! $revisit) { ?>
30 30
 			<div class="spco-ticket-info-dv small-text">
31
-				<h5><?php _e('Details', 'event_espresso');?></h5>
31
+				<h5><?php _e('Details', 'event_espresso'); ?></h5>
32 32
 				<table>
33 33
 					<thead>
34 34
 						<tr>
35
-							<th scope="col" width=""><?php _e('Name and Description', 'event_espresso');?></th>
36
-							<th scope="col" width="7.5%" class="jst-rght"><?php _e('Qty', 'event_espresso');?></th>
37
-							<th scope="col" width="17.5%" class="jst-rght"><?php _e('Price', 'event_espresso');?></th>
38
-							<th scope="col" width="17.5%" class="jst-rght"><?php _e('Total', 'event_espresso');?></th>
35
+							<th scope="col" width=""><?php _e('Name and Description', 'event_espresso'); ?></th>
36
+							<th scope="col" width="7.5%" class="jst-rght"><?php _e('Qty', 'event_espresso'); ?></th>
37
+							<th scope="col" width="17.5%" class="jst-rght"><?php _e('Price', 'event_espresso'); ?></th>
38
+							<th scope="col" width="17.5%" class="jst-rght"><?php _e('Total', 'event_espresso'); ?></th>
39 39
 						</tr>
40 40
 					</thead>
41 41
 					<tbody>
42
-					<?php echo $ticket_line_item[ $registration->ticket()->ID() ]; ?>
42
+					<?php echo $ticket_line_item[$registration->ticket()->ID()]; ?>
43 43
 					</tbody>
44 44
 				</table>
45 45
 			</div>
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 
49 49
 			<?php
50 50
 			// ATTENDEE QUESTIONS
51
-			$reg_form = EE_Template_Layout::get_subform_name( $registration->reg_url_link() );
51
+			$reg_form = EE_Template_Layout::get_subform_name($registration->reg_url_link());
52 52
 			echo ${$reg_form};
53 53
 			?>
54 54
 
Please login to merge, or discard this patch.