Completed
Branch back-compat-edtr-taxes (752e0e)
by
unknown
12:08 queued 09:43
created
core/db_models/helpers/EE_Secondary_Table.php 2 patches
Indentation   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -8,118 +8,118 @@
 block discarded – undo
8 8
  */
9 9
 class EE_Secondary_Table extends EE_Table_Base
10 10
 {
11
-    protected $_extra_join_conditions;
11
+	protected $_extra_join_conditions;
12 12
 
13
-    /**
14
-     *
15
-     * @global type $wpdb
16
-     * @param string $table_name with or without wpdb prefix
17
-     * @param string $pk_column name of primary key column on THIS table
18
-     * @param string $fk_column the name of the COLUMN that is a foreign key to the primary table's primary key
19
-     * @param string $extra_join_conditions string for additional SQL to add onto the join statement's ON condition
20
-     * @param boolean $global whether the table is "global" as in there is only 1 table on an entire multisite install,
21
-     *                  or whether each site on a multisite install has a copy of this table
22
-     */
23
-    public function __construct($table_name, $pk_column, $fk_column = null, $extra_join_conditions = null, $global = false)
24
-    {
25
-        $this->_fk_on_table = $fk_column;
26
-        $this->_extra_join_conditions = $extra_join_conditions;
27
-        parent::__construct($table_name, $pk_column, $global);
28
-    }
29
-    public function get_fk_on_table()
30
-    {
31
-        return $this->_fk_on_table;
32
-    }
33
-    public function _construct_finalize_set_table_to_join_with(EE_Table_Base $table)
34
-    {
35
-        $this->_table_to_join_with = $table;
36
-    }
37
-    /**
38
-     *
39
-     * @return string of sql like "Event.post_type = 'event'", which gets added to
40
-     * the end of the join statement with the primary table
41
-     */
42
-    public function get_extra_join_conditions()
43
-    {
44
-        return $this->_extra_join_conditions;
45
-    }
46
-    /**
47
-     *
48
-     * @return EE_Primary_Table
49
-     */
50
-    public function get_table_to_join_with()
51
-    {
52
-        return $this->_table_to_join_with;
53
-    }
54
-    /**
55
-     * creates join statement FROM primary table
56
-     * gets SQL like "LEFT JOIN table_name AS table_alias ON other_table_alias.pk = table_alias.fk
57
-     *
58
-     * @param string $table allows us to set special conditions on the $table_name portion of the join query (i.e. doing a subquery)
59
-     * @return string of SQL
60
-     */
61
-    public function get_join_sql($primary_table_alias_with_model_chain_prefix)
62
-    {
13
+	/**
14
+	 *
15
+	 * @global type $wpdb
16
+	 * @param string $table_name with or without wpdb prefix
17
+	 * @param string $pk_column name of primary key column on THIS table
18
+	 * @param string $fk_column the name of the COLUMN that is a foreign key to the primary table's primary key
19
+	 * @param string $extra_join_conditions string for additional SQL to add onto the join statement's ON condition
20
+	 * @param boolean $global whether the table is "global" as in there is only 1 table on an entire multisite install,
21
+	 *                  or whether each site on a multisite install has a copy of this table
22
+	 */
23
+	public function __construct($table_name, $pk_column, $fk_column = null, $extra_join_conditions = null, $global = false)
24
+	{
25
+		$this->_fk_on_table = $fk_column;
26
+		$this->_extra_join_conditions = $extra_join_conditions;
27
+		parent::__construct($table_name, $pk_column, $global);
28
+	}
29
+	public function get_fk_on_table()
30
+	{
31
+		return $this->_fk_on_table;
32
+	}
33
+	public function _construct_finalize_set_table_to_join_with(EE_Table_Base $table)
34
+	{
35
+		$this->_table_to_join_with = $table;
36
+	}
37
+	/**
38
+	 *
39
+	 * @return string of sql like "Event.post_type = 'event'", which gets added to
40
+	 * the end of the join statement with the primary table
41
+	 */
42
+	public function get_extra_join_conditions()
43
+	{
44
+		return $this->_extra_join_conditions;
45
+	}
46
+	/**
47
+	 *
48
+	 * @return EE_Primary_Table
49
+	 */
50
+	public function get_table_to_join_with()
51
+	{
52
+		return $this->_table_to_join_with;
53
+	}
54
+	/**
55
+	 * creates join statement FROM primary table
56
+	 * gets SQL like "LEFT JOIN table_name AS table_alias ON other_table_alias.pk = table_alias.fk
57
+	 *
58
+	 * @param string $table allows us to set special conditions on the $table_name portion of the join query (i.e. doing a subquery)
59
+	 * @return string of SQL
60
+	 */
61
+	public function get_join_sql($primary_table_alias_with_model_chain_prefix)
62
+	{
63 63
 
64
-        $table_name = $this->get_table_name();
65
-        $secondary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($primary_table_alias_with_model_chain_prefix) . $this->get_table_alias();
66
-        $other_table_pk = $this->get_table_to_join_with()->get_pk_column();
67
-        $fk = $this->get_fk_on_table();
68
-        $join_sql = " LEFT JOIN $table_name AS $secondary_table_alias ON $primary_table_alias_with_model_chain_prefix.$other_table_pk = $secondary_table_alias.$fk ";
69
-        if ($this->get_extra_join_conditions()) {
70
-            $join_sql .= "AND " . $this->get_extra_join_conditions();
71
-        }
72
-        return $join_sql;
73
-    }
64
+		$table_name = $this->get_table_name();
65
+		$secondary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($primary_table_alias_with_model_chain_prefix) . $this->get_table_alias();
66
+		$other_table_pk = $this->get_table_to_join_with()->get_pk_column();
67
+		$fk = $this->get_fk_on_table();
68
+		$join_sql = " LEFT JOIN $table_name AS $secondary_table_alias ON $primary_table_alias_with_model_chain_prefix.$other_table_pk = $secondary_table_alias.$fk ";
69
+		if ($this->get_extra_join_conditions()) {
70
+			$join_sql .= "AND " . $this->get_extra_join_conditions();
71
+		}
72
+		return $join_sql;
73
+	}
74 74
 
75 75
 
76
-    /**
77
-     * Produces join SQL like get_join_sql, except instead of joining the primary table to the
78
-     * secondary table, does the inverse: joins the secondary table to the primary one. (Eg, isntead of
79
-     * " LEFT JOIN secondary_table_table AS Secondary ON ..." like get_join_sql, this function returns
80
-     * " LEFT JOIN primary_table AS Primary ON ...".
81
-     * This is useful if the secondary table is already included in the SQL, but the primary table is not yet.
82
-     * @return string
83
-     */
84
-    public function get_inverse_join_sql($secondary_table_alias_with_model_chain_prefix)
85
-    {
86
-        $primary_table_name = $this->get_table_to_join_with()->get_table_name();
87
-        $primary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($secondary_table_alias_with_model_chain_prefix) . $this->get_table_to_join_with()->get_table_alias();
88
-        $primary_table_pk = $this->get_table_to_join_with()->get_pk_column();// $this->get_pk_column();
89
-        $fk = $this->get_fk_on_table();
90
-        $join_sql = " LEFT JOIN $primary_table_name AS $primary_table_alias ON $primary_table_alias.$primary_table_pk = $secondary_table_alias_with_model_chain_prefix.$fk ";
91
-        if ($this->get_extra_join_conditions()) {
92
-            $join_sql .= "AND " . $this->get_extra_join_conditions();
93
-        }
94
-        return $join_sql;
95
-    }
76
+	/**
77
+	 * Produces join SQL like get_join_sql, except instead of joining the primary table to the
78
+	 * secondary table, does the inverse: joins the secondary table to the primary one. (Eg, isntead of
79
+	 * " LEFT JOIN secondary_table_table AS Secondary ON ..." like get_join_sql, this function returns
80
+	 * " LEFT JOIN primary_table AS Primary ON ...".
81
+	 * This is useful if the secondary table is already included in the SQL, but the primary table is not yet.
82
+	 * @return string
83
+	 */
84
+	public function get_inverse_join_sql($secondary_table_alias_with_model_chain_prefix)
85
+	{
86
+		$primary_table_name = $this->get_table_to_join_with()->get_table_name();
87
+		$primary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($secondary_table_alias_with_model_chain_prefix) . $this->get_table_to_join_with()->get_table_alias();
88
+		$primary_table_pk = $this->get_table_to_join_with()->get_pk_column();// $this->get_pk_column();
89
+		$fk = $this->get_fk_on_table();
90
+		$join_sql = " LEFT JOIN $primary_table_name AS $primary_table_alias ON $primary_table_alias.$primary_table_pk = $secondary_table_alias_with_model_chain_prefix.$fk ";
91
+		if ($this->get_extra_join_conditions()) {
92
+			$join_sql .= "AND " . $this->get_extra_join_conditions();
93
+		}
94
+		return $join_sql;
95
+	}
96 96
 
97
-    /**
98
-     * This prepares the join on the other table using a select with a internal limit.
99
-     * @param  mixed (array|string) $limit limit
100
-     * @return string                       SQL to return
101
-     */
102
-    public function get_select_join_limit_join($limit)
103
-    {
104
-        // first get the select
105
-        $select = $this->get_select_join_limit($limit);
106
-        $join_sql = $this->get_join_sql($select);
107
-        return $join_sql;
108
-    }
97
+	/**
98
+	 * This prepares the join on the other table using a select with a internal limit.
99
+	 * @param  mixed (array|string) $limit limit
100
+	 * @return string                       SQL to return
101
+	 */
102
+	public function get_select_join_limit_join($limit)
103
+	{
104
+		// first get the select
105
+		$select = $this->get_select_join_limit($limit);
106
+		$join_sql = $this->get_join_sql($select);
107
+		return $join_sql;
108
+	}
109 109
 
110 110
 
111 111
 
112
-    public function get_fully_qualified_fk_column()
113
-    {
114
-        $table_alias = $this->get_table_alias();
115
-        $fk = $this->get_fk_on_table();
116
-        return $table_alias . '.' . $fk;
117
-    }
112
+	public function get_fully_qualified_fk_column()
113
+	{
114
+		$table_alias = $this->get_table_alias();
115
+		$fk = $this->get_fk_on_table();
116
+		return $table_alias . '.' . $fk;
117
+	}
118 118
 
119
-    public function get_fully_qualified_pk_on_fk_table()
120
-    {
121
-        $table_alias = $this->get_table_to_join_with()->get_table_alias();
122
-        $pk = $this->get_table_to_join_with()->get_pk_column();
123
-        return $table_alias . '.' . $pk;
124
-    }
119
+	public function get_fully_qualified_pk_on_fk_table()
120
+	{
121
+		$table_alias = $this->get_table_to_join_with()->get_table_alias();
122
+		$pk = $this->get_table_to_join_with()->get_pk_column();
123
+		return $table_alias . '.' . $pk;
124
+	}
125 125
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -62,12 +62,12 @@  discard block
 block discarded – undo
62 62
     {
63 63
 
64 64
         $table_name = $this->get_table_name();
65
-        $secondary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($primary_table_alias_with_model_chain_prefix) . $this->get_table_alias();
65
+        $secondary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($primary_table_alias_with_model_chain_prefix).$this->get_table_alias();
66 66
         $other_table_pk = $this->get_table_to_join_with()->get_pk_column();
67 67
         $fk = $this->get_fk_on_table();
68 68
         $join_sql = " LEFT JOIN $table_name AS $secondary_table_alias ON $primary_table_alias_with_model_chain_prefix.$other_table_pk = $secondary_table_alias.$fk ";
69 69
         if ($this->get_extra_join_conditions()) {
70
-            $join_sql .= "AND " . $this->get_extra_join_conditions();
70
+            $join_sql .= "AND ".$this->get_extra_join_conditions();
71 71
         }
72 72
         return $join_sql;
73 73
     }
@@ -84,12 +84,12 @@  discard block
 block discarded – undo
84 84
     public function get_inverse_join_sql($secondary_table_alias_with_model_chain_prefix)
85 85
     {
86 86
         $primary_table_name = $this->get_table_to_join_with()->get_table_name();
87
-        $primary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($secondary_table_alias_with_model_chain_prefix) . $this->get_table_to_join_with()->get_table_alias();
88
-        $primary_table_pk = $this->get_table_to_join_with()->get_pk_column();// $this->get_pk_column();
87
+        $primary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($secondary_table_alias_with_model_chain_prefix).$this->get_table_to_join_with()->get_table_alias();
88
+        $primary_table_pk = $this->get_table_to_join_with()->get_pk_column(); // $this->get_pk_column();
89 89
         $fk = $this->get_fk_on_table();
90 90
         $join_sql = " LEFT JOIN $primary_table_name AS $primary_table_alias ON $primary_table_alias.$primary_table_pk = $secondary_table_alias_with_model_chain_prefix.$fk ";
91 91
         if ($this->get_extra_join_conditions()) {
92
-            $join_sql .= "AND " . $this->get_extra_join_conditions();
92
+            $join_sql .= "AND ".$this->get_extra_join_conditions();
93 93
         }
94 94
         return $join_sql;
95 95
     }
@@ -113,13 +113,13 @@  discard block
 block discarded – undo
113 113
     {
114 114
         $table_alias = $this->get_table_alias();
115 115
         $fk = $this->get_fk_on_table();
116
-        return $table_alias . '.' . $fk;
116
+        return $table_alias.'.'.$fk;
117 117
     }
118 118
 
119 119
     public function get_fully_qualified_pk_on_fk_table()
120 120
     {
121 121
         $table_alias = $this->get_table_to_join_with()->get_table_alias();
122 122
         $pk = $this->get_table_to_join_with()->get_pk_column();
123
-        return $table_alias . '.' . $pk;
123
+        return $table_alias.'.'.$pk;
124 124
     }
125 125
 }
Please login to merge, or discard this patch.
core/db_models/helpers/EE_Index.php 2 patches
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -6,45 +6,45 @@
 block discarded – undo
6 6
  */
7 7
 class EE_Index
8 8
 {
9
-    protected $_name;
10
-    protected $_field_names;
11
-    protected $_model_name;
12
-    public function __construct($fields)
13
-    {
14
-        $this->_field_names = $fields;
15
-    }
16
-    public function _construct_finalize($name, $model_name)
17
-    {
18
-        $this->_name = $name;
19
-        $this->_model_name = $model_name;
20
-    }
21
-    public function field_names()
22
-    {
23
-        return $this->_field_names;
24
-    }
25
-    /**
26
-     * Internally used by get_this_model() and get_other_model()
27
-     * @param string $model_name like Event, Question_Group, etc. omit the EEM_
28
-     * @return EEM_Base
29
-     */
30
-    protected function _get_model($model_name)
31
-    {
32
-        $modelInstance = call_user_func("EEM_" . $model_name . "::instance");
33
-        return $modelInstance;
34
-    }
35
-    /**
36
-     * Gets all the fields for this index
37
-     * @return EE_Model_Field_Base[]
38
-     */
39
-    public function fields()
40
-    {
41
-        $fields = array();
42
-        $model = $this->_get_model($this->_model_name);
43
-        foreach ($model->field_settings() as $field_name => $field_obj) {
44
-            if (in_array($field_name, $this->field_names())) {
45
-                $fields[ $field_name ] = $field_obj;
46
-            }
47
-        }
48
-        return $fields;
49
-    }
9
+	protected $_name;
10
+	protected $_field_names;
11
+	protected $_model_name;
12
+	public function __construct($fields)
13
+	{
14
+		$this->_field_names = $fields;
15
+	}
16
+	public function _construct_finalize($name, $model_name)
17
+	{
18
+		$this->_name = $name;
19
+		$this->_model_name = $model_name;
20
+	}
21
+	public function field_names()
22
+	{
23
+		return $this->_field_names;
24
+	}
25
+	/**
26
+	 * Internally used by get_this_model() and get_other_model()
27
+	 * @param string $model_name like Event, Question_Group, etc. omit the EEM_
28
+	 * @return EEM_Base
29
+	 */
30
+	protected function _get_model($model_name)
31
+	{
32
+		$modelInstance = call_user_func("EEM_" . $model_name . "::instance");
33
+		return $modelInstance;
34
+	}
35
+	/**
36
+	 * Gets all the fields for this index
37
+	 * @return EE_Model_Field_Base[]
38
+	 */
39
+	public function fields()
40
+	{
41
+		$fields = array();
42
+		$model = $this->_get_model($this->_model_name);
43
+		foreach ($model->field_settings() as $field_name => $field_obj) {
44
+			if (in_array($field_name, $this->field_names())) {
45
+				$fields[ $field_name ] = $field_obj;
46
+			}
47
+		}
48
+		return $fields;
49
+	}
50 50
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
      */
30 30
     protected function _get_model($model_name)
31 31
     {
32
-        $modelInstance = call_user_func("EEM_" . $model_name . "::instance");
32
+        $modelInstance = call_user_func("EEM_".$model_name."::instance");
33 33
         return $modelInstance;
34 34
     }
35 35
     /**
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
         $model = $this->_get_model($this->_model_name);
43 43
         foreach ($model->field_settings() as $field_name => $field_obj) {
44 44
             if (in_array($field_name, $this->field_names())) {
45
-                $fields[ $field_name ] = $field_obj;
45
+                $fields[$field_name] = $field_obj;
46 46
             }
47 47
         }
48 48
         return $fields;
Please login to merge, or discard this patch.
core/db_models/helpers/EE_Primary_Table.php 2 patches
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -7,24 +7,24 @@
 block discarded – undo
7 7
 class EE_Primary_Table extends EE_Table_Base
8 8
 {
9 9
 
10
-    /**
11
-     *
12
-     * @global type $wpdb
13
-     * @param string $table_name with or without wpdb prefix
14
-     * @param string $pk_column name of primary key column
15
-     * @param boolean $global whether the table is "global" as in there is only 1 table on an entire multisite install,
16
-     *                  or whether each site on a multisite install has a copy of this table
17
-     */
18
-    public function __construct($table_name, $pk_column = null, $global = false)
19
-    {
20
-        parent::__construct($table_name, $pk_column, $global);
21
-    }
22
-    /**
23
-     * Gets SQL for this table and assigning it an alias. Eg " wp_esp_attendee AS Attendee "
24
-     * @return string
25
-     */
26
-    public function get_table_sql()
27
-    {
28
-        return " " . $this->get_table_name() . " AS " . $this->get_table_alias() . " ";
29
-    }
10
+	/**
11
+	 *
12
+	 * @global type $wpdb
13
+	 * @param string $table_name with or without wpdb prefix
14
+	 * @param string $pk_column name of primary key column
15
+	 * @param boolean $global whether the table is "global" as in there is only 1 table on an entire multisite install,
16
+	 *                  or whether each site on a multisite install has a copy of this table
17
+	 */
18
+	public function __construct($table_name, $pk_column = null, $global = false)
19
+	{
20
+		parent::__construct($table_name, $pk_column, $global);
21
+	}
22
+	/**
23
+	 * Gets SQL for this table and assigning it an alias. Eg " wp_esp_attendee AS Attendee "
24
+	 * @return string
25
+	 */
26
+	public function get_table_sql()
27
+	{
28
+		return " " . $this->get_table_name() . " AS " . $this->get_table_alias() . " ";
29
+	}
30 30
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -25,6 +25,6 @@
 block discarded – undo
25 25
      */
26 26
     public function get_table_sql()
27 27
     {
28
-        return " " . $this->get_table_name() . " AS " . $this->get_table_alias() . " ";
28
+        return " ".$this->get_table_name()." AS ".$this->get_table_alias()." ";
29 29
     }
30 30
 }
Please login to merge, or discard this patch.
core/db_models/EEM_State.model.php 2 patches
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
             'Venue' => new EE_Has_Many_Relation(),
43 43
         );
44 44
         // this model is generally available for reading
45
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
45
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
46 46
         // @todo: only show STA_active
47 47
         parent::__construct($timezone);
48 48
     }
@@ -73,8 +73,8 @@  discard block
 block discarded – undo
73 73
     */
74 74
     public function get_all_states()
75 75
     {
76
-        if (! self::$_all_states) {
77
-            self::$_all_states = $this->get_all(array( 'order_by' => array( 'STA_name' => 'ASC' ), 'limit' => array( 0, 99999 )));
76
+        if ( ! self::$_all_states) {
77
+            self::$_all_states = $this->get_all(array('order_by' => array('STA_name' => 'ASC'), 'limit' => array(0, 99999)));
78 78
         }
79 79
         return self::$_all_states;
80 80
     }
@@ -91,13 +91,13 @@  discard block
 block discarded – undo
91 91
      */
92 92
     public function get_all_active_states($countries = array(), $flush_cache = false)
93 93
     {
94
-        if (! self::$_active_states || $flush_cache) {
94
+        if ( ! self::$_active_states || $flush_cache) {
95 95
             $countries = is_array($countries) && ! empty($countries) ? $countries : EEM_Country::instance()->get_all_active_countries();
96
-            self::$_active_states =  $this->get_all(array(
97
-                array( 'STA_active' => true, 'CNT_ISO' => array( 'IN', array_keys($countries))),
98
-                'order_by' => array( 'STA_name' => 'ASC' ),
99
-                'limit' => array( 0, 99999 ),
100
-                'force_join' => array( 'Country' )
96
+            self::$_active_states = $this->get_all(array(
97
+                array('STA_active' => true, 'CNT_ISO' => array('IN', array_keys($countries))),
98
+                'order_by' => array('STA_name' => 'ASC'),
99
+                'limit' => array(0, 99999),
100
+                'force_join' => array('Country')
101 101
             ));
102 102
         }
103 103
         return self::$_active_states;
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
      */
112 112
     public function get_all_states_of_active_countries()
113 113
     {
114
-        if ($states = $this->get_all(array( array( 'Country.CNT_active' => true, 'STA_active' => true ),  'order_by' => array( 'Country.CNT_name' => 'ASC', 'STA_name' => 'ASC' )))) {
114
+        if ($states = $this->get_all(array(array('Country.CNT_active' => true, 'STA_active' => true), 'order_by' => array('Country.CNT_name' => 'ASC', 'STA_name' => 'ASC')))) {
115 115
             return $states;
116 116
         }
117 117
         return false;
@@ -125,10 +125,10 @@  discard block
 block discarded – undo
125 125
      */
126 126
     public function get_all_active_states_for_these_countries($countries)
127 127
     {
128
-        if (! $countries) {
128
+        if ( ! $countries) {
129 129
             return false;
130 130
         }
131
-        if ($states = $this->get_all(array(  array( 'Country.CNT_ISO' => array( 'IN', array_keys($countries)), 'STA_active' => true ),  'order_by' => array( 'Country.CNT_name' => 'ASC', 'STA_name' => 'ASC' )))) {
131
+        if ($states = $this->get_all(array(array('Country.CNT_ISO' => array('IN', array_keys($countries)), 'STA_active' => true), 'order_by' => array('Country.CNT_name' => 'ASC', 'STA_name' => 'ASC')))) {
132 132
             return $states;
133 133
         }
134 134
         return false;
@@ -142,10 +142,10 @@  discard block
 block discarded – undo
142 142
      */
143 143
     public function get_all_states_for_these_countries($countries)
144 144
     {
145
-        if (! $countries) {
145
+        if ( ! $countries) {
146 146
             return false;
147 147
         }
148
-        if ($states = $this->get_all(array( array( 'Country.CNT_ISO' => array( 'IN', array_keys($countries))),  'order_by' => array( 'Country.CNT_name' => 'ASC', 'STA_name' => 'ASC' )))) {
148
+        if ($states = $this->get_all(array(array('Country.CNT_ISO' => array('IN', array_keys($countries))), 'order_by' => array('Country.CNT_name' => 'ASC', 'STA_name' => 'ASC')))) {
149 149
             return $states;
150 150
         }
151 151
         return false;
@@ -159,12 +159,12 @@  discard block
 block discarded – undo
159 159
     public function get_state_name_by_ID($state_ID)
160 160
     {
161 161
         if (
162
-            isset(self::$_all_states[ $state_ID ]) &&
163
-                self::$_all_states[ $state_ID ] instanceof EE_State
162
+            isset(self::$_all_states[$state_ID]) &&
163
+                self::$_all_states[$state_ID] instanceof EE_State
164 164
         ) {
165
-            return self::$_all_states[ $state_ID ]->name();
165
+            return self::$_all_states[$state_ID]->name();
166 166
         }
167
-        $names = $this->get_col(array( array( 'STA_ID' => $state_ID ), 'limit' => 1), 'STA_name');
167
+        $names = $this->get_col(array(array('STA_ID' => $state_ID), 'limit' => 1), 'STA_name');
168 168
         if (is_array($names) && ! empty($names)) {
169 169
             return reset($names);
170 170
         } else {
Please login to merge, or discard this patch.
Indentation   +159 added lines, -159 removed lines patch added patch discarded remove patch
@@ -12,163 +12,163 @@
 block discarded – undo
12 12
 class EEM_State extends EEM_Base
13 13
 {
14 14
 
15
-    // private instance of the Attendee object
16
-    protected static $_instance = null;
17
-    // array of all states
18
-    private static $_all_states = false;
19
-    // array of all active states
20
-    private static $_active_states = false;
21
-
22
-    protected function __construct($timezone = null)
23
-    {
24
-        $this->singular_item = esc_html__('State/Province', 'event_espresso');
25
-        $this->plural_item = esc_html__('States/Provinces', 'event_espresso');
26
-
27
-        $this->_tables = array(
28
-            'State' => new EE_Primary_Table('esp_state', 'STA_ID')
29
-        );
30
-
31
-        $this->_fields = array(
32
-            'State' => array(
33
-                'STA_ID' => new EE_Primary_Key_Int_Field('STA_ID', esc_html__('State ID', 'event_espresso')),
34
-                'CNT_ISO' => new EE_Foreign_Key_String_Field('CNT_ISO', esc_html__('Country ISO Code', 'event_espresso'), false, null, 'Country'),
35
-                'STA_abbrev' => new EE_Plain_Text_Field('STA_abbrev', esc_html__('State Abbreviation', 'event_espresso'), false, ''),
36
-                'STA_name' => new EE_Plain_Text_Field('STA_name', esc_html__('State Name', 'event_espresso'), false, ''),
37
-                'STA_active' => new EE_Boolean_Field('STA_active', esc_html__('State Active Flag', 'event_espresso'), false, false)
38
-                ));
39
-        $this->_model_relations = array(
40
-            'Attendee' => new EE_Has_Many_Relation(),
41
-            'Country' => new EE_Belongs_To_Relation(),
42
-            'Venue' => new EE_Has_Many_Relation(),
43
-        );
44
-        // this model is generally available for reading
45
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
46
-        // @todo: only show STA_active
47
-        parent::__construct($timezone);
48
-    }
49
-
50
-
51
-
52
-
53
-    /**
54
-    *   reset_cached_states
55
-    *
56
-    *   @access     private
57
-    *   @return         void
58
-    */
59
-    public function reset_cached_states()
60
-    {
61
-        EEM_State::$_active_states = array();
62
-        EEM_State::$_all_states = array();
63
-    }
64
-
65
-
66
-
67
-
68
-    /**
69
-    *       _get_states
70
-    *
71
-    *       @access     private
72
-    *       @return         array
73
-    */
74
-    public function get_all_states()
75
-    {
76
-        if (! self::$_all_states) {
77
-            self::$_all_states = $this->get_all(array( 'order_by' => array( 'STA_name' => 'ASC' ), 'limit' => array( 0, 99999 )));
78
-        }
79
-        return self::$_all_states;
80
-    }
81
-
82
-
83
-
84
-    /**
85
-     *        _get_states
86
-     *
87
-     * @access        public
88
-     * @param array $countries
89
-     * @param bool  $flush_cache
90
-     * @return        array
91
-     */
92
-    public function get_all_active_states($countries = array(), $flush_cache = false)
93
-    {
94
-        if (! self::$_active_states || $flush_cache) {
95
-            $countries = is_array($countries) && ! empty($countries) ? $countries : EEM_Country::instance()->get_all_active_countries();
96
-            self::$_active_states =  $this->get_all(array(
97
-                array( 'STA_active' => true, 'CNT_ISO' => array( 'IN', array_keys($countries))),
98
-                'order_by' => array( 'STA_name' => 'ASC' ),
99
-                'limit' => array( 0, 99999 ),
100
-                'force_join' => array( 'Country' )
101
-            ));
102
-        }
103
-        return self::$_active_states;
104
-    }
105
-
106
-
107
-
108
-    /**
109
-     *  get_all_states_of_active_countries
110
-     * @return array
111
-     */
112
-    public function get_all_states_of_active_countries()
113
-    {
114
-        if ($states = $this->get_all(array( array( 'Country.CNT_active' => true, 'STA_active' => true ),  'order_by' => array( 'Country.CNT_name' => 'ASC', 'STA_name' => 'ASC' )))) {
115
-            return $states;
116
-        }
117
-        return false;
118
-    }
119
-
120
-
121
-
122
-    /**
123
-     *  get_all_states_of_active_countries
124
-     * @return array
125
-     */
126
-    public function get_all_active_states_for_these_countries($countries)
127
-    {
128
-        if (! $countries) {
129
-            return false;
130
-        }
131
-        if ($states = $this->get_all(array(  array( 'Country.CNT_ISO' => array( 'IN', array_keys($countries)), 'STA_active' => true ),  'order_by' => array( 'Country.CNT_name' => 'ASC', 'STA_name' => 'ASC' )))) {
132
-            return $states;
133
-        }
134
-        return false;
135
-    }
136
-
137
-
138
-
139
-    /**
140
-     *  get_all_states_of_active_countries
141
-     * @return array
142
-     */
143
-    public function get_all_states_for_these_countries($countries)
144
-    {
145
-        if (! $countries) {
146
-            return false;
147
-        }
148
-        if ($states = $this->get_all(array( array( 'Country.CNT_ISO' => array( 'IN', array_keys($countries))),  'order_by' => array( 'Country.CNT_name' => 'ASC', 'STA_name' => 'ASC' )))) {
149
-            return $states;
150
-        }
151
-        return false;
152
-    }
153
-
154
-    /**
155
-     * Gets the state's name by its ID
156
-     * @param string $state_ID
157
-     * @return string
158
-     */
159
-    public function get_state_name_by_ID($state_ID)
160
-    {
161
-        if (
162
-            isset(self::$_all_states[ $state_ID ]) &&
163
-                self::$_all_states[ $state_ID ] instanceof EE_State
164
-        ) {
165
-            return self::$_all_states[ $state_ID ]->name();
166
-        }
167
-        $names = $this->get_col(array( array( 'STA_ID' => $state_ID ), 'limit' => 1), 'STA_name');
168
-        if (is_array($names) && ! empty($names)) {
169
-            return reset($names);
170
-        } else {
171
-            return '';
172
-        }
173
-    }
15
+	// private instance of the Attendee object
16
+	protected static $_instance = null;
17
+	// array of all states
18
+	private static $_all_states = false;
19
+	// array of all active states
20
+	private static $_active_states = false;
21
+
22
+	protected function __construct($timezone = null)
23
+	{
24
+		$this->singular_item = esc_html__('State/Province', 'event_espresso');
25
+		$this->plural_item = esc_html__('States/Provinces', 'event_espresso');
26
+
27
+		$this->_tables = array(
28
+			'State' => new EE_Primary_Table('esp_state', 'STA_ID')
29
+		);
30
+
31
+		$this->_fields = array(
32
+			'State' => array(
33
+				'STA_ID' => new EE_Primary_Key_Int_Field('STA_ID', esc_html__('State ID', 'event_espresso')),
34
+				'CNT_ISO' => new EE_Foreign_Key_String_Field('CNT_ISO', esc_html__('Country ISO Code', 'event_espresso'), false, null, 'Country'),
35
+				'STA_abbrev' => new EE_Plain_Text_Field('STA_abbrev', esc_html__('State Abbreviation', 'event_espresso'), false, ''),
36
+				'STA_name' => new EE_Plain_Text_Field('STA_name', esc_html__('State Name', 'event_espresso'), false, ''),
37
+				'STA_active' => new EE_Boolean_Field('STA_active', esc_html__('State Active Flag', 'event_espresso'), false, false)
38
+				));
39
+		$this->_model_relations = array(
40
+			'Attendee' => new EE_Has_Many_Relation(),
41
+			'Country' => new EE_Belongs_To_Relation(),
42
+			'Venue' => new EE_Has_Many_Relation(),
43
+		);
44
+		// this model is generally available for reading
45
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
46
+		// @todo: only show STA_active
47
+		parent::__construct($timezone);
48
+	}
49
+
50
+
51
+
52
+
53
+	/**
54
+	 *   reset_cached_states
55
+	 *
56
+	 *   @access     private
57
+	 *   @return         void
58
+	 */
59
+	public function reset_cached_states()
60
+	{
61
+		EEM_State::$_active_states = array();
62
+		EEM_State::$_all_states = array();
63
+	}
64
+
65
+
66
+
67
+
68
+	/**
69
+	 *       _get_states
70
+	 *
71
+	 *       @access     private
72
+	 *       @return         array
73
+	 */
74
+	public function get_all_states()
75
+	{
76
+		if (! self::$_all_states) {
77
+			self::$_all_states = $this->get_all(array( 'order_by' => array( 'STA_name' => 'ASC' ), 'limit' => array( 0, 99999 )));
78
+		}
79
+		return self::$_all_states;
80
+	}
81
+
82
+
83
+
84
+	/**
85
+	 *        _get_states
86
+	 *
87
+	 * @access        public
88
+	 * @param array $countries
89
+	 * @param bool  $flush_cache
90
+	 * @return        array
91
+	 */
92
+	public function get_all_active_states($countries = array(), $flush_cache = false)
93
+	{
94
+		if (! self::$_active_states || $flush_cache) {
95
+			$countries = is_array($countries) && ! empty($countries) ? $countries : EEM_Country::instance()->get_all_active_countries();
96
+			self::$_active_states =  $this->get_all(array(
97
+				array( 'STA_active' => true, 'CNT_ISO' => array( 'IN', array_keys($countries))),
98
+				'order_by' => array( 'STA_name' => 'ASC' ),
99
+				'limit' => array( 0, 99999 ),
100
+				'force_join' => array( 'Country' )
101
+			));
102
+		}
103
+		return self::$_active_states;
104
+	}
105
+
106
+
107
+
108
+	/**
109
+	 *  get_all_states_of_active_countries
110
+	 * @return array
111
+	 */
112
+	public function get_all_states_of_active_countries()
113
+	{
114
+		if ($states = $this->get_all(array( array( 'Country.CNT_active' => true, 'STA_active' => true ),  'order_by' => array( 'Country.CNT_name' => 'ASC', 'STA_name' => 'ASC' )))) {
115
+			return $states;
116
+		}
117
+		return false;
118
+	}
119
+
120
+
121
+
122
+	/**
123
+	 *  get_all_states_of_active_countries
124
+	 * @return array
125
+	 */
126
+	public function get_all_active_states_for_these_countries($countries)
127
+	{
128
+		if (! $countries) {
129
+			return false;
130
+		}
131
+		if ($states = $this->get_all(array(  array( 'Country.CNT_ISO' => array( 'IN', array_keys($countries)), 'STA_active' => true ),  'order_by' => array( 'Country.CNT_name' => 'ASC', 'STA_name' => 'ASC' )))) {
132
+			return $states;
133
+		}
134
+		return false;
135
+	}
136
+
137
+
138
+
139
+	/**
140
+	 *  get_all_states_of_active_countries
141
+	 * @return array
142
+	 */
143
+	public function get_all_states_for_these_countries($countries)
144
+	{
145
+		if (! $countries) {
146
+			return false;
147
+		}
148
+		if ($states = $this->get_all(array( array( 'Country.CNT_ISO' => array( 'IN', array_keys($countries))),  'order_by' => array( 'Country.CNT_name' => 'ASC', 'STA_name' => 'ASC' )))) {
149
+			return $states;
150
+		}
151
+		return false;
152
+	}
153
+
154
+	/**
155
+	 * Gets the state's name by its ID
156
+	 * @param string $state_ID
157
+	 * @return string
158
+	 */
159
+	public function get_state_name_by_ID($state_ID)
160
+	{
161
+		if (
162
+			isset(self::$_all_states[ $state_ID ]) &&
163
+				self::$_all_states[ $state_ID ] instanceof EE_State
164
+		) {
165
+			return self::$_all_states[ $state_ID ]->name();
166
+		}
167
+		$names = $this->get_col(array( array( 'STA_ID' => $state_ID ), 'limit' => 1), 'STA_name');
168
+		if (is_array($names) && ! empty($names)) {
169
+			return reset($names);
170
+		} else {
171
+			return '';
172
+		}
173
+	}
174 174
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Ticket_Template.model.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -43,11 +43,11 @@
 block discarded – undo
43 43
             'Ticket' => new EE_Has_Many_Relation()
44 44
         );
45 45
         $this->_model_chain_to_wp_user = 'Ticket';
46
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
46
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
47 47
         // account for default tickets in the caps
48
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
49
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
50
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
48
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
49
+        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
50
+        $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
51 51
         parent::__construct($timezone);
52 52
     }
53 53
 }
Please login to merge, or discard this patch.
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -14,40 +14,40 @@
 block discarded – undo
14 14
 
15 15
 
16 16
 
17
-    // private instance of the EEM_Ticket_Template object
18
-    protected static $_instance = null;
17
+	// private instance of the EEM_Ticket_Template object
18
+	protected static $_instance = null;
19 19
 
20
-    /**
21
-     *      private constructor to prevent direct creation
22
-     *      @Constructor
23
-     *      @access private
24
-     *      @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
25
-     *      @return void
26
-     */
27
-    protected function __construct($timezone)
28
-    {
29
-        $this->singular_item = esc_html__('Ticket Template', 'event_espresso');
30
-        $this->plural_item = esc_html__('Ticket Templates', 'event_espresso');
20
+	/**
21
+	 *      private constructor to prevent direct creation
22
+	 *      @Constructor
23
+	 *      @access private
24
+	 *      @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
25
+	 *      @return void
26
+	 */
27
+	protected function __construct($timezone)
28
+	{
29
+		$this->singular_item = esc_html__('Ticket Template', 'event_espresso');
30
+		$this->plural_item = esc_html__('Ticket Templates', 'event_espresso');
31 31
 
32
-        $this->_tables = array(
33
-            'Ticket_Template' => new EE_Primary_Table('esp_ticket_template', 'TTM_ID')
34
-        );
35
-        $this->_fields = array(
36
-            'Ticket_Template' => array(
37
-                'TTM_ID' => new EE_Primary_Key_Int_Field('TTM_ID', esc_html__('Ticket Template ID', 'event_espresso')),
38
-                'TTM_name' => new EE_Plain_Text_Field('TTM_name', esc_html__('The name of the ticket template', 'event_espresso'), false, ''),
39
-                'TTM_description' => new EE_Plain_Text_Field('TTM_description', esc_html__('The description for the ticket template', 'event_espresso'), true, ''),
40
-                'TTM_file' => new EE_Plain_Text_Field('TTM_file', esc_html__('The file name for the actual template file saved on disk', 'event_espresso'), true, ''),
41
-            ));
42
-        $this->_model_relations = array(
43
-            'Ticket' => new EE_Has_Many_Relation()
44
-        );
45
-        $this->_model_chain_to_wp_user = 'Ticket';
46
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
47
-        // account for default tickets in the caps
48
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
49
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
50
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
51
-        parent::__construct($timezone);
52
-    }
32
+		$this->_tables = array(
33
+			'Ticket_Template' => new EE_Primary_Table('esp_ticket_template', 'TTM_ID')
34
+		);
35
+		$this->_fields = array(
36
+			'Ticket_Template' => array(
37
+				'TTM_ID' => new EE_Primary_Key_Int_Field('TTM_ID', esc_html__('Ticket Template ID', 'event_espresso')),
38
+				'TTM_name' => new EE_Plain_Text_Field('TTM_name', esc_html__('The name of the ticket template', 'event_espresso'), false, ''),
39
+				'TTM_description' => new EE_Plain_Text_Field('TTM_description', esc_html__('The description for the ticket template', 'event_espresso'), true, ''),
40
+				'TTM_file' => new EE_Plain_Text_Field('TTM_file', esc_html__('The file name for the actual template file saved on disk', 'event_espresso'), true, ''),
41
+			));
42
+		$this->_model_relations = array(
43
+			'Ticket' => new EE_Has_Many_Relation()
44
+		);
45
+		$this->_model_chain_to_wp_user = 'Ticket';
46
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
47
+		// account for default tickets in the caps
48
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
49
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
50
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
51
+		parent::__construct($timezone);
52
+	}
53 53
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Answer.model.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
      */
99 99
     public function get_registration_question_answer_object(EE_Registration $registration, $question_id = null)
100 100
     {
101
-        $answer_obj = $this->get_one(array( array( 'QST_ID' => $question_id, 'REG_ID' => $registration->ID() )));
101
+        $answer_obj = $this->get_one(array(array('QST_ID' => $question_id, 'REG_ID' => $registration->ID())));
102 102
         return apply_filters('FHEE__EEM_Answer__get_registration_question_answer_object__answer_obj', $answer_obj, $registration, $question_id);
103 103
     }
104 104
 
@@ -121,9 +121,9 @@  discard block
 block discarded – undo
121 121
         if (is_numeric($question_system_id)) {
122 122
             // find this question's QST_system value
123 123
             $question_id = $question_system_id;
124
-            $question_system_id = EEM_Question::instance()->get_var(array( array( 'QST_ID' => $question_system_id ) ), 'QST_system');
124
+            $question_system_id = EEM_Question::instance()->get_var(array(array('QST_ID' => $question_system_id)), 'QST_system');
125 125
         } else {
126
-            $question_id = (int) EEM_Question::instance()->get_var(array( array( 'QST_system' => $question_system_id ) ), 'QST_ID');
126
+            $question_id = (int) EEM_Question::instance()->get_var(array(array('QST_system' => $question_system_id)), 'QST_ID');
127 127
         }
128 128
         // only bother checking if the registration has an attendee
129 129
         if ($registration->attendee() instanceof EE_Attendee) {
Please login to merge, or discard this patch.
Indentation   +125 added lines, -125 removed lines patch added patch discarded remove patch
@@ -10,142 +10,142 @@
 block discarded – undo
10 10
 class EEM_Answer extends EEM_Base
11 11
 {
12 12
 
13
-    /**
14
-     * private instance of the EEM_Answer object
15
-     * @type EEM_Answer
16
-     */
17
-    protected static $_instance = null;
13
+	/**
14
+	 * private instance of the EEM_Answer object
15
+	 * @type EEM_Answer
16
+	 */
17
+	protected static $_instance = null;
18 18
 
19
-    /**
20
-     * Mapping from system question ids to attendee field names
21
-     * @type array
22
-     * @deprecated since version 4.8.8
23
-     */
24
-    protected $_question_id_to_att_field_map = array(
25
-        EEM_Attendee::fname_question_id => 'ATT_fname',
26
-        EEM_Attendee::lname_question_id => 'ATT_lname',
27
-        EEM_Attendee::email_question_id => 'ATT_email',
28
-        EEM_Attendee::address_question_id => 'ATT_address',
29
-        EEM_Attendee::address2_question_id => 'ATT_address2',
30
-        EEM_Attendee::city_question_id => 'ATT_city',
31
-        EEM_Attendee::state_question_id => 'STA_ID',
32
-        EEM_Attendee::country_question_id => 'CNT_ISO',
33
-        EEM_Attendee::zip_question_id => 'ATT_zip',
34
-        EEM_Attendee::phone_question_id => 'ATT_phone'
35
-    );
19
+	/**
20
+	 * Mapping from system question ids to attendee field names
21
+	 * @type array
22
+	 * @deprecated since version 4.8.8
23
+	 */
24
+	protected $_question_id_to_att_field_map = array(
25
+		EEM_Attendee::fname_question_id => 'ATT_fname',
26
+		EEM_Attendee::lname_question_id => 'ATT_lname',
27
+		EEM_Attendee::email_question_id => 'ATT_email',
28
+		EEM_Attendee::address_question_id => 'ATT_address',
29
+		EEM_Attendee::address2_question_id => 'ATT_address2',
30
+		EEM_Attendee::city_question_id => 'ATT_city',
31
+		EEM_Attendee::state_question_id => 'STA_ID',
32
+		EEM_Attendee::country_question_id => 'CNT_ISO',
33
+		EEM_Attendee::zip_question_id => 'ATT_zip',
34
+		EEM_Attendee::phone_question_id => 'ATT_phone'
35
+	);
36 36
 
37 37
 
38 38
 
39
-    /**
40
-     *  constructor
41
-     */
42
-    protected function __construct($timezone = null)
43
-    {
44
-        $this->singular_item = esc_html__('Answer', 'event_espresso');
45
-        $this->plural_item = esc_html__('Answers', 'event_espresso');
46
-        $this->_tables = array(
47
-            'Answer' => new EE_Primary_Table('esp_answer', 'ANS_ID')
48
-        );
49
-        $this->_fields = array(
50
-            'Answer' => array(
51
-                'ANS_ID' => new EE_Primary_Key_Int_Field('ANS_ID', esc_html__('Answer ID', 'event_espresso')),
52
-                'REG_ID' => new EE_Foreign_Key_Int_Field('REG_ID', esc_html__('Registration ID', 'event_espresso'), false, 0, 'Registration'),
53
-                'QST_ID' => new EE_Foreign_Key_Int_Field('QST_ID', esc_html__('Question ID', 'event_espresso'), false, 0, 'Question'),
54
-                'ANS_value' => new EE_Maybe_Serialized_Simple_HTML_Field('ANS_value', esc_html__('Answer Value', 'event_espresso'), false, '')
55
-            ));
56
-        $this->_model_relations = array(
57
-            'Registration' => new EE_Belongs_To_Relation(),
58
-            'Question' => new EE_Belongs_To_Relation()
59
-        );
60
-        $this->_model_chain_to_wp_user = 'Registration.Event';
61
-        $this->_caps_slug = 'registrations';
62
-        parent::__construct($timezone);
63
-    }
39
+	/**
40
+	 *  constructor
41
+	 */
42
+	protected function __construct($timezone = null)
43
+	{
44
+		$this->singular_item = esc_html__('Answer', 'event_espresso');
45
+		$this->plural_item = esc_html__('Answers', 'event_espresso');
46
+		$this->_tables = array(
47
+			'Answer' => new EE_Primary_Table('esp_answer', 'ANS_ID')
48
+		);
49
+		$this->_fields = array(
50
+			'Answer' => array(
51
+				'ANS_ID' => new EE_Primary_Key_Int_Field('ANS_ID', esc_html__('Answer ID', 'event_espresso')),
52
+				'REG_ID' => new EE_Foreign_Key_Int_Field('REG_ID', esc_html__('Registration ID', 'event_espresso'), false, 0, 'Registration'),
53
+				'QST_ID' => new EE_Foreign_Key_Int_Field('QST_ID', esc_html__('Question ID', 'event_espresso'), false, 0, 'Question'),
54
+				'ANS_value' => new EE_Maybe_Serialized_Simple_HTML_Field('ANS_value', esc_html__('Answer Value', 'event_espresso'), false, '')
55
+			));
56
+		$this->_model_relations = array(
57
+			'Registration' => new EE_Belongs_To_Relation(),
58
+			'Question' => new EE_Belongs_To_Relation()
59
+		);
60
+		$this->_model_chain_to_wp_user = 'Registration.Event';
61
+		$this->_caps_slug = 'registrations';
62
+		parent::__construct($timezone);
63
+	}
64 64
 
65 65
 
66 66
 
67
-    /**
68
-     * Gets the string answer to the question for this registration (it could either be stored
69
-     * on the attendee or in the answer table. This function finds its value regardless)
70
-     * @param EE_Registration $registration
71
-     * @param int $question_id
72
-     * @param boolean $pretty_answer whether to call 'pretty_value' or just 'value'
73
-     * @return string
74
-     */
75
-    public function get_answer_value_to_question(EE_Registration $registration, $question_id = null, $pretty_answer = false)
76
-    {
77
-        $value = $this->get_attendee_property_answer_value($registration, $question_id, $pretty_answer);
78
-        if ($value === null) {
79
-            $answer_obj = $this->get_registration_question_answer_object($registration, $question_id);
80
-            if ($answer_obj instanceof EE_Answer) {
81
-                if ($pretty_answer) {
82
-                    $value = $answer_obj->pretty_value();
83
-                } else {
84
-                    $value = $answer_obj->value();
85
-                }
86
-            }
87
-        }
88
-        return apply_filters('FHEE__EEM_Answer__get_answer_value_to_question__answer_value', $value, $registration, $question_id);
89
-    }
67
+	/**
68
+	 * Gets the string answer to the question for this registration (it could either be stored
69
+	 * on the attendee or in the answer table. This function finds its value regardless)
70
+	 * @param EE_Registration $registration
71
+	 * @param int $question_id
72
+	 * @param boolean $pretty_answer whether to call 'pretty_value' or just 'value'
73
+	 * @return string
74
+	 */
75
+	public function get_answer_value_to_question(EE_Registration $registration, $question_id = null, $pretty_answer = false)
76
+	{
77
+		$value = $this->get_attendee_property_answer_value($registration, $question_id, $pretty_answer);
78
+		if ($value === null) {
79
+			$answer_obj = $this->get_registration_question_answer_object($registration, $question_id);
80
+			if ($answer_obj instanceof EE_Answer) {
81
+				if ($pretty_answer) {
82
+					$value = $answer_obj->pretty_value();
83
+				} else {
84
+					$value = $answer_obj->value();
85
+				}
86
+			}
87
+		}
88
+		return apply_filters('FHEE__EEM_Answer__get_answer_value_to_question__answer_value', $value, $registration, $question_id);
89
+	}
90 90
 
91 91
 
92 92
 
93
-    /**
94
-     * Gets the EE_Answer object for the question for this registration (if it exists)
95
-     * @param EE_Registration $registration
96
-     * @param int $question_id
97
-     * @return EE_Answer
98
-     */
99
-    public function get_registration_question_answer_object(EE_Registration $registration, $question_id = null)
100
-    {
101
-        $answer_obj = $this->get_one(array( array( 'QST_ID' => $question_id, 'REG_ID' => $registration->ID() )));
102
-        return apply_filters('FHEE__EEM_Answer__get_registration_question_answer_object__answer_obj', $answer_obj, $registration, $question_id);
103
-    }
93
+	/**
94
+	 * Gets the EE_Answer object for the question for this registration (if it exists)
95
+	 * @param EE_Registration $registration
96
+	 * @param int $question_id
97
+	 * @return EE_Answer
98
+	 */
99
+	public function get_registration_question_answer_object(EE_Registration $registration, $question_id = null)
100
+	{
101
+		$answer_obj = $this->get_one(array( array( 'QST_ID' => $question_id, 'REG_ID' => $registration->ID() )));
102
+		return apply_filters('FHEE__EEM_Answer__get_registration_question_answer_object__answer_obj', $answer_obj, $registration, $question_id);
103
+	}
104 104
 
105 105
 
106 106
 
107
-    /**
108
-     * Gets the string answer to the question for this registration's attendee
109
-     * @param EE_Registration $registration
110
-     * @param int|string $question_system_id if an INT this is understood to be the question's ID; if a string then it should be its QST_system value.
111
-     *  Passing in the QST_system value is more efficient
112
-     * @param boolean $pretty_answer
113
-     * @return string|null (if the registration has no attendee, or the question_system_id is not a QST_ID or QST_system for
114
-     * a question corresponding to an attendee field, returns null)
115
-     */
116
-    public function get_attendee_property_answer_value(EE_Registration $registration, $question_system_id = null, $pretty_answer = false)
117
-    {
118
-        $field_name = null;
119
-        $value = null;
120
-                // backward compat: we still want to find the question's ID
121
-        if (is_numeric($question_system_id)) {
122
-            // find this question's QST_system value
123
-            $question_id = $question_system_id;
124
-            $question_system_id = EEM_Question::instance()->get_var(array( array( 'QST_ID' => $question_system_id ) ), 'QST_system');
125
-        } else {
126
-            $question_id = (int) EEM_Question::instance()->get_var(array( array( 'QST_system' => $question_system_id ) ), 'QST_ID');
127
-        }
128
-        // only bother checking if the registration has an attendee
129
-        if ($registration->attendee() instanceof EE_Attendee) {
130
-            $field_name = EEM_Attendee::instance()->get_attendee_field_for_system_question($question_system_id);
131
-            if ($field_name) {
132
-                if ($pretty_answer) {
133
-                    if ($field_name === 'STA_ID') {
134
-                        $state = $registration->attendee()->state_obj();
135
-                        $value = $state instanceof EE_State ? $state->name() : sprintf(esc_html__('Unknown State (%s)', 'event_espresso'), $registration->attendee()->state_ID());
136
-                    } elseif ($field_name === 'CNT_ISO') {
137
-                        $country = $registration->attendee()->country_obj();
138
-                        $value = $country instanceof EE_Country ? $country->name() : sprintf(esc_html__('Unknown Country (%s)', "event_espresso"), $registration->attendee()->country_ID());
139
-                    } else {
140
-                        $value = $registration->attendee()->get_pretty($field_name);
141
-                    }
142
-                    // if field name is blank, leave the value as null too
143
-                } else {
144
-                    $value = $registration->attendee()->get($field_name);
145
-                }
146
-            }
147
-            // if no field was found, leave value blank
148
-        }
149
-        return apply_filters('FHEE__EEM_Answer__get_attendee_question_answer_value__answer_value', $value, $registration, $question_id, $question_system_id);
150
-    }
107
+	/**
108
+	 * Gets the string answer to the question for this registration's attendee
109
+	 * @param EE_Registration $registration
110
+	 * @param int|string $question_system_id if an INT this is understood to be the question's ID; if a string then it should be its QST_system value.
111
+	 *  Passing in the QST_system value is more efficient
112
+	 * @param boolean $pretty_answer
113
+	 * @return string|null (if the registration has no attendee, or the question_system_id is not a QST_ID or QST_system for
114
+	 * a question corresponding to an attendee field, returns null)
115
+	 */
116
+	public function get_attendee_property_answer_value(EE_Registration $registration, $question_system_id = null, $pretty_answer = false)
117
+	{
118
+		$field_name = null;
119
+		$value = null;
120
+				// backward compat: we still want to find the question's ID
121
+		if (is_numeric($question_system_id)) {
122
+			// find this question's QST_system value
123
+			$question_id = $question_system_id;
124
+			$question_system_id = EEM_Question::instance()->get_var(array( array( 'QST_ID' => $question_system_id ) ), 'QST_system');
125
+		} else {
126
+			$question_id = (int) EEM_Question::instance()->get_var(array( array( 'QST_system' => $question_system_id ) ), 'QST_ID');
127
+		}
128
+		// only bother checking if the registration has an attendee
129
+		if ($registration->attendee() instanceof EE_Attendee) {
130
+			$field_name = EEM_Attendee::instance()->get_attendee_field_for_system_question($question_system_id);
131
+			if ($field_name) {
132
+				if ($pretty_answer) {
133
+					if ($field_name === 'STA_ID') {
134
+						$state = $registration->attendee()->state_obj();
135
+						$value = $state instanceof EE_State ? $state->name() : sprintf(esc_html__('Unknown State (%s)', 'event_espresso'), $registration->attendee()->state_ID());
136
+					} elseif ($field_name === 'CNT_ISO') {
137
+						$country = $registration->attendee()->country_obj();
138
+						$value = $country instanceof EE_Country ? $country->name() : sprintf(esc_html__('Unknown Country (%s)', "event_espresso"), $registration->attendee()->country_ID());
139
+					} else {
140
+						$value = $registration->attendee()->get_pretty($field_name);
141
+					}
142
+					// if field name is blank, leave the value as null too
143
+				} else {
144
+					$value = $registration->attendee()->get($field_name);
145
+				}
146
+			}
147
+			// if no field was found, leave value blank
148
+		}
149
+		return apply_filters('FHEE__EEM_Answer__get_attendee_question_answer_value__answer_value', $value, $registration, $question_id, $question_system_id);
150
+	}
151 151
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Registration.model.php 2 patches
Indentation   +868 added lines, -868 removed lines patch added patch discarded remove patch
@@ -14,817 +14,817 @@  discard block
 block discarded – undo
14 14
 class EEM_Registration extends EEM_Soft_Delete_Base
15 15
 {
16 16
 
17
-    /**
18
-     * @var EEM_Registration $_instance
19
-     */
20
-    protected static $_instance;
21
-
22
-    /**
23
-     * Keys are the status IDs for registrations (eg, RAP, RCN, etc), and the values
24
-     * are status codes (eg, approved, cancelled, etc)
25
-     *
26
-     * @var array
27
-     */
28
-    private static $_reg_status;
29
-
30
-    /**
31
-     * The value of REG_count for a primary registrant
32
-     */
33
-    const PRIMARY_REGISTRANT_COUNT = 1;
34
-
35
-    /**
36
-     * Status ID (STS_ID on esp_status table) to indicate an INCOMPLETE registration.
37
-     * Initial status for registrations when they are first created
38
-     * Payments are NOT allowed.
39
-     * Automatically toggled to whatever the default Event registration status is upon completion of the attendee
40
-     * information reg step NO space reserved. Registration is NOT active
41
-     */
42
-    const status_id_incomplete = 'RIC';
43
-
44
-    /**
45
-     * Status ID (STS_ID on esp_status table) to indicate an UNAPPROVED registration.
46
-     * Payments are NOT allowed.
47
-     * Event Admin must manually toggle STS_ID for it to change
48
-     * No space reserved.
49
-     * Registration is active
50
-     */
51
-    const status_id_not_approved = 'RNA';
52
-
53
-    /**
54
-     * Status ID (STS_ID on esp_status table) to indicate registration is PENDING_PAYMENT .
55
-     * Payments are allowed.
56
-     * STS_ID will automatically be toggled to RAP if payment is made in full by the attendee
57
-     * No space reserved.
58
-     * Registration is active
59
-     */
60
-    const status_id_pending_payment = 'RPP';
61
-
62
-    /**
63
-     * Status ID (STS_ID on esp_status table) to indicate registration is on the WAIT_LIST .
64
-     * Payments are allowed.
65
-     * STS_ID will automatically be toggled to RAP if payment is made in full by the attendee
66
-     * No space reserved.
67
-     * Registration is active
68
-     */
69
-    const status_id_wait_list = 'RWL';
70
-
71
-    /**
72
-     * Status ID (STS_ID on esp_status table) to indicate an APPROVED registration.
73
-     * the TXN may or may not be completed ( paid in full )
74
-     * Payments are allowed.
75
-     * A space IS reserved.
76
-     * Registration is active
77
-     */
78
-    const status_id_approved = 'RAP';
79
-
80
-    /**
81
-     * Status ID (STS_ID on esp_status table) to indicate a registration was CANCELLED by the attendee.
82
-     * Payments are NOT allowed.
83
-     * NO space reserved.
84
-     * Registration is NOT active
85
-     */
86
-    const status_id_cancelled = 'RCN';
87
-
88
-    /**
89
-     * Status ID (STS_ID on esp_status table) to indicate a registration was DECLINED by the Event Admin
90
-     * Payments are NOT allowed.
91
-     * No space reserved.
92
-     * Registration is NOT active
93
-     */
94
-    const status_id_declined = 'RDC';
95
-
96
-    /**
97
-     * @var TableAnalysis $table_analysis
98
-     */
99
-    protected $_table_analysis;
100
-
101
-
102
-    /**
103
-     *    private constructor to prevent direct creation
104
-     *
105
-     * @Constructor
106
-     * @access protected
107
-     * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any
108
-     *                         incoming timezone data that gets saved). Note this just sends the timezone info to the
109
-     *                         date time model field objects.  Default is NULL (and will be assumed using the set
110
-     *                         timezone in the 'timezone_string' wp option)
111
-     * @throws EE_Error
112
-     */
113
-    protected function __construct($timezone = null)
114
-    {
115
-        $this->_table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
116
-        $this->singular_item = esc_html__('Registration', 'event_espresso');
117
-        $this->plural_item = esc_html__('Registrations', 'event_espresso');
118
-        $this->_tables = array(
119
-            'Registration' => new EE_Primary_Table('esp_registration', 'REG_ID'),
120
-        );
121
-        $this->_fields = array(
122
-            'Registration' => array(
123
-                'REG_ID' => new EE_Primary_Key_Int_Field(
124
-                    'REG_ID',
125
-                    esc_html__('Registration ID', 'event_espresso')
126
-                ),
127
-                'EVT_ID' => new EE_Foreign_Key_Int_Field(
128
-                    'EVT_ID',
129
-                    esc_html__('Event ID', 'event_espresso'),
130
-                    false,
131
-                    0,
132
-                    'Event'
133
-                ),
134
-                'ATT_ID' => new EE_Foreign_Key_Int_Field(
135
-                    'ATT_ID',
136
-                    esc_html__('Attendee ID', 'event_espresso'),
137
-                    false,
138
-                    0,
139
-                    'Attendee'
140
-                ),
141
-                'TXN_ID' => new EE_Foreign_Key_Int_Field(
142
-                    'TXN_ID',
143
-                    esc_html__('Transaction ID', 'event_espresso'),
144
-                    false,
145
-                    0,
146
-                    'Transaction'
147
-                ),
148
-                'TKT_ID' => new EE_Foreign_Key_Int_Field(
149
-                    'TKT_ID',
150
-                    esc_html__('Ticket ID', 'event_espresso'),
151
-                    false,
152
-                    0,
153
-                    'Ticket'
154
-                ),
155
-                'STS_ID' => new EE_Foreign_Key_String_Field(
156
-                    'STS_ID',
157
-                    esc_html__('Status ID', 'event_espresso'),
158
-                    false,
159
-                    EEM_Registration::status_id_incomplete,
160
-                    'Status'
161
-                ),
162
-                'REG_date' => new EE_Datetime_Field(
163
-                    'REG_date',
164
-                    esc_html__('Time registration occurred', 'event_espresso'),
165
-                    false,
166
-                    EE_Datetime_Field::now,
167
-                    $timezone
168
-                ),
169
-                'REG_final_price' => new EE_Money_Field(
170
-                    'REG_final_price',
171
-                    esc_html__('Registration\'s share of the transaction total', 'event_espresso'),
172
-                    false,
173
-                    0
174
-                ),
175
-                'REG_paid' => new EE_Money_Field(
176
-                    'REG_paid',
177
-                    esc_html__('Amount paid to date towards registration', 'event_espresso'),
178
-                    false,
179
-                    0
180
-                ),
181
-                'REG_session' => new EE_Plain_Text_Field(
182
-                    'REG_session',
183
-                    esc_html__('Session ID of registration', 'event_espresso'),
184
-                    false,
185
-                    ''
186
-                ),
187
-                'REG_code' => new EE_Plain_Text_Field(
188
-                    'REG_code',
189
-                    esc_html__('Unique Code for this registration', 'event_espresso'),
190
-                    false,
191
-                    ''
192
-                ),
193
-                'REG_url_link' => new EE_Plain_Text_Field(
194
-                    'REG_url_link',
195
-                    esc_html__('String to be used in URL for identifying registration', 'event_espresso'),
196
-                    false,
197
-                    ''
198
-                ),
199
-                'REG_count' => new EE_Integer_Field(
200
-                    'REG_count',
201
-                    esc_html__('Count of this registration in the group registration ', 'event_espresso'),
202
-                    true,
203
-                    1
204
-                ),
205
-                'REG_group_size' => new EE_Integer_Field(
206
-                    'REG_group_size',
207
-                    esc_html__('Number of registrations on this group', 'event_espresso'),
208
-                    false,
209
-                    1
210
-                ),
211
-                'REG_att_is_going' => new EE_Boolean_Field(
212
-                    'REG_att_is_going',
213
-                    esc_html__('Flag indicating the registrant plans on attending', 'event_espresso'),
214
-                    false,
215
-                    false
216
-                ),
217
-                'REG_deleted' => new EE_Trashed_Flag_Field(
218
-                    'REG_deleted',
219
-                    esc_html__('Flag indicating if registration has been archived or not.', 'event_espresso'),
220
-                    false,
221
-                    false
222
-                ),
223
-            ),
224
-        );
225
-        $this->_model_relations = array(
226
-            'Event' => new EE_Belongs_To_Relation(),
227
-            'Attendee' => new EE_Belongs_To_Relation(),
228
-            'Transaction' => new EE_Belongs_To_Relation(),
229
-            'Ticket' => new EE_Belongs_To_Relation(),
230
-            'Status' => new EE_Belongs_To_Relation(),
231
-            'Answer' => new EE_Has_Many_Relation(),
232
-            'Checkin' => new EE_Has_Many_Relation(),
233
-            'Registration_Payment' => new EE_Has_Many_Relation(),
234
-            'Payment' => new EE_HABTM_Relation('Registration_Payment'),
235
-            'Message' => new EE_Has_Many_Any_Relation(false)
236
-            // allow deletes even if there are messages in the queue related
237
-        );
238
-        $this->_model_chain_to_wp_user = 'Event';
239
-        parent::__construct($timezone);
240
-    }
241
-
242
-
243
-    /**
244
-     * a list of ALL valid registration statuses currently in use within the system
245
-     * generated by combining the filterable active and inactive reg status arrays
246
-     *
247
-     * @return array
248
-     */
249
-    public static function reg_statuses()
250
-    {
251
-        return array_unique(
252
-            array_merge(
253
-                EEM_Registration::active_reg_statuses(),
254
-                EEM_Registration::inactive_reg_statuses()
255
-            )
256
-        );
257
-    }
258
-
259
-
260
-    /**
261
-     * reg_statuses_that_allow_payment
262
-     * a filterable list of registration statuses that allow a registrant to make a payment
263
-     *
264
-     * @access public
265
-     * @return array
266
-     */
267
-    public static function reg_statuses_that_allow_payment()
268
-    {
269
-        return apply_filters(
270
-            'FHEE__EEM_Registration__reg_statuses_that_allow_payment',
271
-            array(
272
-                EEM_Registration::status_id_approved,
273
-                EEM_Registration::status_id_pending_payment,
274
-            )
275
-        );
276
-    }
277
-
278
-
279
-    /**
280
-     * active_reg_statuses
281
-     * a filterable list of registration statuses that are considered active
282
-     *
283
-     * @access public
284
-     * @return array
285
-     */
286
-    public static function active_reg_statuses()
287
-    {
288
-        return apply_filters(
289
-            'FHEE__EEM_Registration__active_reg_statuses',
290
-            array(
291
-                EEM_Registration::status_id_approved,
292
-                EEM_Registration::status_id_pending_payment,
293
-                EEM_Registration::status_id_wait_list,
294
-                EEM_Registration::status_id_not_approved,
295
-            )
296
-        );
297
-    }
298
-
299
-
300
-    /**
301
-     * inactive_reg_statuses
302
-     * a filterable list of registration statuses that are not considered active
303
-     *
304
-     * @access public
305
-     * @return array
306
-     */
307
-    public static function inactive_reg_statuses()
308
-    {
309
-        return apply_filters(
310
-            'FHEE__EEM_Registration__inactive_reg_statuses',
311
-            array(
312
-                EEM_Registration::status_id_incomplete,
313
-                EEM_Registration::status_id_cancelled,
314
-                EEM_Registration::status_id_declined,
315
-            )
316
-        );
317
-    }
318
-
319
-
320
-    /**
321
-     *    closed_reg_statuses
322
-     *    a filterable list of registration statuses that are considered "closed"
323
-     * meaning they should not be considered in any calculations involving monies owing
324
-     *
325
-     * @access public
326
-     * @return array
327
-     */
328
-    public static function closed_reg_statuses()
329
-    {
330
-        return apply_filters(
331
-            'FHEE__EEM_Registration__closed_reg_statuses',
332
-            array(
333
-                EEM_Registration::status_id_cancelled,
334
-                EEM_Registration::status_id_declined,
335
-                EEM_Registration::status_id_wait_list,
336
-            )
337
-        );
338
-    }
339
-
340
-
341
-    /**
342
-     *        get list of registration statuses
343
-     *
344
-     * @access public
345
-     * @param array $exclude The status ids to exclude from the returned results
346
-     * @param bool $translated If true will return the values as singular localized strings
347
-     * @return array
348
-     * @throws EE_Error
349
-     */
350
-    public static function reg_status_array($exclude = array(), $translated = false)
351
-    {
352
-        EEM_Registration::instance()->_get_registration_status_array($exclude);
353
-        return $translated
354
-            ? EEM_Status::instance()->localized_status(self::$_reg_status, false, 'sentence')
355
-            : self::$_reg_status;
356
-    }
357
-
358
-
359
-    /**
360
-     *    get list of registration statuses
361
-     *
362
-     * @access private
363
-     * @param array $exclude
364
-     * @return void
365
-     * @throws EE_Error
366
-     */
367
-    private function _get_registration_status_array($exclude = array())
368
-    {
369
-        // in the very rare circumstance that we are deleting a model's table's data
370
-        // and the table hasn't actually been created, this could have an error
371
-        /** @type WPDB $wpdb */
372
-        global $wpdb;
373
-        if ($this->_get_table_analysis()->tableExists($wpdb->prefix . 'esp_status')) {
374
-            $results = $wpdb->get_results(
375
-                "SELECT STS_ID, STS_code FROM {$wpdb->prefix}esp_status WHERE STS_type = 'registration'"
376
-            );
377
-            self::$_reg_status = array();
378
-            foreach ($results as $status) {
379
-                if (!in_array($status->STS_ID, $exclude, true)) {
380
-                    self::$_reg_status[ $status->STS_ID ] = $status->STS_code;
381
-                }
382
-            }
383
-        }
384
-    }
385
-
386
-
387
-    /**
388
-     * Gets the injected table analyzer, or throws an exception
389
-     *
390
-     * @return TableAnalysis
391
-     * @throws EE_Error
392
-     */
393
-    protected function _get_table_analysis()
394
-    {
395
-        if ($this->_table_analysis instanceof TableAnalysis) {
396
-            return $this->_table_analysis;
397
-        }
398
-        throw new EE_Error(
399
-            sprintf(
400
-                esc_html__('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
401
-                get_class($this)
402
-            )
403
-        );
404
-    }
405
-
406
-
407
-    /**
408
-     * This returns a wpdb->results array of all registration date month and years matching the incoming query params
409
-     * and grouped by month and year.
410
-     *
411
-     * @param  array $where_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions
412
-     * @return array
413
-     * @throws EE_Error
414
-     */
415
-    public function get_reg_months_and_years($where_params)
416
-    {
417
-        $query_params[0] = $where_params;
418
-        $query_params['group_by'] = array('reg_year', 'reg_month');
419
-        $query_params['order_by'] = array('REG_date' => 'DESC');
420
-        $columns_to_select = array(
421
-            'reg_year' => array('YEAR(REG_date)', '%s'),
422
-            'reg_month' => array('MONTHNAME(REG_date)', '%s'),
423
-        );
424
-        return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
425
-    }
426
-
427
-
428
-    /**
429
-     * retrieve ALL registrations for a particular Attendee from db
430
-     *
431
-     * @param int $ATT_ID
432
-     * @return EE_Base_Class[]|EE_Registration[]|null
433
-     * @throws EE_Error
434
-     */
435
-    public function get_all_registrations_for_attendee($ATT_ID = 0)
436
-    {
437
-        if (!$ATT_ID) {
438
-            return null;
439
-        }
440
-        return $this->get_all(array(array('ATT_ID' => $ATT_ID)));
441
-    }
442
-
443
-
444
-    /**
445
-     * Gets a registration given their REG_url_link. Yes, this should usually
446
-     * be passed via a GET parameter.
447
-     *
448
-     * @param string $REG_url_link
449
-     * @return EE_Base_Class|EE_Registration|null
450
-     * @throws EE_Error
451
-     */
452
-    public function get_registration_for_reg_url_link($REG_url_link)
453
-    {
454
-        if (!$REG_url_link) {
455
-            return null;
456
-        }
457
-        return $this->get_one(array(array('REG_url_link' => $REG_url_link)));
458
-    }
459
-
460
-
461
-    /**
462
-     *        retrieve registration for a specific transaction attendee from db
463
-     *
464
-     * @access        public
465
-     * @param    int $TXN_ID
466
-     * @param    int $ATT_ID
467
-     * @param    int $att_nmbr in case the ATT_ID is the same for multiple registrations (same details used) then the
468
-     *                         attendee number is required
469
-     * @return        mixed        array on success, FALSE on fail
470
-     * @throws EE_Error
471
-     */
472
-    public function get_registration_for_transaction_attendee($TXN_ID = 0, $ATT_ID = 0, $att_nmbr = 0)
473
-    {
474
-        return $this->get_one(array(
475
-            array(
476
-                'TXN_ID' => $TXN_ID,
477
-                'ATT_ID' => $ATT_ID,
478
-            ),
479
-            'limit' => array(min($att_nmbr - 1, 0), 1),
480
-        ));
481
-    }
482
-
483
-
484
-    /**
485
-     *        get the number of registrations per day  for the Registration Admin page Reports Tab.
486
-     *        (doesn't utilize models because it's a fairly specialized query)
487
-     *
488
-     * @access        public
489
-     * @param $period string which can be passed to php's strtotime function (eg "-1 month")
490
-     * @return stdClass[] with properties regDate and total
491
-     * @throws EE_Error
492
-     */
493
-    public function get_registrations_per_day_report($period = '-1 month')
494
-    {
495
-        $sql_date = $this->convert_datetime_for_query(
496
-            'REG_date',
497
-            date('Y-m-d H:i:s', strtotime($period)),
498
-            'Y-m-d H:i:s',
499
-            'UTC'
500
-        );
501
-        $where = array(
502
-            'REG_date' => array('>=', $sql_date),
503
-            'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
504
-        );
505
-        if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_day_report')) {
506
-            $where['Event.EVT_wp_user'] = get_current_user_id();
507
-        }
508
-        $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'REG_date');
509
-        $results = $this->_get_all_wpdb_results(
510
-            array(
511
-                $where,
512
-                'group_by' => 'regDate',
513
-                'order_by' => array('REG_date' => 'ASC'),
514
-            ),
515
-            OBJECT,
516
-            array(
517
-                'regDate' => array('DATE(' . $query_interval . ')', '%s'),
518
-                'total' => array('count(REG_ID)', '%d'),
519
-            )
520
-        );
521
-        return $results;
522
-    }
523
-
524
-
525
-    /**
526
-     * Get the number of registrations per day including the count of registrations for each Registration Status.
527
-     * Note: EEM_Registration::status_id_incomplete registrations are excluded from the results.
528
-     *
529
-     * @param string $period
530
-     * @return stdClass[] with properties Registration_REG_date and a column for each registration status as the STS_ID
531
-     * @throws EE_Error
532
-     *                    (i.e. RAP)
533
-     */
534
-    public function get_registrations_per_day_and_per_status_report($period = '-1 month')
535
-    {
536
-        global $wpdb;
537
-        $registration_table = $wpdb->prefix . 'esp_registration';
538
-        $event_table = $wpdb->posts;
539
-        $sql_date = date('Y-m-d H:i:s', strtotime($period));
540
-        // prepare the query interval for displaying offset
541
-        $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'dates.REG_date');
542
-        // inner date query
543
-        $inner_date_query = "SELECT DISTINCT REG_date from {$registration_table} ";
544
-        $inner_where = ' WHERE';
545
-        // exclude events not authored by user if permissions in effect
546
-        if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
547
-            $inner_date_query .= "LEFT JOIN {$event_table} ON ID = EVT_ID";
548
-            $inner_where .= ' post_author = ' . get_current_user_id() . ' AND';
549
-        }
550
-        $inner_where .= " REG_date >= '{$sql_date}'";
551
-        $inner_date_query .= $inner_where;
552
-        // start main query
553
-        $select = "SELECT DATE({$query_interval}) as Registration_REG_date, ";
554
-        $join = '';
555
-        $join_parts = array();
556
-        $select_parts = array();
557
-        // loop through registration stati to do parts for each status.
558
-        foreach (EEM_Registration::reg_status_array() as $STS_ID => $STS_code) {
559
-            if ($STS_ID === EEM_Registration::status_id_incomplete) {
560
-                continue;
561
-            }
562
-            $select_parts[] = "COUNT({$STS_code}.REG_ID) as {$STS_ID}";
563
-            $join_parts[] = "{$registration_table} AS {$STS_code} ON {$STS_code}.REG_date = dates.REG_date AND {$STS_code}.STS_ID = '{$STS_ID}'";
564
-        }
565
-        // setup the selects
566
-        $select .= implode(', ', $select_parts);
567
-        $select .= " FROM ($inner_date_query) AS dates LEFT JOIN ";
568
-        // setup the joins
569
-        $join .= implode(' LEFT JOIN ', $join_parts);
570
-        // now let's put it all together
571
-        $query = $select . $join . ' GROUP BY Registration_REG_date';
572
-        // and execute it
573
-        return $wpdb->get_results($query, ARRAY_A);
574
-    }
575
-
576
-
577
-    /**
578
-     *        get the number of registrations per event  for the Registration Admin page Reports Tab
579
-     *
580
-     * @access        public
581
-     * @param $period string which can be passed to php's strtotime function (eg "-1 month")
582
-     * @return stdClass[] each with properties event_name, reg_limit, and total
583
-     * @throws EE_Error
584
-     */
585
-    public function get_registrations_per_event_report($period = '-1 month')
586
-    {
587
-        $date_sql = $this->convert_datetime_for_query(
588
-            'REG_date',
589
-            date('Y-m-d H:i:s', strtotime($period)),
590
-            'Y-m-d H:i:s',
591
-            'UTC'
592
-        );
593
-        $where = array(
594
-            'REG_date' => array('>=', $date_sql),
595
-            'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
596
-        );
597
-        if (
598
-            !EE_Registry::instance()->CAP->current_user_can(
599
-                'ee_read_others_registrations',
600
-                'reg_per_event_report'
601
-            )
602
-        ) {
603
-            $where['Event.EVT_wp_user'] = get_current_user_id();
604
-        }
605
-        $results = $this->_get_all_wpdb_results(
606
-            array(
607
-            $where,
608
-            'group_by' => 'Event.EVT_name',
609
-            'order_by' => 'Event.EVT_name',
610
-            'limit' => array(0, 24),
611
-            ),
612
-            OBJECT,
613
-            array(
614
-                'event_name' => array('Event_CPT.post_title', '%s'),
615
-                'total' => array('COUNT(REG_ID)', '%s'),
616
-            )
617
-        );
618
-        return $results;
619
-    }
620
-
621
-
622
-    /**
623
-     * Get the number of registrations per event grouped by registration status.
624
-     * Note: EEM_Registration::status_id_incomplete registrations are excluded from the results.
625
-     *
626
-     * @param string $period
627
-     * @return stdClass[] with properties `Registration_Event` and a column for each registration status as the STS_ID
628
-     * @throws EE_Error
629
-     *                    (i.e. RAP)
630
-     */
631
-    public function get_registrations_per_event_and_per_status_report($period = '-1 month')
632
-    {
633
-        global $wpdb;
634
-        $registration_table = $wpdb->prefix . 'esp_registration';
635
-        $event_table = $wpdb->posts;
636
-        $sql_date = date('Y-m-d H:i:s', strtotime($period));
637
-        // inner date query
638
-        $inner_date_query = "SELECT DISTINCT EVT_ID, REG_date from $registration_table ";
639
-        $inner_where = ' WHERE';
640
-        // exclude events not authored by user if permissions in effect
641
-        if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
642
-            $inner_date_query .= "LEFT JOIN {$event_table} ON ID = EVT_ID";
643
-            $inner_where .= ' post_author = ' . get_current_user_id() . ' AND';
644
-        }
645
-        $inner_where .= " REG_date >= '{$sql_date}'";
646
-        $inner_date_query .= $inner_where;
647
-        // build main query
648
-        $select = 'SELECT Event.post_title as Registration_Event, ';
649
-        $join = '';
650
-        $join_parts = array();
651
-        $select_parts = array();
652
-        // loop through registration stati to do parts for each status.
653
-        foreach (EEM_Registration::reg_status_array() as $STS_ID => $STS_code) {
654
-            if ($STS_ID === EEM_Registration::status_id_incomplete) {
655
-                continue;
656
-            }
657
-            $select_parts[] = "COUNT({$STS_code}.REG_ID) as {$STS_ID}";
658
-            $join_parts[] = "{$registration_table} AS {$STS_code} ON {$STS_code}.EVT_ID = dates.EVT_ID AND {$STS_code}.STS_ID = '{$STS_ID}' AND {$STS_code}.REG_date = dates.REG_date";
659
-        }
660
-        // setup the selects
661
-        $select .= implode(', ', $select_parts);
662
-        $select .= " FROM ($inner_date_query) AS dates LEFT JOIN $event_table as Event ON Event.ID = dates.EVT_ID LEFT JOIN ";
663
-        // setup remaining joins
664
-        $join .= implode(' LEFT JOIN ', $join_parts);
665
-        // now put it all together
666
-        $query = $select . $join . ' GROUP BY Registration_Event';
667
-        // and execute
668
-        return $wpdb->get_results($query, ARRAY_A);
669
-    }
670
-
671
-
672
-    /**
673
-     * Returns the EE_Registration of the primary attendee on the transaction id provided
674
-     *
675
-     * @param int $TXN_ID
676
-     * @return EE_Base_Class|EE_Registration|null
677
-     * @throws EE_Error
678
-     */
679
-    public function get_primary_registration_for_transaction_ID($TXN_ID = 0)
680
-    {
681
-        if (!$TXN_ID) {
682
-            return null;
683
-        }
684
-        return $this->get_one(array(
685
-            array(
686
-                'TXN_ID' => $TXN_ID,
687
-                'REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT,
688
-            ),
689
-        ));
690
-    }
691
-
692
-
693
-    /**
694
-     *        get_event_registration_count
695
-     *
696
-     * @access public
697
-     * @param int $EVT_ID
698
-     * @param boolean $for_incomplete_payments
699
-     * @return int
700
-     * @throws EE_Error
701
-     */
702
-    public function get_event_registration_count($EVT_ID, $for_incomplete_payments = false)
703
-    {
704
-        // we only count approved registrations towards registration limits
705
-        $query_params = array(array('EVT_ID' => $EVT_ID, 'STS_ID' => self::status_id_approved));
706
-        if ($for_incomplete_payments) {
707
-            $query_params[0]['Transaction.STS_ID'] = array('!=', EEM_Transaction::complete_status_code);
708
-        }
709
-        return $this->count($query_params);
710
-    }
711
-
712
-
713
-    /**
714
-     * Deletes all registrations with no transactions. Note that this needs to be very efficient
715
-     * and so it uses wpdb directly. Also, we can't put a limit on this because MySQL doesn't allow a limit on a delete
716
-     * when joining tables like this.
717
-     *
718
-     * @global WPDB $wpdb
719
-     * @return int number deleted
720
-     * @throws EE_Error
721
-     */
722
-    public function delete_registrations_with_no_transaction()
723
-    {
724
-        /** @type WPDB $wpdb */
725
-        global $wpdb;
726
-        return $wpdb->query(
727
-            'DELETE r FROM '
728
-            . $this->table()
729
-            . ' r LEFT JOIN '
730
-            . EEM_Transaction::instance()->table()
731
-            . ' t ON r.TXN_ID = t.TXN_ID WHERE t.TXN_ID IS NULL'
732
-        );
733
-    }
734
-
735
-
736
-    /**
737
-     *  Count registrations checked into (or out of) a datetime
738
-     *
739
-     * @param int $DTT_ID datetime ID
740
-     * @param boolean $checked_in whether to count registrations checked IN or OUT
741
-     * @return int
742
-     * @throws EE_Error
743
-     */
744
-    public function count_registrations_checked_into_datetime($DTT_ID, $checked_in = true)
745
-    {
746
-        global $wpdb;
747
-        // subquery to get latest checkin
748
-        $query = $wpdb->prepare(
749
-            'SELECT '
750
-            . 'COUNT( DISTINCT checkins.REG_ID ) '
751
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN'
752
-            . '( SELECT '
753
-            . 'max( CHK_timestamp ) AS latest_checkin, '
754
-            . 'REG_ID AS REG_ID '
755
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' '
756
-            . 'WHERE DTT_ID=%d '
757
-            . 'GROUP BY REG_ID'
758
-            . ') AS most_recent_checkin_per_reg '
759
-            . 'ON checkins.REG_ID=most_recent_checkin_per_reg.REG_ID '
760
-            . 'AND checkins.CHK_timestamp = most_recent_checkin_per_reg.latest_checkin '
761
-            . 'WHERE '
762
-            . 'checkins.CHK_in=%d',
763
-            $DTT_ID,
764
-            $checked_in
765
-        );
766
-        return (int) $wpdb->get_var($query);
767
-    }
768
-
769
-
770
-    /**
771
-     *  Count registrations checked into (or out of) an event.
772
-     *
773
-     * @param int $EVT_ID event ID
774
-     * @param boolean $checked_in whether to count registrations checked IN or OUT
775
-     * @return int
776
-     * @throws EE_Error
777
-     */
778
-    public function count_registrations_checked_into_event($EVT_ID, $checked_in = true)
779
-    {
780
-        global $wpdb;
781
-        // subquery to get latest checkin
782
-        $query = $wpdb->prepare(
783
-            'SELECT '
784
-            . 'COUNT( DISTINCT checkins.REG_ID ) '
785
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN'
786
-            . '( SELECT '
787
-            . 'max( CHK_timestamp ) AS latest_checkin, '
788
-            . 'REG_ID AS REG_ID '
789
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' AS c '
790
-            . 'INNER JOIN ' . EEM_Datetime::instance()->table() . ' AS d '
791
-            . 'ON c.DTT_ID=d.DTT_ID '
792
-            . 'WHERE d.EVT_ID=%d '
793
-            . 'GROUP BY REG_ID'
794
-            . ') AS most_recent_checkin_per_reg '
795
-            . 'ON checkins.REG_ID=most_recent_checkin_per_reg.REG_ID '
796
-            . 'AND checkins.CHK_timestamp = most_recent_checkin_per_reg.latest_checkin '
797
-            . 'WHERE '
798
-            . 'checkins.CHK_in=%d',
799
-            $EVT_ID,
800
-            $checked_in
801
-        );
802
-        return (int) $wpdb->get_var($query);
803
-    }
804
-
805
-
806
-    /**
807
-     * The purpose of this method is to retrieve an array of
808
-     * EE_Registration objects that represent the latest registration
809
-     * for each ATT_ID given in the function argument.
810
-     *
811
-     * @param array $attendee_ids
812
-     * @return EE_Base_Class[]|EE_Registration[]
813
-     * @throws EE_Error
814
-     */
815
-    public function get_latest_registration_for_each_of_given_contacts($attendee_ids = array())
816
-    {
817
-        // first do a native wp_query to get the latest REG_ID's matching these attendees.
818
-        global $wpdb;
819
-        $registration_table = $wpdb->prefix . 'esp_registration';
820
-        $attendee_table = $wpdb->posts;
821
-        $attendee_ids = is_array($attendee_ids)
822
-            ? array_map('absint', $attendee_ids)
823
-            : array((int) $attendee_ids);
824
-        $ATT_IDs = implode(',', $attendee_ids);
825
-        // first we do a query to get the registration ids
826
-        // (because a group by before order by causes the order by to be ignored.)
827
-        $registration_id_query = "
17
+	/**
18
+	 * @var EEM_Registration $_instance
19
+	 */
20
+	protected static $_instance;
21
+
22
+	/**
23
+	 * Keys are the status IDs for registrations (eg, RAP, RCN, etc), and the values
24
+	 * are status codes (eg, approved, cancelled, etc)
25
+	 *
26
+	 * @var array
27
+	 */
28
+	private static $_reg_status;
29
+
30
+	/**
31
+	 * The value of REG_count for a primary registrant
32
+	 */
33
+	const PRIMARY_REGISTRANT_COUNT = 1;
34
+
35
+	/**
36
+	 * Status ID (STS_ID on esp_status table) to indicate an INCOMPLETE registration.
37
+	 * Initial status for registrations when they are first created
38
+	 * Payments are NOT allowed.
39
+	 * Automatically toggled to whatever the default Event registration status is upon completion of the attendee
40
+	 * information reg step NO space reserved. Registration is NOT active
41
+	 */
42
+	const status_id_incomplete = 'RIC';
43
+
44
+	/**
45
+	 * Status ID (STS_ID on esp_status table) to indicate an UNAPPROVED registration.
46
+	 * Payments are NOT allowed.
47
+	 * Event Admin must manually toggle STS_ID for it to change
48
+	 * No space reserved.
49
+	 * Registration is active
50
+	 */
51
+	const status_id_not_approved = 'RNA';
52
+
53
+	/**
54
+	 * Status ID (STS_ID on esp_status table) to indicate registration is PENDING_PAYMENT .
55
+	 * Payments are allowed.
56
+	 * STS_ID will automatically be toggled to RAP if payment is made in full by the attendee
57
+	 * No space reserved.
58
+	 * Registration is active
59
+	 */
60
+	const status_id_pending_payment = 'RPP';
61
+
62
+	/**
63
+	 * Status ID (STS_ID on esp_status table) to indicate registration is on the WAIT_LIST .
64
+	 * Payments are allowed.
65
+	 * STS_ID will automatically be toggled to RAP if payment is made in full by the attendee
66
+	 * No space reserved.
67
+	 * Registration is active
68
+	 */
69
+	const status_id_wait_list = 'RWL';
70
+
71
+	/**
72
+	 * Status ID (STS_ID on esp_status table) to indicate an APPROVED registration.
73
+	 * the TXN may or may not be completed ( paid in full )
74
+	 * Payments are allowed.
75
+	 * A space IS reserved.
76
+	 * Registration is active
77
+	 */
78
+	const status_id_approved = 'RAP';
79
+
80
+	/**
81
+	 * Status ID (STS_ID on esp_status table) to indicate a registration was CANCELLED by the attendee.
82
+	 * Payments are NOT allowed.
83
+	 * NO space reserved.
84
+	 * Registration is NOT active
85
+	 */
86
+	const status_id_cancelled = 'RCN';
87
+
88
+	/**
89
+	 * Status ID (STS_ID on esp_status table) to indicate a registration was DECLINED by the Event Admin
90
+	 * Payments are NOT allowed.
91
+	 * No space reserved.
92
+	 * Registration is NOT active
93
+	 */
94
+	const status_id_declined = 'RDC';
95
+
96
+	/**
97
+	 * @var TableAnalysis $table_analysis
98
+	 */
99
+	protected $_table_analysis;
100
+
101
+
102
+	/**
103
+	 *    private constructor to prevent direct creation
104
+	 *
105
+	 * @Constructor
106
+	 * @access protected
107
+	 * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any
108
+	 *                         incoming timezone data that gets saved). Note this just sends the timezone info to the
109
+	 *                         date time model field objects.  Default is NULL (and will be assumed using the set
110
+	 *                         timezone in the 'timezone_string' wp option)
111
+	 * @throws EE_Error
112
+	 */
113
+	protected function __construct($timezone = null)
114
+	{
115
+		$this->_table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
116
+		$this->singular_item = esc_html__('Registration', 'event_espresso');
117
+		$this->plural_item = esc_html__('Registrations', 'event_espresso');
118
+		$this->_tables = array(
119
+			'Registration' => new EE_Primary_Table('esp_registration', 'REG_ID'),
120
+		);
121
+		$this->_fields = array(
122
+			'Registration' => array(
123
+				'REG_ID' => new EE_Primary_Key_Int_Field(
124
+					'REG_ID',
125
+					esc_html__('Registration ID', 'event_espresso')
126
+				),
127
+				'EVT_ID' => new EE_Foreign_Key_Int_Field(
128
+					'EVT_ID',
129
+					esc_html__('Event ID', 'event_espresso'),
130
+					false,
131
+					0,
132
+					'Event'
133
+				),
134
+				'ATT_ID' => new EE_Foreign_Key_Int_Field(
135
+					'ATT_ID',
136
+					esc_html__('Attendee ID', 'event_espresso'),
137
+					false,
138
+					0,
139
+					'Attendee'
140
+				),
141
+				'TXN_ID' => new EE_Foreign_Key_Int_Field(
142
+					'TXN_ID',
143
+					esc_html__('Transaction ID', 'event_espresso'),
144
+					false,
145
+					0,
146
+					'Transaction'
147
+				),
148
+				'TKT_ID' => new EE_Foreign_Key_Int_Field(
149
+					'TKT_ID',
150
+					esc_html__('Ticket ID', 'event_espresso'),
151
+					false,
152
+					0,
153
+					'Ticket'
154
+				),
155
+				'STS_ID' => new EE_Foreign_Key_String_Field(
156
+					'STS_ID',
157
+					esc_html__('Status ID', 'event_espresso'),
158
+					false,
159
+					EEM_Registration::status_id_incomplete,
160
+					'Status'
161
+				),
162
+				'REG_date' => new EE_Datetime_Field(
163
+					'REG_date',
164
+					esc_html__('Time registration occurred', 'event_espresso'),
165
+					false,
166
+					EE_Datetime_Field::now,
167
+					$timezone
168
+				),
169
+				'REG_final_price' => new EE_Money_Field(
170
+					'REG_final_price',
171
+					esc_html__('Registration\'s share of the transaction total', 'event_espresso'),
172
+					false,
173
+					0
174
+				),
175
+				'REG_paid' => new EE_Money_Field(
176
+					'REG_paid',
177
+					esc_html__('Amount paid to date towards registration', 'event_espresso'),
178
+					false,
179
+					0
180
+				),
181
+				'REG_session' => new EE_Plain_Text_Field(
182
+					'REG_session',
183
+					esc_html__('Session ID of registration', 'event_espresso'),
184
+					false,
185
+					''
186
+				),
187
+				'REG_code' => new EE_Plain_Text_Field(
188
+					'REG_code',
189
+					esc_html__('Unique Code for this registration', 'event_espresso'),
190
+					false,
191
+					''
192
+				),
193
+				'REG_url_link' => new EE_Plain_Text_Field(
194
+					'REG_url_link',
195
+					esc_html__('String to be used in URL for identifying registration', 'event_espresso'),
196
+					false,
197
+					''
198
+				),
199
+				'REG_count' => new EE_Integer_Field(
200
+					'REG_count',
201
+					esc_html__('Count of this registration in the group registration ', 'event_espresso'),
202
+					true,
203
+					1
204
+				),
205
+				'REG_group_size' => new EE_Integer_Field(
206
+					'REG_group_size',
207
+					esc_html__('Number of registrations on this group', 'event_espresso'),
208
+					false,
209
+					1
210
+				),
211
+				'REG_att_is_going' => new EE_Boolean_Field(
212
+					'REG_att_is_going',
213
+					esc_html__('Flag indicating the registrant plans on attending', 'event_espresso'),
214
+					false,
215
+					false
216
+				),
217
+				'REG_deleted' => new EE_Trashed_Flag_Field(
218
+					'REG_deleted',
219
+					esc_html__('Flag indicating if registration has been archived or not.', 'event_espresso'),
220
+					false,
221
+					false
222
+				),
223
+			),
224
+		);
225
+		$this->_model_relations = array(
226
+			'Event' => new EE_Belongs_To_Relation(),
227
+			'Attendee' => new EE_Belongs_To_Relation(),
228
+			'Transaction' => new EE_Belongs_To_Relation(),
229
+			'Ticket' => new EE_Belongs_To_Relation(),
230
+			'Status' => new EE_Belongs_To_Relation(),
231
+			'Answer' => new EE_Has_Many_Relation(),
232
+			'Checkin' => new EE_Has_Many_Relation(),
233
+			'Registration_Payment' => new EE_Has_Many_Relation(),
234
+			'Payment' => new EE_HABTM_Relation('Registration_Payment'),
235
+			'Message' => new EE_Has_Many_Any_Relation(false)
236
+			// allow deletes even if there are messages in the queue related
237
+		);
238
+		$this->_model_chain_to_wp_user = 'Event';
239
+		parent::__construct($timezone);
240
+	}
241
+
242
+
243
+	/**
244
+	 * a list of ALL valid registration statuses currently in use within the system
245
+	 * generated by combining the filterable active and inactive reg status arrays
246
+	 *
247
+	 * @return array
248
+	 */
249
+	public static function reg_statuses()
250
+	{
251
+		return array_unique(
252
+			array_merge(
253
+				EEM_Registration::active_reg_statuses(),
254
+				EEM_Registration::inactive_reg_statuses()
255
+			)
256
+		);
257
+	}
258
+
259
+
260
+	/**
261
+	 * reg_statuses_that_allow_payment
262
+	 * a filterable list of registration statuses that allow a registrant to make a payment
263
+	 *
264
+	 * @access public
265
+	 * @return array
266
+	 */
267
+	public static function reg_statuses_that_allow_payment()
268
+	{
269
+		return apply_filters(
270
+			'FHEE__EEM_Registration__reg_statuses_that_allow_payment',
271
+			array(
272
+				EEM_Registration::status_id_approved,
273
+				EEM_Registration::status_id_pending_payment,
274
+			)
275
+		);
276
+	}
277
+
278
+
279
+	/**
280
+	 * active_reg_statuses
281
+	 * a filterable list of registration statuses that are considered active
282
+	 *
283
+	 * @access public
284
+	 * @return array
285
+	 */
286
+	public static function active_reg_statuses()
287
+	{
288
+		return apply_filters(
289
+			'FHEE__EEM_Registration__active_reg_statuses',
290
+			array(
291
+				EEM_Registration::status_id_approved,
292
+				EEM_Registration::status_id_pending_payment,
293
+				EEM_Registration::status_id_wait_list,
294
+				EEM_Registration::status_id_not_approved,
295
+			)
296
+		);
297
+	}
298
+
299
+
300
+	/**
301
+	 * inactive_reg_statuses
302
+	 * a filterable list of registration statuses that are not considered active
303
+	 *
304
+	 * @access public
305
+	 * @return array
306
+	 */
307
+	public static function inactive_reg_statuses()
308
+	{
309
+		return apply_filters(
310
+			'FHEE__EEM_Registration__inactive_reg_statuses',
311
+			array(
312
+				EEM_Registration::status_id_incomplete,
313
+				EEM_Registration::status_id_cancelled,
314
+				EEM_Registration::status_id_declined,
315
+			)
316
+		);
317
+	}
318
+
319
+
320
+	/**
321
+	 *    closed_reg_statuses
322
+	 *    a filterable list of registration statuses that are considered "closed"
323
+	 * meaning they should not be considered in any calculations involving monies owing
324
+	 *
325
+	 * @access public
326
+	 * @return array
327
+	 */
328
+	public static function closed_reg_statuses()
329
+	{
330
+		return apply_filters(
331
+			'FHEE__EEM_Registration__closed_reg_statuses',
332
+			array(
333
+				EEM_Registration::status_id_cancelled,
334
+				EEM_Registration::status_id_declined,
335
+				EEM_Registration::status_id_wait_list,
336
+			)
337
+		);
338
+	}
339
+
340
+
341
+	/**
342
+	 *        get list of registration statuses
343
+	 *
344
+	 * @access public
345
+	 * @param array $exclude The status ids to exclude from the returned results
346
+	 * @param bool $translated If true will return the values as singular localized strings
347
+	 * @return array
348
+	 * @throws EE_Error
349
+	 */
350
+	public static function reg_status_array($exclude = array(), $translated = false)
351
+	{
352
+		EEM_Registration::instance()->_get_registration_status_array($exclude);
353
+		return $translated
354
+			? EEM_Status::instance()->localized_status(self::$_reg_status, false, 'sentence')
355
+			: self::$_reg_status;
356
+	}
357
+
358
+
359
+	/**
360
+	 *    get list of registration statuses
361
+	 *
362
+	 * @access private
363
+	 * @param array $exclude
364
+	 * @return void
365
+	 * @throws EE_Error
366
+	 */
367
+	private function _get_registration_status_array($exclude = array())
368
+	{
369
+		// in the very rare circumstance that we are deleting a model's table's data
370
+		// and the table hasn't actually been created, this could have an error
371
+		/** @type WPDB $wpdb */
372
+		global $wpdb;
373
+		if ($this->_get_table_analysis()->tableExists($wpdb->prefix . 'esp_status')) {
374
+			$results = $wpdb->get_results(
375
+				"SELECT STS_ID, STS_code FROM {$wpdb->prefix}esp_status WHERE STS_type = 'registration'"
376
+			);
377
+			self::$_reg_status = array();
378
+			foreach ($results as $status) {
379
+				if (!in_array($status->STS_ID, $exclude, true)) {
380
+					self::$_reg_status[ $status->STS_ID ] = $status->STS_code;
381
+				}
382
+			}
383
+		}
384
+	}
385
+
386
+
387
+	/**
388
+	 * Gets the injected table analyzer, or throws an exception
389
+	 *
390
+	 * @return TableAnalysis
391
+	 * @throws EE_Error
392
+	 */
393
+	protected function _get_table_analysis()
394
+	{
395
+		if ($this->_table_analysis instanceof TableAnalysis) {
396
+			return $this->_table_analysis;
397
+		}
398
+		throw new EE_Error(
399
+			sprintf(
400
+				esc_html__('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
401
+				get_class($this)
402
+			)
403
+		);
404
+	}
405
+
406
+
407
+	/**
408
+	 * This returns a wpdb->results array of all registration date month and years matching the incoming query params
409
+	 * and grouped by month and year.
410
+	 *
411
+	 * @param  array $where_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions
412
+	 * @return array
413
+	 * @throws EE_Error
414
+	 */
415
+	public function get_reg_months_and_years($where_params)
416
+	{
417
+		$query_params[0] = $where_params;
418
+		$query_params['group_by'] = array('reg_year', 'reg_month');
419
+		$query_params['order_by'] = array('REG_date' => 'DESC');
420
+		$columns_to_select = array(
421
+			'reg_year' => array('YEAR(REG_date)', '%s'),
422
+			'reg_month' => array('MONTHNAME(REG_date)', '%s'),
423
+		);
424
+		return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
425
+	}
426
+
427
+
428
+	/**
429
+	 * retrieve ALL registrations for a particular Attendee from db
430
+	 *
431
+	 * @param int $ATT_ID
432
+	 * @return EE_Base_Class[]|EE_Registration[]|null
433
+	 * @throws EE_Error
434
+	 */
435
+	public function get_all_registrations_for_attendee($ATT_ID = 0)
436
+	{
437
+		if (!$ATT_ID) {
438
+			return null;
439
+		}
440
+		return $this->get_all(array(array('ATT_ID' => $ATT_ID)));
441
+	}
442
+
443
+
444
+	/**
445
+	 * Gets a registration given their REG_url_link. Yes, this should usually
446
+	 * be passed via a GET parameter.
447
+	 *
448
+	 * @param string $REG_url_link
449
+	 * @return EE_Base_Class|EE_Registration|null
450
+	 * @throws EE_Error
451
+	 */
452
+	public function get_registration_for_reg_url_link($REG_url_link)
453
+	{
454
+		if (!$REG_url_link) {
455
+			return null;
456
+		}
457
+		return $this->get_one(array(array('REG_url_link' => $REG_url_link)));
458
+	}
459
+
460
+
461
+	/**
462
+	 *        retrieve registration for a specific transaction attendee from db
463
+	 *
464
+	 * @access        public
465
+	 * @param    int $TXN_ID
466
+	 * @param    int $ATT_ID
467
+	 * @param    int $att_nmbr in case the ATT_ID is the same for multiple registrations (same details used) then the
468
+	 *                         attendee number is required
469
+	 * @return        mixed        array on success, FALSE on fail
470
+	 * @throws EE_Error
471
+	 */
472
+	public function get_registration_for_transaction_attendee($TXN_ID = 0, $ATT_ID = 0, $att_nmbr = 0)
473
+	{
474
+		return $this->get_one(array(
475
+			array(
476
+				'TXN_ID' => $TXN_ID,
477
+				'ATT_ID' => $ATT_ID,
478
+			),
479
+			'limit' => array(min($att_nmbr - 1, 0), 1),
480
+		));
481
+	}
482
+
483
+
484
+	/**
485
+	 *        get the number of registrations per day  for the Registration Admin page Reports Tab.
486
+	 *        (doesn't utilize models because it's a fairly specialized query)
487
+	 *
488
+	 * @access        public
489
+	 * @param $period string which can be passed to php's strtotime function (eg "-1 month")
490
+	 * @return stdClass[] with properties regDate and total
491
+	 * @throws EE_Error
492
+	 */
493
+	public function get_registrations_per_day_report($period = '-1 month')
494
+	{
495
+		$sql_date = $this->convert_datetime_for_query(
496
+			'REG_date',
497
+			date('Y-m-d H:i:s', strtotime($period)),
498
+			'Y-m-d H:i:s',
499
+			'UTC'
500
+		);
501
+		$where = array(
502
+			'REG_date' => array('>=', $sql_date),
503
+			'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
504
+		);
505
+		if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_day_report')) {
506
+			$where['Event.EVT_wp_user'] = get_current_user_id();
507
+		}
508
+		$query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'REG_date');
509
+		$results = $this->_get_all_wpdb_results(
510
+			array(
511
+				$where,
512
+				'group_by' => 'regDate',
513
+				'order_by' => array('REG_date' => 'ASC'),
514
+			),
515
+			OBJECT,
516
+			array(
517
+				'regDate' => array('DATE(' . $query_interval . ')', '%s'),
518
+				'total' => array('count(REG_ID)', '%d'),
519
+			)
520
+		);
521
+		return $results;
522
+	}
523
+
524
+
525
+	/**
526
+	 * Get the number of registrations per day including the count of registrations for each Registration Status.
527
+	 * Note: EEM_Registration::status_id_incomplete registrations are excluded from the results.
528
+	 *
529
+	 * @param string $period
530
+	 * @return stdClass[] with properties Registration_REG_date and a column for each registration status as the STS_ID
531
+	 * @throws EE_Error
532
+	 *                    (i.e. RAP)
533
+	 */
534
+	public function get_registrations_per_day_and_per_status_report($period = '-1 month')
535
+	{
536
+		global $wpdb;
537
+		$registration_table = $wpdb->prefix . 'esp_registration';
538
+		$event_table = $wpdb->posts;
539
+		$sql_date = date('Y-m-d H:i:s', strtotime($period));
540
+		// prepare the query interval for displaying offset
541
+		$query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'dates.REG_date');
542
+		// inner date query
543
+		$inner_date_query = "SELECT DISTINCT REG_date from {$registration_table} ";
544
+		$inner_where = ' WHERE';
545
+		// exclude events not authored by user if permissions in effect
546
+		if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
547
+			$inner_date_query .= "LEFT JOIN {$event_table} ON ID = EVT_ID";
548
+			$inner_where .= ' post_author = ' . get_current_user_id() . ' AND';
549
+		}
550
+		$inner_where .= " REG_date >= '{$sql_date}'";
551
+		$inner_date_query .= $inner_where;
552
+		// start main query
553
+		$select = "SELECT DATE({$query_interval}) as Registration_REG_date, ";
554
+		$join = '';
555
+		$join_parts = array();
556
+		$select_parts = array();
557
+		// loop through registration stati to do parts for each status.
558
+		foreach (EEM_Registration::reg_status_array() as $STS_ID => $STS_code) {
559
+			if ($STS_ID === EEM_Registration::status_id_incomplete) {
560
+				continue;
561
+			}
562
+			$select_parts[] = "COUNT({$STS_code}.REG_ID) as {$STS_ID}";
563
+			$join_parts[] = "{$registration_table} AS {$STS_code} ON {$STS_code}.REG_date = dates.REG_date AND {$STS_code}.STS_ID = '{$STS_ID}'";
564
+		}
565
+		// setup the selects
566
+		$select .= implode(', ', $select_parts);
567
+		$select .= " FROM ($inner_date_query) AS dates LEFT JOIN ";
568
+		// setup the joins
569
+		$join .= implode(' LEFT JOIN ', $join_parts);
570
+		// now let's put it all together
571
+		$query = $select . $join . ' GROUP BY Registration_REG_date';
572
+		// and execute it
573
+		return $wpdb->get_results($query, ARRAY_A);
574
+	}
575
+
576
+
577
+	/**
578
+	 *        get the number of registrations per event  for the Registration Admin page Reports Tab
579
+	 *
580
+	 * @access        public
581
+	 * @param $period string which can be passed to php's strtotime function (eg "-1 month")
582
+	 * @return stdClass[] each with properties event_name, reg_limit, and total
583
+	 * @throws EE_Error
584
+	 */
585
+	public function get_registrations_per_event_report($period = '-1 month')
586
+	{
587
+		$date_sql = $this->convert_datetime_for_query(
588
+			'REG_date',
589
+			date('Y-m-d H:i:s', strtotime($period)),
590
+			'Y-m-d H:i:s',
591
+			'UTC'
592
+		);
593
+		$where = array(
594
+			'REG_date' => array('>=', $date_sql),
595
+			'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
596
+		);
597
+		if (
598
+			!EE_Registry::instance()->CAP->current_user_can(
599
+				'ee_read_others_registrations',
600
+				'reg_per_event_report'
601
+			)
602
+		) {
603
+			$where['Event.EVT_wp_user'] = get_current_user_id();
604
+		}
605
+		$results = $this->_get_all_wpdb_results(
606
+			array(
607
+			$where,
608
+			'group_by' => 'Event.EVT_name',
609
+			'order_by' => 'Event.EVT_name',
610
+			'limit' => array(0, 24),
611
+			),
612
+			OBJECT,
613
+			array(
614
+				'event_name' => array('Event_CPT.post_title', '%s'),
615
+				'total' => array('COUNT(REG_ID)', '%s'),
616
+			)
617
+		);
618
+		return $results;
619
+	}
620
+
621
+
622
+	/**
623
+	 * Get the number of registrations per event grouped by registration status.
624
+	 * Note: EEM_Registration::status_id_incomplete registrations are excluded from the results.
625
+	 *
626
+	 * @param string $period
627
+	 * @return stdClass[] with properties `Registration_Event` and a column for each registration status as the STS_ID
628
+	 * @throws EE_Error
629
+	 *                    (i.e. RAP)
630
+	 */
631
+	public function get_registrations_per_event_and_per_status_report($period = '-1 month')
632
+	{
633
+		global $wpdb;
634
+		$registration_table = $wpdb->prefix . 'esp_registration';
635
+		$event_table = $wpdb->posts;
636
+		$sql_date = date('Y-m-d H:i:s', strtotime($period));
637
+		// inner date query
638
+		$inner_date_query = "SELECT DISTINCT EVT_ID, REG_date from $registration_table ";
639
+		$inner_where = ' WHERE';
640
+		// exclude events not authored by user if permissions in effect
641
+		if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
642
+			$inner_date_query .= "LEFT JOIN {$event_table} ON ID = EVT_ID";
643
+			$inner_where .= ' post_author = ' . get_current_user_id() . ' AND';
644
+		}
645
+		$inner_where .= " REG_date >= '{$sql_date}'";
646
+		$inner_date_query .= $inner_where;
647
+		// build main query
648
+		$select = 'SELECT Event.post_title as Registration_Event, ';
649
+		$join = '';
650
+		$join_parts = array();
651
+		$select_parts = array();
652
+		// loop through registration stati to do parts for each status.
653
+		foreach (EEM_Registration::reg_status_array() as $STS_ID => $STS_code) {
654
+			if ($STS_ID === EEM_Registration::status_id_incomplete) {
655
+				continue;
656
+			}
657
+			$select_parts[] = "COUNT({$STS_code}.REG_ID) as {$STS_ID}";
658
+			$join_parts[] = "{$registration_table} AS {$STS_code} ON {$STS_code}.EVT_ID = dates.EVT_ID AND {$STS_code}.STS_ID = '{$STS_ID}' AND {$STS_code}.REG_date = dates.REG_date";
659
+		}
660
+		// setup the selects
661
+		$select .= implode(', ', $select_parts);
662
+		$select .= " FROM ($inner_date_query) AS dates LEFT JOIN $event_table as Event ON Event.ID = dates.EVT_ID LEFT JOIN ";
663
+		// setup remaining joins
664
+		$join .= implode(' LEFT JOIN ', $join_parts);
665
+		// now put it all together
666
+		$query = $select . $join . ' GROUP BY Registration_Event';
667
+		// and execute
668
+		return $wpdb->get_results($query, ARRAY_A);
669
+	}
670
+
671
+
672
+	/**
673
+	 * Returns the EE_Registration of the primary attendee on the transaction id provided
674
+	 *
675
+	 * @param int $TXN_ID
676
+	 * @return EE_Base_Class|EE_Registration|null
677
+	 * @throws EE_Error
678
+	 */
679
+	public function get_primary_registration_for_transaction_ID($TXN_ID = 0)
680
+	{
681
+		if (!$TXN_ID) {
682
+			return null;
683
+		}
684
+		return $this->get_one(array(
685
+			array(
686
+				'TXN_ID' => $TXN_ID,
687
+				'REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT,
688
+			),
689
+		));
690
+	}
691
+
692
+
693
+	/**
694
+	 *        get_event_registration_count
695
+	 *
696
+	 * @access public
697
+	 * @param int $EVT_ID
698
+	 * @param boolean $for_incomplete_payments
699
+	 * @return int
700
+	 * @throws EE_Error
701
+	 */
702
+	public function get_event_registration_count($EVT_ID, $for_incomplete_payments = false)
703
+	{
704
+		// we only count approved registrations towards registration limits
705
+		$query_params = array(array('EVT_ID' => $EVT_ID, 'STS_ID' => self::status_id_approved));
706
+		if ($for_incomplete_payments) {
707
+			$query_params[0]['Transaction.STS_ID'] = array('!=', EEM_Transaction::complete_status_code);
708
+		}
709
+		return $this->count($query_params);
710
+	}
711
+
712
+
713
+	/**
714
+	 * Deletes all registrations with no transactions. Note that this needs to be very efficient
715
+	 * and so it uses wpdb directly. Also, we can't put a limit on this because MySQL doesn't allow a limit on a delete
716
+	 * when joining tables like this.
717
+	 *
718
+	 * @global WPDB $wpdb
719
+	 * @return int number deleted
720
+	 * @throws EE_Error
721
+	 */
722
+	public function delete_registrations_with_no_transaction()
723
+	{
724
+		/** @type WPDB $wpdb */
725
+		global $wpdb;
726
+		return $wpdb->query(
727
+			'DELETE r FROM '
728
+			. $this->table()
729
+			. ' r LEFT JOIN '
730
+			. EEM_Transaction::instance()->table()
731
+			. ' t ON r.TXN_ID = t.TXN_ID WHERE t.TXN_ID IS NULL'
732
+		);
733
+	}
734
+
735
+
736
+	/**
737
+	 *  Count registrations checked into (or out of) a datetime
738
+	 *
739
+	 * @param int $DTT_ID datetime ID
740
+	 * @param boolean $checked_in whether to count registrations checked IN or OUT
741
+	 * @return int
742
+	 * @throws EE_Error
743
+	 */
744
+	public function count_registrations_checked_into_datetime($DTT_ID, $checked_in = true)
745
+	{
746
+		global $wpdb;
747
+		// subquery to get latest checkin
748
+		$query = $wpdb->prepare(
749
+			'SELECT '
750
+			. 'COUNT( DISTINCT checkins.REG_ID ) '
751
+			. 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN'
752
+			. '( SELECT '
753
+			. 'max( CHK_timestamp ) AS latest_checkin, '
754
+			. 'REG_ID AS REG_ID '
755
+			. 'FROM ' . EEM_Checkin::instance()->table() . ' '
756
+			. 'WHERE DTT_ID=%d '
757
+			. 'GROUP BY REG_ID'
758
+			. ') AS most_recent_checkin_per_reg '
759
+			. 'ON checkins.REG_ID=most_recent_checkin_per_reg.REG_ID '
760
+			. 'AND checkins.CHK_timestamp = most_recent_checkin_per_reg.latest_checkin '
761
+			. 'WHERE '
762
+			. 'checkins.CHK_in=%d',
763
+			$DTT_ID,
764
+			$checked_in
765
+		);
766
+		return (int) $wpdb->get_var($query);
767
+	}
768
+
769
+
770
+	/**
771
+	 *  Count registrations checked into (or out of) an event.
772
+	 *
773
+	 * @param int $EVT_ID event ID
774
+	 * @param boolean $checked_in whether to count registrations checked IN or OUT
775
+	 * @return int
776
+	 * @throws EE_Error
777
+	 */
778
+	public function count_registrations_checked_into_event($EVT_ID, $checked_in = true)
779
+	{
780
+		global $wpdb;
781
+		// subquery to get latest checkin
782
+		$query = $wpdb->prepare(
783
+			'SELECT '
784
+			. 'COUNT( DISTINCT checkins.REG_ID ) '
785
+			. 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN'
786
+			. '( SELECT '
787
+			. 'max( CHK_timestamp ) AS latest_checkin, '
788
+			. 'REG_ID AS REG_ID '
789
+			. 'FROM ' . EEM_Checkin::instance()->table() . ' AS c '
790
+			. 'INNER JOIN ' . EEM_Datetime::instance()->table() . ' AS d '
791
+			. 'ON c.DTT_ID=d.DTT_ID '
792
+			. 'WHERE d.EVT_ID=%d '
793
+			. 'GROUP BY REG_ID'
794
+			. ') AS most_recent_checkin_per_reg '
795
+			. 'ON checkins.REG_ID=most_recent_checkin_per_reg.REG_ID '
796
+			. 'AND checkins.CHK_timestamp = most_recent_checkin_per_reg.latest_checkin '
797
+			. 'WHERE '
798
+			. 'checkins.CHK_in=%d',
799
+			$EVT_ID,
800
+			$checked_in
801
+		);
802
+		return (int) $wpdb->get_var($query);
803
+	}
804
+
805
+
806
+	/**
807
+	 * The purpose of this method is to retrieve an array of
808
+	 * EE_Registration objects that represent the latest registration
809
+	 * for each ATT_ID given in the function argument.
810
+	 *
811
+	 * @param array $attendee_ids
812
+	 * @return EE_Base_Class[]|EE_Registration[]
813
+	 * @throws EE_Error
814
+	 */
815
+	public function get_latest_registration_for_each_of_given_contacts($attendee_ids = array())
816
+	{
817
+		// first do a native wp_query to get the latest REG_ID's matching these attendees.
818
+		global $wpdb;
819
+		$registration_table = $wpdb->prefix . 'esp_registration';
820
+		$attendee_table = $wpdb->posts;
821
+		$attendee_ids = is_array($attendee_ids)
822
+			? array_map('absint', $attendee_ids)
823
+			: array((int) $attendee_ids);
824
+		$ATT_IDs = implode(',', $attendee_ids);
825
+		// first we do a query to get the registration ids
826
+		// (because a group by before order by causes the order by to be ignored.)
827
+		$registration_id_query = "
828 828
 			SELECT registrations.registration_ids as registration_id
829 829
 			FROM (
830 830
 				SELECT
@@ -838,61 +838,61 @@  discard block
 block discarded – undo
838 838
 			  ) AS registrations
839 839
 			  GROUP BY registrations.attendee_ids
840 840
 		";
841
-        $registration_ids = $wpdb->get_results($registration_id_query, ARRAY_A);
842
-        if (empty($registration_ids)) {
843
-            return array();
844
-        }
845
-        $ids_for_model_query = array();
846
-        // let's flatten the ids so they can be used in the model query.
847
-        foreach ($registration_ids as $registration_id) {
848
-            if (isset($registration_id['registration_id'])) {
849
-                $ids_for_model_query[] = $registration_id['registration_id'];
850
-            }
851
-        }
852
-        // construct query
853
-        $_where = array(
854
-            'REG_ID' => array('IN', $ids_for_model_query),
855
-        );
856
-        return $this->get_all(array($_where));
857
-    }
858
-
859
-
860
-
861
-    /**
862
-     * returns a count of registrations for the supplied event having the status as specified
863
-     *
864
-     * @param int $EVT_ID
865
-     * @param array $statuses
866
-     * @return int
867
-     * @throws InvalidArgumentException
868
-     * @throws InvalidStatusException
869
-     * @throws EE_Error
870
-     */
871
-    public function event_reg_count_for_statuses($EVT_ID, $statuses = array())
872
-    {
873
-        $EVT_ID = absint($EVT_ID);
874
-        if (! $EVT_ID) {
875
-            throw new InvalidArgumentException(
876
-                esc_html__('An invalid Event ID was supplied.', 'event_espresso')
877
-            );
878
-        }
879
-        $statuses = is_array($statuses) ? $statuses : array($statuses);
880
-        $statuses = ! empty($statuses) ? $statuses : array(EEM_Registration::status_id_approved);
881
-        $valid_reg_statuses = EEM_Registration::reg_statuses();
882
-        foreach ($statuses as $status) {
883
-            if (! in_array($status, $valid_reg_statuses, true)) {
884
-                throw new InvalidStatusException($status, esc_html__('Registration', 'event_espresso'));
885
-            }
886
-        }
887
-        return $this->count(
888
-            array(
889
-                array(
890
-                    'EVT_ID' => $EVT_ID,
891
-                    'STS_ID' => array('IN', $statuses),
892
-                ),
893
-            ),
894
-            'REG_ID',
895
-            true
896
-        );
897
-    }
841
+		$registration_ids = $wpdb->get_results($registration_id_query, ARRAY_A);
842
+		if (empty($registration_ids)) {
843
+			return array();
844
+		}
845
+		$ids_for_model_query = array();
846
+		// let's flatten the ids so they can be used in the model query.
847
+		foreach ($registration_ids as $registration_id) {
848
+			if (isset($registration_id['registration_id'])) {
849
+				$ids_for_model_query[] = $registration_id['registration_id'];
850
+			}
851
+		}
852
+		// construct query
853
+		$_where = array(
854
+			'REG_ID' => array('IN', $ids_for_model_query),
855
+		);
856
+		return $this->get_all(array($_where));
857
+	}
858
+
859
+
860
+
861
+	/**
862
+	 * returns a count of registrations for the supplied event having the status as specified
863
+	 *
864
+	 * @param int $EVT_ID
865
+	 * @param array $statuses
866
+	 * @return int
867
+	 * @throws InvalidArgumentException
868
+	 * @throws InvalidStatusException
869
+	 * @throws EE_Error
870
+	 */
871
+	public function event_reg_count_for_statuses($EVT_ID, $statuses = array())
872
+	{
873
+		$EVT_ID = absint($EVT_ID);
874
+		if (! $EVT_ID) {
875
+			throw new InvalidArgumentException(
876
+				esc_html__('An invalid Event ID was supplied.', 'event_espresso')
877
+			);
878
+		}
879
+		$statuses = is_array($statuses) ? $statuses : array($statuses);
880
+		$statuses = ! empty($statuses) ? $statuses : array(EEM_Registration::status_id_approved);
881
+		$valid_reg_statuses = EEM_Registration::reg_statuses();
882
+		foreach ($statuses as $status) {
883
+			if (! in_array($status, $valid_reg_statuses, true)) {
884
+				throw new InvalidStatusException($status, esc_html__('Registration', 'event_espresso'));
885
+			}
886
+		}
887
+		return $this->count(
888
+			array(
889
+				array(
890
+					'EVT_ID' => $EVT_ID,
891
+					'STS_ID' => array('IN', $statuses),
892
+				),
893
+			),
894
+			'REG_ID',
895
+			true
896
+		);
897
+	}
898 898
 }
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -370,14 +370,14 @@  discard block
 block discarded – undo
370 370
         // and the table hasn't actually been created, this could have an error
371 371
         /** @type WPDB $wpdb */
372 372
         global $wpdb;
373
-        if ($this->_get_table_analysis()->tableExists($wpdb->prefix . 'esp_status')) {
373
+        if ($this->_get_table_analysis()->tableExists($wpdb->prefix.'esp_status')) {
374 374
             $results = $wpdb->get_results(
375 375
                 "SELECT STS_ID, STS_code FROM {$wpdb->prefix}esp_status WHERE STS_type = 'registration'"
376 376
             );
377 377
             self::$_reg_status = array();
378 378
             foreach ($results as $status) {
379
-                if (!in_array($status->STS_ID, $exclude, true)) {
380
-                    self::$_reg_status[ $status->STS_ID ] = $status->STS_code;
379
+                if ( ! in_array($status->STS_ID, $exclude, true)) {
380
+                    self::$_reg_status[$status->STS_ID] = $status->STS_code;
381 381
                 }
382 382
             }
383 383
         }
@@ -434,7 +434,7 @@  discard block
 block discarded – undo
434 434
      */
435 435
     public function get_all_registrations_for_attendee($ATT_ID = 0)
436 436
     {
437
-        if (!$ATT_ID) {
437
+        if ( ! $ATT_ID) {
438 438
             return null;
439 439
         }
440 440
         return $this->get_all(array(array('ATT_ID' => $ATT_ID)));
@@ -451,7 +451,7 @@  discard block
 block discarded – undo
451 451
      */
452 452
     public function get_registration_for_reg_url_link($REG_url_link)
453 453
     {
454
-        if (!$REG_url_link) {
454
+        if ( ! $REG_url_link) {
455 455
             return null;
456 456
         }
457 457
         return $this->get_one(array(array('REG_url_link' => $REG_url_link)));
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
             'REG_date' => array('>=', $sql_date),
503 503
             'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
504 504
         );
505
-        if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_day_report')) {
505
+        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_day_report')) {
506 506
             $where['Event.EVT_wp_user'] = get_current_user_id();
507 507
         }
508 508
         $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'REG_date');
@@ -514,7 +514,7 @@  discard block
 block discarded – undo
514 514
             ),
515 515
             OBJECT,
516 516
             array(
517
-                'regDate' => array('DATE(' . $query_interval . ')', '%s'),
517
+                'regDate' => array('DATE('.$query_interval.')', '%s'),
518 518
                 'total' => array('count(REG_ID)', '%d'),
519 519
             )
520 520
         );
@@ -534,7 +534,7 @@  discard block
 block discarded – undo
534 534
     public function get_registrations_per_day_and_per_status_report($period = '-1 month')
535 535
     {
536 536
         global $wpdb;
537
-        $registration_table = $wpdb->prefix . 'esp_registration';
537
+        $registration_table = $wpdb->prefix.'esp_registration';
538 538
         $event_table = $wpdb->posts;
539 539
         $sql_date = date('Y-m-d H:i:s', strtotime($period));
540 540
         // prepare the query interval for displaying offset
@@ -543,9 +543,9 @@  discard block
 block discarded – undo
543 543
         $inner_date_query = "SELECT DISTINCT REG_date from {$registration_table} ";
544 544
         $inner_where = ' WHERE';
545 545
         // exclude events not authored by user if permissions in effect
546
-        if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
546
+        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
547 547
             $inner_date_query .= "LEFT JOIN {$event_table} ON ID = EVT_ID";
548
-            $inner_where .= ' post_author = ' . get_current_user_id() . ' AND';
548
+            $inner_where .= ' post_author = '.get_current_user_id().' AND';
549 549
         }
550 550
         $inner_where .= " REG_date >= '{$sql_date}'";
551 551
         $inner_date_query .= $inner_where;
@@ -568,7 +568,7 @@  discard block
 block discarded – undo
568 568
         // setup the joins
569 569
         $join .= implode(' LEFT JOIN ', $join_parts);
570 570
         // now let's put it all together
571
-        $query = $select . $join . ' GROUP BY Registration_REG_date';
571
+        $query = $select.$join.' GROUP BY Registration_REG_date';
572 572
         // and execute it
573 573
         return $wpdb->get_results($query, ARRAY_A);
574 574
     }
@@ -595,7 +595,7 @@  discard block
 block discarded – undo
595 595
             'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
596 596
         );
597 597
         if (
598
-            !EE_Registry::instance()->CAP->current_user_can(
598
+            ! EE_Registry::instance()->CAP->current_user_can(
599 599
                 'ee_read_others_registrations',
600 600
                 'reg_per_event_report'
601 601
             )
@@ -631,16 +631,16 @@  discard block
 block discarded – undo
631 631
     public function get_registrations_per_event_and_per_status_report($period = '-1 month')
632 632
     {
633 633
         global $wpdb;
634
-        $registration_table = $wpdb->prefix . 'esp_registration';
634
+        $registration_table = $wpdb->prefix.'esp_registration';
635 635
         $event_table = $wpdb->posts;
636 636
         $sql_date = date('Y-m-d H:i:s', strtotime($period));
637 637
         // inner date query
638 638
         $inner_date_query = "SELECT DISTINCT EVT_ID, REG_date from $registration_table ";
639 639
         $inner_where = ' WHERE';
640 640
         // exclude events not authored by user if permissions in effect
641
-        if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
641
+        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
642 642
             $inner_date_query .= "LEFT JOIN {$event_table} ON ID = EVT_ID";
643
-            $inner_where .= ' post_author = ' . get_current_user_id() . ' AND';
643
+            $inner_where .= ' post_author = '.get_current_user_id().' AND';
644 644
         }
645 645
         $inner_where .= " REG_date >= '{$sql_date}'";
646 646
         $inner_date_query .= $inner_where;
@@ -663,7 +663,7 @@  discard block
 block discarded – undo
663 663
         // setup remaining joins
664 664
         $join .= implode(' LEFT JOIN ', $join_parts);
665 665
         // now put it all together
666
-        $query = $select . $join . ' GROUP BY Registration_Event';
666
+        $query = $select.$join.' GROUP BY Registration_Event';
667 667
         // and execute
668 668
         return $wpdb->get_results($query, ARRAY_A);
669 669
     }
@@ -678,7 +678,7 @@  discard block
 block discarded – undo
678 678
      */
679 679
     public function get_primary_registration_for_transaction_ID($TXN_ID = 0)
680 680
     {
681
-        if (!$TXN_ID) {
681
+        if ( ! $TXN_ID) {
682 682
             return null;
683 683
         }
684 684
         return $this->get_one(array(
@@ -748,11 +748,11 @@  discard block
 block discarded – undo
748 748
         $query = $wpdb->prepare(
749 749
             'SELECT '
750 750
             . 'COUNT( DISTINCT checkins.REG_ID ) '
751
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN'
751
+            . 'FROM '.EEM_Checkin::instance()->table().' AS checkins INNER JOIN'
752 752
             . '( SELECT '
753 753
             . 'max( CHK_timestamp ) AS latest_checkin, '
754 754
             . 'REG_ID AS REG_ID '
755
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' '
755
+            . 'FROM '.EEM_Checkin::instance()->table().' '
756 756
             . 'WHERE DTT_ID=%d '
757 757
             . 'GROUP BY REG_ID'
758 758
             . ') AS most_recent_checkin_per_reg '
@@ -782,12 +782,12 @@  discard block
 block discarded – undo
782 782
         $query = $wpdb->prepare(
783 783
             'SELECT '
784 784
             . 'COUNT( DISTINCT checkins.REG_ID ) '
785
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN'
785
+            . 'FROM '.EEM_Checkin::instance()->table().' AS checkins INNER JOIN'
786 786
             . '( SELECT '
787 787
             . 'max( CHK_timestamp ) AS latest_checkin, '
788 788
             . 'REG_ID AS REG_ID '
789
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' AS c '
790
-            . 'INNER JOIN ' . EEM_Datetime::instance()->table() . ' AS d '
789
+            . 'FROM '.EEM_Checkin::instance()->table().' AS c '
790
+            . 'INNER JOIN '.EEM_Datetime::instance()->table().' AS d '
791 791
             . 'ON c.DTT_ID=d.DTT_ID '
792 792
             . 'WHERE d.EVT_ID=%d '
793 793
             . 'GROUP BY REG_ID'
@@ -816,7 +816,7 @@  discard block
 block discarded – undo
816 816
     {
817 817
         // first do a native wp_query to get the latest REG_ID's matching these attendees.
818 818
         global $wpdb;
819
-        $registration_table = $wpdb->prefix . 'esp_registration';
819
+        $registration_table = $wpdb->prefix.'esp_registration';
820 820
         $attendee_table = $wpdb->posts;
821 821
         $attendee_ids = is_array($attendee_ids)
822 822
             ? array_map('absint', $attendee_ids)
@@ -871,7 +871,7 @@  discard block
 block discarded – undo
871 871
     public function event_reg_count_for_statuses($EVT_ID, $statuses = array())
872 872
     {
873 873
         $EVT_ID = absint($EVT_ID);
874
-        if (! $EVT_ID) {
874
+        if ( ! $EVT_ID) {
875 875
             throw new InvalidArgumentException(
876 876
                 esc_html__('An invalid Event ID was supplied.', 'event_espresso')
877 877
             );
@@ -880,7 +880,7 @@  discard block
 block discarded – undo
880 880
         $statuses = ! empty($statuses) ? $statuses : array(EEM_Registration::status_id_approved);
881 881
         $valid_reg_statuses = EEM_Registration::reg_statuses();
882 882
         foreach ($statuses as $status) {
883
-            if (! in_array($status, $valid_reg_statuses, true)) {
883
+            if ( ! in_array($status, $valid_reg_statuses, true)) {
884 884
                 throw new InvalidStatusException($status, esc_html__('Registration', 'event_espresso'));
885 885
             }
886 886
         }
Please login to merge, or discard this patch.
core/db_models/EEM_Soft_Delete_Base.model.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
      */
33 33
     protected function __construct($timezone = null)
34 34
     {
35
-        if (! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
35
+        if ( ! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
36 36
             $this->_default_where_conditions_strategy = new EE_Soft_Delete_Where_Conditions();
37 37
         }
38 38
         parent::__construct($timezone);
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
     protected function _alter_query_params_so_only_trashed_items_included($query_params)
134 134
     {
135 135
         $deletedFlagFieldName = $this->deleted_field_name();
136
-        $query_params[0][ $deletedFlagFieldName ] = true;
136
+        $query_params[0][$deletedFlagFieldName] = true;
137 137
         return $query_params;
138 138
     }
139 139
 
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
      */
174 174
     protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params)
175 175
     {
176
-        if (! isset($query_params['default_where_conditions'])) {
176
+        if ( ! isset($query_params['default_where_conditions'])) {
177 177
             $query_params['default_where_conditions'] = 'minimum';
178 178
         }
179 179
         return $query_params;
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
      */
302 302
     public function delete_or_restore_by_ID($delete = true, $ID = false)
303 303
     {
304
-        if (! $ID) {
304
+        if ( ! $ID) {
305 305
             return false;
306 306
         }
307 307
         if (
Please login to merge, or discard this patch.
Indentation   +361 added lines, -361 removed lines patch added patch discarded remove patch
@@ -27,365 +27,365 @@
 block discarded – undo
27 27
 abstract class EEM_Soft_Delete_Base extends EEM_Base
28 28
 {
29 29
 
30
-    /**
31
-     * @param null $timezone
32
-     */
33
-    protected function __construct($timezone = null)
34
-    {
35
-        if (! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
36
-            $this->_default_where_conditions_strategy = new EE_Soft_Delete_Where_Conditions();
37
-        }
38
-        parent::__construct($timezone);
39
-    }
40
-
41
-
42
-
43
-    /**
44
-     * Searches for field on this model of type 'deleted_flag'. if it is found,
45
-     * returns it's name.
46
-     *
47
-     * @return string
48
-     * @throws EE_Error
49
-     */
50
-    public function deleted_field_name()
51
-    {
52
-        $field = $this->get_a_field_of_type('EE_Trashed_Flag_Field');
53
-        if ($field) {
54
-            return $field->get_name();
55
-        } else {
56
-            throw new EE_Error(sprintf(esc_html__(
57
-                'We are trying to find the deleted flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?',
58
-                'event_espresso'
59
-            ), get_class($this), get_class($this)));
60
-        }
61
-    }
62
-
63
-
64
-
65
-    /**
66
-     * Gets one item that's been deleted, according to $query_params
67
-     *
68
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
69
-     * @return EE_Soft_Delete_Base_Class
70
-     */
71
-    public function get_one_deleted($query_params = array())
72
-    {
73
-        $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
74
-        return parent::get_one($query_params);
75
-    }
76
-
77
-
78
-
79
-    /**
80
-     * Gets one item from the DB, regardless of whether it's been soft-deleted or not
81
-     *
82
-     * @param array $query_params like EEM_base::get_all's $query_params
83
-     * @return EE_Soft_Delete_Base_Class
84
-     */
85
-    public function get_one_deleted_or_undeleted($query_params = array())
86
-    {
87
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
88
-        return parent::get_one($query_params);
89
-    }
90
-
91
-
92
-
93
-    /**
94
-     * Gets the item indicated by its ID. But if it's soft-deleted, pretends it doesn't exist.
95
-     *
96
-     * @param int|string $id
97
-     * @return EE_Soft_Delete_Base_Class
98
-     */
99
-    public function get_one_by_ID_but_ignore_deleted($id)
100
-    {
101
-        return $this->get_one(
102
-            $this->alter_query_params_to_restrict_by_ID(
103
-                $id,
104
-                array('default_where_conditions' => 'default')
105
-            )
106
-        );
107
-    }
108
-
109
-
110
-
111
-    /**
112
-     * Counts all the deleted/trashed items
113
-     *
114
-     * @param array  $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
115
-     * @param string $field_to_count
116
-     * @param bool   $distinct     if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE;
117
-     * @return int
118
-     */
119
-    public function count_deleted($query_params = null, $field_to_count = null, $distinct = false)
120
-    {
121
-        $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
122
-        return parent::count($query_params, $field_to_count, $distinct);
123
-    }
124
-
125
-
126
-
127
-    /**
128
-     * Alters the query params so that only trashed/soft-deleted items are considered
129
-     *
130
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
131
-     * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
132
-     */
133
-    protected function _alter_query_params_so_only_trashed_items_included($query_params)
134
-    {
135
-        $deletedFlagFieldName = $this->deleted_field_name();
136
-        $query_params[0][ $deletedFlagFieldName ] = true;
137
-        return $query_params;
138
-    }
139
-
140
-
141
-
142
-    /**
143
-     * Alters the query params so that only trashed/soft-deleted items are considered
144
-     *
145
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
146
-     * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
147
-     */
148
-    public function alter_query_params_so_only_trashed_items_included($query_params)
149
-    {
150
-        return $this->_alter_query_params_so_only_trashed_items_included($query_params);
151
-    }
152
-
153
-
154
-
155
-    /**
156
-     * Alters the query params so each item's deleted status is ignored.
157
-     *
158
-     * @param array $query_params
159
-     * @return array
160
-     */
161
-    public function alter_query_params_so_deleted_and_undeleted_items_included($query_params = array())
162
-    {
163
-        return $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
164
-    }
165
-
166
-
167
-
168
-    /**
169
-     * Alters the query params so each item's deleted status is ignored.
170
-     *
171
-     * @param array $query_params
172
-     * @return array
173
-     */
174
-    protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params)
175
-    {
176
-        if (! isset($query_params['default_where_conditions'])) {
177
-            $query_params['default_where_conditions'] = 'minimum';
178
-        }
179
-        return $query_params;
180
-    }
181
-
182
-
183
-
184
-    /**
185
-     * Counts all deleted and undeleted items
186
-     *
187
-     * @param array  $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
188
-     * @param string $field_to_count
189
-     * @param bool   $distinct     if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE;
190
-     * @return int
191
-     */
192
-    public function count_deleted_and_undeleted($query_params = null, $field_to_count = null, $distinct = false)
193
-    {
194
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
195
-        return parent::count($query_params, $field_to_count, $distinct);
196
-    }
197
-
198
-
199
-
200
-    /**
201
-     * Sum all the deleted items.
202
-     *
203
-     * @param array  $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
204
-     * @param string $field_to_sum
205
-     * @return int
206
-     */
207
-    public function sum_deleted($query_params = null, $field_to_sum = null)
208
-    {
209
-        $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
210
-        return parent::sum($query_params, $field_to_sum);
211
-    }
212
-
213
-
214
-
215
-    /**
216
-     * Sums all the deleted and undeleted items.
217
-     *
218
-     * @param array  $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
219
-     * @param string $field_to_sum
220
-     * @return int
221
-     */
222
-    public function sum_deleted_and_undeleted($query_params = null, $field_to_sum = null)
223
-    {
224
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
225
-        parent::sum($query_params, $field_to_sum);
226
-    }
227
-
228
-
229
-
230
-    /**
231
-     * Gets all deleted and undeleted mode objects from the db that meet the criteria, regardless of
232
-     * whether they've been soft-deleted or not
233
-     *
234
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
235
-     * @return EE_Soft_Delete_Base_Class[]
236
-     */
237
-    public function get_all_deleted_and_undeleted($query_params = array())
238
-    {
239
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
240
-        return parent::get_all($query_params);
241
-    }
242
-
243
-
244
-
245
-    /**
246
-     * For 'soft deletable' models, gets all which ARE deleted, according to conditions specified in $query_params.
247
-     *
248
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
249
-     * @return EE_Soft_Delete_Base_Class[]
250
-     */
251
-    public function get_all_deleted($query_params = array())
252
-    {
253
-        $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
254
-        return parent::get_all($query_params);
255
-    }
256
-
257
-
258
-
259
-    /**
260
-     * Permanently deletes the selected rows. When selecting rows for deletion, ignores
261
-     * whether they've been soft-deleted or not. (ie, you don't have to soft-delete objects
262
-     * before you can permanently delete them).
263
-     * Because this will cause a real deletion, related models may block this deletion (ie, add an error
264
-     * and abort the delete)
265
-     *
266
-     * @param array   $query_params   @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
267
-     * @param boolean $allow_blocking if TRUE, matched objects will only be deleted if there is no related model info
268
-     *                                that blocks it (ie, there' sno other data that depends on this data); if false, deletes regardless of other objects
269
-     *                                which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB
270
-     * @return int                    number of rows deleted
271
-     * @throws EE_Error
272
-     */
273
-    public function delete_permanently($query_params, $allow_blocking = true)
274
-    {
275
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
276
-        return parent::delete_permanently($query_params, $allow_blocking);
277
-    }
278
-
279
-
280
-
281
-    /**
282
-     * Restores a particular item by its ID (primary key). Ignores the fact whether the item
283
-     * has been soft-deleted or not.
284
-     *
285
-     * @param mixed $ID int if primary key is an int, string otherwise
286
-     * @return boolean success
287
-     */
288
-    public function restore_by_ID($ID = false)
289
-    {
290
-        return $this->delete_or_restore_by_ID(false, $ID);
291
-    }
292
-
293
-
294
-
295
-    /**
296
-     * For deleting or restoring a particular item. Note that this model is a SOFT-DELETABLE model! However,
297
-     * this function will ignore whether the items have been soft-deleted or not.
298
-     *
299
-     * @param boolean $delete true for delete, false for restore
300
-     * @param mixed   $ID     int if primary key is an int, string otherwise
301
-     * @return boolean
302
-     */
303
-    public function delete_or_restore_by_ID($delete = true, $ID = false)
304
-    {
305
-        if (! $ID) {
306
-            return false;
307
-        }
308
-        if (
309
-            $this->delete_or_restore(
310
-                $delete,
311
-                $this->alter_query_params_to_restrict_by_ID($ID)
312
-            )
313
-        ) {
314
-            return true;
315
-        } else {
316
-            return false;
317
-        }
318
-    }
319
-
320
-
321
-
322
-    /**
323
-     * Overrides parent's 'delete' method to instead do a soft delete on all rows that
324
-     * meet the criteria in $where_col_n_values. This particular function ignores whether the items have been soft-deleted or not.
325
-     * Note: because this item will be soft-deleted only,
326
-     * doesn't block because of model dependencies
327
-     *
328
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
329
-     * @param bool  $block_deletes
330
-     * @return boolean
331
-     */
332
-    public function delete($query_params = array(), $block_deletes = false)
333
-    {
334
-        // no matter what, we WON'T block soft deletes.
335
-        return $this->delete_or_restore(true, $query_params);
336
-    }
337
-
338
-
339
-
340
-    /**
341
-     * 'Un-deletes' the chosen items. Note that this model is a SOFT-DELETABLE model! That means that, by default, trashed/soft-deleted
342
-     * items are ignored in queries. However, this particular function ignores whether the items have been soft-deleted or not.
343
-     *
344
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
345
-     * @return boolean
346
-     */
347
-    public function restore($query_params = array())
348
-    {
349
-        return $this->delete_or_restore(false, $query_params);
350
-    }
351
-
352
-
353
-
354
-    /**
355
-     * Performs deletes or restores on items. Both soft-deleted and non-soft-deleted items considered.
356
-     *
357
-     * @param boolean $delete       true to indicate deletion, false to indicate restoration
358
-     * @param array   $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
359
-     * @return boolean
360
-     */
361
-    public function delete_or_restore($delete = true, $query_params = array())
362
-    {
363
-        $deletedFlagFieldName = $this->deleted_field_name();
364
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
365
-        if ($this->update(array($deletedFlagFieldName => $delete), $query_params)) {
366
-            return true;
367
-        } else {
368
-            return false;
369
-        }
370
-    }
371
-
372
-
373
-
374
-    /**
375
-     * Updates all the items of this model which match the $query params, regardless of whether
376
-     * they've been soft-deleted or not
377
-     *
378
-     * @param array   $fields_n_values         like EEM_Base::update's $fields_n_value
379
-     * @param array   $query_params            like EEM_base::get_all's $query_params
380
-     * @param boolean $keep_model_objs_in_sync if TRUE, makes sure we ALSO update model objects
381
-     *                                         in this model's entity map according to $fields_n_values that match $query_params. This
382
-     *                                         obviously has some overhead, so you can disable it by setting this to FALSE, but
383
-     *                                         be aware that model objects being used could get out-of-sync with the database
384
-     * @return int number of items updated
385
-     */
386
-    public function update_deleted_and_undeleted($fields_n_values, $query_params, $keep_model_objs_in_sync = true)
387
-    {
388
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
389
-        return $this->update($fields_n_values, $query_params, $keep_model_objs_in_sync);
390
-    }
30
+	/**
31
+	 * @param null $timezone
32
+	 */
33
+	protected function __construct($timezone = null)
34
+	{
35
+		if (! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
36
+			$this->_default_where_conditions_strategy = new EE_Soft_Delete_Where_Conditions();
37
+		}
38
+		parent::__construct($timezone);
39
+	}
40
+
41
+
42
+
43
+	/**
44
+	 * Searches for field on this model of type 'deleted_flag'. if it is found,
45
+	 * returns it's name.
46
+	 *
47
+	 * @return string
48
+	 * @throws EE_Error
49
+	 */
50
+	public function deleted_field_name()
51
+	{
52
+		$field = $this->get_a_field_of_type('EE_Trashed_Flag_Field');
53
+		if ($field) {
54
+			return $field->get_name();
55
+		} else {
56
+			throw new EE_Error(sprintf(esc_html__(
57
+				'We are trying to find the deleted flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?',
58
+				'event_espresso'
59
+			), get_class($this), get_class($this)));
60
+		}
61
+	}
62
+
63
+
64
+
65
+	/**
66
+	 * Gets one item that's been deleted, according to $query_params
67
+	 *
68
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
69
+	 * @return EE_Soft_Delete_Base_Class
70
+	 */
71
+	public function get_one_deleted($query_params = array())
72
+	{
73
+		$query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
74
+		return parent::get_one($query_params);
75
+	}
76
+
77
+
78
+
79
+	/**
80
+	 * Gets one item from the DB, regardless of whether it's been soft-deleted or not
81
+	 *
82
+	 * @param array $query_params like EEM_base::get_all's $query_params
83
+	 * @return EE_Soft_Delete_Base_Class
84
+	 */
85
+	public function get_one_deleted_or_undeleted($query_params = array())
86
+	{
87
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
88
+		return parent::get_one($query_params);
89
+	}
90
+
91
+
92
+
93
+	/**
94
+	 * Gets the item indicated by its ID. But if it's soft-deleted, pretends it doesn't exist.
95
+	 *
96
+	 * @param int|string $id
97
+	 * @return EE_Soft_Delete_Base_Class
98
+	 */
99
+	public function get_one_by_ID_but_ignore_deleted($id)
100
+	{
101
+		return $this->get_one(
102
+			$this->alter_query_params_to_restrict_by_ID(
103
+				$id,
104
+				array('default_where_conditions' => 'default')
105
+			)
106
+		);
107
+	}
108
+
109
+
110
+
111
+	/**
112
+	 * Counts all the deleted/trashed items
113
+	 *
114
+	 * @param array  $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
115
+	 * @param string $field_to_count
116
+	 * @param bool   $distinct     if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE;
117
+	 * @return int
118
+	 */
119
+	public function count_deleted($query_params = null, $field_to_count = null, $distinct = false)
120
+	{
121
+		$query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
122
+		return parent::count($query_params, $field_to_count, $distinct);
123
+	}
124
+
125
+
126
+
127
+	/**
128
+	 * Alters the query params so that only trashed/soft-deleted items are considered
129
+	 *
130
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
131
+	 * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
132
+	 */
133
+	protected function _alter_query_params_so_only_trashed_items_included($query_params)
134
+	{
135
+		$deletedFlagFieldName = $this->deleted_field_name();
136
+		$query_params[0][ $deletedFlagFieldName ] = true;
137
+		return $query_params;
138
+	}
139
+
140
+
141
+
142
+	/**
143
+	 * Alters the query params so that only trashed/soft-deleted items are considered
144
+	 *
145
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
146
+	 * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
147
+	 */
148
+	public function alter_query_params_so_only_trashed_items_included($query_params)
149
+	{
150
+		return $this->_alter_query_params_so_only_trashed_items_included($query_params);
151
+	}
152
+
153
+
154
+
155
+	/**
156
+	 * Alters the query params so each item's deleted status is ignored.
157
+	 *
158
+	 * @param array $query_params
159
+	 * @return array
160
+	 */
161
+	public function alter_query_params_so_deleted_and_undeleted_items_included($query_params = array())
162
+	{
163
+		return $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
164
+	}
165
+
166
+
167
+
168
+	/**
169
+	 * Alters the query params so each item's deleted status is ignored.
170
+	 *
171
+	 * @param array $query_params
172
+	 * @return array
173
+	 */
174
+	protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params)
175
+	{
176
+		if (! isset($query_params['default_where_conditions'])) {
177
+			$query_params['default_where_conditions'] = 'minimum';
178
+		}
179
+		return $query_params;
180
+	}
181
+
182
+
183
+
184
+	/**
185
+	 * Counts all deleted and undeleted items
186
+	 *
187
+	 * @param array  $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
188
+	 * @param string $field_to_count
189
+	 * @param bool   $distinct     if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE;
190
+	 * @return int
191
+	 */
192
+	public function count_deleted_and_undeleted($query_params = null, $field_to_count = null, $distinct = false)
193
+	{
194
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
195
+		return parent::count($query_params, $field_to_count, $distinct);
196
+	}
197
+
198
+
199
+
200
+	/**
201
+	 * Sum all the deleted items.
202
+	 *
203
+	 * @param array  $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
204
+	 * @param string $field_to_sum
205
+	 * @return int
206
+	 */
207
+	public function sum_deleted($query_params = null, $field_to_sum = null)
208
+	{
209
+		$query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
210
+		return parent::sum($query_params, $field_to_sum);
211
+	}
212
+
213
+
214
+
215
+	/**
216
+	 * Sums all the deleted and undeleted items.
217
+	 *
218
+	 * @param array  $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
219
+	 * @param string $field_to_sum
220
+	 * @return int
221
+	 */
222
+	public function sum_deleted_and_undeleted($query_params = null, $field_to_sum = null)
223
+	{
224
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
225
+		parent::sum($query_params, $field_to_sum);
226
+	}
227
+
228
+
229
+
230
+	/**
231
+	 * Gets all deleted and undeleted mode objects from the db that meet the criteria, regardless of
232
+	 * whether they've been soft-deleted or not
233
+	 *
234
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
235
+	 * @return EE_Soft_Delete_Base_Class[]
236
+	 */
237
+	public function get_all_deleted_and_undeleted($query_params = array())
238
+	{
239
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
240
+		return parent::get_all($query_params);
241
+	}
242
+
243
+
244
+
245
+	/**
246
+	 * For 'soft deletable' models, gets all which ARE deleted, according to conditions specified in $query_params.
247
+	 *
248
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
249
+	 * @return EE_Soft_Delete_Base_Class[]
250
+	 */
251
+	public function get_all_deleted($query_params = array())
252
+	{
253
+		$query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
254
+		return parent::get_all($query_params);
255
+	}
256
+
257
+
258
+
259
+	/**
260
+	 * Permanently deletes the selected rows. When selecting rows for deletion, ignores
261
+	 * whether they've been soft-deleted or not. (ie, you don't have to soft-delete objects
262
+	 * before you can permanently delete them).
263
+	 * Because this will cause a real deletion, related models may block this deletion (ie, add an error
264
+	 * and abort the delete)
265
+	 *
266
+	 * @param array   $query_params   @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
267
+	 * @param boolean $allow_blocking if TRUE, matched objects will only be deleted if there is no related model info
268
+	 *                                that blocks it (ie, there' sno other data that depends on this data); if false, deletes regardless of other objects
269
+	 *                                which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB
270
+	 * @return int                    number of rows deleted
271
+	 * @throws EE_Error
272
+	 */
273
+	public function delete_permanently($query_params, $allow_blocking = true)
274
+	{
275
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
276
+		return parent::delete_permanently($query_params, $allow_blocking);
277
+	}
278
+
279
+
280
+
281
+	/**
282
+	 * Restores a particular item by its ID (primary key). Ignores the fact whether the item
283
+	 * has been soft-deleted or not.
284
+	 *
285
+	 * @param mixed $ID int if primary key is an int, string otherwise
286
+	 * @return boolean success
287
+	 */
288
+	public function restore_by_ID($ID = false)
289
+	{
290
+		return $this->delete_or_restore_by_ID(false, $ID);
291
+	}
292
+
293
+
294
+
295
+	/**
296
+	 * For deleting or restoring a particular item. Note that this model is a SOFT-DELETABLE model! However,
297
+	 * this function will ignore whether the items have been soft-deleted or not.
298
+	 *
299
+	 * @param boolean $delete true for delete, false for restore
300
+	 * @param mixed   $ID     int if primary key is an int, string otherwise
301
+	 * @return boolean
302
+	 */
303
+	public function delete_or_restore_by_ID($delete = true, $ID = false)
304
+	{
305
+		if (! $ID) {
306
+			return false;
307
+		}
308
+		if (
309
+			$this->delete_or_restore(
310
+				$delete,
311
+				$this->alter_query_params_to_restrict_by_ID($ID)
312
+			)
313
+		) {
314
+			return true;
315
+		} else {
316
+			return false;
317
+		}
318
+	}
319
+
320
+
321
+
322
+	/**
323
+	 * Overrides parent's 'delete' method to instead do a soft delete on all rows that
324
+	 * meet the criteria in $where_col_n_values. This particular function ignores whether the items have been soft-deleted or not.
325
+	 * Note: because this item will be soft-deleted only,
326
+	 * doesn't block because of model dependencies
327
+	 *
328
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
329
+	 * @param bool  $block_deletes
330
+	 * @return boolean
331
+	 */
332
+	public function delete($query_params = array(), $block_deletes = false)
333
+	{
334
+		// no matter what, we WON'T block soft deletes.
335
+		return $this->delete_or_restore(true, $query_params);
336
+	}
337
+
338
+
339
+
340
+	/**
341
+	 * 'Un-deletes' the chosen items. Note that this model is a SOFT-DELETABLE model! That means that, by default, trashed/soft-deleted
342
+	 * items are ignored in queries. However, this particular function ignores whether the items have been soft-deleted or not.
343
+	 *
344
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
345
+	 * @return boolean
346
+	 */
347
+	public function restore($query_params = array())
348
+	{
349
+		return $this->delete_or_restore(false, $query_params);
350
+	}
351
+
352
+
353
+
354
+	/**
355
+	 * Performs deletes or restores on items. Both soft-deleted and non-soft-deleted items considered.
356
+	 *
357
+	 * @param boolean $delete       true to indicate deletion, false to indicate restoration
358
+	 * @param array   $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
359
+	 * @return boolean
360
+	 */
361
+	public function delete_or_restore($delete = true, $query_params = array())
362
+	{
363
+		$deletedFlagFieldName = $this->deleted_field_name();
364
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
365
+		if ($this->update(array($deletedFlagFieldName => $delete), $query_params)) {
366
+			return true;
367
+		} else {
368
+			return false;
369
+		}
370
+	}
371
+
372
+
373
+
374
+	/**
375
+	 * Updates all the items of this model which match the $query params, regardless of whether
376
+	 * they've been soft-deleted or not
377
+	 *
378
+	 * @param array   $fields_n_values         like EEM_Base::update's $fields_n_value
379
+	 * @param array   $query_params            like EEM_base::get_all's $query_params
380
+	 * @param boolean $keep_model_objs_in_sync if TRUE, makes sure we ALSO update model objects
381
+	 *                                         in this model's entity map according to $fields_n_values that match $query_params. This
382
+	 *                                         obviously has some overhead, so you can disable it by setting this to FALSE, but
383
+	 *                                         be aware that model objects being used could get out-of-sync with the database
384
+	 * @return int number of items updated
385
+	 */
386
+	public function update_deleted_and_undeleted($fields_n_values, $query_params, $keep_model_objs_in_sync = true)
387
+	{
388
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
389
+		return $this->update($fields_n_values, $query_params, $keep_model_objs_in_sync);
390
+	}
391 391
 }
Please login to merge, or discard this patch.
core/helpers/EEH_HTML.helper.php 2 patches
Indentation   +862 added lines, -862 removed lines patch added patch discarded remove patch
@@ -1,876 +1,876 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
  /**
4
- *
5
- * Class EEH_HTML
6
- *
4
+  *
5
+  * Class EEH_HTML
6
+  *
7 7
   * Sometimes when writing PHP you need to generate some standard HTML,
8 8
   * but either not enough to warrant creating a template file,
9 9
   * or the amount of PHP conditionals and/or loops peppered throughout the HTML
10 10
   * just make it really ugly and difficult to read.
11 11
   * This class simply adds a bunch of methods for generating basic HTML tags.
12 12
   * Most of the methods have the same name as the HTML tag they generate, and most have the same set of parameters.
13
- *
14
- * @package         Event Espresso
15
- * @subpackage    core
16
- * @author              Brent Christensen
17
- *
18
- *
19
- */
13
+  *
14
+  * @package         Event Espresso
15
+  * @subpackage    core
16
+  * @author              Brent Christensen
17
+  *
18
+  *
19
+  */
20 20
 class EEH_HTML
21 21
 {
22 22
 
23
-    /**
24
-     *  instance of the EEH_Autoloader object
25
-     *  @var    $_instance
26
-     *  @access     private
27
-     */
28
-    private static $_instance;
29
-
30
-    /**
31
-     *  @var array  $_indent
32
-     *  @access     private
33
-     */
34
-    private static $_indent = array();
35
-
36
-
37
-
38
-    /**
39
-     *  @singleton method used to instantiate class object
40
-     *  @access public
41
-     *  @return EEH_HTML
42
-     */
43
-    public static function instance()
44
-    {
45
-        // check if class object is instantiated, and instantiated properly
46
-        if (! self::$_instance instanceof EEH_HTML) {
47
-            self::$_instance = new EEH_HTML();
48
-        }
49
-        return self::$_instance;
50
-    }
51
-
52
-
53
-
54
-    /**
55
-     *  class constructor
56
-     *
57
-     * @access    private
58
-     * @return \EEH_HTML
59
-     */
60
-    private function __construct()
61
-    {
62
-        // set some initial formatting for table indentation
63
-        EEH_HTML::$_indent = array(
64
-            'table'     => 0,
65
-            'thead' => 1,
66
-            'tbody' => 1,
67
-            'tr'    => 2,
68
-            'th'    => 3,
69
-            'td'    => 3,
70
-            'div'   => 0,
71
-            'h1'    => 0,
72
-            'h2'    => 0,
73
-            'h3'    => 0,
74
-            'h4'    => 0,
75
-            'h5'    => 0,
76
-            'h6'    => 0,
77
-            'p'     => 0,
78
-            'ul'    => 0,
79
-            'li'    => 1
80
-        );
81
-    }
82
-
83
-
84
-
85
-    /**
86
-     * Generates an opening HTML <XX> tag and adds any passed attributes
87
-     * if passed content, it will also add that, as well as the closing </XX> tag
88
-     *
89
-     * @access protected
90
-     * @param string $tag
91
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
92
-     * @param string $id - html id attribute
93
-     * @param string $class - html class attribute
94
-     * @param string $style - html style attribute for applying inline styles
95
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
96
-     * @param bool   $force_close
97
-     * @return string
98
-     */
99
-    protected static function _open_tag(
100
-        $tag = 'div',
101
-        $content = '',
102
-        $id = '',
103
-        $class = '',
104
-        $style = '',
105
-        $other_attributes = '',
106
-        $force_close = false
107
-    ) {
108
-        $attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
109
-        $attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
110
-        $attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
111
-        $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
112
-        $html = EEH_HTML::nl(0, $tag) . '<' . $tag . $attributes . '>';
113
-        $html .= ! empty($content) ? EEH_HTML::nl(1, $tag) . $content : '';
114
-        $indent = ! empty($content) || $force_close ? true : false;
115
-        $html .= ! empty($content) || $force_close ? EEH_HTML::_close_tag($tag, $id, $class, $indent) : '';
116
-        return $html;
117
-    }
118
-
119
-
120
-
121
-    /**
122
-     * Generates HTML closing </XX> tag - if passed the id or class attribute
123
-     * used for the opening tag, will append a comment
124
-     *
23
+	/**
24
+	 *  instance of the EEH_Autoloader object
25
+	 *  @var    $_instance
26
+	 *  @access     private
27
+	 */
28
+	private static $_instance;
29
+
30
+	/**
31
+	 *  @var array  $_indent
32
+	 *  @access     private
33
+	 */
34
+	private static $_indent = array();
35
+
36
+
37
+
38
+	/**
39
+	 *  @singleton method used to instantiate class object
40
+	 *  @access public
41
+	 *  @return EEH_HTML
42
+	 */
43
+	public static function instance()
44
+	{
45
+		// check if class object is instantiated, and instantiated properly
46
+		if (! self::$_instance instanceof EEH_HTML) {
47
+			self::$_instance = new EEH_HTML();
48
+		}
49
+		return self::$_instance;
50
+	}
51
+
52
+
53
+
54
+	/**
55
+	 *  class constructor
56
+	 *
57
+	 * @access    private
58
+	 * @return \EEH_HTML
59
+	 */
60
+	private function __construct()
61
+	{
62
+		// set some initial formatting for table indentation
63
+		EEH_HTML::$_indent = array(
64
+			'table'     => 0,
65
+			'thead' => 1,
66
+			'tbody' => 1,
67
+			'tr'    => 2,
68
+			'th'    => 3,
69
+			'td'    => 3,
70
+			'div'   => 0,
71
+			'h1'    => 0,
72
+			'h2'    => 0,
73
+			'h3'    => 0,
74
+			'h4'    => 0,
75
+			'h5'    => 0,
76
+			'h6'    => 0,
77
+			'p'     => 0,
78
+			'ul'    => 0,
79
+			'li'    => 1
80
+		);
81
+	}
82
+
83
+
84
+
85
+	/**
86
+	 * Generates an opening HTML <XX> tag and adds any passed attributes
87
+	 * if passed content, it will also add that, as well as the closing </XX> tag
88
+	 *
89
+	 * @access protected
90
+	 * @param string $tag
91
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
92
+	 * @param string $id - html id attribute
93
+	 * @param string $class - html class attribute
94
+	 * @param string $style - html style attribute for applying inline styles
95
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
96
+	 * @param bool   $force_close
97
+	 * @return string
98
+	 */
99
+	protected static function _open_tag(
100
+		$tag = 'div',
101
+		$content = '',
102
+		$id = '',
103
+		$class = '',
104
+		$style = '',
105
+		$other_attributes = '',
106
+		$force_close = false
107
+	) {
108
+		$attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
109
+		$attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
110
+		$attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
111
+		$attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
112
+		$html = EEH_HTML::nl(0, $tag) . '<' . $tag . $attributes . '>';
113
+		$html .= ! empty($content) ? EEH_HTML::nl(1, $tag) . $content : '';
114
+		$indent = ! empty($content) || $force_close ? true : false;
115
+		$html .= ! empty($content) || $force_close ? EEH_HTML::_close_tag($tag, $id, $class, $indent) : '';
116
+		return $html;
117
+	}
118
+
119
+
120
+
121
+	/**
122
+	 * Generates HTML closing </XX> tag - if passed the id or class attribute
123
+	 * used for the opening tag, will append a comment
124
+	 *
125 125
 *@access protected
126
-     * @param string $tag
127
-     * @param string $id - html id attribute
128
-     * @param string $class - html class attribute
129
-     * @param bool   $indent
130
-     * @return string
131
-     */
132
-    protected static function _close_tag($tag = 'div', $id = '', $class = '', $indent = true)
133
-    {
134
-        $comment = '';
135
-        if ($id) {
136
-            $comment = EEH_HTML::comment('close ' . $id) . EEH_HTML::nl(0, $tag);
137
-        } elseif ($class) {
138
-            $comment = EEH_HTML::comment('close ' . $class) . EEH_HTML::nl(0, $tag);
139
-        }
140
-        $html = $indent ? EEH_HTML::nl(-1, $tag) : '';
141
-        $html .= '</' . $tag . '>' . $comment;
142
-        return $html;
143
-    }
144
-
145
-
146
-
147
-    /**
148
-     *  div - generates HTML opening <div> tag and adds any passed attributes
149
-     *  to add an id use:       echo EEH_HTML::div( 'this is some content', 'footer' );
150
-     *  to add a class use:     echo EEH_HTML::div( 'this is some content', '', 'float_left' );
151
-     *  to add a both an id and a class use:    echo EEH_HTML::div( 'this is some content', 'footer', 'float_left' );
152
-     *
153
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
154
-     * @param string $id - html id attribute
155
-     * @param string $class - html class attribute
156
-     * @param string $style - html style attribute for applying inline styles
157
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
158
-     * @return string
159
-     */
160
-    public static function div($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
161
-    {
162
-        return EEH_HTML::_open_tag('div', $content, $id, $class, $style, $other_attributes);
163
-    }
164
-
165
-
166
-
167
-    /**
168
-     * Generates HTML closing </div> tag - if passed the id or class attribute used for the opening div tag, will append a comment
169
-     * usage: echo EEH_HTML::divx();
170
-     *
171
-     * @param string $id - html id attribute
172
-     * @param string $class - html class attribute
173
-     * @return string
174
-     */
175
-    public static function divx($id = '', $class = '')
176
-    {
177
-        return EEH_HTML::_close_tag('div', $id, $class);
178
-    }
179
-
180
-
181
-
182
-    /**
183
-     * Generates HTML <h1></h1> tags, inserts content, and adds any passed attributes
184
-     * usage: echo EEH_HTML::h1( 'This is a Heading' );
185
-     *
186
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
187
-     * @param string $id - html id attribute
188
-     * @param string $class - html class attribute
189
-     * @param string $style - html style attribute for applying inline styles
190
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
191
-     * @return string
192
-     */
193
-    public static function h1($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
194
-    {
195
-        return EEH_HTML::_open_tag('h1', $content, $id, $class, $style, $other_attributes, true);
196
-    }
197
-
198
-
199
-
200
-    /**
201
-     * Generates HTML <h2></h2> tags, inserts content, and adds any passed attributes
202
-     * usage: echo EEH_HTML::h2( 'This is a Heading' );
203
-     *
204
-     * @param string $content          - inserted after opening tag, and appends closing tag, otherwise tag is left open
205
-     * @param string $id               - html id attribute
206
-     * @param string $class            - html class attribute
207
-     * @param string $style            - html style attribute for applying inline styles
208
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
209
-     * @return string
210
-     */
211
-    public static function h2($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
212
-    {
213
-        return EEH_HTML::_open_tag('h2', $content, $id, $class, $style, $other_attributes, true);
214
-    }
215
-
216
-
217
-
218
-    /**
219
-     * Generates HTML <h3></h3> tags, inserts content, and adds any passed attributes
220
-     * usage: echo EEH_HTML::h3( 'This is a Heading' );
221
-     *
222
-     * @param string $content          - inserted after opening tag, and appends closing tag, otherwise tag is left open
223
-     * @param string $id               - html id attribute
224
-     * @param string $class            - html class attribute
225
-     * @param string $style            - html style attribute for applying inline styles
226
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
227
-     * @return string
228
-     */
229
-    public static function h3($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
230
-    {
231
-        return EEH_HTML::_open_tag('h3', $content, $id, $class, $style, $other_attributes, true);
232
-    }
233
-
234
-
235
-
236
-    /**
237
-     * Generates HTML <h4></h4> tags, inserts content, and adds any passed attributes
238
-     * usage: echo EEH_HTML::h4( 'This is a Heading' );
239
-     *
240
-     * @param string $content          - inserted after opening tag, and appends closing tag, otherwise tag is left open
241
-     * @param string $id               - html id attribute
242
-     * @param string $class            - html class attribute
243
-     * @param string $style            - html style attribute for applying inline styles
244
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
245
-     * @return string
246
-     */
247
-    public static function h4($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
248
-    {
249
-        return EEH_HTML::_open_tag('h4', $content, $id, $class, $style, $other_attributes, true);
250
-    }
251
-
252
-
253
-
254
-    /**
255
-     * Generates HTML <h5></h5> tags, inserts content, and adds any passed attributes
256
-     * usage: echo EEH_HTML::h5( 'This is a Heading' );
257
-     *
258
-     * @param string $content          - inserted after opening tag, and appends closing tag, otherwise tag is left open
259
-     * @param string $id               - html id attribute
260
-     * @param string $class            - html class attribute
261
-     * @param string $style            - html style attribute for applying inline styles
262
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
263
-     * @return string
264
-     */
265
-    public static function h5($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
266
-    {
267
-        return EEH_HTML::_open_tag('h5', $content, $id, $class, $style, $other_attributes, true);
268
-    }
269
-
270
-
271
-
272
-    /**
273
-     * Generates HTML <h6></h6> tags, inserts content, and adds any passed attributes
274
-     * usage: echo EEH_HTML::h6( 'This is a Heading' );
275
-     *
276
-     * @param string $content          - inserted after opening tag, and appends closing tag, otherwise tag is left open
277
-     * @param string $id               - html id attribute
278
-     * @param string $class            - html class attribute
279
-     * @param string $style            - html style attribute for applying inline styles
280
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
281
-     * @return string
282
-     */
283
-    public static function h6($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
284
-    {
285
-        return EEH_HTML::_open_tag('h6', $content, $id, $class, $style, $other_attributes, true);
286
-    }
287
-
288
-
289
-
290
-    /**
291
-     * Generates HTML <p></p> tags, inserts content, and adds any passed attributes
292
-     * usage: echo EEH_HTML::p( 'this is a paragraph' );
293
-     *
294
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
295
-     * @param string $id - html id attribute
296
-     * @param string $class - html class attribute
297
-     * @param string $style - html style attribute for applying inline styles
298
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
299
-     * @return string
300
-     */
301
-    public static function p($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
302
-    {
303
-        return EEH_HTML::_open_tag('p', $content, $id, $class, $style, $other_attributes, true);
304
-    }
305
-
306
-
307
-
308
-    /**
309
-     *  ul - generates HTML opening <ul> tag and adds any passed attributes
310
-     *  usage:      echo EEH_HTML::ul( 'my-list-id', 'my-list-class' );
311
-     *
312
-     * @param string $id - html id attribute
313
-     * @param string $class - html class attribute
314
-     * @param string $style - html style attribute for applying inline styles
315
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
316
-     * @return string
317
-     */
318
-    public static function ul($id = '', $class = '', $style = '', $other_attributes = '')
319
-    {
320
-        return EEH_HTML::_open_tag('ul', '', $id, $class, $style, $other_attributes);
321
-    }
322
-
323
-
324
-
325
-    /**
326
-     * Generates HTML closing </ul> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
327
-     * usage: echo EEH_HTML::ulx();
328
-     *
329
-     * @param string $id - html id attribute
330
-     * @param string $class - html class attribute
331
-     * @return string
332
-     */
333
-    public static function ulx($id = '', $class = '')
334
-    {
335
-        return EEH_HTML::_close_tag('ul', $id, $class);
336
-    }
337
-
338
-
339
-
340
-    /**
341
-     * Generates HTML <li> tag, inserts content, and adds any passed attributes
342
-     * if passed content, it will also add that, as well as the closing </li> tag
343
-     * usage: echo EEH_HTML::li( 'this is a line item' );
344
-     *
345
-     * @param string $id - html id attribute
346
-     * @param string $class - html class attribute
347
-     * @param string $style - html style attribute for applying inline styles
348
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
349
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
350
-     * @return string
351
-     */
352
-    public static function li($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
353
-    {
354
-        return EEH_HTML::_open_tag('li', $content, $id, $class, $style, $other_attributes);
355
-    }
356
-
357
-
358
-
359
-    /**
360
-     * Generates HTML closing </li> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
361
-     * usage: echo EEH_HTML::lix();
362
-     *
363
-     * @param string $id - html id attribute
364
-     * @param string $class - html class attribute
365
-     * @return string
366
-     */
367
-    public static function lix($id = '', $class = '')
368
-    {
369
-        return EEH_HTML::_close_tag('li', $id, $class);
370
-    }
371
-
372
-
373
-
374
-    /**
375
-     *    table - generates an HTML <table> tag and adds any passed attributes
376
-     *    usage: echo EEH_HTML::table();
377
-     *
378
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
379
-     * @param string $id - html id attribute
380
-     * @param string $class - html class attribute
381
-     * @param string $style - html style attribute for applying inline styles
382
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
383
-     * @return string
384
-     */
385
-    public static function table($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
386
-    {
387
-        return EEH_HTML::_open_tag('table', $content, $id, $class, $style, $other_attributes);
388
-    }
389
-
390
-
391
-
392
-    /**
393
-     * tablex - generates an HTML </table> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
394
-     *
395
-     * @param string $id - html id attribute
396
-     * @param string $class - html class attribute
397
-     * @return string
398
-     */
399
-    public static function tablex($id = '', $class = '')
400
-    {
401
-        return EEH_HTML::_close_tag('table', $id, $class);
402
-    }
403
-
404
-
405
-
406
-    /**
407
-     *    thead - generates an HTML <thead> tag and adds any passed attributes
408
-     *    usage: echo EEH_HTML::thead();
409
-     *
410
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
411
-     * @param string $id - html id attribute
412
-     * @param string $class - html class attribute
413
-     * @param string $style - html style attribute for applying inline styles
414
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
415
-     * @return string
416
-     */
417
-    public static function thead($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
418
-    {
419
-        return EEH_HTML::_open_tag('thead', $content, $id, $class, $style, $other_attributes);
420
-    }
421
-
422
-
423
-
424
-    /**
425
-     * theadx - generates an HTML </thead> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
426
-     *
427
-     * @param string $id - html id attribute
428
-     * @param string $class - html class attribute
429
-     * @return string
430
-     */
431
-    public static function theadx($id = '', $class = '')
432
-    {
433
-        return EEH_HTML::_close_tag('thead', $id, $class);
434
-    }
435
-
436
-
437
-
438
-    /**
439
-     *    tbody - generates an HTML <tbody> tag and adds any passed attributes
440
-     *    usage: echo EEH_HTML::tbody();
441
-     *
442
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
443
-     * @param string $id - html id attribute
444
-     * @param string $class - html class attribute
445
-     * @param string $style - html style attribute for applying inline styles
446
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
447
-     * @return string
448
-     */
449
-    public static function tbody($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
450
-    {
451
-        return EEH_HTML::_open_tag('tbody', $content, $id, $class, $style, $other_attributes);
452
-    }
453
-
454
-
455
-
456
-    /**
457
-     * tbodyx - generates an HTML </tbody> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
458
-     *
459
-     * @param string $id - html id attribute
460
-     * @param string $class - html class attribute
461
-     * @return string
462
-     */
463
-    public static function tbodyx($id = '', $class = '')
464
-    {
465
-        return EEH_HTML::_close_tag('tbody', $id, $class);
466
-    }
467
-
468
-
469
-
470
-    /**
471
-     *    tr - generates an HTML <tr> tag and adds any passed attributes
472
-     *    usage: echo EEH_HTML::tr();
473
-     *
474
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
475
-     * @param string $id - html id attribute
476
-     * @param string $class - html class attribute
477
-     * @param string $style - html style attribute for applying inline styles
478
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
479
-     * @return string
480
-     */
481
-    public static function tr($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
482
-    {
483
-        return EEH_HTML::_open_tag('tr', $content, $id, $class, $style, $other_attributes);
484
-    }
485
-
486
-
487
-
488
-    /**
489
-     * trx - generates an HTML </tr> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
490
-     *
491
-     * @param string $id - html id attribute
492
-     * @param string $class - html class attribute
493
-     * @return string
494
-     */
495
-    public static function trx($id = '', $class = '')
496
-    {
497
-        return EEH_HTML::_close_tag('tr', $id, $class);
498
-    }
499
-
500
-
501
-
502
-    /**
503
-     *    th - generates an HTML <th> tag and adds any passed attributes
504
-     *    usage: echo EEH_HTML::th();
505
-     *
506
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
507
-     * @param string $id - html id attribute
508
-     * @param string $class - html class attribute
509
-     * @param string $style - html style attribute for applying inline styles
510
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
511
-     * @return string
512
-     */
513
-    public static function th($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
514
-    {
515
-        return EEH_HTML::_open_tag('th', $content, $id, $class, $style, $other_attributes);
516
-    }
517
-
518
-
519
-
520
-    /**
521
-     * thx - generates an HTML </th> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
522
-     *
523
-     * @param string $id - html id attribute
524
-     * @param string $class - html class attribute
525
-     * @return string
526
-     */
527
-    public static function thx($id = '', $class = '')
528
-    {
529
-        return EEH_HTML::_close_tag('th', $id, $class);
530
-    }
531
-
532
-
533
-
534
-    /**
535
-     *    td - generates an HTML <td> tag and adds any passed attributes
536
-     *    usage: echo EEH_HTML::td();
537
-     *
538
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
539
-     * @param string $id - html id attribute
540
-     * @param string $class - html class attribute
541
-     * @param string $style - html style attribute for applying inline styles
542
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
543
-     * @return string
544
-     */
545
-    public static function td($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
546
-    {
547
-        return EEH_HTML::_open_tag('td', $content, $id, $class, $style, $other_attributes);
548
-    }
549
-
550
-
551
-
552
-    /**
553
-     * tdx - generates an HTML </td> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
554
-     *
555
-     * @param string $id - html id attribute
556
-     * @param string $class - html class attribute
557
-     * @return string
558
-     */
559
-    public static function tdx($id = '', $class = '')
560
-    {
561
-        return EEH_HTML::_close_tag('td', $id, $class);
562
-    }
563
-
564
-
565
-
566
-    /**
567
-     * no_row - for generating a "hidden" table row, good for embedding tables within tables
568
-     * generates a new table row with one td cell that spans however many columns you set
569
-     * removes all styles from the tr and td
570
-     *
571
-     * @param string $content
572
-     * @param int    $colspan
573
-     * @return string
574
-     */
575
-    public static function no_row($content = '', $colspan = 2)
576
-    {
577
-        return EEH_HTML::tr(
578
-            EEH_HTML::td($content, '', '', 'padding:0; border:none;', 'colspan="' . $colspan . '"'),
579
-            '',
580
-            '',
581
-            'padding:0; border:none;'
582
-        );
583
-    }
584
-
585
-
586
-
587
-    /**
588
-     * Generates HTML <label></label> tags, inserts content, and adds any passed attributes
589
-     * usage: echo EEH_HTML::span( 'this is some inline text' );
590
-     *
591
-     * @access public
592
-     * @param string $href URL to link to
593
-     * @param string $link_text - the text that will become "hyperlinked"
594
-     * @param string $title - html title attribute
595
-     * @param string $id - html id attribute
596
-     * @param string $class - html class attribute
597
-     * @param string $style - html style attribute for applying inline styles
598
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
599
-     * @return string
600
-     */
601
-    public static function link($href = '', $link_text = '', $title = '', $id = '', $class = '', $style = '', $other_attributes = '')
602
-    {
603
-        $link_text = ! empty($link_text) ? $link_text : $href;
604
-        $attributes = ! empty($href) ? ' href="' . $href . '"' : '';
605
-        $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
606
-        $attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
607
-        $attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
608
-        $attributes .= ! empty($title) ? ' title="' . esc_attr($title) . '"' : '';
609
-        $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
610
-        return "<a{$attributes}>{$link_text}</a>";
611
-    }
612
-
613
-
614
-
615
-    /**
616
-     *    img - generates an HTML <img> tag and adds any passed attributes
617
-     *    usage: echo EEH_HTML::img();
618
-     *
619
-     * @param string $src - html src attribute ie: the path or URL to the image
620
-     * @param string $alt - html alt attribute
621
-     * @param string $id - html id attribute
622
-     * @param string $class - html class attribute
623
-     * @param string $style - html style attribute for applying inline styles
624
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
625
-     * @return string
626
-     */
627
-    public static function img($src = '', $alt = '', $id = '', $class = '', $style = '', $other_attributes = '')
628
-    {
629
-        $attributes = ! empty($src) ? ' src="' . esc_url_raw($src) . '"' : '';
630
-        $attributes .= ! empty($alt) ? ' alt="' . esc_attr($alt) . '"' : '';
631
-        $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
632
-        $attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
633
-        $attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
634
-        $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
635
-        return '<img' . $attributes  . '/>';
636
-    }
637
-
638
-
639
-
640
-    /**
641
-     * Generates HTML <label></label> tags, inserts content, and adds any passed attributes
642
-     * usage: echo EEH_HTML::span( 'this is some inline text' );
643
-     *
644
-     * @access protected
645
-     * @param string $tag
646
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
647
-     * @param string $id - html id attribute
648
-     * @param string $class - html class attribute
649
-     * @param string $style - html style attribute for applying inline styles
650
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
651
-     * @return string
652
-     */
653
-    protected static function _inline_tag($tag = 'span', $content = '', $id = '', $class = '', $style = '', $other_attributes = '')
654
-    {
655
-        $attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
656
-        $attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
657
-        $attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
658
-        $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
659
-        return '<' . $tag . ' ' . $attributes . '>'  . $content  . '</' . $tag . '>';
660
-    }
661
-
662
-
663
-
664
-    /**
665
-     * Generates HTML <label></label> tags, inserts content, and adds any passed attributes
666
-     * usage: echo EEH_HTML::span( 'this is some inline text' );
667
-     *
668
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
669
-     * @param string $id - html id attribute
670
-     * @param string $class - html class attribute
671
-     * @param string $style - html style attribute for applying inline styles
672
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
673
-     * @return string
674
-     */
675
-    public static function label($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
676
-    {
677
-        return EEH_HTML::_inline_tag('label', $content, $id, $class, $style, $other_attributes);
678
-    }
679
-
680
-
681
-
682
-    /**
683
-     * Generates HTML <span></span> tags, inserts content, and adds any passed attributes
684
-     * usage: echo EEH_HTML::span( 'this is some inline text' );
685
-     *
686
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
687
-     * @param string $id - html id attribute
688
-     * @param string $class - html class attribute
689
-     * @param string $style - html style attribute for applying inline styles
690
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
691
-     * @return string
692
-     */
693
-    public static function span($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
694
-    {
695
-        return EEH_HTML::_inline_tag('span', $content, $id, $class, $style, $other_attributes);
696
-    }
697
-
698
-
699
-
700
-    /**
701
-     * Generates HTML <span></span> tags, inserts content, and adds any passed attributes
702
-     * usage: echo EEH_HTML::span( 'this is some inline text' );
703
-     *
704
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
705
-     * @param string $id - html id attribute
706
-     * @param string $class - html class attribute
707
-     * @param string $style - html style attribute for applying inline styles
708
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
709
-     * @return string
710
-     */
711
-    public static function strong($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
712
-    {
713
-        return EEH_HTML::_inline_tag('strong', $content, $id, $class, $style, $other_attributes);
714
-    }
715
-
716
-
717
-
718
-    /**
719
-     * Generates an html <--  comment --> tag
720
-     *  usage: echo comment( 'this is a comment' );
721
-     *
722
-     * @param string $comment
723
-     * @return string
724
-     */
725
-    public static function comment($comment = '')
726
-    {
727
-        return ! empty($comment) ? EEH_HTML::nl() . '<!-- ' . $comment . ' -->' : '';
728
-    }
729
-
730
-
731
-
732
-    /**
733
-     * br - generates a line break
734
-     *
735
-     * @param int $nmbr - the number of line breaks to return
736
-     * @return string
737
-     */
738
-    public static function br($nmbr = 1)
739
-    {
740
-        return str_repeat('<br />', $nmbr);
741
-    }
742
-
743
-
744
-
745
-    /**
746
-     * nbsp - generates non-breaking space entities based on number supplied
747
-     *
748
-     * @param int $nmbr - the number of non-breaking spaces to return
749
-     * @return string
750
-     */
751
-    public static function nbsp($nmbr = 1)
752
-    {
753
-        return str_repeat('&nbsp;', $nmbr);
754
-    }
755
-
756
-
757
-
758
-    /**
759
-     * sanitize_id
760
-     *
761
-     * functionally does the same as the wp_core function sanitize_key except it does NOT use
762
-     * strtolower and allows capitals.
763
-     *
764
-     * @param string $id
765
-     * @return string
766
-     */
767
-    public static function sanitize_id($id = '')
768
-    {
769
-        $key = str_replace(' ', '-', trim($id));
770
-        return preg_replace('/[^a-zA-Z0-9_\-]/', '', $key);
771
-    }
772
-
773
-
774
-
775
-    /**
776
-     * return a newline and tabs ("nl" stands for "new line")
777
-     *
778
-     * @param int    $indent the number of tabs to ADD to the current indent (can be negative or zero)
779
-     * @param string $tag
780
-     * @return string - newline character plus # of indents passed (can be + or -)
781
-     */
782
-    public static function nl($indent = 0, $tag = 'none')
783
-    {
784
-        $html = "\n";
785
-        EEH_HTML::indent($indent, $tag);
786
-        for ($x = 0; $x < EEH_HTML::$_indent[ $tag ]; $x++) {
787
-            $html .= "\t";
788
-        }
789
-        return $html;
790
-    }
791
-
792
-
793
-
794
-    /**
795
-     * Changes the indents used in EEH_HTML::nl. Often its convenient to change
796
-     * the indentation level without actually creating a new line
797
-     *
798
-     * @param int    $indent can be negative to decrease the indentation level
799
-     * @param string $tag
800
-     */
801
-    public static function indent($indent, $tag = 'none')
802
-    {
803
-        static $default_indentation = false;
804
-        if (! $default_indentation) {
805
-            EEH_HTML::_set_default_indentation();
806
-            $default_indentation = true;
807
-        }
808
-        if (! isset(EEH_HTML::$_indent[ $tag ])) {
809
-            EEH_HTML::$_indent[ $tag ] = 0;
810
-        }
811
-        EEH_HTML::$_indent[ $tag ] += (int) $indent;
812
-        EEH_HTML::$_indent[ $tag ] = EEH_HTML::$_indent[ $tag ] >= 0 ? EEH_HTML::$_indent[ $tag ] : 0;
813
-    }
814
-
815
-
816
-    /**
817
-     *  class _set_default_indentation
818
-     *
819
-     * @access    private
820
-     */
821
-    private static function _set_default_indentation()
822
-    {
823
-        // set some initial formatting for table indentation
824
-        EEH_HTML::$_indent = array(
825
-            'none'  => 0,
826
-            'form'  => 0,
827
-            'radio'     => 0,
828
-            'checkbox'  => 0,
829
-            'select'    => 0,
830
-            'option' => 0,
831
-            'optgroup' => 0,
832
-            'table'     => 1,
833
-            'thead' => 2,
834
-            'tbody' => 2,
835
-            'tr'    => 3,
836
-            'th'    => 4,
837
-            'td'    => 4,
838
-            'div'   => 0,
839
-            'h1'    => 0,
840
-            'h2'    => 0,
841
-            'h3'    => 0,
842
-            'h4'    => 0,
843
-            'h5'    => 0,
844
-            'h6'    => 0,
845
-            'p'     => 0,
846
-            'ul'    => 0,
847
-            'li'    => 1
848
-        );
849
-    }
850
-
851
-
852
-
853
-    /**
854
-     * Retrieves the list of tags considered "simple", that are probably safe for
855
-     * use in inputs
856
-     * @global array $allowedtags
857
-     * @return array
858
-     */
859
-    public static function get_simple_tags()
860
-    {
861
-        global $allowedtags;
862
-        $tags_we_allow['p'] = array();
863
-        $tags_we_allow = array_merge_recursive(
864
-            $allowedtags,
865
-            array(
866
-                'ol' => array(),
867
-                'ul' => array(),
868
-                'li' => array(),
869
-                'br' => array(),
870
-                'p' => array(),
871
-                'a' => array('target')
872
-            )
873
-        );
874
-        return apply_filters('FHEE__EEH_HTML__get_simple_tags', $tags_we_allow);
875
-    }
126
+	 * @param string $tag
127
+	 * @param string $id - html id attribute
128
+	 * @param string $class - html class attribute
129
+	 * @param bool   $indent
130
+	 * @return string
131
+	 */
132
+	protected static function _close_tag($tag = 'div', $id = '', $class = '', $indent = true)
133
+	{
134
+		$comment = '';
135
+		if ($id) {
136
+			$comment = EEH_HTML::comment('close ' . $id) . EEH_HTML::nl(0, $tag);
137
+		} elseif ($class) {
138
+			$comment = EEH_HTML::comment('close ' . $class) . EEH_HTML::nl(0, $tag);
139
+		}
140
+		$html = $indent ? EEH_HTML::nl(-1, $tag) : '';
141
+		$html .= '</' . $tag . '>' . $comment;
142
+		return $html;
143
+	}
144
+
145
+
146
+
147
+	/**
148
+	 *  div - generates HTML opening <div> tag and adds any passed attributes
149
+	 *  to add an id use:       echo EEH_HTML::div( 'this is some content', 'footer' );
150
+	 *  to add a class use:     echo EEH_HTML::div( 'this is some content', '', 'float_left' );
151
+	 *  to add a both an id and a class use:    echo EEH_HTML::div( 'this is some content', 'footer', 'float_left' );
152
+	 *
153
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
154
+	 * @param string $id - html id attribute
155
+	 * @param string $class - html class attribute
156
+	 * @param string $style - html style attribute for applying inline styles
157
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
158
+	 * @return string
159
+	 */
160
+	public static function div($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
161
+	{
162
+		return EEH_HTML::_open_tag('div', $content, $id, $class, $style, $other_attributes);
163
+	}
164
+
165
+
166
+
167
+	/**
168
+	 * Generates HTML closing </div> tag - if passed the id or class attribute used for the opening div tag, will append a comment
169
+	 * usage: echo EEH_HTML::divx();
170
+	 *
171
+	 * @param string $id - html id attribute
172
+	 * @param string $class - html class attribute
173
+	 * @return string
174
+	 */
175
+	public static function divx($id = '', $class = '')
176
+	{
177
+		return EEH_HTML::_close_tag('div', $id, $class);
178
+	}
179
+
180
+
181
+
182
+	/**
183
+	 * Generates HTML <h1></h1> tags, inserts content, and adds any passed attributes
184
+	 * usage: echo EEH_HTML::h1( 'This is a Heading' );
185
+	 *
186
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
187
+	 * @param string $id - html id attribute
188
+	 * @param string $class - html class attribute
189
+	 * @param string $style - html style attribute for applying inline styles
190
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
191
+	 * @return string
192
+	 */
193
+	public static function h1($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
194
+	{
195
+		return EEH_HTML::_open_tag('h1', $content, $id, $class, $style, $other_attributes, true);
196
+	}
197
+
198
+
199
+
200
+	/**
201
+	 * Generates HTML <h2></h2> tags, inserts content, and adds any passed attributes
202
+	 * usage: echo EEH_HTML::h2( 'This is a Heading' );
203
+	 *
204
+	 * @param string $content          - inserted after opening tag, and appends closing tag, otherwise tag is left open
205
+	 * @param string $id               - html id attribute
206
+	 * @param string $class            - html class attribute
207
+	 * @param string $style            - html style attribute for applying inline styles
208
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
209
+	 * @return string
210
+	 */
211
+	public static function h2($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
212
+	{
213
+		return EEH_HTML::_open_tag('h2', $content, $id, $class, $style, $other_attributes, true);
214
+	}
215
+
216
+
217
+
218
+	/**
219
+	 * Generates HTML <h3></h3> tags, inserts content, and adds any passed attributes
220
+	 * usage: echo EEH_HTML::h3( 'This is a Heading' );
221
+	 *
222
+	 * @param string $content          - inserted after opening tag, and appends closing tag, otherwise tag is left open
223
+	 * @param string $id               - html id attribute
224
+	 * @param string $class            - html class attribute
225
+	 * @param string $style            - html style attribute for applying inline styles
226
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
227
+	 * @return string
228
+	 */
229
+	public static function h3($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
230
+	{
231
+		return EEH_HTML::_open_tag('h3', $content, $id, $class, $style, $other_attributes, true);
232
+	}
233
+
234
+
235
+
236
+	/**
237
+	 * Generates HTML <h4></h4> tags, inserts content, and adds any passed attributes
238
+	 * usage: echo EEH_HTML::h4( 'This is a Heading' );
239
+	 *
240
+	 * @param string $content          - inserted after opening tag, and appends closing tag, otherwise tag is left open
241
+	 * @param string $id               - html id attribute
242
+	 * @param string $class            - html class attribute
243
+	 * @param string $style            - html style attribute for applying inline styles
244
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
245
+	 * @return string
246
+	 */
247
+	public static function h4($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
248
+	{
249
+		return EEH_HTML::_open_tag('h4', $content, $id, $class, $style, $other_attributes, true);
250
+	}
251
+
252
+
253
+
254
+	/**
255
+	 * Generates HTML <h5></h5> tags, inserts content, and adds any passed attributes
256
+	 * usage: echo EEH_HTML::h5( 'This is a Heading' );
257
+	 *
258
+	 * @param string $content          - inserted after opening tag, and appends closing tag, otherwise tag is left open
259
+	 * @param string $id               - html id attribute
260
+	 * @param string $class            - html class attribute
261
+	 * @param string $style            - html style attribute for applying inline styles
262
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
263
+	 * @return string
264
+	 */
265
+	public static function h5($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
266
+	{
267
+		return EEH_HTML::_open_tag('h5', $content, $id, $class, $style, $other_attributes, true);
268
+	}
269
+
270
+
271
+
272
+	/**
273
+	 * Generates HTML <h6></h6> tags, inserts content, and adds any passed attributes
274
+	 * usage: echo EEH_HTML::h6( 'This is a Heading' );
275
+	 *
276
+	 * @param string $content          - inserted after opening tag, and appends closing tag, otherwise tag is left open
277
+	 * @param string $id               - html id attribute
278
+	 * @param string $class            - html class attribute
279
+	 * @param string $style            - html style attribute for applying inline styles
280
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
281
+	 * @return string
282
+	 */
283
+	public static function h6($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
284
+	{
285
+		return EEH_HTML::_open_tag('h6', $content, $id, $class, $style, $other_attributes, true);
286
+	}
287
+
288
+
289
+
290
+	/**
291
+	 * Generates HTML <p></p> tags, inserts content, and adds any passed attributes
292
+	 * usage: echo EEH_HTML::p( 'this is a paragraph' );
293
+	 *
294
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
295
+	 * @param string $id - html id attribute
296
+	 * @param string $class - html class attribute
297
+	 * @param string $style - html style attribute for applying inline styles
298
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
299
+	 * @return string
300
+	 */
301
+	public static function p($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
302
+	{
303
+		return EEH_HTML::_open_tag('p', $content, $id, $class, $style, $other_attributes, true);
304
+	}
305
+
306
+
307
+
308
+	/**
309
+	 *  ul - generates HTML opening <ul> tag and adds any passed attributes
310
+	 *  usage:      echo EEH_HTML::ul( 'my-list-id', 'my-list-class' );
311
+	 *
312
+	 * @param string $id - html id attribute
313
+	 * @param string $class - html class attribute
314
+	 * @param string $style - html style attribute for applying inline styles
315
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
316
+	 * @return string
317
+	 */
318
+	public static function ul($id = '', $class = '', $style = '', $other_attributes = '')
319
+	{
320
+		return EEH_HTML::_open_tag('ul', '', $id, $class, $style, $other_attributes);
321
+	}
322
+
323
+
324
+
325
+	/**
326
+	 * Generates HTML closing </ul> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
327
+	 * usage: echo EEH_HTML::ulx();
328
+	 *
329
+	 * @param string $id - html id attribute
330
+	 * @param string $class - html class attribute
331
+	 * @return string
332
+	 */
333
+	public static function ulx($id = '', $class = '')
334
+	{
335
+		return EEH_HTML::_close_tag('ul', $id, $class);
336
+	}
337
+
338
+
339
+
340
+	/**
341
+	 * Generates HTML <li> tag, inserts content, and adds any passed attributes
342
+	 * if passed content, it will also add that, as well as the closing </li> tag
343
+	 * usage: echo EEH_HTML::li( 'this is a line item' );
344
+	 *
345
+	 * @param string $id - html id attribute
346
+	 * @param string $class - html class attribute
347
+	 * @param string $style - html style attribute for applying inline styles
348
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
349
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
350
+	 * @return string
351
+	 */
352
+	public static function li($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
353
+	{
354
+		return EEH_HTML::_open_tag('li', $content, $id, $class, $style, $other_attributes);
355
+	}
356
+
357
+
358
+
359
+	/**
360
+	 * Generates HTML closing </li> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
361
+	 * usage: echo EEH_HTML::lix();
362
+	 *
363
+	 * @param string $id - html id attribute
364
+	 * @param string $class - html class attribute
365
+	 * @return string
366
+	 */
367
+	public static function lix($id = '', $class = '')
368
+	{
369
+		return EEH_HTML::_close_tag('li', $id, $class);
370
+	}
371
+
372
+
373
+
374
+	/**
375
+	 *    table - generates an HTML <table> tag and adds any passed attributes
376
+	 *    usage: echo EEH_HTML::table();
377
+	 *
378
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
379
+	 * @param string $id - html id attribute
380
+	 * @param string $class - html class attribute
381
+	 * @param string $style - html style attribute for applying inline styles
382
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
383
+	 * @return string
384
+	 */
385
+	public static function table($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
386
+	{
387
+		return EEH_HTML::_open_tag('table', $content, $id, $class, $style, $other_attributes);
388
+	}
389
+
390
+
391
+
392
+	/**
393
+	 * tablex - generates an HTML </table> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
394
+	 *
395
+	 * @param string $id - html id attribute
396
+	 * @param string $class - html class attribute
397
+	 * @return string
398
+	 */
399
+	public static function tablex($id = '', $class = '')
400
+	{
401
+		return EEH_HTML::_close_tag('table', $id, $class);
402
+	}
403
+
404
+
405
+
406
+	/**
407
+	 *    thead - generates an HTML <thead> tag and adds any passed attributes
408
+	 *    usage: echo EEH_HTML::thead();
409
+	 *
410
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
411
+	 * @param string $id - html id attribute
412
+	 * @param string $class - html class attribute
413
+	 * @param string $style - html style attribute for applying inline styles
414
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
415
+	 * @return string
416
+	 */
417
+	public static function thead($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
418
+	{
419
+		return EEH_HTML::_open_tag('thead', $content, $id, $class, $style, $other_attributes);
420
+	}
421
+
422
+
423
+
424
+	/**
425
+	 * theadx - generates an HTML </thead> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
426
+	 *
427
+	 * @param string $id - html id attribute
428
+	 * @param string $class - html class attribute
429
+	 * @return string
430
+	 */
431
+	public static function theadx($id = '', $class = '')
432
+	{
433
+		return EEH_HTML::_close_tag('thead', $id, $class);
434
+	}
435
+
436
+
437
+
438
+	/**
439
+	 *    tbody - generates an HTML <tbody> tag and adds any passed attributes
440
+	 *    usage: echo EEH_HTML::tbody();
441
+	 *
442
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
443
+	 * @param string $id - html id attribute
444
+	 * @param string $class - html class attribute
445
+	 * @param string $style - html style attribute for applying inline styles
446
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
447
+	 * @return string
448
+	 */
449
+	public static function tbody($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
450
+	{
451
+		return EEH_HTML::_open_tag('tbody', $content, $id, $class, $style, $other_attributes);
452
+	}
453
+
454
+
455
+
456
+	/**
457
+	 * tbodyx - generates an HTML </tbody> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
458
+	 *
459
+	 * @param string $id - html id attribute
460
+	 * @param string $class - html class attribute
461
+	 * @return string
462
+	 */
463
+	public static function tbodyx($id = '', $class = '')
464
+	{
465
+		return EEH_HTML::_close_tag('tbody', $id, $class);
466
+	}
467
+
468
+
469
+
470
+	/**
471
+	 *    tr - generates an HTML <tr> tag and adds any passed attributes
472
+	 *    usage: echo EEH_HTML::tr();
473
+	 *
474
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
475
+	 * @param string $id - html id attribute
476
+	 * @param string $class - html class attribute
477
+	 * @param string $style - html style attribute for applying inline styles
478
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
479
+	 * @return string
480
+	 */
481
+	public static function tr($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
482
+	{
483
+		return EEH_HTML::_open_tag('tr', $content, $id, $class, $style, $other_attributes);
484
+	}
485
+
486
+
487
+
488
+	/**
489
+	 * trx - generates an HTML </tr> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
490
+	 *
491
+	 * @param string $id - html id attribute
492
+	 * @param string $class - html class attribute
493
+	 * @return string
494
+	 */
495
+	public static function trx($id = '', $class = '')
496
+	{
497
+		return EEH_HTML::_close_tag('tr', $id, $class);
498
+	}
499
+
500
+
501
+
502
+	/**
503
+	 *    th - generates an HTML <th> tag and adds any passed attributes
504
+	 *    usage: echo EEH_HTML::th();
505
+	 *
506
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
507
+	 * @param string $id - html id attribute
508
+	 * @param string $class - html class attribute
509
+	 * @param string $style - html style attribute for applying inline styles
510
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
511
+	 * @return string
512
+	 */
513
+	public static function th($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
514
+	{
515
+		return EEH_HTML::_open_tag('th', $content, $id, $class, $style, $other_attributes);
516
+	}
517
+
518
+
519
+
520
+	/**
521
+	 * thx - generates an HTML </th> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
522
+	 *
523
+	 * @param string $id - html id attribute
524
+	 * @param string $class - html class attribute
525
+	 * @return string
526
+	 */
527
+	public static function thx($id = '', $class = '')
528
+	{
529
+		return EEH_HTML::_close_tag('th', $id, $class);
530
+	}
531
+
532
+
533
+
534
+	/**
535
+	 *    td - generates an HTML <td> tag and adds any passed attributes
536
+	 *    usage: echo EEH_HTML::td();
537
+	 *
538
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
539
+	 * @param string $id - html id attribute
540
+	 * @param string $class - html class attribute
541
+	 * @param string $style - html style attribute for applying inline styles
542
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
543
+	 * @return string
544
+	 */
545
+	public static function td($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
546
+	{
547
+		return EEH_HTML::_open_tag('td', $content, $id, $class, $style, $other_attributes);
548
+	}
549
+
550
+
551
+
552
+	/**
553
+	 * tdx - generates an HTML </td> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
554
+	 *
555
+	 * @param string $id - html id attribute
556
+	 * @param string $class - html class attribute
557
+	 * @return string
558
+	 */
559
+	public static function tdx($id = '', $class = '')
560
+	{
561
+		return EEH_HTML::_close_tag('td', $id, $class);
562
+	}
563
+
564
+
565
+
566
+	/**
567
+	 * no_row - for generating a "hidden" table row, good for embedding tables within tables
568
+	 * generates a new table row with one td cell that spans however many columns you set
569
+	 * removes all styles from the tr and td
570
+	 *
571
+	 * @param string $content
572
+	 * @param int    $colspan
573
+	 * @return string
574
+	 */
575
+	public static function no_row($content = '', $colspan = 2)
576
+	{
577
+		return EEH_HTML::tr(
578
+			EEH_HTML::td($content, '', '', 'padding:0; border:none;', 'colspan="' . $colspan . '"'),
579
+			'',
580
+			'',
581
+			'padding:0; border:none;'
582
+		);
583
+	}
584
+
585
+
586
+
587
+	/**
588
+	 * Generates HTML <label></label> tags, inserts content, and adds any passed attributes
589
+	 * usage: echo EEH_HTML::span( 'this is some inline text' );
590
+	 *
591
+	 * @access public
592
+	 * @param string $href URL to link to
593
+	 * @param string $link_text - the text that will become "hyperlinked"
594
+	 * @param string $title - html title attribute
595
+	 * @param string $id - html id attribute
596
+	 * @param string $class - html class attribute
597
+	 * @param string $style - html style attribute for applying inline styles
598
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
599
+	 * @return string
600
+	 */
601
+	public static function link($href = '', $link_text = '', $title = '', $id = '', $class = '', $style = '', $other_attributes = '')
602
+	{
603
+		$link_text = ! empty($link_text) ? $link_text : $href;
604
+		$attributes = ! empty($href) ? ' href="' . $href . '"' : '';
605
+		$attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
606
+		$attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
607
+		$attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
608
+		$attributes .= ! empty($title) ? ' title="' . esc_attr($title) . '"' : '';
609
+		$attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
610
+		return "<a{$attributes}>{$link_text}</a>";
611
+	}
612
+
613
+
614
+
615
+	/**
616
+	 *    img - generates an HTML <img> tag and adds any passed attributes
617
+	 *    usage: echo EEH_HTML::img();
618
+	 *
619
+	 * @param string $src - html src attribute ie: the path or URL to the image
620
+	 * @param string $alt - html alt attribute
621
+	 * @param string $id - html id attribute
622
+	 * @param string $class - html class attribute
623
+	 * @param string $style - html style attribute for applying inline styles
624
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
625
+	 * @return string
626
+	 */
627
+	public static function img($src = '', $alt = '', $id = '', $class = '', $style = '', $other_attributes = '')
628
+	{
629
+		$attributes = ! empty($src) ? ' src="' . esc_url_raw($src) . '"' : '';
630
+		$attributes .= ! empty($alt) ? ' alt="' . esc_attr($alt) . '"' : '';
631
+		$attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
632
+		$attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
633
+		$attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
634
+		$attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
635
+		return '<img' . $attributes  . '/>';
636
+	}
637
+
638
+
639
+
640
+	/**
641
+	 * Generates HTML <label></label> tags, inserts content, and adds any passed attributes
642
+	 * usage: echo EEH_HTML::span( 'this is some inline text' );
643
+	 *
644
+	 * @access protected
645
+	 * @param string $tag
646
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
647
+	 * @param string $id - html id attribute
648
+	 * @param string $class - html class attribute
649
+	 * @param string $style - html style attribute for applying inline styles
650
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
651
+	 * @return string
652
+	 */
653
+	protected static function _inline_tag($tag = 'span', $content = '', $id = '', $class = '', $style = '', $other_attributes = '')
654
+	{
655
+		$attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
656
+		$attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
657
+		$attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
658
+		$attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
659
+		return '<' . $tag . ' ' . $attributes . '>'  . $content  . '</' . $tag . '>';
660
+	}
661
+
662
+
663
+
664
+	/**
665
+	 * Generates HTML <label></label> tags, inserts content, and adds any passed attributes
666
+	 * usage: echo EEH_HTML::span( 'this is some inline text' );
667
+	 *
668
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
669
+	 * @param string $id - html id attribute
670
+	 * @param string $class - html class attribute
671
+	 * @param string $style - html style attribute for applying inline styles
672
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
673
+	 * @return string
674
+	 */
675
+	public static function label($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
676
+	{
677
+		return EEH_HTML::_inline_tag('label', $content, $id, $class, $style, $other_attributes);
678
+	}
679
+
680
+
681
+
682
+	/**
683
+	 * Generates HTML <span></span> tags, inserts content, and adds any passed attributes
684
+	 * usage: echo EEH_HTML::span( 'this is some inline text' );
685
+	 *
686
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
687
+	 * @param string $id - html id attribute
688
+	 * @param string $class - html class attribute
689
+	 * @param string $style - html style attribute for applying inline styles
690
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
691
+	 * @return string
692
+	 */
693
+	public static function span($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
694
+	{
695
+		return EEH_HTML::_inline_tag('span', $content, $id, $class, $style, $other_attributes);
696
+	}
697
+
698
+
699
+
700
+	/**
701
+	 * Generates HTML <span></span> tags, inserts content, and adds any passed attributes
702
+	 * usage: echo EEH_HTML::span( 'this is some inline text' );
703
+	 *
704
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
705
+	 * @param string $id - html id attribute
706
+	 * @param string $class - html class attribute
707
+	 * @param string $style - html style attribute for applying inline styles
708
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
709
+	 * @return string
710
+	 */
711
+	public static function strong($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
712
+	{
713
+		return EEH_HTML::_inline_tag('strong', $content, $id, $class, $style, $other_attributes);
714
+	}
715
+
716
+
717
+
718
+	/**
719
+	 * Generates an html <--  comment --> tag
720
+	 *  usage: echo comment( 'this is a comment' );
721
+	 *
722
+	 * @param string $comment
723
+	 * @return string
724
+	 */
725
+	public static function comment($comment = '')
726
+	{
727
+		return ! empty($comment) ? EEH_HTML::nl() . '<!-- ' . $comment . ' -->' : '';
728
+	}
729
+
730
+
731
+
732
+	/**
733
+	 * br - generates a line break
734
+	 *
735
+	 * @param int $nmbr - the number of line breaks to return
736
+	 * @return string
737
+	 */
738
+	public static function br($nmbr = 1)
739
+	{
740
+		return str_repeat('<br />', $nmbr);
741
+	}
742
+
743
+
744
+
745
+	/**
746
+	 * nbsp - generates non-breaking space entities based on number supplied
747
+	 *
748
+	 * @param int $nmbr - the number of non-breaking spaces to return
749
+	 * @return string
750
+	 */
751
+	public static function nbsp($nmbr = 1)
752
+	{
753
+		return str_repeat('&nbsp;', $nmbr);
754
+	}
755
+
756
+
757
+
758
+	/**
759
+	 * sanitize_id
760
+	 *
761
+	 * functionally does the same as the wp_core function sanitize_key except it does NOT use
762
+	 * strtolower and allows capitals.
763
+	 *
764
+	 * @param string $id
765
+	 * @return string
766
+	 */
767
+	public static function sanitize_id($id = '')
768
+	{
769
+		$key = str_replace(' ', '-', trim($id));
770
+		return preg_replace('/[^a-zA-Z0-9_\-]/', '', $key);
771
+	}
772
+
773
+
774
+
775
+	/**
776
+	 * return a newline and tabs ("nl" stands for "new line")
777
+	 *
778
+	 * @param int    $indent the number of tabs to ADD to the current indent (can be negative or zero)
779
+	 * @param string $tag
780
+	 * @return string - newline character plus # of indents passed (can be + or -)
781
+	 */
782
+	public static function nl($indent = 0, $tag = 'none')
783
+	{
784
+		$html = "\n";
785
+		EEH_HTML::indent($indent, $tag);
786
+		for ($x = 0; $x < EEH_HTML::$_indent[ $tag ]; $x++) {
787
+			$html .= "\t";
788
+		}
789
+		return $html;
790
+	}
791
+
792
+
793
+
794
+	/**
795
+	 * Changes the indents used in EEH_HTML::nl. Often its convenient to change
796
+	 * the indentation level without actually creating a new line
797
+	 *
798
+	 * @param int    $indent can be negative to decrease the indentation level
799
+	 * @param string $tag
800
+	 */
801
+	public static function indent($indent, $tag = 'none')
802
+	{
803
+		static $default_indentation = false;
804
+		if (! $default_indentation) {
805
+			EEH_HTML::_set_default_indentation();
806
+			$default_indentation = true;
807
+		}
808
+		if (! isset(EEH_HTML::$_indent[ $tag ])) {
809
+			EEH_HTML::$_indent[ $tag ] = 0;
810
+		}
811
+		EEH_HTML::$_indent[ $tag ] += (int) $indent;
812
+		EEH_HTML::$_indent[ $tag ] = EEH_HTML::$_indent[ $tag ] >= 0 ? EEH_HTML::$_indent[ $tag ] : 0;
813
+	}
814
+
815
+
816
+	/**
817
+	 *  class _set_default_indentation
818
+	 *
819
+	 * @access    private
820
+	 */
821
+	private static function _set_default_indentation()
822
+	{
823
+		// set some initial formatting for table indentation
824
+		EEH_HTML::$_indent = array(
825
+			'none'  => 0,
826
+			'form'  => 0,
827
+			'radio'     => 0,
828
+			'checkbox'  => 0,
829
+			'select'    => 0,
830
+			'option' => 0,
831
+			'optgroup' => 0,
832
+			'table'     => 1,
833
+			'thead' => 2,
834
+			'tbody' => 2,
835
+			'tr'    => 3,
836
+			'th'    => 4,
837
+			'td'    => 4,
838
+			'div'   => 0,
839
+			'h1'    => 0,
840
+			'h2'    => 0,
841
+			'h3'    => 0,
842
+			'h4'    => 0,
843
+			'h5'    => 0,
844
+			'h6'    => 0,
845
+			'p'     => 0,
846
+			'ul'    => 0,
847
+			'li'    => 1
848
+		);
849
+	}
850
+
851
+
852
+
853
+	/**
854
+	 * Retrieves the list of tags considered "simple", that are probably safe for
855
+	 * use in inputs
856
+	 * @global array $allowedtags
857
+	 * @return array
858
+	 */
859
+	public static function get_simple_tags()
860
+	{
861
+		global $allowedtags;
862
+		$tags_we_allow['p'] = array();
863
+		$tags_we_allow = array_merge_recursive(
864
+			$allowedtags,
865
+			array(
866
+				'ol' => array(),
867
+				'ul' => array(),
868
+				'li' => array(),
869
+				'br' => array(),
870
+				'p' => array(),
871
+				'a' => array('target')
872
+			)
873
+		);
874
+		return apply_filters('FHEE__EEH_HTML__get_simple_tags', $tags_we_allow);
875
+	}
876 876
 }
Please login to merge, or discard this patch.
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
     public static function instance()
44 44
     {
45 45
         // check if class object is instantiated, and instantiated properly
46
-        if (! self::$_instance instanceof EEH_HTML) {
46
+        if ( ! self::$_instance instanceof EEH_HTML) {
47 47
             self::$_instance = new EEH_HTML();
48 48
         }
49 49
         return self::$_instance;
@@ -105,12 +105,12 @@  discard block
 block discarded – undo
105 105
         $other_attributes = '',
106 106
         $force_close = false
107 107
     ) {
108
-        $attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
109
-        $attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
110
-        $attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
111
-        $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
112
-        $html = EEH_HTML::nl(0, $tag) . '<' . $tag . $attributes . '>';
113
-        $html .= ! empty($content) ? EEH_HTML::nl(1, $tag) . $content : '';
108
+        $attributes = ! empty($id) ? ' id="'.EEH_HTML::sanitize_id($id).'"' : '';
109
+        $attributes .= ! empty($class) ? ' class="'.$class.'"' : '';
110
+        $attributes .= ! empty($style) ? ' style="'.$style.'"' : '';
111
+        $attributes .= ! empty($other_attributes) ? ' '.$other_attributes : '';
112
+        $html = EEH_HTML::nl(0, $tag).'<'.$tag.$attributes.'>';
113
+        $html .= ! empty($content) ? EEH_HTML::nl(1, $tag).$content : '';
114 114
         $indent = ! empty($content) || $force_close ? true : false;
115 115
         $html .= ! empty($content) || $force_close ? EEH_HTML::_close_tag($tag, $id, $class, $indent) : '';
116 116
         return $html;
@@ -133,12 +133,12 @@  discard block
 block discarded – undo
133 133
     {
134 134
         $comment = '';
135 135
         if ($id) {
136
-            $comment = EEH_HTML::comment('close ' . $id) . EEH_HTML::nl(0, $tag);
136
+            $comment = EEH_HTML::comment('close '.$id).EEH_HTML::nl(0, $tag);
137 137
         } elseif ($class) {
138
-            $comment = EEH_HTML::comment('close ' . $class) . EEH_HTML::nl(0, $tag);
138
+            $comment = EEH_HTML::comment('close '.$class).EEH_HTML::nl(0, $tag);
139 139
         }
140 140
         $html = $indent ? EEH_HTML::nl(-1, $tag) : '';
141
-        $html .= '</' . $tag . '>' . $comment;
141
+        $html .= '</'.$tag.'>'.$comment;
142 142
         return $html;
143 143
     }
144 144
 
@@ -575,7 +575,7 @@  discard block
 block discarded – undo
575 575
     public static function no_row($content = '', $colspan = 2)
576 576
     {
577 577
         return EEH_HTML::tr(
578
-            EEH_HTML::td($content, '', '', 'padding:0; border:none;', 'colspan="' . $colspan . '"'),
578
+            EEH_HTML::td($content, '', '', 'padding:0; border:none;', 'colspan="'.$colspan.'"'),
579 579
             '',
580 580
             '',
581 581
             'padding:0; border:none;'
@@ -601,12 +601,12 @@  discard block
 block discarded – undo
601 601
     public static function link($href = '', $link_text = '', $title = '', $id = '', $class = '', $style = '', $other_attributes = '')
602 602
     {
603 603
         $link_text = ! empty($link_text) ? $link_text : $href;
604
-        $attributes = ! empty($href) ? ' href="' . $href . '"' : '';
605
-        $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
606
-        $attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
607
-        $attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
608
-        $attributes .= ! empty($title) ? ' title="' . esc_attr($title) . '"' : '';
609
-        $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
604
+        $attributes = ! empty($href) ? ' href="'.$href.'"' : '';
605
+        $attributes .= ! empty($id) ? ' id="'.EEH_HTML::sanitize_id($id).'"' : '';
606
+        $attributes .= ! empty($class) ? ' class="'.$class.'"' : '';
607
+        $attributes .= ! empty($style) ? ' style="'.$style.'"' : '';
608
+        $attributes .= ! empty($title) ? ' title="'.esc_attr($title).'"' : '';
609
+        $attributes .= ! empty($other_attributes) ? ' '.$other_attributes : '';
610 610
         return "<a{$attributes}>{$link_text}</a>";
611 611
     }
612 612
 
@@ -626,13 +626,13 @@  discard block
 block discarded – undo
626 626
      */
627 627
     public static function img($src = '', $alt = '', $id = '', $class = '', $style = '', $other_attributes = '')
628 628
     {
629
-        $attributes = ! empty($src) ? ' src="' . esc_url_raw($src) . '"' : '';
630
-        $attributes .= ! empty($alt) ? ' alt="' . esc_attr($alt) . '"' : '';
631
-        $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
632
-        $attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
633
-        $attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
634
-        $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
635
-        return '<img' . $attributes  . '/>';
629
+        $attributes = ! empty($src) ? ' src="'.esc_url_raw($src).'"' : '';
630
+        $attributes .= ! empty($alt) ? ' alt="'.esc_attr($alt).'"' : '';
631
+        $attributes .= ! empty($id) ? ' id="'.EEH_HTML::sanitize_id($id).'"' : '';
632
+        $attributes .= ! empty($class) ? ' class="'.$class.'"' : '';
633
+        $attributes .= ! empty($style) ? ' style="'.$style.'"' : '';
634
+        $attributes .= ! empty($other_attributes) ? ' '.$other_attributes : '';
635
+        return '<img'.$attributes.'/>';
636 636
     }
637 637
 
638 638
 
@@ -652,11 +652,11 @@  discard block
 block discarded – undo
652 652
      */
653 653
     protected static function _inline_tag($tag = 'span', $content = '', $id = '', $class = '', $style = '', $other_attributes = '')
654 654
     {
655
-        $attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
656
-        $attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
657
-        $attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
658
-        $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
659
-        return '<' . $tag . ' ' . $attributes . '>'  . $content  . '</' . $tag . '>';
655
+        $attributes = ! empty($id) ? ' id="'.EEH_HTML::sanitize_id($id).'"' : '';
656
+        $attributes .= ! empty($class) ? ' class="'.$class.'"' : '';
657
+        $attributes .= ! empty($style) ? ' style="'.$style.'"' : '';
658
+        $attributes .= ! empty($other_attributes) ? ' '.$other_attributes : '';
659
+        return '<'.$tag.' '.$attributes.'>'.$content.'</'.$tag.'>';
660 660
     }
661 661
 
662 662
 
@@ -724,7 +724,7 @@  discard block
 block discarded – undo
724 724
      */
725 725
     public static function comment($comment = '')
726 726
     {
727
-        return ! empty($comment) ? EEH_HTML::nl() . '<!-- ' . $comment . ' -->' : '';
727
+        return ! empty($comment) ? EEH_HTML::nl().'<!-- '.$comment.' -->' : '';
728 728
     }
729 729
 
730 730
 
@@ -783,7 +783,7 @@  discard block
 block discarded – undo
783 783
     {
784 784
         $html = "\n";
785 785
         EEH_HTML::indent($indent, $tag);
786
-        for ($x = 0; $x < EEH_HTML::$_indent[ $tag ]; $x++) {
786
+        for ($x = 0; $x < EEH_HTML::$_indent[$tag]; $x++) {
787 787
             $html .= "\t";
788 788
         }
789 789
         return $html;
@@ -801,15 +801,15 @@  discard block
 block discarded – undo
801 801
     public static function indent($indent, $tag = 'none')
802 802
     {
803 803
         static $default_indentation = false;
804
-        if (! $default_indentation) {
804
+        if ( ! $default_indentation) {
805 805
             EEH_HTML::_set_default_indentation();
806 806
             $default_indentation = true;
807 807
         }
808
-        if (! isset(EEH_HTML::$_indent[ $tag ])) {
809
-            EEH_HTML::$_indent[ $tag ] = 0;
808
+        if ( ! isset(EEH_HTML::$_indent[$tag])) {
809
+            EEH_HTML::$_indent[$tag] = 0;
810 810
         }
811
-        EEH_HTML::$_indent[ $tag ] += (int) $indent;
812
-        EEH_HTML::$_indent[ $tag ] = EEH_HTML::$_indent[ $tag ] >= 0 ? EEH_HTML::$_indent[ $tag ] : 0;
811
+        EEH_HTML::$_indent[$tag] += (int) $indent;
812
+        EEH_HTML::$_indent[$tag] = EEH_HTML::$_indent[$tag] >= 0 ? EEH_HTML::$_indent[$tag] : 0;
813 813
     }
814 814
 
815 815
 
Please login to merge, or discard this patch.