Completed
Branch TASK-9118-extensions-page (b89c2b)
by
unknown
506:56 queued 485:08
created

EEM_Attendee::__construct()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 46
Code Lines 40

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 46
rs 8.9412
cc 1
eloc 40
nc 1
nop 1
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),
0 ignored issues
show
Documentation introduced by
0 is of type integer, but the function expects a null.

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...
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, ''),
1 ignored issue
show
Documentation introduced by
'' is of type string, but the function expects a null.

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...
147
				'ATT_lname'=>new EE_Plain_Text_Field('ATT_lname', __('Last Name','event_espresso'), true, ''),
1 ignored issue
show
Documentation introduced by
'' is of type string, but the function expects a null.

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...
148
				'ATT_address'=>new EE_Plain_Text_Field('ATT_address', __('Address Part 1','event_espresso'), true, ''),
1 ignored issue
show
Documentation introduced by
'' is of type string, but the function expects a null.

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...
149
				'ATT_address2'=>new EE_Plain_Text_Field('ATT_address2', __('Address Part 2','event_espresso'), true, ''),
1 ignored issue
show
Documentation introduced by
'' is of type string, but the function expects a null.

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...
150
				'ATT_city'=>new EE_Plain_Text_Field('ATT_city', __('City','event_espresso'), true, ''),
1 ignored issue
show
Documentation introduced by
'' is of type string, but the function expects a null.

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...
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, ''),
1 ignored issue
show
Documentation introduced by
'' is of type string, but the function expects a null.

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...
154
				'ATT_email'=>new EE_Email_Field('ATT_email', __('Email Address','event_espresso'), true, ''),
1 ignored issue
show
Documentation introduced by
'' is of type string, but the function expects a null.

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...
155
				'ATT_phone'=>new EE_Plain_Text_Field('ATT_phone', __('Phone','event_espresso'), true, '')
1 ignored issue
show
Documentation introduced by
'' is of type string, but the function expects a null.

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...
156
			));
157
		$this->_model_relations = array(
0 ignored issues
show
Documentation Bug introduced by
It seems like array('Registration' => ..._Belongs_To_Relation()) of type array<string,object<EE_H...Belongs_To_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 ),
162
			'WP_User' => new EE_Belongs_To_Relation(),
163
		);
164
		$this->_caps_slug = 'contacts';
165
		parent::__construct( $timezone );
166
167
	}
168
169
	/**
170
	 * Gets the name of the field on the attendee model corresponding to the system question string
171
	 * which should be one of the keys from EEM_Attendee::_system_question_to_attendee_field_name
172
	 * @param string $system_question_string
173
	 * @return string|null if not found
174
	 */
175
	public function get_attendee_field_for_system_question( $system_question_string ) {
176
		return isset( $this->_system_question_to_attendee_field_name[ $system_question_string ] ) ? $this->_system_question_to_attendee_field_name[ $system_question_string ] : null;
177
	}
178
179
180
181
182
	/**
183
	 * Gets all the attendees for a transaction (by using the esp_registration as a join table)
184
	 * @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...
185
	 * @return EE_Attendee[]
186
	 */
187
	public function get_attendees_for_transaction( $transaction_id_or_obj ){
188
		return $this->get_all( array( array(
189
			  'Registration.Transaction.TXN_ID' => $transaction_id_or_obj instanceof EE_Transaction ? $transaction_id_or_obj->ID() : $transaction_id_or_obj
190
		  )));
191
	}
192
193
194
195
	/**
196
	*		retrieve  a single attendee from db via their ID
197
	*
198
	* 		@access		public
199
	* 		@param		$ATT_ID
200
	*		@return 		mixed		array on success, FALSE on fail
201
	 * 		@deprecated
202
	*/
203
	public function get_attendee_by_ID( $ATT_ID = FALSE ) {
204
		// retrieve a particular EE_Attendee
205
		return $this->get_one_by_ID( $ATT_ID );
206
	}
207
208
209
210
211
	/**
212
	*		retrieve  a single attendee from db via their ID
213
	*
214
	* 		@access		public
215
	* 		@param		array $where_cols_n_values
216
	*		@return 		mixed		array on success, FALSE on fail
217
	*/
218
	public function get_attendee( $where_cols_n_values = array() ) {
219
220
		if ( empty( $where_cols_n_values )) {
221
			return FALSE;
222
		}
223
		$attendee = $this->get_all( array($where_cols_n_values ));
224
		if ( ! empty( $attendee )) {
225
			return array_shift( $attendee );
226
		} else {
227
			return FALSE;
228
		}
229
230
	}
231
232
233
234
	/**
235
	 *        Search for an existing Attendee record in the DB
236
	 *
237
	 * @access        public
238
	 * @param array $where_cols_n_values
239
	 * @return bool|mixed
240
	 */
241
	public function find_existing_attendee( $where_cols_n_values = NULL ) {
242
		// search by combo of first and last names plus the email address
243
		$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...
244
		// no search params means attendee object already exists.
245
		$where_cols_n_values = is_array( $where_cols_n_values ) && ! empty( $where_cols_n_values ) ? $where_cols_n_values : $attendee_data_keys;
246
		$valid_data = TRUE;
247
		// check for required values
248
		$valid_data = isset( $where_cols_n_values['ATT_fname'] ) && ! empty( $where_cols_n_values['ATT_fname'] ) ? $valid_data : FALSE;
249
		$valid_data = isset( $where_cols_n_values['ATT_lname'] ) && ! empty( $where_cols_n_values['ATT_lname'] ) ? $valid_data : FALSE;
250
		$valid_data = isset( $where_cols_n_values['ATT_email'] ) && ! empty( $where_cols_n_values['ATT_email'] ) ? $valid_data : FALSE;
251
252
		if ( $valid_data ) {
253
			$attendee = $this->get_attendee( $where_cols_n_values );
254
			if ( $attendee instanceof EE_Attendee ) {
255
				return $attendee;
256
			}
257
		}
258
		return FALSE;
259
260
	}
261
262
263
264
	/**
265
             * Takes an incoming array of EE_Registration ids and sends back a list of corresponding non duplicate
266
             * EE_Attendee objects.
267
             *
268
             * @since    4.3.0
269
             * @param  array $ids array of EE_Registration ids
270
             * @return  EE_Attendee[]
271
             */
272
            public function get_array_of_contacts_from_reg_ids( $ids ) {
273
                $ids = (array) $ids;
274
                $_where = array(
275
                    'Registration.REG_ID' => array( 'in', $ids )
276
                    );
277
                return $this->get_all( array( $_where ) );
278
            }
279
280
281
}
282
// End of file EEM_Attendee.model.php
283
// Location: /ee-mvc/models/EEM_Attendee.model.php
284