Completed
Branch dependabot/npm_and_yarn/wordpr... (839ddb)
by
unknown
16:10 queued 14:20
created
core/db_models/EEM_Extra_Join.model.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -23,32 +23,32 @@
 block discarded – undo
23 23
  */
24 24
 class EEM_Extra_Join extends EEM_Base
25 25
 {
26
-    // private instance of the Extra Join object
27
-    protected static $_instance = null;
26
+	// private instance of the Extra Join object
27
+	protected static $_instance = null;
28 28
     
29
-    public function __construct($timezone = null)
30
-    {
31
-        $models_this_can_join = array_keys(EE_Registry::instance()->non_abstract_db_models);
32
-        $this->_tables = array(
33
-            'Extra_Join' => new EE_Primary_Table('esp_extra_join', 'EXJ_ID'),
34
-        );
35
-        $this->_fields = array(
36
-            'Extra_Join' => array(
37
-                'EXJ_ID' => new EE_Primary_Key_Int_Field('EXJ_ID', __('Extra Join ID', 'event_espresso')),
38
-                'EXJ_first_model_ID' => new EE_Foreign_Key_String_Field('EXJ_first_model_ID', __('First Model ID', 'event_espresso'), true, 0, $models_this_can_join),
39
-                'EXJ_first_model_name' => new EE_Any_Foreign_Model_Name_Field('EXJ_first_model_name', __('First Model Name', 'event_espresso'), true, '', $models_this_can_join),
40
-                'EXJ_second_model_ID' => new EE_Foreign_Key_String_Field('EXJ_second_model_ID', __('Second Model ID', 'event_espresso'), true, 0, $models_this_can_join),
41
-                'EXJ_second_model_name' => new EE_Any_Foreign_Model_Name_Field('EXJ_second_model_name', __('Second Model Name', 'event_espresso'), true, '', $models_this_can_join),
29
+	public function __construct($timezone = null)
30
+	{
31
+		$models_this_can_join = array_keys(EE_Registry::instance()->non_abstract_db_models);
32
+		$this->_tables = array(
33
+			'Extra_Join' => new EE_Primary_Table('esp_extra_join', 'EXJ_ID'),
34
+		);
35
+		$this->_fields = array(
36
+			'Extra_Join' => array(
37
+				'EXJ_ID' => new EE_Primary_Key_Int_Field('EXJ_ID', __('Extra Join ID', 'event_espresso')),
38
+				'EXJ_first_model_ID' => new EE_Foreign_Key_String_Field('EXJ_first_model_ID', __('First Model ID', 'event_espresso'), true, 0, $models_this_can_join),
39
+				'EXJ_first_model_name' => new EE_Any_Foreign_Model_Name_Field('EXJ_first_model_name', __('First Model Name', 'event_espresso'), true, '', $models_this_can_join),
40
+				'EXJ_second_model_ID' => new EE_Foreign_Key_String_Field('EXJ_second_model_ID', __('Second Model ID', 'event_espresso'), true, 0, $models_this_can_join),
41
+				'EXJ_second_model_name' => new EE_Any_Foreign_Model_Name_Field('EXJ_second_model_name', __('Second Model Name', 'event_espresso'), true, '', $models_this_can_join),
42 42
                 
43
-            )
44
-        );
45
-        // this model is weird in that it has two foreign key columns which can point to any model/table.
46
-        // eg a foreign key to event will be in "EXJ_first_model_ID", provided the other
47
-        // model linked to is alphabetically greater than event (eg venue).
48
-        // but if the model linked to is alphabetically lower (eg attendee),
49
-        // the foreign key to the event will be in "EXJ_second_model_ID"
50
-        // so normal usage of foreign keys is weird. So don't define any
51
-        // relations to other models because they won't work properly with this model
52
-        parent::__construct($timezone);
53
-    }
43
+			)
44
+		);
45
+		// this model is weird in that it has two foreign key columns which can point to any model/table.
46
+		// eg a foreign key to event will be in "EXJ_first_model_ID", provided the other
47
+		// model linked to is alphabetically greater than event (eg venue).
48
+		// but if the model linked to is alphabetically lower (eg attendee),
49
+		// the foreign key to the event will be in "EXJ_second_model_ID"
50
+		// so normal usage of foreign keys is weird. So don't define any
51
+		// relations to other models because they won't work properly with this model
52
+		parent::__construct($timezone);
53
+	}
54 54
 }
Please login to merge, or discard this patch.
core/db_models/EEM_State.model.php 2 patches
Indentation   +157 added lines, -157 removed lines patch added patch discarded remove patch
@@ -11,161 +11,161 @@
 block discarded – undo
11 11
 class EEM_State extends EEM_Base
12 12
 {
13 13
 
14
-    // private instance of the Attendee object
15
-    protected static $_instance = null;
16
-    // array of all states
17
-    private static $_all_states = false;
18
-    // array of all active states
19
-    private static $_active_states = false;
20
-
21
-    protected function __construct($timezone = null)
22
-    {
23
-        $this->singular_item = __('State/Province', 'event_espresso');
24
-        $this->plural_item = __('States/Provinces', 'event_espresso');
25
-
26
-        $this->_tables = array(
27
-            'State'=> new EE_Primary_Table('esp_state', 'STA_ID')
28
-        );
29
-
30
-        $this->_fields = array(
31
-            'State'=>array(
32
-                'STA_ID'=> new EE_Primary_Key_Int_Field('STA_ID', __('State ID', 'event_espresso')),
33
-                'CNT_ISO'=> new EE_Foreign_Key_String_Field('CNT_ISO', __('Country ISO Code', 'event_espresso'), false, null, 'Country'),
34
-                'STA_abbrev' => new EE_Plain_Text_Field('STA_abbrev', __('State Abbreviation', 'event_espresso'), false, ''),
35
-                'STA_name' => new EE_Plain_Text_Field('STA_name', __('State Name', 'event_espresso'), false, ''),
36
-                'STA_active'=> new EE_Boolean_Field('STA_active', __('State Active Flag', 'event_espresso'), false, false)
37
-                ));
38
-        $this->_model_relations = array(
39
-            'Attendee'=>new EE_Has_Many_Relation(),
40
-            'Country' => new EE_Belongs_To_Relation(),
41
-            'Venue'=>new EE_Has_Many_Relation(),
42
-        );
43
-        // this model is generally available for reading
44
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
45
-        // @todo: only show STA_active
46
-        parent::__construct($timezone);
47
-    }
48
-
49
-
50
-
51
-
52
-    /**
53
-    *   reset_cached_states
54
-    *
55
-    *   @access     private
56
-    *   @return         void
57
-    */
58
-    public function reset_cached_states()
59
-    {
60
-        EEM_State::$_active_states = array();
61
-        EEM_State::$_all_states = array();
62
-    }
63
-
64
-
65
-
66
-
67
-    /**
68
-    *       _get_states
69
-    *
70
-    *       @access     private
71
-    *       @return         array
72
-    */
73
-    public function get_all_states()
74
-    {
75
-        if (! self::$_all_states) {
76
-            self::$_all_states = $this->get_all(array( 'order_by'=>array( 'STA_name'=>'ASC' ), 'limit'=> array( 0, 99999 )));
77
-        }
78
-        return self::$_all_states;
79
-    }
80
-
81
-
82
-
83
-    /**
84
-     *        _get_states
85
-     *
86
-     * @access        public
87
-     * @param array $countries
88
-     * @param bool  $flush_cache
89
-     * @return        array
90
-     */
91
-    public function get_all_active_states($countries = array(), $flush_cache = false)
92
-    {
93
-        if (! self::$_active_states || $flush_cache) {
94
-            $countries = is_array($countries) && ! empty($countries) ? $countries : EEM_Country::instance()->get_all_active_countries();
95
-            self::$_active_states =  $this->get_all(array(
96
-                array( 'STA_active' => true, 'CNT_ISO' => array( 'IN', array_keys($countries))),
97
-                'order_by' => array( 'STA_name'=>'ASC' ),
98
-                'limit' => array( 0, 99999 ),
99
-                'force_join' => array( 'Country' )
100
-            ));
101
-        }
102
-        return self::$_active_states;
103
-    }
104
-
105
-
106
-
107
-    /**
108
-     *  get_all_states_of_active_countries
109
-     * @return array
110
-     */
111
-    public function get_all_states_of_active_countries()
112
-    {
113
-        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
-            return $states;
115
-        }
116
-        return false;
117
-    }
118
-
119
-
120
-
121
-    /**
122
-     *  get_all_states_of_active_countries
123
-     * @return array
124
-     */
125
-    public function get_all_active_states_for_these_countries($countries)
126
-    {
127
-        if (! $countries) {
128
-            return false;
129
-        }
130
-        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
-            return $states;
132
-        }
133
-        return false;
134
-    }
135
-
136
-
137
-
138
-    /**
139
-     *  get_all_states_of_active_countries
140
-     * @return array
141
-     */
142
-    public function get_all_states_for_these_countries($countries)
143
-    {
144
-        if (! $countries) {
145
-            return false;
146
-        }
147
-        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
-            return $states;
149
-        }
150
-        return false;
151
-    }
152
-
153
-    /**
154
-     * Gets the state's name by its ID
155
-     * @param string $state_ID
156
-     * @return string
157
-     */
158
-    public function get_state_name_by_ID($state_ID)
159
-    {
160
-        if (isset(self::$_all_states[ $state_ID ]) &&
161
-                self::$_all_states[ $state_ID ] instanceof EE_State ) {
162
-            return self::$_all_states[ $state_ID ]->name();
163
-        }
164
-        $names = $this->get_col(array( array( 'STA_ID' => $state_ID ), 'limit' => 1), 'STA_name');
165
-        if (is_array($names) && ! empty($names)) {
166
-            return reset($names);
167
-        } else {
168
-            return '';
169
-        }
170
-    }
14
+	// private instance of the Attendee object
15
+	protected static $_instance = null;
16
+	// array of all states
17
+	private static $_all_states = false;
18
+	// array of all active states
19
+	private static $_active_states = false;
20
+
21
+	protected function __construct($timezone = null)
22
+	{
23
+		$this->singular_item = __('State/Province', 'event_espresso');
24
+		$this->plural_item = __('States/Provinces', 'event_espresso');
25
+
26
+		$this->_tables = array(
27
+			'State'=> new EE_Primary_Table('esp_state', 'STA_ID')
28
+		);
29
+
30
+		$this->_fields = array(
31
+			'State'=>array(
32
+				'STA_ID'=> new EE_Primary_Key_Int_Field('STA_ID', __('State ID', 'event_espresso')),
33
+				'CNT_ISO'=> new EE_Foreign_Key_String_Field('CNT_ISO', __('Country ISO Code', 'event_espresso'), false, null, 'Country'),
34
+				'STA_abbrev' => new EE_Plain_Text_Field('STA_abbrev', __('State Abbreviation', 'event_espresso'), false, ''),
35
+				'STA_name' => new EE_Plain_Text_Field('STA_name', __('State Name', 'event_espresso'), false, ''),
36
+				'STA_active'=> new EE_Boolean_Field('STA_active', __('State Active Flag', 'event_espresso'), false, false)
37
+				));
38
+		$this->_model_relations = array(
39
+			'Attendee'=>new EE_Has_Many_Relation(),
40
+			'Country' => new EE_Belongs_To_Relation(),
41
+			'Venue'=>new EE_Has_Many_Relation(),
42
+		);
43
+		// this model is generally available for reading
44
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
45
+		// @todo: only show STA_active
46
+		parent::__construct($timezone);
47
+	}
48
+
49
+
50
+
51
+
52
+	/**
53
+	 *   reset_cached_states
54
+	 *
55
+	 *   @access     private
56
+	 *   @return         void
57
+	 */
58
+	public function reset_cached_states()
59
+	{
60
+		EEM_State::$_active_states = array();
61
+		EEM_State::$_all_states = array();
62
+	}
63
+
64
+
65
+
66
+
67
+	/**
68
+	 *       _get_states
69
+	 *
70
+	 *       @access     private
71
+	 *       @return         array
72
+	 */
73
+	public function get_all_states()
74
+	{
75
+		if (! self::$_all_states) {
76
+			self::$_all_states = $this->get_all(array( 'order_by'=>array( 'STA_name'=>'ASC' ), 'limit'=> array( 0, 99999 )));
77
+		}
78
+		return self::$_all_states;
79
+	}
80
+
81
+
82
+
83
+	/**
84
+	 *        _get_states
85
+	 *
86
+	 * @access        public
87
+	 * @param array $countries
88
+	 * @param bool  $flush_cache
89
+	 * @return        array
90
+	 */
91
+	public function get_all_active_states($countries = array(), $flush_cache = false)
92
+	{
93
+		if (! self::$_active_states || $flush_cache) {
94
+			$countries = is_array($countries) && ! empty($countries) ? $countries : EEM_Country::instance()->get_all_active_countries();
95
+			self::$_active_states =  $this->get_all(array(
96
+				array( 'STA_active' => true, 'CNT_ISO' => array( 'IN', array_keys($countries))),
97
+				'order_by' => array( 'STA_name'=>'ASC' ),
98
+				'limit' => array( 0, 99999 ),
99
+				'force_join' => array( 'Country' )
100
+			));
101
+		}
102
+		return self::$_active_states;
103
+	}
104
+
105
+
106
+
107
+	/**
108
+	 *  get_all_states_of_active_countries
109
+	 * @return array
110
+	 */
111
+	public function get_all_states_of_active_countries()
112
+	{
113
+		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
+			return $states;
115
+		}
116
+		return false;
117
+	}
118
+
119
+
120
+
121
+	/**
122
+	 *  get_all_states_of_active_countries
123
+	 * @return array
124
+	 */
125
+	public function get_all_active_states_for_these_countries($countries)
126
+	{
127
+		if (! $countries) {
128
+			return false;
129
+		}
130
+		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
+			return $states;
132
+		}
133
+		return false;
134
+	}
135
+
136
+
137
+
138
+	/**
139
+	 *  get_all_states_of_active_countries
140
+	 * @return array
141
+	 */
142
+	public function get_all_states_for_these_countries($countries)
143
+	{
144
+		if (! $countries) {
145
+			return false;
146
+		}
147
+		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
+			return $states;
149
+		}
150
+		return false;
151
+	}
152
+
153
+	/**
154
+	 * Gets the state's name by its ID
155
+	 * @param string $state_ID
156
+	 * @return string
157
+	 */
158
+	public function get_state_name_by_ID($state_ID)
159
+	{
160
+		if (isset(self::$_all_states[ $state_ID ]) &&
161
+				self::$_all_states[ $state_ID ] instanceof EE_State ) {
162
+			return self::$_all_states[ $state_ID ]->name();
163
+		}
164
+		$names = $this->get_col(array( array( 'STA_ID' => $state_ID ), 'limit' => 1), 'STA_name');
165
+		if (is_array($names) && ! empty($names)) {
166
+			return reset($names);
167
+		} else {
168
+			return '';
169
+		}
170
+	}
171 171
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
             'Venue'=>new EE_Has_Many_Relation(),
42 42
         );
43 43
         // this model is generally available for reading
44
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
44
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
45 45
         // @todo: only show STA_active
46 46
         parent::__construct($timezone);
47 47
     }
@@ -72,8 +72,8 @@  discard block
 block discarded – undo
72 72
     */
73 73
     public function get_all_states()
74 74
     {
75
-        if (! self::$_all_states) {
76
-            self::$_all_states = $this->get_all(array( 'order_by'=>array( 'STA_name'=>'ASC' ), 'limit'=> array( 0, 99999 )));
75
+        if ( ! self::$_all_states) {
76
+            self::$_all_states = $this->get_all(array('order_by'=>array('STA_name'=>'ASC'), 'limit'=> array(0, 99999)));
77 77
         }
78 78
         return self::$_all_states;
79 79
     }
@@ -90,13 +90,13 @@  discard block
 block discarded – undo
90 90
      */
91 91
     public function get_all_active_states($countries = array(), $flush_cache = false)
92 92
     {
93
-        if (! self::$_active_states || $flush_cache) {
93
+        if ( ! self::$_active_states || $flush_cache) {
94 94
             $countries = is_array($countries) && ! empty($countries) ? $countries : EEM_Country::instance()->get_all_active_countries();
95
-            self::$_active_states =  $this->get_all(array(
96
-                array( 'STA_active' => true, 'CNT_ISO' => array( 'IN', array_keys($countries))),
97
-                'order_by' => array( 'STA_name'=>'ASC' ),
98
-                'limit' => array( 0, 99999 ),
99
-                'force_join' => array( 'Country' )
95
+            self::$_active_states = $this->get_all(array(
96
+                array('STA_active' => true, 'CNT_ISO' => array('IN', array_keys($countries))),
97
+                'order_by' => array('STA_name'=>'ASC'),
98
+                'limit' => array(0, 99999),
99
+                'force_join' => array('Country')
100 100
             ));
101 101
         }
102 102
         return self::$_active_states;
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
      */
111 111
     public function get_all_states_of_active_countries()
112 112
     {
113
-        if ($states = $this->get_all(array( array( 'Country.CNT_active' => true, 'STA_active' => true ),  'order_by' => array( 'Country.CNT_name' => 'ASC', 'STA_name' => 'ASC' )))) {
113
+        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 114
             return $states;
115 115
         }
116 116
         return false;
@@ -124,10 +124,10 @@  discard block
 block discarded – undo
124 124
      */
125 125
     public function get_all_active_states_for_these_countries($countries)
126 126
     {
127
-        if (! $countries) {
127
+        if ( ! $countries) {
128 128
             return false;
129 129
         }
130
-        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' )))) {
130
+        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 131
             return $states;
132 132
         }
133 133
         return false;
@@ -141,10 +141,10 @@  discard block
 block discarded – undo
141 141
      */
142 142
     public function get_all_states_for_these_countries($countries)
143 143
     {
144
-        if (! $countries) {
144
+        if ( ! $countries) {
145 145
             return false;
146 146
         }
147
-        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' )))) {
147
+        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 148
             return $states;
149 149
         }
150 150
         return false;
@@ -157,11 +157,11 @@  discard block
 block discarded – undo
157 157
      */
158 158
     public function get_state_name_by_ID($state_ID)
159 159
     {
160
-        if (isset(self::$_all_states[ $state_ID ]) &&
161
-                self::$_all_states[ $state_ID ] instanceof EE_State ) {
162
-            return self::$_all_states[ $state_ID ]->name();
160
+        if (isset(self::$_all_states[$state_ID]) &&
161
+                self::$_all_states[$state_ID] instanceof EE_State) {
162
+            return self::$_all_states[$state_ID]->name();
163 163
         }
164
-        $names = $this->get_col(array( array( 'STA_ID' => $state_ID ), 'limit' => 1), 'STA_name');
164
+        $names = $this->get_col(array(array('STA_ID' => $state_ID), 'limit' => 1), 'STA_name');
165 165
         if (is_array($names) && ! empty($names)) {
166 166
             return reset($names);
167 167
         } else {
Please login to merge, or discard this patch.
core/db_models/EEM_Ticket_Template.model.php 2 patches
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -13,40 +13,40 @@
 block discarded – undo
13 13
 
14 14
 
15 15
 
16
-    // private instance of the EEM_Ticket_Template object
17
-    protected static $_instance = null;
16
+	// private instance of the EEM_Ticket_Template object
17
+	protected static $_instance = null;
18 18
 
19
-    /**
20
-     *      private constructor to prevent direct creation
21
-     *      @Constructor
22
-     *      @access private
23
-     *      @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)
24
-     *      @return void
25
-     */
26
-    protected function __construct($timezone)
27
-    {
28
-        $this->singular_item = __('Ticket Template', 'event_espresso');
29
-        $this->plural_item = __('Ticket Templates', 'event_espresso');
19
+	/**
20
+	 *      private constructor to prevent direct creation
21
+	 *      @Constructor
22
+	 *      @access private
23
+	 *      @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)
24
+	 *      @return void
25
+	 */
26
+	protected function __construct($timezone)
27
+	{
28
+		$this->singular_item = __('Ticket Template', 'event_espresso');
29
+		$this->plural_item = __('Ticket Templates', 'event_espresso');
30 30
 
31
-        $this->_tables = array(
32
-            'Ticket_Template'=> new EE_Primary_Table('esp_ticket_template', 'TTM_ID')
33
-        );
34
-        $this->_fields = array(
35
-            'Ticket_Template'=>array(
36
-                'TTM_ID'=>new EE_Primary_Key_Int_Field('TTM_ID', __('Ticket Template ID', 'event_espresso')),
37
-                'TTM_name'=>new EE_Plain_Text_Field('TTM_name', __('The name of the ticket template', 'event_espresso'), false, ''),
38
-                'TTM_description'=>new EE_Plain_Text_Field('TTM_description', __('The description for the ticket template', 'event_espresso'), true, ''),
39
-                'TTM_file'=>new EE_Plain_Text_Field('TTM_file', __('The file name for the actual template file saved on disk', 'event_espresso'), true, ''),
40
-            ));
41
-        $this->_model_relations = array(
42
-            'Ticket'=>new EE_Has_Many_Relation()
43
-        );
44
-        $this->_model_chain_to_wp_user = 'Ticket';
45
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
46
-        // account for default tickets in the caps
47
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
48
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
49
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
50
-        parent::__construct($timezone);
51
-    }
31
+		$this->_tables = array(
32
+			'Ticket_Template'=> new EE_Primary_Table('esp_ticket_template', 'TTM_ID')
33
+		);
34
+		$this->_fields = array(
35
+			'Ticket_Template'=>array(
36
+				'TTM_ID'=>new EE_Primary_Key_Int_Field('TTM_ID', __('Ticket Template ID', 'event_espresso')),
37
+				'TTM_name'=>new EE_Plain_Text_Field('TTM_name', __('The name of the ticket template', 'event_espresso'), false, ''),
38
+				'TTM_description'=>new EE_Plain_Text_Field('TTM_description', __('The description for the ticket template', 'event_espresso'), true, ''),
39
+				'TTM_file'=>new EE_Plain_Text_Field('TTM_file', __('The file name for the actual template file saved on disk', 'event_espresso'), true, ''),
40
+			));
41
+		$this->_model_relations = array(
42
+			'Ticket'=>new EE_Has_Many_Relation()
43
+		);
44
+		$this->_model_chain_to_wp_user = 'Ticket';
45
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
46
+		// account for default tickets in the caps
47
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
48
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
49
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
50
+		parent::__construct($timezone);
51
+	}
52 52
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -42,11 +42,11 @@
 block discarded – undo
42 42
             'Ticket'=>new EE_Has_Many_Relation()
43 43
         );
44 44
         $this->_model_chain_to_wp_user = 'Ticket';
45
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
45
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
46 46
         // account for default tickets in the caps
47
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
48
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
49
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
47
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
48
+        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
49
+        $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
50 50
         parent::__construct($timezone);
51 51
     }
52 52
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Message.model.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
             self::priority_low    => __('low', 'event_espresso'),
125 125
         );
126 126
 
127
-        $this->_fields          = array(
127
+        $this->_fields = array(
128 128
             'Message' => array(
129 129
                 'MSG_ID'             => new EE_Primary_Key_Int_Field('MSG_ID', __('Message ID', 'event_espresso')),
130 130
                 'MSG_token'          => new EE_Plain_Text_Field(
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
                         );
425 425
                         break;
426 426
                     default:
427
-                        $query_params[0]['AND**filter_by'][ 'OR**filter_by_' . $request_key ][ $model_name . '.' . $request_key ] = $request_value;
427
+                        $query_params[0]['AND**filter_by']['OR**filter_by_'.$request_key][$model_name.'.'.$request_key] = $request_value;
428 428
                         break;
429 429
                 }
430 430
             }
@@ -485,8 +485,8 @@  discard block
 block discarded – undo
485 485
         if ($label_parts) {
486 486
             // prepend to the last element of $label_parts an "and".
487 487
             if (count($label_parts) > 1) {
488
-                $label_parts_index_to_prepend               = count($label_parts) - 1;
489
-                $label_parts[ $label_parts_index_to_prepend ] = 'and' . $label_parts[ $label_parts_index_to_prepend ];
488
+                $label_parts_index_to_prepend = count($label_parts) - 1;
489
+                $label_parts[$label_parts_index_to_prepend] = 'and'.$label_parts[$label_parts_index_to_prepend];
490 490
             }
491 491
 
492 492
             $pretty_label .= sprintf(
@@ -546,7 +546,7 @@  discard block
 block discarded – undo
546 546
             $is_debugging = defined('EE_DEBUG_MESSAGES') && EE_DEBUG_MESSAGES;
547 547
         }
548 548
 
549
-        if (! is_null($set_debug)) {
549
+        if ( ! is_null($set_debug)) {
550 550
             $is_debugging = filter_var($set_debug, FILTER_VALIDATE_BOOLEAN);
551 551
         }
552 552
 
@@ -606,13 +606,13 @@  discard block
 block discarded – undo
606 606
             )
607 607
         );
608 608
 
609
-        if (! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) {
609
+        if ( ! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) {
610 610
             global $wpdb;
611 611
             $number_deleted = $wpdb->query('
612 612
                 DELETE
613
-                FROM ' . $this->table() . '
613
+                FROM ' . $this->table().'
614 614
                 WHERE
615
-                    MSG_ID IN (' . implode(",", $message_ids_to_delete) . ')
615
+                    MSG_ID IN (' . implode(",", $message_ids_to_delete).')
616 616
             ');
617 617
         }
618 618
 
Please login to merge, or discard this patch.
Indentation   +617 added lines, -617 removed lines patch added patch discarded remove patch
@@ -9,628 +9,628 @@
 block discarded – undo
9 9
 class EEM_Message extends EEM_Base implements EEI_Query_Filter
10 10
 {
11 11
 
12
-    // private instance of the Message object
13
-    protected static $_instance = null;
12
+	// private instance of the Message object
13
+	protected static $_instance = null;
14 14
 
15 15
 
16
-    /**
17
-     * This priority indicates a message should be generated and sent ASAP
18
-     *
19
-     * @type int
20
-     */
21
-    const priority_high = 10;
22
-
23
-
24
-    /**
25
-     * This priority indicates a message should be generated ASAP and queued for sending.
26
-     *
27
-     * @type
28
-     */
29
-    const priority_medium = 20;
30
-
31
-
32
-    /**
33
-     * This priority indicates a message should be queued for generating.
34
-     *
35
-     * @type int
36
-     */
37
-    const priority_low = 30;
38
-
39
-
40
-    /**
41
-     * indicates this message was sent at the time modified
42
-     */
43
-    const status_sent = 'MSN';
44
-
45
-
46
-    /**
47
-     * indicates this message is waiting to be sent
48
-     */
49
-    const status_idle = 'MID';
50
-
51
-
52
-    /**
53
-     * indicates an attempt was a made to send this message
54
-     * at the scheduled time, but it failed at the time modified.  This differs from MDO status in that it will ALWAYS
55
-     * appear to the end user.
56
-     */
57
-    const status_failed = 'MFL';
58
-
59
-
60
-    /**
61
-     * indicates the message has been flagged for resending (at the time modified).
62
-     */
63
-    const status_resend = 'MRS';
64
-
65
-
66
-    /**
67
-     * indicates the message has been flagged for generation but has not been generated yet.  Messages always start as
68
-     * this status when added to the queue.
69
-     */
70
-    const status_incomplete = 'MIC';
71
-
72
-
73
-    /**
74
-     * Indicates everything was generated fine for the message, however, the messenger was unable to send.
75
-     * This status means that its possible to retry sending the message.
76
-     */
77
-    const status_retry = 'MRT';
78
-
79
-
80
-    /**
81
-     * This is used for more informational messages that may not indicate anything is broken but still cannot be
82
-     * generated or sent correctly. An example of a message that would get flagged this way would be when a not
83
-     * approved message was queued for generation, but at time of generation, the attached registration(s) are
84
-     * approved. So the message queued for generation is no longer valid.  Messages for this status will only persist
85
-     * in the db and be viewable in the message activity list table when the messages system is in debug mode.
86
-     *
87
-     * @see EEM_Message::debug()
88
-     */
89
-    const status_debug_only = 'MDO';
90
-
91
-
92
-    /**
93
-     * This status is given to messages it is processed by the messenger send method.
94
-     * Messages with this status should rarely be seen in the Message List table, but if they are, that's usually
95
-     * indicative of a PHP timeout or memory limit issue.
96
-     */
97
-    const status_messenger_executing = 'MEX';
98
-
99
-
100
-    /**
101
-     *    Private constructor to prevent direct creation.
102
-     *
103
-     * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and
104
-     *                         any incoming timezone data that gets saved).  Note this just sends the timezone info to
105
-     *                         the date time model field objects.  Default is null (and will be assumed using the set
106
-     *                         timezone in the 'timezone_string' wp option)
107
-     * @return EEM_Message
108
-     */
109
-    protected function __construct($timezone = null)
110
-    {
111
-        $this->singular_item = __('Message', 'event_espresso');
112
-        $this->plural_item   = __('Messages', 'event_espresso');
113
-
114
-        // used for token generator
115
-        EE_Registry::instance()->load_helper('URL');
116
-
117
-        $this->_tables = array(
118
-            'Message' => new EE_Primary_Table('esp_message', 'MSG_ID'),
119
-        );
120
-
121
-        $allowed_priority = array(
122
-            self::priority_high   => __('high', 'event_espresso'),
123
-            self::priority_medium => __('medium', 'event_espresso'),
124
-            self::priority_low    => __('low', 'event_espresso'),
125
-        );
126
-
127
-        $this->_fields          = array(
128
-            'Message' => array(
129
-                'MSG_ID'             => new EE_Primary_Key_Int_Field('MSG_ID', __('Message ID', 'event_espresso')),
130
-                'MSG_token'          => new EE_Plain_Text_Field(
131
-                    'MSG_token',
132
-                    __(
133
-                        'Unique Token used to represent this row in publicly viewable contexts (eg. a url).',
134
-                        'event_espresso'
135
-                    ),
136
-                    false,
137
-                    EEH_URL::generate_unique_token()
138
-                ),
139
-                'GRP_ID'             => new EE_Foreign_Key_Int_Field(
140
-                    'GRP_ID',
141
-                    __('Foreign key to the EEM_Message_Template_Group table.', 'event_espresso'),
142
-                    true,
143
-                    0,
144
-                    'Message_Template_Group'
145
-                ),
146
-                'TXN_ID'             => new EE_Foreign_Key_Int_Field(
147
-                    'TXN_ID',
148
-                    __(
149
-                        'Foreign key to the related EE_Transaction.  This is required to give context for regenerating the specific message',
150
-                        'event_espresso'
151
-                    ),
152
-                    true,
153
-                    0,
154
-                    'Transaction'
155
-                ),
156
-                'MSG_messenger'      => new EE_Plain_Text_Field(
157
-                    'MSG_messenger',
158
-                    __(
159
-                        'Corresponds to the EE_messenger::name used to send this message. This will also be used to attempt any resending of the message.',
160
-                        'event_espresso'
161
-                    ),
162
-                    false,
163
-                    'email'
164
-                ),
165
-                'MSG_message_type'   => new EE_Plain_Text_Field(
166
-                    'MSG_message_type',
167
-                    __('Corresponds to the EE_message_type::name used to generate this message.', 'event_espresso'),
168
-                    false,
169
-                    'receipt'
170
-                ),
171
-                'MSG_context'        => new EE_Plain_Text_Field('MSG_context', __('Context', 'event_espresso'), false),
172
-                'MSG_recipient_ID'   => new EE_Foreign_Key_Int_Field(
173
-                    'MSG_recipient_ID',
174
-                    __('Recipient ID', 'event_espresso'),
175
-                    true,
176
-                    null,
177
-                    array('Registration', 'Attendee', 'WP_User')
178
-                ),
179
-                'MSG_recipient_type' => new EE_Any_Foreign_Model_Name_Field(
180
-                    'MSG_recipient_type',
181
-                    __('Recipient Type', 'event_espresso'),
182
-                    true,
183
-                    null,
184
-                    array('Registration', 'Attendee', 'WP_User')
185
-                ),
186
-                'MSG_content'        => new EE_Maybe_Serialized_Text_Field(
187
-                    'MSG_content',
188
-                    __('Content', 'event_espresso'),
189
-                    true,
190
-                    ''
191
-                ),
192
-                'MSG_to'             => new EE_Maybe_Serialized_Text_Field(
193
-                    'MSG_to',
194
-                    __('Address To', 'event_espresso'),
195
-                    true
196
-                ),
197
-                'MSG_from'           => new EE_Maybe_Serialized_Text_Field(
198
-                    'MSG_from',
199
-                    __('Address From', 'event_espresso'),
200
-                    true
201
-                ),
202
-                'MSG_subject'        => new EE_Maybe_Serialized_Text_Field(
203
-                    'MSG_subject',
204
-                    __('Subject', 'event_espresso'),
205
-                    true,
206
-                    ''
207
-                ),
208
-                'MSG_priority'       => new EE_Enum_Integer_Field(
209
-                    'MSG_priority',
210
-                    __('Priority', 'event_espresso'),
211
-                    false,
212
-                    self::priority_low,
213
-                    $allowed_priority
214
-                ),
215
-                'STS_ID'             => new EE_Foreign_Key_String_Field(
216
-                    'STS_ID',
217
-                    __('Status', 'event_espresso'),
218
-                    false,
219
-                    self::status_incomplete,
220
-                    'Status'
221
-                ),
222
-                'MSG_created'        => new EE_Datetime_Field(
223
-                    'MSG_created',
224
-                    __('Created', 'event_espresso'),
225
-                    false,
226
-                    EE_Datetime_Field::now
227
-                ),
228
-                'MSG_modified'       => new EE_Datetime_Field(
229
-                    'MSG_modified',
230
-                    __('Modified', 'event_espresso'),
231
-                    true,
232
-                    EE_Datetime_Field::now
233
-                ),
234
-            ),
235
-        );
236
-        $this->_model_relations = array(
237
-            'Attendee'               => new EE_Belongs_To_Any_Relation(),
238
-            'Registration'           => new EE_Belongs_To_Any_Relation(),
239
-            'WP_User'                => new EE_Belongs_To_Any_Relation(),
240
-            'Message_Template_Group' => new EE_Belongs_To_Relation(),
241
-            'Transaction'            => new EE_Belongs_To_Relation(),
242
-        );
243
-        parent::__construct($timezone);
244
-    }
245
-
246
-
247
-    /**
248
-     * @return \EE_Message
249
-     */
250
-    public function create_default_object()
251
-    {
252
-        /** @type EE_Message $message */
253
-        $message = parent::create_default_object();
254
-        if ($message instanceof EE_Message) {
255
-            return EE_Message_Factory::set_messenger_and_message_type($message);
256
-        }
257
-        return null;
258
-    }
259
-
260
-
261
-    /**
262
-     * @param mixed $cols_n_values
263
-     * @return \EE_Message
264
-     */
265
-    public function instantiate_class_from_array_or_object($cols_n_values)
266
-    {
267
-        /** @type EE_Message $message */
268
-        $message = parent::instantiate_class_from_array_or_object($cols_n_values);
269
-        if ($message instanceof EE_Message) {
270
-            return EE_Message_Factory::set_messenger_and_message_type($message);
271
-        }
272
-        return null;
273
-    }
274
-
275
-
276
-    /**
277
-     * Returns whether or not a message of that type was sent for a given attendee.
278
-     *
279
-     * @param EE_Attendee|int $attendee
280
-     * @param string          $message_type the message type slug
281
-     * @return boolean
282
-     */
283
-    public function message_sent_for_attendee($attendee, $message_type)
284
-    {
285
-        $attendee_ID = EEM_Attendee::instance()->ensure_is_ID($attendee);
286
-        return $this->exists(array(
287
-            array(
288
-                'Attendee.ATT_ID'  => $attendee_ID,
289
-                'MSG_message_type' => $message_type,
290
-                'STS_ID'           => array('IN', $this->stati_indicating_sent()),
291
-            ),
292
-        ));
293
-    }
294
-
295
-
296
-    /**
297
-     * Returns whether or not a message of that type was sent for a given registration
298
-     *
299
-     * @param EE_Registration|int $registration
300
-     * @param string              $message_type the message type slug
301
-     * @return boolean
302
-     */
303
-    public function message_sent_for_registration($registration, $message_type)
304
-    {
305
-        $registrationID = EEM_Registration::instance()->ensure_is_ID($registration);
306
-        return $this->exists(array(
307
-            array(
308
-                'Registration.REG_ID' => $registrationID,
309
-                'MSG_message_type'    => $message_type,
310
-                'STS_ID'              => array('IN', $this->stati_indicating_sent()),
311
-            ),
312
-        ));
313
-    }
314
-
315
-
316
-    /**
317
-     * This retrieves an EE_Message object from the db matching the given token string.
318
-     *
319
-     * @param string $token
320
-     * @return EE_Message
321
-     */
322
-    public function get_one_by_token($token)
323
-    {
324
-        return $this->get_one(array(
325
-            array(
326
-                'MSG_token' => $token,
327
-            ),
328
-        ));
329
-    }
330
-
331
-
332
-    /**
333
-     * Returns stati that indicate the message HAS been sent
334
-     *
335
-     * @return array of strings for possible stati
336
-     */
337
-    public function stati_indicating_sent()
338
-    {
339
-        return apply_filters('FHEE__EEM_Message__stati_indicating_sent', array(self::status_sent));
340
-    }
341
-
342
-
343
-    /**
344
-     * Returns stati that indicate the message is waiting to be sent.
345
-     *
346
-     * @return array of strings for possible stati.
347
-     */
348
-    public function stati_indicating_to_send()
349
-    {
350
-        return apply_filters(
351
-            'FHEE__EEM_Message__stati_indicating_to_send',
352
-            array(self::status_idle, self::status_resend)
353
-        );
354
-    }
355
-
356
-
357
-    /**
358
-     * Returns stati that indicate the message has failed sending
359
-     *
360
-     * @return array  array of strings for possible stati.
361
-     */
362
-    public function stati_indicating_failed_sending()
363
-    {
364
-        $failed_stati = array(
365
-            self::status_failed,
366
-            self::status_retry,
367
-            self::status_messenger_executing,
368
-        );
369
-        // if WP_DEBUG is set, then let's include debug_only fails
370
-        if (WP_DEBUG) {
371
-            $failed_stati[] = self::status_debug_only;
372
-        }
373
-        return apply_filters('FHEE__EEM_Message__stati_indicating_failed_sending', $failed_stati);
374
-    }
375
-
376
-
377
-    /**
378
-     * Returns filterable array of all EEM_Message statuses.
379
-     *
380
-     * @return array
381
-     */
382
-    public function all_statuses()
383
-    {
384
-        return apply_filters(
385
-            'FHEE__EEM_Message__all_statuses',
386
-            array(
387
-                EEM_Message::status_sent,
388
-                EEM_Message::status_incomplete,
389
-                EEM_Message::status_idle,
390
-                EEM_Message::status_resend,
391
-                EEM_Message::status_retry,
392
-                EEM_Message::status_failed,
393
-                EEM_Message::status_messenger_executing,
394
-                EEM_Message::status_debug_only,
395
-            )
396
-        );
397
-    }
398
-
399
-    /**
400
-     * Detects any specific query variables in the request and uses those to setup appropriate
401
-     * filter for any queries.
402
-     *
403
-     * @return array
404
-     */
405
-    public function filter_by_query_params()
406
-    {
407
-        // expected possible query_vars, the key in this array matches an expected key in the request,
408
-        // the value, matches the corresponding EEM_Base child reference.
409
-        $expected_vars   = $this->_expected_vars_for_query_inject();
410
-        $query_params[0] = array();
411
-        foreach ($expected_vars as $request_key => $model_name) {
412
-            $request_value = EE_Registry::instance()->REQ->get($request_key);
413
-            if ($request_value) {
414
-                // special case
415
-                switch ($request_key) {
416
-                    case '_REG_ID':
417
-                        $query_params[0]['AND**filter_by']['OR**filter_by_REG_ID'] = array(
418
-                            'Transaction.Registration.REG_ID' => $request_value,
419
-                        );
420
-                        break;
421
-                    case 'EVT_ID':
422
-                        $query_params[0]['AND**filter_by']['OR**filter_by_EVT_ID'] = array(
423
-                            'Transaction.Registration.EVT_ID' => $request_value,
424
-                        );
425
-                        break;
426
-                    default:
427
-                        $query_params[0]['AND**filter_by'][ 'OR**filter_by_' . $request_key ][ $model_name . '.' . $request_key ] = $request_value;
428
-                        break;
429
-                }
430
-            }
431
-        }
432
-        return $query_params;
433
-    }
434
-
435
-
436
-    /**
437
-     * @return string
438
-     */
439
-    public function get_pretty_label_for_results()
440
-    {
441
-        $expected_vars = $this->_expected_vars_for_query_inject();
442
-        $pretty_label  = '';
443
-        $label_parts   = array();
444
-        foreach ($expected_vars as $request_key => $model_name) {
445
-            $model = EE_Registry::instance()->load_model($model_name);
446
-            if ($model_field_value = EE_Registry::instance()->REQ->get($request_key)) {
447
-                switch ($request_key) {
448
-                    case '_REG_ID':
449
-                        $label_parts[] = sprintf(
450
-                            esc_html__('Registration with the ID: %s', 'event_espresso'),
451
-                            $model_field_value
452
-                        );
453
-                        break;
454
-                    case 'ATT_ID':
455
-                        /** @var EE_Attendee $attendee */
456
-                        $attendee      = $model->get_one_by_ID($model_field_value);
457
-                        $label_parts[] = $attendee instanceof EE_Attendee
458
-                            ? sprintf(esc_html__('Attendee %s', 'event_espresso'), $attendee->full_name())
459
-                            : sprintf(esc_html__('Attendee ID: %s', 'event_espresso'), $model_field_value);
460
-                        break;
461
-                    case 'ID':
462
-                        /** @var EE_WP_User $wpUser */
463
-                        $wpUser        = $model->get_one_by_ID($model_field_value);
464
-                        $label_parts[] = $wpUser instanceof EE_WP_User
465
-                            ? sprintf(esc_html__('WP User: %s', 'event_espresso'), $wpUser->name())
466
-                            : sprintf(esc_html__('WP User ID: %s', 'event_espresso'), $model_field_value);
467
-                        break;
468
-                    case 'TXN_ID':
469
-                        $label_parts[] = sprintf(
470
-                            esc_html__('Transaction with the ID: %s', 'event_espresso'),
471
-                            $model_field_value
472
-                        );
473
-                        break;
474
-                    case 'EVT_ID':
475
-                        /** @var EE_Event $Event */
476
-                        $Event         = $model->get_one_by_ID($model_field_value);
477
-                        $label_parts[] = $Event instanceof EE_Event
478
-                            ? sprintf(esc_html__('for the Event: %s', 'event_espresso'), $Event->name())
479
-                            : sprintf(esc_html__('for the Event with ID: %s', 'event_espresso'), $model_field_value);
480
-                        break;
481
-                }
482
-            }
483
-        }
484
-
485
-        if ($label_parts) {
486
-            // prepend to the last element of $label_parts an "and".
487
-            if (count($label_parts) > 1) {
488
-                $label_parts_index_to_prepend               = count($label_parts) - 1;
489
-                $label_parts[ $label_parts_index_to_prepend ] = 'and' . $label_parts[ $label_parts_index_to_prepend ];
490
-            }
491
-
492
-            $pretty_label .= sprintf(
493
-                esc_html_x(
494
-                    'Showing messages for %s',
495
-                    'A label for the messages returned in a query that are filtered by items in the query. This could be Transaction, Event, Attendee, Registration, or WP_User.',
496
-                    'event_espresso'
497
-                ),
498
-                implode(', ', $label_parts)
499
-            );
500
-        }
501
-        return $pretty_label;
502
-    }
503
-
504
-
505
-    /**
506
-     * This returns the array of expected variables for the EEI_Query_Filter methods being implemented
507
-     * The array is in the format:
508
-     * array(
509
-     *  {$field_name} => {$model_name}
510
-     * );
511
-     *
512
-     * @since 4.9.0
513
-     * @return array
514
-     */
515
-    protected function _expected_vars_for_query_inject()
516
-    {
517
-        return array(
518
-            '_REG_ID' => 'Registration',
519
-            'ATT_ID'  => 'Attendee',
520
-            'ID'      => 'WP_User',
521
-            'TXN_ID'  => 'Transaction',
522
-            'EVT_ID'  => 'Event',
523
-        );
524
-    }
525
-
526
-
527
-    /**
528
-     * This returns whether EEM_Message is in debug mode or not.
529
-     * Currently "debug mode" is used to control the handling of the EEM_Message::debug_only status when
530
-     * generating/sending messages. Debug mode can be set by either:
531
-     * 1. Sending in a value for the $set_debug argument
532
-     * 2. Defining `EE_DEBUG_MESSAGES` constant in wp-config.php
533
-     * 3. Overriding the above via the provided filter.
534
-     *
535
-     * @param bool|null $set_debug      If provided, then the debug mode will be set internally until reset via the
536
-     *                                  provided boolean. When no argument is provided (default null) then the debug
537
-     *                                  mode will be returned.
538
-     * @return bool         true means Messages is in debug mode.  false means messages system is not in debug mode.
539
-     */
540
-    public static function debug($set_debug = null)
541
-    {
542
-        static $is_debugging = null;
543
-
544
-        // initialize (use constant if set).
545
-        if (is_null($set_debug) && is_null($is_debugging)) {
546
-            $is_debugging = defined('EE_DEBUG_MESSAGES') && EE_DEBUG_MESSAGES;
547
-        }
548
-
549
-        if (! is_null($set_debug)) {
550
-            $is_debugging = filter_var($set_debug, FILTER_VALIDATE_BOOLEAN);
551
-        }
552
-
553
-        // return filtered value
554
-        return apply_filters('FHEE__EEM_Message__debug', $is_debugging);
555
-    }
556
-
557
-
558
-    /**
559
-     * Deletes old messages meeting certain criteria for removal from the database.
560
-     * By default, this will delete messages that:
561
-     * - are older than the value of the delete_threshold in months.
562
-     * - have a STS_ID other than EEM_Message::status_idle
563
-     *
564
-     * @param int $delete_threshold  This integer will be used to set the boundary for what messages are deleted in months.
565
-     * @return bool|false|int Either the number of records affected or false if there was an error (you can call
566
-     *                         $wpdb->last_error to find out what the error was.
567
-     */
568
-    public function delete_old_messages($delete_threshold = 6)
569
-    {
570
-        $number_deleted = 0;
571
-        /**
572
-         * Allows code to change the boundary for what messages are kept.
573
-         * Uses the value of the `delete_threshold` variable by default.
574
-         *
575
-         * @param int $seconds seconds that will be subtracted from the timestamp for now.
576
-         * @return int
577
-         */
578
-        $time_to_leave_alone = absint(
579
-            apply_filters(
580
-                'FHEE__EEM_Message__delete_old_messages__time_to_leave_alone',
581
-                ((int) $delete_threshold) * MONTH_IN_SECONDS
582
-            )
583
-        );
584
-
585
-
586
-        /**
587
-         * Allows code to change what message stati are ignored when deleting.
588
-         * Defaults to only ignore EEM_Message::status_idle messages.
589
-         *
590
-         * @param string $message_stati_to_keep  An array of message statuses that will be ignored when deleting.
591
-         */
592
-        $message_stati_to_keep = (array) apply_filters(
593
-            'FHEE__EEM_Message__delete_old_messages__message_stati_to_keep',
594
-            array(
595
-                EEM_Message::status_idle
596
-            )
597
-        );
598
-
599
-        // first get all the ids of messages being deleted
600
-        $message_ids_to_delete = EEM_Message::instance()->get_col(
601
-            array(
602
-                0 => array(
603
-                    'STS_ID' => array('NOT_IN', $message_stati_to_keep),
604
-                    'MSG_modified' => array('<', time() - $time_to_leave_alone)
605
-                ),
606
-                'limit' => apply_filters(
607
-                    'EEM_Message__delete_old_messages__limit',
608
-                    2000,
609
-                    $delete_threshold
610
-                )
611
-            )
612
-        );
613
-
614
-        if (! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) {
615
-            global $wpdb;
616
-            $number_deleted = $wpdb->query('
16
+	/**
17
+	 * This priority indicates a message should be generated and sent ASAP
18
+	 *
19
+	 * @type int
20
+	 */
21
+	const priority_high = 10;
22
+
23
+
24
+	/**
25
+	 * This priority indicates a message should be generated ASAP and queued for sending.
26
+	 *
27
+	 * @type
28
+	 */
29
+	const priority_medium = 20;
30
+
31
+
32
+	/**
33
+	 * This priority indicates a message should be queued for generating.
34
+	 *
35
+	 * @type int
36
+	 */
37
+	const priority_low = 30;
38
+
39
+
40
+	/**
41
+	 * indicates this message was sent at the time modified
42
+	 */
43
+	const status_sent = 'MSN';
44
+
45
+
46
+	/**
47
+	 * indicates this message is waiting to be sent
48
+	 */
49
+	const status_idle = 'MID';
50
+
51
+
52
+	/**
53
+	 * indicates an attempt was a made to send this message
54
+	 * at the scheduled time, but it failed at the time modified.  This differs from MDO status in that it will ALWAYS
55
+	 * appear to the end user.
56
+	 */
57
+	const status_failed = 'MFL';
58
+
59
+
60
+	/**
61
+	 * indicates the message has been flagged for resending (at the time modified).
62
+	 */
63
+	const status_resend = 'MRS';
64
+
65
+
66
+	/**
67
+	 * indicates the message has been flagged for generation but has not been generated yet.  Messages always start as
68
+	 * this status when added to the queue.
69
+	 */
70
+	const status_incomplete = 'MIC';
71
+
72
+
73
+	/**
74
+	 * Indicates everything was generated fine for the message, however, the messenger was unable to send.
75
+	 * This status means that its possible to retry sending the message.
76
+	 */
77
+	const status_retry = 'MRT';
78
+
79
+
80
+	/**
81
+	 * This is used for more informational messages that may not indicate anything is broken but still cannot be
82
+	 * generated or sent correctly. An example of a message that would get flagged this way would be when a not
83
+	 * approved message was queued for generation, but at time of generation, the attached registration(s) are
84
+	 * approved. So the message queued for generation is no longer valid.  Messages for this status will only persist
85
+	 * in the db and be viewable in the message activity list table when the messages system is in debug mode.
86
+	 *
87
+	 * @see EEM_Message::debug()
88
+	 */
89
+	const status_debug_only = 'MDO';
90
+
91
+
92
+	/**
93
+	 * This status is given to messages it is processed by the messenger send method.
94
+	 * Messages with this status should rarely be seen in the Message List table, but if they are, that's usually
95
+	 * indicative of a PHP timeout or memory limit issue.
96
+	 */
97
+	const status_messenger_executing = 'MEX';
98
+
99
+
100
+	/**
101
+	 *    Private constructor to prevent direct creation.
102
+	 *
103
+	 * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and
104
+	 *                         any incoming timezone data that gets saved).  Note this just sends the timezone info to
105
+	 *                         the date time model field objects.  Default is null (and will be assumed using the set
106
+	 *                         timezone in the 'timezone_string' wp option)
107
+	 * @return EEM_Message
108
+	 */
109
+	protected function __construct($timezone = null)
110
+	{
111
+		$this->singular_item = __('Message', 'event_espresso');
112
+		$this->plural_item   = __('Messages', 'event_espresso');
113
+
114
+		// used for token generator
115
+		EE_Registry::instance()->load_helper('URL');
116
+
117
+		$this->_tables = array(
118
+			'Message' => new EE_Primary_Table('esp_message', 'MSG_ID'),
119
+		);
120
+
121
+		$allowed_priority = array(
122
+			self::priority_high   => __('high', 'event_espresso'),
123
+			self::priority_medium => __('medium', 'event_espresso'),
124
+			self::priority_low    => __('low', 'event_espresso'),
125
+		);
126
+
127
+		$this->_fields          = array(
128
+			'Message' => array(
129
+				'MSG_ID'             => new EE_Primary_Key_Int_Field('MSG_ID', __('Message ID', 'event_espresso')),
130
+				'MSG_token'          => new EE_Plain_Text_Field(
131
+					'MSG_token',
132
+					__(
133
+						'Unique Token used to represent this row in publicly viewable contexts (eg. a url).',
134
+						'event_espresso'
135
+					),
136
+					false,
137
+					EEH_URL::generate_unique_token()
138
+				),
139
+				'GRP_ID'             => new EE_Foreign_Key_Int_Field(
140
+					'GRP_ID',
141
+					__('Foreign key to the EEM_Message_Template_Group table.', 'event_espresso'),
142
+					true,
143
+					0,
144
+					'Message_Template_Group'
145
+				),
146
+				'TXN_ID'             => new EE_Foreign_Key_Int_Field(
147
+					'TXN_ID',
148
+					__(
149
+						'Foreign key to the related EE_Transaction.  This is required to give context for regenerating the specific message',
150
+						'event_espresso'
151
+					),
152
+					true,
153
+					0,
154
+					'Transaction'
155
+				),
156
+				'MSG_messenger'      => new EE_Plain_Text_Field(
157
+					'MSG_messenger',
158
+					__(
159
+						'Corresponds to the EE_messenger::name used to send this message. This will also be used to attempt any resending of the message.',
160
+						'event_espresso'
161
+					),
162
+					false,
163
+					'email'
164
+				),
165
+				'MSG_message_type'   => new EE_Plain_Text_Field(
166
+					'MSG_message_type',
167
+					__('Corresponds to the EE_message_type::name used to generate this message.', 'event_espresso'),
168
+					false,
169
+					'receipt'
170
+				),
171
+				'MSG_context'        => new EE_Plain_Text_Field('MSG_context', __('Context', 'event_espresso'), false),
172
+				'MSG_recipient_ID'   => new EE_Foreign_Key_Int_Field(
173
+					'MSG_recipient_ID',
174
+					__('Recipient ID', 'event_espresso'),
175
+					true,
176
+					null,
177
+					array('Registration', 'Attendee', 'WP_User')
178
+				),
179
+				'MSG_recipient_type' => new EE_Any_Foreign_Model_Name_Field(
180
+					'MSG_recipient_type',
181
+					__('Recipient Type', 'event_espresso'),
182
+					true,
183
+					null,
184
+					array('Registration', 'Attendee', 'WP_User')
185
+				),
186
+				'MSG_content'        => new EE_Maybe_Serialized_Text_Field(
187
+					'MSG_content',
188
+					__('Content', 'event_espresso'),
189
+					true,
190
+					''
191
+				),
192
+				'MSG_to'             => new EE_Maybe_Serialized_Text_Field(
193
+					'MSG_to',
194
+					__('Address To', 'event_espresso'),
195
+					true
196
+				),
197
+				'MSG_from'           => new EE_Maybe_Serialized_Text_Field(
198
+					'MSG_from',
199
+					__('Address From', 'event_espresso'),
200
+					true
201
+				),
202
+				'MSG_subject'        => new EE_Maybe_Serialized_Text_Field(
203
+					'MSG_subject',
204
+					__('Subject', 'event_espresso'),
205
+					true,
206
+					''
207
+				),
208
+				'MSG_priority'       => new EE_Enum_Integer_Field(
209
+					'MSG_priority',
210
+					__('Priority', 'event_espresso'),
211
+					false,
212
+					self::priority_low,
213
+					$allowed_priority
214
+				),
215
+				'STS_ID'             => new EE_Foreign_Key_String_Field(
216
+					'STS_ID',
217
+					__('Status', 'event_espresso'),
218
+					false,
219
+					self::status_incomplete,
220
+					'Status'
221
+				),
222
+				'MSG_created'        => new EE_Datetime_Field(
223
+					'MSG_created',
224
+					__('Created', 'event_espresso'),
225
+					false,
226
+					EE_Datetime_Field::now
227
+				),
228
+				'MSG_modified'       => new EE_Datetime_Field(
229
+					'MSG_modified',
230
+					__('Modified', 'event_espresso'),
231
+					true,
232
+					EE_Datetime_Field::now
233
+				),
234
+			),
235
+		);
236
+		$this->_model_relations = array(
237
+			'Attendee'               => new EE_Belongs_To_Any_Relation(),
238
+			'Registration'           => new EE_Belongs_To_Any_Relation(),
239
+			'WP_User'                => new EE_Belongs_To_Any_Relation(),
240
+			'Message_Template_Group' => new EE_Belongs_To_Relation(),
241
+			'Transaction'            => new EE_Belongs_To_Relation(),
242
+		);
243
+		parent::__construct($timezone);
244
+	}
245
+
246
+
247
+	/**
248
+	 * @return \EE_Message
249
+	 */
250
+	public function create_default_object()
251
+	{
252
+		/** @type EE_Message $message */
253
+		$message = parent::create_default_object();
254
+		if ($message instanceof EE_Message) {
255
+			return EE_Message_Factory::set_messenger_and_message_type($message);
256
+		}
257
+		return null;
258
+	}
259
+
260
+
261
+	/**
262
+	 * @param mixed $cols_n_values
263
+	 * @return \EE_Message
264
+	 */
265
+	public function instantiate_class_from_array_or_object($cols_n_values)
266
+	{
267
+		/** @type EE_Message $message */
268
+		$message = parent::instantiate_class_from_array_or_object($cols_n_values);
269
+		if ($message instanceof EE_Message) {
270
+			return EE_Message_Factory::set_messenger_and_message_type($message);
271
+		}
272
+		return null;
273
+	}
274
+
275
+
276
+	/**
277
+	 * Returns whether or not a message of that type was sent for a given attendee.
278
+	 *
279
+	 * @param EE_Attendee|int $attendee
280
+	 * @param string          $message_type the message type slug
281
+	 * @return boolean
282
+	 */
283
+	public function message_sent_for_attendee($attendee, $message_type)
284
+	{
285
+		$attendee_ID = EEM_Attendee::instance()->ensure_is_ID($attendee);
286
+		return $this->exists(array(
287
+			array(
288
+				'Attendee.ATT_ID'  => $attendee_ID,
289
+				'MSG_message_type' => $message_type,
290
+				'STS_ID'           => array('IN', $this->stati_indicating_sent()),
291
+			),
292
+		));
293
+	}
294
+
295
+
296
+	/**
297
+	 * Returns whether or not a message of that type was sent for a given registration
298
+	 *
299
+	 * @param EE_Registration|int $registration
300
+	 * @param string              $message_type the message type slug
301
+	 * @return boolean
302
+	 */
303
+	public function message_sent_for_registration($registration, $message_type)
304
+	{
305
+		$registrationID = EEM_Registration::instance()->ensure_is_ID($registration);
306
+		return $this->exists(array(
307
+			array(
308
+				'Registration.REG_ID' => $registrationID,
309
+				'MSG_message_type'    => $message_type,
310
+				'STS_ID'              => array('IN', $this->stati_indicating_sent()),
311
+			),
312
+		));
313
+	}
314
+
315
+
316
+	/**
317
+	 * This retrieves an EE_Message object from the db matching the given token string.
318
+	 *
319
+	 * @param string $token
320
+	 * @return EE_Message
321
+	 */
322
+	public function get_one_by_token($token)
323
+	{
324
+		return $this->get_one(array(
325
+			array(
326
+				'MSG_token' => $token,
327
+			),
328
+		));
329
+	}
330
+
331
+
332
+	/**
333
+	 * Returns stati that indicate the message HAS been sent
334
+	 *
335
+	 * @return array of strings for possible stati
336
+	 */
337
+	public function stati_indicating_sent()
338
+	{
339
+		return apply_filters('FHEE__EEM_Message__stati_indicating_sent', array(self::status_sent));
340
+	}
341
+
342
+
343
+	/**
344
+	 * Returns stati that indicate the message is waiting to be sent.
345
+	 *
346
+	 * @return array of strings for possible stati.
347
+	 */
348
+	public function stati_indicating_to_send()
349
+	{
350
+		return apply_filters(
351
+			'FHEE__EEM_Message__stati_indicating_to_send',
352
+			array(self::status_idle, self::status_resend)
353
+		);
354
+	}
355
+
356
+
357
+	/**
358
+	 * Returns stati that indicate the message has failed sending
359
+	 *
360
+	 * @return array  array of strings for possible stati.
361
+	 */
362
+	public function stati_indicating_failed_sending()
363
+	{
364
+		$failed_stati = array(
365
+			self::status_failed,
366
+			self::status_retry,
367
+			self::status_messenger_executing,
368
+		);
369
+		// if WP_DEBUG is set, then let's include debug_only fails
370
+		if (WP_DEBUG) {
371
+			$failed_stati[] = self::status_debug_only;
372
+		}
373
+		return apply_filters('FHEE__EEM_Message__stati_indicating_failed_sending', $failed_stati);
374
+	}
375
+
376
+
377
+	/**
378
+	 * Returns filterable array of all EEM_Message statuses.
379
+	 *
380
+	 * @return array
381
+	 */
382
+	public function all_statuses()
383
+	{
384
+		return apply_filters(
385
+			'FHEE__EEM_Message__all_statuses',
386
+			array(
387
+				EEM_Message::status_sent,
388
+				EEM_Message::status_incomplete,
389
+				EEM_Message::status_idle,
390
+				EEM_Message::status_resend,
391
+				EEM_Message::status_retry,
392
+				EEM_Message::status_failed,
393
+				EEM_Message::status_messenger_executing,
394
+				EEM_Message::status_debug_only,
395
+			)
396
+		);
397
+	}
398
+
399
+	/**
400
+	 * Detects any specific query variables in the request and uses those to setup appropriate
401
+	 * filter for any queries.
402
+	 *
403
+	 * @return array
404
+	 */
405
+	public function filter_by_query_params()
406
+	{
407
+		// expected possible query_vars, the key in this array matches an expected key in the request,
408
+		// the value, matches the corresponding EEM_Base child reference.
409
+		$expected_vars   = $this->_expected_vars_for_query_inject();
410
+		$query_params[0] = array();
411
+		foreach ($expected_vars as $request_key => $model_name) {
412
+			$request_value = EE_Registry::instance()->REQ->get($request_key);
413
+			if ($request_value) {
414
+				// special case
415
+				switch ($request_key) {
416
+					case '_REG_ID':
417
+						$query_params[0]['AND**filter_by']['OR**filter_by_REG_ID'] = array(
418
+							'Transaction.Registration.REG_ID' => $request_value,
419
+						);
420
+						break;
421
+					case 'EVT_ID':
422
+						$query_params[0]['AND**filter_by']['OR**filter_by_EVT_ID'] = array(
423
+							'Transaction.Registration.EVT_ID' => $request_value,
424
+						);
425
+						break;
426
+					default:
427
+						$query_params[0]['AND**filter_by'][ 'OR**filter_by_' . $request_key ][ $model_name . '.' . $request_key ] = $request_value;
428
+						break;
429
+				}
430
+			}
431
+		}
432
+		return $query_params;
433
+	}
434
+
435
+
436
+	/**
437
+	 * @return string
438
+	 */
439
+	public function get_pretty_label_for_results()
440
+	{
441
+		$expected_vars = $this->_expected_vars_for_query_inject();
442
+		$pretty_label  = '';
443
+		$label_parts   = array();
444
+		foreach ($expected_vars as $request_key => $model_name) {
445
+			$model = EE_Registry::instance()->load_model($model_name);
446
+			if ($model_field_value = EE_Registry::instance()->REQ->get($request_key)) {
447
+				switch ($request_key) {
448
+					case '_REG_ID':
449
+						$label_parts[] = sprintf(
450
+							esc_html__('Registration with the ID: %s', 'event_espresso'),
451
+							$model_field_value
452
+						);
453
+						break;
454
+					case 'ATT_ID':
455
+						/** @var EE_Attendee $attendee */
456
+						$attendee      = $model->get_one_by_ID($model_field_value);
457
+						$label_parts[] = $attendee instanceof EE_Attendee
458
+							? sprintf(esc_html__('Attendee %s', 'event_espresso'), $attendee->full_name())
459
+							: sprintf(esc_html__('Attendee ID: %s', 'event_espresso'), $model_field_value);
460
+						break;
461
+					case 'ID':
462
+						/** @var EE_WP_User $wpUser */
463
+						$wpUser        = $model->get_one_by_ID($model_field_value);
464
+						$label_parts[] = $wpUser instanceof EE_WP_User
465
+							? sprintf(esc_html__('WP User: %s', 'event_espresso'), $wpUser->name())
466
+							: sprintf(esc_html__('WP User ID: %s', 'event_espresso'), $model_field_value);
467
+						break;
468
+					case 'TXN_ID':
469
+						$label_parts[] = sprintf(
470
+							esc_html__('Transaction with the ID: %s', 'event_espresso'),
471
+							$model_field_value
472
+						);
473
+						break;
474
+					case 'EVT_ID':
475
+						/** @var EE_Event $Event */
476
+						$Event         = $model->get_one_by_ID($model_field_value);
477
+						$label_parts[] = $Event instanceof EE_Event
478
+							? sprintf(esc_html__('for the Event: %s', 'event_espresso'), $Event->name())
479
+							: sprintf(esc_html__('for the Event with ID: %s', 'event_espresso'), $model_field_value);
480
+						break;
481
+				}
482
+			}
483
+		}
484
+
485
+		if ($label_parts) {
486
+			// prepend to the last element of $label_parts an "and".
487
+			if (count($label_parts) > 1) {
488
+				$label_parts_index_to_prepend               = count($label_parts) - 1;
489
+				$label_parts[ $label_parts_index_to_prepend ] = 'and' . $label_parts[ $label_parts_index_to_prepend ];
490
+			}
491
+
492
+			$pretty_label .= sprintf(
493
+				esc_html_x(
494
+					'Showing messages for %s',
495
+					'A label for the messages returned in a query that are filtered by items in the query. This could be Transaction, Event, Attendee, Registration, or WP_User.',
496
+					'event_espresso'
497
+				),
498
+				implode(', ', $label_parts)
499
+			);
500
+		}
501
+		return $pretty_label;
502
+	}
503
+
504
+
505
+	/**
506
+	 * This returns the array of expected variables for the EEI_Query_Filter methods being implemented
507
+	 * The array is in the format:
508
+	 * array(
509
+	 *  {$field_name} => {$model_name}
510
+	 * );
511
+	 *
512
+	 * @since 4.9.0
513
+	 * @return array
514
+	 */
515
+	protected function _expected_vars_for_query_inject()
516
+	{
517
+		return array(
518
+			'_REG_ID' => 'Registration',
519
+			'ATT_ID'  => 'Attendee',
520
+			'ID'      => 'WP_User',
521
+			'TXN_ID'  => 'Transaction',
522
+			'EVT_ID'  => 'Event',
523
+		);
524
+	}
525
+
526
+
527
+	/**
528
+	 * This returns whether EEM_Message is in debug mode or not.
529
+	 * Currently "debug mode" is used to control the handling of the EEM_Message::debug_only status when
530
+	 * generating/sending messages. Debug mode can be set by either:
531
+	 * 1. Sending in a value for the $set_debug argument
532
+	 * 2. Defining `EE_DEBUG_MESSAGES` constant in wp-config.php
533
+	 * 3. Overriding the above via the provided filter.
534
+	 *
535
+	 * @param bool|null $set_debug      If provided, then the debug mode will be set internally until reset via the
536
+	 *                                  provided boolean. When no argument is provided (default null) then the debug
537
+	 *                                  mode will be returned.
538
+	 * @return bool         true means Messages is in debug mode.  false means messages system is not in debug mode.
539
+	 */
540
+	public static function debug($set_debug = null)
541
+	{
542
+		static $is_debugging = null;
543
+
544
+		// initialize (use constant if set).
545
+		if (is_null($set_debug) && is_null($is_debugging)) {
546
+			$is_debugging = defined('EE_DEBUG_MESSAGES') && EE_DEBUG_MESSAGES;
547
+		}
548
+
549
+		if (! is_null($set_debug)) {
550
+			$is_debugging = filter_var($set_debug, FILTER_VALIDATE_BOOLEAN);
551
+		}
552
+
553
+		// return filtered value
554
+		return apply_filters('FHEE__EEM_Message__debug', $is_debugging);
555
+	}
556
+
557
+
558
+	/**
559
+	 * Deletes old messages meeting certain criteria for removal from the database.
560
+	 * By default, this will delete messages that:
561
+	 * - are older than the value of the delete_threshold in months.
562
+	 * - have a STS_ID other than EEM_Message::status_idle
563
+	 *
564
+	 * @param int $delete_threshold  This integer will be used to set the boundary for what messages are deleted in months.
565
+	 * @return bool|false|int Either the number of records affected or false if there was an error (you can call
566
+	 *                         $wpdb->last_error to find out what the error was.
567
+	 */
568
+	public function delete_old_messages($delete_threshold = 6)
569
+	{
570
+		$number_deleted = 0;
571
+		/**
572
+		 * Allows code to change the boundary for what messages are kept.
573
+		 * Uses the value of the `delete_threshold` variable by default.
574
+		 *
575
+		 * @param int $seconds seconds that will be subtracted from the timestamp for now.
576
+		 * @return int
577
+		 */
578
+		$time_to_leave_alone = absint(
579
+			apply_filters(
580
+				'FHEE__EEM_Message__delete_old_messages__time_to_leave_alone',
581
+				((int) $delete_threshold) * MONTH_IN_SECONDS
582
+			)
583
+		);
584
+
585
+
586
+		/**
587
+		 * Allows code to change what message stati are ignored when deleting.
588
+		 * Defaults to only ignore EEM_Message::status_idle messages.
589
+		 *
590
+		 * @param string $message_stati_to_keep  An array of message statuses that will be ignored when deleting.
591
+		 */
592
+		$message_stati_to_keep = (array) apply_filters(
593
+			'FHEE__EEM_Message__delete_old_messages__message_stati_to_keep',
594
+			array(
595
+				EEM_Message::status_idle
596
+			)
597
+		);
598
+
599
+		// first get all the ids of messages being deleted
600
+		$message_ids_to_delete = EEM_Message::instance()->get_col(
601
+			array(
602
+				0 => array(
603
+					'STS_ID' => array('NOT_IN', $message_stati_to_keep),
604
+					'MSG_modified' => array('<', time() - $time_to_leave_alone)
605
+				),
606
+				'limit' => apply_filters(
607
+					'EEM_Message__delete_old_messages__limit',
608
+					2000,
609
+					$delete_threshold
610
+				)
611
+			)
612
+		);
613
+
614
+		if (! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) {
615
+			global $wpdb;
616
+			$number_deleted = $wpdb->query('
617 617
                 DELETE
618 618
                 FROM ' . $this->table() . '
619 619
                 WHERE
620 620
                     MSG_ID IN (' . implode(",", $message_ids_to_delete) . ')
621 621
             ');
622
-        }
623
-
624
-        /**
625
-         * This will get called if the number of records deleted 0 or greater.  So a successful deletion is one where
626
-         * there were no errors.  An unsuccessful deletion is where there were errors.  Keep that in mind for the actions
627
-         * below.
628
-         */
629
-        if ($number_deleted !== false) {
630
-            do_action('AHEE__EEM_Message__delete_old_messages__after_successful_deletion', $message_ids_to_delete, $number_deleted);
631
-        } else {
632
-            do_action('AHEE__EEM_Message__delete_old_messages__after_deletion_fail', $message_ids_to_delete, $number_deleted);
633
-        }
634
-        return $number_deleted;
635
-    }
622
+		}
623
+
624
+		/**
625
+		 * This will get called if the number of records deleted 0 or greater.  So a successful deletion is one where
626
+		 * there were no errors.  An unsuccessful deletion is where there were errors.  Keep that in mind for the actions
627
+		 * below.
628
+		 */
629
+		if ($number_deleted !== false) {
630
+			do_action('AHEE__EEM_Message__delete_old_messages__after_successful_deletion', $message_ids_to_delete, $number_deleted);
631
+		} else {
632
+			do_action('AHEE__EEM_Message__delete_old_messages__after_deletion_fail', $message_ids_to_delete, $number_deleted);
633
+		}
634
+		return $number_deleted;
635
+	}
636 636
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Registration.model.php 2 patches
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -369,14 +369,14 @@  discard block
 block discarded – undo
369 369
         // and the table hasn't actually been created, this could have an error
370 370
         /** @type WPDB $wpdb */
371 371
         global $wpdb;
372
-        if ($this->_get_table_analysis()->tableExists($wpdb->prefix . 'esp_status')) {
372
+        if ($this->_get_table_analysis()->tableExists($wpdb->prefix.'esp_status')) {
373 373
             $results = $wpdb->get_results(
374 374
                 "SELECT STS_ID, STS_code FROM {$wpdb->prefix}esp_status WHERE STS_type = 'registration'"
375 375
             );
376 376
             self::$_reg_status = array();
377 377
             foreach ($results as $status) {
378
-                if (!in_array($status->STS_ID, $exclude, true)) {
379
-                    self::$_reg_status[ $status->STS_ID ] = $status->STS_code;
378
+                if ( ! in_array($status->STS_ID, $exclude, true)) {
379
+                    self::$_reg_status[$status->STS_ID] = $status->STS_code;
380 380
                 }
381 381
             }
382 382
         }
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
      */
434 434
     public function get_all_registrations_for_attendee($ATT_ID = 0)
435 435
     {
436
-        if (!$ATT_ID) {
436
+        if ( ! $ATT_ID) {
437 437
             return null;
438 438
         }
439 439
         return $this->get_all(array(array('ATT_ID' => $ATT_ID)));
@@ -450,7 +450,7 @@  discard block
 block discarded – undo
450 450
      */
451 451
     public function get_registration_for_reg_url_link($REG_url_link)
452 452
     {
453
-        if (!$REG_url_link) {
453
+        if ( ! $REG_url_link) {
454 454
             return null;
455 455
         }
456 456
         return $this->get_one(array(array('REG_url_link' => $REG_url_link)));
@@ -501,7 +501,7 @@  discard block
 block discarded – undo
501 501
             'REG_date' => array('>=', $sql_date),
502 502
             'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
503 503
         );
504
-        if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_day_report')) {
504
+        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_day_report')) {
505 505
             $where['Event.EVT_wp_user'] = get_current_user_id();
506 506
         }
507 507
         $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'REG_date');
@@ -513,7 +513,7 @@  discard block
 block discarded – undo
513 513
             ),
514 514
             OBJECT,
515 515
             array(
516
-                'regDate' => array('DATE(' . $query_interval . ')', '%s'),
516
+                'regDate' => array('DATE('.$query_interval.')', '%s'),
517 517
                 'total' => array('count(REG_ID)', '%d'),
518 518
             )
519 519
         );
@@ -533,7 +533,7 @@  discard block
 block discarded – undo
533 533
     public function get_registrations_per_day_and_per_status_report($period = '-1 month')
534 534
     {
535 535
         global $wpdb;
536
-        $registration_table = $wpdb->prefix . 'esp_registration';
536
+        $registration_table = $wpdb->prefix.'esp_registration';
537 537
         $event_table = $wpdb->posts;
538 538
         $sql_date = date('Y-m-d H:i:s', strtotime($period));
539 539
         // prepare the query interval for displaying offset
@@ -542,9 +542,9 @@  discard block
 block discarded – undo
542 542
         $inner_date_query = "SELECT DISTINCT REG_date from {$registration_table} ";
543 543
         $inner_where = ' WHERE';
544 544
         // exclude events not authored by user if permissions in effect
545
-        if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
545
+        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
546 546
             $inner_date_query .= "LEFT JOIN {$event_table} ON ID = EVT_ID";
547
-            $inner_where .= ' post_author = ' . get_current_user_id() . ' AND';
547
+            $inner_where .= ' post_author = '.get_current_user_id().' AND';
548 548
         }
549 549
         $inner_where .= " REG_date >= '{$sql_date}'";
550 550
         $inner_date_query .= $inner_where;
@@ -567,7 +567,7 @@  discard block
 block discarded – undo
567 567
         // setup the joins
568 568
         $join .= implode(' LEFT JOIN ', $join_parts);
569 569
         // now let's put it all together
570
-        $query = $select . $join . ' GROUP BY Registration_REG_date';
570
+        $query = $select.$join.' GROUP BY Registration_REG_date';
571 571
         // and execute it
572 572
         return $wpdb->get_results($query, ARRAY_A);
573 573
     }
@@ -593,7 +593,7 @@  discard block
 block discarded – undo
593 593
             'REG_date' => array('>=', $date_sql),
594 594
             'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
595 595
         );
596
-        if (!EE_Registry::instance()->CAP->current_user_can(
596
+        if ( ! EE_Registry::instance()->CAP->current_user_can(
597 597
             'ee_read_others_registrations',
598 598
             'reg_per_event_report'
599 599
         )
@@ -629,16 +629,16 @@  discard block
 block discarded – undo
629 629
     public function get_registrations_per_event_and_per_status_report($period = '-1 month')
630 630
     {
631 631
         global $wpdb;
632
-        $registration_table = $wpdb->prefix . 'esp_registration';
632
+        $registration_table = $wpdb->prefix.'esp_registration';
633 633
         $event_table = $wpdb->posts;
634 634
         $sql_date = date('Y-m-d H:i:s', strtotime($period));
635 635
         // inner date query
636 636
         $inner_date_query = "SELECT DISTINCT EVT_ID, REG_date from $registration_table ";
637 637
         $inner_where = ' WHERE';
638 638
         // exclude events not authored by user if permissions in effect
639
-        if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
639
+        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
640 640
             $inner_date_query .= "LEFT JOIN {$event_table} ON ID = EVT_ID";
641
-            $inner_where .= ' post_author = ' . get_current_user_id() . ' AND';
641
+            $inner_where .= ' post_author = '.get_current_user_id().' AND';
642 642
         }
643 643
         $inner_where .= " REG_date >= '{$sql_date}'";
644 644
         $inner_date_query .= $inner_where;
@@ -661,7 +661,7 @@  discard block
 block discarded – undo
661 661
         // setup remaining joins
662 662
         $join .= implode(' LEFT JOIN ', $join_parts);
663 663
         // now put it all together
664
-        $query = $select . $join . ' GROUP BY Registration_Event';
664
+        $query = $select.$join.' GROUP BY Registration_Event';
665 665
         // and execute
666 666
         return $wpdb->get_results($query, ARRAY_A);
667 667
     }
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
      */
677 677
     public function get_primary_registration_for_transaction_ID($TXN_ID = 0)
678 678
     {
679
-        if (!$TXN_ID) {
679
+        if ( ! $TXN_ID) {
680 680
             return null;
681 681
         }
682 682
         return $this->get_one(array(
@@ -745,11 +745,11 @@  discard block
 block discarded – undo
745 745
         $query = $wpdb->prepare(
746 746
             'SELECT '
747 747
             . 'COUNT( DISTINCT checkins.REG_ID ) '
748
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN'
748
+            . 'FROM '.EEM_Checkin::instance()->table().' AS checkins INNER JOIN'
749 749
             . '( SELECT '
750 750
             . 'max( CHK_timestamp ) AS latest_checkin, '
751 751
             . 'REG_ID AS REG_ID '
752
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' '
752
+            . 'FROM '.EEM_Checkin::instance()->table().' '
753 753
             . 'WHERE DTT_ID=%d '
754 754
             . 'GROUP BY REG_ID'
755 755
             . ') AS most_recent_checkin_per_reg '
@@ -779,12 +779,12 @@  discard block
 block discarded – undo
779 779
         $query = $wpdb->prepare(
780 780
             'SELECT '
781 781
             . 'COUNT( DISTINCT checkins.REG_ID ) '
782
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN'
782
+            . 'FROM '.EEM_Checkin::instance()->table().' AS checkins INNER JOIN'
783 783
             . '( SELECT '
784 784
             . 'max( CHK_timestamp ) AS latest_checkin, '
785 785
             . 'REG_ID AS REG_ID '
786
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' AS c '
787
-            . 'INNER JOIN ' . EEM_Datetime::instance()->table() . ' AS d '
786
+            . 'FROM '.EEM_Checkin::instance()->table().' AS c '
787
+            . 'INNER JOIN '.EEM_Datetime::instance()->table().' AS d '
788 788
             . 'ON c.DTT_ID=d.DTT_ID '
789 789
             . 'WHERE d.EVT_ID=%d '
790 790
             . 'GROUP BY REG_ID'
@@ -813,7 +813,7 @@  discard block
 block discarded – undo
813 813
     {
814 814
         // first do a native wp_query to get the latest REG_ID's matching these attendees.
815 815
         global $wpdb;
816
-        $registration_table = $wpdb->prefix . 'esp_registration';
816
+        $registration_table = $wpdb->prefix.'esp_registration';
817 817
         $attendee_table = $wpdb->posts;
818 818
         $attendee_ids = is_array($attendee_ids)
819 819
             ? array_map('absint', $attendee_ids)
@@ -868,7 +868,7 @@  discard block
 block discarded – undo
868 868
     public function event_reg_count_for_statuses($EVT_ID, $statuses = array())
869 869
     {
870 870
         $EVT_ID = absint($EVT_ID);
871
-        if (! $EVT_ID) {
871
+        if ( ! $EVT_ID) {
872 872
             throw new InvalidArgumentException(
873 873
                 esc_html__('An invalid Event ID was supplied.', 'event_espresso')
874 874
             );
@@ -877,7 +877,7 @@  discard block
 block discarded – undo
877 877
         $statuses = ! empty($statuses) ? $statuses : array(EEM_Registration::status_id_approved);
878 878
         $valid_reg_statuses = EEM_Registration::reg_statuses();
879 879
         foreach ($statuses as $status) {
880
-            if (! in_array($status, $valid_reg_statuses, true)) {
880
+            if ( ! in_array($status, $valid_reg_statuses, true)) {
881 881
                 throw new InvalidStatusException($status, esc_html__('Registration', 'event_espresso'));
882 882
             }
883 883
         }
Please login to merge, or discard this patch.
Indentation   +867 added lines, -867 removed lines patch added patch discarded remove patch
@@ -13,816 +13,816 @@  discard block
 block discarded – undo
13 13
 class EEM_Registration extends EEM_Soft_Delete_Base
14 14
 {
15 15
 
16
-    /**
17
-     * @var EEM_Registration $_instance
18
-     */
19
-    protected static $_instance;
20
-
21
-    /**
22
-     * Keys are the status IDs for registrations (eg, RAP, RCN, etc), and the values
23
-     * are status codes (eg, approved, cancelled, etc)
24
-     *
25
-     * @var array
26
-     */
27
-    private static $_reg_status;
28
-
29
-    /**
30
-     * The value of REG_count for a primary registrant
31
-     */
32
-    const PRIMARY_REGISTRANT_COUNT = 1;
33
-
34
-    /**
35
-     * Status ID (STS_ID on esp_status table) to indicate an INCOMPLETE registration.
36
-     * Initial status for registrations when they are first created
37
-     * Payments are NOT allowed.
38
-     * Automatically toggled to whatever the default Event registration status is upon completion of the attendee
39
-     * information reg step NO space reserved. Registration is NOT active
40
-     */
41
-    const status_id_incomplete = 'RIC';
42
-
43
-    /**
44
-     * Status ID (STS_ID on esp_status table) to indicate an UNAPPROVED registration.
45
-     * Payments are NOT allowed.
46
-     * Event Admin must manually toggle STS_ID for it to change
47
-     * No space reserved.
48
-     * Registration is active
49
-     */
50
-    const status_id_not_approved = 'RNA';
51
-
52
-    /**
53
-     * Status ID (STS_ID on esp_status table) to indicate registration is PENDING_PAYMENT .
54
-     * Payments are allowed.
55
-     * STS_ID will automatically be toggled to RAP if payment is made in full by the attendee
56
-     * No space reserved.
57
-     * Registration is active
58
-     */
59
-    const status_id_pending_payment = 'RPP';
60
-
61
-    /**
62
-     * Status ID (STS_ID on esp_status table) to indicate registration is on the WAIT_LIST .
63
-     * Payments are allowed.
64
-     * STS_ID will automatically be toggled to RAP if payment is made in full by the attendee
65
-     * No space reserved.
66
-     * Registration is active
67
-     */
68
-    const status_id_wait_list = 'RWL';
69
-
70
-    /**
71
-     * Status ID (STS_ID on esp_status table) to indicate an APPROVED registration.
72
-     * the TXN may or may not be completed ( paid in full )
73
-     * Payments are allowed.
74
-     * A space IS reserved.
75
-     * Registration is active
76
-     */
77
-    const status_id_approved = 'RAP';
78
-
79
-    /**
80
-     * Status ID (STS_ID on esp_status table) to indicate a registration was CANCELLED by the attendee.
81
-     * Payments are NOT allowed.
82
-     * NO space reserved.
83
-     * Registration is NOT active
84
-     */
85
-    const status_id_cancelled = 'RCN';
86
-
87
-    /**
88
-     * Status ID (STS_ID on esp_status table) to indicate a registration was DECLINED by the Event Admin
89
-     * Payments are NOT allowed.
90
-     * No space reserved.
91
-     * Registration is NOT active
92
-     */
93
-    const status_id_declined = 'RDC';
94
-
95
-    /**
96
-     * @var TableAnalysis $table_analysis
97
-     */
98
-    protected $_table_analysis;
99
-
100
-
101
-    /**
102
-     *    private constructor to prevent direct creation
103
-     *
104
-     * @Constructor
105
-     * @access protected
106
-     * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any
107
-     *                         incoming timezone data that gets saved). Note this just sends the timezone info to the
108
-     *                         date time model field objects.  Default is NULL (and will be assumed using the set
109
-     *                         timezone in the 'timezone_string' wp option)
110
-     * @throws EE_Error
111
-     */
112
-    protected function __construct($timezone = null)
113
-    {
114
-        $this->_table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
115
-        $this->singular_item = esc_html__('Registration', 'event_espresso');
116
-        $this->plural_item = esc_html__('Registrations', 'event_espresso');
117
-        $this->_tables = array(
118
-            'Registration' => new EE_Primary_Table('esp_registration', 'REG_ID'),
119
-        );
120
-        $this->_fields = array(
121
-            'Registration' => array(
122
-                'REG_ID' => new EE_Primary_Key_Int_Field(
123
-                    'REG_ID',
124
-                    esc_html__('Registration ID', 'event_espresso')
125
-                ),
126
-                'EVT_ID' => new EE_Foreign_Key_Int_Field(
127
-                    'EVT_ID',
128
-                    esc_html__('Event ID', 'event_espresso'),
129
-                    false,
130
-                    0,
131
-                    'Event'
132
-                ),
133
-                'ATT_ID' => new EE_Foreign_Key_Int_Field(
134
-                    'ATT_ID',
135
-                    esc_html__('Attendee ID', 'event_espresso'),
136
-                    false,
137
-                    0,
138
-                    'Attendee'
139
-                ),
140
-                'TXN_ID' => new EE_Foreign_Key_Int_Field(
141
-                    'TXN_ID',
142
-                    esc_html__('Transaction ID', 'event_espresso'),
143
-                    false,
144
-                    0,
145
-                    'Transaction'
146
-                ),
147
-                'TKT_ID' => new EE_Foreign_Key_Int_Field(
148
-                    'TKT_ID',
149
-                    esc_html__('Ticket ID', 'event_espresso'),
150
-                    false,
151
-                    0,
152
-                    'Ticket'
153
-                ),
154
-                'STS_ID' => new EE_Foreign_Key_String_Field(
155
-                    'STS_ID',
156
-                    esc_html__('Status ID', 'event_espresso'),
157
-                    false,
158
-                    EEM_Registration::status_id_incomplete,
159
-                    'Status'
160
-                ),
161
-                'REG_date' => new EE_Datetime_Field(
162
-                    'REG_date',
163
-                    esc_html__('Time registration occurred', 'event_espresso'),
164
-                    false,
165
-                    EE_Datetime_Field::now,
166
-                    $timezone
167
-                ),
168
-                'REG_final_price' => new EE_Money_Field(
169
-                    'REG_final_price',
170
-                    esc_html__('Registration\'s share of the transaction total', 'event_espresso'),
171
-                    false,
172
-                    0
173
-                ),
174
-                'REG_paid' => new EE_Money_Field(
175
-                    'REG_paid',
176
-                    esc_html__('Amount paid to date towards registration', 'event_espresso'),
177
-                    false,
178
-                    0
179
-                ),
180
-                'REG_session' => new EE_Plain_Text_Field(
181
-                    'REG_session',
182
-                    esc_html__('Session ID of registration', 'event_espresso'),
183
-                    false,
184
-                    ''
185
-                ),
186
-                'REG_code' => new EE_Plain_Text_Field(
187
-                    'REG_code',
188
-                    esc_html__('Unique Code for this registration', 'event_espresso'),
189
-                    false,
190
-                    ''
191
-                ),
192
-                'REG_url_link' => new EE_Plain_Text_Field(
193
-                    'REG_url_link',
194
-                    esc_html__('String to be used in URL for identifying registration', 'event_espresso'),
195
-                    false,
196
-                    ''
197
-                ),
198
-                'REG_count' => new EE_Integer_Field(
199
-                    'REG_count',
200
-                    esc_html__('Count of this registration in the group registration ', 'event_espresso'),
201
-                    true,
202
-                    1
203
-                ),
204
-                'REG_group_size' => new EE_Integer_Field(
205
-                    'REG_group_size',
206
-                    esc_html__('Number of registrations on this group', 'event_espresso'),
207
-                    false,
208
-                    1
209
-                ),
210
-                'REG_att_is_going' => new EE_Boolean_Field(
211
-                    'REG_att_is_going',
212
-                    esc_html__('Flag indicating the registrant plans on attending', 'event_espresso'),
213
-                    false,
214
-                    false
215
-                ),
216
-                'REG_deleted' => new EE_Trashed_Flag_Field(
217
-                    'REG_deleted',
218
-                    esc_html__('Flag indicating if registration has been archived or not.', 'event_espresso'),
219
-                    false,
220
-                    false
221
-                ),
222
-            ),
223
-        );
224
-        $this->_model_relations = array(
225
-            'Event' => new EE_Belongs_To_Relation(),
226
-            'Attendee' => new EE_Belongs_To_Relation(),
227
-            'Transaction' => new EE_Belongs_To_Relation(),
228
-            'Ticket' => new EE_Belongs_To_Relation(),
229
-            'Status' => new EE_Belongs_To_Relation(),
230
-            'Answer' => new EE_Has_Many_Relation(),
231
-            'Checkin' => new EE_Has_Many_Relation(),
232
-            'Registration_Payment' => new EE_Has_Many_Relation(),
233
-            'Payment' => new EE_HABTM_Relation('Registration_Payment'),
234
-            'Message' => new EE_Has_Many_Any_Relation(false)
235
-            // allow deletes even if there are messages in the queue related
236
-        );
237
-        $this->_model_chain_to_wp_user = 'Event';
238
-        parent::__construct($timezone);
239
-    }
240
-
241
-
242
-    /**
243
-     * a list of ALL valid registration statuses currently in use within the system
244
-     * generated by combining the filterable active and inactive reg status arrays
245
-     *
246
-     * @return array
247
-     */
248
-    public static function reg_statuses()
249
-    {
250
-        return array_unique(
251
-            array_merge(
252
-                EEM_Registration::active_reg_statuses(),
253
-                EEM_Registration::inactive_reg_statuses()
254
-            )
255
-        );
256
-    }
257
-
258
-
259
-    /**
260
-     * reg_statuses_that_allow_payment
261
-     * a filterable list of registration statuses that allow a registrant to make a payment
262
-     *
263
-     * @access public
264
-     * @return array
265
-     */
266
-    public static function reg_statuses_that_allow_payment()
267
-    {
268
-        return apply_filters(
269
-            'FHEE__EEM_Registration__reg_statuses_that_allow_payment',
270
-            array(
271
-                EEM_Registration::status_id_approved,
272
-                EEM_Registration::status_id_pending_payment,
273
-            )
274
-        );
275
-    }
276
-
277
-
278
-    /**
279
-     * active_reg_statuses
280
-     * a filterable list of registration statuses that are considered active
281
-     *
282
-     * @access public
283
-     * @return array
284
-     */
285
-    public static function active_reg_statuses()
286
-    {
287
-        return apply_filters(
288
-            'FHEE__EEM_Registration__active_reg_statuses',
289
-            array(
290
-                EEM_Registration::status_id_approved,
291
-                EEM_Registration::status_id_pending_payment,
292
-                EEM_Registration::status_id_wait_list,
293
-                EEM_Registration::status_id_not_approved,
294
-            )
295
-        );
296
-    }
297
-
298
-
299
-    /**
300
-     * inactive_reg_statuses
301
-     * a filterable list of registration statuses that are not considered active
302
-     *
303
-     * @access public
304
-     * @return array
305
-     */
306
-    public static function inactive_reg_statuses()
307
-    {
308
-        return apply_filters(
309
-            'FHEE__EEM_Registration__inactive_reg_statuses',
310
-            array(
311
-                EEM_Registration::status_id_incomplete,
312
-                EEM_Registration::status_id_cancelled,
313
-                EEM_Registration::status_id_declined,
314
-            )
315
-        );
316
-    }
317
-
318
-
319
-    /**
320
-     *    closed_reg_statuses
321
-     *    a filterable list of registration statuses that are considered "closed"
322
-     * meaning they should not be considered in any calculations involving monies owing
323
-     *
324
-     * @access public
325
-     * @return array
326
-     */
327
-    public static function closed_reg_statuses()
328
-    {
329
-        return apply_filters(
330
-            'FHEE__EEM_Registration__closed_reg_statuses',
331
-            array(
332
-                EEM_Registration::status_id_cancelled,
333
-                EEM_Registration::status_id_declined,
334
-                EEM_Registration::status_id_wait_list,
335
-            )
336
-        );
337
-    }
338
-
339
-
340
-    /**
341
-     *        get list of registration statuses
342
-     *
343
-     * @access public
344
-     * @param array $exclude The status ids to exclude from the returned results
345
-     * @param bool $translated If true will return the values as singular localized strings
346
-     * @return array
347
-     * @throws EE_Error
348
-     */
349
-    public static function reg_status_array($exclude = array(), $translated = false)
350
-    {
351
-        EEM_Registration::instance()->_get_registration_status_array($exclude);
352
-        return $translated
353
-            ? EEM_Status::instance()->localized_status(self::$_reg_status, false, 'sentence')
354
-            : self::$_reg_status;
355
-    }
356
-
357
-
358
-    /**
359
-     *    get list of registration statuses
360
-     *
361
-     * @access private
362
-     * @param array $exclude
363
-     * @return void
364
-     * @throws EE_Error
365
-     */
366
-    private function _get_registration_status_array($exclude = array())
367
-    {
368
-        // in the very rare circumstance that we are deleting a model's table's data
369
-        // and the table hasn't actually been created, this could have an error
370
-        /** @type WPDB $wpdb */
371
-        global $wpdb;
372
-        if ($this->_get_table_analysis()->tableExists($wpdb->prefix . 'esp_status')) {
373
-            $results = $wpdb->get_results(
374
-                "SELECT STS_ID, STS_code FROM {$wpdb->prefix}esp_status WHERE STS_type = 'registration'"
375
-            );
376
-            self::$_reg_status = array();
377
-            foreach ($results as $status) {
378
-                if (!in_array($status->STS_ID, $exclude, true)) {
379
-                    self::$_reg_status[ $status->STS_ID ] = $status->STS_code;
380
-                }
381
-            }
382
-        }
383
-    }
384
-
385
-
386
-    /**
387
-     * Gets the injected table analyzer, or throws an exception
388
-     *
389
-     * @return TableAnalysis
390
-     * @throws EE_Error
391
-     */
392
-    protected function _get_table_analysis()
393
-    {
394
-        if ($this->_table_analysis instanceof TableAnalysis) {
395
-            return $this->_table_analysis;
396
-        }
397
-        throw new EE_Error(
398
-            sprintf(
399
-                esc_html__('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
400
-                get_class($this)
401
-            )
402
-        );
403
-    }
404
-
405
-
406
-    /**
407
-     * This returns a wpdb->results array of all registration date month and years matching the incoming query params
408
-     * and grouped by month and year.
409
-     *
410
-     * @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
411
-     * @return array
412
-     * @throws EE_Error
413
-     */
414
-    public function get_reg_months_and_years($where_params)
415
-    {
416
-        $query_params[0] = $where_params;
417
-        $query_params['group_by'] = array('reg_year', 'reg_month');
418
-        $query_params['order_by'] = array('REG_date' => 'DESC');
419
-        $columns_to_select = array(
420
-            'reg_year' => array('YEAR(REG_date)', '%s'),
421
-            'reg_month' => array('MONTHNAME(REG_date)', '%s'),
422
-        );
423
-        return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
424
-    }
425
-
426
-
427
-    /**
428
-     * retrieve ALL registrations for a particular Attendee from db
429
-     *
430
-     * @param int $ATT_ID
431
-     * @return EE_Base_Class[]|EE_Registration[]|null
432
-     * @throws EE_Error
433
-     */
434
-    public function get_all_registrations_for_attendee($ATT_ID = 0)
435
-    {
436
-        if (!$ATT_ID) {
437
-            return null;
438
-        }
439
-        return $this->get_all(array(array('ATT_ID' => $ATT_ID)));
440
-    }
441
-
442
-
443
-    /**
444
-     * Gets a registration given their REG_url_link. Yes, this should usually
445
-     * be passed via a GET parameter.
446
-     *
447
-     * @param string $REG_url_link
448
-     * @return EE_Base_Class|EE_Registration|null
449
-     * @throws EE_Error
450
-     */
451
-    public function get_registration_for_reg_url_link($REG_url_link)
452
-    {
453
-        if (!$REG_url_link) {
454
-            return null;
455
-        }
456
-        return $this->get_one(array(array('REG_url_link' => $REG_url_link)));
457
-    }
458
-
459
-
460
-    /**
461
-     *        retrieve registration for a specific transaction attendee from db
462
-     *
463
-     * @access        public
464
-     * @param    int $TXN_ID
465
-     * @param    int $ATT_ID
466
-     * @param    int $att_nmbr in case the ATT_ID is the same for multiple registrations (same details used) then the
467
-     *                         attendee number is required
468
-     * @return        mixed        array on success, FALSE on fail
469
-     * @throws EE_Error
470
-     */
471
-    public function get_registration_for_transaction_attendee($TXN_ID = 0, $ATT_ID = 0, $att_nmbr = 0)
472
-    {
473
-        return $this->get_one(array(
474
-            array(
475
-                'TXN_ID' => $TXN_ID,
476
-                'ATT_ID' => $ATT_ID,
477
-            ),
478
-            'limit' => array(min($att_nmbr - 1, 0), 1),
479
-        ));
480
-    }
481
-
482
-
483
-    /**
484
-     *        get the number of registrations per day  for the Registration Admin page Reports Tab.
485
-     *        (doesn't utilize models because it's a fairly specialized query)
486
-     *
487
-     * @access        public
488
-     * @param $period string which can be passed to php's strtotime function (eg "-1 month")
489
-     * @return stdClass[] with properties regDate and total
490
-     * @throws EE_Error
491
-     */
492
-    public function get_registrations_per_day_report($period = '-1 month')
493
-    {
494
-        $sql_date = $this->convert_datetime_for_query(
495
-            'REG_date',
496
-            date('Y-m-d H:i:s', strtotime($period)),
497
-            'Y-m-d H:i:s',
498
-            'UTC'
499
-        );
500
-        $where = array(
501
-            'REG_date' => array('>=', $sql_date),
502
-            'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
503
-        );
504
-        if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_day_report')) {
505
-            $where['Event.EVT_wp_user'] = get_current_user_id();
506
-        }
507
-        $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'REG_date');
508
-        $results = $this->_get_all_wpdb_results(
509
-            array(
510
-                $where,
511
-                'group_by' => 'regDate',
512
-                'order_by' => array('REG_date' => 'ASC'),
513
-            ),
514
-            OBJECT,
515
-            array(
516
-                'regDate' => array('DATE(' . $query_interval . ')', '%s'),
517
-                'total' => array('count(REG_ID)', '%d'),
518
-            )
519
-        );
520
-        return $results;
521
-    }
522
-
523
-
524
-    /**
525
-     * Get the number of registrations per day including the count of registrations for each Registration Status.
526
-     * Note: EEM_Registration::status_id_incomplete registrations are excluded from the results.
527
-     *
528
-     * @param string $period
529
-     * @return stdClass[] with properties Registration_REG_date and a column for each registration status as the STS_ID
530
-     * @throws EE_Error
531
-     *                    (i.e. RAP)
532
-     */
533
-    public function get_registrations_per_day_and_per_status_report($period = '-1 month')
534
-    {
535
-        global $wpdb;
536
-        $registration_table = $wpdb->prefix . 'esp_registration';
537
-        $event_table = $wpdb->posts;
538
-        $sql_date = date('Y-m-d H:i:s', strtotime($period));
539
-        // prepare the query interval for displaying offset
540
-        $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'dates.REG_date');
541
-        // inner date query
542
-        $inner_date_query = "SELECT DISTINCT REG_date from {$registration_table} ";
543
-        $inner_where = ' WHERE';
544
-        // exclude events not authored by user if permissions in effect
545
-        if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
546
-            $inner_date_query .= "LEFT JOIN {$event_table} ON ID = EVT_ID";
547
-            $inner_where .= ' post_author = ' . get_current_user_id() . ' AND';
548
-        }
549
-        $inner_where .= " REG_date >= '{$sql_date}'";
550
-        $inner_date_query .= $inner_where;
551
-        // start main query
552
-        $select = "SELECT DATE({$query_interval}) as Registration_REG_date, ";
553
-        $join = '';
554
-        $join_parts = array();
555
-        $select_parts = array();
556
-        // loop through registration stati to do parts for each status.
557
-        foreach (EEM_Registration::reg_status_array() as $STS_ID => $STS_code) {
558
-            if ($STS_ID === EEM_Registration::status_id_incomplete) {
559
-                continue;
560
-            }
561
-            $select_parts[] = "COUNT({$STS_code}.REG_ID) as {$STS_ID}";
562
-            $join_parts[] = "{$registration_table} AS {$STS_code} ON {$STS_code}.REG_date = dates.REG_date AND {$STS_code}.STS_ID = '{$STS_ID}'";
563
-        }
564
-        // setup the selects
565
-        $select .= implode(', ', $select_parts);
566
-        $select .= " FROM ($inner_date_query) AS dates LEFT JOIN ";
567
-        // setup the joins
568
-        $join .= implode(' LEFT JOIN ', $join_parts);
569
-        // now let's put it all together
570
-        $query = $select . $join . ' GROUP BY Registration_REG_date';
571
-        // and execute it
572
-        return $wpdb->get_results($query, ARRAY_A);
573
-    }
574
-
575
-
576
-    /**
577
-     *        get the number of registrations per event  for the Registration Admin page Reports Tab
578
-     *
579
-     * @access        public
580
-     * @param $period string which can be passed to php's strtotime function (eg "-1 month")
581
-     * @return stdClass[] each with properties event_name, reg_limit, and total
582
-     * @throws EE_Error
583
-     */
584
-    public function get_registrations_per_event_report($period = '-1 month')
585
-    {
586
-        $date_sql = $this->convert_datetime_for_query(
587
-            'REG_date',
588
-            date('Y-m-d H:i:s', strtotime($period)),
589
-            'Y-m-d H:i:s',
590
-            'UTC'
591
-        );
592
-        $where = array(
593
-            'REG_date' => array('>=', $date_sql),
594
-            'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
595
-        );
596
-        if (!EE_Registry::instance()->CAP->current_user_can(
597
-            'ee_read_others_registrations',
598
-            'reg_per_event_report'
599
-        )
600
-        ) {
601
-            $where['Event.EVT_wp_user'] = get_current_user_id();
602
-        }
603
-        $results = $this->_get_all_wpdb_results(
604
-            array(
605
-            $where,
606
-            'group_by' => 'Event.EVT_name',
607
-            'order_by' => 'Event.EVT_name',
608
-            'limit' => array(0, 24),
609
-            ),
610
-            OBJECT,
611
-            array(
612
-                'event_name' => array('Event_CPT.post_title', '%s'),
613
-                'total' => array('COUNT(REG_ID)', '%s'),
614
-            )
615
-        );
616
-        return $results;
617
-    }
618
-
619
-
620
-    /**
621
-     * Get the number of registrations per event grouped by registration status.
622
-     * Note: EEM_Registration::status_id_incomplete registrations are excluded from the results.
623
-     *
624
-     * @param string $period
625
-     * @return stdClass[] with properties `Registration_Event` and a column for each registration status as the STS_ID
626
-     * @throws EE_Error
627
-     *                    (i.e. RAP)
628
-     */
629
-    public function get_registrations_per_event_and_per_status_report($period = '-1 month')
630
-    {
631
-        global $wpdb;
632
-        $registration_table = $wpdb->prefix . 'esp_registration';
633
-        $event_table = $wpdb->posts;
634
-        $sql_date = date('Y-m-d H:i:s', strtotime($period));
635
-        // inner date query
636
-        $inner_date_query = "SELECT DISTINCT EVT_ID, REG_date from $registration_table ";
637
-        $inner_where = ' WHERE';
638
-        // exclude events not authored by user if permissions in effect
639
-        if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
640
-            $inner_date_query .= "LEFT JOIN {$event_table} ON ID = EVT_ID";
641
-            $inner_where .= ' post_author = ' . get_current_user_id() . ' AND';
642
-        }
643
-        $inner_where .= " REG_date >= '{$sql_date}'";
644
-        $inner_date_query .= $inner_where;
645
-        // build main query
646
-        $select = 'SELECT Event.post_title as Registration_Event, ';
647
-        $join = '';
648
-        $join_parts = array();
649
-        $select_parts = array();
650
-        // loop through registration stati to do parts for each status.
651
-        foreach (EEM_Registration::reg_status_array() as $STS_ID => $STS_code) {
652
-            if ($STS_ID === EEM_Registration::status_id_incomplete) {
653
-                continue;
654
-            }
655
-            $select_parts[] = "COUNT({$STS_code}.REG_ID) as {$STS_ID}";
656
-            $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";
657
-        }
658
-        // setup the selects
659
-        $select .= implode(', ', $select_parts);
660
-        $select .= " FROM ($inner_date_query) AS dates LEFT JOIN $event_table as Event ON Event.ID = dates.EVT_ID LEFT JOIN ";
661
-        // setup remaining joins
662
-        $join .= implode(' LEFT JOIN ', $join_parts);
663
-        // now put it all together
664
-        $query = $select . $join . ' GROUP BY Registration_Event';
665
-        // and execute
666
-        return $wpdb->get_results($query, ARRAY_A);
667
-    }
668
-
669
-
670
-    /**
671
-     * Returns the EE_Registration of the primary attendee on the transaction id provided
672
-     *
673
-     * @param int $TXN_ID
674
-     * @return EE_Base_Class|EE_Registration|null
675
-     * @throws EE_Error
676
-     */
677
-    public function get_primary_registration_for_transaction_ID($TXN_ID = 0)
678
-    {
679
-        if (!$TXN_ID) {
680
-            return null;
681
-        }
682
-        return $this->get_one(array(
683
-            array(
684
-                'TXN_ID' => $TXN_ID,
685
-                'REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT,
686
-            ),
687
-        ));
688
-    }
689
-
690
-
691
-    /**
692
-     *        get_event_registration_count
693
-     *
694
-     * @access public
695
-     * @param int $EVT_ID
696
-     * @param boolean $for_incomplete_payments
697
-     * @return int
698
-     * @throws EE_Error
699
-     */
700
-    public function get_event_registration_count($EVT_ID, $for_incomplete_payments = false)
701
-    {
702
-        // we only count approved registrations towards registration limits
703
-        $query_params = array(array('EVT_ID' => $EVT_ID, 'STS_ID' => self::status_id_approved));
704
-        if ($for_incomplete_payments) {
705
-            $query_params[0]['Transaction.STS_ID'] = array('!=', EEM_Transaction::complete_status_code);
706
-        }
707
-        return $this->count($query_params);
708
-    }
709
-
710
-
711
-    /**
712
-     * Deletes all registrations with no transactions. Note that this needs to be very efficient
713
-     * 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
714
-     * when joining tables like this.
715
-     *
716
-     * @global WPDB $wpdb
717
-     * @return int number deleted
718
-     * @throws EE_Error
719
-     */
720
-    public function delete_registrations_with_no_transaction()
721
-    {
722
-        /** @type WPDB $wpdb */
723
-        global $wpdb;
724
-        return $wpdb->query(
725
-            'DELETE r FROM '
726
-            . $this->table()
727
-            . ' r LEFT JOIN '
728
-            . EEM_Transaction::instance()->table()
729
-            . ' t ON r.TXN_ID = t.TXN_ID WHERE t.TXN_ID IS NULL'
730
-        );
731
-    }
732
-
733
-
734
-    /**
735
-     *  Count registrations checked into (or out of) a datetime
736
-     *
737
-     * @param int $DTT_ID datetime ID
738
-     * @param boolean $checked_in whether to count registrations checked IN or OUT
739
-     * @return int
740
-     * @throws EE_Error
741
-     */
742
-    public function count_registrations_checked_into_datetime($DTT_ID, $checked_in = true)
743
-    {
744
-        global $wpdb;
745
-        // subquery to get latest checkin
746
-        $query = $wpdb->prepare(
747
-            'SELECT '
748
-            . 'COUNT( DISTINCT checkins.REG_ID ) '
749
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN'
750
-            . '( SELECT '
751
-            . 'max( CHK_timestamp ) AS latest_checkin, '
752
-            . 'REG_ID AS REG_ID '
753
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' '
754
-            . 'WHERE DTT_ID=%d '
755
-            . 'GROUP BY REG_ID'
756
-            . ') AS most_recent_checkin_per_reg '
757
-            . 'ON checkins.REG_ID=most_recent_checkin_per_reg.REG_ID '
758
-            . 'AND checkins.CHK_timestamp = most_recent_checkin_per_reg.latest_checkin '
759
-            . 'WHERE '
760
-            . 'checkins.CHK_in=%d',
761
-            $DTT_ID,
762
-            $checked_in
763
-        );
764
-        return (int) $wpdb->get_var($query);
765
-    }
766
-
767
-
768
-    /**
769
-     *  Count registrations checked into (or out of) an event.
770
-     *
771
-     * @param int $EVT_ID event ID
772
-     * @param boolean $checked_in whether to count registrations checked IN or OUT
773
-     * @return int
774
-     * @throws EE_Error
775
-     */
776
-    public function count_registrations_checked_into_event($EVT_ID, $checked_in = true)
777
-    {
778
-        global $wpdb;
779
-        // subquery to get latest checkin
780
-        $query = $wpdb->prepare(
781
-            'SELECT '
782
-            . 'COUNT( DISTINCT checkins.REG_ID ) '
783
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN'
784
-            . '( SELECT '
785
-            . 'max( CHK_timestamp ) AS latest_checkin, '
786
-            . 'REG_ID AS REG_ID '
787
-            . 'FROM ' . EEM_Checkin::instance()->table() . ' AS c '
788
-            . 'INNER JOIN ' . EEM_Datetime::instance()->table() . ' AS d '
789
-            . 'ON c.DTT_ID=d.DTT_ID '
790
-            . 'WHERE d.EVT_ID=%d '
791
-            . 'GROUP BY REG_ID'
792
-            . ') AS most_recent_checkin_per_reg '
793
-            . 'ON checkins.REG_ID=most_recent_checkin_per_reg.REG_ID '
794
-            . 'AND checkins.CHK_timestamp = most_recent_checkin_per_reg.latest_checkin '
795
-            . 'WHERE '
796
-            . 'checkins.CHK_in=%d',
797
-            $EVT_ID,
798
-            $checked_in
799
-        );
800
-        return (int) $wpdb->get_var($query);
801
-    }
802
-
803
-
804
-    /**
805
-     * The purpose of this method is to retrieve an array of
806
-     * EE_Registration objects that represent the latest registration
807
-     * for each ATT_ID given in the function argument.
808
-     *
809
-     * @param array $attendee_ids
810
-     * @return EE_Base_Class[]|EE_Registration[]
811
-     * @throws EE_Error
812
-     */
813
-    public function get_latest_registration_for_each_of_given_contacts($attendee_ids = array())
814
-    {
815
-        // first do a native wp_query to get the latest REG_ID's matching these attendees.
816
-        global $wpdb;
817
-        $registration_table = $wpdb->prefix . 'esp_registration';
818
-        $attendee_table = $wpdb->posts;
819
-        $attendee_ids = is_array($attendee_ids)
820
-            ? array_map('absint', $attendee_ids)
821
-            : array((int) $attendee_ids);
822
-        $ATT_IDs = implode(',', $attendee_ids);
823
-        // first we do a query to get the registration ids
824
-        // (because a group by before order by causes the order by to be ignored.)
825
-        $registration_id_query = "
16
+	/**
17
+	 * @var EEM_Registration $_instance
18
+	 */
19
+	protected static $_instance;
20
+
21
+	/**
22
+	 * Keys are the status IDs for registrations (eg, RAP, RCN, etc), and the values
23
+	 * are status codes (eg, approved, cancelled, etc)
24
+	 *
25
+	 * @var array
26
+	 */
27
+	private static $_reg_status;
28
+
29
+	/**
30
+	 * The value of REG_count for a primary registrant
31
+	 */
32
+	const PRIMARY_REGISTRANT_COUNT = 1;
33
+
34
+	/**
35
+	 * Status ID (STS_ID on esp_status table) to indicate an INCOMPLETE registration.
36
+	 * Initial status for registrations when they are first created
37
+	 * Payments are NOT allowed.
38
+	 * Automatically toggled to whatever the default Event registration status is upon completion of the attendee
39
+	 * information reg step NO space reserved. Registration is NOT active
40
+	 */
41
+	const status_id_incomplete = 'RIC';
42
+
43
+	/**
44
+	 * Status ID (STS_ID on esp_status table) to indicate an UNAPPROVED registration.
45
+	 * Payments are NOT allowed.
46
+	 * Event Admin must manually toggle STS_ID for it to change
47
+	 * No space reserved.
48
+	 * Registration is active
49
+	 */
50
+	const status_id_not_approved = 'RNA';
51
+
52
+	/**
53
+	 * Status ID (STS_ID on esp_status table) to indicate registration is PENDING_PAYMENT .
54
+	 * Payments are allowed.
55
+	 * STS_ID will automatically be toggled to RAP if payment is made in full by the attendee
56
+	 * No space reserved.
57
+	 * Registration is active
58
+	 */
59
+	const status_id_pending_payment = 'RPP';
60
+
61
+	/**
62
+	 * Status ID (STS_ID on esp_status table) to indicate registration is on the WAIT_LIST .
63
+	 * Payments are allowed.
64
+	 * STS_ID will automatically be toggled to RAP if payment is made in full by the attendee
65
+	 * No space reserved.
66
+	 * Registration is active
67
+	 */
68
+	const status_id_wait_list = 'RWL';
69
+
70
+	/**
71
+	 * Status ID (STS_ID on esp_status table) to indicate an APPROVED registration.
72
+	 * the TXN may or may not be completed ( paid in full )
73
+	 * Payments are allowed.
74
+	 * A space IS reserved.
75
+	 * Registration is active
76
+	 */
77
+	const status_id_approved = 'RAP';
78
+
79
+	/**
80
+	 * Status ID (STS_ID on esp_status table) to indicate a registration was CANCELLED by the attendee.
81
+	 * Payments are NOT allowed.
82
+	 * NO space reserved.
83
+	 * Registration is NOT active
84
+	 */
85
+	const status_id_cancelled = 'RCN';
86
+
87
+	/**
88
+	 * Status ID (STS_ID on esp_status table) to indicate a registration was DECLINED by the Event Admin
89
+	 * Payments are NOT allowed.
90
+	 * No space reserved.
91
+	 * Registration is NOT active
92
+	 */
93
+	const status_id_declined = 'RDC';
94
+
95
+	/**
96
+	 * @var TableAnalysis $table_analysis
97
+	 */
98
+	protected $_table_analysis;
99
+
100
+
101
+	/**
102
+	 *    private constructor to prevent direct creation
103
+	 *
104
+	 * @Constructor
105
+	 * @access protected
106
+	 * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any
107
+	 *                         incoming timezone data that gets saved). Note this just sends the timezone info to the
108
+	 *                         date time model field objects.  Default is NULL (and will be assumed using the set
109
+	 *                         timezone in the 'timezone_string' wp option)
110
+	 * @throws EE_Error
111
+	 */
112
+	protected function __construct($timezone = null)
113
+	{
114
+		$this->_table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
115
+		$this->singular_item = esc_html__('Registration', 'event_espresso');
116
+		$this->plural_item = esc_html__('Registrations', 'event_espresso');
117
+		$this->_tables = array(
118
+			'Registration' => new EE_Primary_Table('esp_registration', 'REG_ID'),
119
+		);
120
+		$this->_fields = array(
121
+			'Registration' => array(
122
+				'REG_ID' => new EE_Primary_Key_Int_Field(
123
+					'REG_ID',
124
+					esc_html__('Registration ID', 'event_espresso')
125
+				),
126
+				'EVT_ID' => new EE_Foreign_Key_Int_Field(
127
+					'EVT_ID',
128
+					esc_html__('Event ID', 'event_espresso'),
129
+					false,
130
+					0,
131
+					'Event'
132
+				),
133
+				'ATT_ID' => new EE_Foreign_Key_Int_Field(
134
+					'ATT_ID',
135
+					esc_html__('Attendee ID', 'event_espresso'),
136
+					false,
137
+					0,
138
+					'Attendee'
139
+				),
140
+				'TXN_ID' => new EE_Foreign_Key_Int_Field(
141
+					'TXN_ID',
142
+					esc_html__('Transaction ID', 'event_espresso'),
143
+					false,
144
+					0,
145
+					'Transaction'
146
+				),
147
+				'TKT_ID' => new EE_Foreign_Key_Int_Field(
148
+					'TKT_ID',
149
+					esc_html__('Ticket ID', 'event_espresso'),
150
+					false,
151
+					0,
152
+					'Ticket'
153
+				),
154
+				'STS_ID' => new EE_Foreign_Key_String_Field(
155
+					'STS_ID',
156
+					esc_html__('Status ID', 'event_espresso'),
157
+					false,
158
+					EEM_Registration::status_id_incomplete,
159
+					'Status'
160
+				),
161
+				'REG_date' => new EE_Datetime_Field(
162
+					'REG_date',
163
+					esc_html__('Time registration occurred', 'event_espresso'),
164
+					false,
165
+					EE_Datetime_Field::now,
166
+					$timezone
167
+				),
168
+				'REG_final_price' => new EE_Money_Field(
169
+					'REG_final_price',
170
+					esc_html__('Registration\'s share of the transaction total', 'event_espresso'),
171
+					false,
172
+					0
173
+				),
174
+				'REG_paid' => new EE_Money_Field(
175
+					'REG_paid',
176
+					esc_html__('Amount paid to date towards registration', 'event_espresso'),
177
+					false,
178
+					0
179
+				),
180
+				'REG_session' => new EE_Plain_Text_Field(
181
+					'REG_session',
182
+					esc_html__('Session ID of registration', 'event_espresso'),
183
+					false,
184
+					''
185
+				),
186
+				'REG_code' => new EE_Plain_Text_Field(
187
+					'REG_code',
188
+					esc_html__('Unique Code for this registration', 'event_espresso'),
189
+					false,
190
+					''
191
+				),
192
+				'REG_url_link' => new EE_Plain_Text_Field(
193
+					'REG_url_link',
194
+					esc_html__('String to be used in URL for identifying registration', 'event_espresso'),
195
+					false,
196
+					''
197
+				),
198
+				'REG_count' => new EE_Integer_Field(
199
+					'REG_count',
200
+					esc_html__('Count of this registration in the group registration ', 'event_espresso'),
201
+					true,
202
+					1
203
+				),
204
+				'REG_group_size' => new EE_Integer_Field(
205
+					'REG_group_size',
206
+					esc_html__('Number of registrations on this group', 'event_espresso'),
207
+					false,
208
+					1
209
+				),
210
+				'REG_att_is_going' => new EE_Boolean_Field(
211
+					'REG_att_is_going',
212
+					esc_html__('Flag indicating the registrant plans on attending', 'event_espresso'),
213
+					false,
214
+					false
215
+				),
216
+				'REG_deleted' => new EE_Trashed_Flag_Field(
217
+					'REG_deleted',
218
+					esc_html__('Flag indicating if registration has been archived or not.', 'event_espresso'),
219
+					false,
220
+					false
221
+				),
222
+			),
223
+		);
224
+		$this->_model_relations = array(
225
+			'Event' => new EE_Belongs_To_Relation(),
226
+			'Attendee' => new EE_Belongs_To_Relation(),
227
+			'Transaction' => new EE_Belongs_To_Relation(),
228
+			'Ticket' => new EE_Belongs_To_Relation(),
229
+			'Status' => new EE_Belongs_To_Relation(),
230
+			'Answer' => new EE_Has_Many_Relation(),
231
+			'Checkin' => new EE_Has_Many_Relation(),
232
+			'Registration_Payment' => new EE_Has_Many_Relation(),
233
+			'Payment' => new EE_HABTM_Relation('Registration_Payment'),
234
+			'Message' => new EE_Has_Many_Any_Relation(false)
235
+			// allow deletes even if there are messages in the queue related
236
+		);
237
+		$this->_model_chain_to_wp_user = 'Event';
238
+		parent::__construct($timezone);
239
+	}
240
+
241
+
242
+	/**
243
+	 * a list of ALL valid registration statuses currently in use within the system
244
+	 * generated by combining the filterable active and inactive reg status arrays
245
+	 *
246
+	 * @return array
247
+	 */
248
+	public static function reg_statuses()
249
+	{
250
+		return array_unique(
251
+			array_merge(
252
+				EEM_Registration::active_reg_statuses(),
253
+				EEM_Registration::inactive_reg_statuses()
254
+			)
255
+		);
256
+	}
257
+
258
+
259
+	/**
260
+	 * reg_statuses_that_allow_payment
261
+	 * a filterable list of registration statuses that allow a registrant to make a payment
262
+	 *
263
+	 * @access public
264
+	 * @return array
265
+	 */
266
+	public static function reg_statuses_that_allow_payment()
267
+	{
268
+		return apply_filters(
269
+			'FHEE__EEM_Registration__reg_statuses_that_allow_payment',
270
+			array(
271
+				EEM_Registration::status_id_approved,
272
+				EEM_Registration::status_id_pending_payment,
273
+			)
274
+		);
275
+	}
276
+
277
+
278
+	/**
279
+	 * active_reg_statuses
280
+	 * a filterable list of registration statuses that are considered active
281
+	 *
282
+	 * @access public
283
+	 * @return array
284
+	 */
285
+	public static function active_reg_statuses()
286
+	{
287
+		return apply_filters(
288
+			'FHEE__EEM_Registration__active_reg_statuses',
289
+			array(
290
+				EEM_Registration::status_id_approved,
291
+				EEM_Registration::status_id_pending_payment,
292
+				EEM_Registration::status_id_wait_list,
293
+				EEM_Registration::status_id_not_approved,
294
+			)
295
+		);
296
+	}
297
+
298
+
299
+	/**
300
+	 * inactive_reg_statuses
301
+	 * a filterable list of registration statuses that are not considered active
302
+	 *
303
+	 * @access public
304
+	 * @return array
305
+	 */
306
+	public static function inactive_reg_statuses()
307
+	{
308
+		return apply_filters(
309
+			'FHEE__EEM_Registration__inactive_reg_statuses',
310
+			array(
311
+				EEM_Registration::status_id_incomplete,
312
+				EEM_Registration::status_id_cancelled,
313
+				EEM_Registration::status_id_declined,
314
+			)
315
+		);
316
+	}
317
+
318
+
319
+	/**
320
+	 *    closed_reg_statuses
321
+	 *    a filterable list of registration statuses that are considered "closed"
322
+	 * meaning they should not be considered in any calculations involving monies owing
323
+	 *
324
+	 * @access public
325
+	 * @return array
326
+	 */
327
+	public static function closed_reg_statuses()
328
+	{
329
+		return apply_filters(
330
+			'FHEE__EEM_Registration__closed_reg_statuses',
331
+			array(
332
+				EEM_Registration::status_id_cancelled,
333
+				EEM_Registration::status_id_declined,
334
+				EEM_Registration::status_id_wait_list,
335
+			)
336
+		);
337
+	}
338
+
339
+
340
+	/**
341
+	 *        get list of registration statuses
342
+	 *
343
+	 * @access public
344
+	 * @param array $exclude The status ids to exclude from the returned results
345
+	 * @param bool $translated If true will return the values as singular localized strings
346
+	 * @return array
347
+	 * @throws EE_Error
348
+	 */
349
+	public static function reg_status_array($exclude = array(), $translated = false)
350
+	{
351
+		EEM_Registration::instance()->_get_registration_status_array($exclude);
352
+		return $translated
353
+			? EEM_Status::instance()->localized_status(self::$_reg_status, false, 'sentence')
354
+			: self::$_reg_status;
355
+	}
356
+
357
+
358
+	/**
359
+	 *    get list of registration statuses
360
+	 *
361
+	 * @access private
362
+	 * @param array $exclude
363
+	 * @return void
364
+	 * @throws EE_Error
365
+	 */
366
+	private function _get_registration_status_array($exclude = array())
367
+	{
368
+		// in the very rare circumstance that we are deleting a model's table's data
369
+		// and the table hasn't actually been created, this could have an error
370
+		/** @type WPDB $wpdb */
371
+		global $wpdb;
372
+		if ($this->_get_table_analysis()->tableExists($wpdb->prefix . 'esp_status')) {
373
+			$results = $wpdb->get_results(
374
+				"SELECT STS_ID, STS_code FROM {$wpdb->prefix}esp_status WHERE STS_type = 'registration'"
375
+			);
376
+			self::$_reg_status = array();
377
+			foreach ($results as $status) {
378
+				if (!in_array($status->STS_ID, $exclude, true)) {
379
+					self::$_reg_status[ $status->STS_ID ] = $status->STS_code;
380
+				}
381
+			}
382
+		}
383
+	}
384
+
385
+
386
+	/**
387
+	 * Gets the injected table analyzer, or throws an exception
388
+	 *
389
+	 * @return TableAnalysis
390
+	 * @throws EE_Error
391
+	 */
392
+	protected function _get_table_analysis()
393
+	{
394
+		if ($this->_table_analysis instanceof TableAnalysis) {
395
+			return $this->_table_analysis;
396
+		}
397
+		throw new EE_Error(
398
+			sprintf(
399
+				esc_html__('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
400
+				get_class($this)
401
+			)
402
+		);
403
+	}
404
+
405
+
406
+	/**
407
+	 * This returns a wpdb->results array of all registration date month and years matching the incoming query params
408
+	 * and grouped by month and year.
409
+	 *
410
+	 * @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
411
+	 * @return array
412
+	 * @throws EE_Error
413
+	 */
414
+	public function get_reg_months_and_years($where_params)
415
+	{
416
+		$query_params[0] = $where_params;
417
+		$query_params['group_by'] = array('reg_year', 'reg_month');
418
+		$query_params['order_by'] = array('REG_date' => 'DESC');
419
+		$columns_to_select = array(
420
+			'reg_year' => array('YEAR(REG_date)', '%s'),
421
+			'reg_month' => array('MONTHNAME(REG_date)', '%s'),
422
+		);
423
+		return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
424
+	}
425
+
426
+
427
+	/**
428
+	 * retrieve ALL registrations for a particular Attendee from db
429
+	 *
430
+	 * @param int $ATT_ID
431
+	 * @return EE_Base_Class[]|EE_Registration[]|null
432
+	 * @throws EE_Error
433
+	 */
434
+	public function get_all_registrations_for_attendee($ATT_ID = 0)
435
+	{
436
+		if (!$ATT_ID) {
437
+			return null;
438
+		}
439
+		return $this->get_all(array(array('ATT_ID' => $ATT_ID)));
440
+	}
441
+
442
+
443
+	/**
444
+	 * Gets a registration given their REG_url_link. Yes, this should usually
445
+	 * be passed via a GET parameter.
446
+	 *
447
+	 * @param string $REG_url_link
448
+	 * @return EE_Base_Class|EE_Registration|null
449
+	 * @throws EE_Error
450
+	 */
451
+	public function get_registration_for_reg_url_link($REG_url_link)
452
+	{
453
+		if (!$REG_url_link) {
454
+			return null;
455
+		}
456
+		return $this->get_one(array(array('REG_url_link' => $REG_url_link)));
457
+	}
458
+
459
+
460
+	/**
461
+	 *        retrieve registration for a specific transaction attendee from db
462
+	 *
463
+	 * @access        public
464
+	 * @param    int $TXN_ID
465
+	 * @param    int $ATT_ID
466
+	 * @param    int $att_nmbr in case the ATT_ID is the same for multiple registrations (same details used) then the
467
+	 *                         attendee number is required
468
+	 * @return        mixed        array on success, FALSE on fail
469
+	 * @throws EE_Error
470
+	 */
471
+	public function get_registration_for_transaction_attendee($TXN_ID = 0, $ATT_ID = 0, $att_nmbr = 0)
472
+	{
473
+		return $this->get_one(array(
474
+			array(
475
+				'TXN_ID' => $TXN_ID,
476
+				'ATT_ID' => $ATT_ID,
477
+			),
478
+			'limit' => array(min($att_nmbr - 1, 0), 1),
479
+		));
480
+	}
481
+
482
+
483
+	/**
484
+	 *        get the number of registrations per day  for the Registration Admin page Reports Tab.
485
+	 *        (doesn't utilize models because it's a fairly specialized query)
486
+	 *
487
+	 * @access        public
488
+	 * @param $period string which can be passed to php's strtotime function (eg "-1 month")
489
+	 * @return stdClass[] with properties regDate and total
490
+	 * @throws EE_Error
491
+	 */
492
+	public function get_registrations_per_day_report($period = '-1 month')
493
+	{
494
+		$sql_date = $this->convert_datetime_for_query(
495
+			'REG_date',
496
+			date('Y-m-d H:i:s', strtotime($period)),
497
+			'Y-m-d H:i:s',
498
+			'UTC'
499
+		);
500
+		$where = array(
501
+			'REG_date' => array('>=', $sql_date),
502
+			'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
503
+		);
504
+		if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_day_report')) {
505
+			$where['Event.EVT_wp_user'] = get_current_user_id();
506
+		}
507
+		$query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'REG_date');
508
+		$results = $this->_get_all_wpdb_results(
509
+			array(
510
+				$where,
511
+				'group_by' => 'regDate',
512
+				'order_by' => array('REG_date' => 'ASC'),
513
+			),
514
+			OBJECT,
515
+			array(
516
+				'regDate' => array('DATE(' . $query_interval . ')', '%s'),
517
+				'total' => array('count(REG_ID)', '%d'),
518
+			)
519
+		);
520
+		return $results;
521
+	}
522
+
523
+
524
+	/**
525
+	 * Get the number of registrations per day including the count of registrations for each Registration Status.
526
+	 * Note: EEM_Registration::status_id_incomplete registrations are excluded from the results.
527
+	 *
528
+	 * @param string $period
529
+	 * @return stdClass[] with properties Registration_REG_date and a column for each registration status as the STS_ID
530
+	 * @throws EE_Error
531
+	 *                    (i.e. RAP)
532
+	 */
533
+	public function get_registrations_per_day_and_per_status_report($period = '-1 month')
534
+	{
535
+		global $wpdb;
536
+		$registration_table = $wpdb->prefix . 'esp_registration';
537
+		$event_table = $wpdb->posts;
538
+		$sql_date = date('Y-m-d H:i:s', strtotime($period));
539
+		// prepare the query interval for displaying offset
540
+		$query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'dates.REG_date');
541
+		// inner date query
542
+		$inner_date_query = "SELECT DISTINCT REG_date from {$registration_table} ";
543
+		$inner_where = ' WHERE';
544
+		// exclude events not authored by user if permissions in effect
545
+		if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
546
+			$inner_date_query .= "LEFT JOIN {$event_table} ON ID = EVT_ID";
547
+			$inner_where .= ' post_author = ' . get_current_user_id() . ' AND';
548
+		}
549
+		$inner_where .= " REG_date >= '{$sql_date}'";
550
+		$inner_date_query .= $inner_where;
551
+		// start main query
552
+		$select = "SELECT DATE({$query_interval}) as Registration_REG_date, ";
553
+		$join = '';
554
+		$join_parts = array();
555
+		$select_parts = array();
556
+		// loop through registration stati to do parts for each status.
557
+		foreach (EEM_Registration::reg_status_array() as $STS_ID => $STS_code) {
558
+			if ($STS_ID === EEM_Registration::status_id_incomplete) {
559
+				continue;
560
+			}
561
+			$select_parts[] = "COUNT({$STS_code}.REG_ID) as {$STS_ID}";
562
+			$join_parts[] = "{$registration_table} AS {$STS_code} ON {$STS_code}.REG_date = dates.REG_date AND {$STS_code}.STS_ID = '{$STS_ID}'";
563
+		}
564
+		// setup the selects
565
+		$select .= implode(', ', $select_parts);
566
+		$select .= " FROM ($inner_date_query) AS dates LEFT JOIN ";
567
+		// setup the joins
568
+		$join .= implode(' LEFT JOIN ', $join_parts);
569
+		// now let's put it all together
570
+		$query = $select . $join . ' GROUP BY Registration_REG_date';
571
+		// and execute it
572
+		return $wpdb->get_results($query, ARRAY_A);
573
+	}
574
+
575
+
576
+	/**
577
+	 *        get the number of registrations per event  for the Registration Admin page Reports Tab
578
+	 *
579
+	 * @access        public
580
+	 * @param $period string which can be passed to php's strtotime function (eg "-1 month")
581
+	 * @return stdClass[] each with properties event_name, reg_limit, and total
582
+	 * @throws EE_Error
583
+	 */
584
+	public function get_registrations_per_event_report($period = '-1 month')
585
+	{
586
+		$date_sql = $this->convert_datetime_for_query(
587
+			'REG_date',
588
+			date('Y-m-d H:i:s', strtotime($period)),
589
+			'Y-m-d H:i:s',
590
+			'UTC'
591
+		);
592
+		$where = array(
593
+			'REG_date' => array('>=', $date_sql),
594
+			'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
595
+		);
596
+		if (!EE_Registry::instance()->CAP->current_user_can(
597
+			'ee_read_others_registrations',
598
+			'reg_per_event_report'
599
+		)
600
+		) {
601
+			$where['Event.EVT_wp_user'] = get_current_user_id();
602
+		}
603
+		$results = $this->_get_all_wpdb_results(
604
+			array(
605
+			$where,
606
+			'group_by' => 'Event.EVT_name',
607
+			'order_by' => 'Event.EVT_name',
608
+			'limit' => array(0, 24),
609
+			),
610
+			OBJECT,
611
+			array(
612
+				'event_name' => array('Event_CPT.post_title', '%s'),
613
+				'total' => array('COUNT(REG_ID)', '%s'),
614
+			)
615
+		);
616
+		return $results;
617
+	}
618
+
619
+
620
+	/**
621
+	 * Get the number of registrations per event grouped by registration status.
622
+	 * Note: EEM_Registration::status_id_incomplete registrations are excluded from the results.
623
+	 *
624
+	 * @param string $period
625
+	 * @return stdClass[] with properties `Registration_Event` and a column for each registration status as the STS_ID
626
+	 * @throws EE_Error
627
+	 *                    (i.e. RAP)
628
+	 */
629
+	public function get_registrations_per_event_and_per_status_report($period = '-1 month')
630
+	{
631
+		global $wpdb;
632
+		$registration_table = $wpdb->prefix . 'esp_registration';
633
+		$event_table = $wpdb->posts;
634
+		$sql_date = date('Y-m-d H:i:s', strtotime($period));
635
+		// inner date query
636
+		$inner_date_query = "SELECT DISTINCT EVT_ID, REG_date from $registration_table ";
637
+		$inner_where = ' WHERE';
638
+		// exclude events not authored by user if permissions in effect
639
+		if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
640
+			$inner_date_query .= "LEFT JOIN {$event_table} ON ID = EVT_ID";
641
+			$inner_where .= ' post_author = ' . get_current_user_id() . ' AND';
642
+		}
643
+		$inner_where .= " REG_date >= '{$sql_date}'";
644
+		$inner_date_query .= $inner_where;
645
+		// build main query
646
+		$select = 'SELECT Event.post_title as Registration_Event, ';
647
+		$join = '';
648
+		$join_parts = array();
649
+		$select_parts = array();
650
+		// loop through registration stati to do parts for each status.
651
+		foreach (EEM_Registration::reg_status_array() as $STS_ID => $STS_code) {
652
+			if ($STS_ID === EEM_Registration::status_id_incomplete) {
653
+				continue;
654
+			}
655
+			$select_parts[] = "COUNT({$STS_code}.REG_ID) as {$STS_ID}";
656
+			$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";
657
+		}
658
+		// setup the selects
659
+		$select .= implode(', ', $select_parts);
660
+		$select .= " FROM ($inner_date_query) AS dates LEFT JOIN $event_table as Event ON Event.ID = dates.EVT_ID LEFT JOIN ";
661
+		// setup remaining joins
662
+		$join .= implode(' LEFT JOIN ', $join_parts);
663
+		// now put it all together
664
+		$query = $select . $join . ' GROUP BY Registration_Event';
665
+		// and execute
666
+		return $wpdb->get_results($query, ARRAY_A);
667
+	}
668
+
669
+
670
+	/**
671
+	 * Returns the EE_Registration of the primary attendee on the transaction id provided
672
+	 *
673
+	 * @param int $TXN_ID
674
+	 * @return EE_Base_Class|EE_Registration|null
675
+	 * @throws EE_Error
676
+	 */
677
+	public function get_primary_registration_for_transaction_ID($TXN_ID = 0)
678
+	{
679
+		if (!$TXN_ID) {
680
+			return null;
681
+		}
682
+		return $this->get_one(array(
683
+			array(
684
+				'TXN_ID' => $TXN_ID,
685
+				'REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT,
686
+			),
687
+		));
688
+	}
689
+
690
+
691
+	/**
692
+	 *        get_event_registration_count
693
+	 *
694
+	 * @access public
695
+	 * @param int $EVT_ID
696
+	 * @param boolean $for_incomplete_payments
697
+	 * @return int
698
+	 * @throws EE_Error
699
+	 */
700
+	public function get_event_registration_count($EVT_ID, $for_incomplete_payments = false)
701
+	{
702
+		// we only count approved registrations towards registration limits
703
+		$query_params = array(array('EVT_ID' => $EVT_ID, 'STS_ID' => self::status_id_approved));
704
+		if ($for_incomplete_payments) {
705
+			$query_params[0]['Transaction.STS_ID'] = array('!=', EEM_Transaction::complete_status_code);
706
+		}
707
+		return $this->count($query_params);
708
+	}
709
+
710
+
711
+	/**
712
+	 * Deletes all registrations with no transactions. Note that this needs to be very efficient
713
+	 * 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
714
+	 * when joining tables like this.
715
+	 *
716
+	 * @global WPDB $wpdb
717
+	 * @return int number deleted
718
+	 * @throws EE_Error
719
+	 */
720
+	public function delete_registrations_with_no_transaction()
721
+	{
722
+		/** @type WPDB $wpdb */
723
+		global $wpdb;
724
+		return $wpdb->query(
725
+			'DELETE r FROM '
726
+			. $this->table()
727
+			. ' r LEFT JOIN '
728
+			. EEM_Transaction::instance()->table()
729
+			. ' t ON r.TXN_ID = t.TXN_ID WHERE t.TXN_ID IS NULL'
730
+		);
731
+	}
732
+
733
+
734
+	/**
735
+	 *  Count registrations checked into (or out of) a datetime
736
+	 *
737
+	 * @param int $DTT_ID datetime ID
738
+	 * @param boolean $checked_in whether to count registrations checked IN or OUT
739
+	 * @return int
740
+	 * @throws EE_Error
741
+	 */
742
+	public function count_registrations_checked_into_datetime($DTT_ID, $checked_in = true)
743
+	{
744
+		global $wpdb;
745
+		// subquery to get latest checkin
746
+		$query = $wpdb->prepare(
747
+			'SELECT '
748
+			. 'COUNT( DISTINCT checkins.REG_ID ) '
749
+			. 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN'
750
+			. '( SELECT '
751
+			. 'max( CHK_timestamp ) AS latest_checkin, '
752
+			. 'REG_ID AS REG_ID '
753
+			. 'FROM ' . EEM_Checkin::instance()->table() . ' '
754
+			. 'WHERE DTT_ID=%d '
755
+			. 'GROUP BY REG_ID'
756
+			. ') AS most_recent_checkin_per_reg '
757
+			. 'ON checkins.REG_ID=most_recent_checkin_per_reg.REG_ID '
758
+			. 'AND checkins.CHK_timestamp = most_recent_checkin_per_reg.latest_checkin '
759
+			. 'WHERE '
760
+			. 'checkins.CHK_in=%d',
761
+			$DTT_ID,
762
+			$checked_in
763
+		);
764
+		return (int) $wpdb->get_var($query);
765
+	}
766
+
767
+
768
+	/**
769
+	 *  Count registrations checked into (or out of) an event.
770
+	 *
771
+	 * @param int $EVT_ID event ID
772
+	 * @param boolean $checked_in whether to count registrations checked IN or OUT
773
+	 * @return int
774
+	 * @throws EE_Error
775
+	 */
776
+	public function count_registrations_checked_into_event($EVT_ID, $checked_in = true)
777
+	{
778
+		global $wpdb;
779
+		// subquery to get latest checkin
780
+		$query = $wpdb->prepare(
781
+			'SELECT '
782
+			. 'COUNT( DISTINCT checkins.REG_ID ) '
783
+			. 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN'
784
+			. '( SELECT '
785
+			. 'max( CHK_timestamp ) AS latest_checkin, '
786
+			. 'REG_ID AS REG_ID '
787
+			. 'FROM ' . EEM_Checkin::instance()->table() . ' AS c '
788
+			. 'INNER JOIN ' . EEM_Datetime::instance()->table() . ' AS d '
789
+			. 'ON c.DTT_ID=d.DTT_ID '
790
+			. 'WHERE d.EVT_ID=%d '
791
+			. 'GROUP BY REG_ID'
792
+			. ') AS most_recent_checkin_per_reg '
793
+			. 'ON checkins.REG_ID=most_recent_checkin_per_reg.REG_ID '
794
+			. 'AND checkins.CHK_timestamp = most_recent_checkin_per_reg.latest_checkin '
795
+			. 'WHERE '
796
+			. 'checkins.CHK_in=%d',
797
+			$EVT_ID,
798
+			$checked_in
799
+		);
800
+		return (int) $wpdb->get_var($query);
801
+	}
802
+
803
+
804
+	/**
805
+	 * The purpose of this method is to retrieve an array of
806
+	 * EE_Registration objects that represent the latest registration
807
+	 * for each ATT_ID given in the function argument.
808
+	 *
809
+	 * @param array $attendee_ids
810
+	 * @return EE_Base_Class[]|EE_Registration[]
811
+	 * @throws EE_Error
812
+	 */
813
+	public function get_latest_registration_for_each_of_given_contacts($attendee_ids = array())
814
+	{
815
+		// first do a native wp_query to get the latest REG_ID's matching these attendees.
816
+		global $wpdb;
817
+		$registration_table = $wpdb->prefix . 'esp_registration';
818
+		$attendee_table = $wpdb->posts;
819
+		$attendee_ids = is_array($attendee_ids)
820
+			? array_map('absint', $attendee_ids)
821
+			: array((int) $attendee_ids);
822
+		$ATT_IDs = implode(',', $attendee_ids);
823
+		// first we do a query to get the registration ids
824
+		// (because a group by before order by causes the order by to be ignored.)
825
+		$registration_id_query = "
826 826
 			SELECT registrations.registration_ids as registration_id
827 827
 			FROM (
828 828
 				SELECT
@@ -836,61 +836,61 @@  discard block
 block discarded – undo
836 836
 			  ) AS registrations
837 837
 			  GROUP BY registrations.attendee_ids
838 838
 		";
839
-        $registration_ids = $wpdb->get_results($registration_id_query, ARRAY_A);
840
-        if (empty($registration_ids)) {
841
-            return array();
842
-        }
843
-        $ids_for_model_query = array();
844
-        // let's flatten the ids so they can be used in the model query.
845
-        foreach ($registration_ids as $registration_id) {
846
-            if (isset($registration_id['registration_id'])) {
847
-                $ids_for_model_query[] = $registration_id['registration_id'];
848
-            }
849
-        }
850
-        // construct query
851
-        $_where = array(
852
-            'REG_ID' => array('IN', $ids_for_model_query),
853
-        );
854
-        return $this->get_all(array($_where));
855
-    }
856
-
857
-
858
-
859
-    /**
860
-     * returns a count of registrations for the supplied event having the status as specified
861
-     *
862
-     * @param int $EVT_ID
863
-     * @param array $statuses
864
-     * @return int
865
-     * @throws InvalidArgumentException
866
-     * @throws InvalidStatusException
867
-     * @throws EE_Error
868
-     */
869
-    public function event_reg_count_for_statuses($EVT_ID, $statuses = array())
870
-    {
871
-        $EVT_ID = absint($EVT_ID);
872
-        if (! $EVT_ID) {
873
-            throw new InvalidArgumentException(
874
-                esc_html__('An invalid Event ID was supplied.', 'event_espresso')
875
-            );
876
-        }
877
-        $statuses = is_array($statuses) ? $statuses : array($statuses);
878
-        $statuses = ! empty($statuses) ? $statuses : array(EEM_Registration::status_id_approved);
879
-        $valid_reg_statuses = EEM_Registration::reg_statuses();
880
-        foreach ($statuses as $status) {
881
-            if (! in_array($status, $valid_reg_statuses, true)) {
882
-                throw new InvalidStatusException($status, esc_html__('Registration', 'event_espresso'));
883
-            }
884
-        }
885
-        return $this->count(
886
-            array(
887
-                array(
888
-                    'EVT_ID' => $EVT_ID,
889
-                    'STS_ID' => array('IN', $statuses),
890
-                ),
891
-            ),
892
-            'REG_ID',
893
-            true
894
-        );
895
-    }
839
+		$registration_ids = $wpdb->get_results($registration_id_query, ARRAY_A);
840
+		if (empty($registration_ids)) {
841
+			return array();
842
+		}
843
+		$ids_for_model_query = array();
844
+		// let's flatten the ids so they can be used in the model query.
845
+		foreach ($registration_ids as $registration_id) {
846
+			if (isset($registration_id['registration_id'])) {
847
+				$ids_for_model_query[] = $registration_id['registration_id'];
848
+			}
849
+		}
850
+		// construct query
851
+		$_where = array(
852
+			'REG_ID' => array('IN', $ids_for_model_query),
853
+		);
854
+		return $this->get_all(array($_where));
855
+	}
856
+
857
+
858
+
859
+	/**
860
+	 * returns a count of registrations for the supplied event having the status as specified
861
+	 *
862
+	 * @param int $EVT_ID
863
+	 * @param array $statuses
864
+	 * @return int
865
+	 * @throws InvalidArgumentException
866
+	 * @throws InvalidStatusException
867
+	 * @throws EE_Error
868
+	 */
869
+	public function event_reg_count_for_statuses($EVT_ID, $statuses = array())
870
+	{
871
+		$EVT_ID = absint($EVT_ID);
872
+		if (! $EVT_ID) {
873
+			throw new InvalidArgumentException(
874
+				esc_html__('An invalid Event ID was supplied.', 'event_espresso')
875
+			);
876
+		}
877
+		$statuses = is_array($statuses) ? $statuses : array($statuses);
878
+		$statuses = ! empty($statuses) ? $statuses : array(EEM_Registration::status_id_approved);
879
+		$valid_reg_statuses = EEM_Registration::reg_statuses();
880
+		foreach ($statuses as $status) {
881
+			if (! in_array($status, $valid_reg_statuses, true)) {
882
+				throw new InvalidStatusException($status, esc_html__('Registration', 'event_espresso'));
883
+			}
884
+		}
885
+		return $this->count(
886
+			array(
887
+				array(
888
+					'EVT_ID' => $EVT_ID,
889
+					'STS_ID' => array('IN', $statuses),
890
+				),
891
+			),
892
+			'REG_ID',
893
+			true
894
+		);
895
+	}
896 896
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Post_Meta.model.php 2 patches
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -18,56 +18,56 @@
 block discarded – undo
18 18
 class EEM_Post_Meta extends EEM_Base
19 19
 {
20 20
 
21
-    // private instance of the EE_Post_Meta object
22
-    protected static $_instance = null;
21
+	// private instance of the EE_Post_Meta object
22
+	protected static $_instance = null;
23 23
 
24 24
 
25 25
 
26
-    protected function __construct($timezone = null)
27
-    {
28
-        $this->singular_item = __('Post Meta', 'event_espresso');
29
-        $this->plural_item = __('Post Metas', 'event_espresso');
30
-        $this->_tables = array(
31
-            'Post_Meta' => new EE_Primary_Table('postmeta', 'meta_id'),
32
-        );
33
-        $models_this_can_attach_to = array_keys(EE_Registry::instance()->cpt_models());
34
-        $this->_fields = array(
35
-            'Post_Meta' => array(
36
-                'meta_id'    => new EE_Primary_Key_Int_Field(
37
-                    'meta_id',
38
-                    __("Meta ID", "event_espresso")
39
-                ),
40
-                'post_id'    => new EE_Foreign_Key_Int_Field(
41
-                    'post_id',
42
-                    __("Primary Key of Post", "event_espresso"),
43
-                    false,
44
-                    0,
45
-                    $models_this_can_attach_to
46
-                ),
47
-                'meta_key'   => new EE_Plain_Text_Field(
48
-                    'meta_key',
49
-                    __("Meta Key", "event_espresso"),
50
-                    false,
51
-                    ''
52
-                ),
53
-                'meta_value' => new EE_Maybe_Serialized_Text_Field(
54
-                    'meta_value',
55
-                    __("Meta Value", "event_espresso"),
56
-                    true
57
-                ),
58
-            ),
59
-        );
60
-        $this->_model_relations = array();
61
-        foreach ($models_this_can_attach_to as $model) {
62
-            $this->_model_relations[ $model ] = new EE_Belongs_To_Relation();
63
-        }
64
-        $this->_wp_core_model = true;
65
-        foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) {
66
-            $this->_cap_restriction_generators[ $cap_context ] = new EE_Restriction_Generator_Meta(
67
-                'meta_key',
68
-                'meta_value'
69
-            );
70
-        }
71
-        parent::__construct($timezone);
72
-    }
26
+	protected function __construct($timezone = null)
27
+	{
28
+		$this->singular_item = __('Post Meta', 'event_espresso');
29
+		$this->plural_item = __('Post Metas', 'event_espresso');
30
+		$this->_tables = array(
31
+			'Post_Meta' => new EE_Primary_Table('postmeta', 'meta_id'),
32
+		);
33
+		$models_this_can_attach_to = array_keys(EE_Registry::instance()->cpt_models());
34
+		$this->_fields = array(
35
+			'Post_Meta' => array(
36
+				'meta_id'    => new EE_Primary_Key_Int_Field(
37
+					'meta_id',
38
+					__("Meta ID", "event_espresso")
39
+				),
40
+				'post_id'    => new EE_Foreign_Key_Int_Field(
41
+					'post_id',
42
+					__("Primary Key of Post", "event_espresso"),
43
+					false,
44
+					0,
45
+					$models_this_can_attach_to
46
+				),
47
+				'meta_key'   => new EE_Plain_Text_Field(
48
+					'meta_key',
49
+					__("Meta Key", "event_espresso"),
50
+					false,
51
+					''
52
+				),
53
+				'meta_value' => new EE_Maybe_Serialized_Text_Field(
54
+					'meta_value',
55
+					__("Meta Value", "event_espresso"),
56
+					true
57
+				),
58
+			),
59
+		);
60
+		$this->_model_relations = array();
61
+		foreach ($models_this_can_attach_to as $model) {
62
+			$this->_model_relations[ $model ] = new EE_Belongs_To_Relation();
63
+		}
64
+		$this->_wp_core_model = true;
65
+		foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) {
66
+			$this->_cap_restriction_generators[ $cap_context ] = new EE_Restriction_Generator_Meta(
67
+				'meta_key',
68
+				'meta_value'
69
+			);
70
+		}
71
+		parent::__construct($timezone);
72
+	}
73 73
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -59,11 +59,11 @@
 block discarded – undo
59 59
         );
60 60
         $this->_model_relations = array();
61 61
         foreach ($models_this_can_attach_to as $model) {
62
-            $this->_model_relations[ $model ] = new EE_Belongs_To_Relation();
62
+            $this->_model_relations[$model] = new EE_Belongs_To_Relation();
63 63
         }
64 64
         $this->_wp_core_model = true;
65 65
         foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) {
66
-            $this->_cap_restriction_generators[ $cap_context ] = new EE_Restriction_Generator_Meta(
66
+            $this->_cap_restriction_generators[$cap_context] = new EE_Restriction_Generator_Meta(
67 67
                 'meta_key',
68 68
                 'meta_value'
69 69
             );
Please login to merge, or discard this patch.
core/db_models/fields/EE_Float_Field.php 1 patch
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -7,77 +7,77 @@
 block discarded – undo
7 7
 class EE_Float_Field extends EE_Model_Field_Base
8 8
 {
9 9
 
10
-    /**
11
-     * @param string $table_column
12
-     * @param string $nicename
13
-     * @param bool   $nullable
14
-     * @param null   $default_value
15
-     */
16
-    public function __construct($table_column, $nicename, $nullable, $default_value = null)
17
-    {
18
-        parent::__construct($table_column, $nicename, $nullable, $default_value);
19
-        $this->setSchemaType('number');
20
-    }
10
+	/**
11
+	 * @param string $table_column
12
+	 * @param string $nicename
13
+	 * @param bool   $nullable
14
+	 * @param null   $default_value
15
+	 */
16
+	public function __construct($table_column, $nicename, $nullable, $default_value = null)
17
+	{
18
+		parent::__construct($table_column, $nicename, $nullable, $default_value);
19
+		$this->setSchemaType('number');
20
+	}
21 21
 
22 22
 
23
-    /**
24
-     * If provided a string, strips out number-related formatting, like commas, periods, spaces, other junk, etc.
25
-     * However, treats commas and periods as thousand-separators ro decimal marks, as indicate by the config's currency.
26
-     * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, call floatval() on it first.
27
-     * Returns a float
28
-     *
29
-     * @param type $value_inputted_for_field_on_model_object
30
-     * @return float
31
-     */
32
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
33
-    {
23
+	/**
24
+	 * If provided a string, strips out number-related formatting, like commas, periods, spaces, other junk, etc.
25
+	 * However, treats commas and periods as thousand-separators ro decimal marks, as indicate by the config's currency.
26
+	 * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, call floatval() on it first.
27
+	 * Returns a float
28
+	 *
29
+	 * @param type $value_inputted_for_field_on_model_object
30
+	 * @return float
31
+	 */
32
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
33
+	{
34 34
 //      echo __LINE__."$value_inputted_for_field_on_model_object<br>";
35
-        // remove whitespaces and thousands separators
36
-        if (is_string($value_inputted_for_field_on_model_object)) {
37
-            $value_inputted_for_field_on_model_object = str_replace(
38
-                array(" ", EE_Config::instance()->currency->thsnds),
39
-                "",
40
-                $value_inputted_for_field_on_model_object
41
-            );
35
+		// remove whitespaces and thousands separators
36
+		if (is_string($value_inputted_for_field_on_model_object)) {
37
+			$value_inputted_for_field_on_model_object = str_replace(
38
+				array(" ", EE_Config::instance()->currency->thsnds),
39
+				"",
40
+				$value_inputted_for_field_on_model_object
41
+			);
42 42
 // echo __LINE__."$value_inputted_for_field_on_model_object<br>";
43 43
 // normalize it so periods are decimal marks (we don't care where you're from: we're talking PHP now)
44
-            $value_inputted_for_field_on_model_object = str_replace(
45
-                EE_Config::instance()->currency->dec_mrk,
46
-                ".",
47
-                $value_inputted_for_field_on_model_object
48
-            );
44
+			$value_inputted_for_field_on_model_object = str_replace(
45
+				EE_Config::instance()->currency->dec_mrk,
46
+				".",
47
+				$value_inputted_for_field_on_model_object
48
+			);
49 49
 // echo __LINE__."$value_inputted_for_field_on_model_object<br>";
50 50
 // double-check there's absolutely nothing left on this string besides numbers
51
-            $value_inputted_for_field_on_model_object = preg_replace(
52
-                "/[^0-9,.]/",
53
-                "",
54
-                $value_inputted_for_field_on_model_object
55
-            );
56
-        }
51
+			$value_inputted_for_field_on_model_object = preg_replace(
52
+				"/[^0-9,.]/",
53
+				"",
54
+				$value_inputted_for_field_on_model_object
55
+			);
56
+		}
57 57
 //      echo __LINE__."$value_inputted_for_field_on_model_object<br>";
58
-        return floatval($value_inputted_for_field_on_model_object);
59
-    }
58
+		return floatval($value_inputted_for_field_on_model_object);
59
+	}
60 60
 
61
-    /**
62
-     * Returns the number formatted according to local custom (set by the country of the blog).
63
-     *
64
-     * @param float $value_on_field_to_be_outputted
65
-     * @return string
66
-     */
67
-    public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
68
-    {
69
-        $EE = EE_Registry::instance();
70
-        return number_format(
71
-            $value_on_field_to_be_outputted,
72
-            $EE->CFG->currency->dec_plc,
73
-            $EE->CFG->currency->dec_mrk,
74
-            $EE->CFG->currency->thsnds
75
-        );
76
-    }
61
+	/**
62
+	 * Returns the number formatted according to local custom (set by the country of the blog).
63
+	 *
64
+	 * @param float $value_on_field_to_be_outputted
65
+	 * @return string
66
+	 */
67
+	public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
68
+	{
69
+		$EE = EE_Registry::instance();
70
+		return number_format(
71
+			$value_on_field_to_be_outputted,
72
+			$EE->CFG->currency->dec_plc,
73
+			$EE->CFG->currency->dec_mrk,
74
+			$EE->CFG->currency->thsnds
75
+		);
76
+	}
77 77
 
78
-    public function prepare_for_set_from_db($value_found_in_db_for_model_object)
79
-    {
78
+	public function prepare_for_set_from_db($value_found_in_db_for_model_object)
79
+	{
80 80
 //      echo "prepare for set from db of ";d($value_found_in_db_for_model_object);
81
-        return floatval($value_found_in_db_for_model_object);
82
-    }
81
+		return floatval($value_found_in_db_for_model_object);
82
+	}
83 83
 }
Please login to merge, or discard this patch.
core/db_models/fields/EE_All_Caps_Text_Field.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -6,14 +6,14 @@
 block discarded – undo
6 6
  */
7 7
 class EE_All_Caps_Text_Field extends EE_Text_Field_Base
8 8
 {
9
-    /**
10
-     * makes it all upper case, and key-like
11
-     *
12
-     * @param string $value_inputted_for_field_on_model_object
13
-     * @return string
14
-     */
15
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
16
-    {
17
-        return strtoupper(sanitize_key($value_inputted_for_field_on_model_object));
18
-    }
9
+	/**
10
+	 * makes it all upper case, and key-like
11
+	 *
12
+	 * @param string $value_inputted_for_field_on_model_object
13
+	 * @return string
14
+	 */
15
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
16
+	{
17
+		return strtoupper(sanitize_key($value_inputted_for_field_on_model_object));
18
+	}
19 19
 }
Please login to merge, or discard this patch.
core/db_models/fields/EE_Text_Field_Base.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -7,49 +7,49 @@
 block discarded – undo
7 7
 abstract class EE_Text_Field_Base extends EE_Model_Field_Base
8 8
 {
9 9
 
10
-    /**
11
-     * Gets the value in the format expected when being set.
12
-     * For display on the front-end, usually you would use prepare_for_pretty_echoing() instead.
13
-     * @param mixed $value_of_field_on_model_object
14
-     * @return mixed|string
15
-     */
16
-    public function prepare_for_get($value_of_field_on_model_object)
17
-    {
18
-        return $value_of_field_on_model_object;
19
-    }
10
+	/**
11
+	 * Gets the value in the format expected when being set.
12
+	 * For display on the front-end, usually you would use prepare_for_pretty_echoing() instead.
13
+	 * @param mixed $value_of_field_on_model_object
14
+	 * @return mixed|string
15
+	 */
16
+	public function prepare_for_get($value_of_field_on_model_object)
17
+	{
18
+		return $value_of_field_on_model_object;
19
+	}
20 20
 
21
-    /**
22
-     * Accepts schema of 'form_input' which formats the string for echoing in form input's value.
23
-     *
24
-     * @param string $value_on_field_to_be_outputted
25
-     * @param string $schema
26
-     * @return string
27
-     */
28
-    public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
29
-    {
30
-        if ($schema === 'form_input') {
31
-            $value_on_field_to_be_outputted = (string) htmlentities(
32
-                $value_on_field_to_be_outputted,
33
-                ENT_QUOTES,
34
-                'UTF-8'
35
-            );
36
-        }
37
-        return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted);
38
-    }
21
+	/**
22
+	 * Accepts schema of 'form_input' which formats the string for echoing in form input's value.
23
+	 *
24
+	 * @param string $value_on_field_to_be_outputted
25
+	 * @param string $schema
26
+	 * @return string
27
+	 */
28
+	public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
29
+	{
30
+		if ($schema === 'form_input') {
31
+			$value_on_field_to_be_outputted = (string) htmlentities(
32
+				$value_on_field_to_be_outputted,
33
+				ENT_QUOTES,
34
+				'UTF-8'
35
+			);
36
+		}
37
+		return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted);
38
+	}
39 39
 
40
-    /**
41
-     * Data received from the user should be exactly as they hope to save it in the DB, with the exception that
42
-     * quotes need to have slashes added to it. This method takes care of removing the slashes added by WP
43
-     * in magic-quotes fashion. We used to call html_entity_decode on the value here,
44
-     * because we called htmlentities when in EE_Text_Field_Base::prepare_for_pretty_echoing, but that's not necessary
45
-     * because web browsers always decode HTML entities in element attributes, like a form element's value attribute.
46
-     * So if we do it again here, we'll be removing HTML entities the user intended to have.)
47
-     *
48
-     * @param string $value_inputted_for_field_on_model_object
49
-     * @return string
50
-     */
51
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
52
-    {
53
-        return stripslashes(parent::prepare_for_set($value_inputted_for_field_on_model_object));
54
-    }
40
+	/**
41
+	 * Data received from the user should be exactly as they hope to save it in the DB, with the exception that
42
+	 * quotes need to have slashes added to it. This method takes care of removing the slashes added by WP
43
+	 * in magic-quotes fashion. We used to call html_entity_decode on the value here,
44
+	 * because we called htmlentities when in EE_Text_Field_Base::prepare_for_pretty_echoing, but that's not necessary
45
+	 * because web browsers always decode HTML entities in element attributes, like a form element's value attribute.
46
+	 * So if we do it again here, we'll be removing HTML entities the user intended to have.)
47
+	 *
48
+	 * @param string $value_inputted_for_field_on_model_object
49
+	 * @return string
50
+	 */
51
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
52
+	{
53
+		return stripslashes(parent::prepare_for_set($value_inputted_for_field_on_model_object));
54
+	}
55 55
 }
Please login to merge, or discard this patch.