Completed
Branch BUG-9623-config-log (c144cd)
by
unknown
527:42 queued 509:06
created

EEM_Attendee::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 47
Code Lines 41

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 41
nc 1
nop 1
dl 0
loc 47
rs 9.0303
c 0
b 0
f 0
1
<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
2
require_once ( EE_MODELS . 'EEM_Base.model.php' );
3
4
/**
5
 *
6
 * Attendee Model
7
 *
8
 * @package			Event Espresso
9
 * @subpackage		includes/models/
10
 * @author				Mike Nelson, Brent Christensen
11
 */
12
13
class EEM_Attendee extends EEM_CPT_Base {
14
15
  	// private instance of the Attendee object
16
	protected static $_instance = NULL;
17
18
	/**
19
	 * QST_system for questions are strings not ints now,
20
	 * so these constants are deprecated.
21
	 * Please instead use the EEM_Attendee::system_question_* constants
22
	 * @deprecated
23
	 */
24
	const fname_question_id=1;
25
26
	/**
27
	 * @deprecated
28
	 */
29
	const lname_question_id=2;
30
31
32
	/**
33
	 * @deprecated
34
	 */
35
	const email_question_id=3;
36
37
38
	/**
39
	 * @deprecated
40
	 */
41
	const address_question_id=4;
42
43
44
	/**
45
	 * @deprecated
46
	 */
47
	const address2_question_id=5;
48
49
50
	/**
51
	 * @deprecated
52
	 */
53
	const city_question_id=6;
54
55
56
	/**
57
	 * @deprecated
58
	 */
59
	const state_question_id=7;
60
61
62
	/**
63
	 * @deprecated
64
	 */
65
	const country_question_id=8;
66
67
68
	/**
69
	 * @deprecated
70
	 */
71
	const zip_question_id=9;
72
73
74
	/**
75
	 * @deprecated
76
	 */
77
	const phone_question_id=10;
78
79
	/**
80
	 * When looking for questions that correspond to attendee fields,
81
	 * look for the question with this QST_system value.
82
	 * These replace the old constants like EEM_Attendee::*_question_id
83
	 */
84
	const system_question_fname = 'fname';
85
	const system_question_lname = 'lname';
86
	const system_question_email = 'email';
87
	const system_question_address = 'address';
88
	const system_question_address2 = 'address2';
89
	const system_question_city = 'city';
90
	const system_question_state = 'state';
91
	const system_question_country = 'country';
92
	const system_question_zip = 'zip';
93
	const system_question_phone = 'phone';
94
95
	/**
96
	 * Keys are all the EEM_Attendee::system_question_* constants, which are
97
	 * also all the values of QST_system in the questions table, and values
98
	 * are their corresponding Attendee field names
99
	 * @var array
100
	 */
101
	protected $_system_question_to_attendee_field_name = array(
102
		EEM_Attendee::system_question_fname => 'ATT_fname',
103
		EEM_Attendee::system_question_lname => 'ATT_lname',
104
		EEM_Attendee::system_question_email => 'ATT_email',
105
		EEM_Attendee::system_question_address => 'ATT_address',
106
		EEM_Attendee::system_question_address2 => 'ATT_address2',
107
		EEM_Attendee::system_question_city => 'ATT_city',
108
		EEM_Attendee::system_question_state => 'STA_ID',
109
		EEM_Attendee::system_question_country => 'CNT_ISO',
110
		EEM_Attendee::system_question_zip => 'ATT_zip',
111
		EEM_Attendee::system_question_phone => 'ATT_phone',
112
	);
113
114
115
	/**
116
	 *        private constructor to prevent direct creation
117
	 *
118
	 * @Constructor
119
	 * @access protected
120
	 * @param null $timezone
121
	 */
122
	protected function __construct( $timezone = NULL ) {
123
		$this->singular_item = __('Attendee','event_espresso');
124
		$this->plural_item = __('Attendees','event_espresso');
125
		$this->_tables = array(
0 ignored issues
show
Documentation Bug introduced by
It seems like array('Attendee_CPT' => ..., 'ATTM_ID', 'ATT_ID')) of type array<string,object<EE_P...<EE_Secondary_Table>"}> is incompatible with the declared type array<integer,object<EE_Table_Base>> of property $_tables.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
126
			'Attendee_CPT'=> new EE_Primary_Table('posts', 'ID'),
127
			'Attendee_Meta'=>new EE_Secondary_Table('esp_attendee_meta', 'ATTM_ID', 'ATT_ID')
128
		);
129
		$this->_fields = array(
0 ignored issues
show
Documentation Bug introduced by
It seems like array('Attendee_CPT' => ...espresso'), true, ''))) of type array<string,array<strin...lain_Text_Field>\"}>"}> is incompatible with the declared type array<integer,object<EE_Model_Field_Base>> of property $_fields.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
130
			'Attendee_CPT'=>array(
131
				'ATT_ID'=>new EE_Primary_Key_Int_Field('ID', __("Attendee ID", "event_espresso")),
132
				'ATT_full_name'=>new EE_Plain_Text_Field('post_title', __("Attendee Full Name", "event_espresso"), false, __("Unknown", "event_espresso")),
133
				'ATT_bio'=>new EE_Post_Content_Field('post_content', __("Attendee Biography", "event_espresso"), false, __("No Biography Provided", "event_espresso")),
134
				'ATT_slug'=>new EE_Slug_Field('post_name', __("Attendee URL Slug", "event_espresso"), false),
135
				'ATT_created'=>new EE_Datetime_Field('post_date', __("Time Attendee Created", "event_espresso"), false, time()),
136
				'ATT_short_bio'=>new EE_Simple_HTML_Field('post_excerpt', __("Attendee Short Biography", "event_espresso"), true, __("No Biography Provided", "event_espresso")),
137
				'ATT_modified'=>new EE_Datetime_Field('post_modified', __("Time Attendee Last Modified", "event_espresso"), FALSE, time()),
138
				'ATT_author'=>new EE_WP_User_Field('post_author', __("Creator ID of the first Event attended", "event_espresso"), false ),
139
				'ATT_parent'=>new EE_DB_Only_Int_Field('post_parent', __("Parent Attendee (unused)", "event_espresso"), false, 0),
140
				'post_type'=>new EE_WP_Post_Type_Field('espresso_attendees'),// EE_DB_Only_Text_Field('post_type', __("Post Type of Attendee", "event_espresso"), false,'espresso_attendees'),
141
				'status' => new EE_WP_Post_Status_Field('post_status', __('Attendee Status', 'event_espresso'), false, 'publish')
142
			),
143
			'Attendee_Meta'=>array(
144
				'ATTM_ID'=> new EE_DB_Only_Int_Field('ATTM_ID', __('Attendee Meta Row ID','event_espresso'), false),
145
				'ATT_ID_fk'=>new EE_DB_Only_Int_Field('ATT_ID', __("Foreign Key to Attendee in Post Table", "event_espresso"), false),
146
				'ATT_fname'=>new EE_Plain_Text_Field('ATT_fname', __('First Name','event_espresso'), true, ''),
147
				'ATT_lname'=>new EE_Plain_Text_Field('ATT_lname', __('Last Name','event_espresso'), true, ''),
148
				'ATT_address'=>new EE_Plain_Text_Field('ATT_address', __('Address Part 1','event_espresso'), true, ''),
149
				'ATT_address2'=>new EE_Plain_Text_Field('ATT_address2', __('Address Part 2','event_espresso'), true, ''),
150
				'ATT_city'=>new EE_Plain_Text_Field('ATT_city', __('City','event_espresso'), true, ''),
151
				'STA_ID'=>new EE_Foreign_Key_Int_Field('STA_ID', __('State','event_espresso'), true,0,'State'),
152
				'CNT_ISO'=>new EE_Foreign_Key_String_Field('CNT_ISO', __('Country','event_espresso'), true,'','Country'),
153
				'ATT_zip'=>new EE_Plain_Text_Field('ATT_zip', __('ZIP/Postal Code','event_espresso'), true, ''),
154
				'ATT_email'=>new EE_Email_Field('ATT_email', __('Email Address','event_espresso'), true, ''),
155
				'ATT_phone'=>new EE_Plain_Text_Field('ATT_phone', __('Phone','event_espresso'), true, '')
156
			));
157
		$this->_model_relations = array(
0 ignored issues
show
Documentation Bug introduced by
It seems like array('Registration' => ...ny_Any_Relation(false)) of type array<string,object<EE_H...s_Many_Any_Relation>"}> is incompatible with the declared type array<integer,object<EE_Model_Relation_Base>> of property $_model_relations.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
158
			'Registration'=>new EE_Has_Many_Relation(),
159
			'State'=>new EE_Belongs_To_Relation(),
160
			'Country'=>new EE_Belongs_To_Relation(),
161
			'Event'=>new EE_HABTM_Relation('Registration', FALSE ),
0 ignored issues
show
Documentation introduced by
'Registration' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
162
			'WP_User' => new EE_Belongs_To_Relation(),
163
			'Message' => new EE_Has_Many_Any_Relation( false ) //allow deletion of attendees even if they have messages in the queue for them.
164
		);
165
		$this->_caps_slug = 'contacts';
166
		parent::__construct( $timezone );
167
168
	}
169
170
	/**
171
	 * Gets the name of the field on the attendee model corresponding to the system question string
172
	 * which should be one of the keys from EEM_Attendee::_system_question_to_attendee_field_name
173
	 * @param string $system_question_string
174
	 * @return string|null if not found
175
	 */
176
	public function get_attendee_field_for_system_question( $system_question_string ) {
177
		return isset( $this->_system_question_to_attendee_field_name[ $system_question_string ] ) ? $this->_system_question_to_attendee_field_name[ $system_question_string ] : null;
178
	}
179
180
181
182
183
	/**
184
	 * Gets all the attendees for a transaction (by using the esp_registration as a join table)
185
	 * @param EE_Transaction/int $transaction_id_or_obj EE_Transaction or its ID
0 ignored issues
show
Documentation introduced by
The doc-type EE_Transaction/int could not be parsed: Unknown type name "EE_Transaction/int" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
186
	 * @return EE_Attendee[]
187
	 */
188
	public function get_attendees_for_transaction( $transaction_id_or_obj ){
189
		return $this->get_all( array( array(
190
			  'Registration.Transaction.TXN_ID' => $transaction_id_or_obj instanceof EE_Transaction ? $transaction_id_or_obj->ID() : $transaction_id_or_obj
191
		  )));
192
	}
193
194
195
196
	/**
197
	*		retrieve  a single attendee from db via their ID
198
	*
199
	* 		@access		public
200
	* 		@param		$ATT_ID
201
	*		@return 		mixed		array on success, FALSE on fail
202
	 * 		@deprecated
203
	*/
204
	public function get_attendee_by_ID( $ATT_ID = FALSE ) {
205
		// retrieve a particular EE_Attendee
206
		return $this->get_one_by_ID( $ATT_ID );
207
	}
208
209
210
211
212
	/**
213
	*		retrieve  a single attendee from db via their ID
214
	*
215
	* 		@access		public
216
	* 		@param		array $where_cols_n_values
217
	*		@return 		mixed		array on success, FALSE on fail
218
	*/
219
	public function get_attendee( $where_cols_n_values = array() ) {
220
221
		if ( empty( $where_cols_n_values )) {
222
			return FALSE;
223
		}
224
		$attendee = $this->get_all( array($where_cols_n_values ));
225
		if ( ! empty( $attendee )) {
226
			return array_shift( $attendee );
227
		} else {
228
			return FALSE;
229
		}
230
231
	}
232
233
234
235
	/**
236
	 *        Search for an existing Attendee record in the DB
237
	 *
238
	 * @access        public
239
	 * @param array $where_cols_n_values
240
	 * @return bool|mixed
241
	 */
242
	public function find_existing_attendee( $where_cols_n_values = NULL ) {
243
		// search by combo of first and last names plus the email address
244
		$attendee_data_keys = array( 'ATT_fname' => $this->_ATT_fname, 'ATT_lname' => $this->_ATT_lname, 'ATT_email' => $this->_ATT_email );
0 ignored issues
show
Documentation introduced by
The property _ATT_fname does not exist on object<EEM_Attendee>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property _ATT_lname does not exist on object<EEM_Attendee>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property _ATT_email does not exist on object<EEM_Attendee>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
245
		// no search params means attendee object already exists.
246
		$where_cols_n_values = is_array( $where_cols_n_values ) && ! empty( $where_cols_n_values ) ? $where_cols_n_values : $attendee_data_keys;
247
		$valid_data = TRUE;
248
		// check for required values
249
		$valid_data = isset( $where_cols_n_values['ATT_fname'] ) && ! empty( $where_cols_n_values['ATT_fname'] ) ? $valid_data : FALSE;
250
		$valid_data = isset( $where_cols_n_values['ATT_lname'] ) && ! empty( $where_cols_n_values['ATT_lname'] ) ? $valid_data : FALSE;
251
		$valid_data = isset( $where_cols_n_values['ATT_email'] ) && ! empty( $where_cols_n_values['ATT_email'] ) ? $valid_data : FALSE;
252
253
		if ( $valid_data ) {
254
			$attendee = $this->get_attendee( $where_cols_n_values );
255
			if ( $attendee instanceof EE_Attendee ) {
256
				return $attendee;
257
			}
258
		}
259
		return FALSE;
260
261
	}
262
263
264
265
	/**
266
             * Takes an incoming array of EE_Registration ids and sends back a list of corresponding non duplicate
267
             * EE_Attendee objects.
268
             *
269
             * @since    4.3.0
270
             * @param  array $ids array of EE_Registration ids
271
             * @return  EE_Attendee[]
272
             */
273
            public function get_array_of_contacts_from_reg_ids( $ids ) {
274
                $ids = (array) $ids;
275
                $_where = array(
276
                    'Registration.REG_ID' => array( 'in', $ids )
277
                    );
278
                return $this->get_all( array( $_where ) );
279
            }
280
281
282
}
283
// End of file EEM_Attendee.model.php
284
// Location: /ee-mvc/models/EEM_Attendee.model.php
285