@@ -10,143 +10,143 @@ |
||
| 10 | 10 | abstract class EE_Configurable extends EE_Base |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * @var $_config |
|
| 15 | - * @type EE_Config_Base |
|
| 16 | - */ |
|
| 17 | - protected $_config; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * @var $_config_section |
|
| 21 | - * @type string |
|
| 22 | - */ |
|
| 23 | - protected $_config_section = ''; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @var $_config_class |
|
| 27 | - * @type string |
|
| 28 | - */ |
|
| 29 | - protected $_config_class = ''; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var $_config_name |
|
| 33 | - * @type string |
|
| 34 | - */ |
|
| 35 | - protected $_config_name = ''; |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @param string $config_section |
|
| 40 | - */ |
|
| 41 | - public function set_config_section($config_section = '') |
|
| 42 | - { |
|
| 43 | - $this->_config_section = ! empty($config_section) ? $config_section : 'modules'; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @return mixed |
|
| 49 | - */ |
|
| 50 | - public function config_section() |
|
| 51 | - { |
|
| 52 | - return $this->_config_section; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @param string $config_class |
|
| 58 | - */ |
|
| 59 | - public function set_config_class($config_class = '') |
|
| 60 | - { |
|
| 61 | - $this->_config_class = $config_class; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @return mixed |
|
| 67 | - */ |
|
| 68 | - public function config_class() |
|
| 69 | - { |
|
| 70 | - return $this->_config_class; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @param mixed $config_name |
|
| 76 | - */ |
|
| 77 | - public function set_config_name($config_name) |
|
| 78 | - { |
|
| 79 | - $this->_config_name = ! empty($config_name) ? $config_name : get_called_class(); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @return mixed |
|
| 85 | - */ |
|
| 86 | - public function config_name() |
|
| 87 | - { |
|
| 88 | - return $this->_config_name; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * set_config |
|
| 94 | - * this method integrates directly with EE_Config to set up the config object for this class |
|
| 95 | - * |
|
| 96 | - * @access protected |
|
| 97 | - * @param EE_Config_Base $config_obj |
|
| 98 | - * @return mixed EE_Config_Base | NULL |
|
| 99 | - */ |
|
| 100 | - protected function _set_config(EE_Config_Base $config_obj = null) |
|
| 101 | - { |
|
| 102 | - return EE_Config::instance()->set_config( |
|
| 103 | - $this->config_section(), |
|
| 104 | - $this->config_name(), |
|
| 105 | - $this->config_class(), |
|
| 106 | - $config_obj |
|
| 107 | - ); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * _update_config |
|
| 113 | - * this method integrates directly with EE_Config to update an existing config object for this class |
|
| 114 | - * |
|
| 115 | - * @access protected |
|
| 116 | - * @param EE_Config_Base $config_obj |
|
| 117 | - * @throws \EE_Error |
|
| 118 | - * @return mixed EE_Config_Base | NULL |
|
| 119 | - */ |
|
| 120 | - public function _update_config(EE_Config_Base $config_obj = null) |
|
| 121 | - { |
|
| 122 | - $config_class = $this->config_class(); |
|
| 123 | - if (! $config_obj instanceof $config_class) { |
|
| 124 | - throw new EE_Error( |
|
| 125 | - sprintf( |
|
| 126 | - __('The "%1$s" class is not an instance of %2$s.', 'event_espresso'), |
|
| 127 | - print_r($config_obj, true), |
|
| 128 | - $config_class |
|
| 129 | - ) |
|
| 130 | - ); |
|
| 131 | - } |
|
| 132 | - return EE_Config::instance()->update_config($this->config_section(), $this->config_name(), $config_obj); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * gets the class's config object |
|
| 138 | - * |
|
| 139 | - * @return EE_Config_Base |
|
| 140 | - */ |
|
| 141 | - public function config() |
|
| 142 | - { |
|
| 143 | - if (empty($this->_config)) { |
|
| 144 | - $this->_config = EE_Config::instance()->get_config( |
|
| 145 | - $this->config_section(), |
|
| 146 | - $this->config_name(), |
|
| 147 | - $this->config_class() |
|
| 148 | - ); |
|
| 149 | - } |
|
| 150 | - return $this->_config; |
|
| 151 | - } |
|
| 13 | + /** |
|
| 14 | + * @var $_config |
|
| 15 | + * @type EE_Config_Base |
|
| 16 | + */ |
|
| 17 | + protected $_config; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * @var $_config_section |
|
| 21 | + * @type string |
|
| 22 | + */ |
|
| 23 | + protected $_config_section = ''; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @var $_config_class |
|
| 27 | + * @type string |
|
| 28 | + */ |
|
| 29 | + protected $_config_class = ''; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var $_config_name |
|
| 33 | + * @type string |
|
| 34 | + */ |
|
| 35 | + protected $_config_name = ''; |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @param string $config_section |
|
| 40 | + */ |
|
| 41 | + public function set_config_section($config_section = '') |
|
| 42 | + { |
|
| 43 | + $this->_config_section = ! empty($config_section) ? $config_section : 'modules'; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @return mixed |
|
| 49 | + */ |
|
| 50 | + public function config_section() |
|
| 51 | + { |
|
| 52 | + return $this->_config_section; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @param string $config_class |
|
| 58 | + */ |
|
| 59 | + public function set_config_class($config_class = '') |
|
| 60 | + { |
|
| 61 | + $this->_config_class = $config_class; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @return mixed |
|
| 67 | + */ |
|
| 68 | + public function config_class() |
|
| 69 | + { |
|
| 70 | + return $this->_config_class; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @param mixed $config_name |
|
| 76 | + */ |
|
| 77 | + public function set_config_name($config_name) |
|
| 78 | + { |
|
| 79 | + $this->_config_name = ! empty($config_name) ? $config_name : get_called_class(); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @return mixed |
|
| 85 | + */ |
|
| 86 | + public function config_name() |
|
| 87 | + { |
|
| 88 | + return $this->_config_name; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * set_config |
|
| 94 | + * this method integrates directly with EE_Config to set up the config object for this class |
|
| 95 | + * |
|
| 96 | + * @access protected |
|
| 97 | + * @param EE_Config_Base $config_obj |
|
| 98 | + * @return mixed EE_Config_Base | NULL |
|
| 99 | + */ |
|
| 100 | + protected function _set_config(EE_Config_Base $config_obj = null) |
|
| 101 | + { |
|
| 102 | + return EE_Config::instance()->set_config( |
|
| 103 | + $this->config_section(), |
|
| 104 | + $this->config_name(), |
|
| 105 | + $this->config_class(), |
|
| 106 | + $config_obj |
|
| 107 | + ); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * _update_config |
|
| 113 | + * this method integrates directly with EE_Config to update an existing config object for this class |
|
| 114 | + * |
|
| 115 | + * @access protected |
|
| 116 | + * @param EE_Config_Base $config_obj |
|
| 117 | + * @throws \EE_Error |
|
| 118 | + * @return mixed EE_Config_Base | NULL |
|
| 119 | + */ |
|
| 120 | + public function _update_config(EE_Config_Base $config_obj = null) |
|
| 121 | + { |
|
| 122 | + $config_class = $this->config_class(); |
|
| 123 | + if (! $config_obj instanceof $config_class) { |
|
| 124 | + throw new EE_Error( |
|
| 125 | + sprintf( |
|
| 126 | + __('The "%1$s" class is not an instance of %2$s.', 'event_espresso'), |
|
| 127 | + print_r($config_obj, true), |
|
| 128 | + $config_class |
|
| 129 | + ) |
|
| 130 | + ); |
|
| 131 | + } |
|
| 132 | + return EE_Config::instance()->update_config($this->config_section(), $this->config_name(), $config_obj); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * gets the class's config object |
|
| 138 | + * |
|
| 139 | + * @return EE_Config_Base |
|
| 140 | + */ |
|
| 141 | + public function config() |
|
| 142 | + { |
|
| 143 | + if (empty($this->_config)) { |
|
| 144 | + $this->_config = EE_Config::instance()->get_config( |
|
| 145 | + $this->config_section(), |
|
| 146 | + $this->config_name(), |
|
| 147 | + $this->config_class() |
|
| 148 | + ); |
|
| 149 | + } |
|
| 150 | + return $this->_config; |
|
| 151 | + } |
|
| 152 | 152 | } |
@@ -120,7 +120,7 @@ |
||
| 120 | 120 | public function _update_config(EE_Config_Base $config_obj = null) |
| 121 | 121 | { |
| 122 | 122 | $config_class = $this->config_class(); |
| 123 | - if (! $config_obj instanceof $config_class) { |
|
| 123 | + if ( ! $config_obj instanceof $config_class) { |
|
| 124 | 124 | throw new EE_Error( |
| 125 | 125 | sprintf( |
| 126 | 126 | __('The "%1$s" class is not an instance of %2$s.', 'event_espresso'), |
@@ -10,128 +10,128 @@ |
||
| 10 | 10 | class EEM_Term_Taxonomy extends EEM_Base |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - // private instance of the Attendee object |
|
| 14 | - protected static $_instance = null; |
|
| 13 | + // private instance of the Attendee object |
|
| 14 | + protected static $_instance = null; |
|
| 15 | 15 | |
| 16 | 16 | |
| 17 | 17 | |
| 18 | - protected function __construct($timezone = null) |
|
| 19 | - { |
|
| 20 | - $this->singular_item = __('Term Taxonomy', 'event_espresso'); |
|
| 21 | - $this->plural_item = __('Term Taxonomy', 'event_espresso'); |
|
| 22 | - $this->_tables = array( |
|
| 23 | - 'Term_Taxonomy' => new EE_Primary_Table('term_taxonomy', 'term_taxonomy_id'), |
|
| 24 | - ); |
|
| 25 | - $this->_fields = array( |
|
| 26 | - 'Term_Taxonomy' => array( |
|
| 27 | - 'term_taxonomy_id' => new EE_Primary_Key_Int_Field( |
|
| 28 | - 'term_taxonomy_id', |
|
| 29 | - __('Term-Taxonomy ID', 'event_espresso') |
|
| 30 | - ), |
|
| 31 | - 'term_id' => new EE_Foreign_Key_Int_Field( |
|
| 32 | - 'term_id', |
|
| 33 | - __("Term Id", "event_espresso"), |
|
| 34 | - false, |
|
| 35 | - 0, |
|
| 36 | - 'Term' |
|
| 37 | - ), |
|
| 38 | - 'taxonomy' => new EE_Plain_Text_Field( |
|
| 39 | - 'taxonomy', |
|
| 40 | - __('Taxonomy Name', 'event_espresso'), |
|
| 41 | - false, |
|
| 42 | - 'category' |
|
| 43 | - ), |
|
| 44 | - 'description' => new EE_Post_Content_Field( |
|
| 45 | - 'description', |
|
| 46 | - __("Description of Term", "event_espresso"), |
|
| 47 | - false, |
|
| 48 | - '' |
|
| 49 | - ), |
|
| 50 | - 'parent' => new EE_Integer_Field('parent', __("Parent Term ID", "event_espresso"), false, 0), |
|
| 51 | - 'term_count' => new EE_Integer_Field( |
|
| 52 | - 'count', |
|
| 53 | - __("Count of Objects attached", 'event_espresso'), |
|
| 54 | - false, |
|
| 55 | - 0 |
|
| 56 | - ), |
|
| 57 | - ), |
|
| 58 | - ); |
|
| 59 | - $this->_model_relations = array( |
|
| 60 | - 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
| 61 | - 'Term' => new EE_Belongs_To_Relation(), |
|
| 62 | - ); |
|
| 63 | - $cpt_models = array_keys(EE_Registry::instance()->cpt_models()); |
|
| 64 | - foreach ($cpt_models as $model_name) { |
|
| 65 | - $this->_model_relations[ $model_name ] = new EE_HABTM_Relation('Term_Relationship'); |
|
| 66 | - } |
|
| 67 | - $this->_wp_core_model = true; |
|
| 68 | - $this->_indexes = array( |
|
| 69 | - 'term_id_taxonomy' => new EE_Unique_Index(array('term_id', 'taxonomy')), |
|
| 70 | - ); |
|
| 71 | - $path_to_tax_model = ''; |
|
| 72 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
| 73 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Taxonomy_Protected( |
|
| 74 | - $path_to_tax_model |
|
| 75 | - ); |
|
| 76 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = false; |
|
| 77 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = false; |
|
| 78 | - // add cap restrictions for editing relating to the "ee_edit_*" |
|
| 79 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
|
| 80 | - array( |
|
| 81 | - $path_to_tax_model . 'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'), |
|
| 82 | - ) |
|
| 83 | - ); |
|
| 84 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
|
| 85 | - array( |
|
| 86 | - $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'), |
|
| 87 | - ) |
|
| 88 | - ); |
|
| 89 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
|
| 90 | - array( |
|
| 91 | - $path_to_tax_model . 'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'), |
|
| 92 | - ) |
|
| 93 | - ); |
|
| 94 | - // add cap restrictions for deleting relating to the "ee_deleting_*" |
|
| 95 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
|
| 96 | - array( |
|
| 97 | - $path_to_tax_model . 'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'), |
|
| 98 | - ) |
|
| 99 | - ); |
|
| 100 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
|
| 101 | - array( |
|
| 102 | - $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'), |
|
| 103 | - ) |
|
| 104 | - ); |
|
| 105 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
|
| 106 | - array( |
|
| 107 | - $path_to_tax_model . 'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'), |
|
| 108 | - ) |
|
| 109 | - ); |
|
| 110 | - parent::__construct($timezone); |
|
| 111 | - add_filter('FHEE__Read__create_model_query_params', array('EEM_Term_Taxonomy', 'rest_api_query_params'), 10, 3); |
|
| 112 | - } |
|
| 18 | + protected function __construct($timezone = null) |
|
| 19 | + { |
|
| 20 | + $this->singular_item = __('Term Taxonomy', 'event_espresso'); |
|
| 21 | + $this->plural_item = __('Term Taxonomy', 'event_espresso'); |
|
| 22 | + $this->_tables = array( |
|
| 23 | + 'Term_Taxonomy' => new EE_Primary_Table('term_taxonomy', 'term_taxonomy_id'), |
|
| 24 | + ); |
|
| 25 | + $this->_fields = array( |
|
| 26 | + 'Term_Taxonomy' => array( |
|
| 27 | + 'term_taxonomy_id' => new EE_Primary_Key_Int_Field( |
|
| 28 | + 'term_taxonomy_id', |
|
| 29 | + __('Term-Taxonomy ID', 'event_espresso') |
|
| 30 | + ), |
|
| 31 | + 'term_id' => new EE_Foreign_Key_Int_Field( |
|
| 32 | + 'term_id', |
|
| 33 | + __("Term Id", "event_espresso"), |
|
| 34 | + false, |
|
| 35 | + 0, |
|
| 36 | + 'Term' |
|
| 37 | + ), |
|
| 38 | + 'taxonomy' => new EE_Plain_Text_Field( |
|
| 39 | + 'taxonomy', |
|
| 40 | + __('Taxonomy Name', 'event_espresso'), |
|
| 41 | + false, |
|
| 42 | + 'category' |
|
| 43 | + ), |
|
| 44 | + 'description' => new EE_Post_Content_Field( |
|
| 45 | + 'description', |
|
| 46 | + __("Description of Term", "event_espresso"), |
|
| 47 | + false, |
|
| 48 | + '' |
|
| 49 | + ), |
|
| 50 | + 'parent' => new EE_Integer_Field('parent', __("Parent Term ID", "event_espresso"), false, 0), |
|
| 51 | + 'term_count' => new EE_Integer_Field( |
|
| 52 | + 'count', |
|
| 53 | + __("Count of Objects attached", 'event_espresso'), |
|
| 54 | + false, |
|
| 55 | + 0 |
|
| 56 | + ), |
|
| 57 | + ), |
|
| 58 | + ); |
|
| 59 | + $this->_model_relations = array( |
|
| 60 | + 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
| 61 | + 'Term' => new EE_Belongs_To_Relation(), |
|
| 62 | + ); |
|
| 63 | + $cpt_models = array_keys(EE_Registry::instance()->cpt_models()); |
|
| 64 | + foreach ($cpt_models as $model_name) { |
|
| 65 | + $this->_model_relations[ $model_name ] = new EE_HABTM_Relation('Term_Relationship'); |
|
| 66 | + } |
|
| 67 | + $this->_wp_core_model = true; |
|
| 68 | + $this->_indexes = array( |
|
| 69 | + 'term_id_taxonomy' => new EE_Unique_Index(array('term_id', 'taxonomy')), |
|
| 70 | + ); |
|
| 71 | + $path_to_tax_model = ''; |
|
| 72 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
| 73 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Taxonomy_Protected( |
|
| 74 | + $path_to_tax_model |
|
| 75 | + ); |
|
| 76 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = false; |
|
| 77 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = false; |
|
| 78 | + // add cap restrictions for editing relating to the "ee_edit_*" |
|
| 79 | + $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
|
| 80 | + array( |
|
| 81 | + $path_to_tax_model . 'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'), |
|
| 82 | + ) |
|
| 83 | + ); |
|
| 84 | + $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
|
| 85 | + array( |
|
| 86 | + $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'), |
|
| 87 | + ) |
|
| 88 | + ); |
|
| 89 | + $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
|
| 90 | + array( |
|
| 91 | + $path_to_tax_model . 'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'), |
|
| 92 | + ) |
|
| 93 | + ); |
|
| 94 | + // add cap restrictions for deleting relating to the "ee_deleting_*" |
|
| 95 | + $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
|
| 96 | + array( |
|
| 97 | + $path_to_tax_model . 'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'), |
|
| 98 | + ) |
|
| 99 | + ); |
|
| 100 | + $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
|
| 101 | + array( |
|
| 102 | + $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'), |
|
| 103 | + ) |
|
| 104 | + ); |
|
| 105 | + $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
|
| 106 | + array( |
|
| 107 | + $path_to_tax_model . 'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'), |
|
| 108 | + ) |
|
| 109 | + ); |
|
| 110 | + parent::__construct($timezone); |
|
| 111 | + add_filter('FHEE__Read__create_model_query_params', array('EEM_Term_Taxonomy', 'rest_api_query_params'), 10, 3); |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | 114 | |
| 115 | 115 | |
| 116 | - /** |
|
| 117 | - * Makes sure that during REST API queries, we only return term-taxonomies |
|
| 118 | - * for term taxonomies which should be shown in the rest api |
|
| 119 | - * |
|
| 120 | - * @param array $model_query_params |
|
| 121 | - * @param array $querystring_query_params |
|
| 122 | - * @param EEM_Base $model |
|
| 123 | - * @return array |
|
| 124 | - */ |
|
| 125 | - public static function rest_api_query_params($model_query_params, $querystring_query_params, $model) |
|
| 126 | - { |
|
| 127 | - if ($model === EEM_Term_Taxonomy::instance()) { |
|
| 128 | - $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
|
| 129 | - if (! empty($taxonomies)) { |
|
| 130 | - $model_query_params[0]['taxonomy'] = array('IN', $taxonomies); |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - return $model_query_params; |
|
| 134 | - } |
|
| 116 | + /** |
|
| 117 | + * Makes sure that during REST API queries, we only return term-taxonomies |
|
| 118 | + * for term taxonomies which should be shown in the rest api |
|
| 119 | + * |
|
| 120 | + * @param array $model_query_params |
|
| 121 | + * @param array $querystring_query_params |
|
| 122 | + * @param EEM_Base $model |
|
| 123 | + * @return array |
|
| 124 | + */ |
|
| 125 | + public static function rest_api_query_params($model_query_params, $querystring_query_params, $model) |
|
| 126 | + { |
|
| 127 | + if ($model === EEM_Term_Taxonomy::instance()) { |
|
| 128 | + $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
|
| 129 | + if (! empty($taxonomies)) { |
|
| 130 | + $model_query_params[0]['taxonomy'] = array('IN', $taxonomies); |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + return $model_query_params; |
|
| 134 | + } |
|
| 135 | 135 | } |
| 136 | 136 | // End of file EEM_Term_Taxonomy.model.php |
| 137 | 137 | // Location: /includes/models/EEM_Term_Taxonomy.model.php |
@@ -62,49 +62,49 @@ discard block |
||
| 62 | 62 | ); |
| 63 | 63 | $cpt_models = array_keys(EE_Registry::instance()->cpt_models()); |
| 64 | 64 | foreach ($cpt_models as $model_name) { |
| 65 | - $this->_model_relations[ $model_name ] = new EE_HABTM_Relation('Term_Relationship'); |
|
| 65 | + $this->_model_relations[$model_name] = new EE_HABTM_Relation('Term_Relationship'); |
|
| 66 | 66 | } |
| 67 | 67 | $this->_wp_core_model = true; |
| 68 | 68 | $this->_indexes = array( |
| 69 | 69 | 'term_id_taxonomy' => new EE_Unique_Index(array('term_id', 'taxonomy')), |
| 70 | 70 | ); |
| 71 | 71 | $path_to_tax_model = ''; |
| 72 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
| 73 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Taxonomy_Protected( |
|
| 72 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
| 73 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Taxonomy_Protected( |
|
| 74 | 74 | $path_to_tax_model |
| 75 | 75 | ); |
| 76 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = false; |
|
| 77 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = false; |
|
| 76 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = false; |
|
| 77 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = false; |
|
| 78 | 78 | // add cap restrictions for editing relating to the "ee_edit_*" |
| 79 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
|
| 79 | + $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
|
| 80 | 80 | array( |
| 81 | - $path_to_tax_model . 'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'), |
|
| 81 | + $path_to_tax_model.'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'), |
|
| 82 | 82 | ) |
| 83 | 83 | ); |
| 84 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
|
| 84 | + $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
|
| 85 | 85 | array( |
| 86 | - $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'), |
|
| 86 | + $path_to_tax_model.'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'), |
|
| 87 | 87 | ) |
| 88 | 88 | ); |
| 89 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
|
| 89 | + $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
|
| 90 | 90 | array( |
| 91 | - $path_to_tax_model . 'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'), |
|
| 91 | + $path_to_tax_model.'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'), |
|
| 92 | 92 | ) |
| 93 | 93 | ); |
| 94 | 94 | // add cap restrictions for deleting relating to the "ee_deleting_*" |
| 95 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
|
| 95 | + $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
|
| 96 | 96 | array( |
| 97 | - $path_to_tax_model . 'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'), |
|
| 97 | + $path_to_tax_model.'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'), |
|
| 98 | 98 | ) |
| 99 | 99 | ); |
| 100 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
|
| 100 | + $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
|
| 101 | 101 | array( |
| 102 | - $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'), |
|
| 102 | + $path_to_tax_model.'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'), |
|
| 103 | 103 | ) |
| 104 | 104 | ); |
| 105 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
|
| 105 | + $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
|
| 106 | 106 | array( |
| 107 | - $path_to_tax_model . 'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'), |
|
| 107 | + $path_to_tax_model.'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'), |
|
| 108 | 108 | ) |
| 109 | 109 | ); |
| 110 | 110 | parent::__construct($timezone); |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | { |
| 127 | 127 | if ($model === EEM_Term_Taxonomy::instance()) { |
| 128 | 128 | $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
| 129 | - if (! empty($taxonomies)) { |
|
| 129 | + if ( ! empty($taxonomies)) { |
|
| 130 | 130 | $model_query_params[0]['taxonomy'] = array('IN', $taxonomies); |
| 131 | 131 | } |
| 132 | 132 | } |
@@ -38,10 +38,10 @@ |
||
| 38 | 38 | )); |
| 39 | 39 | $this->_model_relations = array(); |
| 40 | 40 | foreach ($models_this_can_attach_to as $model) { |
| 41 | - $this->_model_relations[ $model ] = new EE_Belongs_To_Any_Relation(); |
|
| 41 | + $this->_model_relations[$model] = new EE_Belongs_To_Any_Relation(); |
|
| 42 | 42 | } |
| 43 | 43 | foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) { |
| 44 | - $this->_cap_restriction_generators[ $cap_context ] = new EE_Restriction_Generator_Meta('EXM_key', 'EXM_value'); |
|
| 44 | + $this->_cap_restriction_generators[$cap_context] = new EE_Restriction_Generator_Meta('EXM_key', 'EXM_value'); |
|
| 45 | 45 | } |
| 46 | 46 | parent::__construct($timezone); |
| 47 | 47 | } |
@@ -17,33 +17,33 @@ |
||
| 17 | 17 | class EEM_Extra_Meta extends EEM_Base |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - // private instance of the Attendee object |
|
| 21 | - protected static $_instance = null; |
|
| 20 | + // private instance of the Attendee object |
|
| 21 | + protected static $_instance = null; |
|
| 22 | 22 | |
| 23 | - protected function __construct($timezone = null) |
|
| 24 | - { |
|
| 25 | - $this->singular_item = __('Extra Meta', 'event_espresso'); |
|
| 26 | - $this->plural_item = __('Extra Metas', 'event_espresso'); |
|
| 27 | - $this->_tables = array( |
|
| 28 | - 'Extra_Meta' => new EE_Primary_Table('esp_extra_meta', 'EXM_ID') |
|
| 29 | - ); |
|
| 30 | - $models_this_can_attach_to = array_keys(EE_Registry::instance()->non_abstract_db_models); |
|
| 31 | - $this->_fields = array( |
|
| 32 | - 'Extra_Meta' => array( |
|
| 33 | - 'EXM_ID' => new EE_Primary_Key_Int_Field('EXM_ID', __("Extra Meta ID", "event_espresso")), |
|
| 34 | - 'OBJ_ID' => new EE_Foreign_Key_Int_Field('OBJ_ID', __("Primary Key of Attached Thing", "event_espresso"), false, 0, $models_this_can_attach_to), |
|
| 35 | - 'EXM_type' => new EE_Any_Foreign_Model_Name_Field('EXM_type', __("Model of Attached Thing", "event_espresso"), false, 'Transaction', $models_this_can_attach_to), |
|
| 36 | - 'EXM_key' => new EE_Plain_Text_Field('EXM_key', __("Meta Key", "event_espresso"), false, ''), |
|
| 37 | - 'EXM_value' => new EE_Maybe_Serialized_Text_Field('EXM_value', __("Meta Value", "event_espresso"), true) |
|
| 23 | + protected function __construct($timezone = null) |
|
| 24 | + { |
|
| 25 | + $this->singular_item = __('Extra Meta', 'event_espresso'); |
|
| 26 | + $this->plural_item = __('Extra Metas', 'event_espresso'); |
|
| 27 | + $this->_tables = array( |
|
| 28 | + 'Extra_Meta' => new EE_Primary_Table('esp_extra_meta', 'EXM_ID') |
|
| 29 | + ); |
|
| 30 | + $models_this_can_attach_to = array_keys(EE_Registry::instance()->non_abstract_db_models); |
|
| 31 | + $this->_fields = array( |
|
| 32 | + 'Extra_Meta' => array( |
|
| 33 | + 'EXM_ID' => new EE_Primary_Key_Int_Field('EXM_ID', __("Extra Meta ID", "event_espresso")), |
|
| 34 | + 'OBJ_ID' => new EE_Foreign_Key_Int_Field('OBJ_ID', __("Primary Key of Attached Thing", "event_espresso"), false, 0, $models_this_can_attach_to), |
|
| 35 | + 'EXM_type' => new EE_Any_Foreign_Model_Name_Field('EXM_type', __("Model of Attached Thing", "event_espresso"), false, 'Transaction', $models_this_can_attach_to), |
|
| 36 | + 'EXM_key' => new EE_Plain_Text_Field('EXM_key', __("Meta Key", "event_espresso"), false, ''), |
|
| 37 | + 'EXM_value' => new EE_Maybe_Serialized_Text_Field('EXM_value', __("Meta Value", "event_espresso"), true) |
|
| 38 | 38 | |
| 39 | - )); |
|
| 40 | - $this->_model_relations = array(); |
|
| 41 | - foreach ($models_this_can_attach_to as $model) { |
|
| 42 | - $this->_model_relations[ $model ] = new EE_Belongs_To_Any_Relation(); |
|
| 43 | - } |
|
| 44 | - foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) { |
|
| 45 | - $this->_cap_restriction_generators[ $cap_context ] = new EE_Restriction_Generator_Meta('EXM_key', 'EXM_value'); |
|
| 46 | - } |
|
| 47 | - parent::__construct($timezone); |
|
| 48 | - } |
|
| 39 | + )); |
|
| 40 | + $this->_model_relations = array(); |
|
| 41 | + foreach ($models_this_can_attach_to as $model) { |
|
| 42 | + $this->_model_relations[ $model ] = new EE_Belongs_To_Any_Relation(); |
|
| 43 | + } |
|
| 44 | + foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) { |
|
| 45 | + $this->_cap_restriction_generators[ $cap_context ] = new EE_Restriction_Generator_Meta('EXM_key', 'EXM_value'); |
|
| 46 | + } |
|
| 47 | + parent::__construct($timezone); |
|
| 48 | + } |
|
| 49 | 49 | } |
@@ -284,8 +284,8 @@ discard block |
||
| 284 | 284 | */ |
| 285 | 285 | public function get_attendee_field_for_system_question($system_question_string) |
| 286 | 286 | { |
| 287 | - return isset($this->_system_question_to_attendee_field_name[ $system_question_string ]) |
|
| 288 | - ? $this->_system_question_to_attendee_field_name[ $system_question_string ] |
|
| 287 | + return isset($this->_system_question_to_attendee_field_name[$system_question_string]) |
|
| 288 | + ? $this->_system_question_to_attendee_field_name[$system_question_string] |
|
| 289 | 289 | : null; |
| 290 | 290 | } |
| 291 | 291 | |
@@ -353,7 +353,7 @@ discard block |
||
| 353 | 353 | return false; |
| 354 | 354 | } |
| 355 | 355 | $attendee = $this->get_all(array($where_cols_n_values)); |
| 356 | - if (! empty($attendee)) { |
|
| 356 | + if ( ! empty($attendee)) { |
|
| 357 | 357 | return array_shift($attendee); |
| 358 | 358 | } |
| 359 | 359 | return false; |
@@ -12,432 +12,432 @@ |
||
| 12 | 12 | class EEM_Attendee extends EEM_CPT_Base |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - // private instance of the Attendee object |
|
| 16 | - protected static $_instance = null; |
|
| 15 | + // private instance of the Attendee object |
|
| 16 | + protected static $_instance = null; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * QST_system for questions are strings not integers now, |
|
| 20 | - * so these constants are deprecated. |
|
| 21 | - * Please instead use the EEM_Attendee::system_question_* constants |
|
| 22 | - * |
|
| 23 | - * @deprecated |
|
| 24 | - */ |
|
| 25 | - const fname_question_id = 1; |
|
| 18 | + /** |
|
| 19 | + * QST_system for questions are strings not integers now, |
|
| 20 | + * so these constants are deprecated. |
|
| 21 | + * Please instead use the EEM_Attendee::system_question_* constants |
|
| 22 | + * |
|
| 23 | + * @deprecated |
|
| 24 | + */ |
|
| 25 | + const fname_question_id = 1; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @deprecated |
|
| 29 | - */ |
|
| 30 | - const lname_question_id = 2; |
|
| 27 | + /** |
|
| 28 | + * @deprecated |
|
| 29 | + */ |
|
| 30 | + const lname_question_id = 2; |
|
| 31 | 31 | |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @deprecated |
|
| 35 | - */ |
|
| 36 | - const email_question_id = 3; |
|
| 33 | + /** |
|
| 34 | + * @deprecated |
|
| 35 | + */ |
|
| 36 | + const email_question_id = 3; |
|
| 37 | 37 | |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @deprecated |
|
| 41 | - */ |
|
| 42 | - const address_question_id = 4; |
|
| 39 | + /** |
|
| 40 | + * @deprecated |
|
| 41 | + */ |
|
| 42 | + const address_question_id = 4; |
|
| 43 | 43 | |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @deprecated |
|
| 47 | - */ |
|
| 48 | - const address2_question_id = 5; |
|
| 45 | + /** |
|
| 46 | + * @deprecated |
|
| 47 | + */ |
|
| 48 | + const address2_question_id = 5; |
|
| 49 | 49 | |
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @deprecated |
|
| 53 | - */ |
|
| 54 | - const city_question_id = 6; |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @deprecated |
|
| 59 | - */ |
|
| 60 | - const state_question_id = 7; |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @deprecated |
|
| 65 | - */ |
|
| 66 | - const country_question_id = 8; |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @deprecated |
|
| 71 | - */ |
|
| 72 | - const zip_question_id = 9; |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @deprecated |
|
| 77 | - */ |
|
| 78 | - const phone_question_id = 10; |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * When looking for questions that correspond to attendee fields, |
|
| 82 | - * look for the question with this QST_system value. |
|
| 83 | - * These replace the old constants like EEM_Attendee::*_question_id |
|
| 84 | - */ |
|
| 85 | - const system_question_fname = 'fname'; |
|
| 86 | - |
|
| 87 | - const system_question_lname = 'lname'; |
|
| 88 | - |
|
| 89 | - const system_question_email = 'email'; |
|
| 90 | - |
|
| 91 | - const system_question_email_confirm = 'email_confirm'; |
|
| 92 | - |
|
| 93 | - const system_question_address = 'address'; |
|
| 94 | - |
|
| 95 | - const system_question_address2 = 'address2'; |
|
| 96 | - |
|
| 97 | - const system_question_city = 'city'; |
|
| 98 | - |
|
| 99 | - const system_question_state = 'state'; |
|
| 100 | - |
|
| 101 | - const system_question_country = 'country'; |
|
| 102 | - |
|
| 103 | - const system_question_zip = 'zip'; |
|
| 104 | - |
|
| 105 | - const system_question_phone = 'phone'; |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Keys are all the EEM_Attendee::system_question_* constants, which are |
|
| 109 | - * also all the values of QST_system in the questions table, and values |
|
| 110 | - * are their corresponding Attendee field names |
|
| 111 | - * |
|
| 112 | - * @var array |
|
| 113 | - */ |
|
| 114 | - protected $_system_question_to_attendee_field_name = array( |
|
| 115 | - EEM_Attendee::system_question_fname => 'ATT_fname', |
|
| 116 | - EEM_Attendee::system_question_lname => 'ATT_lname', |
|
| 117 | - EEM_Attendee::system_question_email => 'ATT_email', |
|
| 118 | - EEM_Attendee::system_question_address => 'ATT_address', |
|
| 119 | - EEM_Attendee::system_question_address2 => 'ATT_address2', |
|
| 120 | - EEM_Attendee::system_question_city => 'ATT_city', |
|
| 121 | - EEM_Attendee::system_question_state => 'STA_ID', |
|
| 122 | - EEM_Attendee::system_question_country => 'CNT_ISO', |
|
| 123 | - EEM_Attendee::system_question_zip => 'ATT_zip', |
|
| 124 | - EEM_Attendee::system_question_phone => 'ATT_phone', |
|
| 125 | - ); |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * EEM_Attendee constructor. |
|
| 131 | - * |
|
| 132 | - * @param null $timezone |
|
| 133 | - * @param ModelFieldFactory $model_field_factory |
|
| 134 | - * @throws EE_Error |
|
| 135 | - * @throws InvalidArgumentException |
|
| 136 | - */ |
|
| 137 | - protected function __construct($timezone = null, ModelFieldFactory $model_field_factory) |
|
| 138 | - { |
|
| 139 | - $this->singular_item = esc_html__('Attendee', 'event_espresso'); |
|
| 140 | - $this->plural_item = esc_html__('Attendees', 'event_espresso'); |
|
| 141 | - $this->_tables = array( |
|
| 142 | - 'Attendee_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
| 143 | - 'Attendee_Meta' => new EE_Secondary_Table( |
|
| 144 | - 'esp_attendee_meta', |
|
| 145 | - 'ATTM_ID', |
|
| 146 | - 'ATT_ID' |
|
| 147 | - ), |
|
| 148 | - ); |
|
| 149 | - $this->_fields = array( |
|
| 150 | - 'Attendee_CPT' => array( |
|
| 151 | - 'ATT_ID' => $model_field_factory->createPrimaryKeyIntField( |
|
| 152 | - 'ID', |
|
| 153 | - esc_html__('Attendee ID', 'event_espresso') |
|
| 154 | - ), |
|
| 155 | - 'ATT_full_name' => $model_field_factory->createPlainTextField( |
|
| 156 | - 'post_title', |
|
| 157 | - esc_html__('Attendee Full Name', 'event_espresso'), |
|
| 158 | - false, |
|
| 159 | - esc_html__('Unknown', 'event_espresso') |
|
| 160 | - ), |
|
| 161 | - 'ATT_bio' => $model_field_factory->createPostContentField( |
|
| 162 | - 'post_content', |
|
| 163 | - esc_html__('Attendee Biography', 'event_espresso'), |
|
| 164 | - false, |
|
| 165 | - esc_html__('No Biography Provided', 'event_espresso') |
|
| 166 | - ), |
|
| 167 | - 'ATT_slug' => $model_field_factory->createSlugField( |
|
| 168 | - 'post_name', |
|
| 169 | - esc_html__('Attendee URL Slug', 'event_espresso') |
|
| 170 | - ), |
|
| 171 | - 'ATT_created' => $model_field_factory->createDatetimeField( |
|
| 172 | - 'post_date', |
|
| 173 | - esc_html__('Time Attendee Created', 'event_espresso') |
|
| 174 | - ), |
|
| 175 | - 'ATT_short_bio' => $model_field_factory->createSimpleHtmlField( |
|
| 176 | - 'post_excerpt', |
|
| 177 | - esc_html__('Attendee Short Biography', 'event_espresso'), |
|
| 178 | - true, |
|
| 179 | - esc_html__('No Biography Provided', 'event_espresso') |
|
| 180 | - ), |
|
| 181 | - 'ATT_modified' => $model_field_factory->createDatetimeField( |
|
| 182 | - 'post_modified', |
|
| 183 | - esc_html__('Time Attendee Last Modified', 'event_espresso') |
|
| 184 | - ), |
|
| 185 | - 'ATT_author' => $model_field_factory->createWpUserField( |
|
| 186 | - 'post_author', |
|
| 187 | - esc_html__('Creator ID of the first Event attended', 'event_espresso'), |
|
| 188 | - false |
|
| 189 | - ), |
|
| 190 | - 'ATT_parent' => $model_field_factory->createDbOnlyIntField( |
|
| 191 | - 'post_parent', |
|
| 192 | - esc_html__('Parent Attendee (unused)', 'event_espresso'), |
|
| 193 | - false, |
|
| 194 | - 0 |
|
| 195 | - ), |
|
| 196 | - 'post_type' => $model_field_factory->createWpPostTypeField('espresso_attendees'), |
|
| 197 | - 'status' => $model_field_factory->createWpPostStatusField( |
|
| 198 | - 'post_status', |
|
| 199 | - esc_html__('Attendee Status', 'event_espresso'), |
|
| 200 | - false, |
|
| 201 | - 'publish' |
|
| 202 | - ), |
|
| 203 | - 'password' => new EE_Password_Field( |
|
| 204 | - 'post_password', |
|
| 205 | - __('Password', 'event_espresso'), |
|
| 206 | - false, |
|
| 207 | - '', |
|
| 208 | - array( |
|
| 209 | - 'ATT_bio', |
|
| 210 | - 'ATT_short_bio', |
|
| 211 | - 'ATT_address', |
|
| 212 | - 'ATT_address2', |
|
| 213 | - 'ATT_city', |
|
| 214 | - 'STA_ID', |
|
| 215 | - 'CNT_ISO', |
|
| 216 | - 'ATT_zip', |
|
| 217 | - 'ATT_email', |
|
| 218 | - 'ATT_phone' |
|
| 219 | - ) |
|
| 220 | - ) |
|
| 221 | - ), |
|
| 222 | - 'Attendee_Meta' => array( |
|
| 223 | - 'ATTM_ID' => $model_field_factory->createDbOnlyIntField( |
|
| 224 | - 'ATTM_ID', |
|
| 225 | - esc_html__('Attendee Meta Row ID', 'event_espresso'), |
|
| 226 | - false |
|
| 227 | - ), |
|
| 228 | - 'ATT_ID_fk' => $model_field_factory->createDbOnlyIntField( |
|
| 229 | - 'ATT_ID', |
|
| 230 | - esc_html__('Foreign Key to Attendee in Post Table', 'event_espresso'), |
|
| 231 | - false |
|
| 232 | - ), |
|
| 233 | - 'ATT_fname' => $model_field_factory->createPlainTextField( |
|
| 234 | - 'ATT_fname', |
|
| 235 | - esc_html__('First Name', 'event_espresso') |
|
| 236 | - ), |
|
| 237 | - 'ATT_lname' => $model_field_factory->createPlainTextField( |
|
| 238 | - 'ATT_lname', |
|
| 239 | - esc_html__('Last Name', 'event_espresso') |
|
| 240 | - ), |
|
| 241 | - 'ATT_address' => $model_field_factory->createPlainTextField( |
|
| 242 | - 'ATT_address', |
|
| 243 | - esc_html__('Address Part 1', 'event_espresso') |
|
| 244 | - ), |
|
| 245 | - 'ATT_address2' => $model_field_factory->createPlainTextField( |
|
| 246 | - 'ATT_address2', |
|
| 247 | - esc_html__('Address Part 2', 'event_espresso') |
|
| 248 | - ), |
|
| 249 | - 'ATT_city' => $model_field_factory->createPlainTextField( |
|
| 250 | - 'ATT_city', |
|
| 251 | - esc_html__('City', 'event_espresso') |
|
| 252 | - ), |
|
| 253 | - 'STA_ID' => $model_field_factory->createForeignKeyIntField( |
|
| 254 | - 'STA_ID', |
|
| 255 | - esc_html__('State', 'event_espresso'), |
|
| 256 | - true, |
|
| 257 | - 0, |
|
| 258 | - 'State' |
|
| 259 | - ), |
|
| 260 | - 'CNT_ISO' => $model_field_factory->createForeignKeyStringField( |
|
| 261 | - 'CNT_ISO', |
|
| 262 | - esc_html__('Country', 'event_espresso'), |
|
| 263 | - true, |
|
| 264 | - '', |
|
| 265 | - 'Country' |
|
| 266 | - ), |
|
| 267 | - 'ATT_zip' => $model_field_factory->createPlainTextField( |
|
| 268 | - 'ATT_zip', |
|
| 269 | - esc_html__('ZIP/Postal Code', 'event_espresso') |
|
| 270 | - ), |
|
| 271 | - 'ATT_email' => $model_field_factory->createEmailField( |
|
| 272 | - 'ATT_email', |
|
| 273 | - esc_html__('Email Address', 'event_espresso') |
|
| 274 | - ), |
|
| 275 | - 'ATT_phone' => $model_field_factory->createPlainTextField( |
|
| 276 | - 'ATT_phone', |
|
| 277 | - esc_html__('Phone', 'event_espresso') |
|
| 278 | - ), |
|
| 279 | - ), |
|
| 280 | - ); |
|
| 281 | - $this->_model_relations = array( |
|
| 282 | - 'Registration' => new EE_Has_Many_Relation(), |
|
| 283 | - 'State' => new EE_Belongs_To_Relation(), |
|
| 284 | - 'Country' => new EE_Belongs_To_Relation(), |
|
| 285 | - 'Event' => new EE_HABTM_Relation('Registration', false), |
|
| 286 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
| 287 | - 'Message' => new EE_Has_Many_Any_Relation(false), |
|
| 288 | - // allow deletion of attendees even if they have messages in the queue for them. |
|
| 289 | - 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
| 290 | - 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
| 291 | - ); |
|
| 292 | - $this->_caps_slug = 'contacts'; |
|
| 293 | - $this->model_chain_to_password = ''; |
|
| 294 | - parent::__construct($timezone); |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - |
|
| 298 | - |
|
| 299 | - /** |
|
| 300 | - * Gets the name of the field on the attendee model corresponding to the system question string |
|
| 301 | - * which should be one of the keys from EEM_Attendee::_system_question_to_attendee_field_name |
|
| 302 | - * |
|
| 303 | - * @param string $system_question_string |
|
| 304 | - * @return string|null if not found |
|
| 305 | - */ |
|
| 306 | - public function get_attendee_field_for_system_question($system_question_string) |
|
| 307 | - { |
|
| 308 | - return isset($this->_system_question_to_attendee_field_name[ $system_question_string ]) |
|
| 309 | - ? $this->_system_question_to_attendee_field_name[ $system_question_string ] |
|
| 310 | - : null; |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * Gets mapping from esp_question.QST_system values to their corresponding attendee field names |
|
| 317 | - * |
|
| 318 | - * @return array |
|
| 319 | - */ |
|
| 320 | - public function system_question_to_attendee_field_mapping() |
|
| 321 | - { |
|
| 322 | - return $this->_system_question_to_attendee_field_name; |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - |
|
| 326 | - |
|
| 327 | - /** |
|
| 328 | - * Gets all the attendees for a transaction (by using the esp_registration as a join table) |
|
| 329 | - * |
|
| 330 | - * @param EE_Transaction /int $transaction_id_or_obj EE_Transaction or its ID |
|
| 331 | - * @return EE_Attendee[]|EE_Base_Class[] |
|
| 332 | - * @throws EE_Error |
|
| 333 | - */ |
|
| 334 | - public function get_attendees_for_transaction($transaction_id_or_obj) |
|
| 335 | - { |
|
| 336 | - return $this->get_all( |
|
| 337 | - array( |
|
| 338 | - array( |
|
| 339 | - 'Registration.Transaction.TXN_ID' => $transaction_id_or_obj instanceof EE_Transaction |
|
| 340 | - ? $transaction_id_or_obj->ID() |
|
| 341 | - : $transaction_id_or_obj, |
|
| 342 | - ), |
|
| 343 | - ) |
|
| 344 | - ); |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - |
|
| 348 | - |
|
| 349 | - /** |
|
| 350 | - * retrieve a single attendee from db via their ID |
|
| 351 | - * |
|
| 352 | - * @param $ATT_ID |
|
| 353 | - * @return mixed array on success, FALSE on fail |
|
| 354 | - * @deprecated |
|
| 355 | - */ |
|
| 356 | - public function get_attendee_by_ID($ATT_ID = false) |
|
| 357 | - { |
|
| 358 | - // retrieve a particular EE_Attendee |
|
| 359 | - return $this->get_one_by_ID($ATT_ID); |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * retrieve a single attendee from db via their ID |
|
| 366 | - * |
|
| 367 | - * @param array $where_cols_n_values |
|
| 368 | - * @return mixed array on success, FALSE on fail |
|
| 369 | - * @throws EE_Error |
|
| 370 | - */ |
|
| 371 | - public function get_attendee($where_cols_n_values = array()) |
|
| 372 | - { |
|
| 373 | - if (empty($where_cols_n_values)) { |
|
| 374 | - return false; |
|
| 375 | - } |
|
| 376 | - $attendee = $this->get_all(array($where_cols_n_values)); |
|
| 377 | - if (! empty($attendee)) { |
|
| 378 | - return array_shift($attendee); |
|
| 379 | - } |
|
| 380 | - return false; |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * Search for an existing Attendee record in the DB |
|
| 387 | - * |
|
| 388 | - * @param array $where_cols_n_values |
|
| 389 | - * @return bool|mixed |
|
| 390 | - * @throws EE_Error |
|
| 391 | - */ |
|
| 392 | - public function find_existing_attendee($where_cols_n_values = null) |
|
| 393 | - { |
|
| 394 | - // search by combo of first and last names plus the email address |
|
| 395 | - $attendee_data_keys = array( |
|
| 396 | - 'ATT_fname' => $this->_ATT_fname, |
|
| 397 | - 'ATT_lname' => $this->_ATT_lname, |
|
| 398 | - 'ATT_email' => $this->_ATT_email, |
|
| 399 | - ); |
|
| 400 | - // no search params means attendee object already exists. |
|
| 401 | - $where_cols_n_values = is_array($where_cols_n_values) && ! empty($where_cols_n_values) |
|
| 402 | - ? $where_cols_n_values |
|
| 403 | - : $attendee_data_keys; |
|
| 404 | - $valid_data = true; |
|
| 405 | - // check for required values |
|
| 406 | - $valid_data = isset($where_cols_n_values['ATT_fname']) && ! empty($where_cols_n_values['ATT_fname']) |
|
| 407 | - ? $valid_data |
|
| 408 | - : false; |
|
| 409 | - $valid_data = isset($where_cols_n_values['ATT_lname']) && ! empty($where_cols_n_values['ATT_lname']) |
|
| 410 | - ? $valid_data |
|
| 411 | - : false; |
|
| 412 | - $valid_data = isset($where_cols_n_values['ATT_email']) && ! empty($where_cols_n_values['ATT_email']) |
|
| 413 | - ? $valid_data |
|
| 414 | - : false; |
|
| 415 | - if ($valid_data) { |
|
| 416 | - $attendee = $this->get_attendee($where_cols_n_values); |
|
| 417 | - if ($attendee instanceof EE_Attendee) { |
|
| 418 | - return $attendee; |
|
| 419 | - } |
|
| 420 | - } |
|
| 421 | - return false; |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - |
|
| 425 | - |
|
| 426 | - /** |
|
| 427 | - * Takes an incoming array of EE_Registration ids |
|
| 428 | - * and sends back a list of corresponding non duplicate EE_Attendee objects. |
|
| 429 | - * |
|
| 430 | - * @since 4.3.0 |
|
| 431 | - * @param array $ids array of EE_Registration ids |
|
| 432 | - * @return EE_Attendee[]|EE_Base_Class[] |
|
| 433 | - * @throws EE_Error |
|
| 434 | - */ |
|
| 435 | - public function get_array_of_contacts_from_reg_ids($ids) |
|
| 436 | - { |
|
| 437 | - $ids = (array) $ids; |
|
| 438 | - $_where = array( |
|
| 439 | - 'Registration.REG_ID' => array('in', $ids), |
|
| 440 | - ); |
|
| 441 | - return $this->get_all(array($_where)); |
|
| 442 | - } |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @deprecated |
|
| 53 | + */ |
|
| 54 | + const city_question_id = 6; |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @deprecated |
|
| 59 | + */ |
|
| 60 | + const state_question_id = 7; |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @deprecated |
|
| 65 | + */ |
|
| 66 | + const country_question_id = 8; |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @deprecated |
|
| 71 | + */ |
|
| 72 | + const zip_question_id = 9; |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @deprecated |
|
| 77 | + */ |
|
| 78 | + const phone_question_id = 10; |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * When looking for questions that correspond to attendee fields, |
|
| 82 | + * look for the question with this QST_system value. |
|
| 83 | + * These replace the old constants like EEM_Attendee::*_question_id |
|
| 84 | + */ |
|
| 85 | + const system_question_fname = 'fname'; |
|
| 86 | + |
|
| 87 | + const system_question_lname = 'lname'; |
|
| 88 | + |
|
| 89 | + const system_question_email = 'email'; |
|
| 90 | + |
|
| 91 | + const system_question_email_confirm = 'email_confirm'; |
|
| 92 | + |
|
| 93 | + const system_question_address = 'address'; |
|
| 94 | + |
|
| 95 | + const system_question_address2 = 'address2'; |
|
| 96 | + |
|
| 97 | + const system_question_city = 'city'; |
|
| 98 | + |
|
| 99 | + const system_question_state = 'state'; |
|
| 100 | + |
|
| 101 | + const system_question_country = 'country'; |
|
| 102 | + |
|
| 103 | + const system_question_zip = 'zip'; |
|
| 104 | + |
|
| 105 | + const system_question_phone = 'phone'; |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Keys are all the EEM_Attendee::system_question_* constants, which are |
|
| 109 | + * also all the values of QST_system in the questions table, and values |
|
| 110 | + * are their corresponding Attendee field names |
|
| 111 | + * |
|
| 112 | + * @var array |
|
| 113 | + */ |
|
| 114 | + protected $_system_question_to_attendee_field_name = array( |
|
| 115 | + EEM_Attendee::system_question_fname => 'ATT_fname', |
|
| 116 | + EEM_Attendee::system_question_lname => 'ATT_lname', |
|
| 117 | + EEM_Attendee::system_question_email => 'ATT_email', |
|
| 118 | + EEM_Attendee::system_question_address => 'ATT_address', |
|
| 119 | + EEM_Attendee::system_question_address2 => 'ATT_address2', |
|
| 120 | + EEM_Attendee::system_question_city => 'ATT_city', |
|
| 121 | + EEM_Attendee::system_question_state => 'STA_ID', |
|
| 122 | + EEM_Attendee::system_question_country => 'CNT_ISO', |
|
| 123 | + EEM_Attendee::system_question_zip => 'ATT_zip', |
|
| 124 | + EEM_Attendee::system_question_phone => 'ATT_phone', |
|
| 125 | + ); |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * EEM_Attendee constructor. |
|
| 131 | + * |
|
| 132 | + * @param null $timezone |
|
| 133 | + * @param ModelFieldFactory $model_field_factory |
|
| 134 | + * @throws EE_Error |
|
| 135 | + * @throws InvalidArgumentException |
|
| 136 | + */ |
|
| 137 | + protected function __construct($timezone = null, ModelFieldFactory $model_field_factory) |
|
| 138 | + { |
|
| 139 | + $this->singular_item = esc_html__('Attendee', 'event_espresso'); |
|
| 140 | + $this->plural_item = esc_html__('Attendees', 'event_espresso'); |
|
| 141 | + $this->_tables = array( |
|
| 142 | + 'Attendee_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
| 143 | + 'Attendee_Meta' => new EE_Secondary_Table( |
|
| 144 | + 'esp_attendee_meta', |
|
| 145 | + 'ATTM_ID', |
|
| 146 | + 'ATT_ID' |
|
| 147 | + ), |
|
| 148 | + ); |
|
| 149 | + $this->_fields = array( |
|
| 150 | + 'Attendee_CPT' => array( |
|
| 151 | + 'ATT_ID' => $model_field_factory->createPrimaryKeyIntField( |
|
| 152 | + 'ID', |
|
| 153 | + esc_html__('Attendee ID', 'event_espresso') |
|
| 154 | + ), |
|
| 155 | + 'ATT_full_name' => $model_field_factory->createPlainTextField( |
|
| 156 | + 'post_title', |
|
| 157 | + esc_html__('Attendee Full Name', 'event_espresso'), |
|
| 158 | + false, |
|
| 159 | + esc_html__('Unknown', 'event_espresso') |
|
| 160 | + ), |
|
| 161 | + 'ATT_bio' => $model_field_factory->createPostContentField( |
|
| 162 | + 'post_content', |
|
| 163 | + esc_html__('Attendee Biography', 'event_espresso'), |
|
| 164 | + false, |
|
| 165 | + esc_html__('No Biography Provided', 'event_espresso') |
|
| 166 | + ), |
|
| 167 | + 'ATT_slug' => $model_field_factory->createSlugField( |
|
| 168 | + 'post_name', |
|
| 169 | + esc_html__('Attendee URL Slug', 'event_espresso') |
|
| 170 | + ), |
|
| 171 | + 'ATT_created' => $model_field_factory->createDatetimeField( |
|
| 172 | + 'post_date', |
|
| 173 | + esc_html__('Time Attendee Created', 'event_espresso') |
|
| 174 | + ), |
|
| 175 | + 'ATT_short_bio' => $model_field_factory->createSimpleHtmlField( |
|
| 176 | + 'post_excerpt', |
|
| 177 | + esc_html__('Attendee Short Biography', 'event_espresso'), |
|
| 178 | + true, |
|
| 179 | + esc_html__('No Biography Provided', 'event_espresso') |
|
| 180 | + ), |
|
| 181 | + 'ATT_modified' => $model_field_factory->createDatetimeField( |
|
| 182 | + 'post_modified', |
|
| 183 | + esc_html__('Time Attendee Last Modified', 'event_espresso') |
|
| 184 | + ), |
|
| 185 | + 'ATT_author' => $model_field_factory->createWpUserField( |
|
| 186 | + 'post_author', |
|
| 187 | + esc_html__('Creator ID of the first Event attended', 'event_espresso'), |
|
| 188 | + false |
|
| 189 | + ), |
|
| 190 | + 'ATT_parent' => $model_field_factory->createDbOnlyIntField( |
|
| 191 | + 'post_parent', |
|
| 192 | + esc_html__('Parent Attendee (unused)', 'event_espresso'), |
|
| 193 | + false, |
|
| 194 | + 0 |
|
| 195 | + ), |
|
| 196 | + 'post_type' => $model_field_factory->createWpPostTypeField('espresso_attendees'), |
|
| 197 | + 'status' => $model_field_factory->createWpPostStatusField( |
|
| 198 | + 'post_status', |
|
| 199 | + esc_html__('Attendee Status', 'event_espresso'), |
|
| 200 | + false, |
|
| 201 | + 'publish' |
|
| 202 | + ), |
|
| 203 | + 'password' => new EE_Password_Field( |
|
| 204 | + 'post_password', |
|
| 205 | + __('Password', 'event_espresso'), |
|
| 206 | + false, |
|
| 207 | + '', |
|
| 208 | + array( |
|
| 209 | + 'ATT_bio', |
|
| 210 | + 'ATT_short_bio', |
|
| 211 | + 'ATT_address', |
|
| 212 | + 'ATT_address2', |
|
| 213 | + 'ATT_city', |
|
| 214 | + 'STA_ID', |
|
| 215 | + 'CNT_ISO', |
|
| 216 | + 'ATT_zip', |
|
| 217 | + 'ATT_email', |
|
| 218 | + 'ATT_phone' |
|
| 219 | + ) |
|
| 220 | + ) |
|
| 221 | + ), |
|
| 222 | + 'Attendee_Meta' => array( |
|
| 223 | + 'ATTM_ID' => $model_field_factory->createDbOnlyIntField( |
|
| 224 | + 'ATTM_ID', |
|
| 225 | + esc_html__('Attendee Meta Row ID', 'event_espresso'), |
|
| 226 | + false |
|
| 227 | + ), |
|
| 228 | + 'ATT_ID_fk' => $model_field_factory->createDbOnlyIntField( |
|
| 229 | + 'ATT_ID', |
|
| 230 | + esc_html__('Foreign Key to Attendee in Post Table', 'event_espresso'), |
|
| 231 | + false |
|
| 232 | + ), |
|
| 233 | + 'ATT_fname' => $model_field_factory->createPlainTextField( |
|
| 234 | + 'ATT_fname', |
|
| 235 | + esc_html__('First Name', 'event_espresso') |
|
| 236 | + ), |
|
| 237 | + 'ATT_lname' => $model_field_factory->createPlainTextField( |
|
| 238 | + 'ATT_lname', |
|
| 239 | + esc_html__('Last Name', 'event_espresso') |
|
| 240 | + ), |
|
| 241 | + 'ATT_address' => $model_field_factory->createPlainTextField( |
|
| 242 | + 'ATT_address', |
|
| 243 | + esc_html__('Address Part 1', 'event_espresso') |
|
| 244 | + ), |
|
| 245 | + 'ATT_address2' => $model_field_factory->createPlainTextField( |
|
| 246 | + 'ATT_address2', |
|
| 247 | + esc_html__('Address Part 2', 'event_espresso') |
|
| 248 | + ), |
|
| 249 | + 'ATT_city' => $model_field_factory->createPlainTextField( |
|
| 250 | + 'ATT_city', |
|
| 251 | + esc_html__('City', 'event_espresso') |
|
| 252 | + ), |
|
| 253 | + 'STA_ID' => $model_field_factory->createForeignKeyIntField( |
|
| 254 | + 'STA_ID', |
|
| 255 | + esc_html__('State', 'event_espresso'), |
|
| 256 | + true, |
|
| 257 | + 0, |
|
| 258 | + 'State' |
|
| 259 | + ), |
|
| 260 | + 'CNT_ISO' => $model_field_factory->createForeignKeyStringField( |
|
| 261 | + 'CNT_ISO', |
|
| 262 | + esc_html__('Country', 'event_espresso'), |
|
| 263 | + true, |
|
| 264 | + '', |
|
| 265 | + 'Country' |
|
| 266 | + ), |
|
| 267 | + 'ATT_zip' => $model_field_factory->createPlainTextField( |
|
| 268 | + 'ATT_zip', |
|
| 269 | + esc_html__('ZIP/Postal Code', 'event_espresso') |
|
| 270 | + ), |
|
| 271 | + 'ATT_email' => $model_field_factory->createEmailField( |
|
| 272 | + 'ATT_email', |
|
| 273 | + esc_html__('Email Address', 'event_espresso') |
|
| 274 | + ), |
|
| 275 | + 'ATT_phone' => $model_field_factory->createPlainTextField( |
|
| 276 | + 'ATT_phone', |
|
| 277 | + esc_html__('Phone', 'event_espresso') |
|
| 278 | + ), |
|
| 279 | + ), |
|
| 280 | + ); |
|
| 281 | + $this->_model_relations = array( |
|
| 282 | + 'Registration' => new EE_Has_Many_Relation(), |
|
| 283 | + 'State' => new EE_Belongs_To_Relation(), |
|
| 284 | + 'Country' => new EE_Belongs_To_Relation(), |
|
| 285 | + 'Event' => new EE_HABTM_Relation('Registration', false), |
|
| 286 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
| 287 | + 'Message' => new EE_Has_Many_Any_Relation(false), |
|
| 288 | + // allow deletion of attendees even if they have messages in the queue for them. |
|
| 289 | + 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
| 290 | + 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
| 291 | + ); |
|
| 292 | + $this->_caps_slug = 'contacts'; |
|
| 293 | + $this->model_chain_to_password = ''; |
|
| 294 | + parent::__construct($timezone); |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + |
|
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * Gets the name of the field on the attendee model corresponding to the system question string |
|
| 301 | + * which should be one of the keys from EEM_Attendee::_system_question_to_attendee_field_name |
|
| 302 | + * |
|
| 303 | + * @param string $system_question_string |
|
| 304 | + * @return string|null if not found |
|
| 305 | + */ |
|
| 306 | + public function get_attendee_field_for_system_question($system_question_string) |
|
| 307 | + { |
|
| 308 | + return isset($this->_system_question_to_attendee_field_name[ $system_question_string ]) |
|
| 309 | + ? $this->_system_question_to_attendee_field_name[ $system_question_string ] |
|
| 310 | + : null; |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * Gets mapping from esp_question.QST_system values to their corresponding attendee field names |
|
| 317 | + * |
|
| 318 | + * @return array |
|
| 319 | + */ |
|
| 320 | + public function system_question_to_attendee_field_mapping() |
|
| 321 | + { |
|
| 322 | + return $this->_system_question_to_attendee_field_name; |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + |
|
| 326 | + |
|
| 327 | + /** |
|
| 328 | + * Gets all the attendees for a transaction (by using the esp_registration as a join table) |
|
| 329 | + * |
|
| 330 | + * @param EE_Transaction /int $transaction_id_or_obj EE_Transaction or its ID |
|
| 331 | + * @return EE_Attendee[]|EE_Base_Class[] |
|
| 332 | + * @throws EE_Error |
|
| 333 | + */ |
|
| 334 | + public function get_attendees_for_transaction($transaction_id_or_obj) |
|
| 335 | + { |
|
| 336 | + return $this->get_all( |
|
| 337 | + array( |
|
| 338 | + array( |
|
| 339 | + 'Registration.Transaction.TXN_ID' => $transaction_id_or_obj instanceof EE_Transaction |
|
| 340 | + ? $transaction_id_or_obj->ID() |
|
| 341 | + : $transaction_id_or_obj, |
|
| 342 | + ), |
|
| 343 | + ) |
|
| 344 | + ); |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + |
|
| 348 | + |
|
| 349 | + /** |
|
| 350 | + * retrieve a single attendee from db via their ID |
|
| 351 | + * |
|
| 352 | + * @param $ATT_ID |
|
| 353 | + * @return mixed array on success, FALSE on fail |
|
| 354 | + * @deprecated |
|
| 355 | + */ |
|
| 356 | + public function get_attendee_by_ID($ATT_ID = false) |
|
| 357 | + { |
|
| 358 | + // retrieve a particular EE_Attendee |
|
| 359 | + return $this->get_one_by_ID($ATT_ID); |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * retrieve a single attendee from db via their ID |
|
| 366 | + * |
|
| 367 | + * @param array $where_cols_n_values |
|
| 368 | + * @return mixed array on success, FALSE on fail |
|
| 369 | + * @throws EE_Error |
|
| 370 | + */ |
|
| 371 | + public function get_attendee($where_cols_n_values = array()) |
|
| 372 | + { |
|
| 373 | + if (empty($where_cols_n_values)) { |
|
| 374 | + return false; |
|
| 375 | + } |
|
| 376 | + $attendee = $this->get_all(array($where_cols_n_values)); |
|
| 377 | + if (! empty($attendee)) { |
|
| 378 | + return array_shift($attendee); |
|
| 379 | + } |
|
| 380 | + return false; |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * Search for an existing Attendee record in the DB |
|
| 387 | + * |
|
| 388 | + * @param array $where_cols_n_values |
|
| 389 | + * @return bool|mixed |
|
| 390 | + * @throws EE_Error |
|
| 391 | + */ |
|
| 392 | + public function find_existing_attendee($where_cols_n_values = null) |
|
| 393 | + { |
|
| 394 | + // search by combo of first and last names plus the email address |
|
| 395 | + $attendee_data_keys = array( |
|
| 396 | + 'ATT_fname' => $this->_ATT_fname, |
|
| 397 | + 'ATT_lname' => $this->_ATT_lname, |
|
| 398 | + 'ATT_email' => $this->_ATT_email, |
|
| 399 | + ); |
|
| 400 | + // no search params means attendee object already exists. |
|
| 401 | + $where_cols_n_values = is_array($where_cols_n_values) && ! empty($where_cols_n_values) |
|
| 402 | + ? $where_cols_n_values |
|
| 403 | + : $attendee_data_keys; |
|
| 404 | + $valid_data = true; |
|
| 405 | + // check for required values |
|
| 406 | + $valid_data = isset($where_cols_n_values['ATT_fname']) && ! empty($where_cols_n_values['ATT_fname']) |
|
| 407 | + ? $valid_data |
|
| 408 | + : false; |
|
| 409 | + $valid_data = isset($where_cols_n_values['ATT_lname']) && ! empty($where_cols_n_values['ATT_lname']) |
|
| 410 | + ? $valid_data |
|
| 411 | + : false; |
|
| 412 | + $valid_data = isset($where_cols_n_values['ATT_email']) && ! empty($where_cols_n_values['ATT_email']) |
|
| 413 | + ? $valid_data |
|
| 414 | + : false; |
|
| 415 | + if ($valid_data) { |
|
| 416 | + $attendee = $this->get_attendee($where_cols_n_values); |
|
| 417 | + if ($attendee instanceof EE_Attendee) { |
|
| 418 | + return $attendee; |
|
| 419 | + } |
|
| 420 | + } |
|
| 421 | + return false; |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + |
|
| 425 | + |
|
| 426 | + /** |
|
| 427 | + * Takes an incoming array of EE_Registration ids |
|
| 428 | + * and sends back a list of corresponding non duplicate EE_Attendee objects. |
|
| 429 | + * |
|
| 430 | + * @since 4.3.0 |
|
| 431 | + * @param array $ids array of EE_Registration ids |
|
| 432 | + * @return EE_Attendee[]|EE_Base_Class[] |
|
| 433 | + * @throws EE_Error |
|
| 434 | + */ |
|
| 435 | + public function get_array_of_contacts_from_reg_ids($ids) |
|
| 436 | + { |
|
| 437 | + $ids = (array) $ids; |
|
| 438 | + $_where = array( |
|
| 439 | + 'Registration.REG_ID' => array('in', $ids), |
|
| 440 | + ); |
|
| 441 | + return $this->get_all(array($_where)); |
|
| 442 | + } |
|
| 443 | 443 | } |
@@ -23,32 +23,32 @@ |
||
| 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 | } |
@@ -124,7 +124,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | |
@@ -9,628 +9,628 @@ |
||
| 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 | } |
@@ -18,56 +18,56 @@ |
||
| 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 | } |
@@ -59,11 +59,11 @@ |
||
| 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 | ); |
@@ -6,14 +6,14 @@ |
||
| 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 | } |
@@ -7,49 +7,49 @@ |
||
| 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 | } |