1
|
|
|
<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
2
|
|
|
exit('No direct script access allowed'); |
3
|
|
|
} |
4
|
|
|
/** |
5
|
|
|
* Event Espresso |
6
|
|
|
* Event Registration and Management Plugin for WordPress |
7
|
|
|
* @ package Event Espresso |
8
|
|
|
* @ author Seth Shoultes |
9
|
|
|
* @ copyright (c) 2008-2011 Event Espresso All Rights Reserved. |
10
|
|
|
* @ license http://eventespresso.com/support/terms-conditions/ * see Plugin Licensing * |
11
|
|
|
* @ link http://www.eventespresso.com |
12
|
|
|
* @ version 4.0 |
13
|
|
|
* ------------------------------------------------------------------------ |
14
|
|
|
* Attendee Model |
15
|
|
|
* |
16
|
|
|
* @package Event Espresso |
17
|
|
|
* @subpackage includes/models/ |
18
|
|
|
* @author Michael Nelson |
19
|
|
|
* ------------------------------------------------------------------------ |
20
|
|
|
*/ |
21
|
|
|
require_once(EE_MODELS . 'EEM_Base.model.php'); |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
|
25
|
|
|
class EEM_Term_Taxonomy extends EEM_Base |
26
|
|
|
{ |
27
|
|
|
|
28
|
|
|
// private instance of the Attendee object |
29
|
|
|
protected static $_instance = null; |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
|
33
|
|
|
protected function __construct($timezone = null) |
34
|
|
|
{ |
35
|
|
|
$this->singular_item = __('Term Taxonomy', 'event_espresso'); |
36
|
|
|
$this->plural_item = __('Term Taxonomy', 'event_espresso'); |
37
|
|
|
$this->_tables = array( |
38
|
|
|
'Term_Taxonomy' => new EE_Primary_Table('term_taxonomy', 'term_taxonomy_id'), |
39
|
|
|
); |
40
|
|
|
$this->_fields = array( |
41
|
|
|
'Term_Taxonomy' => array( |
42
|
|
|
'term_taxonomy_id' => new EE_Primary_Key_Int_Field( |
43
|
|
|
'term_taxonomy_id', |
44
|
|
|
__('Term-Taxonomy ID', 'event_espresso') |
45
|
|
|
), |
46
|
|
|
'term_id' => new EE_Foreign_Key_Int_Field( |
47
|
|
|
'term_id', |
48
|
|
|
__("Term Id", "event_espresso"), |
49
|
|
|
false, |
50
|
|
|
0, |
51
|
|
|
'Term' |
52
|
|
|
), |
53
|
|
|
'taxonomy' => new EE_Plain_Text_Field( |
54
|
|
|
'taxonomy', |
55
|
|
|
__('Taxonomy Name', 'event_espresso'), |
56
|
|
|
false, |
57
|
|
|
'category' |
58
|
|
|
), |
59
|
|
|
'description' => new EE_Post_Content_Field( |
60
|
|
|
'description', |
61
|
|
|
__("Description of Term", "event_espresso"), |
62
|
|
|
false, |
63
|
|
|
'' |
64
|
|
|
), |
65
|
|
|
'parent' => new EE_Integer_Field('parent', __("Parent Term ID", "event_espresso"), false, 0), |
66
|
|
|
'term_count' => new EE_Integer_Field( |
67
|
|
|
'count', |
68
|
|
|
__("Count of Objects attached", 'event_espresso'), |
69
|
|
|
false, |
70
|
|
|
0 |
71
|
|
|
), |
72
|
|
|
), |
73
|
|
|
); |
74
|
|
|
$this->_model_relations = array( |
75
|
|
|
'Term_Relationship' => new EE_Has_Many_Relation(), |
76
|
|
|
'Term' => new EE_Belongs_To_Relation(), |
77
|
|
|
); |
78
|
|
|
$cpt_models = array_keys(EE_Registry::instance()->cpt_models()); |
79
|
|
|
foreach ($cpt_models as $model_name) { |
80
|
|
|
$this->_model_relations[$model_name] = new EE_HABTM_Relation('Term_Relationship'); |
81
|
|
|
} |
82
|
|
|
$this->_indexes = array( |
83
|
|
|
'term_id_taxonomy' => new EE_Unique_Index(array('term_id', 'taxonomy')), |
84
|
|
|
); |
85
|
|
|
$path_to_tax_model = ''; |
86
|
|
|
$this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
87
|
|
|
$this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Taxonomy_Protected( |
88
|
|
|
$path_to_tax_model |
89
|
|
|
); |
90
|
|
|
$this->_cap_restriction_generators[EEM_Base::caps_edit] = false; |
91
|
|
|
$this->_cap_restriction_generators[EEM_Base::caps_delete] = false; |
92
|
|
|
//add cap restrictions for editing relating to the "ee_edit_*" |
93
|
|
|
$this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
94
|
|
|
array( |
95
|
|
|
$path_to_tax_model . 'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'), |
96
|
|
|
) |
97
|
|
|
); |
98
|
|
|
$this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
99
|
|
|
array( |
100
|
|
|
$path_to_tax_model . 'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'), |
101
|
|
|
) |
102
|
|
|
); |
103
|
|
|
$this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
104
|
|
|
array( |
105
|
|
|
$path_to_tax_model . 'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'), |
106
|
|
|
) |
107
|
|
|
); |
108
|
|
|
//add cap restrictions for deleting relating to the "ee_deleting_*" |
109
|
|
|
$this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
110
|
|
|
array( |
111
|
|
|
$path_to_tax_model . 'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'), |
112
|
|
|
) |
113
|
|
|
); |
114
|
|
|
$this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
115
|
|
|
array( |
116
|
|
|
$path_to_tax_model . 'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'), |
117
|
|
|
) |
118
|
|
|
); |
119
|
|
|
$this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
120
|
|
|
array( |
121
|
|
|
$path_to_tax_model . 'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'), |
122
|
|
|
) |
123
|
|
|
); |
124
|
|
|
parent::__construct($timezone); |
125
|
|
|
add_filter('FHEE__Read__create_model_query_params', array('EEM_Term_Taxonomy', 'rest_api_query_params'), 10, 3); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
|
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Makes sure that during REST API queries, we only return term-taxonomies |
132
|
|
|
* for term taxonomies which should be shown in the rest api |
133
|
|
|
* |
134
|
|
|
* @param array $model_query_params |
135
|
|
|
* @param array $querystring_query_params |
136
|
|
|
* @param EEM_Base $model |
137
|
|
|
* @return array |
138
|
|
|
*/ |
139
|
|
View Code Duplication |
public static function rest_api_query_params($model_query_params, $querystring_query_params, $model) |
140
|
|
|
{ |
141
|
|
|
if ($model === EEM_Term_Taxonomy::instance()) { |
142
|
|
|
$taxonomies = get_taxonomies(array('show_in_rest' => true)); |
143
|
|
|
if (! empty($taxonomies)) { |
144
|
|
|
$model_query_params[0]['taxonomy'] = array('IN', $taxonomies); |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
return $model_query_params; |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
// End of file EEM_Term_Taxonomy.model.php |
151
|
|
|
// Location: /includes/models/EEM_Term_Taxonomy.model.php |
152
|
|
|
|