@@ -46,6 +46,10 @@ discard block  | 
                                                    ||
| 46 | 46 | */  | 
                                                        
| 47 | 47 | protected $model_obj_nodes;  | 
                                                        
| 48 | 48 | |
| 49 | + /**  | 
                                                        |
| 50 | + * @param EE_Base_Class $main_model_obj  | 
                                                        |
| 51 | + * @param EEM_Base|null $related_model  | 
                                                        |
| 52 | + */  | 
                                                        |
| 49 | 53 | public function __construct($main_model_obj, $related_model)  | 
                                                        
| 50 | 54 |      { | 
                                                        
| 51 | 55 | $this->main_model_obj = $main_model_obj;  | 
                                                        
@@ -122,7 +126,7 @@ discard block  | 
                                                    ||
| 122 | 126 | * Visits the provided nodes and keeps track of how much work was done, making sure to not go over budget.  | 
                                                        
| 123 | 127 | * @since $VID:$  | 
                                                        
| 124 | 128 | * @param ModelObjNode[] $model_obj_nodes  | 
                                                        
| 125 | - * @param $work_budget  | 
                                                        |
| 129 | + * @param integer $work_budget  | 
                                                        |
| 126 | 130 | * @return int  | 
                                                        
| 127 | 131 | */  | 
                                                        
| 128 | 132 | protected function visitAlreadyDiscoveredNodes($model_obj_nodes, $work_budget)  | 
                                                        
@@ -5,11 +5,9 @@  | 
                                                    ||
| 5 | 5 | use EE_Base_Class;  | 
                                                        
| 6 | 6 | use EE_Error;  | 
                                                        
| 7 | 7 | use EE_Has_Many_Any_Relation;  | 
                                                        
| 8 | -use EE_Model_Relation_Base;  | 
                                                        |
| 9 | 8 | use EEM_Base;  | 
                                                        
| 10 | 9 | use EventEspresso\core\exceptions\InvalidDataTypeException;  | 
                                                        
| 11 | 10 | use EventEspresso\core\exceptions\InvalidInterfaceException;  | 
                                                        
| 12 | -use EventEspresso\core\services\payment_methods\forms\PayPalSettingsForm;  | 
                                                        |
| 13 | 11 | use InvalidArgumentException;  | 
                                                        
| 14 | 12 | use ReflectionException;  | 
                                                        
| 15 | 13 | |
@@ -26,225 +26,225 @@  | 
                                                    ||
| 26 | 26 | */  | 
                                                        
| 27 | 27 | class RelationNode extends BaseNode  | 
                                                        
| 28 | 28 |  { | 
                                                        
| 29 | - /**  | 
                                                        |
| 30 | - * @var EE_Base_Class  | 
                                                        |
| 31 | - */  | 
                                                        |
| 32 | - protected $main_model_obj;  | 
                                                        |
| 33 | -  | 
                                                        |
| 34 | - /**  | 
                                                        |
| 35 | - * @var int  | 
                                                        |
| 36 | - */  | 
                                                        |
| 37 | - protected $count;  | 
                                                        |
| 38 | -  | 
                                                        |
| 39 | - /**  | 
                                                        |
| 40 | - * @var EEM_Base  | 
                                                        |
| 41 | - */  | 
                                                        |
| 42 | - protected $related_model;  | 
                                                        |
| 43 | -  | 
                                                        |
| 44 | - /**  | 
                                                        |
| 45 | - * @var ModelObjNode[]  | 
                                                        |
| 46 | - */  | 
                                                        |
| 47 | - protected $model_obj_nodes;  | 
                                                        |
| 48 | -  | 
                                                        |
| 49 | - public function __construct($main_model_obj, $related_model)  | 
                                                        |
| 50 | -    { | 
                                                        |
| 51 | - $this->main_model_obj = $main_model_obj;  | 
                                                        |
| 52 | - $this->related_model = $related_model;  | 
                                                        |
| 53 | - $this->model_obj_nodes = [];  | 
                                                        |
| 54 | - }  | 
                                                        |
| 55 | -  | 
                                                        |
| 56 | -  | 
                                                        |
| 57 | - /**  | 
                                                        |
| 58 | - * Here is where most of the work happens. We've counted how many related model objects exist, here we identify  | 
                                                        |
| 59 | - * them (ie, learn their IDs). But its recursive, so we'll also find their related dependent model objects etc.  | 
                                                        |
| 60 | - * @since $VID:$  | 
                                                        |
| 61 | - * @param int $model_objects_to_identify  | 
                                                        |
| 62 | - * @return int  | 
                                                        |
| 63 | - * @throws EE_Error  | 
                                                        |
| 64 | - * @throws InvalidArgumentException  | 
                                                        |
| 65 | - * @throws InvalidDataTypeException  | 
                                                        |
| 66 | - * @throws InvalidInterfaceException  | 
                                                        |
| 67 | - * @throws ReflectionException  | 
                                                        |
| 68 | - */  | 
                                                        |
| 69 | - protected function work($model_objects_to_identify)  | 
                                                        |
| 70 | -    { | 
                                                        |
| 71 | - $num_identified = $this->visitAlreadyDiscoveredNodes($this->model_obj_nodes, $model_objects_to_identify);  | 
                                                        |
| 72 | -        if ($num_identified < $model_objects_to_identify) { | 
                                                        |
| 73 | - $related_model_objs = $this->related_model->get_all(  | 
                                                        |
| 74 | - [  | 
                                                        |
| 75 | - $this->whereQueryParams(),  | 
                                                        |
| 76 | - 'limit' => [  | 
                                                        |
| 77 | - count($this->model_obj_nodes),  | 
                                                        |
| 78 | - $model_objects_to_identify  | 
                                                        |
| 79 | - ]  | 
                                                        |
| 80 | - ]  | 
                                                        |
| 81 | - );  | 
                                                        |
| 82 | - $new_item_nodes = [];  | 
                                                        |
| 83 | -  | 
                                                        |
| 84 | - // Add entity nodes for each of the model objects we fetched.  | 
                                                        |
| 85 | -            foreach ($related_model_objs as $related_model_obj) { | 
                                                        |
| 86 | - $entity_node = new ModelObjNode($related_model_obj);  | 
                                                        |
| 87 | - $this->model_obj_nodes[ $related_model_obj->ID() ] = $entity_node;  | 
                                                        |
| 88 | - $new_item_nodes[ $related_model_obj->ID() ] = $entity_node;  | 
                                                        |
| 89 | - }  | 
                                                        |
| 90 | - $num_identified += count($new_item_nodes);  | 
                                                        |
| 91 | -            if ($num_identified < $model_objects_to_identify) { | 
                                                        |
| 92 | - // And lastly do the work.  | 
                                                        |
| 93 | - $num_identified += $this->visitAlreadyDiscoveredNodes(  | 
                                                        |
| 94 | - $new_item_nodes,  | 
                                                        |
| 95 | - $model_objects_to_identify - $num_identified  | 
                                                        |
| 96 | - );  | 
                                                        |
| 97 | - }  | 
                                                        |
| 98 | - }  | 
                                                        |
| 99 | -  | 
                                                        |
| 100 | -        if (count($this->model_obj_nodes) >= $this->count && $this->allChildrenComplete()) { | 
                                                        |
| 101 | - $this->complete = true;  | 
                                                        |
| 102 | - }  | 
                                                        |
| 103 | - return $num_identified;  | 
                                                        |
| 104 | - }  | 
                                                        |
| 105 | -  | 
                                                        |
| 106 | - /**  | 
                                                        |
| 107 | - * Checks if all the identified child nodes are complete or not.  | 
                                                        |
| 108 | - * @since $VID:$  | 
                                                        |
| 109 | - * @return bool  | 
                                                        |
| 110 | - */  | 
                                                        |
| 111 | - protected function allChildrenComplete()  | 
                                                        |
| 112 | -    { | 
                                                        |
| 113 | -        foreach ($this->model_obj_nodes as $model_obj_node) { | 
                                                        |
| 114 | -            if (! $model_obj_node->isComplete()) { | 
                                                        |
| 115 | - return false;  | 
                                                        |
| 116 | - }  | 
                                                        |
| 117 | - }  | 
                                                        |
| 118 | - return true;  | 
                                                        |
| 119 | - }  | 
                                                        |
| 120 | -  | 
                                                        |
| 121 | - /**  | 
                                                        |
| 122 | - * Visits the provided nodes and keeps track of how much work was done, making sure to not go over budget.  | 
                                                        |
| 123 | - * @since $VID:$  | 
                                                        |
| 124 | - * @param ModelObjNode[] $model_obj_nodes  | 
                                                        |
| 125 | - * @param $work_budget  | 
                                                        |
| 126 | - * @return int  | 
                                                        |
| 127 | - */  | 
                                                        |
| 128 | - protected function visitAlreadyDiscoveredNodes($model_obj_nodes, $work_budget)  | 
                                                        |
| 129 | -    { | 
                                                        |
| 130 | - $work_done = 0;  | 
                                                        |
| 131 | -        if (! $model_obj_nodes) { | 
                                                        |
| 132 | - return 0;  | 
                                                        |
| 133 | - }  | 
                                                        |
| 134 | -        foreach ($model_obj_nodes as $model_obj_node) { | 
                                                        |
| 135 | -            if ($work_done >= $work_budget) { | 
                                                        |
| 136 | - break;  | 
                                                        |
| 137 | - }  | 
                                                        |
| 138 | - $work_done += $model_obj_node->visit($work_budget - $work_done);  | 
                                                        |
| 139 | - }  | 
                                                        |
| 140 | - return $work_done;  | 
                                                        |
| 141 | - }  | 
                                                        |
| 142 | -  | 
                                                        |
| 143 | - /**  | 
                                                        |
| 144 | - * Whether this item has already been initialized  | 
                                                        |
| 145 | - */  | 
                                                        |
| 146 | - protected function isDiscovered()  | 
                                                        |
| 147 | -    { | 
                                                        |
| 148 | - return $this->count !== null;  | 
                                                        |
| 149 | - }  | 
                                                        |
| 150 | -  | 
                                                        |
| 151 | - /**  | 
                                                        |
| 152 | - * @since $VID:$  | 
                                                        |
| 153 | - * @return boolean  | 
                                                        |
| 154 | - */  | 
                                                        |
| 155 | - public function isComplete()  | 
                                                        |
| 156 | -    { | 
                                                        |
| 157 | -        if ($this->complete === null) { | 
                                                        |
| 158 | -            if (count($this->model_obj_nodes) === $this->count) { | 
                                                        |
| 159 | - $this->complete = true;  | 
                                                        |
| 160 | -            } else { | 
                                                        |
| 161 | - $this->complete = false;  | 
                                                        |
| 162 | - }  | 
                                                        |
| 163 | - }  | 
                                                        |
| 164 | - return $this->complete;  | 
                                                        |
| 165 | - }  | 
                                                        |
| 166 | -  | 
                                                        |
| 167 | - /**  | 
                                                        |
| 168 | - * Discovers how many related model objects exist.  | 
                                                        |
| 169 | - * @since $VID:$  | 
                                                        |
| 170 | - * @return mixed|void  | 
                                                        |
| 171 | - * @throws EE_Error  | 
                                                        |
| 172 | - * @throws InvalidArgumentException  | 
                                                        |
| 173 | - * @throws InvalidDataTypeException  | 
                                                        |
| 174 | - * @throws InvalidInterfaceException  | 
                                                        |
| 175 | - * @throws ReflectionException  | 
                                                        |
| 176 | - */  | 
                                                        |
| 177 | - protected function discover()  | 
                                                        |
| 178 | -    { | 
                                                        |
| 179 | - $this->count = $this->related_model->count([$this->whereQueryParams()]);  | 
                                                        |
| 180 | - }  | 
                                                        |
| 181 | -  | 
                                                        |
| 182 | - /**  | 
                                                        |
| 183 | - * @since $VID:$  | 
                                                        |
| 184 | - * @return array  | 
                                                        |
| 185 | - * @throws EE_Error  | 
                                                        |
| 186 | - * @throws InvalidDataTypeException  | 
                                                        |
| 187 | - * @throws InvalidInterfaceException  | 
                                                        |
| 188 | - * @throws InvalidArgumentException  | 
                                                        |
| 189 | - * @throws ReflectionException  | 
                                                        |
| 190 | - */  | 
                                                        |
| 191 | - protected function whereQueryParams()  | 
                                                        |
| 192 | -    { | 
                                                        |
| 193 | - $where_params = [  | 
                                                        |
| 194 | - $this->related_model->get_foreign_key_to(  | 
                                                        |
| 195 | - $this->main_model_obj->get_model()->get_this_model_name()  | 
                                                        |
| 196 | - )->get_name() => $this->main_model_obj->ID()  | 
                                                        |
| 197 | - ];  | 
                                                        |
| 198 | -        try { | 
                                                        |
| 199 | - $relation_settings = $this->main_model_obj->get_model()->related_settings_for($this->related_model->get_this_model_name());  | 
                                                        |
| 200 | -        } catch (EE_Error $e) { | 
                                                        |
| 201 | - // This will happen for has-and-belongs-to-many relations, when this node's related model is that join table  | 
                                                        |
| 202 | - // which hasn't been explicitly declared in the main model object's model's relations.  | 
                                                        |
| 203 | - $relation_settings = null;  | 
                                                        |
| 204 | - }  | 
                                                        |
| 205 | -        if ($relation_settings instanceof EE_Has_Many_Any_Relation) { | 
                                                        |
| 206 | - $where_params[ $this->related_model->get_field_containing_related_model_name()->get_name() ] = $this->main_model_obj->get_model()->get_this_model_name();  | 
                                                        |
| 207 | - }  | 
                                                        |
| 208 | - return $where_params;  | 
                                                        |
| 209 | - }  | 
                                                        |
| 210 | - /**  | 
                                                        |
| 211 | - * @since $VID:$  | 
                                                        |
| 212 | - * @return array  | 
                                                        |
| 213 | - */  | 
                                                        |
| 214 | - public function toArray()  | 
                                                        |
| 215 | -    { | 
                                                        |
| 216 | - $tree = [  | 
                                                        |
| 217 | - 'count' => $this->count,  | 
                                                        |
| 218 | - 'complete' => $this->isComplete(),  | 
                                                        |
| 219 | - 'objs' => []  | 
                                                        |
| 220 | - ];  | 
                                                        |
| 221 | -        foreach ($this->model_obj_nodes as $id => $model_obj_node) { | 
                                                        |
| 222 | - $tree['objs'][ $id ] = $model_obj_node->toArray();  | 
                                                        |
| 223 | - }  | 
                                                        |
| 224 | - return $tree;  | 
                                                        |
| 225 | - }  | 
                                                        |
| 226 | -  | 
                                                        |
| 227 | - /**  | 
                                                        |
| 228 | - * Gets the IDs of all the model objects to delete; indexed first by model object name.  | 
                                                        |
| 229 | - * @since $VID:$  | 
                                                        |
| 230 | - * @return array  | 
                                                        |
| 231 | - */  | 
                                                        |
| 232 | - public function getIds()  | 
                                                        |
| 233 | -    { | 
                                                        |
| 234 | -        if (empty($this->model_obj_nodes)) { | 
                                                        |
| 235 | - return [];  | 
                                                        |
| 236 | - }  | 
                                                        |
| 237 | - $ids = [  | 
                                                        |
| 238 | - $this->related_model->get_this_model_name() => array_combine(  | 
                                                        |
| 239 | - array_keys($this->model_obj_nodes),  | 
                                                        |
| 240 | - array_keys($this->model_obj_nodes)  | 
                                                        |
| 241 | - )  | 
                                                        |
| 242 | - ];  | 
                                                        |
| 243 | -        foreach ($this->model_obj_nodes as $model_obj_node) { | 
                                                        |
| 244 | - $ids = array_replace_recursive($ids, $model_obj_node->getIds());  | 
                                                        |
| 245 | - }  | 
                                                        |
| 246 | - return $ids;  | 
                                                        |
| 247 | - }  | 
                                                        |
| 29 | + /**  | 
                                                        |
| 30 | + * @var EE_Base_Class  | 
                                                        |
| 31 | + */  | 
                                                        |
| 32 | + protected $main_model_obj;  | 
                                                        |
| 33 | +  | 
                                                        |
| 34 | + /**  | 
                                                        |
| 35 | + * @var int  | 
                                                        |
| 36 | + */  | 
                                                        |
| 37 | + protected $count;  | 
                                                        |
| 38 | +  | 
                                                        |
| 39 | + /**  | 
                                                        |
| 40 | + * @var EEM_Base  | 
                                                        |
| 41 | + */  | 
                                                        |
| 42 | + protected $related_model;  | 
                                                        |
| 43 | +  | 
                                                        |
| 44 | + /**  | 
                                                        |
| 45 | + * @var ModelObjNode[]  | 
                                                        |
| 46 | + */  | 
                                                        |
| 47 | + protected $model_obj_nodes;  | 
                                                        |
| 48 | +  | 
                                                        |
| 49 | + public function __construct($main_model_obj, $related_model)  | 
                                                        |
| 50 | +	{ | 
                                                        |
| 51 | + $this->main_model_obj = $main_model_obj;  | 
                                                        |
| 52 | + $this->related_model = $related_model;  | 
                                                        |
| 53 | + $this->model_obj_nodes = [];  | 
                                                        |
| 54 | + }  | 
                                                        |
| 55 | +  | 
                                                        |
| 56 | +  | 
                                                        |
| 57 | + /**  | 
                                                        |
| 58 | + * Here is where most of the work happens. We've counted how many related model objects exist, here we identify  | 
                                                        |
| 59 | + * them (ie, learn their IDs). But its recursive, so we'll also find their related dependent model objects etc.  | 
                                                        |
| 60 | + * @since $VID:$  | 
                                                        |
| 61 | + * @param int $model_objects_to_identify  | 
                                                        |
| 62 | + * @return int  | 
                                                        |
| 63 | + * @throws EE_Error  | 
                                                        |
| 64 | + * @throws InvalidArgumentException  | 
                                                        |
| 65 | + * @throws InvalidDataTypeException  | 
                                                        |
| 66 | + * @throws InvalidInterfaceException  | 
                                                        |
| 67 | + * @throws ReflectionException  | 
                                                        |
| 68 | + */  | 
                                                        |
| 69 | + protected function work($model_objects_to_identify)  | 
                                                        |
| 70 | +	{ | 
                                                        |
| 71 | + $num_identified = $this->visitAlreadyDiscoveredNodes($this->model_obj_nodes, $model_objects_to_identify);  | 
                                                        |
| 72 | +		if ($num_identified < $model_objects_to_identify) { | 
                                                        |
| 73 | + $related_model_objs = $this->related_model->get_all(  | 
                                                        |
| 74 | + [  | 
                                                        |
| 75 | + $this->whereQueryParams(),  | 
                                                        |
| 76 | + 'limit' => [  | 
                                                        |
| 77 | + count($this->model_obj_nodes),  | 
                                                        |
| 78 | + $model_objects_to_identify  | 
                                                        |
| 79 | + ]  | 
                                                        |
| 80 | + ]  | 
                                                        |
| 81 | + );  | 
                                                        |
| 82 | + $new_item_nodes = [];  | 
                                                        |
| 83 | +  | 
                                                        |
| 84 | + // Add entity nodes for each of the model objects we fetched.  | 
                                                        |
| 85 | +			foreach ($related_model_objs as $related_model_obj) { | 
                                                        |
| 86 | + $entity_node = new ModelObjNode($related_model_obj);  | 
                                                        |
| 87 | + $this->model_obj_nodes[ $related_model_obj->ID() ] = $entity_node;  | 
                                                        |
| 88 | + $new_item_nodes[ $related_model_obj->ID() ] = $entity_node;  | 
                                                        |
| 89 | + }  | 
                                                        |
| 90 | + $num_identified += count($new_item_nodes);  | 
                                                        |
| 91 | +			if ($num_identified < $model_objects_to_identify) { | 
                                                        |
| 92 | + // And lastly do the work.  | 
                                                        |
| 93 | + $num_identified += $this->visitAlreadyDiscoveredNodes(  | 
                                                        |
| 94 | + $new_item_nodes,  | 
                                                        |
| 95 | + $model_objects_to_identify - $num_identified  | 
                                                        |
| 96 | + );  | 
                                                        |
| 97 | + }  | 
                                                        |
| 98 | + }  | 
                                                        |
| 99 | +  | 
                                                        |
| 100 | +		if (count($this->model_obj_nodes) >= $this->count && $this->allChildrenComplete()) { | 
                                                        |
| 101 | + $this->complete = true;  | 
                                                        |
| 102 | + }  | 
                                                        |
| 103 | + return $num_identified;  | 
                                                        |
| 104 | + }  | 
                                                        |
| 105 | +  | 
                                                        |
| 106 | + /**  | 
                                                        |
| 107 | + * Checks if all the identified child nodes are complete or not.  | 
                                                        |
| 108 | + * @since $VID:$  | 
                                                        |
| 109 | + * @return bool  | 
                                                        |
| 110 | + */  | 
                                                        |
| 111 | + protected function allChildrenComplete()  | 
                                                        |
| 112 | +	{ | 
                                                        |
| 113 | +		foreach ($this->model_obj_nodes as $model_obj_node) { | 
                                                        |
| 114 | +			if (! $model_obj_node->isComplete()) { | 
                                                        |
| 115 | + return false;  | 
                                                        |
| 116 | + }  | 
                                                        |
| 117 | + }  | 
                                                        |
| 118 | + return true;  | 
                                                        |
| 119 | + }  | 
                                                        |
| 120 | +  | 
                                                        |
| 121 | + /**  | 
                                                        |
| 122 | + * Visits the provided nodes and keeps track of how much work was done, making sure to not go over budget.  | 
                                                        |
| 123 | + * @since $VID:$  | 
                                                        |
| 124 | + * @param ModelObjNode[] $model_obj_nodes  | 
                                                        |
| 125 | + * @param $work_budget  | 
                                                        |
| 126 | + * @return int  | 
                                                        |
| 127 | + */  | 
                                                        |
| 128 | + protected function visitAlreadyDiscoveredNodes($model_obj_nodes, $work_budget)  | 
                                                        |
| 129 | +	{ | 
                                                        |
| 130 | + $work_done = 0;  | 
                                                        |
| 131 | +		if (! $model_obj_nodes) { | 
                                                        |
| 132 | + return 0;  | 
                                                        |
| 133 | + }  | 
                                                        |
| 134 | +		foreach ($model_obj_nodes as $model_obj_node) { | 
                                                        |
| 135 | +			if ($work_done >= $work_budget) { | 
                                                        |
| 136 | + break;  | 
                                                        |
| 137 | + }  | 
                                                        |
| 138 | + $work_done += $model_obj_node->visit($work_budget - $work_done);  | 
                                                        |
| 139 | + }  | 
                                                        |
| 140 | + return $work_done;  | 
                                                        |
| 141 | + }  | 
                                                        |
| 142 | +  | 
                                                        |
| 143 | + /**  | 
                                                        |
| 144 | + * Whether this item has already been initialized  | 
                                                        |
| 145 | + */  | 
                                                        |
| 146 | + protected function isDiscovered()  | 
                                                        |
| 147 | +	{ | 
                                                        |
| 148 | + return $this->count !== null;  | 
                                                        |
| 149 | + }  | 
                                                        |
| 150 | +  | 
                                                        |
| 151 | + /**  | 
                                                        |
| 152 | + * @since $VID:$  | 
                                                        |
| 153 | + * @return boolean  | 
                                                        |
| 154 | + */  | 
                                                        |
| 155 | + public function isComplete()  | 
                                                        |
| 156 | +	{ | 
                                                        |
| 157 | +		if ($this->complete === null) { | 
                                                        |
| 158 | +			if (count($this->model_obj_nodes) === $this->count) { | 
                                                        |
| 159 | + $this->complete = true;  | 
                                                        |
| 160 | +			} else { | 
                                                        |
| 161 | + $this->complete = false;  | 
                                                        |
| 162 | + }  | 
                                                        |
| 163 | + }  | 
                                                        |
| 164 | + return $this->complete;  | 
                                                        |
| 165 | + }  | 
                                                        |
| 166 | +  | 
                                                        |
| 167 | + /**  | 
                                                        |
| 168 | + * Discovers how many related model objects exist.  | 
                                                        |
| 169 | + * @since $VID:$  | 
                                                        |
| 170 | + * @return mixed|void  | 
                                                        |
| 171 | + * @throws EE_Error  | 
                                                        |
| 172 | + * @throws InvalidArgumentException  | 
                                                        |
| 173 | + * @throws InvalidDataTypeException  | 
                                                        |
| 174 | + * @throws InvalidInterfaceException  | 
                                                        |
| 175 | + * @throws ReflectionException  | 
                                                        |
| 176 | + */  | 
                                                        |
| 177 | + protected function discover()  | 
                                                        |
| 178 | +	{ | 
                                                        |
| 179 | + $this->count = $this->related_model->count([$this->whereQueryParams()]);  | 
                                                        |
| 180 | + }  | 
                                                        |
| 181 | +  | 
                                                        |
| 182 | + /**  | 
                                                        |
| 183 | + * @since $VID:$  | 
                                                        |
| 184 | + * @return array  | 
                                                        |
| 185 | + * @throws EE_Error  | 
                                                        |
| 186 | + * @throws InvalidDataTypeException  | 
                                                        |
| 187 | + * @throws InvalidInterfaceException  | 
                                                        |
| 188 | + * @throws InvalidArgumentException  | 
                                                        |
| 189 | + * @throws ReflectionException  | 
                                                        |
| 190 | + */  | 
                                                        |
| 191 | + protected function whereQueryParams()  | 
                                                        |
| 192 | +	{ | 
                                                        |
| 193 | + $where_params = [  | 
                                                        |
| 194 | + $this->related_model->get_foreign_key_to(  | 
                                                        |
| 195 | + $this->main_model_obj->get_model()->get_this_model_name()  | 
                                                        |
| 196 | + )->get_name() => $this->main_model_obj->ID()  | 
                                                        |
| 197 | + ];  | 
                                                        |
| 198 | +		try { | 
                                                        |
| 199 | + $relation_settings = $this->main_model_obj->get_model()->related_settings_for($this->related_model->get_this_model_name());  | 
                                                        |
| 200 | +		} catch (EE_Error $e) { | 
                                                        |
| 201 | + // This will happen for has-and-belongs-to-many relations, when this node's related model is that join table  | 
                                                        |
| 202 | + // which hasn't been explicitly declared in the main model object's model's relations.  | 
                                                        |
| 203 | + $relation_settings = null;  | 
                                                        |
| 204 | + }  | 
                                                        |
| 205 | +		if ($relation_settings instanceof EE_Has_Many_Any_Relation) { | 
                                                        |
| 206 | + $where_params[ $this->related_model->get_field_containing_related_model_name()->get_name() ] = $this->main_model_obj->get_model()->get_this_model_name();  | 
                                                        |
| 207 | + }  | 
                                                        |
| 208 | + return $where_params;  | 
                                                        |
| 209 | + }  | 
                                                        |
| 210 | + /**  | 
                                                        |
| 211 | + * @since $VID:$  | 
                                                        |
| 212 | + * @return array  | 
                                                        |
| 213 | + */  | 
                                                        |
| 214 | + public function toArray()  | 
                                                        |
| 215 | +	{ | 
                                                        |
| 216 | + $tree = [  | 
                                                        |
| 217 | + 'count' => $this->count,  | 
                                                        |
| 218 | + 'complete' => $this->isComplete(),  | 
                                                        |
| 219 | + 'objs' => []  | 
                                                        |
| 220 | + ];  | 
                                                        |
| 221 | +		foreach ($this->model_obj_nodes as $id => $model_obj_node) { | 
                                                        |
| 222 | + $tree['objs'][ $id ] = $model_obj_node->toArray();  | 
                                                        |
| 223 | + }  | 
                                                        |
| 224 | + return $tree;  | 
                                                        |
| 225 | + }  | 
                                                        |
| 226 | +  | 
                                                        |
| 227 | + /**  | 
                                                        |
| 228 | + * Gets the IDs of all the model objects to delete; indexed first by model object name.  | 
                                                        |
| 229 | + * @since $VID:$  | 
                                                        |
| 230 | + * @return array  | 
                                                        |
| 231 | + */  | 
                                                        |
| 232 | + public function getIds()  | 
                                                        |
| 233 | +	{ | 
                                                        |
| 234 | +		if (empty($this->model_obj_nodes)) { | 
                                                        |
| 235 | + return [];  | 
                                                        |
| 236 | + }  | 
                                                        |
| 237 | + $ids = [  | 
                                                        |
| 238 | + $this->related_model->get_this_model_name() => array_combine(  | 
                                                        |
| 239 | + array_keys($this->model_obj_nodes),  | 
                                                        |
| 240 | + array_keys($this->model_obj_nodes)  | 
                                                        |
| 241 | + )  | 
                                                        |
| 242 | + ];  | 
                                                        |
| 243 | +		foreach ($this->model_obj_nodes as $model_obj_node) { | 
                                                        |
| 244 | + $ids = array_replace_recursive($ids, $model_obj_node->getIds());  | 
                                                        |
| 245 | + }  | 
                                                        |
| 246 | + return $ids;  | 
                                                        |
| 247 | + }  | 
                                                        |
| 248 | 248 | }  | 
                                                        
| 249 | 249 | // End of file RelationNode.php  | 
                                                        
| 250 | 250 | // Location: EventEspresso\core\services\orm\tree_traversal/RelationNode.php  | 
                                                        
@@ -84,8 +84,8 @@ discard block  | 
                                                    ||
| 84 | 84 | // Add entity nodes for each of the model objects we fetched.  | 
                                                        
| 85 | 85 |              foreach ($related_model_objs as $related_model_obj) { | 
                                                        
| 86 | 86 | $entity_node = new ModelObjNode($related_model_obj);  | 
                                                        
| 87 | - $this->model_obj_nodes[ $related_model_obj->ID() ] = $entity_node;  | 
                                                        |
| 88 | - $new_item_nodes[ $related_model_obj->ID() ] = $entity_node;  | 
                                                        |
| 87 | + $this->model_obj_nodes[$related_model_obj->ID()] = $entity_node;  | 
                                                        |
| 88 | + $new_item_nodes[$related_model_obj->ID()] = $entity_node;  | 
                                                        |
| 89 | 89 | }  | 
                                                        
| 90 | 90 | $num_identified += count($new_item_nodes);  | 
                                                        
| 91 | 91 |              if ($num_identified < $model_objects_to_identify) { | 
                                                        
@@ -111,7 +111,7 @@ discard block  | 
                                                    ||
| 111 | 111 | protected function allChildrenComplete()  | 
                                                        
| 112 | 112 |      { | 
                                                        
| 113 | 113 |          foreach ($this->model_obj_nodes as $model_obj_node) { | 
                                                        
| 114 | -            if (! $model_obj_node->isComplete()) { | 
                                                        |
| 114 | +            if ( ! $model_obj_node->isComplete()) { | 
                                                        |
| 115 | 115 | return false;  | 
                                                        
| 116 | 116 | }  | 
                                                        
| 117 | 117 | }  | 
                                                        
@@ -128,7 +128,7 @@ discard block  | 
                                                    ||
| 128 | 128 | protected function visitAlreadyDiscoveredNodes($model_obj_nodes, $work_budget)  | 
                                                        
| 129 | 129 |      { | 
                                                        
| 130 | 130 | $work_done = 0;  | 
                                                        
| 131 | -        if (! $model_obj_nodes) { | 
                                                        |
| 131 | +        if ( ! $model_obj_nodes) { | 
                                                        |
| 132 | 132 | return 0;  | 
                                                        
| 133 | 133 | }  | 
                                                        
| 134 | 134 |          foreach ($model_obj_nodes as $model_obj_node) { | 
                                                        
@@ -190,7 +190,7 @@ discard block  | 
                                                    ||
| 190 | 190 | */  | 
                                                        
| 191 | 191 | protected function whereQueryParams()  | 
                                                        
| 192 | 192 |      { | 
                                                        
| 193 | - $where_params = [  | 
                                                        |
| 193 | + $where_params = [  | 
                                                        |
| 194 | 194 | $this->related_model->get_foreign_key_to(  | 
                                                        
| 195 | 195 | $this->main_model_obj->get_model()->get_this_model_name()  | 
                                                        
| 196 | 196 | )->get_name() => $this->main_model_obj->ID()  | 
                                                        
@@ -203,7 +203,7 @@ discard block  | 
                                                    ||
| 203 | 203 | $relation_settings = null;  | 
                                                        
| 204 | 204 | }  | 
                                                        
| 205 | 205 |          if ($relation_settings instanceof EE_Has_Many_Any_Relation) { | 
                                                        
| 206 | - $where_params[ $this->related_model->get_field_containing_related_model_name()->get_name() ] = $this->main_model_obj->get_model()->get_this_model_name();  | 
                                                        |
| 206 | + $where_params[$this->related_model->get_field_containing_related_model_name()->get_name()] = $this->main_model_obj->get_model()->get_this_model_name();  | 
                                                        |
| 207 | 207 | }  | 
                                                        
| 208 | 208 | return $where_params;  | 
                                                        
| 209 | 209 | }  | 
                                                        
@@ -219,7 +219,7 @@ discard block  | 
                                                    ||
| 219 | 219 | 'objs' => []  | 
                                                        
| 220 | 220 | ];  | 
                                                        
| 221 | 221 |          foreach ($this->model_obj_nodes as $id => $model_obj_node) { | 
                                                        
| 222 | - $tree['objs'][ $id ] = $model_obj_node->toArray();  | 
                                                        |
| 222 | + $tree['objs'][$id] = $model_obj_node->toArray();  | 
                                                        |
| 223 | 223 | }  | 
                                                        
| 224 | 224 | return $tree;  | 
                                                        
| 225 | 225 | }  | 
                                                        
@@ -31,73 +31,73 @@  | 
                                                    ||
| 31 | 31 | */  | 
                                                        
| 32 | 32 | abstract class BaseNode  | 
                                                        
| 33 | 33 |  { | 
                                                        
| 34 | - /**  | 
                                                        |
| 35 | - * @var boolean  | 
                                                        |
| 36 | - */  | 
                                                        |
| 37 | - protected $complete;  | 
                                                        |
| 38 | - /**  | 
                                                        |
| 39 | - * Whether this item has already been initialized  | 
                                                        |
| 40 | - */  | 
                                                        |
| 41 | - abstract protected function isDiscovered();  | 
                                                        |
| 34 | + /**  | 
                                                        |
| 35 | + * @var boolean  | 
                                                        |
| 36 | + */  | 
                                                        |
| 37 | + protected $complete;  | 
                                                        |
| 38 | + /**  | 
                                                        |
| 39 | + * Whether this item has already been initialized  | 
                                                        |
| 40 | + */  | 
                                                        |
| 41 | + abstract protected function isDiscovered();  | 
                                                        |
| 42 | 42 | |
| 43 | - /**  | 
                                                        |
| 44 | - * Determines if the work is done yet or not. Requires you to have first discovered what work exists by calling  | 
                                                        |
| 45 | - * discover().  | 
                                                        |
| 46 | - * @since $VID:$  | 
                                                        |
| 47 | - * @return boolean  | 
                                                        |
| 48 | - */  | 
                                                        |
| 49 | - abstract public function isComplete();  | 
                                                        |
| 43 | + /**  | 
                                                        |
| 44 | + * Determines if the work is done yet or not. Requires you to have first discovered what work exists by calling  | 
                                                        |
| 45 | + * discover().  | 
                                                        |
| 46 | + * @since $VID:$  | 
                                                        |
| 47 | + * @return boolean  | 
                                                        |
| 48 | + */  | 
                                                        |
| 49 | + abstract public function isComplete();  | 
                                                        |
| 50 | 50 | |
| 51 | - /**  | 
                                                        |
| 52 | - * Discovers what work needs to be done to complete traversing this node and its children.  | 
                                                        |
| 53 | - * Note that this is separate from the constructor, so we can create child nodes without  | 
                                                        |
| 54 | - * discovering them immediately.  | 
                                                        |
| 55 | - * @since $VID:$  | 
                                                        |
| 56 | - * @return mixed  | 
                                                        |
| 57 | - */  | 
                                                        |
| 58 | - abstract protected function discover();  | 
                                                        |
| 51 | + /**  | 
                                                        |
| 52 | + * Discovers what work needs to be done to complete traversing this node and its children.  | 
                                                        |
| 53 | + * Note that this is separate from the constructor, so we can create child nodes without  | 
                                                        |
| 54 | + * discovering them immediately.  | 
                                                        |
| 55 | + * @since $VID:$  | 
                                                        |
| 56 | + * @return mixed  | 
                                                        |
| 57 | + */  | 
                                                        |
| 58 | + abstract protected function discover();  | 
                                                        |
| 59 | 59 | |
| 60 | - /**  | 
                                                        |
| 61 | - * Identifies model objects, up to the limit $model_objects_to_identify.  | 
                                                        |
| 62 | - * @since $VID:$  | 
                                                        |
| 63 | - * @param int $model_objects_to_identify  | 
                                                        |
| 64 | - * @return int units of work done  | 
                                                        |
| 65 | - */  | 
                                                        |
| 66 | - abstract protected function work($model_objects_to_identify);  | 
                                                        |
| 60 | + /**  | 
                                                        |
| 61 | + * Identifies model objects, up to the limit $model_objects_to_identify.  | 
                                                        |
| 62 | + * @since $VID:$  | 
                                                        |
| 63 | + * @param int $model_objects_to_identify  | 
                                                        |
| 64 | + * @return int units of work done  | 
                                                        |
| 65 | + */  | 
                                                        |
| 66 | + abstract protected function work($model_objects_to_identify);  | 
                                                        |
| 67 | 67 | |
| 68 | - /**  | 
                                                        |
| 69 | - * Shows the entity/relation node as an array.  | 
                                                        |
| 70 | - * @since $VID:$  | 
                                                        |
| 71 | - * @return array  | 
                                                        |
| 72 | - */  | 
                                                        |
| 73 | - abstract public function toArray();  | 
                                                        |
| 68 | + /**  | 
                                                        |
| 69 | + * Shows the entity/relation node as an array.  | 
                                                        |
| 70 | + * @since $VID:$  | 
                                                        |
| 71 | + * @return array  | 
                                                        |
| 72 | + */  | 
                                                        |
| 73 | + abstract public function toArray();  | 
                                                        |
| 74 | 74 | |
| 75 | - /**  | 
                                                        |
| 76 | - * Discovers how much work there is to do, double-checks the work isn't already finished, and then does the work.  | 
                                                        |
| 77 | - * Note: do not call when site is in maintenance mode level 2.  | 
                                                        |
| 78 | - *  | 
                                                        |
| 79 | - * @since $VID:$  | 
                                                        |
| 80 | - * @param $model_objects_to_identify  | 
                                                        |
| 81 | - * @return int number of model objects we want to identify during this call. On subsequent calls we'll continue  | 
                                                        |
| 82 | - * where we left off.  | 
                                                        |
| 83 | - */  | 
                                                        |
| 84 | - public function visit($model_objects_to_identify)  | 
                                                        |
| 85 | -    { | 
                                                        |
| 86 | -        if (! $this->isDiscovered()) { | 
                                                        |
| 87 | - $this->discover();  | 
                                                        |
| 88 | - }  | 
                                                        |
| 89 | -        if ($this->isComplete()) { | 
                                                        |
| 90 | - return 0;  | 
                                                        |
| 91 | - }  | 
                                                        |
| 92 | - return $this->work($model_objects_to_identify);  | 
                                                        |
| 93 | - }  | 
                                                        |
| 75 | + /**  | 
                                                        |
| 76 | + * Discovers how much work there is to do, double-checks the work isn't already finished, and then does the work.  | 
                                                        |
| 77 | + * Note: do not call when site is in maintenance mode level 2.  | 
                                                        |
| 78 | + *  | 
                                                        |
| 79 | + * @since $VID:$  | 
                                                        |
| 80 | + * @param $model_objects_to_identify  | 
                                                        |
| 81 | + * @return int number of model objects we want to identify during this call. On subsequent calls we'll continue  | 
                                                        |
| 82 | + * where we left off.  | 
                                                        |
| 83 | + */  | 
                                                        |
| 84 | + public function visit($model_objects_to_identify)  | 
                                                        |
| 85 | +	{ | 
                                                        |
| 86 | +		if (! $this->isDiscovered()) { | 
                                                        |
| 87 | + $this->discover();  | 
                                                        |
| 88 | + }  | 
                                                        |
| 89 | +		if ($this->isComplete()) { | 
                                                        |
| 90 | + return 0;  | 
                                                        |
| 91 | + }  | 
                                                        |
| 92 | + return $this->work($model_objects_to_identify);  | 
                                                        |
| 93 | + }  | 
                                                        |
| 94 | 94 | |
| 95 | - /**  | 
                                                        |
| 96 | - * Gets the IDs of completely identified model objects that can be deleted.  | 
                                                        |
| 97 | - * @since $VID:$  | 
                                                        |
| 98 | - * @return mixed  | 
                                                        |
| 99 | - */  | 
                                                        |
| 100 | - abstract public function getIds();  | 
                                                        |
| 95 | + /**  | 
                                                        |
| 96 | + * Gets the IDs of completely identified model objects that can be deleted.  | 
                                                        |
| 97 | + * @since $VID:$  | 
                                                        |
| 98 | + * @return mixed  | 
                                                        |
| 99 | + */  | 
                                                        |
| 100 | + abstract public function getIds();  | 
                                                        |
| 101 | 101 | }  | 
                                                        
| 102 | 102 | // End of file BaseNode.php  | 
                                                        
| 103 | 103 | // Location: EventEspresso\core\services\orm\tree_traversal/BaseNode.php  | 
                                                        
@@ -21,134 +21,134 @@  | 
                                                    ||
| 21 | 21 | */  | 
                                                        
| 22 | 22 | class ModelObjNode extends BaseNode  | 
                                                        
| 23 | 23 |  { | 
                                                        
| 24 | - /**  | 
                                                        |
| 25 | - * @var EE_Base_Class  | 
                                                        |
| 26 | - */  | 
                                                        |
| 27 | - protected $model_obj;  | 
                                                        |
| 24 | + /**  | 
                                                        |
| 25 | + * @var EE_Base_Class  | 
                                                        |
| 26 | + */  | 
                                                        |
| 27 | + protected $model_obj;  | 
                                                        |
| 28 | 28 | |
| 29 | - /**  | 
                                                        |
| 30 | - * @var RelationNode[]  | 
                                                        |
| 31 | - */  | 
                                                        |
| 32 | - protected $relation_nodes;  | 
                                                        |
| 29 | + /**  | 
                                                        |
| 30 | + * @var RelationNode[]  | 
                                                        |
| 31 | + */  | 
                                                        |
| 32 | + protected $relation_nodes;  | 
                                                        |
| 33 | 33 | |
| 34 | - public function __construct($instance)  | 
                                                        |
| 35 | -    { | 
                                                        |
| 36 | - $this->model_obj = $instance;  | 
                                                        |
| 37 | - }  | 
                                                        |
| 34 | + public function __construct($instance)  | 
                                                        |
| 35 | +	{ | 
                                                        |
| 36 | + $this->model_obj = $instance;  | 
                                                        |
| 37 | + }  | 
                                                        |
| 38 | 38 | |
| 39 | - /**  | 
                                                        |
| 40 | - * Creates a relation node for each relation of this model's relations.  | 
                                                        |
| 41 | - * Does NOT call `discover` on them yet though.  | 
                                                        |
| 42 | - * @since $VID:$  | 
                                                        |
| 43 | - * @throws \EE_Error  | 
                                                        |
| 44 | - * @throws InvalidDataTypeException  | 
                                                        |
| 45 | - * @throws InvalidInterfaceException  | 
                                                        |
| 46 | - * @throws InvalidArgumentException  | 
                                                        |
| 47 | - * @throws ReflectionException  | 
                                                        |
| 48 | - */  | 
                                                        |
| 49 | - protected function discover()  | 
                                                        |
| 50 | -    { | 
                                                        |
| 51 | - $this->relation_nodes = [];  | 
                                                        |
| 52 | -        foreach ($this->model_obj->get_model()->relation_settings() as $relationName => $relation) { | 
                                                        |
| 53 | -            if ($relation instanceof EE_Has_Many_Relation) { | 
                                                        |
| 54 | - $this->relation_nodes[ $relationName ] = new RelationNode($this->model_obj, $relation->get_other_model());  | 
                                                        |
| 55 | -            } elseif ($relation instanceof EE_HABTM_Relation) { | 
                                                        |
| 56 | - $this->relation_nodes[ $relation->get_join_model()->get_this_model_name() ] = new RelationNode($this->model_obj, $relation->get_join_model());  | 
                                                        |
| 57 | - }  | 
                                                        |
| 58 | - }  | 
                                                        |
| 59 | - ksort($this->relation_nodes);  | 
                                                        |
| 60 | - }  | 
                                                        |
| 39 | + /**  | 
                                                        |
| 40 | + * Creates a relation node for each relation of this model's relations.  | 
                                                        |
| 41 | + * Does NOT call `discover` on them yet though.  | 
                                                        |
| 42 | + * @since $VID:$  | 
                                                        |
| 43 | + * @throws \EE_Error  | 
                                                        |
| 44 | + * @throws InvalidDataTypeException  | 
                                                        |
| 45 | + * @throws InvalidInterfaceException  | 
                                                        |
| 46 | + * @throws InvalidArgumentException  | 
                                                        |
| 47 | + * @throws ReflectionException  | 
                                                        |
| 48 | + */  | 
                                                        |
| 49 | + protected function discover()  | 
                                                        |
| 50 | +	{ | 
                                                        |
| 51 | + $this->relation_nodes = [];  | 
                                                        |
| 52 | +		foreach ($this->model_obj->get_model()->relation_settings() as $relationName => $relation) { | 
                                                        |
| 53 | +			if ($relation instanceof EE_Has_Many_Relation) { | 
                                                        |
| 54 | + $this->relation_nodes[ $relationName ] = new RelationNode($this->model_obj, $relation->get_other_model());  | 
                                                        |
| 55 | +			} elseif ($relation instanceof EE_HABTM_Relation) { | 
                                                        |
| 56 | + $this->relation_nodes[ $relation->get_join_model()->get_this_model_name() ] = new RelationNode($this->model_obj, $relation->get_join_model());  | 
                                                        |
| 57 | + }  | 
                                                        |
| 58 | + }  | 
                                                        |
| 59 | + ksort($this->relation_nodes);  | 
                                                        |
| 60 | + }  | 
                                                        |
| 61 | 61 | |
| 62 | 62 | |
| 63 | - /**  | 
                                                        |
| 64 | - * Whether this item has already been initialized  | 
                                                        |
| 65 | - */  | 
                                                        |
| 66 | - protected function isDiscovered()  | 
                                                        |
| 67 | -    { | 
                                                        |
| 68 | - return $this->relation_nodes !== null && is_array($this->relation_nodes);  | 
                                                        |
| 69 | - }  | 
                                                        |
| 63 | + /**  | 
                                                        |
| 64 | + * Whether this item has already been initialized  | 
                                                        |
| 65 | + */  | 
                                                        |
| 66 | + protected function isDiscovered()  | 
                                                        |
| 67 | +	{ | 
                                                        |
| 68 | + return $this->relation_nodes !== null && is_array($this->relation_nodes);  | 
                                                        |
| 69 | + }  | 
                                                        |
| 70 | 70 | |
| 71 | - /**  | 
                                                        |
| 72 | - * @since $VID:$  | 
                                                        |
| 73 | - * @return boolean  | 
                                                        |
| 74 | - */  | 
                                                        |
| 75 | - public function isComplete()  | 
                                                        |
| 76 | -    { | 
                                                        |
| 77 | -        if ($this->complete === null) { | 
                                                        |
| 78 | - $this->complete = false;  | 
                                                        |
| 79 | - }  | 
                                                        |
| 80 | - return $this->complete;  | 
                                                        |
| 81 | - }  | 
                                                        |
| 71 | + /**  | 
                                                        |
| 72 | + * @since $VID:$  | 
                                                        |
| 73 | + * @return boolean  | 
                                                        |
| 74 | + */  | 
                                                        |
| 75 | + public function isComplete()  | 
                                                        |
| 76 | +	{ | 
                                                        |
| 77 | +		if ($this->complete === null) { | 
                                                        |
| 78 | + $this->complete = false;  | 
                                                        |
| 79 | + }  | 
                                                        |
| 80 | + return $this->complete;  | 
                                                        |
| 81 | + }  | 
                                                        |
| 82 | 82 | |
| 83 | - /**  | 
                                                        |
| 84 | - * Triggers working on each child relation node that has work to do.  | 
                                                        |
| 85 | - * @since $VID:$  | 
                                                        |
| 86 | - * @param $model_objects_to_identify  | 
                                                        |
| 87 | - * @return int units of work done  | 
                                                        |
| 88 | - */  | 
                                                        |
| 89 | - protected function work($model_objects_to_identify)  | 
                                                        |
| 90 | -    { | 
                                                        |
| 91 | - $num_identified = 0;  | 
                                                        |
| 92 | - // Begin assuming we'll finish all the work on this node and its children...  | 
                                                        |
| 93 | - $this->complete = true;  | 
                                                        |
| 94 | -        foreach ($this->relation_nodes as $relation_node) { | 
                                                        |
| 95 | - $num_identified += $relation_node->visit($model_objects_to_identify);  | 
                                                        |
| 96 | -            if ($num_identified >= $model_objects_to_identify) { | 
                                                        |
| 97 | - // ...but admit we're wrong if the work exceeded the budget.  | 
                                                        |
| 98 | - $this->complete = false;  | 
                                                        |
| 99 | - break;  | 
                                                        |
| 100 | - }  | 
                                                        |
| 101 | - }  | 
                                                        |
| 102 | - return $num_identified;  | 
                                                        |
| 103 | - }  | 
                                                        |
| 83 | + /**  | 
                                                        |
| 84 | + * Triggers working on each child relation node that has work to do.  | 
                                                        |
| 85 | + * @since $VID:$  | 
                                                        |
| 86 | + * @param $model_objects_to_identify  | 
                                                        |
| 87 | + * @return int units of work done  | 
                                                        |
| 88 | + */  | 
                                                        |
| 89 | + protected function work($model_objects_to_identify)  | 
                                                        |
| 90 | +	{ | 
                                                        |
| 91 | + $num_identified = 0;  | 
                                                        |
| 92 | + // Begin assuming we'll finish all the work on this node and its children...  | 
                                                        |
| 93 | + $this->complete = true;  | 
                                                        |
| 94 | +		foreach ($this->relation_nodes as $relation_node) { | 
                                                        |
| 95 | + $num_identified += $relation_node->visit($model_objects_to_identify);  | 
                                                        |
| 96 | +			if ($num_identified >= $model_objects_to_identify) { | 
                                                        |
| 97 | + // ...but admit we're wrong if the work exceeded the budget.  | 
                                                        |
| 98 | + $this->complete = false;  | 
                                                        |
| 99 | + break;  | 
                                                        |
| 100 | + }  | 
                                                        |
| 101 | + }  | 
                                                        |
| 102 | + return $num_identified;  | 
                                                        |
| 103 | + }  | 
                                                        |
| 104 | 104 | |
| 105 | - /**  | 
                                                        |
| 106 | - * @since $VID:$  | 
                                                        |
| 107 | - * @return array  | 
                                                        |
| 108 | - * @throws \EE_Error  | 
                                                        |
| 109 | - * @throws InvalidDataTypeException  | 
                                                        |
| 110 | - * @throws InvalidInterfaceException  | 
                                                        |
| 111 | - * @throws InvalidArgumentException  | 
                                                        |
| 112 | - * @throws ReflectionException  | 
                                                        |
| 113 | - */  | 
                                                        |
| 114 | - public function toArray()  | 
                                                        |
| 115 | -    { | 
                                                        |
| 116 | - $tree = [  | 
                                                        |
| 117 | - 'id' => $this->model_obj->ID(),  | 
                                                        |
| 118 | - 'complete' => $this->isComplete(),  | 
                                                        |
| 119 | - 'rels' => []  | 
                                                        |
| 120 | - ];  | 
                                                        |
| 121 | -        if ($this->relation_nodes === null) { | 
                                                        |
| 122 | - $tree['rels'] = null;  | 
                                                        |
| 123 | -        } else { | 
                                                        |
| 124 | -            foreach ($this->relation_nodes as $relation_name => $relation_node) { | 
                                                        |
| 125 | - $tree['rels'][ $relation_name ] = $relation_node->toArray();  | 
                                                        |
| 126 | - }  | 
                                                        |
| 127 | - }  | 
                                                        |
| 128 | - return $tree;  | 
                                                        |
| 129 | - }  | 
                                                        |
| 105 | + /**  | 
                                                        |
| 106 | + * @since $VID:$  | 
                                                        |
| 107 | + * @return array  | 
                                                        |
| 108 | + * @throws \EE_Error  | 
                                                        |
| 109 | + * @throws InvalidDataTypeException  | 
                                                        |
| 110 | + * @throws InvalidInterfaceException  | 
                                                        |
| 111 | + * @throws InvalidArgumentException  | 
                                                        |
| 112 | + * @throws ReflectionException  | 
                                                        |
| 113 | + */  | 
                                                        |
| 114 | + public function toArray()  | 
                                                        |
| 115 | +	{ | 
                                                        |
| 116 | + $tree = [  | 
                                                        |
| 117 | + 'id' => $this->model_obj->ID(),  | 
                                                        |
| 118 | + 'complete' => $this->isComplete(),  | 
                                                        |
| 119 | + 'rels' => []  | 
                                                        |
| 120 | + ];  | 
                                                        |
| 121 | +		if ($this->relation_nodes === null) { | 
                                                        |
| 122 | + $tree['rels'] = null;  | 
                                                        |
| 123 | +		} else { | 
                                                        |
| 124 | +			foreach ($this->relation_nodes as $relation_name => $relation_node) { | 
                                                        |
| 125 | + $tree['rels'][ $relation_name ] = $relation_node->toArray();  | 
                                                        |
| 126 | + }  | 
                                                        |
| 127 | + }  | 
                                                        |
| 128 | + return $tree;  | 
                                                        |
| 129 | + }  | 
                                                        |
| 130 | 130 | |
| 131 | - /**  | 
                                                        |
| 132 | - * @since $VID:$  | 
                                                        |
| 133 | - * @return array|mixed  | 
                                                        |
| 134 | - * @throws InvalidArgumentException  | 
                                                        |
| 135 | - * @throws InvalidDataTypeException  | 
                                                        |
| 136 | - * @throws InvalidInterfaceException  | 
                                                        |
| 137 | - * @throws ReflectionException  | 
                                                        |
| 138 | - * @throws \EE_Error  | 
                                                        |
| 139 | - */  | 
                                                        |
| 140 | - public function getIds()  | 
                                                        |
| 141 | -    { | 
                                                        |
| 142 | - $ids = [  | 
                                                        |
| 143 | - $this->model_obj->get_model()->get_this_model_name() => [  | 
                                                        |
| 144 | - $this->model_obj->ID() => $this->model_obj->ID()  | 
                                                        |
| 145 | - ]  | 
                                                        |
| 146 | - ];  | 
                                                        |
| 147 | -        foreach ($this->relation_nodes as $relation_node) { | 
                                                        |
| 148 | - $ids = array_replace_recursive($ids, $relation_node->getIds());  | 
                                                        |
| 149 | - }  | 
                                                        |
| 150 | - return $ids;  | 
                                                        |
| 151 | - }  | 
                                                        |
| 131 | + /**  | 
                                                        |
| 132 | + * @since $VID:$  | 
                                                        |
| 133 | + * @return array|mixed  | 
                                                        |
| 134 | + * @throws InvalidArgumentException  | 
                                                        |
| 135 | + * @throws InvalidDataTypeException  | 
                                                        |
| 136 | + * @throws InvalidInterfaceException  | 
                                                        |
| 137 | + * @throws ReflectionException  | 
                                                        |
| 138 | + * @throws \EE_Error  | 
                                                        |
| 139 | + */  | 
                                                        |
| 140 | + public function getIds()  | 
                                                        |
| 141 | +	{ | 
                                                        |
| 142 | + $ids = [  | 
                                                        |
| 143 | + $this->model_obj->get_model()->get_this_model_name() => [  | 
                                                        |
| 144 | + $this->model_obj->ID() => $this->model_obj->ID()  | 
                                                        |
| 145 | + ]  | 
                                                        |
| 146 | + ];  | 
                                                        |
| 147 | +		foreach ($this->relation_nodes as $relation_node) { | 
                                                        |
| 148 | + $ids = array_replace_recursive($ids, $relation_node->getIds());  | 
                                                        |
| 149 | + }  | 
                                                        |
| 150 | + return $ids;  | 
                                                        |
| 151 | + }  | 
                                                        |
| 152 | 152 | }  | 
                                                        
| 153 | 153 | // End of file Visitor.php  | 
                                                        
| 154 | 154 | // Location: EventEspresso\core\services\orm\tree_traversal/Visitor.php  | 
                                                        
@@ -2090,7 +2090,6 @@ discard block  | 
                                                    ||
| 2090 | 2090 | * _delete_event  | 
                                                        
| 2091 | 2091 | *  | 
                                                        
| 2092 | 2092 | * @access protected  | 
                                                        
| 2093 | - * @param bool $redirect_after  | 
                                                        |
| 2094 | 2093 | */  | 
                                                        
| 2095 | 2094 | protected function _delete_event()  | 
                                                        
| 2096 | 2095 |      { | 
                                                        
@@ -2176,7 +2175,7 @@ discard block  | 
                                                    ||
| 2176 | 2175 | * message template groups.  | 
                                                        
| 2177 | 2176 | * @since $VID:$  | 
                                                        
| 2178 | 2177 | * @param $event_ids  | 
                                                        
| 2179 | - * @return int  | 
                                                        |
| 2178 | + * @return boolean  | 
                                                        |
| 2180 | 2179 | * @throws EE_Error  | 
                                                        
| 2181 | 2180 | * @throws InvalidArgumentException  | 
                                                        
| 2182 | 2181 | * @throws ReflectionException  | 
                                                        
@@ -16,509 +16,509 @@ discard block  | 
                                                    ||
| 16 | 16 | class Events_Admin_Page extends EE_Admin_Page_CPT  | 
                                                        
| 17 | 17 |  { | 
                                                        
| 18 | 18 | |
| 19 | - /**  | 
                                                        |
| 20 | - * This will hold the event object for event_details screen.  | 
                                                        |
| 21 | - *  | 
                                                        |
| 22 | - * @access protected  | 
                                                        |
| 23 | - * @var EE_Event $_event  | 
                                                        |
| 24 | - */  | 
                                                        |
| 25 | - protected $_event;  | 
                                                        |
| 26 | -  | 
                                                        |
| 27 | -  | 
                                                        |
| 28 | - /**  | 
                                                        |
| 29 | - * This will hold the category object for category_details screen.  | 
                                                        |
| 30 | - *  | 
                                                        |
| 31 | - * @var stdClass $_category  | 
                                                        |
| 32 | - */  | 
                                                        |
| 33 | - protected $_category;  | 
                                                        |
| 34 | -  | 
                                                        |
| 35 | -  | 
                                                        |
| 36 | - /**  | 
                                                        |
| 37 | - * This will hold the event model instance  | 
                                                        |
| 38 | - *  | 
                                                        |
| 39 | - * @var EEM_Event $_event_model  | 
                                                        |
| 40 | - */  | 
                                                        |
| 41 | - protected $_event_model;  | 
                                                        |
| 42 | -  | 
                                                        |
| 43 | -  | 
                                                        |
| 44 | - /**  | 
                                                        |
| 45 | - * @var EE_Event  | 
                                                        |
| 46 | - */  | 
                                                        |
| 47 | - protected $_cpt_model_obj = false;  | 
                                                        |
| 48 | -  | 
                                                        |
| 49 | -  | 
                                                        |
| 50 | - /**  | 
                                                        |
| 51 | - * Initialize page props for this admin page group.  | 
                                                        |
| 52 | - */  | 
                                                        |
| 53 | - protected function _init_page_props()  | 
                                                        |
| 54 | -    { | 
                                                        |
| 55 | - $this->page_slug = EVENTS_PG_SLUG;  | 
                                                        |
| 56 | - $this->page_label = EVENTS_LABEL;  | 
                                                        |
| 57 | - $this->_admin_base_url = EVENTS_ADMIN_URL;  | 
                                                        |
| 58 | - $this->_admin_base_path = EVENTS_ADMIN;  | 
                                                        |
| 59 | - $this->_cpt_model_names = array(  | 
                                                        |
| 60 | - 'create_new' => 'EEM_Event',  | 
                                                        |
| 61 | - 'edit' => 'EEM_Event',  | 
                                                        |
| 62 | - );  | 
                                                        |
| 63 | - $this->_cpt_edit_routes = array(  | 
                                                        |
| 64 | - 'espresso_events' => 'edit',  | 
                                                        |
| 65 | - );  | 
                                                        |
| 66 | - add_action(  | 
                                                        |
| 67 | - 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',  | 
                                                        |
| 68 | - array($this, 'verify_event_edit'),  | 
                                                        |
| 69 | - 10,  | 
                                                        |
| 70 | - 2  | 
                                                        |
| 71 | - );  | 
                                                        |
| 72 | - }  | 
                                                        |
| 73 | -  | 
                                                        |
| 74 | -  | 
                                                        |
| 75 | - /**  | 
                                                        |
| 76 | - * Sets the ajax hooks used for this admin page group.  | 
                                                        |
| 77 | - */  | 
                                                        |
| 78 | - protected function _ajax_hooks()  | 
                                                        |
| 79 | -    { | 
                                                        |
| 80 | -        add_action('wp_ajax_ee_save_timezone_setting', array($this, 'save_timezonestring_setting')); | 
                                                        |
| 81 | - }  | 
                                                        |
| 82 | -  | 
                                                        |
| 83 | -  | 
                                                        |
| 84 | - /**  | 
                                                        |
| 85 | - * Sets the page properties for this admin page group.  | 
                                                        |
| 86 | - */  | 
                                                        |
| 87 | - protected function _define_page_props()  | 
                                                        |
| 88 | -    { | 
                                                        |
| 89 | - $this->_admin_page_title = EVENTS_LABEL;  | 
                                                        |
| 90 | - $this->_labels = array(  | 
                                                        |
| 91 | - 'buttons' => array(  | 
                                                        |
| 92 | -                'add'             => esc_html__('Add New Event', 'event_espresso'), | 
                                                        |
| 93 | -                'edit'            => esc_html__('Edit Event', 'event_espresso'), | 
                                                        |
| 94 | -                'delete'          => esc_html__('Delete Event', 'event_espresso'), | 
                                                        |
| 95 | -                'add_category'    => esc_html__('Add New Category', 'event_espresso'), | 
                                                        |
| 96 | -                'edit_category'   => esc_html__('Edit Category', 'event_espresso'), | 
                                                        |
| 97 | -                'delete_category' => esc_html__('Delete Category', 'event_espresso'), | 
                                                        |
| 98 | - ),  | 
                                                        |
| 99 | - 'editor_title' => array(  | 
                                                        |
| 100 | -                'espresso_events' => esc_html__('Enter event title here', 'event_espresso'), | 
                                                        |
| 101 | - ),  | 
                                                        |
| 102 | - 'publishbox' => array(  | 
                                                        |
| 103 | -                'create_new'        => esc_html__('Save New Event', 'event_espresso'), | 
                                                        |
| 104 | -                'edit'              => esc_html__('Update Event', 'event_espresso'), | 
                                                        |
| 105 | -                'add_category'      => esc_html__('Save New Category', 'event_espresso'), | 
                                                        |
| 106 | -                'edit_category'     => esc_html__('Update Category', 'event_espresso'), | 
                                                        |
| 107 | -                'template_settings' => esc_html__('Update Settings', 'event_espresso'), | 
                                                        |
| 108 | - ),  | 
                                                        |
| 109 | - );  | 
                                                        |
| 110 | - }  | 
                                                        |
| 111 | -  | 
                                                        |
| 112 | -  | 
                                                        |
| 113 | - /**  | 
                                                        |
| 114 | - * Sets the page routes property for this admin page group.  | 
                                                        |
| 115 | - */  | 
                                                        |
| 116 | - protected function _set_page_routes()  | 
                                                        |
| 117 | -    { | 
                                                        |
| 118 | - // load formatter helper  | 
                                                        |
| 119 | - // load field generator helper  | 
                                                        |
| 120 | - // is there a evt_id in the request?  | 
                                                        |
| 121 | - $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])  | 
                                                        |
| 122 | - ? $this->_req_data['EVT_ID']  | 
                                                        |
| 123 | - : 0;  | 
                                                        |
| 124 | - $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;  | 
                                                        |
| 125 | - $this->_page_routes = array(  | 
                                                        |
| 126 | - 'default' => array(  | 
                                                        |
| 127 | - 'func' => '_events_overview_list_table',  | 
                                                        |
| 128 | - 'capability' => 'ee_read_events',  | 
                                                        |
| 129 | - ),  | 
                                                        |
| 130 | - 'create_new' => array(  | 
                                                        |
| 131 | - 'func' => '_create_new_cpt_item',  | 
                                                        |
| 132 | - 'capability' => 'ee_edit_events',  | 
                                                        |
| 133 | - ),  | 
                                                        |
| 134 | - 'edit' => array(  | 
                                                        |
| 135 | - 'func' => '_edit_cpt_item',  | 
                                                        |
| 136 | - 'capability' => 'ee_edit_event',  | 
                                                        |
| 137 | - 'obj_id' => $evt_id,  | 
                                                        |
| 138 | - ),  | 
                                                        |
| 139 | - 'copy_event' => array(  | 
                                                        |
| 140 | - 'func' => '_copy_events',  | 
                                                        |
| 141 | - 'capability' => 'ee_edit_event',  | 
                                                        |
| 142 | - 'obj_id' => $evt_id,  | 
                                                        |
| 143 | - 'noheader' => true,  | 
                                                        |
| 144 | - ),  | 
                                                        |
| 145 | - 'trash_event' => array(  | 
                                                        |
| 146 | - 'func' => '_trash_or_restore_event',  | 
                                                        |
| 147 | -                'args'       => array('event_status' => 'trash'), | 
                                                        |
| 148 | - 'capability' => 'ee_delete_event',  | 
                                                        |
| 149 | - 'obj_id' => $evt_id,  | 
                                                        |
| 150 | - 'noheader' => true,  | 
                                                        |
| 151 | - ),  | 
                                                        |
| 152 | - 'trash_events' => array(  | 
                                                        |
| 153 | - 'func' => '_trash_or_restore_events',  | 
                                                        |
| 154 | -                'args'       => array('event_status' => 'trash'), | 
                                                        |
| 155 | - 'capability' => 'ee_delete_events',  | 
                                                        |
| 156 | - 'noheader' => true,  | 
                                                        |
| 157 | - ),  | 
                                                        |
| 158 | - 'restore_event' => array(  | 
                                                        |
| 159 | - 'func' => '_trash_or_restore_event',  | 
                                                        |
| 160 | -                'args'       => array('event_status' => 'draft'), | 
                                                        |
| 161 | - 'capability' => 'ee_delete_event',  | 
                                                        |
| 162 | - 'obj_id' => $evt_id,  | 
                                                        |
| 163 | - 'noheader' => true,  | 
                                                        |
| 164 | - ),  | 
                                                        |
| 165 | - 'restore_events' => array(  | 
                                                        |
| 166 | - 'func' => '_trash_or_restore_events',  | 
                                                        |
| 167 | -                'args'       => array('event_status' => 'draft'), | 
                                                        |
| 168 | - 'capability' => 'ee_delete_events',  | 
                                                        |
| 169 | - 'noheader' => true,  | 
                                                        |
| 170 | - ),  | 
                                                        |
| 171 | - 'delete_event' => array(  | 
                                                        |
| 172 | - 'func' => '_delete_event',  | 
                                                        |
| 173 | - 'capability' => 'ee_delete_event',  | 
                                                        |
| 174 | - 'obj_id' => $evt_id,  | 
                                                        |
| 175 | - 'noheader' => true,  | 
                                                        |
| 176 | - ),  | 
                                                        |
| 177 | - 'delete_events' => array(  | 
                                                        |
| 178 | - 'func' => '_delete_events',  | 
                                                        |
| 179 | - 'capability' => 'ee_delete_events',  | 
                                                        |
| 180 | - 'noheader' => true,  | 
                                                        |
| 181 | - ),  | 
                                                        |
| 182 | - 'view_report' => array(  | 
                                                        |
| 183 | - 'func' => '_view_report',  | 
                                                        |
| 184 | - 'capablity' => 'ee_edit_events',  | 
                                                        |
| 185 | - ),  | 
                                                        |
| 186 | - 'default_event_settings' => array(  | 
                                                        |
| 187 | - 'func' => '_default_event_settings',  | 
                                                        |
| 188 | - 'capability' => 'manage_options',  | 
                                                        |
| 189 | - ),  | 
                                                        |
| 190 | - 'update_default_event_settings' => array(  | 
                                                        |
| 191 | - 'func' => '_update_default_event_settings',  | 
                                                        |
| 192 | - 'capability' => 'manage_options',  | 
                                                        |
| 193 | - 'noheader' => true,  | 
                                                        |
| 194 | - ),  | 
                                                        |
| 195 | - 'template_settings' => array(  | 
                                                        |
| 196 | - 'func' => '_template_settings',  | 
                                                        |
| 197 | - 'capability' => 'manage_options',  | 
                                                        |
| 198 | - ),  | 
                                                        |
| 199 | - // event category tab related  | 
                                                        |
| 200 | - 'add_category' => array(  | 
                                                        |
| 201 | - 'func' => '_category_details',  | 
                                                        |
| 202 | - 'capability' => 'ee_edit_event_category',  | 
                                                        |
| 203 | -                'args'       => array('add'), | 
                                                        |
| 204 | - ),  | 
                                                        |
| 205 | - 'edit_category' => array(  | 
                                                        |
| 206 | - 'func' => '_category_details',  | 
                                                        |
| 207 | - 'capability' => 'ee_edit_event_category',  | 
                                                        |
| 208 | -                'args'       => array('edit'), | 
                                                        |
| 209 | - ),  | 
                                                        |
| 210 | - 'delete_categories' => array(  | 
                                                        |
| 211 | - 'func' => '_delete_categories',  | 
                                                        |
| 212 | - 'capability' => 'ee_delete_event_category',  | 
                                                        |
| 213 | - 'noheader' => true,  | 
                                                        |
| 214 | - ),  | 
                                                        |
| 215 | - 'delete_category' => array(  | 
                                                        |
| 216 | - 'func' => '_delete_categories',  | 
                                                        |
| 217 | - 'capability' => 'ee_delete_event_category',  | 
                                                        |
| 218 | - 'noheader' => true,  | 
                                                        |
| 219 | - ),  | 
                                                        |
| 220 | - 'insert_category' => array(  | 
                                                        |
| 221 | - 'func' => '_insert_or_update_category',  | 
                                                        |
| 222 | -                'args'       => array('new_category' => true), | 
                                                        |
| 223 | - 'capability' => 'ee_edit_event_category',  | 
                                                        |
| 224 | - 'noheader' => true,  | 
                                                        |
| 225 | - ),  | 
                                                        |
| 226 | - 'update_category' => array(  | 
                                                        |
| 227 | - 'func' => '_insert_or_update_category',  | 
                                                        |
| 228 | -                'args'       => array('new_category' => false), | 
                                                        |
| 229 | - 'capability' => 'ee_edit_event_category',  | 
                                                        |
| 230 | - 'noheader' => true,  | 
                                                        |
| 231 | - ),  | 
                                                        |
| 232 | - 'category_list' => array(  | 
                                                        |
| 233 | - 'func' => '_category_list_table',  | 
                                                        |
| 234 | - 'capability' => 'ee_manage_event_categories',  | 
                                                        |
| 235 | - ),  | 
                                                        |
| 236 | - 'preview_deletion' => [  | 
                                                        |
| 237 | - 'func' => 'previewDeletion',  | 
                                                        |
| 238 | - 'capability' => 'ee_delete_events'  | 
                                                        |
| 239 | - ],  | 
                                                        |
| 240 | - 'confirm_deletion' => [  | 
                                                        |
| 241 | - 'func' => 'confirmDeletion',  | 
                                                        |
| 242 | - 'capability' => 'ee_delete_events',  | 
                                                        |
| 243 | - 'noheader' => true  | 
                                                        |
| 244 | - ]  | 
                                                        |
| 245 | - );  | 
                                                        |
| 246 | - }  | 
                                                        |
| 247 | -  | 
                                                        |
| 248 | -  | 
                                                        |
| 249 | - /**  | 
                                                        |
| 250 | - * Set the _page_config property for this admin page group.  | 
                                                        |
| 251 | - */  | 
                                                        |
| 252 | - protected function _set_page_config()  | 
                                                        |
| 253 | -    { | 
                                                        |
| 254 | - $this->_page_config = array(  | 
                                                        |
| 255 | - 'default' => array(  | 
                                                        |
| 256 | - 'nav' => array(  | 
                                                        |
| 257 | -                    'label' => esc_html__('Overview', 'event_espresso'), | 
                                                        |
| 258 | - 'order' => 10,  | 
                                                        |
| 259 | - ),  | 
                                                        |
| 260 | - 'list_table' => 'Events_Admin_List_Table',  | 
                                                        |
| 261 | - 'help_tabs' => array(  | 
                                                        |
| 262 | - 'events_overview_help_tab' => array(  | 
                                                        |
| 263 | -                        'title'    => esc_html__('Events Overview', 'event_espresso'), | 
                                                        |
| 264 | - 'filename' => 'events_overview',  | 
                                                        |
| 265 | - ),  | 
                                                        |
| 266 | - 'events_overview_table_column_headings_help_tab' => array(  | 
                                                        |
| 267 | -                        'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'), | 
                                                        |
| 268 | - 'filename' => 'events_overview_table_column_headings',  | 
                                                        |
| 269 | - ),  | 
                                                        |
| 270 | - 'events_overview_filters_help_tab' => array(  | 
                                                        |
| 271 | -                        'title'    => esc_html__('Events Overview Filters', 'event_espresso'), | 
                                                        |
| 272 | - 'filename' => 'events_overview_filters',  | 
                                                        |
| 273 | - ),  | 
                                                        |
| 274 | - 'events_overview_view_help_tab' => array(  | 
                                                        |
| 275 | -                        'title'    => esc_html__('Events Overview Views', 'event_espresso'), | 
                                                        |
| 276 | - 'filename' => 'events_overview_views',  | 
                                                        |
| 277 | - ),  | 
                                                        |
| 278 | - 'events_overview_other_help_tab' => array(  | 
                                                        |
| 279 | -                        'title'    => esc_html__('Events Overview Other', 'event_espresso'), | 
                                                        |
| 280 | - 'filename' => 'events_overview_other',  | 
                                                        |
| 281 | - ),  | 
                                                        |
| 282 | - ),  | 
                                                        |
| 283 | - 'help_tour' => array(  | 
                                                        |
| 284 | - 'Event_Overview_Help_Tour',  | 
                                                        |
| 285 | - // 'New_Features_Test_Help_Tour' for testing multiple help tour  | 
                                                        |
| 286 | - ),  | 
                                                        |
| 287 | - 'qtips' => array(  | 
                                                        |
| 288 | - 'EE_Event_List_Table_Tips',  | 
                                                        |
| 289 | - ),  | 
                                                        |
| 290 | - 'require_nonce' => false,  | 
                                                        |
| 291 | - ),  | 
                                                        |
| 292 | - 'create_new' => array(  | 
                                                        |
| 293 | - 'nav' => array(  | 
                                                        |
| 294 | -                    'label'      => esc_html__('Add Event', 'event_espresso'), | 
                                                        |
| 295 | - 'order' => 5,  | 
                                                        |
| 296 | - 'persistent' => false,  | 
                                                        |
| 297 | - ),  | 
                                                        |
| 298 | -                'metaboxes'     => array('_register_event_editor_meta_boxes'), | 
                                                        |
| 299 | - 'help_tabs' => array(  | 
                                                        |
| 300 | - 'event_editor_help_tab' => array(  | 
                                                        |
| 301 | -                        'title'    => esc_html__('Event Editor', 'event_espresso'), | 
                                                        |
| 302 | - 'filename' => 'event_editor',  | 
                                                        |
| 303 | - ),  | 
                                                        |
| 304 | - 'event_editor_title_richtexteditor_help_tab' => array(  | 
                                                        |
| 305 | -                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), | 
                                                        |
| 306 | - 'filename' => 'event_editor_title_richtexteditor',  | 
                                                        |
| 307 | - ),  | 
                                                        |
| 308 | - 'event_editor_venue_details_help_tab' => array(  | 
                                                        |
| 309 | -                        'title'    => esc_html__('Event Venue Details', 'event_espresso'), | 
                                                        |
| 310 | - 'filename' => 'event_editor_venue_details',  | 
                                                        |
| 311 | - ),  | 
                                                        |
| 312 | - 'event_editor_event_datetimes_help_tab' => array(  | 
                                                        |
| 313 | -                        'title'    => esc_html__('Event Datetimes', 'event_espresso'), | 
                                                        |
| 314 | - 'filename' => 'event_editor_event_datetimes',  | 
                                                        |
| 315 | - ),  | 
                                                        |
| 316 | - 'event_editor_event_tickets_help_tab' => array(  | 
                                                        |
| 317 | -                        'title'    => esc_html__('Event Tickets', 'event_espresso'), | 
                                                        |
| 318 | - 'filename' => 'event_editor_event_tickets',  | 
                                                        |
| 319 | - ),  | 
                                                        |
| 320 | - 'event_editor_event_registration_options_help_tab' => array(  | 
                                                        |
| 321 | -                        'title'    => esc_html__('Event Registration Options', 'event_espresso'), | 
                                                        |
| 322 | - 'filename' => 'event_editor_event_registration_options',  | 
                                                        |
| 323 | - ),  | 
                                                        |
| 324 | - 'event_editor_tags_categories_help_tab' => array(  | 
                                                        |
| 325 | -                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'), | 
                                                        |
| 326 | - 'filename' => 'event_editor_tags_categories',  | 
                                                        |
| 327 | - ),  | 
                                                        |
| 328 | - 'event_editor_questions_registrants_help_tab' => array(  | 
                                                        |
| 329 | -                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'), | 
                                                        |
| 330 | - 'filename' => 'event_editor_questions_registrants',  | 
                                                        |
| 331 | - ),  | 
                                                        |
| 332 | - 'event_editor_save_new_event_help_tab' => array(  | 
                                                        |
| 333 | -                        'title'    => esc_html__('Save New Event', 'event_espresso'), | 
                                                        |
| 334 | - 'filename' => 'event_editor_save_new_event',  | 
                                                        |
| 335 | - ),  | 
                                                        |
| 336 | - 'event_editor_other_help_tab' => array(  | 
                                                        |
| 337 | -                        'title'    => esc_html__('Event Other', 'event_espresso'), | 
                                                        |
| 338 | - 'filename' => 'event_editor_other',  | 
                                                        |
| 339 | - ),  | 
                                                        |
| 340 | - ),  | 
                                                        |
| 341 | - 'help_tour' => array(  | 
                                                        |
| 342 | - 'Event_Editor_Help_Tour',  | 
                                                        |
| 343 | - ),  | 
                                                        |
| 344 | -                'qtips'         => array('EE_Event_Editor_Decaf_Tips'), | 
                                                        |
| 345 | - 'require_nonce' => false,  | 
                                                        |
| 346 | - ),  | 
                                                        |
| 347 | - 'edit' => array(  | 
                                                        |
| 348 | - 'nav' => array(  | 
                                                        |
| 349 | -                    'label'      => esc_html__('Edit Event', 'event_espresso'), | 
                                                        |
| 350 | - 'order' => 5,  | 
                                                        |
| 351 | - 'persistent' => false,  | 
                                                        |
| 352 | - 'url' => isset($this->_req_data['post'])  | 
                                                        |
| 353 | - ? EE_Admin_Page::add_query_args_and_nonce(  | 
                                                        |
| 354 | -                            array('post' => $this->_req_data['post'], 'action' => 'edit'), | 
                                                        |
| 355 | - $this->_current_page_view_url  | 
                                                        |
| 356 | - )  | 
                                                        |
| 357 | - : $this->_admin_base_url,  | 
                                                        |
| 358 | - ),  | 
                                                        |
| 359 | -                'metaboxes'     => array('_register_event_editor_meta_boxes'), | 
                                                        |
| 360 | - 'help_tabs' => array(  | 
                                                        |
| 361 | - 'event_editor_help_tab' => array(  | 
                                                        |
| 362 | -                        'title'    => esc_html__('Event Editor', 'event_espresso'), | 
                                                        |
| 363 | - 'filename' => 'event_editor',  | 
                                                        |
| 364 | - ),  | 
                                                        |
| 365 | - 'event_editor_title_richtexteditor_help_tab' => array(  | 
                                                        |
| 366 | -                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), | 
                                                        |
| 367 | - 'filename' => 'event_editor_title_richtexteditor',  | 
                                                        |
| 368 | - ),  | 
                                                        |
| 369 | - 'event_editor_venue_details_help_tab' => array(  | 
                                                        |
| 370 | -                        'title'    => esc_html__('Event Venue Details', 'event_espresso'), | 
                                                        |
| 371 | - 'filename' => 'event_editor_venue_details',  | 
                                                        |
| 372 | - ),  | 
                                                        |
| 373 | - 'event_editor_event_datetimes_help_tab' => array(  | 
                                                        |
| 374 | -                        'title'    => esc_html__('Event Datetimes', 'event_espresso'), | 
                                                        |
| 375 | - 'filename' => 'event_editor_event_datetimes',  | 
                                                        |
| 376 | - ),  | 
                                                        |
| 377 | - 'event_editor_event_tickets_help_tab' => array(  | 
                                                        |
| 378 | -                        'title'    => esc_html__('Event Tickets', 'event_espresso'), | 
                                                        |
| 379 | - 'filename' => 'event_editor_event_tickets',  | 
                                                        |
| 380 | - ),  | 
                                                        |
| 381 | - 'event_editor_event_registration_options_help_tab' => array(  | 
                                                        |
| 382 | -                        'title'    => esc_html__('Event Registration Options', 'event_espresso'), | 
                                                        |
| 383 | - 'filename' => 'event_editor_event_registration_options',  | 
                                                        |
| 384 | - ),  | 
                                                        |
| 385 | - 'event_editor_tags_categories_help_tab' => array(  | 
                                                        |
| 386 | -                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'), | 
                                                        |
| 387 | - 'filename' => 'event_editor_tags_categories',  | 
                                                        |
| 388 | - ),  | 
                                                        |
| 389 | - 'event_editor_questions_registrants_help_tab' => array(  | 
                                                        |
| 390 | -                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'), | 
                                                        |
| 391 | - 'filename' => 'event_editor_questions_registrants',  | 
                                                        |
| 392 | - ),  | 
                                                        |
| 393 | - 'event_editor_save_new_event_help_tab' => array(  | 
                                                        |
| 394 | -                        'title'    => esc_html__('Save New Event', 'event_espresso'), | 
                                                        |
| 395 | - 'filename' => 'event_editor_save_new_event',  | 
                                                        |
| 396 | - ),  | 
                                                        |
| 397 | - 'event_editor_other_help_tab' => array(  | 
                                                        |
| 398 | -                        'title'    => esc_html__('Event Other', 'event_espresso'), | 
                                                        |
| 399 | - 'filename' => 'event_editor_other',  | 
                                                        |
| 400 | - ),  | 
                                                        |
| 401 | - ),  | 
                                                        |
| 402 | -                'qtips'         => array('EE_Event_Editor_Decaf_Tips'), | 
                                                        |
| 403 | - 'require_nonce' => false,  | 
                                                        |
| 404 | - ),  | 
                                                        |
| 405 | - 'default_event_settings' => array(  | 
                                                        |
| 406 | - 'nav' => array(  | 
                                                        |
| 407 | -                    'label' => esc_html__('Default Settings', 'event_espresso'), | 
                                                        |
| 408 | - 'order' => 40,  | 
                                                        |
| 409 | - ),  | 
                                                        |
| 410 | -                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), | 
                                                        |
| 411 | - 'labels' => array(  | 
                                                        |
| 412 | -                    'publishbox' => esc_html__('Update Settings', 'event_espresso'), | 
                                                        |
| 413 | - ),  | 
                                                        |
| 414 | - 'help_tabs' => array(  | 
                                                        |
| 415 | - 'default_settings_help_tab' => array(  | 
                                                        |
| 416 | -                        'title'    => esc_html__('Default Event Settings', 'event_espresso'), | 
                                                        |
| 417 | - 'filename' => 'events_default_settings',  | 
                                                        |
| 418 | - ),  | 
                                                        |
| 419 | - 'default_settings_status_help_tab' => array(  | 
                                                        |
| 420 | -                        'title'    => esc_html__('Default Registration Status', 'event_espresso'), | 
                                                        |
| 421 | - 'filename' => 'events_default_settings_status',  | 
                                                        |
| 422 | - ),  | 
                                                        |
| 423 | - 'default_maximum_tickets_help_tab' => array(  | 
                                                        |
| 424 | -                        'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'), | 
                                                        |
| 425 | - 'filename' => 'events_default_settings_max_tickets',  | 
                                                        |
| 426 | - ),  | 
                                                        |
| 427 | - ),  | 
                                                        |
| 428 | -                'help_tour'     => array('Event_Default_Settings_Help_Tour'), | 
                                                        |
| 429 | - 'require_nonce' => false,  | 
                                                        |
| 430 | - ),  | 
                                                        |
| 431 | - // template settings  | 
                                                        |
| 432 | - 'template_settings' => array(  | 
                                                        |
| 433 | - 'nav' => array(  | 
                                                        |
| 434 | -                    'label' => esc_html__('Templates', 'event_espresso'), | 
                                                        |
| 435 | - 'order' => 30,  | 
                                                        |
| 436 | - ),  | 
                                                        |
| 437 | - 'metaboxes' => $this->_default_espresso_metaboxes,  | 
                                                        |
| 438 | - 'help_tabs' => array(  | 
                                                        |
| 439 | - 'general_settings_templates_help_tab' => array(  | 
                                                        |
| 440 | -                        'title'    => esc_html__('Templates', 'event_espresso'), | 
                                                        |
| 441 | - 'filename' => 'general_settings_templates',  | 
                                                        |
| 442 | - ),  | 
                                                        |
| 443 | - ),  | 
                                                        |
| 444 | -                'help_tour'     => array('Templates_Help_Tour'), | 
                                                        |
| 445 | - 'require_nonce' => false,  | 
                                                        |
| 446 | - ),  | 
                                                        |
| 447 | - // event category stuff  | 
                                                        |
| 448 | - 'add_category' => array(  | 
                                                        |
| 449 | - 'nav' => array(  | 
                                                        |
| 450 | -                    'label'      => esc_html__('Add Category', 'event_espresso'), | 
                                                        |
| 451 | - 'order' => 15,  | 
                                                        |
| 452 | - 'persistent' => false,  | 
                                                        |
| 453 | - ),  | 
                                                        |
| 454 | - 'help_tabs' => array(  | 
                                                        |
| 455 | - 'add_category_help_tab' => array(  | 
                                                        |
| 456 | -                        'title'    => esc_html__('Add New Event Category', 'event_espresso'), | 
                                                        |
| 457 | - 'filename' => 'events_add_category',  | 
                                                        |
| 458 | - ),  | 
                                                        |
| 459 | - ),  | 
                                                        |
| 460 | -                'help_tour'     => array('Event_Add_Category_Help_Tour'), | 
                                                        |
| 461 | -                'metaboxes'     => array('_publish_post_box'), | 
                                                        |
| 462 | - 'require_nonce' => false,  | 
                                                        |
| 463 | - ),  | 
                                                        |
| 464 | - 'edit_category' => array(  | 
                                                        |
| 465 | - 'nav' => array(  | 
                                                        |
| 466 | -                    'label'      => esc_html__('Edit Category', 'event_espresso'), | 
                                                        |
| 467 | - 'order' => 15,  | 
                                                        |
| 468 | - 'persistent' => false,  | 
                                                        |
| 469 | - 'url' => isset($this->_req_data['EVT_CAT_ID'])  | 
                                                        |
| 470 | - ? add_query_arg(  | 
                                                        |
| 471 | -                            array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']), | 
                                                        |
| 472 | - $this->_current_page_view_url  | 
                                                        |
| 473 | - )  | 
                                                        |
| 474 | - : $this->_admin_base_url,  | 
                                                        |
| 475 | - ),  | 
                                                        |
| 476 | - 'help_tabs' => array(  | 
                                                        |
| 477 | - 'edit_category_help_tab' => array(  | 
                                                        |
| 478 | -                        'title'    => esc_html__('Edit Event Category', 'event_espresso'), | 
                                                        |
| 479 | - 'filename' => 'events_edit_category',  | 
                                                        |
| 480 | - ),  | 
                                                        |
| 481 | - ),  | 
                                                        |
| 482 | -                /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/ | 
                                                        |
| 483 | -                'metaboxes'     => array('_publish_post_box'), | 
                                                        |
| 484 | - 'require_nonce' => false,  | 
                                                        |
| 485 | - ),  | 
                                                        |
| 486 | - 'category_list' => array(  | 
                                                        |
| 487 | - 'nav' => array(  | 
                                                        |
| 488 | -                    'label' => esc_html__('Categories', 'event_espresso'), | 
                                                        |
| 489 | - 'order' => 20,  | 
                                                        |
| 490 | - ),  | 
                                                        |
| 491 | - 'list_table' => 'Event_Categories_Admin_List_Table',  | 
                                                        |
| 492 | - 'help_tabs' => array(  | 
                                                        |
| 493 | - 'events_categories_help_tab' => array(  | 
                                                        |
| 494 | -                        'title'    => esc_html__('Event Categories', 'event_espresso'), | 
                                                        |
| 495 | - 'filename' => 'events_categories',  | 
                                                        |
| 496 | - ),  | 
                                                        |
| 497 | - 'events_categories_table_column_headings_help_tab' => array(  | 
                                                        |
| 498 | -                        'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'), | 
                                                        |
| 499 | - 'filename' => 'events_categories_table_column_headings',  | 
                                                        |
| 500 | - ),  | 
                                                        |
| 501 | - 'events_categories_view_help_tab' => array(  | 
                                                        |
| 502 | -                        'title'    => esc_html__('Event Categories Views', 'event_espresso'), | 
                                                        |
| 503 | - 'filename' => 'events_categories_views',  | 
                                                        |
| 504 | - ),  | 
                                                        |
| 505 | - 'events_categories_other_help_tab' => array(  | 
                                                        |
| 506 | -                        'title'    => esc_html__('Event Categories Other', 'event_espresso'), | 
                                                        |
| 507 | - 'filename' => 'events_categories_other',  | 
                                                        |
| 508 | - ),  | 
                                                        |
| 509 | - ),  | 
                                                        |
| 510 | - 'help_tour' => array(  | 
                                                        |
| 511 | - 'Event_Categories_Help_Tour',  | 
                                                        |
| 512 | - ),  | 
                                                        |
| 513 | - 'metaboxes' => $this->_default_espresso_metaboxes,  | 
                                                        |
| 514 | - 'require_nonce' => false,  | 
                                                        |
| 515 | - ),  | 
                                                        |
| 516 | - 'preview_deletion' => array(  | 
                                                        |
| 517 | - 'nav' => array(  | 
                                                        |
| 518 | -                    'label'      => esc_html__('Preview Deletion', 'event_espresso'), | 
                                                        |
| 519 | - 'order' => 15,  | 
                                                        |
| 520 | - 'persistent' => false,  | 
                                                        |
| 521 | - ),  | 
                                                        |
| 19 | + /**  | 
                                                        |
| 20 | + * This will hold the event object for event_details screen.  | 
                                                        |
| 21 | + *  | 
                                                        |
| 22 | + * @access protected  | 
                                                        |
| 23 | + * @var EE_Event $_event  | 
                                                        |
| 24 | + */  | 
                                                        |
| 25 | + protected $_event;  | 
                                                        |
| 26 | +  | 
                                                        |
| 27 | +  | 
                                                        |
| 28 | + /**  | 
                                                        |
| 29 | + * This will hold the category object for category_details screen.  | 
                                                        |
| 30 | + *  | 
                                                        |
| 31 | + * @var stdClass $_category  | 
                                                        |
| 32 | + */  | 
                                                        |
| 33 | + protected $_category;  | 
                                                        |
| 34 | +  | 
                                                        |
| 35 | +  | 
                                                        |
| 36 | + /**  | 
                                                        |
| 37 | + * This will hold the event model instance  | 
                                                        |
| 38 | + *  | 
                                                        |
| 39 | + * @var EEM_Event $_event_model  | 
                                                        |
| 40 | + */  | 
                                                        |
| 41 | + protected $_event_model;  | 
                                                        |
| 42 | +  | 
                                                        |
| 43 | +  | 
                                                        |
| 44 | + /**  | 
                                                        |
| 45 | + * @var EE_Event  | 
                                                        |
| 46 | + */  | 
                                                        |
| 47 | + protected $_cpt_model_obj = false;  | 
                                                        |
| 48 | +  | 
                                                        |
| 49 | +  | 
                                                        |
| 50 | + /**  | 
                                                        |
| 51 | + * Initialize page props for this admin page group.  | 
                                                        |
| 52 | + */  | 
                                                        |
| 53 | + protected function _init_page_props()  | 
                                                        |
| 54 | +	{ | 
                                                        |
| 55 | + $this->page_slug = EVENTS_PG_SLUG;  | 
                                                        |
| 56 | + $this->page_label = EVENTS_LABEL;  | 
                                                        |
| 57 | + $this->_admin_base_url = EVENTS_ADMIN_URL;  | 
                                                        |
| 58 | + $this->_admin_base_path = EVENTS_ADMIN;  | 
                                                        |
| 59 | + $this->_cpt_model_names = array(  | 
                                                        |
| 60 | + 'create_new' => 'EEM_Event',  | 
                                                        |
| 61 | + 'edit' => 'EEM_Event',  | 
                                                        |
| 62 | + );  | 
                                                        |
| 63 | + $this->_cpt_edit_routes = array(  | 
                                                        |
| 64 | + 'espresso_events' => 'edit',  | 
                                                        |
| 65 | + );  | 
                                                        |
| 66 | + add_action(  | 
                                                        |
| 67 | + 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',  | 
                                                        |
| 68 | + array($this, 'verify_event_edit'),  | 
                                                        |
| 69 | + 10,  | 
                                                        |
| 70 | + 2  | 
                                                        |
| 71 | + );  | 
                                                        |
| 72 | + }  | 
                                                        |
| 73 | +  | 
                                                        |
| 74 | +  | 
                                                        |
| 75 | + /**  | 
                                                        |
| 76 | + * Sets the ajax hooks used for this admin page group.  | 
                                                        |
| 77 | + */  | 
                                                        |
| 78 | + protected function _ajax_hooks()  | 
                                                        |
| 79 | +	{ | 
                                                        |
| 80 | +		add_action('wp_ajax_ee_save_timezone_setting', array($this, 'save_timezonestring_setting')); | 
                                                        |
| 81 | + }  | 
                                                        |
| 82 | +  | 
                                                        |
| 83 | +  | 
                                                        |
| 84 | + /**  | 
                                                        |
| 85 | + * Sets the page properties for this admin page group.  | 
                                                        |
| 86 | + */  | 
                                                        |
| 87 | + protected function _define_page_props()  | 
                                                        |
| 88 | +	{ | 
                                                        |
| 89 | + $this->_admin_page_title = EVENTS_LABEL;  | 
                                                        |
| 90 | + $this->_labels = array(  | 
                                                        |
| 91 | + 'buttons' => array(  | 
                                                        |
| 92 | +				'add'             => esc_html__('Add New Event', 'event_espresso'), | 
                                                        |
| 93 | +				'edit'            => esc_html__('Edit Event', 'event_espresso'), | 
                                                        |
| 94 | +				'delete'          => esc_html__('Delete Event', 'event_espresso'), | 
                                                        |
| 95 | +				'add_category'    => esc_html__('Add New Category', 'event_espresso'), | 
                                                        |
| 96 | +				'edit_category'   => esc_html__('Edit Category', 'event_espresso'), | 
                                                        |
| 97 | +				'delete_category' => esc_html__('Delete Category', 'event_espresso'), | 
                                                        |
| 98 | + ),  | 
                                                        |
| 99 | + 'editor_title' => array(  | 
                                                        |
| 100 | +				'espresso_events' => esc_html__('Enter event title here', 'event_espresso'), | 
                                                        |
| 101 | + ),  | 
                                                        |
| 102 | + 'publishbox' => array(  | 
                                                        |
| 103 | +				'create_new'        => esc_html__('Save New Event', 'event_espresso'), | 
                                                        |
| 104 | +				'edit'              => esc_html__('Update Event', 'event_espresso'), | 
                                                        |
| 105 | +				'add_category'      => esc_html__('Save New Category', 'event_espresso'), | 
                                                        |
| 106 | +				'edit_category'     => esc_html__('Update Category', 'event_espresso'), | 
                                                        |
| 107 | +				'template_settings' => esc_html__('Update Settings', 'event_espresso'), | 
                                                        |
| 108 | + ),  | 
                                                        |
| 109 | + );  | 
                                                        |
| 110 | + }  | 
                                                        |
| 111 | +  | 
                                                        |
| 112 | +  | 
                                                        |
| 113 | + /**  | 
                                                        |
| 114 | + * Sets the page routes property for this admin page group.  | 
                                                        |
| 115 | + */  | 
                                                        |
| 116 | + protected function _set_page_routes()  | 
                                                        |
| 117 | +	{ | 
                                                        |
| 118 | + // load formatter helper  | 
                                                        |
| 119 | + // load field generator helper  | 
                                                        |
| 120 | + // is there a evt_id in the request?  | 
                                                        |
| 121 | + $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])  | 
                                                        |
| 122 | + ? $this->_req_data['EVT_ID']  | 
                                                        |
| 123 | + : 0;  | 
                                                        |
| 124 | + $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;  | 
                                                        |
| 125 | + $this->_page_routes = array(  | 
                                                        |
| 126 | + 'default' => array(  | 
                                                        |
| 127 | + 'func' => '_events_overview_list_table',  | 
                                                        |
| 128 | + 'capability' => 'ee_read_events',  | 
                                                        |
| 129 | + ),  | 
                                                        |
| 130 | + 'create_new' => array(  | 
                                                        |
| 131 | + 'func' => '_create_new_cpt_item',  | 
                                                        |
| 132 | + 'capability' => 'ee_edit_events',  | 
                                                        |
| 133 | + ),  | 
                                                        |
| 134 | + 'edit' => array(  | 
                                                        |
| 135 | + 'func' => '_edit_cpt_item',  | 
                                                        |
| 136 | + 'capability' => 'ee_edit_event',  | 
                                                        |
| 137 | + 'obj_id' => $evt_id,  | 
                                                        |
| 138 | + ),  | 
                                                        |
| 139 | + 'copy_event' => array(  | 
                                                        |
| 140 | + 'func' => '_copy_events',  | 
                                                        |
| 141 | + 'capability' => 'ee_edit_event',  | 
                                                        |
| 142 | + 'obj_id' => $evt_id,  | 
                                                        |
| 143 | + 'noheader' => true,  | 
                                                        |
| 144 | + ),  | 
                                                        |
| 145 | + 'trash_event' => array(  | 
                                                        |
| 146 | + 'func' => '_trash_or_restore_event',  | 
                                                        |
| 147 | +				'args'       => array('event_status' => 'trash'), | 
                                                        |
| 148 | + 'capability' => 'ee_delete_event',  | 
                                                        |
| 149 | + 'obj_id' => $evt_id,  | 
                                                        |
| 150 | + 'noheader' => true,  | 
                                                        |
| 151 | + ),  | 
                                                        |
| 152 | + 'trash_events' => array(  | 
                                                        |
| 153 | + 'func' => '_trash_or_restore_events',  | 
                                                        |
| 154 | +				'args'       => array('event_status' => 'trash'), | 
                                                        |
| 155 | + 'capability' => 'ee_delete_events',  | 
                                                        |
| 156 | + 'noheader' => true,  | 
                                                        |
| 157 | + ),  | 
                                                        |
| 158 | + 'restore_event' => array(  | 
                                                        |
| 159 | + 'func' => '_trash_or_restore_event',  | 
                                                        |
| 160 | +				'args'       => array('event_status' => 'draft'), | 
                                                        |
| 161 | + 'capability' => 'ee_delete_event',  | 
                                                        |
| 162 | + 'obj_id' => $evt_id,  | 
                                                        |
| 163 | + 'noheader' => true,  | 
                                                        |
| 164 | + ),  | 
                                                        |
| 165 | + 'restore_events' => array(  | 
                                                        |
| 166 | + 'func' => '_trash_or_restore_events',  | 
                                                        |
| 167 | +				'args'       => array('event_status' => 'draft'), | 
                                                        |
| 168 | + 'capability' => 'ee_delete_events',  | 
                                                        |
| 169 | + 'noheader' => true,  | 
                                                        |
| 170 | + ),  | 
                                                        |
| 171 | + 'delete_event' => array(  | 
                                                        |
| 172 | + 'func' => '_delete_event',  | 
                                                        |
| 173 | + 'capability' => 'ee_delete_event',  | 
                                                        |
| 174 | + 'obj_id' => $evt_id,  | 
                                                        |
| 175 | + 'noheader' => true,  | 
                                                        |
| 176 | + ),  | 
                                                        |
| 177 | + 'delete_events' => array(  | 
                                                        |
| 178 | + 'func' => '_delete_events',  | 
                                                        |
| 179 | + 'capability' => 'ee_delete_events',  | 
                                                        |
| 180 | + 'noheader' => true,  | 
                                                        |
| 181 | + ),  | 
                                                        |
| 182 | + 'view_report' => array(  | 
                                                        |
| 183 | + 'func' => '_view_report',  | 
                                                        |
| 184 | + 'capablity' => 'ee_edit_events',  | 
                                                        |
| 185 | + ),  | 
                                                        |
| 186 | + 'default_event_settings' => array(  | 
                                                        |
| 187 | + 'func' => '_default_event_settings',  | 
                                                        |
| 188 | + 'capability' => 'manage_options',  | 
                                                        |
| 189 | + ),  | 
                                                        |
| 190 | + 'update_default_event_settings' => array(  | 
                                                        |
| 191 | + 'func' => '_update_default_event_settings',  | 
                                                        |
| 192 | + 'capability' => 'manage_options',  | 
                                                        |
| 193 | + 'noheader' => true,  | 
                                                        |
| 194 | + ),  | 
                                                        |
| 195 | + 'template_settings' => array(  | 
                                                        |
| 196 | + 'func' => '_template_settings',  | 
                                                        |
| 197 | + 'capability' => 'manage_options',  | 
                                                        |
| 198 | + ),  | 
                                                        |
| 199 | + // event category tab related  | 
                                                        |
| 200 | + 'add_category' => array(  | 
                                                        |
| 201 | + 'func' => '_category_details',  | 
                                                        |
| 202 | + 'capability' => 'ee_edit_event_category',  | 
                                                        |
| 203 | +				'args'       => array('add'), | 
                                                        |
| 204 | + ),  | 
                                                        |
| 205 | + 'edit_category' => array(  | 
                                                        |
| 206 | + 'func' => '_category_details',  | 
                                                        |
| 207 | + 'capability' => 'ee_edit_event_category',  | 
                                                        |
| 208 | +				'args'       => array('edit'), | 
                                                        |
| 209 | + ),  | 
                                                        |
| 210 | + 'delete_categories' => array(  | 
                                                        |
| 211 | + 'func' => '_delete_categories',  | 
                                                        |
| 212 | + 'capability' => 'ee_delete_event_category',  | 
                                                        |
| 213 | + 'noheader' => true,  | 
                                                        |
| 214 | + ),  | 
                                                        |
| 215 | + 'delete_category' => array(  | 
                                                        |
| 216 | + 'func' => '_delete_categories',  | 
                                                        |
| 217 | + 'capability' => 'ee_delete_event_category',  | 
                                                        |
| 218 | + 'noheader' => true,  | 
                                                        |
| 219 | + ),  | 
                                                        |
| 220 | + 'insert_category' => array(  | 
                                                        |
| 221 | + 'func' => '_insert_or_update_category',  | 
                                                        |
| 222 | +				'args'       => array('new_category' => true), | 
                                                        |
| 223 | + 'capability' => 'ee_edit_event_category',  | 
                                                        |
| 224 | + 'noheader' => true,  | 
                                                        |
| 225 | + ),  | 
                                                        |
| 226 | + 'update_category' => array(  | 
                                                        |
| 227 | + 'func' => '_insert_or_update_category',  | 
                                                        |
| 228 | +				'args'       => array('new_category' => false), | 
                                                        |
| 229 | + 'capability' => 'ee_edit_event_category',  | 
                                                        |
| 230 | + 'noheader' => true,  | 
                                                        |
| 231 | + ),  | 
                                                        |
| 232 | + 'category_list' => array(  | 
                                                        |
| 233 | + 'func' => '_category_list_table',  | 
                                                        |
| 234 | + 'capability' => 'ee_manage_event_categories',  | 
                                                        |
| 235 | + ),  | 
                                                        |
| 236 | + 'preview_deletion' => [  | 
                                                        |
| 237 | + 'func' => 'previewDeletion',  | 
                                                        |
| 238 | + 'capability' => 'ee_delete_events'  | 
                                                        |
| 239 | + ],  | 
                                                        |
| 240 | + 'confirm_deletion' => [  | 
                                                        |
| 241 | + 'func' => 'confirmDeletion',  | 
                                                        |
| 242 | + 'capability' => 'ee_delete_events',  | 
                                                        |
| 243 | + 'noheader' => true  | 
                                                        |
| 244 | + ]  | 
                                                        |
| 245 | + );  | 
                                                        |
| 246 | + }  | 
                                                        |
| 247 | +  | 
                                                        |
| 248 | +  | 
                                                        |
| 249 | + /**  | 
                                                        |
| 250 | + * Set the _page_config property for this admin page group.  | 
                                                        |
| 251 | + */  | 
                                                        |
| 252 | + protected function _set_page_config()  | 
                                                        |
| 253 | +	{ | 
                                                        |
| 254 | + $this->_page_config = array(  | 
                                                        |
| 255 | + 'default' => array(  | 
                                                        |
| 256 | + 'nav' => array(  | 
                                                        |
| 257 | +					'label' => esc_html__('Overview', 'event_espresso'), | 
                                                        |
| 258 | + 'order' => 10,  | 
                                                        |
| 259 | + ),  | 
                                                        |
| 260 | + 'list_table' => 'Events_Admin_List_Table',  | 
                                                        |
| 261 | + 'help_tabs' => array(  | 
                                                        |
| 262 | + 'events_overview_help_tab' => array(  | 
                                                        |
| 263 | +						'title'    => esc_html__('Events Overview', 'event_espresso'), | 
                                                        |
| 264 | + 'filename' => 'events_overview',  | 
                                                        |
| 265 | + ),  | 
                                                        |
| 266 | + 'events_overview_table_column_headings_help_tab' => array(  | 
                                                        |
| 267 | +						'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'), | 
                                                        |
| 268 | + 'filename' => 'events_overview_table_column_headings',  | 
                                                        |
| 269 | + ),  | 
                                                        |
| 270 | + 'events_overview_filters_help_tab' => array(  | 
                                                        |
| 271 | +						'title'    => esc_html__('Events Overview Filters', 'event_espresso'), | 
                                                        |
| 272 | + 'filename' => 'events_overview_filters',  | 
                                                        |
| 273 | + ),  | 
                                                        |
| 274 | + 'events_overview_view_help_tab' => array(  | 
                                                        |
| 275 | +						'title'    => esc_html__('Events Overview Views', 'event_espresso'), | 
                                                        |
| 276 | + 'filename' => 'events_overview_views',  | 
                                                        |
| 277 | + ),  | 
                                                        |
| 278 | + 'events_overview_other_help_tab' => array(  | 
                                                        |
| 279 | +						'title'    => esc_html__('Events Overview Other', 'event_espresso'), | 
                                                        |
| 280 | + 'filename' => 'events_overview_other',  | 
                                                        |
| 281 | + ),  | 
                                                        |
| 282 | + ),  | 
                                                        |
| 283 | + 'help_tour' => array(  | 
                                                        |
| 284 | + 'Event_Overview_Help_Tour',  | 
                                                        |
| 285 | + // 'New_Features_Test_Help_Tour' for testing multiple help tour  | 
                                                        |
| 286 | + ),  | 
                                                        |
| 287 | + 'qtips' => array(  | 
                                                        |
| 288 | + 'EE_Event_List_Table_Tips',  | 
                                                        |
| 289 | + ),  | 
                                                        |
| 290 | + 'require_nonce' => false,  | 
                                                        |
| 291 | + ),  | 
                                                        |
| 292 | + 'create_new' => array(  | 
                                                        |
| 293 | + 'nav' => array(  | 
                                                        |
| 294 | +					'label'      => esc_html__('Add Event', 'event_espresso'), | 
                                                        |
| 295 | + 'order' => 5,  | 
                                                        |
| 296 | + 'persistent' => false,  | 
                                                        |
| 297 | + ),  | 
                                                        |
| 298 | +				'metaboxes'     => array('_register_event_editor_meta_boxes'), | 
                                                        |
| 299 | + 'help_tabs' => array(  | 
                                                        |
| 300 | + 'event_editor_help_tab' => array(  | 
                                                        |
| 301 | +						'title'    => esc_html__('Event Editor', 'event_espresso'), | 
                                                        |
| 302 | + 'filename' => 'event_editor',  | 
                                                        |
| 303 | + ),  | 
                                                        |
| 304 | + 'event_editor_title_richtexteditor_help_tab' => array(  | 
                                                        |
| 305 | +						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), | 
                                                        |
| 306 | + 'filename' => 'event_editor_title_richtexteditor',  | 
                                                        |
| 307 | + ),  | 
                                                        |
| 308 | + 'event_editor_venue_details_help_tab' => array(  | 
                                                        |
| 309 | +						'title'    => esc_html__('Event Venue Details', 'event_espresso'), | 
                                                        |
| 310 | + 'filename' => 'event_editor_venue_details',  | 
                                                        |
| 311 | + ),  | 
                                                        |
| 312 | + 'event_editor_event_datetimes_help_tab' => array(  | 
                                                        |
| 313 | +						'title'    => esc_html__('Event Datetimes', 'event_espresso'), | 
                                                        |
| 314 | + 'filename' => 'event_editor_event_datetimes',  | 
                                                        |
| 315 | + ),  | 
                                                        |
| 316 | + 'event_editor_event_tickets_help_tab' => array(  | 
                                                        |
| 317 | +						'title'    => esc_html__('Event Tickets', 'event_espresso'), | 
                                                        |
| 318 | + 'filename' => 'event_editor_event_tickets',  | 
                                                        |
| 319 | + ),  | 
                                                        |
| 320 | + 'event_editor_event_registration_options_help_tab' => array(  | 
                                                        |
| 321 | +						'title'    => esc_html__('Event Registration Options', 'event_espresso'), | 
                                                        |
| 322 | + 'filename' => 'event_editor_event_registration_options',  | 
                                                        |
| 323 | + ),  | 
                                                        |
| 324 | + 'event_editor_tags_categories_help_tab' => array(  | 
                                                        |
| 325 | +						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'), | 
                                                        |
| 326 | + 'filename' => 'event_editor_tags_categories',  | 
                                                        |
| 327 | + ),  | 
                                                        |
| 328 | + 'event_editor_questions_registrants_help_tab' => array(  | 
                                                        |
| 329 | +						'title'    => esc_html__('Questions for Registrants', 'event_espresso'), | 
                                                        |
| 330 | + 'filename' => 'event_editor_questions_registrants',  | 
                                                        |
| 331 | + ),  | 
                                                        |
| 332 | + 'event_editor_save_new_event_help_tab' => array(  | 
                                                        |
| 333 | +						'title'    => esc_html__('Save New Event', 'event_espresso'), | 
                                                        |
| 334 | + 'filename' => 'event_editor_save_new_event',  | 
                                                        |
| 335 | + ),  | 
                                                        |
| 336 | + 'event_editor_other_help_tab' => array(  | 
                                                        |
| 337 | +						'title'    => esc_html__('Event Other', 'event_espresso'), | 
                                                        |
| 338 | + 'filename' => 'event_editor_other',  | 
                                                        |
| 339 | + ),  | 
                                                        |
| 340 | + ),  | 
                                                        |
| 341 | + 'help_tour' => array(  | 
                                                        |
| 342 | + 'Event_Editor_Help_Tour',  | 
                                                        |
| 343 | + ),  | 
                                                        |
| 344 | +				'qtips'         => array('EE_Event_Editor_Decaf_Tips'), | 
                                                        |
| 345 | + 'require_nonce' => false,  | 
                                                        |
| 346 | + ),  | 
                                                        |
| 347 | + 'edit' => array(  | 
                                                        |
| 348 | + 'nav' => array(  | 
                                                        |
| 349 | +					'label'      => esc_html__('Edit Event', 'event_espresso'), | 
                                                        |
| 350 | + 'order' => 5,  | 
                                                        |
| 351 | + 'persistent' => false,  | 
                                                        |
| 352 | + 'url' => isset($this->_req_data['post'])  | 
                                                        |
| 353 | + ? EE_Admin_Page::add_query_args_and_nonce(  | 
                                                        |
| 354 | +							array('post' => $this->_req_data['post'], 'action' => 'edit'), | 
                                                        |
| 355 | + $this->_current_page_view_url  | 
                                                        |
| 356 | + )  | 
                                                        |
| 357 | + : $this->_admin_base_url,  | 
                                                        |
| 358 | + ),  | 
                                                        |
| 359 | +				'metaboxes'     => array('_register_event_editor_meta_boxes'), | 
                                                        |
| 360 | + 'help_tabs' => array(  | 
                                                        |
| 361 | + 'event_editor_help_tab' => array(  | 
                                                        |
| 362 | +						'title'    => esc_html__('Event Editor', 'event_espresso'), | 
                                                        |
| 363 | + 'filename' => 'event_editor',  | 
                                                        |
| 364 | + ),  | 
                                                        |
| 365 | + 'event_editor_title_richtexteditor_help_tab' => array(  | 
                                                        |
| 366 | +						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), | 
                                                        |
| 367 | + 'filename' => 'event_editor_title_richtexteditor',  | 
                                                        |
| 368 | + ),  | 
                                                        |
| 369 | + 'event_editor_venue_details_help_tab' => array(  | 
                                                        |
| 370 | +						'title'    => esc_html__('Event Venue Details', 'event_espresso'), | 
                                                        |
| 371 | + 'filename' => 'event_editor_venue_details',  | 
                                                        |
| 372 | + ),  | 
                                                        |
| 373 | + 'event_editor_event_datetimes_help_tab' => array(  | 
                                                        |
| 374 | +						'title'    => esc_html__('Event Datetimes', 'event_espresso'), | 
                                                        |
| 375 | + 'filename' => 'event_editor_event_datetimes',  | 
                                                        |
| 376 | + ),  | 
                                                        |
| 377 | + 'event_editor_event_tickets_help_tab' => array(  | 
                                                        |
| 378 | +						'title'    => esc_html__('Event Tickets', 'event_espresso'), | 
                                                        |
| 379 | + 'filename' => 'event_editor_event_tickets',  | 
                                                        |
| 380 | + ),  | 
                                                        |
| 381 | + 'event_editor_event_registration_options_help_tab' => array(  | 
                                                        |
| 382 | +						'title'    => esc_html__('Event Registration Options', 'event_espresso'), | 
                                                        |
| 383 | + 'filename' => 'event_editor_event_registration_options',  | 
                                                        |
| 384 | + ),  | 
                                                        |
| 385 | + 'event_editor_tags_categories_help_tab' => array(  | 
                                                        |
| 386 | +						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'), | 
                                                        |
| 387 | + 'filename' => 'event_editor_tags_categories',  | 
                                                        |
| 388 | + ),  | 
                                                        |
| 389 | + 'event_editor_questions_registrants_help_tab' => array(  | 
                                                        |
| 390 | +						'title'    => esc_html__('Questions for Registrants', 'event_espresso'), | 
                                                        |
| 391 | + 'filename' => 'event_editor_questions_registrants',  | 
                                                        |
| 392 | + ),  | 
                                                        |
| 393 | + 'event_editor_save_new_event_help_tab' => array(  | 
                                                        |
| 394 | +						'title'    => esc_html__('Save New Event', 'event_espresso'), | 
                                                        |
| 395 | + 'filename' => 'event_editor_save_new_event',  | 
                                                        |
| 396 | + ),  | 
                                                        |
| 397 | + 'event_editor_other_help_tab' => array(  | 
                                                        |
| 398 | +						'title'    => esc_html__('Event Other', 'event_espresso'), | 
                                                        |
| 399 | + 'filename' => 'event_editor_other',  | 
                                                        |
| 400 | + ),  | 
                                                        |
| 401 | + ),  | 
                                                        |
| 402 | +				'qtips'         => array('EE_Event_Editor_Decaf_Tips'), | 
                                                        |
| 403 | + 'require_nonce' => false,  | 
                                                        |
| 404 | + ),  | 
                                                        |
| 405 | + 'default_event_settings' => array(  | 
                                                        |
| 406 | + 'nav' => array(  | 
                                                        |
| 407 | +					'label' => esc_html__('Default Settings', 'event_espresso'), | 
                                                        |
| 408 | + 'order' => 40,  | 
                                                        |
| 409 | + ),  | 
                                                        |
| 410 | +				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), | 
                                                        |
| 411 | + 'labels' => array(  | 
                                                        |
| 412 | +					'publishbox' => esc_html__('Update Settings', 'event_espresso'), | 
                                                        |
| 413 | + ),  | 
                                                        |
| 414 | + 'help_tabs' => array(  | 
                                                        |
| 415 | + 'default_settings_help_tab' => array(  | 
                                                        |
| 416 | +						'title'    => esc_html__('Default Event Settings', 'event_espresso'), | 
                                                        |
| 417 | + 'filename' => 'events_default_settings',  | 
                                                        |
| 418 | + ),  | 
                                                        |
| 419 | + 'default_settings_status_help_tab' => array(  | 
                                                        |
| 420 | +						'title'    => esc_html__('Default Registration Status', 'event_espresso'), | 
                                                        |
| 421 | + 'filename' => 'events_default_settings_status',  | 
                                                        |
| 422 | + ),  | 
                                                        |
| 423 | + 'default_maximum_tickets_help_tab' => array(  | 
                                                        |
| 424 | +						'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'), | 
                                                        |
| 425 | + 'filename' => 'events_default_settings_max_tickets',  | 
                                                        |
| 426 | + ),  | 
                                                        |
| 427 | + ),  | 
                                                        |
| 428 | +				'help_tour'     => array('Event_Default_Settings_Help_Tour'), | 
                                                        |
| 429 | + 'require_nonce' => false,  | 
                                                        |
| 430 | + ),  | 
                                                        |
| 431 | + // template settings  | 
                                                        |
| 432 | + 'template_settings' => array(  | 
                                                        |
| 433 | + 'nav' => array(  | 
                                                        |
| 434 | +					'label' => esc_html__('Templates', 'event_espresso'), | 
                                                        |
| 435 | + 'order' => 30,  | 
                                                        |
| 436 | + ),  | 
                                                        |
| 437 | + 'metaboxes' => $this->_default_espresso_metaboxes,  | 
                                                        |
| 438 | + 'help_tabs' => array(  | 
                                                        |
| 439 | + 'general_settings_templates_help_tab' => array(  | 
                                                        |
| 440 | +						'title'    => esc_html__('Templates', 'event_espresso'), | 
                                                        |
| 441 | + 'filename' => 'general_settings_templates',  | 
                                                        |
| 442 | + ),  | 
                                                        |
| 443 | + ),  | 
                                                        |
| 444 | +				'help_tour'     => array('Templates_Help_Tour'), | 
                                                        |
| 445 | + 'require_nonce' => false,  | 
                                                        |
| 446 | + ),  | 
                                                        |
| 447 | + // event category stuff  | 
                                                        |
| 448 | + 'add_category' => array(  | 
                                                        |
| 449 | + 'nav' => array(  | 
                                                        |
| 450 | +					'label'      => esc_html__('Add Category', 'event_espresso'), | 
                                                        |
| 451 | + 'order' => 15,  | 
                                                        |
| 452 | + 'persistent' => false,  | 
                                                        |
| 453 | + ),  | 
                                                        |
| 454 | + 'help_tabs' => array(  | 
                                                        |
| 455 | + 'add_category_help_tab' => array(  | 
                                                        |
| 456 | +						'title'    => esc_html__('Add New Event Category', 'event_espresso'), | 
                                                        |
| 457 | + 'filename' => 'events_add_category',  | 
                                                        |
| 458 | + ),  | 
                                                        |
| 459 | + ),  | 
                                                        |
| 460 | +				'help_tour'     => array('Event_Add_Category_Help_Tour'), | 
                                                        |
| 461 | +				'metaboxes'     => array('_publish_post_box'), | 
                                                        |
| 462 | + 'require_nonce' => false,  | 
                                                        |
| 463 | + ),  | 
                                                        |
| 464 | + 'edit_category' => array(  | 
                                                        |
| 465 | + 'nav' => array(  | 
                                                        |
| 466 | +					'label'      => esc_html__('Edit Category', 'event_espresso'), | 
                                                        |
| 467 | + 'order' => 15,  | 
                                                        |
| 468 | + 'persistent' => false,  | 
                                                        |
| 469 | + 'url' => isset($this->_req_data['EVT_CAT_ID'])  | 
                                                        |
| 470 | + ? add_query_arg(  | 
                                                        |
| 471 | +							array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']), | 
                                                        |
| 472 | + $this->_current_page_view_url  | 
                                                        |
| 473 | + )  | 
                                                        |
| 474 | + : $this->_admin_base_url,  | 
                                                        |
| 475 | + ),  | 
                                                        |
| 476 | + 'help_tabs' => array(  | 
                                                        |
| 477 | + 'edit_category_help_tab' => array(  | 
                                                        |
| 478 | +						'title'    => esc_html__('Edit Event Category', 'event_espresso'), | 
                                                        |
| 479 | + 'filename' => 'events_edit_category',  | 
                                                        |
| 480 | + ),  | 
                                                        |
| 481 | + ),  | 
                                                        |
| 482 | +				/*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/ | 
                                                        |
| 483 | +				'metaboxes'     => array('_publish_post_box'), | 
                                                        |
| 484 | + 'require_nonce' => false,  | 
                                                        |
| 485 | + ),  | 
                                                        |
| 486 | + 'category_list' => array(  | 
                                                        |
| 487 | + 'nav' => array(  | 
                                                        |
| 488 | +					'label' => esc_html__('Categories', 'event_espresso'), | 
                                                        |
| 489 | + 'order' => 20,  | 
                                                        |
| 490 | + ),  | 
                                                        |
| 491 | + 'list_table' => 'Event_Categories_Admin_List_Table',  | 
                                                        |
| 492 | + 'help_tabs' => array(  | 
                                                        |
| 493 | + 'events_categories_help_tab' => array(  | 
                                                        |
| 494 | +						'title'    => esc_html__('Event Categories', 'event_espresso'), | 
                                                        |
| 495 | + 'filename' => 'events_categories',  | 
                                                        |
| 496 | + ),  | 
                                                        |
| 497 | + 'events_categories_table_column_headings_help_tab' => array(  | 
                                                        |
| 498 | +						'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'), | 
                                                        |
| 499 | + 'filename' => 'events_categories_table_column_headings',  | 
                                                        |
| 500 | + ),  | 
                                                        |
| 501 | + 'events_categories_view_help_tab' => array(  | 
                                                        |
| 502 | +						'title'    => esc_html__('Event Categories Views', 'event_espresso'), | 
                                                        |
| 503 | + 'filename' => 'events_categories_views',  | 
                                                        |
| 504 | + ),  | 
                                                        |
| 505 | + 'events_categories_other_help_tab' => array(  | 
                                                        |
| 506 | +						'title'    => esc_html__('Event Categories Other', 'event_espresso'), | 
                                                        |
| 507 | + 'filename' => 'events_categories_other',  | 
                                                        |
| 508 | + ),  | 
                                                        |
| 509 | + ),  | 
                                                        |
| 510 | + 'help_tour' => array(  | 
                                                        |
| 511 | + 'Event_Categories_Help_Tour',  | 
                                                        |
| 512 | + ),  | 
                                                        |
| 513 | + 'metaboxes' => $this->_default_espresso_metaboxes,  | 
                                                        |
| 514 | + 'require_nonce' => false,  | 
                                                        |
| 515 | + ),  | 
                                                        |
| 516 | + 'preview_deletion' => array(  | 
                                                        |
| 517 | + 'nav' => array(  | 
                                                        |
| 518 | +					'label'      => esc_html__('Preview Deletion', 'event_espresso'), | 
                                                        |
| 519 | + 'order' => 15,  | 
                                                        |
| 520 | + 'persistent' => false,  | 
                                                        |
| 521 | + ),  | 
                                                        |
| 522 | 522 | // 'help_tabs' => array(  | 
                                                        
| 523 | 523 | // 'add_category_help_tab' => array(  | 
                                                        
| 524 | 524 |  //                        'title'    => esc_html__('Add New Event Category', 'event_espresso'), | 
                                                        
@@ -528,2302 +528,2302 @@ discard block  | 
                                                    ||
| 528 | 528 |  //                'help_tour'     => array('Event_Add_Category_Help_Tour'), | 
                                                        
| 529 | 529 |  //                'metaboxes'     => array('_publish_post_box'), | 
                                                        
| 530 | 530 | // 'require_nonce' => false,  | 
                                                        
| 531 | - )  | 
                                                        |
| 532 | - );  | 
                                                        |
| 533 | - }  | 
                                                        |
| 534 | -  | 
                                                        |
| 535 | -  | 
                                                        |
| 536 | - /**  | 
                                                        |
| 537 | - * Used to register any global screen options if necessary for every route in this admin page group.  | 
                                                        |
| 538 | - */  | 
                                                        |
| 539 | - protected function _add_screen_options()  | 
                                                        |
| 540 | -    { | 
                                                        |
| 541 | - }  | 
                                                        |
| 542 | -  | 
                                                        |
| 543 | -  | 
                                                        |
| 544 | - /**  | 
                                                        |
| 545 | - * Implementing the screen options for the 'default' route.  | 
                                                        |
| 546 | - */  | 
                                                        |
| 547 | - protected function _add_screen_options_default()  | 
                                                        |
| 548 | -    { | 
                                                        |
| 549 | - $this->_per_page_screen_option();  | 
                                                        |
| 550 | - }  | 
                                                        |
| 551 | -  | 
                                                        |
| 552 | -  | 
                                                        |
| 553 | - /**  | 
                                                        |
| 554 | - * Implementing screen options for the category list route.  | 
                                                        |
| 555 | - */  | 
                                                        |
| 556 | - protected function _add_screen_options_category_list()  | 
                                                        |
| 557 | -    { | 
                                                        |
| 558 | - $page_title = $this->_admin_page_title;  | 
                                                        |
| 559 | -        $this->_admin_page_title = esc_html__('Categories', 'event_espresso'); | 
                                                        |
| 560 | - $this->_per_page_screen_option();  | 
                                                        |
| 561 | - $this->_admin_page_title = $page_title;  | 
                                                        |
| 562 | - }  | 
                                                        |
| 563 | -  | 
                                                        |
| 564 | -  | 
                                                        |
| 565 | - /**  | 
                                                        |
| 566 | - * Used to register any global feature pointers for the admin page group.  | 
                                                        |
| 567 | - */  | 
                                                        |
| 568 | - protected function _add_feature_pointers()  | 
                                                        |
| 569 | -    { | 
                                                        |
| 570 | - }  | 
                                                        |
| 571 | -  | 
                                                        |
| 572 | -  | 
                                                        |
| 573 | - /**  | 
                                                        |
| 574 | - * Registers and enqueues any global scripts and styles for the entire admin page group.  | 
                                                        |
| 575 | - */  | 
                                                        |
| 576 | - public function load_scripts_styles()  | 
                                                        |
| 577 | -    { | 
                                                        |
| 578 | - wp_register_style(  | 
                                                        |
| 579 | - 'events-admin-css',  | 
                                                        |
| 580 | - EVENTS_ASSETS_URL . 'events-admin-page.css',  | 
                                                        |
| 581 | - array(),  | 
                                                        |
| 582 | - EVENT_ESPRESSO_VERSION  | 
                                                        |
| 583 | - );  | 
                                                        |
| 584 | -        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); | 
                                                        |
| 585 | -        wp_enqueue_style('events-admin-css'); | 
                                                        |
| 586 | -        wp_enqueue_style('ee-cat-admin'); | 
                                                        |
| 587 | - // todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details  | 
                                                        |
| 588 | - // registers for all views  | 
                                                        |
| 589 | - // scripts  | 
                                                        |
| 590 | - wp_register_script(  | 
                                                        |
| 591 | - 'event_editor_js',  | 
                                                        |
| 592 | - EVENTS_ASSETS_URL . 'event_editor.js',  | 
                                                        |
| 593 | -            array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'), | 
                                                        |
| 594 | - EVENT_ESPRESSO_VERSION,  | 
                                                        |
| 595 | - true  | 
                                                        |
| 596 | - );  | 
                                                        |
| 597 | - }  | 
                                                        |
| 598 | -  | 
                                                        |
| 599 | -  | 
                                                        |
| 600 | - /**  | 
                                                        |
| 601 | - * Enqueuing scripts and styles specific to this view  | 
                                                        |
| 602 | - */  | 
                                                        |
| 603 | - public function load_scripts_styles_create_new()  | 
                                                        |
| 604 | -    { | 
                                                        |
| 605 | - $this->load_scripts_styles_edit();  | 
                                                        |
| 606 | - }  | 
                                                        |
| 607 | -  | 
                                                        |
| 608 | -  | 
                                                        |
| 609 | - /**  | 
                                                        |
| 610 | - * Enqueuing scripts and styles specific to this view  | 
                                                        |
| 611 | - */  | 
                                                        |
| 612 | - public function load_scripts_styles_edit()  | 
                                                        |
| 613 | -    { | 
                                                        |
| 614 | - // styles  | 
                                                        |
| 615 | -        wp_enqueue_style('espresso-ui-theme'); | 
                                                        |
| 616 | - wp_register_style(  | 
                                                        |
| 617 | - 'event-editor-css',  | 
                                                        |
| 618 | - EVENTS_ASSETS_URL . 'event-editor.css',  | 
                                                        |
| 619 | -            array('ee-admin-css'), | 
                                                        |
| 620 | - EVENT_ESPRESSO_VERSION  | 
                                                        |
| 621 | - );  | 
                                                        |
| 622 | -        wp_enqueue_style('event-editor-css'); | 
                                                        |
| 623 | - // scripts  | 
                                                        |
| 624 | - wp_register_script(  | 
                                                        |
| 625 | - 'event-datetime-metabox',  | 
                                                        |
| 626 | - EVENTS_ASSETS_URL . 'event-datetime-metabox.js',  | 
                                                        |
| 627 | -            array('event_editor_js', 'ee-datepicker'), | 
                                                        |
| 628 | - EVENT_ESPRESSO_VERSION  | 
                                                        |
| 629 | - );  | 
                                                        |
| 630 | -        wp_enqueue_script('event-datetime-metabox'); | 
                                                        |
| 631 | - }  | 
                                                        |
| 632 | -  | 
                                                        |
| 633 | -  | 
                                                        |
| 634 | - /**  | 
                                                        |
| 635 | - * Populating the _views property for the category list table view.  | 
                                                        |
| 636 | - */  | 
                                                        |
| 637 | - protected function _set_list_table_views_category_list()  | 
                                                        |
| 638 | -    { | 
                                                        |
| 639 | - $this->_views = array(  | 
                                                        |
| 640 | - 'all' => array(  | 
                                                        |
| 641 | - 'slug' => 'all',  | 
                                                        |
| 642 | -                'label'       => esc_html__('All', 'event_espresso'), | 
                                                        |
| 643 | - 'count' => 0,  | 
                                                        |
| 644 | - 'bulk_action' => array(  | 
                                                        |
| 645 | -                    'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'), | 
                                                        |
| 646 | - ),  | 
                                                        |
| 647 | - ),  | 
                                                        |
| 648 | - );  | 
                                                        |
| 649 | - }  | 
                                                        |
| 650 | -  | 
                                                        |
| 651 | -  | 
                                                        |
| 652 | - /**  | 
                                                        |
| 653 | - * For adding anything that fires on the admin_init hook for any route within this admin page group.  | 
                                                        |
| 654 | - */  | 
                                                        |
| 655 | - public function admin_init()  | 
                                                        |
| 656 | -    { | 
                                                        |
| 657 | - EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(  | 
                                                        |
| 658 | - 'Do you really want to delete this image? Please remember to update your event to complete the removal.',  | 
                                                        |
| 659 | - 'event_espresso'  | 
                                                        |
| 660 | - );  | 
                                                        |
| 661 | - }  | 
                                                        |
| 662 | -  | 
                                                        |
| 663 | -  | 
                                                        |
| 664 | - /**  | 
                                                        |
| 665 | - * For adding anything that should be triggered on the admin_notices hook for any route within this admin page  | 
                                                        |
| 666 | - * group.  | 
                                                        |
| 667 | - */  | 
                                                        |
| 668 | - public function admin_notices()  | 
                                                        |
| 669 | -    { | 
                                                        |
| 670 | - }  | 
                                                        |
| 671 | -  | 
                                                        |
| 672 | -  | 
                                                        |
| 673 | - /**  | 
                                                        |
| 674 | - * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within  | 
                                                        |
| 675 | - * this admin page group.  | 
                                                        |
| 676 | - */  | 
                                                        |
| 677 | - public function admin_footer_scripts()  | 
                                                        |
| 678 | -    { | 
                                                        |
| 679 | - }  | 
                                                        |
| 680 | -  | 
                                                        |
| 681 | -  | 
                                                        |
| 682 | - /**  | 
                                                        |
| 683 | - * Call this function to verify if an event is public and has tickets for sale. If it does, then we need to show a  | 
                                                        |
| 684 | - * warning (via EE_Error::add_error());  | 
                                                        |
| 685 | - *  | 
                                                        |
| 686 | - * @param EE_Event $event Event object  | 
                                                        |
| 687 | - * @param string $req_type  | 
                                                        |
| 688 | - * @return void  | 
                                                        |
| 689 | - * @throws EE_Error  | 
                                                        |
| 690 | - * @access public  | 
                                                        |
| 691 | - */  | 
                                                        |
| 692 | - public function verify_event_edit($event = null, $req_type = '')  | 
                                                        |
| 693 | -    { | 
                                                        |
| 694 | - // don't need to do this when processing  | 
                                                        |
| 695 | -        if (! empty($req_type)) { | 
                                                        |
| 696 | - return;  | 
                                                        |
| 697 | - }  | 
                                                        |
| 698 | - // no event?  | 
                                                        |
| 699 | -        if (empty($event)) { | 
                                                        |
| 700 | - // set event  | 
                                                        |
| 701 | - $event = $this->_cpt_model_obj;  | 
                                                        |
| 702 | - }  | 
                                                        |
| 703 | - // STILL no event?  | 
                                                        |
| 704 | -        if (! $event instanceof EE_Event) { | 
                                                        |
| 705 | - return;  | 
                                                        |
| 706 | - }  | 
                                                        |
| 707 | - $orig_status = $event->status();  | 
                                                        |
| 708 | - // first check if event is active.  | 
                                                        |
| 709 | - if ($orig_status === EEM_Event::cancelled  | 
                                                        |
| 710 | - || $orig_status === EEM_Event::postponed  | 
                                                        |
| 711 | - || $event->is_expired()  | 
                                                        |
| 712 | - || $event->is_inactive()  | 
                                                        |
| 713 | -        ) { | 
                                                        |
| 714 | - return;  | 
                                                        |
| 715 | - }  | 
                                                        |
| 716 | - // made it here so it IS active... next check that any of the tickets are sold.  | 
                                                        |
| 717 | -        if ($event->is_sold_out(true)) { | 
                                                        |
| 718 | -            if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) { | 
                                                        |
| 719 | - EE_Error::add_attention(  | 
                                                        |
| 720 | - sprintf(  | 
                                                        |
| 721 | - esc_html__(  | 
                                                        |
| 722 | - 'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event. However, this change is not permanent until you update the event. You can change the status back to something else before updating if you wish.',  | 
                                                        |
| 723 | - 'event_espresso'  | 
                                                        |
| 724 | - ),  | 
                                                        |
| 725 | - EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')  | 
                                                        |
| 726 | - )  | 
                                                        |
| 727 | - );  | 
                                                        |
| 728 | - }  | 
                                                        |
| 729 | - return;  | 
                                                        |
| 730 | -        } elseif ($orig_status === EEM_Event::sold_out) { | 
                                                        |
| 731 | - EE_Error::add_attention(  | 
                                                        |
| 732 | - sprintf(  | 
                                                        |
| 733 | - esc_html__(  | 
                                                        |
| 734 | - 'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets. However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',  | 
                                                        |
| 735 | - 'event_espresso'  | 
                                                        |
| 736 | - ),  | 
                                                        |
| 737 | - EEH_Template::pretty_status($event->status(), false, 'sentence')  | 
                                                        |
| 738 | - )  | 
                                                        |
| 739 | - );  | 
                                                        |
| 740 | - }  | 
                                                        |
| 741 | - // now we need to determine if the event has any tickets on sale. If not then we dont' show the error  | 
                                                        |
| 742 | -        if (! $event->tickets_on_sale()) { | 
                                                        |
| 743 | - return;  | 
                                                        |
| 744 | - }  | 
                                                        |
| 745 | - // made it here so show warning  | 
                                                        |
| 746 | - $this->_edit_event_warning();  | 
                                                        |
| 747 | - }  | 
                                                        |
| 748 | -  | 
                                                        |
| 749 | -  | 
                                                        |
| 750 | - /**  | 
                                                        |
| 751 | - * This is the text used for when an event is being edited that is public and has tickets for sale.  | 
                                                        |
| 752 | - * When needed, hook this into a EE_Error::add_error() notice.  | 
                                                        |
| 753 | - *  | 
                                                        |
| 754 | - * @access protected  | 
                                                        |
| 755 | - * @return void  | 
                                                        |
| 756 | - */  | 
                                                        |
| 757 | - protected function _edit_event_warning()  | 
                                                        |
| 758 | -    { | 
                                                        |
| 759 | - // we don't want to add warnings during these requests  | 
                                                        |
| 760 | -        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') { | 
                                                        |
| 761 | - return;  | 
                                                        |
| 762 | - }  | 
                                                        |
| 763 | - EE_Error::add_attention(  | 
                                                        |
| 764 | - sprintf(  | 
                                                        |
| 765 | - esc_html__(  | 
                                                        |
| 766 | - 'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',  | 
                                                        |
| 767 | - 'event_espresso'  | 
                                                        |
| 768 | - ),  | 
                                                        |
| 769 | - '<a class="espresso-help-tab-lnk">',  | 
                                                        |
| 770 | - '</a>'  | 
                                                        |
| 771 | - )  | 
                                                        |
| 772 | - );  | 
                                                        |
| 773 | - }  | 
                                                        |
| 774 | -  | 
                                                        |
| 775 | -  | 
                                                        |
| 776 | - /**  | 
                                                        |
| 777 | - * When a user is creating a new event, notify them if they haven't set their timezone.  | 
                                                        |
| 778 | - * Otherwise, do the normal logic  | 
                                                        |
| 779 | - *  | 
                                                        |
| 780 | - * @return string  | 
                                                        |
| 781 | - * @throws \EE_Error  | 
                                                        |
| 782 | - */  | 
                                                        |
| 783 | - protected function _create_new_cpt_item()  | 
                                                        |
| 784 | -    { | 
                                                        |
| 785 | -        $has_timezone_string = get_option('timezone_string'); | 
                                                        |
| 786 | - // only nag them about setting their timezone if it's their first event, and they haven't already done it  | 
                                                        |
| 787 | -        if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) { | 
                                                        |
| 788 | - EE_Error::add_attention(  | 
                                                        |
| 789 | - sprintf(  | 
                                                        |
| 790 | - __(  | 
                                                        |
| 791 | - 'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',  | 
                                                        |
| 792 | - 'event_espresso'  | 
                                                        |
| 793 | - ),  | 
                                                        |
| 794 | - '<br>',  | 
                                                        |
| 795 | - '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'  | 
                                                        |
| 796 | -                    . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale()) | 
                                                        |
| 797 | - . '</select>',  | 
                                                        |
| 798 | - '<button class="button button-secondary timezone-submit">',  | 
                                                        |
| 799 | - '</button><span class="spinner"></span>'  | 
                                                        |
| 800 | - ),  | 
                                                        |
| 801 | - __FILE__,  | 
                                                        |
| 802 | - __FUNCTION__,  | 
                                                        |
| 803 | - __LINE__  | 
                                                        |
| 804 | - );  | 
                                                        |
| 805 | - }  | 
                                                        |
| 806 | - return parent::_create_new_cpt_item();  | 
                                                        |
| 807 | - }  | 
                                                        |
| 808 | -  | 
                                                        |
| 809 | -  | 
                                                        |
| 810 | - /**  | 
                                                        |
| 811 | - * Sets the _views property for the default route in this admin page group.  | 
                                                        |
| 812 | - */  | 
                                                        |
| 813 | - protected function _set_list_table_views_default()  | 
                                                        |
| 814 | -    { | 
                                                        |
| 815 | - $this->_views = array(  | 
                                                        |
| 816 | - 'all' => array(  | 
                                                        |
| 817 | - 'slug' => 'all',  | 
                                                        |
| 818 | -                'label'       => esc_html__('View All Events', 'event_espresso'), | 
                                                        |
| 819 | - 'count' => 0,  | 
                                                        |
| 820 | - 'bulk_action' => array(  | 
                                                        |
| 821 | -                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'), | 
                                                        |
| 822 | - ),  | 
                                                        |
| 823 | - ),  | 
                                                        |
| 824 | - 'draft' => array(  | 
                                                        |
| 825 | - 'slug' => 'draft',  | 
                                                        |
| 826 | -                'label'       => esc_html__('Draft', 'event_espresso'), | 
                                                        |
| 827 | - 'count' => 0,  | 
                                                        |
| 828 | - 'bulk_action' => array(  | 
                                                        |
| 829 | -                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'), | 
                                                        |
| 830 | - ),  | 
                                                        |
| 831 | - ),  | 
                                                        |
| 832 | - );  | 
                                                        |
| 833 | -        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { | 
                                                        |
| 834 | - $this->_views['trash'] = array(  | 
                                                        |
| 835 | - 'slug' => 'trash',  | 
                                                        |
| 836 | -                'label'       => esc_html__('Trash', 'event_espresso'), | 
                                                        |
| 837 | - 'count' => 0,  | 
                                                        |
| 838 | - 'bulk_action' => array(  | 
                                                        |
| 839 | -                    'restore_events' => esc_html__('Restore From Trash', 'event_espresso'), | 
                                                        |
| 840 | -                    'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'), | 
                                                        |
| 841 | - ),  | 
                                                        |
| 842 | - );  | 
                                                        |
| 843 | - }  | 
                                                        |
| 844 | - }  | 
                                                        |
| 845 | -  | 
                                                        |
| 846 | -  | 
                                                        |
| 847 | - /**  | 
                                                        |
| 848 | - * Provides the legend item array for the default list table view.  | 
                                                        |
| 849 | - *  | 
                                                        |
| 850 | - * @return array  | 
                                                        |
| 851 | - */  | 
                                                        |
| 852 | - protected function _event_legend_items()  | 
                                                        |
| 853 | -    { | 
                                                        |
| 854 | - $items = array(  | 
                                                        |
| 855 | - 'view_details' => array(  | 
                                                        |
| 856 | - 'class' => 'dashicons dashicons-search',  | 
                                                        |
| 857 | -                'desc'  => esc_html__('View Event', 'event_espresso'), | 
                                                        |
| 858 | - ),  | 
                                                        |
| 859 | - 'edit_event' => array(  | 
                                                        |
| 860 | - 'class' => 'ee-icon ee-icon-calendar-edit',  | 
                                                        |
| 861 | -                'desc'  => esc_html__('Edit Event Details', 'event_espresso'), | 
                                                        |
| 862 | - ),  | 
                                                        |
| 863 | - 'view_attendees' => array(  | 
                                                        |
| 864 | - 'class' => 'dashicons dashicons-groups',  | 
                                                        |
| 865 | -                'desc'  => esc_html__('View Registrations for Event', 'event_espresso'), | 
                                                        |
| 866 | - ),  | 
                                                        |
| 867 | - );  | 
                                                        |
| 868 | -        $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); | 
                                                        |
| 869 | - $statuses = array(  | 
                                                        |
| 870 | - 'sold_out_status' => array(  | 
                                                        |
| 871 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,  | 
                                                        |
| 872 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),  | 
                                                        |
| 873 | - ),  | 
                                                        |
| 874 | - 'active_status' => array(  | 
                                                        |
| 875 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,  | 
                                                        |
| 876 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),  | 
                                                        |
| 877 | - ),  | 
                                                        |
| 878 | - 'upcoming_status' => array(  | 
                                                        |
| 879 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,  | 
                                                        |
| 880 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),  | 
                                                        |
| 881 | - ),  | 
                                                        |
| 882 | - 'postponed_status' => array(  | 
                                                        |
| 883 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,  | 
                                                        |
| 884 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),  | 
                                                        |
| 885 | - ),  | 
                                                        |
| 886 | - 'cancelled_status' => array(  | 
                                                        |
| 887 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,  | 
                                                        |
| 888 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),  | 
                                                        |
| 889 | - ),  | 
                                                        |
| 890 | - 'expired_status' => array(  | 
                                                        |
| 891 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,  | 
                                                        |
| 892 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),  | 
                                                        |
| 893 | - ),  | 
                                                        |
| 894 | - 'inactive_status' => array(  | 
                                                        |
| 895 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,  | 
                                                        |
| 896 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),  | 
                                                        |
| 897 | - ),  | 
                                                        |
| 898 | - );  | 
                                                        |
| 899 | -        $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses); | 
                                                        |
| 900 | - return array_merge($items, $statuses);  | 
                                                        |
| 901 | - }  | 
                                                        |
| 902 | -  | 
                                                        |
| 903 | -  | 
                                                        |
| 904 | - /**  | 
                                                        |
| 905 | - * @return EEM_Event  | 
                                                        |
| 906 | - */  | 
                                                        |
| 907 | - private function _event_model()  | 
                                                        |
| 908 | -    { | 
                                                        |
| 909 | -        if (! $this->_event_model instanceof EEM_Event) { | 
                                                        |
| 910 | -            $this->_event_model = EE_Registry::instance()->load_model('Event'); | 
                                                        |
| 911 | - }  | 
                                                        |
| 912 | - return $this->_event_model;  | 
                                                        |
| 913 | - }  | 
                                                        |
| 914 | -  | 
                                                        |
| 915 | -  | 
                                                        |
| 916 | - /**  | 
                                                        |
| 917 | - * Adds extra buttons to the WP CPT permalink field row.  | 
                                                        |
| 918 | - * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.  | 
                                                        |
| 919 | - *  | 
                                                        |
| 920 | - * @param string $return the current html  | 
                                                        |
| 921 | - * @param int $id the post id for the page  | 
                                                        |
| 922 | - * @param string $new_title What the title is  | 
                                                        |
| 923 | - * @param string $new_slug what the slug is  | 
                                                        |
| 924 | - * @return string The new html string for the permalink area  | 
                                                        |
| 925 | - */  | 
                                                        |
| 926 | - public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)  | 
                                                        |
| 927 | -    { | 
                                                        |
| 928 | - // make sure this is only when editing  | 
                                                        |
| 929 | -        if (! empty($id)) { | 
                                                        |
| 930 | - $post = get_post($id);  | 
                                                        |
| 931 | - $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">'  | 
                                                        |
| 932 | -                       . esc_html__('Shortcode', 'event_espresso') | 
                                                        |
| 933 | - . '</a> ';  | 
                                                        |
| 934 | - $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='  | 
                                                        |
| 935 | - . $post->ID  | 
                                                        |
| 936 | - . ']">';  | 
                                                        |
| 937 | - }  | 
                                                        |
| 938 | - return $return;  | 
                                                        |
| 939 | - }  | 
                                                        |
| 940 | -  | 
                                                        |
| 941 | -  | 
                                                        |
| 942 | - /**  | 
                                                        |
| 943 | - * _events_overview_list_table  | 
                                                        |
| 944 | - * This contains the logic for showing the events_overview list  | 
                                                        |
| 945 | - *  | 
                                                        |
| 946 | - * @access protected  | 
                                                        |
| 947 | - * @return void  | 
                                                        |
| 948 | - * @throws \EE_Error  | 
                                                        |
| 949 | - */  | 
                                                        |
| 950 | - protected function _events_overview_list_table()  | 
                                                        |
| 951 | -    { | 
                                                        |
| 952 | -        do_action('AHEE_log', __FILE__, __FUNCTION__, ''); | 
                                                        |
| 953 | - $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table'])  | 
                                                        |
| 954 | - ? (array) $this->_template_args['after_list_table']  | 
                                                        |
| 955 | - : array();  | 
                                                        |
| 956 | - $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()  | 
                                                        |
| 957 | - . EEH_Template::get_button_or_link(  | 
                                                        |
| 958 | -                    get_post_type_archive_link('espresso_events'), | 
                                                        |
| 959 | -                    esc_html__("View Event Archive Page", "event_espresso"), | 
                                                        |
| 960 | - 'button'  | 
                                                        |
| 961 | - );  | 
                                                        |
| 962 | - $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());  | 
                                                        |
| 963 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(  | 
                                                        |
| 964 | - 'create_new',  | 
                                                        |
| 965 | - 'add',  | 
                                                        |
| 966 | - array(),  | 
                                                        |
| 967 | - 'add-new-h2'  | 
                                                        |
| 968 | - );  | 
                                                        |
| 969 | - $this->display_admin_list_table_page_with_no_sidebar();  | 
                                                        |
| 970 | - }  | 
                                                        |
| 971 | -  | 
                                                        |
| 972 | -  | 
                                                        |
| 973 | - /**  | 
                                                        |
| 974 | - * this allows for extra misc actions in the default WP publish box  | 
                                                        |
| 975 | - *  | 
                                                        |
| 976 | - * @return void  | 
                                                        |
| 977 | - */  | 
                                                        |
| 978 | - public function extra_misc_actions_publish_box()  | 
                                                        |
| 979 | -    { | 
                                                        |
| 980 | - $this->_generate_publish_box_extra_content();  | 
                                                        |
| 981 | - }  | 
                                                        |
| 982 | -  | 
                                                        |
| 983 | -  | 
                                                        |
| 984 | - /**  | 
                                                        |
| 985 | -     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been | 
                                                        |
| 986 | - * saved.  | 
                                                        |
| 987 | - * Typically you would use this to save any additional data.  | 
                                                        |
| 988 | - * Keep in mind also that "save_post" runs on EVERY post update to the database.  | 
                                                        |
| 989 | - * ALSO very important. When a post transitions from scheduled to published,  | 
                                                        |
| 990 | - * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from  | 
                                                        |
| 991 | - * other meta saves. So MAKE sure that you handle this accordingly.  | 
                                                        |
| 992 | - *  | 
                                                        |
| 993 | - * @access protected  | 
                                                        |
| 994 | - * @abstract  | 
                                                        |
| 995 | - * @param string $post_id The ID of the cpt that was saved (so you can link relationally)  | 
                                                        |
| 996 | - * @param object $post The post object of the cpt that was saved.  | 
                                                        |
| 997 | - * @return void  | 
                                                        |
| 998 | - * @throws \EE_Error  | 
                                                        |
| 999 | - */  | 
                                                        |
| 1000 | - protected function _insert_update_cpt_item($post_id, $post)  | 
                                                        |
| 1001 | -    { | 
                                                        |
| 1002 | -        if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') { | 
                                                        |
| 1003 | - // get out we're not processing an event save.  | 
                                                        |
| 1004 | - return;  | 
                                                        |
| 1005 | - }  | 
                                                        |
| 1006 | - $event_values = array(  | 
                                                        |
| 1007 | - 'EVT_display_desc' => ! empty($this->_req_data['display_desc']) ? 1 : 0,  | 
                                                        |
| 1008 | - 'EVT_display_ticket_selector' => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0,  | 
                                                        |
| 1009 | - 'EVT_additional_limit' => min(  | 
                                                        |
| 1010 | -                apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), | 
                                                        |
| 1011 | - ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null  | 
                                                        |
| 1012 | - ),  | 
                                                        |
| 1013 | - 'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status'])  | 
                                                        |
| 1014 | - ? $this->_req_data['EVT_default_registration_status']  | 
                                                        |
| 1015 | - : EE_Registry::instance()->CFG->registration->default_STS_ID,  | 
                                                        |
| 1016 | - 'EVT_member_only' => ! empty($this->_req_data['member_only']) ? 1 : 0,  | 
                                                        |
| 1017 | - 'EVT_allow_overflow' => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,  | 
                                                        |
| 1018 | - 'EVT_timezone_string' => ! empty($this->_req_data['timezone_string'])  | 
                                                        |
| 1019 | - ? $this->_req_data['timezone_string'] : null,  | 
                                                        |
| 1020 | - 'EVT_external_URL' => ! empty($this->_req_data['externalURL'])  | 
                                                        |
| 1021 | - ? $this->_req_data['externalURL'] : null,  | 
                                                        |
| 1022 | - 'EVT_phone' => ! empty($this->_req_data['event_phone'])  | 
                                                        |
| 1023 | - ? $this->_req_data['event_phone'] : null,  | 
                                                        |
| 1024 | - );  | 
                                                        |
| 1025 | - // update event  | 
                                                        |
| 1026 | - $success = $this->_event_model()->update_by_ID($event_values, $post_id);  | 
                                                        |
| 1027 | - // get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id!  | 
                                                        |
| 1028 | - $get_one_where = array(  | 
                                                        |
| 1029 | - $this->_event_model()->primary_key_name() => $post_id,  | 
                                                        |
| 1030 | - 'OR' => array(  | 
                                                        |
| 1031 | - 'status' => $post->post_status,  | 
                                                        |
| 1032 | - // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,  | 
                                                        |
| 1033 | - // but the returned object here has a status of "publish", so use the original post status as well  | 
                                                        |
| 1034 | - 'status*1' => $this->_req_data['original_post_status'],  | 
                                                        |
| 1035 | - ),  | 
                                                        |
| 1036 | - );  | 
                                                        |
| 1037 | - $event = $this->_event_model()->get_one(array($get_one_where));  | 
                                                        |
| 1038 | - // the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.  | 
                                                        |
| 1039 | - $event_update_callbacks = apply_filters(  | 
                                                        |
| 1040 | - 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',  | 
                                                        |
| 1041 | - array(  | 
                                                        |
| 1042 | - array($this, '_default_venue_update'),  | 
                                                        |
| 1043 | - array($this, '_default_tickets_update'),  | 
                                                        |
| 1044 | - )  | 
                                                        |
| 1045 | - );  | 
                                                        |
| 1046 | - $att_success = true;  | 
                                                        |
| 1047 | -        foreach ($event_update_callbacks as $e_callback) { | 
                                                        |
| 1048 | - $_success = is_callable($e_callback)  | 
                                                        |
| 1049 | - ? call_user_func($e_callback, $event, $this->_req_data)  | 
                                                        |
| 1050 | - : false;  | 
                                                        |
| 1051 | - // if ANY of these updates fail then we want the appropriate global error message  | 
                                                        |
| 1052 | - $att_success = ! $att_success ? $att_success : $_success;  | 
                                                        |
| 1053 | - }  | 
                                                        |
| 1054 | - // any errors?  | 
                                                        |
| 1055 | -        if ($success && false === $att_success) { | 
                                                        |
| 1056 | - EE_Error::add_error(  | 
                                                        |
| 1057 | - esc_html__(  | 
                                                        |
| 1058 | - 'Event Details saved successfully but something went wrong with saving attachments.',  | 
                                                        |
| 1059 | - 'event_espresso'  | 
                                                        |
| 1060 | - ),  | 
                                                        |
| 1061 | - __FILE__,  | 
                                                        |
| 1062 | - __FUNCTION__,  | 
                                                        |
| 1063 | - __LINE__  | 
                                                        |
| 1064 | - );  | 
                                                        |
| 1065 | -        } elseif ($success === false) { | 
                                                        |
| 1066 | - EE_Error::add_error(  | 
                                                        |
| 1067 | -                esc_html__('Event Details did not save successfully.', 'event_espresso'), | 
                                                        |
| 1068 | - __FILE__,  | 
                                                        |
| 1069 | - __FUNCTION__,  | 
                                                        |
| 1070 | - __LINE__  | 
                                                        |
| 1071 | - );  | 
                                                        |
| 1072 | - }  | 
                                                        |
| 1073 | - }  | 
                                                        |
| 1074 | -  | 
                                                        |
| 1075 | -  | 
                                                        |
| 1076 | - /**  | 
                                                        |
| 1077 | - * @see parent::restore_item()  | 
                                                        |
| 1078 | - * @param int $post_id  | 
                                                        |
| 1079 | - * @param int $revision_id  | 
                                                        |
| 1080 | - */  | 
                                                        |
| 1081 | - protected function _restore_cpt_item($post_id, $revision_id)  | 
                                                        |
| 1082 | -    { | 
                                                        |
| 1083 | - // copy existing event meta to new post  | 
                                                        |
| 1084 | - $post_evt = $this->_event_model()->get_one_by_ID($post_id);  | 
                                                        |
| 1085 | -        if ($post_evt instanceof EE_Event) { | 
                                                        |
| 1086 | - // meta revision restore  | 
                                                        |
| 1087 | - $post_evt->restore_revision($revision_id);  | 
                                                        |
| 1088 | - // related objs restore  | 
                                                        |
| 1089 | -            $post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price')); | 
                                                        |
| 1090 | - }  | 
                                                        |
| 1091 | - }  | 
                                                        |
| 1092 | -  | 
                                                        |
| 1093 | -  | 
                                                        |
| 1094 | - /**  | 
                                                        |
| 1095 | - * Attach the venue to the Event  | 
                                                        |
| 1096 | - *  | 
                                                        |
| 1097 | - * @param \EE_Event $evtobj Event Object to add the venue to  | 
                                                        |
| 1098 | - * @param array $data The request data from the form  | 
                                                        |
| 1099 | - * @return bool Success or fail.  | 
                                                        |
| 1100 | - */  | 
                                                        |
| 1101 | - protected function _default_venue_update(\EE_Event $evtobj, $data)  | 
                                                        |
| 1102 | -    { | 
                                                        |
| 1103 | - require_once(EE_MODELS . 'EEM_Venue.model.php');  | 
                                                        |
| 1104 | -        $venue_model = EE_Registry::instance()->load_model('Venue'); | 
                                                        |
| 1105 | - $rows_affected = null;  | 
                                                        |
| 1106 | - $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;  | 
                                                        |
| 1107 | - // very important. If we don't have a venue name...  | 
                                                        |
| 1108 | - // then we'll get out because not necessary to create empty venue  | 
                                                        |
| 1109 | -        if (empty($data['venue_title'])) { | 
                                                        |
| 1110 | - return false;  | 
                                                        |
| 1111 | - }  | 
                                                        |
| 1112 | - $venue_array = array(  | 
                                                        |
| 1113 | -            'VNU_wp_user'         => $evtobj->get('EVT_wp_user'), | 
                                                        |
| 1114 | - 'VNU_name' => ! empty($data['venue_title']) ? $data['venue_title'] : null,  | 
                                                        |
| 1115 | - 'VNU_desc' => ! empty($data['venue_description']) ? $data['venue_description'] : null,  | 
                                                        |
| 1116 | - 'VNU_identifier' => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,  | 
                                                        |
| 1117 | - 'VNU_short_desc' => ! empty($data['venue_short_description']) ? $data['venue_short_description']  | 
                                                        |
| 1118 | - : null,  | 
                                                        |
| 1119 | - 'VNU_address' => ! empty($data['address']) ? $data['address'] : null,  | 
                                                        |
| 1120 | - 'VNU_address2' => ! empty($data['address2']) ? $data['address2'] : null,  | 
                                                        |
| 1121 | - 'VNU_city' => ! empty($data['city']) ? $data['city'] : null,  | 
                                                        |
| 1122 | - 'STA_ID' => ! empty($data['state']) ? $data['state'] : null,  | 
                                                        |
| 1123 | - 'CNT_ISO' => ! empty($data['countries']) ? $data['countries'] : null,  | 
                                                        |
| 1124 | - 'VNU_zip' => ! empty($data['zip']) ? $data['zip'] : null,  | 
                                                        |
| 1125 | - 'VNU_phone' => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,  | 
                                                        |
| 1126 | - 'VNU_capacity' => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,  | 
                                                        |
| 1127 | - 'VNU_url' => ! empty($data['venue_url']) ? $data['venue_url'] : null,  | 
                                                        |
| 1128 | - 'VNU_virtual_phone' => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,  | 
                                                        |
| 1129 | - 'VNU_virtual_url' => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,  | 
                                                        |
| 1130 | - 'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,  | 
                                                        |
| 1131 | - 'status' => 'publish',  | 
                                                        |
| 1132 | - );  | 
                                                        |
| 1133 | - // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.  | 
                                                        |
| 1134 | -        if (! empty($venue_id)) { | 
                                                        |
| 1135 | - $update_where = array($venue_model->primary_key_name() => $venue_id);  | 
                                                        |
| 1136 | - $rows_affected = $venue_model->update($venue_array, array($update_where));  | 
                                                        |
| 1137 | - // we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.  | 
                                                        |
| 1138 | - $evtobj->_add_relation_to($venue_id, 'Venue');  | 
                                                        |
| 1139 | - return $rows_affected > 0 ? true : false;  | 
                                                        |
| 1140 | -        } else { | 
                                                        |
| 1141 | - // we insert the venue  | 
                                                        |
| 1142 | - $venue_id = $venue_model->insert($venue_array);  | 
                                                        |
| 1143 | - $evtobj->_add_relation_to($venue_id, 'Venue');  | 
                                                        |
| 1144 | - return ! empty($venue_id) ? true : false;  | 
                                                        |
| 1145 | - }  | 
                                                        |
| 1146 | - // when we have the ancestor come in it's already been handled by the revision save.  | 
                                                        |
| 1147 | - }  | 
                                                        |
| 1148 | -  | 
                                                        |
| 1149 | -  | 
                                                        |
| 1150 | - /**  | 
                                                        |
| 1151 | - * Handles saving everything related to Tickets (datetimes, tickets, prices)  | 
                                                        |
| 1152 | - *  | 
                                                        |
| 1153 | - * @param EE_Event $evtobj The Event object we're attaching data to  | 
                                                        |
| 1154 | - * @param array $data The request data from the form  | 
                                                        |
| 1155 | - * @return array  | 
                                                        |
| 1156 | - */  | 
                                                        |
| 1157 | - protected function _default_tickets_update(EE_Event $evtobj, $data)  | 
                                                        |
| 1158 | -    { | 
                                                        |
| 1159 | - $success = true;  | 
                                                        |
| 1160 | - $saved_dtt = null;  | 
                                                        |
| 1161 | - $saved_tickets = array();  | 
                                                        |
| 1162 | -        $incoming_date_formats = array('Y-m-d', 'h:i a'); | 
                                                        |
| 1163 | -        foreach ($data['edit_event_datetimes'] as $row => $dtt) { | 
                                                        |
| 1164 | - // trim all values to ensure any excess whitespace is removed.  | 
                                                        |
| 1165 | -            $dtt = array_map('trim', $dtt); | 
                                                        |
| 1166 | - $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']  | 
                                                        |
| 1167 | - : $dtt['DTT_EVT_start'];  | 
                                                        |
| 1168 | - $datetime_values = array(  | 
                                                        |
| 1169 | - 'DTT_ID' => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,  | 
                                                        |
| 1170 | - 'DTT_EVT_start' => $dtt['DTT_EVT_start'],  | 
                                                        |
| 1171 | - 'DTT_EVT_end' => $dtt['DTT_EVT_end'],  | 
                                                        |
| 1172 | - 'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],  | 
                                                        |
| 1173 | - 'DTT_order' => $row,  | 
                                                        |
| 1174 | - );  | 
                                                        |
| 1175 | - // if we have an id then let's get existing object first and then set the new values. Otherwise we instantiate a new object for save.  | 
                                                        |
| 1176 | -            if (! empty($dtt['DTT_ID'])) { | 
                                                        |
| 1177 | - $DTM = EE_Registry::instance()  | 
                                                        |
| 1178 | -                                  ->load_model('Datetime', array($evtobj->get_timezone())) | 
                                                        |
| 1179 | - ->get_one_by_ID($dtt['DTT_ID']);  | 
                                                        |
| 1180 | - $DTM->set_date_format($incoming_date_formats[0]);  | 
                                                        |
| 1181 | - $DTM->set_time_format($incoming_date_formats[1]);  | 
                                                        |
| 1182 | -                foreach ($datetime_values as $field => $value) { | 
                                                        |
| 1183 | - $DTM->set($field, $value);  | 
                                                        |
| 1184 | - }  | 
                                                        |
| 1185 | - // make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it. We need to do this so we dont' TRASH the parent DTT.  | 
                                                        |
| 1186 | - $saved_dtts[ $DTM->ID() ] = $DTM;  | 
                                                        |
| 1187 | -            } else { | 
                                                        |
| 1188 | - $DTM = EE_Registry::instance()->load_class(  | 
                                                        |
| 1189 | - 'Datetime',  | 
                                                        |
| 1190 | - array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats),  | 
                                                        |
| 1191 | - false,  | 
                                                        |
| 1192 | - false  | 
                                                        |
| 1193 | - );  | 
                                                        |
| 1194 | -                foreach ($datetime_values as $field => $value) { | 
                                                        |
| 1195 | - $DTM->set($field, $value);  | 
                                                        |
| 1196 | - }  | 
                                                        |
| 1197 | - }  | 
                                                        |
| 1198 | - $DTM->save();  | 
                                                        |
| 1199 | - $DTT = $evtobj->_add_relation_to($DTM, 'Datetime');  | 
                                                        |
| 1200 | - // load DTT helper  | 
                                                        |
| 1201 | - // before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.  | 
                                                        |
| 1202 | -            if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) { | 
                                                        |
| 1203 | -                $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start')); | 
                                                        |
| 1204 | - $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');  | 
                                                        |
| 1205 | - $DTT->save();  | 
                                                        |
| 1206 | - }  | 
                                                        |
| 1207 | - // now we got to make sure we add the new DTT_ID to the $saved_dtts array because it is possible there was a new one created for the autosave.  | 
                                                        |
| 1208 | - $saved_dtt = $DTT;  | 
                                                        |
| 1209 | - $success = ! $success ? $success : $DTT;  | 
                                                        |
| 1210 | - // if ANY of these updates fail then we want the appropriate global error message.  | 
                                                        |
| 1211 | - // //todo this is actually sucky we need a better error message but this is what it is for now.  | 
                                                        |
| 1212 | - }  | 
                                                        |
| 1213 | - // no dtts get deleted so we don't do any of that logic here.  | 
                                                        |
| 1214 | - // update tickets next  | 
                                                        |
| 1215 | -        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); | 
                                                        |
| 1216 | -        foreach ($data['edit_tickets'] as $row => $tkt) { | 
                                                        |
| 1217 | -            $incoming_date_formats = array('Y-m-d', 'h:i a'); | 
                                                        |
| 1218 | - $update_prices = false;  | 
                                                        |
| 1219 | - $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount'])  | 
                                                        |
| 1220 | - ? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0;  | 
                                                        |
| 1221 | - // trim inputs to ensure any excess whitespace is removed.  | 
                                                        |
| 1222 | -            $tkt = array_map('trim', $tkt); | 
                                                        |
| 1223 | -            if (empty($tkt['TKT_start_date'])) { | 
                                                        |
| 1224 | - // let's use now in the set timezone.  | 
                                                        |
| 1225 | -                $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); | 
                                                        |
| 1226 | - $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);  | 
                                                        |
| 1227 | - }  | 
                                                        |
| 1228 | -            if (empty($tkt['TKT_end_date'])) { | 
                                                        |
| 1229 | - // use the start date of the first datetime  | 
                                                        |
| 1230 | - $dtt = $evtobj->first_datetime();  | 
                                                        |
| 1231 | - $tkt['TKT_end_date'] = $dtt->start_date_and_time(  | 
                                                        |
| 1232 | - $incoming_date_formats[0],  | 
                                                        |
| 1233 | - $incoming_date_formats[1]  | 
                                                        |
| 1234 | - );  | 
                                                        |
| 1235 | - }  | 
                                                        |
| 1236 | - $TKT_values = array(  | 
                                                        |
| 1237 | - 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,  | 
                                                        |
| 1238 | - 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,  | 
                                                        |
| 1239 | - 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',  | 
                                                        |
| 1240 | - 'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',  | 
                                                        |
| 1241 | - 'TKT_start_date' => $tkt['TKT_start_date'],  | 
                                                        |
| 1242 | - 'TKT_end_date' => $tkt['TKT_end_date'],  | 
                                                        |
| 1243 | - 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],  | 
                                                        |
| 1244 | - 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],  | 
                                                        |
| 1245 | - 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],  | 
                                                        |
| 1246 | - 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],  | 
                                                        |
| 1247 | - 'TKT_row' => $row,  | 
                                                        |
| 1248 | - 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,  | 
                                                        |
| 1249 | - 'TKT_price' => $ticket_price,  | 
                                                        |
| 1250 | - );  | 
                                                        |
| 1251 | - // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well.  | 
                                                        |
| 1252 | -            if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { | 
                                                        |
| 1253 | - $TKT_values['TKT_ID'] = 0;  | 
                                                        |
| 1254 | - $TKT_values['TKT_is_default'] = 0;  | 
                                                        |
| 1255 | - $TKT_values['TKT_price'] = $ticket_price;  | 
                                                        |
| 1256 | - $update_prices = true;  | 
                                                        |
| 1257 | - }  | 
                                                        |
| 1258 | - // if we have a TKT_ID then we need to get that existing TKT_obj and update it  | 
                                                        |
| 1259 | - // we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.  | 
                                                        |
| 1260 | - // keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived.  | 
                                                        |
| 1261 | -            if (! empty($tkt['TKT_ID'])) { | 
                                                        |
| 1262 | - $TKT = EE_Registry::instance()  | 
                                                        |
| 1263 | -                                  ->load_model('Ticket', array($evtobj->get_timezone())) | 
                                                        |
| 1264 | - ->get_one_by_ID($tkt['TKT_ID']);  | 
                                                        |
| 1265 | -                if ($TKT instanceof EE_Ticket) { | 
                                                        |
| 1266 | - $ticket_sold = $TKT->count_related(  | 
                                                        |
| 1267 | - 'Registration',  | 
                                                        |
| 1268 | - array(  | 
                                                        |
| 1269 | - array(  | 
                                                        |
| 1270 | - 'STS_ID' => array(  | 
                                                        |
| 1271 | - 'NOT IN',  | 
                                                        |
| 1272 | - array(EEM_Registration::status_id_incomplete),  | 
                                                        |
| 1273 | - ),  | 
                                                        |
| 1274 | - ),  | 
                                                        |
| 1275 | - )  | 
                                                        |
| 1276 | - ) > 0 ? true : false;  | 
                                                        |
| 1277 | - // let's just check the total price for the existing ticket and determine if it matches the new total price. if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket.  | 
                                                        |
| 1278 | -                    $create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price') | 
                                                        |
| 1279 | -                                      && ! $TKT->get('TKT_deleted'); | 
                                                        |
| 1280 | - $TKT->set_date_format($incoming_date_formats[0]);  | 
                                                        |
| 1281 | - $TKT->set_time_format($incoming_date_formats[1]);  | 
                                                        |
| 1282 | - // set new values  | 
                                                        |
| 1283 | -                    foreach ($TKT_values as $field => $value) { | 
                                                        |
| 1284 | -                        if ($field == 'TKT_qty') { | 
                                                        |
| 1285 | - $TKT->set_qty($value);  | 
                                                        |
| 1286 | -                        } else { | 
                                                        |
| 1287 | - $TKT->set($field, $value);  | 
                                                        |
| 1288 | - }  | 
                                                        |
| 1289 | - }  | 
                                                        |
| 1290 | - // if $create_new_TKT is false then we can safely update the existing ticket. Otherwise we have to create a new ticket.  | 
                                                        |
| 1291 | -                    if ($create_new_TKT) { | 
                                                        |
| 1292 | - // archive the old ticket first  | 
                                                        |
| 1293 | -                        $TKT->set('TKT_deleted', 1); | 
                                                        |
| 1294 | - $TKT->save();  | 
                                                        |
| 1295 | - // make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.  | 
                                                        |
| 1296 | - $saved_tickets[ $TKT->ID() ] = $TKT;  | 
                                                        |
| 1297 | - // create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it.  | 
                                                        |
| 1298 | - $TKT = clone $TKT;  | 
                                                        |
| 1299 | -                        $TKT->set('TKT_ID', 0); | 
                                                        |
| 1300 | -                        $TKT->set('TKT_deleted', 0); | 
                                                        |
| 1301 | -                        $TKT->set('TKT_price', $ticket_price); | 
                                                        |
| 1302 | -                        $TKT->set('TKT_sold', 0); | 
                                                        |
| 1303 | - // now we need to make sure that $new prices are created as well and attached to new ticket.  | 
                                                        |
| 1304 | - $update_prices = true;  | 
                                                        |
| 1305 | - }  | 
                                                        |
| 1306 | - // make sure price is set if it hasn't been already  | 
                                                        |
| 1307 | -                    $TKT->set('TKT_price', $ticket_price); | 
                                                        |
| 1308 | - }  | 
                                                        |
| 1309 | -            } else { | 
                                                        |
| 1310 | - // no TKT_id so a new TKT  | 
                                                        |
| 1311 | - $TKT_values['TKT_price'] = $ticket_price;  | 
                                                        |
| 1312 | -                $TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false); | 
                                                        |
| 1313 | -                if ($TKT instanceof EE_Ticket) { | 
                                                        |
| 1314 | - // need to reset values to properly account for the date formats  | 
                                                        |
| 1315 | - $TKT->set_date_format($incoming_date_formats[0]);  | 
                                                        |
| 1316 | - $TKT->set_time_format($incoming_date_formats[1]);  | 
                                                        |
| 1317 | - $TKT->set_timezone($evtobj->get_timezone());  | 
                                                        |
| 1318 | - // set new values  | 
                                                        |
| 1319 | -                    foreach ($TKT_values as $field => $value) { | 
                                                        |
| 1320 | -                        if ($field == 'TKT_qty') { | 
                                                        |
| 1321 | - $TKT->set_qty($value);  | 
                                                        |
| 1322 | -                        } else { | 
                                                        |
| 1323 | - $TKT->set($field, $value);  | 
                                                        |
| 1324 | - }  | 
                                                        |
| 1325 | - }  | 
                                                        |
| 1326 | - $update_prices = true;  | 
                                                        |
| 1327 | - }  | 
                                                        |
| 1328 | - }  | 
                                                        |
| 1329 | - // cap ticket qty by datetime reg limits  | 
                                                        |
| 1330 | -            $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit'))); | 
                                                        |
| 1331 | - // update ticket.  | 
                                                        |
| 1332 | - $TKT->save();  | 
                                                        |
| 1333 | - // before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.  | 
                                                        |
| 1334 | -            if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) { | 
                                                        |
| 1335 | -                $TKT->set('TKT_end_date', $TKT->get('TKT_start_date')); | 
                                                        |
| 1336 | - $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');  | 
                                                        |
| 1337 | - $TKT->save();  | 
                                                        |
| 1338 | - }  | 
                                                        |
| 1339 | - // initially let's add the ticket to the dtt  | 
                                                        |
| 1340 | - $saved_dtt->_add_relation_to($TKT, 'Ticket');  | 
                                                        |
| 1341 | - $saved_tickets[ $TKT->ID() ] = $TKT;  | 
                                                        |
| 1342 | - // add prices to ticket  | 
                                                        |
| 1343 | - $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices);  | 
                                                        |
| 1344 | - }  | 
                                                        |
| 1345 | - // however now we need to handle permanently deleting tickets via the ui. Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db.  | 
                                                        |
| 1346 | - $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;  | 
                                                        |
| 1347 | - $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));  | 
                                                        |
| 1348 | -        foreach ($tickets_removed as $id) { | 
                                                        |
| 1349 | - $id = absint($id);  | 
                                                        |
| 1350 | - // get the ticket for this id  | 
                                                        |
| 1351 | -            $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); | 
                                                        |
| 1352 | - // need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold)  | 
                                                        |
| 1353 | -            $dtts = $tkt_to_remove->get_many_related('Datetime'); | 
                                                        |
| 1354 | -            foreach ($dtts as $dtt) { | 
                                                        |
| 1355 | - $tkt_to_remove->_remove_relation_to($dtt, 'Datetime');  | 
                                                        |
| 1356 | - }  | 
                                                        |
| 1357 | - // need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))  | 
                                                        |
| 1358 | -            $tkt_to_remove->delete_related_permanently('Price'); | 
                                                        |
| 1359 | - // finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)  | 
                                                        |
| 1360 | - $tkt_to_remove->delete_permanently();  | 
                                                        |
| 1361 | - }  | 
                                                        |
| 1362 | - return array($saved_dtt, $saved_tickets);  | 
                                                        |
| 1363 | - }  | 
                                                        |
| 1364 | -  | 
                                                        |
| 1365 | -  | 
                                                        |
| 1366 | - /**  | 
                                                        |
| 1367 | - * This attaches a list of given prices to a ticket.  | 
                                                        |
| 1368 | - * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change  | 
                                                        |
| 1369 | - * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old  | 
                                                        |
| 1370 | - * price info and prices are automatically "archived" via the ticket.  | 
                                                        |
| 1371 | - *  | 
                                                        |
| 1372 | - * @access private  | 
                                                        |
| 1373 | - * @param array $prices Array of prices from the form.  | 
                                                        |
| 1374 | - * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to.  | 
                                                        |
| 1375 | - * @param bool $new_prices Whether attach existing incoming prices or create new ones.  | 
                                                        |
| 1376 | - * @return void  | 
                                                        |
| 1377 | - */  | 
                                                        |
| 1378 | - private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)  | 
                                                        |
| 1379 | -    { | 
                                                        |
| 1380 | -        foreach ($prices as $row => $prc) { | 
                                                        |
| 1381 | - $PRC_values = array(  | 
                                                        |
| 1382 | - 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,  | 
                                                        |
| 1383 | - 'PRT_ID' => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,  | 
                                                        |
| 1384 | - 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,  | 
                                                        |
| 1385 | - 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',  | 
                                                        |
| 1386 | - 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',  | 
                                                        |
| 1387 | - 'PRC_is_default' => 0, // make sure prices are NOT set as default from this context  | 
                                                        |
| 1388 | - 'PRC_order' => $row,  | 
                                                        |
| 1389 | - );  | 
                                                        |
| 1390 | -            if ($new_prices || empty($PRC_values['PRC_ID'])) { | 
                                                        |
| 1391 | - $PRC_values['PRC_ID'] = 0;  | 
                                                        |
| 1392 | -                $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false); | 
                                                        |
| 1393 | -            } else { | 
                                                        |
| 1394 | -                $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); | 
                                                        |
| 1395 | - // update this price with new values  | 
                                                        |
| 1396 | -                foreach ($PRC_values as $field => $newprc) { | 
                                                        |
| 1397 | - $PRC->set($field, $newprc);  | 
                                                        |
| 1398 | - }  | 
                                                        |
| 1399 | - $PRC->save();  | 
                                                        |
| 1400 | - }  | 
                                                        |
| 1401 | - $ticket->_add_relation_to($PRC, 'Price');  | 
                                                        |
| 1402 | - }  | 
                                                        |
| 1403 | - }  | 
                                                        |
| 1404 | -  | 
                                                        |
| 1405 | -  | 
                                                        |
| 1406 | - /**  | 
                                                        |
| 1407 | - * Add in our autosave ajax handlers  | 
                                                        |
| 1408 | - *  | 
                                                        |
| 1409 | - */  | 
                                                        |
| 1410 | - protected function _ee_autosave_create_new()  | 
                                                        |
| 1411 | -    { | 
                                                        |
| 1412 | - }  | 
                                                        |
| 1413 | -  | 
                                                        |
| 1414 | -  | 
                                                        |
| 1415 | - /**  | 
                                                        |
| 1416 | - * More autosave handlers.  | 
                                                        |
| 1417 | - */  | 
                                                        |
| 1418 | - protected function _ee_autosave_edit()  | 
                                                        |
| 1419 | -    { | 
                                                        |
| 1420 | - return; // TEMPORARILY EXITING CAUSE THIS IS A TODO  | 
                                                        |
| 1421 | - }  | 
                                                        |
| 1422 | -  | 
                                                        |
| 1423 | -  | 
                                                        |
| 1424 | - /**  | 
                                                        |
| 1425 | - * _generate_publish_box_extra_content  | 
                                                        |
| 1426 | - */  | 
                                                        |
| 1427 | - private function _generate_publish_box_extra_content()  | 
                                                        |
| 1428 | -    { | 
                                                        |
| 1429 | - // load formatter helper  | 
                                                        |
| 1430 | - // args for getting related registrations  | 
                                                        |
| 1431 | - $approved_query_args = array(  | 
                                                        |
| 1432 | - array(  | 
                                                        |
| 1433 | - 'REG_deleted' => 0,  | 
                                                        |
| 1434 | - 'STS_ID' => EEM_Registration::status_id_approved,  | 
                                                        |
| 1435 | - ),  | 
                                                        |
| 1436 | - );  | 
                                                        |
| 1437 | - $not_approved_query_args = array(  | 
                                                        |
| 1438 | - array(  | 
                                                        |
| 1439 | - 'REG_deleted' => 0,  | 
                                                        |
| 1440 | - 'STS_ID' => EEM_Registration::status_id_not_approved,  | 
                                                        |
| 1441 | - ),  | 
                                                        |
| 1442 | - );  | 
                                                        |
| 1443 | - $pending_payment_query_args = array(  | 
                                                        |
| 1444 | - array(  | 
                                                        |
| 1445 | - 'REG_deleted' => 0,  | 
                                                        |
| 1446 | - 'STS_ID' => EEM_Registration::status_id_pending_payment,  | 
                                                        |
| 1447 | - ),  | 
                                                        |
| 1448 | - );  | 
                                                        |
| 1449 | - // publish box  | 
                                                        |
| 1450 | - $publish_box_extra_args = array(  | 
                                                        |
| 1451 | - 'view_approved_reg_url' => add_query_arg(  | 
                                                        |
| 1452 | - array(  | 
                                                        |
| 1453 | - 'action' => 'default',  | 
                                                        |
| 1454 | - 'event_id' => $this->_cpt_model_obj->ID(),  | 
                                                        |
| 1455 | - '_reg_status' => EEM_Registration::status_id_approved,  | 
                                                        |
| 1456 | - ),  | 
                                                        |
| 1457 | - REG_ADMIN_URL  | 
                                                        |
| 1458 | - ),  | 
                                                        |
| 1459 | - 'view_not_approved_reg_url' => add_query_arg(  | 
                                                        |
| 1460 | - array(  | 
                                                        |
| 1461 | - 'action' => 'default',  | 
                                                        |
| 1462 | - 'event_id' => $this->_cpt_model_obj->ID(),  | 
                                                        |
| 1463 | - '_reg_status' => EEM_Registration::status_id_not_approved,  | 
                                                        |
| 1464 | - ),  | 
                                                        |
| 1465 | - REG_ADMIN_URL  | 
                                                        |
| 1466 | - ),  | 
                                                        |
| 1467 | - 'view_pending_payment_reg_url' => add_query_arg(  | 
                                                        |
| 1468 | - array(  | 
                                                        |
| 1469 | - 'action' => 'default',  | 
                                                        |
| 1470 | - 'event_id' => $this->_cpt_model_obj->ID(),  | 
                                                        |
| 1471 | - '_reg_status' => EEM_Registration::status_id_pending_payment,  | 
                                                        |
| 1472 | - ),  | 
                                                        |
| 1473 | - REG_ADMIN_URL  | 
                                                        |
| 1474 | - ),  | 
                                                        |
| 1475 | - 'approved_regs' => $this->_cpt_model_obj->count_related(  | 
                                                        |
| 1476 | - 'Registration',  | 
                                                        |
| 1477 | - $approved_query_args  | 
                                                        |
| 1478 | - ),  | 
                                                        |
| 1479 | - 'not_approved_regs' => $this->_cpt_model_obj->count_related(  | 
                                                        |
| 1480 | - 'Registration',  | 
                                                        |
| 1481 | - $not_approved_query_args  | 
                                                        |
| 1482 | - ),  | 
                                                        |
| 1483 | - 'pending_payment_regs' => $this->_cpt_model_obj->count_related(  | 
                                                        |
| 1484 | - 'Registration',  | 
                                                        |
| 1485 | - $pending_payment_query_args  | 
                                                        |
| 1486 | - ),  | 
                                                        |
| 1487 | - 'misc_pub_section_class' => apply_filters(  | 
                                                        |
| 1488 | - 'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',  | 
                                                        |
| 1489 | - 'misc-pub-section'  | 
                                                        |
| 1490 | - ),  | 
                                                        |
| 1491 | - );  | 
                                                        |
| 1492 | - ob_start();  | 
                                                        |
| 1493 | - do_action(  | 
                                                        |
| 1494 | - 'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',  | 
                                                        |
| 1495 | - $this->_cpt_model_obj  | 
                                                        |
| 1496 | - );  | 
                                                        |
| 1497 | - $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();  | 
                                                        |
| 1498 | - // load template  | 
                                                        |
| 1499 | - EEH_Template::display_template(  | 
                                                        |
| 1500 | - EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',  | 
                                                        |
| 1501 | - $publish_box_extra_args  | 
                                                        |
| 1502 | - );  | 
                                                        |
| 1503 | - }  | 
                                                        |
| 1504 | -  | 
                                                        |
| 1505 | -  | 
                                                        |
| 1506 | - /**  | 
                                                        |
| 1507 | - * @return EE_Event  | 
                                                        |
| 1508 | - */  | 
                                                        |
| 1509 | - public function get_event_object()  | 
                                                        |
| 1510 | -    { | 
                                                        |
| 1511 | - return $this->_cpt_model_obj;  | 
                                                        |
| 1512 | - }  | 
                                                        |
| 1513 | -  | 
                                                        |
| 1514 | -  | 
                                                        |
| 1515 | -  | 
                                                        |
| 1516 | -  | 
                                                        |
| 1517 | - /** METABOXES * */  | 
                                                        |
| 1518 | - /**  | 
                                                        |
| 1519 | - * _register_event_editor_meta_boxes  | 
                                                        |
| 1520 | - * add all metaboxes related to the event_editor  | 
                                                        |
| 1521 | - *  | 
                                                        |
| 1522 | - * @return void  | 
                                                        |
| 1523 | - */  | 
                                                        |
| 1524 | - protected function _register_event_editor_meta_boxes()  | 
                                                        |
| 1525 | -    { | 
                                                        |
| 1526 | - $this->verify_cpt_object();  | 
                                                        |
| 1527 | - add_meta_box(  | 
                                                        |
| 1528 | - 'espresso_event_editor_tickets',  | 
                                                        |
| 1529 | -            esc_html__('Event Datetime & Ticket', 'event_espresso'), | 
                                                        |
| 1530 | - array($this, 'ticket_metabox'),  | 
                                                        |
| 1531 | - $this->page_slug,  | 
                                                        |
| 1532 | - 'normal',  | 
                                                        |
| 1533 | - 'high'  | 
                                                        |
| 1534 | - );  | 
                                                        |
| 1535 | - add_meta_box(  | 
                                                        |
| 1536 | - 'espresso_event_editor_event_options',  | 
                                                        |
| 1537 | -            esc_html__('Event Registration Options', 'event_espresso'), | 
                                                        |
| 1538 | - array($this, 'registration_options_meta_box'),  | 
                                                        |
| 1539 | - $this->page_slug,  | 
                                                        |
| 1540 | - 'side',  | 
                                                        |
| 1541 | - 'default'  | 
                                                        |
| 1542 | - );  | 
                                                        |
| 1543 | - // NOTE: if you're looking for other metaboxes in here,  | 
                                                        |
| 1544 | - // where a metabox has a related management page in the admin  | 
                                                        |
| 1545 | - // you will find it setup in the related management page's "_Hooks" file.  | 
                                                        |
| 1546 | - // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".  | 
                                                        |
| 1547 | - }  | 
                                                        |
| 1548 | -  | 
                                                        |
| 1549 | -  | 
                                                        |
| 1550 | - /**  | 
                                                        |
| 1551 | - * @throws DomainException  | 
                                                        |
| 1552 | - * @throws EE_Error  | 
                                                        |
| 1553 | - */  | 
                                                        |
| 1554 | - public function ticket_metabox()  | 
                                                        |
| 1555 | -    { | 
                                                        |
| 1556 | - $existing_datetime_ids = $existing_ticket_ids = array();  | 
                                                        |
| 1557 | - // defaults for template args  | 
                                                        |
| 1558 | - $template_args = array(  | 
                                                        |
| 1559 | - 'existing_datetime_ids' => '',  | 
                                                        |
| 1560 | - 'event_datetime_help_link' => '',  | 
                                                        |
| 1561 | - 'ticket_options_help_link' => '',  | 
                                                        |
| 1562 | - 'time' => null,  | 
                                                        |
| 1563 | - 'ticket_rows' => '',  | 
                                                        |
| 1564 | - 'existing_ticket_ids' => '',  | 
                                                        |
| 1565 | - 'total_ticket_rows' => 1,  | 
                                                        |
| 1566 | - 'ticket_js_structure' => '',  | 
                                                        |
| 1567 | - 'trash_icon' => 'ee-lock-icon',  | 
                                                        |
| 1568 | - 'disabled' => '',  | 
                                                        |
| 1569 | - );  | 
                                                        |
| 1570 | - $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;  | 
                                                        |
| 1571 | -        do_action('AHEE_log', __FILE__, __FUNCTION__, ''); | 
                                                        |
| 1572 | - /**  | 
                                                        |
| 1573 | - * 1. Start with retrieving Datetimes  | 
                                                        |
| 1574 | - * 2. Fore each datetime get related tickets  | 
                                                        |
| 1575 | - * 3. For each ticket get related prices  | 
                                                        |
| 1576 | - */  | 
                                                        |
| 1577 | -        $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id); | 
                                                        |
| 1578 | - /** @type EE_Datetime $first_datetime */  | 
                                                        |
| 1579 | - $first_datetime = reset($times);  | 
                                                        |
| 1580 | - // do we get related tickets?  | 
                                                        |
| 1581 | - if ($first_datetime instanceof EE_Datetime  | 
                                                        |
| 1582 | - && $first_datetime->ID() !== 0  | 
                                                        |
| 1583 | -        ) { | 
                                                        |
| 1584 | -            $existing_datetime_ids[] = $first_datetime->get('DTT_ID'); | 
                                                        |
| 1585 | - $template_args['time'] = $first_datetime;  | 
                                                        |
| 1586 | - $related_tickets = $first_datetime->tickets(  | 
                                                        |
| 1587 | - array(  | 
                                                        |
| 1588 | -                    array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)), | 
                                                        |
| 1589 | - 'default_where_conditions' => 'none',  | 
                                                        |
| 1590 | - )  | 
                                                        |
| 1591 | - );  | 
                                                        |
| 1592 | -            if (! empty($related_tickets)) { | 
                                                        |
| 1593 | - $template_args['total_ticket_rows'] = count($related_tickets);  | 
                                                        |
| 1594 | - $row = 0;  | 
                                                        |
| 1595 | -                foreach ($related_tickets as $ticket) { | 
                                                        |
| 1596 | -                    $existing_ticket_ids[] = $ticket->get('TKT_ID'); | 
                                                        |
| 1597 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);  | 
                                                        |
| 1598 | - $row++;  | 
                                                        |
| 1599 | - }  | 
                                                        |
| 1600 | -            } else { | 
                                                        |
| 1601 | - $template_args['total_ticket_rows'] = 1;  | 
                                                        |
| 1602 | - /** @type EE_Ticket $ticket */  | 
                                                        |
| 1603 | -                $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object(); | 
                                                        |
| 1604 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);  | 
                                                        |
| 1605 | - }  | 
                                                        |
| 1606 | -        } else { | 
                                                        |
| 1607 | - $template_args['time'] = $times[0];  | 
                                                        |
| 1608 | - /** @type EE_Ticket $ticket */  | 
                                                        |
| 1609 | -            $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets(); | 
                                                        |
| 1610 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]);  | 
                                                        |
| 1611 | - // NOTE: we're just sending the first default row  | 
                                                        |
| 1612 | - // (decaf can't manage default tickets so this should be sufficient);  | 
                                                        |
| 1613 | - }  | 
                                                        |
| 1614 | - $template_args['event_datetime_help_link'] = $this->_get_help_tab_link(  | 
                                                        |
| 1615 | - 'event_editor_event_datetimes_help_tab'  | 
                                                        |
| 1616 | - );  | 
                                                        |
| 1617 | -        $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info'); | 
                                                        |
| 1618 | -        $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); | 
                                                        |
| 1619 | -        $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); | 
                                                        |
| 1620 | - $template_args['ticket_js_structure'] = $this->_get_ticket_row(  | 
                                                        |
| 1621 | -            EE_Registry::instance()->load_model('Ticket')->create_default_object(), | 
                                                        |
| 1622 | - true  | 
                                                        |
| 1623 | - );  | 
                                                        |
| 1624 | - $template = apply_filters(  | 
                                                        |
| 1625 | - 'FHEE__Events_Admin_Page__ticket_metabox__template',  | 
                                                        |
| 1626 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'  | 
                                                        |
| 1627 | - );  | 
                                                        |
| 1628 | - EEH_Template::display_template($template, $template_args);  | 
                                                        |
| 1629 | - }  | 
                                                        |
| 1630 | -  | 
                                                        |
| 1631 | -  | 
                                                        |
| 1632 | - /**  | 
                                                        |
| 1633 | - * Setup an individual ticket form for the decaf event editor page  | 
                                                        |
| 1634 | - *  | 
                                                        |
| 1635 | - * @access private  | 
                                                        |
| 1636 | - * @param EE_Ticket $ticket the ticket object  | 
                                                        |
| 1637 | - * @param boolean $skeleton whether we're generating a skeleton for js manipulation  | 
                                                        |
| 1638 | - * @param int $row  | 
                                                        |
| 1639 | - * @return string generated html for the ticket row.  | 
                                                        |
| 1640 | - */  | 
                                                        |
| 1641 | - private function _get_ticket_row($ticket, $skeleton = false, $row = 0)  | 
                                                        |
| 1642 | -    { | 
                                                        |
| 1643 | - $template_args = array(  | 
                                                        |
| 1644 | - 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(),  | 
                                                        |
| 1645 | - 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'  | 
                                                        |
| 1646 | - : '',  | 
                                                        |
| 1647 | - 'ticketrow' => $skeleton ? 'TICKETNUM' : $row,  | 
                                                        |
| 1648 | -            'TKT_ID'              => $ticket->get('TKT_ID'), | 
                                                        |
| 1649 | -            'TKT_name'            => $ticket->get('TKT_name'), | 
                                                        |
| 1650 | -            'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), | 
                                                        |
| 1651 | -            'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), | 
                                                        |
| 1652 | -            'TKT_is_default'      => $ticket->get('TKT_is_default'), | 
                                                        |
| 1653 | -            'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'), | 
                                                        |
| 1654 | - 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',  | 
                                                        |
| 1655 | -            'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'), | 
                                                        |
| 1656 | -            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted'))) | 
                                                        |
| 1657 | -                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0) | 
                                                        |
| 1658 | - ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',  | 
                                                        |
| 1659 | -            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' | 
                                                        |
| 1660 | - : ' disabled=disabled',  | 
                                                        |
| 1661 | - );  | 
                                                        |
| 1662 | - $price = $ticket->ID() !== 0  | 
                                                        |
| 1663 | -            ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none')) | 
                                                        |
| 1664 | -            : EE_Registry::instance()->load_model('Price')->create_default_object(); | 
                                                        |
| 1665 | - $price_args = array(  | 
                                                        |
| 1666 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,  | 
                                                        |
| 1667 | -            'PRC_amount'            => $price->get('PRC_amount'), | 
                                                        |
| 1668 | -            'PRT_ID'                => $price->get('PRT_ID'), | 
                                                        |
| 1669 | -            'PRC_ID'                => $price->get('PRC_ID'), | 
                                                        |
| 1670 | -            'PRC_is_default'        => $price->get('PRC_is_default'), | 
                                                        |
| 1671 | - );  | 
                                                        |
| 1672 | - // make sure we have default start and end dates if skeleton  | 
                                                        |
| 1673 | - // handle rows that should NOT be empty  | 
                                                        |
| 1674 | -        if (empty($template_args['TKT_start_date'])) { | 
                                                        |
| 1675 | - // if empty then the start date will be now.  | 
                                                        |
| 1676 | -            $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); | 
                                                        |
| 1677 | - }  | 
                                                        |
| 1678 | -        if (empty($template_args['TKT_end_date'])) { | 
                                                        |
| 1679 | - // get the earliest datetime (if present);  | 
                                                        |
| 1680 | - $earliest_dtt = $this->_cpt_model_obj->ID() > 0  | 
                                                        |
| 1681 | - ? $this->_cpt_model_obj->get_first_related(  | 
                                                        |
| 1682 | - 'Datetime',  | 
                                                        |
| 1683 | -                    array('order_by' => array('DTT_EVT_start' => 'ASC')) | 
                                                        |
| 1684 | - )  | 
                                                        |
| 1685 | - : null;  | 
                                                        |
| 1686 | -            if (! empty($earliest_dtt)) { | 
                                                        |
| 1687 | -                $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a'); | 
                                                        |
| 1688 | -            } else { | 
                                                        |
| 1689 | - $template_args['TKT_end_date'] = date(  | 
                                                        |
| 1690 | - 'Y-m-d h:i a',  | 
                                                        |
| 1691 | -                    mktime(0, 0, 0, date("m"), date("d") + 7, date("Y")) | 
                                                        |
| 1692 | - );  | 
                                                        |
| 1693 | - }  | 
                                                        |
| 1694 | - }  | 
                                                        |
| 1695 | - $template_args = array_merge($template_args, $price_args);  | 
                                                        |
| 1696 | - $template = apply_filters(  | 
                                                        |
| 1697 | - 'FHEE__Events_Admin_Page__get_ticket_row__template',  | 
                                                        |
| 1698 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',  | 
                                                        |
| 1699 | - $ticket  | 
                                                        |
| 1700 | - );  | 
                                                        |
| 1701 | - return EEH_Template::display_template($template, $template_args, true);  | 
                                                        |
| 1702 | - }  | 
                                                        |
| 1703 | -  | 
                                                        |
| 1704 | -  | 
                                                        |
| 1705 | - /**  | 
                                                        |
| 1706 | - * @throws DomainException  | 
                                                        |
| 1707 | - */  | 
                                                        |
| 1708 | - public function registration_options_meta_box()  | 
                                                        |
| 1709 | -    { | 
                                                        |
| 1710 | - $yes_no_values = array(  | 
                                                        |
| 1711 | -            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), | 
                                                        |
| 1712 | -            array('id' => false, 'text' => esc_html__('No', 'event_espresso')), | 
                                                        |
| 1713 | - );  | 
                                                        |
| 1714 | - $default_reg_status_values = EEM_Registration::reg_status_array(  | 
                                                        |
| 1715 | - array(  | 
                                                        |
| 1716 | - EEM_Registration::status_id_cancelled,  | 
                                                        |
| 1717 | - EEM_Registration::status_id_declined,  | 
                                                        |
| 1718 | - EEM_Registration::status_id_incomplete,  | 
                                                        |
| 1719 | - ),  | 
                                                        |
| 1720 | - true  | 
                                                        |
| 1721 | - );  | 
                                                        |
| 1722 | -        // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active()); | 
                                                        |
| 1723 | - $template_args['_event'] = $this->_cpt_model_obj;  | 
                                                        |
| 1724 | - $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);  | 
                                                        |
| 1725 | - $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();  | 
                                                        |
| 1726 | - $template_args['default_registration_status'] = EEH_Form_Fields::select_input(  | 
                                                        |
| 1727 | - 'default_reg_status',  | 
                                                        |
| 1728 | - $default_reg_status_values,  | 
                                                        |
| 1729 | - $this->_cpt_model_obj->default_registration_status()  | 
                                                        |
| 1730 | - );  | 
                                                        |
| 1731 | - $template_args['display_description'] = EEH_Form_Fields::select_input(  | 
                                                        |
| 1732 | - 'display_desc',  | 
                                                        |
| 1733 | - $yes_no_values,  | 
                                                        |
| 1734 | - $this->_cpt_model_obj->display_description()  | 
                                                        |
| 1735 | - );  | 
                                                        |
| 1736 | - $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(  | 
                                                        |
| 1737 | - 'display_ticket_selector',  | 
                                                        |
| 1738 | - $yes_no_values,  | 
                                                        |
| 1739 | - $this->_cpt_model_obj->display_ticket_selector(),  | 
                                                        |
| 1740 | - '',  | 
                                                        |
| 1741 | - '',  | 
                                                        |
| 1742 | - false  | 
                                                        |
| 1743 | - );  | 
                                                        |
| 1744 | - $template_args['additional_registration_options'] = apply_filters(  | 
                                                        |
| 1745 | - 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',  | 
                                                        |
| 1746 | - '',  | 
                                                        |
| 1747 | - $template_args,  | 
                                                        |
| 1748 | - $yes_no_values,  | 
                                                        |
| 1749 | - $default_reg_status_values  | 
                                                        |
| 1750 | - );  | 
                                                        |
| 1751 | - EEH_Template::display_template(  | 
                                                        |
| 1752 | - EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',  | 
                                                        |
| 1753 | - $template_args  | 
                                                        |
| 1754 | - );  | 
                                                        |
| 1755 | - }  | 
                                                        |
| 1756 | -  | 
                                                        |
| 1757 | -  | 
                                                        |
| 1758 | - /**  | 
                                                        |
| 1759 | - * _get_events()  | 
                                                        |
| 1760 | - * This method simply returns all the events (for the given _view and paging)  | 
                                                        |
| 1761 | - *  | 
                                                        |
| 1762 | - * @access public  | 
                                                        |
| 1763 | - * @param int $per_page count of items per page (20 default);  | 
                                                        |
| 1764 | - * @param int $current_page what is the current page being viewed.  | 
                                                        |
| 1765 | - * @param bool $count if TRUE then we just return a count of ALL events matching the given _view.  | 
                                                        |
| 1766 | - * If FALSE then we return an array of event objects  | 
                                                        |
| 1767 | - * that match the given _view and paging parameters.  | 
                                                        |
| 1768 | - * @return array an array of event objects.  | 
                                                        |
| 1769 | - */  | 
                                                        |
| 1770 | - public function get_events($per_page = 10, $current_page = 1, $count = false)  | 
                                                        |
| 1771 | -    { | 
                                                        |
| 1772 | - $EEME = $this->_event_model();  | 
                                                        |
| 1773 | - $offset = ($current_page - 1) * $per_page;  | 
                                                        |
| 1774 | - $limit = $count ? null : $offset . ',' . $per_page;  | 
                                                        |
| 1775 | - $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';  | 
                                                        |
| 1776 | - $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";  | 
                                                        |
| 1777 | -        if (isset($this->_req_data['month_range'])) { | 
                                                        |
| 1778 | -            $pieces = explode(' ', $this->_req_data['month_range'], 3); | 
                                                        |
| 1779 | - // simulate the FIRST day of the month, that fixes issues for months like February  | 
                                                        |
| 1780 | - // where PHP doesn't know what to assume for date.  | 
                                                        |
| 1781 | - // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437  | 
                                                        |
| 1782 | -            $month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : ''; | 
                                                        |
| 1783 | - $year_r = ! empty($pieces[1]) ? $pieces[1] : '';  | 
                                                        |
| 1784 | - }  | 
                                                        |
| 1785 | - $where = array();  | 
                                                        |
| 1786 | - $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;  | 
                                                        |
| 1787 | - // determine what post_status our condition will have for the query.  | 
                                                        |
| 1788 | -        switch ($status) { | 
                                                        |
| 1789 | - case 'month':  | 
                                                        |
| 1790 | - case 'today':  | 
                                                        |
| 1791 | - case null:  | 
                                                        |
| 1792 | - case 'all':  | 
                                                        |
| 1793 | - break;  | 
                                                        |
| 1794 | - case 'draft':  | 
                                                        |
| 1795 | -                $where['status'] = array('IN', array('draft', 'auto-draft')); | 
                                                        |
| 1796 | - break;  | 
                                                        |
| 1797 | - default:  | 
                                                        |
| 1798 | - $where['status'] = $status;  | 
                                                        |
| 1799 | - }  | 
                                                        |
| 1800 | - // categories?  | 
                                                        |
| 1801 | - $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0  | 
                                                        |
| 1802 | - ? $this->_req_data['EVT_CAT'] : null;  | 
                                                        |
| 1803 | -        if (! empty($category)) { | 
                                                        |
| 1804 | - $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;  | 
                                                        |
| 1805 | - $where['Term_Taxonomy.term_id'] = $category;  | 
                                                        |
| 1806 | - }  | 
                                                        |
| 1807 | - // date where conditions  | 
                                                        |
| 1808 | -        $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); | 
                                                        |
| 1809 | -        if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') { | 
                                                        |
| 1810 | - $DateTime = new DateTime(  | 
                                                        |
| 1811 | - $year_r . '-' . $month_r . '-01 00:00:00',  | 
                                                        |
| 1812 | - new DateTimeZone(EEM_Datetime::instance()->get_timezone())  | 
                                                        |
| 1813 | - );  | 
                                                        |
| 1814 | -            $start = $DateTime->format(implode(' ', $start_formats)); | 
                                                        |
| 1815 | - $end = $DateTime->setDate(  | 
                                                        |
| 1816 | - $year_r,  | 
                                                        |
| 1817 | - $month_r,  | 
                                                        |
| 1818 | - $DateTime  | 
                                                        |
| 1819 | -                    ->format('t') | 
                                                        |
| 1820 | - )->setTime(23, 59, 59)  | 
                                                        |
| 1821 | -                            ->format(implode(' ', $start_formats)); | 
                                                        |
| 1822 | -            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); | 
                                                        |
| 1823 | -        } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') { | 
                                                        |
| 1824 | -            $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone())); | 
                                                        |
| 1825 | -            $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); | 
                                                        |
| 1826 | -            $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats)); | 
                                                        |
| 1827 | -            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); | 
                                                        |
| 1828 | -        } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') { | 
                                                        |
| 1829 | -            $now = date('Y-m-01'); | 
                                                        |
| 1830 | - $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));  | 
                                                        |
| 1831 | -            $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); | 
                                                        |
| 1832 | -            $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t')) | 
                                                        |
| 1833 | - ->setTime(23, 59, 59)  | 
                                                        |
| 1834 | -                            ->format(implode(' ', $start_formats)); | 
                                                        |
| 1835 | -            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); | 
                                                        |
| 1836 | - }  | 
                                                        |
| 1837 | -        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { | 
                                                        |
| 1838 | - $where['EVT_wp_user'] = get_current_user_id();  | 
                                                        |
| 1839 | -        } else { | 
                                                        |
| 1840 | -            if (! isset($where['status'])) { | 
                                                        |
| 1841 | -                if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { | 
                                                        |
| 1842 | - $where['OR'] = array(  | 
                                                        |
| 1843 | -                        'status*restrict_private' => array('!=', 'private'), | 
                                                        |
| 1844 | - 'AND' => array(  | 
                                                        |
| 1845 | -                            'status*inclusive' => array('=', 'private'), | 
                                                        |
| 1846 | - 'EVT_wp_user' => get_current_user_id(),  | 
                                                        |
| 1847 | - ),  | 
                                                        |
| 1848 | - );  | 
                                                        |
| 1849 | - }  | 
                                                        |
| 1850 | - }  | 
                                                        |
| 1851 | - }  | 
                                                        |
| 1852 | -        if (isset($this->_req_data['EVT_wp_user'])) { | 
                                                        |
| 1853 | - if ($this->_req_data['EVT_wp_user'] != get_current_user_id()  | 
                                                        |
| 1854 | -                && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events') | 
                                                        |
| 1855 | -            ) { | 
                                                        |
| 1856 | - $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];  | 
                                                        |
| 1857 | - }  | 
                                                        |
| 1858 | - }  | 
                                                        |
| 1859 | - // search query handling  | 
                                                        |
| 1860 | -        if (isset($this->_req_data['s'])) { | 
                                                        |
| 1861 | - $search_string = '%' . $this->_req_data['s'] . '%';  | 
                                                        |
| 1862 | - $where['OR'] = array(  | 
                                                        |
| 1863 | -                'EVT_name'       => array('LIKE', $search_string), | 
                                                        |
| 1864 | -                'EVT_desc'       => array('LIKE', $search_string), | 
                                                        |
| 1865 | -                'EVT_short_desc' => array('LIKE', $search_string), | 
                                                        |
| 1866 | - );  | 
                                                        |
| 1867 | - }  | 
                                                        |
| 1868 | - // filter events by venue.  | 
                                                        |
| 1869 | -        if (isset($this->_req_data['venue']) && ! empty($this->_req_data['venue'])) { | 
                                                        |
| 1870 | - $where['Venue.VNU_ID'] = absint($this->_req_data['venue']);  | 
                                                        |
| 1871 | - }  | 
                                                        |
| 1872 | -        $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data); | 
                                                        |
| 1873 | - $query_params = apply_filters(  | 
                                                        |
| 1874 | - 'FHEE__Events_Admin_Page__get_events__query_params',  | 
                                                        |
| 1875 | - array(  | 
                                                        |
| 1876 | - $where,  | 
                                                        |
| 1877 | - 'limit' => $limit,  | 
                                                        |
| 1878 | - 'order_by' => $orderby,  | 
                                                        |
| 1879 | - 'order' => $order,  | 
                                                        |
| 1880 | - 'group_by' => 'EVT_ID',  | 
                                                        |
| 1881 | - ),  | 
                                                        |
| 1882 | - $this->_req_data  | 
                                                        |
| 1883 | - );  | 
                                                        |
| 1884 | - // let's first check if we have special requests coming in.  | 
                                                        |
| 1885 | -        if (isset($this->_req_data['active_status'])) { | 
                                                        |
| 1886 | -            switch ($this->_req_data['active_status']) { | 
                                                        |
| 1887 | - case 'upcoming':  | 
                                                        |
| 1888 | - return $EEME->get_upcoming_events($query_params, $count);  | 
                                                        |
| 1889 | - break;  | 
                                                        |
| 1890 | - case 'expired':  | 
                                                        |
| 1891 | - return $EEME->get_expired_events($query_params, $count);  | 
                                                        |
| 1892 | - break;  | 
                                                        |
| 1893 | - case 'active':  | 
                                                        |
| 1894 | - return $EEME->get_active_events($query_params, $count);  | 
                                                        |
| 1895 | - break;  | 
                                                        |
| 1896 | - case 'inactive':  | 
                                                        |
| 1897 | - return $EEME->get_inactive_events($query_params, $count);  | 
                                                        |
| 1898 | - break;  | 
                                                        |
| 1899 | - }  | 
                                                        |
| 1900 | - }  | 
                                                        |
| 1901 | -  | 
                                                        |
| 1902 | - $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params);  | 
                                                        |
| 1903 | - return $events;  | 
                                                        |
| 1904 | - }  | 
                                                        |
| 1905 | -  | 
                                                        |
| 1906 | -  | 
                                                        |
| 1907 | - /**  | 
                                                        |
| 1908 | - * handling for WordPress CPT actions (trash, restore, delete)  | 
                                                        |
| 1909 | - *  | 
                                                        |
| 1910 | - * @param string $post_id  | 
                                                        |
| 1911 | - */  | 
                                                        |
| 1912 | - public function trash_cpt_item($post_id)  | 
                                                        |
| 1913 | -    { | 
                                                        |
| 1914 | - $this->_req_data['EVT_ID'] = $post_id;  | 
                                                        |
| 1915 | -        $this->_trash_or_restore_event('trash', false); | 
                                                        |
| 1916 | - }  | 
                                                        |
| 1917 | -  | 
                                                        |
| 1918 | -  | 
                                                        |
| 1919 | - /**  | 
                                                        |
| 1920 | - * @param string $post_id  | 
                                                        |
| 1921 | - */  | 
                                                        |
| 1922 | - public function restore_cpt_item($post_id)  | 
                                                        |
| 1923 | -    { | 
                                                        |
| 1924 | - $this->_req_data['EVT_ID'] = $post_id;  | 
                                                        |
| 1925 | -        $this->_trash_or_restore_event('draft', false); | 
                                                        |
| 1926 | - }  | 
                                                        |
| 1927 | -  | 
                                                        |
| 1928 | -  | 
                                                        |
| 1929 | - /**  | 
                                                        |
| 1930 | - * @param string $post_id  | 
                                                        |
| 1931 | - */  | 
                                                        |
| 1932 | - public function delete_cpt_item($post_id)  | 
                                                        |
| 1933 | -    { | 
                                                        |
| 1934 | -        throw new EE_Error(esc_html__('Please contact Event Espresso support with the details of what you did to produce this error.', 'event_espresso')); | 
                                                        |
| 1935 | - $this->_req_data['EVT_ID'] = $post_id;  | 
                                                        |
| 1936 | - $this->_delete_event();  | 
                                                        |
| 1937 | - }  | 
                                                        |
| 1938 | -  | 
                                                        |
| 1939 | -  | 
                                                        |
| 1940 | - /**  | 
                                                        |
| 1941 | - * _trash_or_restore_event  | 
                                                        |
| 1942 | - *  | 
                                                        |
| 1943 | - * @access protected  | 
                                                        |
| 1944 | - * @param string $event_status  | 
                                                        |
| 1945 | - * @param bool $redirect_after  | 
                                                        |
| 1946 | - */  | 
                                                        |
| 1947 | - protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)  | 
                                                        |
| 1948 | -    { | 
                                                        |
| 1949 | - // determine the event id and set to array.  | 
                                                        |
| 1950 | - $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;  | 
                                                        |
| 1951 | - // loop thru events  | 
                                                        |
| 1952 | -        if ($EVT_ID) { | 
                                                        |
| 1953 | - // clean status  | 
                                                        |
| 1954 | - $event_status = sanitize_key($event_status);  | 
                                                        |
| 1955 | - // grab status  | 
                                                        |
| 1956 | -            if (! empty($event_status)) { | 
                                                        |
| 1957 | - $success = $this->_change_event_status($EVT_ID, $event_status);  | 
                                                        |
| 1958 | -            } else { | 
                                                        |
| 1959 | - $success = false;  | 
                                                        |
| 1960 | - $msg = esc_html__(  | 
                                                        |
| 1961 | - 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',  | 
                                                        |
| 1962 | - 'event_espresso'  | 
                                                        |
| 1963 | - );  | 
                                                        |
| 1964 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 1965 | - }  | 
                                                        |
| 1966 | -        } else { | 
                                                        |
| 1967 | - $success = false;  | 
                                                        |
| 1968 | - $msg = esc_html__(  | 
                                                        |
| 1969 | - 'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',  | 
                                                        |
| 1970 | - 'event_espresso'  | 
                                                        |
| 1971 | - );  | 
                                                        |
| 1972 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 1973 | - }  | 
                                                        |
| 1974 | - $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';  | 
                                                        |
| 1975 | -        if ($redirect_after) { | 
                                                        |
| 1976 | -            $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default')); | 
                                                        |
| 1977 | - }  | 
                                                        |
| 1978 | - }  | 
                                                        |
| 1979 | -  | 
                                                        |
| 1980 | -  | 
                                                        |
| 1981 | - /**  | 
                                                        |
| 1982 | - * _trash_or_restore_events  | 
                                                        |
| 1983 | - *  | 
                                                        |
| 1984 | - * @access protected  | 
                                                        |
| 1985 | - * @param string $event_status  | 
                                                        |
| 1986 | - * @return void  | 
                                                        |
| 1987 | - */  | 
                                                        |
| 1988 | - protected function _trash_or_restore_events($event_status = 'trash')  | 
                                                        |
| 1989 | -    { | 
                                                        |
| 1990 | - // clean status  | 
                                                        |
| 1991 | - $event_status = sanitize_key($event_status);  | 
                                                        |
| 1992 | - // grab status  | 
                                                        |
| 1993 | -        if (! empty($event_status)) { | 
                                                        |
| 1994 | - $success = true;  | 
                                                        |
| 1995 | - // determine the event id and set to array.  | 
                                                        |
| 1996 | - $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();  | 
                                                        |
| 1997 | - // loop thru events  | 
                                                        |
| 1998 | -            foreach ($EVT_IDs as $EVT_ID) { | 
                                                        |
| 1999 | -                if ($EVT_ID = absint($EVT_ID)) { | 
                                                        |
| 2000 | - $results = $this->_change_event_status($EVT_ID, $event_status);  | 
                                                        |
| 2001 | - $success = $results !== false ? $success : false;  | 
                                                        |
| 2002 | -                } else { | 
                                                        |
| 2003 | - $msg = sprintf(  | 
                                                        |
| 2004 | - esc_html__(  | 
                                                        |
| 2005 | - 'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',  | 
                                                        |
| 2006 | - 'event_espresso'  | 
                                                        |
| 2007 | - ),  | 
                                                        |
| 2008 | - $EVT_ID  | 
                                                        |
| 2009 | - );  | 
                                                        |
| 2010 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 2011 | - $success = false;  | 
                                                        |
| 2012 | - }  | 
                                                        |
| 2013 | - }  | 
                                                        |
| 2014 | -        } else { | 
                                                        |
| 2015 | - $success = false;  | 
                                                        |
| 2016 | - $msg = esc_html__(  | 
                                                        |
| 2017 | - 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',  | 
                                                        |
| 2018 | - 'event_espresso'  | 
                                                        |
| 2019 | - );  | 
                                                        |
| 2020 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 2021 | - }  | 
                                                        |
| 2022 | - // in order to force a pluralized result message we need to send back a success status greater than 1  | 
                                                        |
| 2023 | - $success = $success ? 2 : false;  | 
                                                        |
| 2024 | - $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';  | 
                                                        |
| 2025 | -        $this->_redirect_after_action($success, 'Events', $action, array('action' => 'default')); | 
                                                        |
| 2026 | - }  | 
                                                        |
| 2027 | -  | 
                                                        |
| 2028 | -  | 
                                                        |
| 2029 | - /**  | 
                                                        |
| 2030 | - * _trash_or_restore_events  | 
                                                        |
| 2031 | - *  | 
                                                        |
| 2032 | - * @access private  | 
                                                        |
| 2033 | - * @param int $EVT_ID  | 
                                                        |
| 2034 | - * @param string $event_status  | 
                                                        |
| 2035 | - * @return bool  | 
                                                        |
| 2036 | - */  | 
                                                        |
| 2037 | - private function _change_event_status($EVT_ID = 0, $event_status = '')  | 
                                                        |
| 2038 | -    { | 
                                                        |
| 2039 | - // grab event id  | 
                                                        |
| 2040 | -        if (! $EVT_ID) { | 
                                                        |
| 2041 | - $msg = esc_html__(  | 
                                                        |
| 2042 | - 'An error occurred. No Event ID or an invalid Event ID was received.',  | 
                                                        |
| 2043 | - 'event_espresso'  | 
                                                        |
| 2044 | - );  | 
                                                        |
| 2045 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 2046 | - return false;  | 
                                                        |
| 2047 | - }  | 
                                                        |
| 2048 | - $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);  | 
                                                        |
| 2049 | - // clean status  | 
                                                        |
| 2050 | - $event_status = sanitize_key($event_status);  | 
                                                        |
| 2051 | - // grab status  | 
                                                        |
| 2052 | -        if (empty($event_status)) { | 
                                                        |
| 2053 | - $msg = esc_html__(  | 
                                                        |
| 2054 | - 'An error occurred. No Event Status or an invalid Event Status was received.',  | 
                                                        |
| 2055 | - 'event_espresso'  | 
                                                        |
| 2056 | - );  | 
                                                        |
| 2057 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 2058 | - return false;  | 
                                                        |
| 2059 | - }  | 
                                                        |
| 2060 | - // was event trashed or restored ?  | 
                                                        |
| 2061 | -        switch ($event_status) { | 
                                                        |
| 2062 | - case 'draft':  | 
                                                        |
| 2063 | - $action = 'restored from the trash';  | 
                                                        |
| 2064 | - $hook = 'AHEE_event_restored_from_trash';  | 
                                                        |
| 2065 | - break;  | 
                                                        |
| 2066 | - case 'trash':  | 
                                                        |
| 2067 | - $action = 'moved to the trash';  | 
                                                        |
| 2068 | - $hook = 'AHEE_event_moved_to_trash';  | 
                                                        |
| 2069 | - break;  | 
                                                        |
| 2070 | - default:  | 
                                                        |
| 2071 | - $action = 'updated';  | 
                                                        |
| 2072 | - $hook = false;  | 
                                                        |
| 2073 | - }  | 
                                                        |
| 2074 | - // use class to change status  | 
                                                        |
| 2075 | - $this->_cpt_model_obj->set_status($event_status);  | 
                                                        |
| 2076 | - $success = $this->_cpt_model_obj->save();  | 
                                                        |
| 2077 | -        if ($success === false) { | 
                                                        |
| 2078 | -            $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); | 
                                                        |
| 2079 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 2080 | - return false;  | 
                                                        |
| 2081 | - }  | 
                                                        |
| 2082 | -        if ($hook) { | 
                                                        |
| 2083 | - do_action($hook);  | 
                                                        |
| 2084 | - }  | 
                                                        |
| 2085 | - return true;  | 
                                                        |
| 2086 | - }  | 
                                                        |
| 2087 | -  | 
                                                        |
| 2088 | -  | 
                                                        |
| 2089 | - /**  | 
                                                        |
| 2090 | - * _delete_event  | 
                                                        |
| 2091 | - *  | 
                                                        |
| 2092 | - * @access protected  | 
                                                        |
| 2093 | - * @param bool $redirect_after  | 
                                                        |
| 2094 | - */  | 
                                                        |
| 2095 | - protected function _delete_event()  | 
                                                        |
| 2096 | -    { | 
                                                        |
| 2097 | - // determine the event id and set to array.  | 
                                                        |
| 2098 | - $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null;  | 
                                                        |
| 2099 | - wp_safe_redirect(  | 
                                                        |
| 2100 | - EE_Admin_Page::add_query_args_and_nonce(  | 
                                                        |
| 2101 | - [  | 
                                                        |
| 2102 | - 'action' => 'preview_deletion',  | 
                                                        |
| 2103 | - 'EVT_IDs[]' => $EVT_ID  | 
                                                        |
| 2104 | - ],  | 
                                                        |
| 2105 | - $this->_admin_base_url  | 
                                                        |
| 2106 | - )  | 
                                                        |
| 2107 | - );  | 
                                                        |
| 2108 | - }  | 
                                                        |
| 2109 | -  | 
                                                        |
| 2110 | -  | 
                                                        |
| 2111 | - /**  | 
                                                        |
| 2112 | - * _delete_events  | 
                                                        |
| 2113 | - *  | 
                                                        |
| 2114 | - * @access protected  | 
                                                        |
| 2115 | - * @return void  | 
                                                        |
| 2116 | - */  | 
                                                        |
| 2117 | - protected function _delete_events()  | 
                                                        |
| 2118 | -    { | 
                                                        |
| 2119 | - $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();  | 
                                                        |
| 2120 | - $args = [  | 
                                                        |
| 2121 | - 'action' => 'preview_deletion',  | 
                                                        |
| 2122 | - ];  | 
                                                        |
| 2123 | -        foreach ($EVT_IDs as $EVT_ID) { | 
                                                        |
| 2124 | - $args['EVT_IDs[]'] = (int) $EVT_ID;  | 
                                                        |
| 2125 | - }  | 
                                                        |
| 2126 | - wp_safe_redirect(  | 
                                                        |
| 2127 | - EE_Admin_Page::add_query_args_and_nonce(  | 
                                                        |
| 2128 | - $args,  | 
                                                        |
| 2129 | - $this->_admin_base_url  | 
                                                        |
| 2130 | - )  | 
                                                        |
| 2131 | - );  | 
                                                        |
| 2132 | - }  | 
                                                        |
| 2133 | -  | 
                                                        |
| 2134 | - /**  | 
                                                        |
| 2135 | - * A page for users to preview what exactly will be deleted, and confirm they want to delete it.  | 
                                                        |
| 2136 | - * @since $VID:$  | 
                                                        |
| 2137 | - */  | 
                                                        |
| 2138 | - protected function previewDeletion()  | 
                                                        |
| 2139 | -    { | 
                                                        |
| 2140 | - $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();  | 
                                                        |
| 2141 | - $confirm_deletion_args = [  | 
                                                        |
| 2142 | - 'action' => 'confirm_deletion',  | 
                                                        |
| 2143 | - ];  | 
                                                        |
| 2144 | -        foreach ($EVT_IDs as $EVT_ID) { | 
                                                        |
| 2145 | - $confirm_deletion_args['EVT_IDs[]'] = (int) $EVT_ID;  | 
                                                        |
| 2146 | - }  | 
                                                        |
| 2147 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template(  | 
                                                        |
| 2148 | - EVENTS_TEMPLATE_PATH . 'event_preview_deletion.template.php',  | 
                                                        |
| 2149 | - [  | 
                                                        |
| 2150 | - 'form_url' => EE_Admin_Page::add_query_args_and_nonce(  | 
                                                        |
| 2151 | - $confirm_deletion_args,  | 
                                                        |
| 2152 | - $this->admin_base_url()  | 
                                                        |
| 2153 | - )  | 
                                                        |
| 2154 | - ],  | 
                                                        |
| 2155 | - true  | 
                                                        |
| 2156 | - );  | 
                                                        |
| 2157 | - $this->display_admin_page_with_no_sidebar();  | 
                                                        |
| 2158 | - }  | 
                                                        |
| 2159 | -  | 
                                                        |
| 2160 | - protected function confirmDeletion()  | 
                                                        |
| 2161 | -    { | 
                                                        |
| 2162 | - $event_ids = isset($this->_req_data['EVT_IDs']) ? $this->_req_data['EVT_IDs'] : array();  | 
                                                        |
| 2163 | - $success = $this->deleteEventsAndDependentData($event_ids);  | 
                                                        |
| 2164 | - $this->redirect_after_action(  | 
                                                        |
| 2165 | - $success,  | 
                                                        |
| 2166 | -            esc_html__('Events', 'event_espresso'), | 
                                                        |
| 2167 | -            esc_html__('deleted', 'event_espresso'), | 
                                                        |
| 2168 | - [  | 
                                                        |
| 2169 | - 'action' => 'default'  | 
                                                        |
| 2170 | - ]  | 
                                                        |
| 2171 | - );  | 
                                                        |
| 2172 | - }  | 
                                                        |
| 2173 | -  | 
                                                        |
| 2174 | - /**  | 
                                                        |
| 2175 | - * Deletes the events and all dependent data, plus those events' non-global/non-default tickets, prices, and  | 
                                                        |
| 2176 | - * message template groups.  | 
                                                        |
| 2177 | - * @since $VID:$  | 
                                                        |
| 2178 | - * @param $event_ids  | 
                                                        |
| 2179 | - * @return int  | 
                                                        |
| 2180 | - * @throws EE_Error  | 
                                                        |
| 2181 | - * @throws InvalidArgumentException  | 
                                                        |
| 2182 | - * @throws ReflectionException  | 
                                                        |
| 2183 | - * @throws InvalidDataTypeException  | 
                                                        |
| 2184 | - * @throws InvalidInterfaceException  | 
                                                        |
| 2185 | - */  | 
                                                        |
| 2186 | - protected function deleteEventsAndDependentData($event_ids)  | 
                                                        |
| 2187 | -    { | 
                                                        |
| 2188 | - // Call me an optimist.  | 
                                                        |
| 2189 | - $success = true;  | 
                                                        |
| 2190 | -        $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); | 
                                                        |
| 2191 | -  | 
                                                        |
| 2192 | - // Find all the root nodes to delete (this isn't just events, because there's other data, like related tickets,  | 
                                                        |
| 2193 | - // prices, message templates, etc, whose model definition doesn't make them dependent on events. But,  | 
                                                        |
| 2194 | - // we have no UI to access them independent of events, so they may as well get deleted too.)  | 
                                                        |
| 2195 | - $model_objects_to_delete = [];  | 
                                                        |
| 2196 | -        foreach ($event_ids as $event_id) { | 
                                                        |
| 2197 | - $event = EEM_Event::instance()->get_one_by_ID($event_id);  | 
                                                        |
| 531 | + )  | 
                                                        |
| 532 | + );  | 
                                                        |
| 533 | + }  | 
                                                        |
| 534 | +  | 
                                                        |
| 535 | +  | 
                                                        |
| 536 | + /**  | 
                                                        |
| 537 | + * Used to register any global screen options if necessary for every route in this admin page group.  | 
                                                        |
| 538 | + */  | 
                                                        |
| 539 | + protected function _add_screen_options()  | 
                                                        |
| 540 | +	{ | 
                                                        |
| 541 | + }  | 
                                                        |
| 542 | +  | 
                                                        |
| 543 | +  | 
                                                        |
| 544 | + /**  | 
                                                        |
| 545 | + * Implementing the screen options for the 'default' route.  | 
                                                        |
| 546 | + */  | 
                                                        |
| 547 | + protected function _add_screen_options_default()  | 
                                                        |
| 548 | +	{ | 
                                                        |
| 549 | + $this->_per_page_screen_option();  | 
                                                        |
| 550 | + }  | 
                                                        |
| 551 | +  | 
                                                        |
| 552 | +  | 
                                                        |
| 553 | + /**  | 
                                                        |
| 554 | + * Implementing screen options for the category list route.  | 
                                                        |
| 555 | + */  | 
                                                        |
| 556 | + protected function _add_screen_options_category_list()  | 
                                                        |
| 557 | +	{ | 
                                                        |
| 558 | + $page_title = $this->_admin_page_title;  | 
                                                        |
| 559 | +		$this->_admin_page_title = esc_html__('Categories', 'event_espresso'); | 
                                                        |
| 560 | + $this->_per_page_screen_option();  | 
                                                        |
| 561 | + $this->_admin_page_title = $page_title;  | 
                                                        |
| 562 | + }  | 
                                                        |
| 563 | +  | 
                                                        |
| 564 | +  | 
                                                        |
| 565 | + /**  | 
                                                        |
| 566 | + * Used to register any global feature pointers for the admin page group.  | 
                                                        |
| 567 | + */  | 
                                                        |
| 568 | + protected function _add_feature_pointers()  | 
                                                        |
| 569 | +	{ | 
                                                        |
| 570 | + }  | 
                                                        |
| 571 | +  | 
                                                        |
| 572 | +  | 
                                                        |
| 573 | + /**  | 
                                                        |
| 574 | + * Registers and enqueues any global scripts and styles for the entire admin page group.  | 
                                                        |
| 575 | + */  | 
                                                        |
| 576 | + public function load_scripts_styles()  | 
                                                        |
| 577 | +	{ | 
                                                        |
| 578 | + wp_register_style(  | 
                                                        |
| 579 | + 'events-admin-css',  | 
                                                        |
| 580 | + EVENTS_ASSETS_URL . 'events-admin-page.css',  | 
                                                        |
| 581 | + array(),  | 
                                                        |
| 582 | + EVENT_ESPRESSO_VERSION  | 
                                                        |
| 583 | + );  | 
                                                        |
| 584 | +		wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); | 
                                                        |
| 585 | +		wp_enqueue_style('events-admin-css'); | 
                                                        |
| 586 | +		wp_enqueue_style('ee-cat-admin'); | 
                                                        |
| 587 | + // todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details  | 
                                                        |
| 588 | + // registers for all views  | 
                                                        |
| 589 | + // scripts  | 
                                                        |
| 590 | + wp_register_script(  | 
                                                        |
| 591 | + 'event_editor_js',  | 
                                                        |
| 592 | + EVENTS_ASSETS_URL . 'event_editor.js',  | 
                                                        |
| 593 | +			array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'), | 
                                                        |
| 594 | + EVENT_ESPRESSO_VERSION,  | 
                                                        |
| 595 | + true  | 
                                                        |
| 596 | + );  | 
                                                        |
| 597 | + }  | 
                                                        |
| 598 | +  | 
                                                        |
| 599 | +  | 
                                                        |
| 600 | + /**  | 
                                                        |
| 601 | + * Enqueuing scripts and styles specific to this view  | 
                                                        |
| 602 | + */  | 
                                                        |
| 603 | + public function load_scripts_styles_create_new()  | 
                                                        |
| 604 | +	{ | 
                                                        |
| 605 | + $this->load_scripts_styles_edit();  | 
                                                        |
| 606 | + }  | 
                                                        |
| 607 | +  | 
                                                        |
| 608 | +  | 
                                                        |
| 609 | + /**  | 
                                                        |
| 610 | + * Enqueuing scripts and styles specific to this view  | 
                                                        |
| 611 | + */  | 
                                                        |
| 612 | + public function load_scripts_styles_edit()  | 
                                                        |
| 613 | +	{ | 
                                                        |
| 614 | + // styles  | 
                                                        |
| 615 | +		wp_enqueue_style('espresso-ui-theme'); | 
                                                        |
| 616 | + wp_register_style(  | 
                                                        |
| 617 | + 'event-editor-css',  | 
                                                        |
| 618 | + EVENTS_ASSETS_URL . 'event-editor.css',  | 
                                                        |
| 619 | +			array('ee-admin-css'), | 
                                                        |
| 620 | + EVENT_ESPRESSO_VERSION  | 
                                                        |
| 621 | + );  | 
                                                        |
| 622 | +		wp_enqueue_style('event-editor-css'); | 
                                                        |
| 623 | + // scripts  | 
                                                        |
| 624 | + wp_register_script(  | 
                                                        |
| 625 | + 'event-datetime-metabox',  | 
                                                        |
| 626 | + EVENTS_ASSETS_URL . 'event-datetime-metabox.js',  | 
                                                        |
| 627 | +			array('event_editor_js', 'ee-datepicker'), | 
                                                        |
| 628 | + EVENT_ESPRESSO_VERSION  | 
                                                        |
| 629 | + );  | 
                                                        |
| 630 | +		wp_enqueue_script('event-datetime-metabox'); | 
                                                        |
| 631 | + }  | 
                                                        |
| 632 | +  | 
                                                        |
| 633 | +  | 
                                                        |
| 634 | + /**  | 
                                                        |
| 635 | + * Populating the _views property for the category list table view.  | 
                                                        |
| 636 | + */  | 
                                                        |
| 637 | + protected function _set_list_table_views_category_list()  | 
                                                        |
| 638 | +	{ | 
                                                        |
| 639 | + $this->_views = array(  | 
                                                        |
| 640 | + 'all' => array(  | 
                                                        |
| 641 | + 'slug' => 'all',  | 
                                                        |
| 642 | +				'label'       => esc_html__('All', 'event_espresso'), | 
                                                        |
| 643 | + 'count' => 0,  | 
                                                        |
| 644 | + 'bulk_action' => array(  | 
                                                        |
| 645 | +					'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'), | 
                                                        |
| 646 | + ),  | 
                                                        |
| 647 | + ),  | 
                                                        |
| 648 | + );  | 
                                                        |
| 649 | + }  | 
                                                        |
| 650 | +  | 
                                                        |
| 651 | +  | 
                                                        |
| 652 | + /**  | 
                                                        |
| 653 | + * For adding anything that fires on the admin_init hook for any route within this admin page group.  | 
                                                        |
| 654 | + */  | 
                                                        |
| 655 | + public function admin_init()  | 
                                                        |
| 656 | +	{ | 
                                                        |
| 657 | + EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(  | 
                                                        |
| 658 | + 'Do you really want to delete this image? Please remember to update your event to complete the removal.',  | 
                                                        |
| 659 | + 'event_espresso'  | 
                                                        |
| 660 | + );  | 
                                                        |
| 661 | + }  | 
                                                        |
| 662 | +  | 
                                                        |
| 663 | +  | 
                                                        |
| 664 | + /**  | 
                                                        |
| 665 | + * For adding anything that should be triggered on the admin_notices hook for any route within this admin page  | 
                                                        |
| 666 | + * group.  | 
                                                        |
| 667 | + */  | 
                                                        |
| 668 | + public function admin_notices()  | 
                                                        |
| 669 | +	{ | 
                                                        |
| 670 | + }  | 
                                                        |
| 671 | +  | 
                                                        |
| 672 | +  | 
                                                        |
| 673 | + /**  | 
                                                        |
| 674 | + * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within  | 
                                                        |
| 675 | + * this admin page group.  | 
                                                        |
| 676 | + */  | 
                                                        |
| 677 | + public function admin_footer_scripts()  | 
                                                        |
| 678 | +	{ | 
                                                        |
| 679 | + }  | 
                                                        |
| 680 | +  | 
                                                        |
| 681 | +  | 
                                                        |
| 682 | + /**  | 
                                                        |
| 683 | + * Call this function to verify if an event is public and has tickets for sale. If it does, then we need to show a  | 
                                                        |
| 684 | + * warning (via EE_Error::add_error());  | 
                                                        |
| 685 | + *  | 
                                                        |
| 686 | + * @param EE_Event $event Event object  | 
                                                        |
| 687 | + * @param string $req_type  | 
                                                        |
| 688 | + * @return void  | 
                                                        |
| 689 | + * @throws EE_Error  | 
                                                        |
| 690 | + * @access public  | 
                                                        |
| 691 | + */  | 
                                                        |
| 692 | + public function verify_event_edit($event = null, $req_type = '')  | 
                                                        |
| 693 | +	{ | 
                                                        |
| 694 | + // don't need to do this when processing  | 
                                                        |
| 695 | +		if (! empty($req_type)) { | 
                                                        |
| 696 | + return;  | 
                                                        |
| 697 | + }  | 
                                                        |
| 698 | + // no event?  | 
                                                        |
| 699 | +		if (empty($event)) { | 
                                                        |
| 700 | + // set event  | 
                                                        |
| 701 | + $event = $this->_cpt_model_obj;  | 
                                                        |
| 702 | + }  | 
                                                        |
| 703 | + // STILL no event?  | 
                                                        |
| 704 | +		if (! $event instanceof EE_Event) { | 
                                                        |
| 705 | + return;  | 
                                                        |
| 706 | + }  | 
                                                        |
| 707 | + $orig_status = $event->status();  | 
                                                        |
| 708 | + // first check if event is active.  | 
                                                        |
| 709 | + if ($orig_status === EEM_Event::cancelled  | 
                                                        |
| 710 | + || $orig_status === EEM_Event::postponed  | 
                                                        |
| 711 | + || $event->is_expired()  | 
                                                        |
| 712 | + || $event->is_inactive()  | 
                                                        |
| 713 | +		) { | 
                                                        |
| 714 | + return;  | 
                                                        |
| 715 | + }  | 
                                                        |
| 716 | + // made it here so it IS active... next check that any of the tickets are sold.  | 
                                                        |
| 717 | +		if ($event->is_sold_out(true)) { | 
                                                        |
| 718 | +			if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) { | 
                                                        |
| 719 | + EE_Error::add_attention(  | 
                                                        |
| 720 | + sprintf(  | 
                                                        |
| 721 | + esc_html__(  | 
                                                        |
| 722 | + 'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event. However, this change is not permanent until you update the event. You can change the status back to something else before updating if you wish.',  | 
                                                        |
| 723 | + 'event_espresso'  | 
                                                        |
| 724 | + ),  | 
                                                        |
| 725 | + EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')  | 
                                                        |
| 726 | + )  | 
                                                        |
| 727 | + );  | 
                                                        |
| 728 | + }  | 
                                                        |
| 729 | + return;  | 
                                                        |
| 730 | +		} elseif ($orig_status === EEM_Event::sold_out) { | 
                                                        |
| 731 | + EE_Error::add_attention(  | 
                                                        |
| 732 | + sprintf(  | 
                                                        |
| 733 | + esc_html__(  | 
                                                        |
| 734 | + 'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets. However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',  | 
                                                        |
| 735 | + 'event_espresso'  | 
                                                        |
| 736 | + ),  | 
                                                        |
| 737 | + EEH_Template::pretty_status($event->status(), false, 'sentence')  | 
                                                        |
| 738 | + )  | 
                                                        |
| 739 | + );  | 
                                                        |
| 740 | + }  | 
                                                        |
| 741 | + // now we need to determine if the event has any tickets on sale. If not then we dont' show the error  | 
                                                        |
| 742 | +		if (! $event->tickets_on_sale()) { | 
                                                        |
| 743 | + return;  | 
                                                        |
| 744 | + }  | 
                                                        |
| 745 | + // made it here so show warning  | 
                                                        |
| 746 | + $this->_edit_event_warning();  | 
                                                        |
| 747 | + }  | 
                                                        |
| 748 | +  | 
                                                        |
| 749 | +  | 
                                                        |
| 750 | + /**  | 
                                                        |
| 751 | + * This is the text used for when an event is being edited that is public and has tickets for sale.  | 
                                                        |
| 752 | + * When needed, hook this into a EE_Error::add_error() notice.  | 
                                                        |
| 753 | + *  | 
                                                        |
| 754 | + * @access protected  | 
                                                        |
| 755 | + * @return void  | 
                                                        |
| 756 | + */  | 
                                                        |
| 757 | + protected function _edit_event_warning()  | 
                                                        |
| 758 | +	{ | 
                                                        |
| 759 | + // we don't want to add warnings during these requests  | 
                                                        |
| 760 | +		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') { | 
                                                        |
| 761 | + return;  | 
                                                        |
| 762 | + }  | 
                                                        |
| 763 | + EE_Error::add_attention(  | 
                                                        |
| 764 | + sprintf(  | 
                                                        |
| 765 | + esc_html__(  | 
                                                        |
| 766 | + 'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',  | 
                                                        |
| 767 | + 'event_espresso'  | 
                                                        |
| 768 | + ),  | 
                                                        |
| 769 | + '<a class="espresso-help-tab-lnk">',  | 
                                                        |
| 770 | + '</a>'  | 
                                                        |
| 771 | + )  | 
                                                        |
| 772 | + );  | 
                                                        |
| 773 | + }  | 
                                                        |
| 774 | +  | 
                                                        |
| 775 | +  | 
                                                        |
| 776 | + /**  | 
                                                        |
| 777 | + * When a user is creating a new event, notify them if they haven't set their timezone.  | 
                                                        |
| 778 | + * Otherwise, do the normal logic  | 
                                                        |
| 779 | + *  | 
                                                        |
| 780 | + * @return string  | 
                                                        |
| 781 | + * @throws \EE_Error  | 
                                                        |
| 782 | + */  | 
                                                        |
| 783 | + protected function _create_new_cpt_item()  | 
                                                        |
| 784 | +	{ | 
                                                        |
| 785 | +		$has_timezone_string = get_option('timezone_string'); | 
                                                        |
| 786 | + // only nag them about setting their timezone if it's their first event, and they haven't already done it  | 
                                                        |
| 787 | +		if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) { | 
                                                        |
| 788 | + EE_Error::add_attention(  | 
                                                        |
| 789 | + sprintf(  | 
                                                        |
| 790 | + __(  | 
                                                        |
| 791 | + 'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',  | 
                                                        |
| 792 | + 'event_espresso'  | 
                                                        |
| 793 | + ),  | 
                                                        |
| 794 | + '<br>',  | 
                                                        |
| 795 | + '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'  | 
                                                        |
| 796 | +					. EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale()) | 
                                                        |
| 797 | + . '</select>',  | 
                                                        |
| 798 | + '<button class="button button-secondary timezone-submit">',  | 
                                                        |
| 799 | + '</button><span class="spinner"></span>'  | 
                                                        |
| 800 | + ),  | 
                                                        |
| 801 | + __FILE__,  | 
                                                        |
| 802 | + __FUNCTION__,  | 
                                                        |
| 803 | + __LINE__  | 
                                                        |
| 804 | + );  | 
                                                        |
| 805 | + }  | 
                                                        |
| 806 | + return parent::_create_new_cpt_item();  | 
                                                        |
| 807 | + }  | 
                                                        |
| 808 | +  | 
                                                        |
| 809 | +  | 
                                                        |
| 810 | + /**  | 
                                                        |
| 811 | + * Sets the _views property for the default route in this admin page group.  | 
                                                        |
| 812 | + */  | 
                                                        |
| 813 | + protected function _set_list_table_views_default()  | 
                                                        |
| 814 | +	{ | 
                                                        |
| 815 | + $this->_views = array(  | 
                                                        |
| 816 | + 'all' => array(  | 
                                                        |
| 817 | + 'slug' => 'all',  | 
                                                        |
| 818 | +				'label'       => esc_html__('View All Events', 'event_espresso'), | 
                                                        |
| 819 | + 'count' => 0,  | 
                                                        |
| 820 | + 'bulk_action' => array(  | 
                                                        |
| 821 | +					'trash_events' => esc_html__('Move to Trash', 'event_espresso'), | 
                                                        |
| 822 | + ),  | 
                                                        |
| 823 | + ),  | 
                                                        |
| 824 | + 'draft' => array(  | 
                                                        |
| 825 | + 'slug' => 'draft',  | 
                                                        |
| 826 | +				'label'       => esc_html__('Draft', 'event_espresso'), | 
                                                        |
| 827 | + 'count' => 0,  | 
                                                        |
| 828 | + 'bulk_action' => array(  | 
                                                        |
| 829 | +					'trash_events' => esc_html__('Move to Trash', 'event_espresso'), | 
                                                        |
| 830 | + ),  | 
                                                        |
| 831 | + ),  | 
                                                        |
| 832 | + );  | 
                                                        |
| 833 | +		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { | 
                                                        |
| 834 | + $this->_views['trash'] = array(  | 
                                                        |
| 835 | + 'slug' => 'trash',  | 
                                                        |
| 836 | +				'label'       => esc_html__('Trash', 'event_espresso'), | 
                                                        |
| 837 | + 'count' => 0,  | 
                                                        |
| 838 | + 'bulk_action' => array(  | 
                                                        |
| 839 | +					'restore_events' => esc_html__('Restore From Trash', 'event_espresso'), | 
                                                        |
| 840 | +					'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'), | 
                                                        |
| 841 | + ),  | 
                                                        |
| 842 | + );  | 
                                                        |
| 843 | + }  | 
                                                        |
| 844 | + }  | 
                                                        |
| 845 | +  | 
                                                        |
| 846 | +  | 
                                                        |
| 847 | + /**  | 
                                                        |
| 848 | + * Provides the legend item array for the default list table view.  | 
                                                        |
| 849 | + *  | 
                                                        |
| 850 | + * @return array  | 
                                                        |
| 851 | + */  | 
                                                        |
| 852 | + protected function _event_legend_items()  | 
                                                        |
| 853 | +	{ | 
                                                        |
| 854 | + $items = array(  | 
                                                        |
| 855 | + 'view_details' => array(  | 
                                                        |
| 856 | + 'class' => 'dashicons dashicons-search',  | 
                                                        |
| 857 | +				'desc'  => esc_html__('View Event', 'event_espresso'), | 
                                                        |
| 858 | + ),  | 
                                                        |
| 859 | + 'edit_event' => array(  | 
                                                        |
| 860 | + 'class' => 'ee-icon ee-icon-calendar-edit',  | 
                                                        |
| 861 | +				'desc'  => esc_html__('Edit Event Details', 'event_espresso'), | 
                                                        |
| 862 | + ),  | 
                                                        |
| 863 | + 'view_attendees' => array(  | 
                                                        |
| 864 | + 'class' => 'dashicons dashicons-groups',  | 
                                                        |
| 865 | +				'desc'  => esc_html__('View Registrations for Event', 'event_espresso'), | 
                                                        |
| 866 | + ),  | 
                                                        |
| 867 | + );  | 
                                                        |
| 868 | +		$items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); | 
                                                        |
| 869 | + $statuses = array(  | 
                                                        |
| 870 | + 'sold_out_status' => array(  | 
                                                        |
| 871 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,  | 
                                                        |
| 872 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),  | 
                                                        |
| 873 | + ),  | 
                                                        |
| 874 | + 'active_status' => array(  | 
                                                        |
| 875 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,  | 
                                                        |
| 876 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),  | 
                                                        |
| 877 | + ),  | 
                                                        |
| 878 | + 'upcoming_status' => array(  | 
                                                        |
| 879 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,  | 
                                                        |
| 880 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),  | 
                                                        |
| 881 | + ),  | 
                                                        |
| 882 | + 'postponed_status' => array(  | 
                                                        |
| 883 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,  | 
                                                        |
| 884 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),  | 
                                                        |
| 885 | + ),  | 
                                                        |
| 886 | + 'cancelled_status' => array(  | 
                                                        |
| 887 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,  | 
                                                        |
| 888 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),  | 
                                                        |
| 889 | + ),  | 
                                                        |
| 890 | + 'expired_status' => array(  | 
                                                        |
| 891 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,  | 
                                                        |
| 892 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),  | 
                                                        |
| 893 | + ),  | 
                                                        |
| 894 | + 'inactive_status' => array(  | 
                                                        |
| 895 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,  | 
                                                        |
| 896 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),  | 
                                                        |
| 897 | + ),  | 
                                                        |
| 898 | + );  | 
                                                        |
| 899 | +		$statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses); | 
                                                        |
| 900 | + return array_merge($items, $statuses);  | 
                                                        |
| 901 | + }  | 
                                                        |
| 902 | +  | 
                                                        |
| 903 | +  | 
                                                        |
| 904 | + /**  | 
                                                        |
| 905 | + * @return EEM_Event  | 
                                                        |
| 906 | + */  | 
                                                        |
| 907 | + private function _event_model()  | 
                                                        |
| 908 | +	{ | 
                                                        |
| 909 | +		if (! $this->_event_model instanceof EEM_Event) { | 
                                                        |
| 910 | +			$this->_event_model = EE_Registry::instance()->load_model('Event'); | 
                                                        |
| 911 | + }  | 
                                                        |
| 912 | + return $this->_event_model;  | 
                                                        |
| 913 | + }  | 
                                                        |
| 914 | +  | 
                                                        |
| 915 | +  | 
                                                        |
| 916 | + /**  | 
                                                        |
| 917 | + * Adds extra buttons to the WP CPT permalink field row.  | 
                                                        |
| 918 | + * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.  | 
                                                        |
| 919 | + *  | 
                                                        |
| 920 | + * @param string $return the current html  | 
                                                        |
| 921 | + * @param int $id the post id for the page  | 
                                                        |
| 922 | + * @param string $new_title What the title is  | 
                                                        |
| 923 | + * @param string $new_slug what the slug is  | 
                                                        |
| 924 | + * @return string The new html string for the permalink area  | 
                                                        |
| 925 | + */  | 
                                                        |
| 926 | + public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)  | 
                                                        |
| 927 | +	{ | 
                                                        |
| 928 | + // make sure this is only when editing  | 
                                                        |
| 929 | +		if (! empty($id)) { | 
                                                        |
| 930 | + $post = get_post($id);  | 
                                                        |
| 931 | + $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">'  | 
                                                        |
| 932 | +					   . esc_html__('Shortcode', 'event_espresso') | 
                                                        |
| 933 | + . '</a> ';  | 
                                                        |
| 934 | + $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='  | 
                                                        |
| 935 | + . $post->ID  | 
                                                        |
| 936 | + . ']">';  | 
                                                        |
| 937 | + }  | 
                                                        |
| 938 | + return $return;  | 
                                                        |
| 939 | + }  | 
                                                        |
| 940 | +  | 
                                                        |
| 941 | +  | 
                                                        |
| 942 | + /**  | 
                                                        |
| 943 | + * _events_overview_list_table  | 
                                                        |
| 944 | + * This contains the logic for showing the events_overview list  | 
                                                        |
| 945 | + *  | 
                                                        |
| 946 | + * @access protected  | 
                                                        |
| 947 | + * @return void  | 
                                                        |
| 948 | + * @throws \EE_Error  | 
                                                        |
| 949 | + */  | 
                                                        |
| 950 | + protected function _events_overview_list_table()  | 
                                                        |
| 951 | +	{ | 
                                                        |
| 952 | +		do_action('AHEE_log', __FILE__, __FUNCTION__, ''); | 
                                                        |
| 953 | + $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table'])  | 
                                                        |
| 954 | + ? (array) $this->_template_args['after_list_table']  | 
                                                        |
| 955 | + : array();  | 
                                                        |
| 956 | + $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()  | 
                                                        |
| 957 | + . EEH_Template::get_button_or_link(  | 
                                                        |
| 958 | +					get_post_type_archive_link('espresso_events'), | 
                                                        |
| 959 | +					esc_html__("View Event Archive Page", "event_espresso"), | 
                                                        |
| 960 | + 'button'  | 
                                                        |
| 961 | + );  | 
                                                        |
| 962 | + $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());  | 
                                                        |
| 963 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(  | 
                                                        |
| 964 | + 'create_new',  | 
                                                        |
| 965 | + 'add',  | 
                                                        |
| 966 | + array(),  | 
                                                        |
| 967 | + 'add-new-h2'  | 
                                                        |
| 968 | + );  | 
                                                        |
| 969 | + $this->display_admin_list_table_page_with_no_sidebar();  | 
                                                        |
| 970 | + }  | 
                                                        |
| 971 | +  | 
                                                        |
| 972 | +  | 
                                                        |
| 973 | + /**  | 
                                                        |
| 974 | + * this allows for extra misc actions in the default WP publish box  | 
                                                        |
| 975 | + *  | 
                                                        |
| 976 | + * @return void  | 
                                                        |
| 977 | + */  | 
                                                        |
| 978 | + public function extra_misc_actions_publish_box()  | 
                                                        |
| 979 | +	{ | 
                                                        |
| 980 | + $this->_generate_publish_box_extra_content();  | 
                                                        |
| 981 | + }  | 
                                                        |
| 982 | +  | 
                                                        |
| 983 | +  | 
                                                        |
| 984 | + /**  | 
                                                        |
| 985 | +	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been | 
                                                        |
| 986 | + * saved.  | 
                                                        |
| 987 | + * Typically you would use this to save any additional data.  | 
                                                        |
| 988 | + * Keep in mind also that "save_post" runs on EVERY post update to the database.  | 
                                                        |
| 989 | + * ALSO very important. When a post transitions from scheduled to published,  | 
                                                        |
| 990 | + * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from  | 
                                                        |
| 991 | + * other meta saves. So MAKE sure that you handle this accordingly.  | 
                                                        |
| 992 | + *  | 
                                                        |
| 993 | + * @access protected  | 
                                                        |
| 994 | + * @abstract  | 
                                                        |
| 995 | + * @param string $post_id The ID of the cpt that was saved (so you can link relationally)  | 
                                                        |
| 996 | + * @param object $post The post object of the cpt that was saved.  | 
                                                        |
| 997 | + * @return void  | 
                                                        |
| 998 | + * @throws \EE_Error  | 
                                                        |
| 999 | + */  | 
                                                        |
| 1000 | + protected function _insert_update_cpt_item($post_id, $post)  | 
                                                        |
| 1001 | +	{ | 
                                                        |
| 1002 | +		if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') { | 
                                                        |
| 1003 | + // get out we're not processing an event save.  | 
                                                        |
| 1004 | + return;  | 
                                                        |
| 1005 | + }  | 
                                                        |
| 1006 | + $event_values = array(  | 
                                                        |
| 1007 | + 'EVT_display_desc' => ! empty($this->_req_data['display_desc']) ? 1 : 0,  | 
                                                        |
| 1008 | + 'EVT_display_ticket_selector' => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0,  | 
                                                        |
| 1009 | + 'EVT_additional_limit' => min(  | 
                                                        |
| 1010 | +				apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), | 
                                                        |
| 1011 | + ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null  | 
                                                        |
| 1012 | + ),  | 
                                                        |
| 1013 | + 'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status'])  | 
                                                        |
| 1014 | + ? $this->_req_data['EVT_default_registration_status']  | 
                                                        |
| 1015 | + : EE_Registry::instance()->CFG->registration->default_STS_ID,  | 
                                                        |
| 1016 | + 'EVT_member_only' => ! empty($this->_req_data['member_only']) ? 1 : 0,  | 
                                                        |
| 1017 | + 'EVT_allow_overflow' => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,  | 
                                                        |
| 1018 | + 'EVT_timezone_string' => ! empty($this->_req_data['timezone_string'])  | 
                                                        |
| 1019 | + ? $this->_req_data['timezone_string'] : null,  | 
                                                        |
| 1020 | + 'EVT_external_URL' => ! empty($this->_req_data['externalURL'])  | 
                                                        |
| 1021 | + ? $this->_req_data['externalURL'] : null,  | 
                                                        |
| 1022 | + 'EVT_phone' => ! empty($this->_req_data['event_phone'])  | 
                                                        |
| 1023 | + ? $this->_req_data['event_phone'] : null,  | 
                                                        |
| 1024 | + );  | 
                                                        |
| 1025 | + // update event  | 
                                                        |
| 1026 | + $success = $this->_event_model()->update_by_ID($event_values, $post_id);  | 
                                                        |
| 1027 | + // get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id!  | 
                                                        |
| 1028 | + $get_one_where = array(  | 
                                                        |
| 1029 | + $this->_event_model()->primary_key_name() => $post_id,  | 
                                                        |
| 1030 | + 'OR' => array(  | 
                                                        |
| 1031 | + 'status' => $post->post_status,  | 
                                                        |
| 1032 | + // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,  | 
                                                        |
| 1033 | + // but the returned object here has a status of "publish", so use the original post status as well  | 
                                                        |
| 1034 | + 'status*1' => $this->_req_data['original_post_status'],  | 
                                                        |
| 1035 | + ),  | 
                                                        |
| 1036 | + );  | 
                                                        |
| 1037 | + $event = $this->_event_model()->get_one(array($get_one_where));  | 
                                                        |
| 1038 | + // the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.  | 
                                                        |
| 1039 | + $event_update_callbacks = apply_filters(  | 
                                                        |
| 1040 | + 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',  | 
                                                        |
| 1041 | + array(  | 
                                                        |
| 1042 | + array($this, '_default_venue_update'),  | 
                                                        |
| 1043 | + array($this, '_default_tickets_update'),  | 
                                                        |
| 1044 | + )  | 
                                                        |
| 1045 | + );  | 
                                                        |
| 1046 | + $att_success = true;  | 
                                                        |
| 1047 | +		foreach ($event_update_callbacks as $e_callback) { | 
                                                        |
| 1048 | + $_success = is_callable($e_callback)  | 
                                                        |
| 1049 | + ? call_user_func($e_callback, $event, $this->_req_data)  | 
                                                        |
| 1050 | + : false;  | 
                                                        |
| 1051 | + // if ANY of these updates fail then we want the appropriate global error message  | 
                                                        |
| 1052 | + $att_success = ! $att_success ? $att_success : $_success;  | 
                                                        |
| 1053 | + }  | 
                                                        |
| 1054 | + // any errors?  | 
                                                        |
| 1055 | +		if ($success && false === $att_success) { | 
                                                        |
| 1056 | + EE_Error::add_error(  | 
                                                        |
| 1057 | + esc_html__(  | 
                                                        |
| 1058 | + 'Event Details saved successfully but something went wrong with saving attachments.',  | 
                                                        |
| 1059 | + 'event_espresso'  | 
                                                        |
| 1060 | + ),  | 
                                                        |
| 1061 | + __FILE__,  | 
                                                        |
| 1062 | + __FUNCTION__,  | 
                                                        |
| 1063 | + __LINE__  | 
                                                        |
| 1064 | + );  | 
                                                        |
| 1065 | +		} elseif ($success === false) { | 
                                                        |
| 1066 | + EE_Error::add_error(  | 
                                                        |
| 1067 | +				esc_html__('Event Details did not save successfully.', 'event_espresso'), | 
                                                        |
| 1068 | + __FILE__,  | 
                                                        |
| 1069 | + __FUNCTION__,  | 
                                                        |
| 1070 | + __LINE__  | 
                                                        |
| 1071 | + );  | 
                                                        |
| 1072 | + }  | 
                                                        |
| 1073 | + }  | 
                                                        |
| 1074 | +  | 
                                                        |
| 1075 | +  | 
                                                        |
| 1076 | + /**  | 
                                                        |
| 1077 | + * @see parent::restore_item()  | 
                                                        |
| 1078 | + * @param int $post_id  | 
                                                        |
| 1079 | + * @param int $revision_id  | 
                                                        |
| 1080 | + */  | 
                                                        |
| 1081 | + protected function _restore_cpt_item($post_id, $revision_id)  | 
                                                        |
| 1082 | +	{ | 
                                                        |
| 1083 | + // copy existing event meta to new post  | 
                                                        |
| 1084 | + $post_evt = $this->_event_model()->get_one_by_ID($post_id);  | 
                                                        |
| 1085 | +		if ($post_evt instanceof EE_Event) { | 
                                                        |
| 1086 | + // meta revision restore  | 
                                                        |
| 1087 | + $post_evt->restore_revision($revision_id);  | 
                                                        |
| 1088 | + // related objs restore  | 
                                                        |
| 1089 | +			$post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price')); | 
                                                        |
| 1090 | + }  | 
                                                        |
| 1091 | + }  | 
                                                        |
| 1092 | +  | 
                                                        |
| 1093 | +  | 
                                                        |
| 1094 | + /**  | 
                                                        |
| 1095 | + * Attach the venue to the Event  | 
                                                        |
| 1096 | + *  | 
                                                        |
| 1097 | + * @param \EE_Event $evtobj Event Object to add the venue to  | 
                                                        |
| 1098 | + * @param array $data The request data from the form  | 
                                                        |
| 1099 | + * @return bool Success or fail.  | 
                                                        |
| 1100 | + */  | 
                                                        |
| 1101 | + protected function _default_venue_update(\EE_Event $evtobj, $data)  | 
                                                        |
| 1102 | +	{ | 
                                                        |
| 1103 | + require_once(EE_MODELS . 'EEM_Venue.model.php');  | 
                                                        |
| 1104 | +		$venue_model = EE_Registry::instance()->load_model('Venue'); | 
                                                        |
| 1105 | + $rows_affected = null;  | 
                                                        |
| 1106 | + $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;  | 
                                                        |
| 1107 | + // very important. If we don't have a venue name...  | 
                                                        |
| 1108 | + // then we'll get out because not necessary to create empty venue  | 
                                                        |
| 1109 | +		if (empty($data['venue_title'])) { | 
                                                        |
| 1110 | + return false;  | 
                                                        |
| 1111 | + }  | 
                                                        |
| 1112 | + $venue_array = array(  | 
                                                        |
| 1113 | +			'VNU_wp_user'         => $evtobj->get('EVT_wp_user'), | 
                                                        |
| 1114 | + 'VNU_name' => ! empty($data['venue_title']) ? $data['venue_title'] : null,  | 
                                                        |
| 1115 | + 'VNU_desc' => ! empty($data['venue_description']) ? $data['venue_description'] : null,  | 
                                                        |
| 1116 | + 'VNU_identifier' => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,  | 
                                                        |
| 1117 | + 'VNU_short_desc' => ! empty($data['venue_short_description']) ? $data['venue_short_description']  | 
                                                        |
| 1118 | + : null,  | 
                                                        |
| 1119 | + 'VNU_address' => ! empty($data['address']) ? $data['address'] : null,  | 
                                                        |
| 1120 | + 'VNU_address2' => ! empty($data['address2']) ? $data['address2'] : null,  | 
                                                        |
| 1121 | + 'VNU_city' => ! empty($data['city']) ? $data['city'] : null,  | 
                                                        |
| 1122 | + 'STA_ID' => ! empty($data['state']) ? $data['state'] : null,  | 
                                                        |
| 1123 | + 'CNT_ISO' => ! empty($data['countries']) ? $data['countries'] : null,  | 
                                                        |
| 1124 | + 'VNU_zip' => ! empty($data['zip']) ? $data['zip'] : null,  | 
                                                        |
| 1125 | + 'VNU_phone' => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,  | 
                                                        |
| 1126 | + 'VNU_capacity' => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,  | 
                                                        |
| 1127 | + 'VNU_url' => ! empty($data['venue_url']) ? $data['venue_url'] : null,  | 
                                                        |
| 1128 | + 'VNU_virtual_phone' => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,  | 
                                                        |
| 1129 | + 'VNU_virtual_url' => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,  | 
                                                        |
| 1130 | + 'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,  | 
                                                        |
| 1131 | + 'status' => 'publish',  | 
                                                        |
| 1132 | + );  | 
                                                        |
| 1133 | + // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.  | 
                                                        |
| 1134 | +		if (! empty($venue_id)) { | 
                                                        |
| 1135 | + $update_where = array($venue_model->primary_key_name() => $venue_id);  | 
                                                        |
| 1136 | + $rows_affected = $venue_model->update($venue_array, array($update_where));  | 
                                                        |
| 1137 | + // we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.  | 
                                                        |
| 1138 | + $evtobj->_add_relation_to($venue_id, 'Venue');  | 
                                                        |
| 1139 | + return $rows_affected > 0 ? true : false;  | 
                                                        |
| 1140 | +		} else { | 
                                                        |
| 1141 | + // we insert the venue  | 
                                                        |
| 1142 | + $venue_id = $venue_model->insert($venue_array);  | 
                                                        |
| 1143 | + $evtobj->_add_relation_to($venue_id, 'Venue');  | 
                                                        |
| 1144 | + return ! empty($venue_id) ? true : false;  | 
                                                        |
| 1145 | + }  | 
                                                        |
| 1146 | + // when we have the ancestor come in it's already been handled by the revision save.  | 
                                                        |
| 1147 | + }  | 
                                                        |
| 1148 | +  | 
                                                        |
| 1149 | +  | 
                                                        |
| 1150 | + /**  | 
                                                        |
| 1151 | + * Handles saving everything related to Tickets (datetimes, tickets, prices)  | 
                                                        |
| 1152 | + *  | 
                                                        |
| 1153 | + * @param EE_Event $evtobj The Event object we're attaching data to  | 
                                                        |
| 1154 | + * @param array $data The request data from the form  | 
                                                        |
| 1155 | + * @return array  | 
                                                        |
| 1156 | + */  | 
                                                        |
| 1157 | + protected function _default_tickets_update(EE_Event $evtobj, $data)  | 
                                                        |
| 1158 | +	{ | 
                                                        |
| 1159 | + $success = true;  | 
                                                        |
| 1160 | + $saved_dtt = null;  | 
                                                        |
| 1161 | + $saved_tickets = array();  | 
                                                        |
| 1162 | +		$incoming_date_formats = array('Y-m-d', 'h:i a'); | 
                                                        |
| 1163 | +		foreach ($data['edit_event_datetimes'] as $row => $dtt) { | 
                                                        |
| 1164 | + // trim all values to ensure any excess whitespace is removed.  | 
                                                        |
| 1165 | +			$dtt = array_map('trim', $dtt); | 
                                                        |
| 1166 | + $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']  | 
                                                        |
| 1167 | + : $dtt['DTT_EVT_start'];  | 
                                                        |
| 1168 | + $datetime_values = array(  | 
                                                        |
| 1169 | + 'DTT_ID' => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,  | 
                                                        |
| 1170 | + 'DTT_EVT_start' => $dtt['DTT_EVT_start'],  | 
                                                        |
| 1171 | + 'DTT_EVT_end' => $dtt['DTT_EVT_end'],  | 
                                                        |
| 1172 | + 'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],  | 
                                                        |
| 1173 | + 'DTT_order' => $row,  | 
                                                        |
| 1174 | + );  | 
                                                        |
| 1175 | + // if we have an id then let's get existing object first and then set the new values. Otherwise we instantiate a new object for save.  | 
                                                        |
| 1176 | +			if (! empty($dtt['DTT_ID'])) { | 
                                                        |
| 1177 | + $DTM = EE_Registry::instance()  | 
                                                        |
| 1178 | +								  ->load_model('Datetime', array($evtobj->get_timezone())) | 
                                                        |
| 1179 | + ->get_one_by_ID($dtt['DTT_ID']);  | 
                                                        |
| 1180 | + $DTM->set_date_format($incoming_date_formats[0]);  | 
                                                        |
| 1181 | + $DTM->set_time_format($incoming_date_formats[1]);  | 
                                                        |
| 1182 | +				foreach ($datetime_values as $field => $value) { | 
                                                        |
| 1183 | + $DTM->set($field, $value);  | 
                                                        |
| 1184 | + }  | 
                                                        |
| 1185 | + // make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it. We need to do this so we dont' TRASH the parent DTT.  | 
                                                        |
| 1186 | + $saved_dtts[ $DTM->ID() ] = $DTM;  | 
                                                        |
| 1187 | +			} else { | 
                                                        |
| 1188 | + $DTM = EE_Registry::instance()->load_class(  | 
                                                        |
| 1189 | + 'Datetime',  | 
                                                        |
| 1190 | + array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats),  | 
                                                        |
| 1191 | + false,  | 
                                                        |
| 1192 | + false  | 
                                                        |
| 1193 | + );  | 
                                                        |
| 1194 | +				foreach ($datetime_values as $field => $value) { | 
                                                        |
| 1195 | + $DTM->set($field, $value);  | 
                                                        |
| 1196 | + }  | 
                                                        |
| 1197 | + }  | 
                                                        |
| 1198 | + $DTM->save();  | 
                                                        |
| 1199 | + $DTT = $evtobj->_add_relation_to($DTM, 'Datetime');  | 
                                                        |
| 1200 | + // load DTT helper  | 
                                                        |
| 1201 | + // before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.  | 
                                                        |
| 1202 | +			if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) { | 
                                                        |
| 1203 | +				$DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start')); | 
                                                        |
| 1204 | + $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');  | 
                                                        |
| 1205 | + $DTT->save();  | 
                                                        |
| 1206 | + }  | 
                                                        |
| 1207 | + // now we got to make sure we add the new DTT_ID to the $saved_dtts array because it is possible there was a new one created for the autosave.  | 
                                                        |
| 1208 | + $saved_dtt = $DTT;  | 
                                                        |
| 1209 | + $success = ! $success ? $success : $DTT;  | 
                                                        |
| 1210 | + // if ANY of these updates fail then we want the appropriate global error message.  | 
                                                        |
| 1211 | + // //todo this is actually sucky we need a better error message but this is what it is for now.  | 
                                                        |
| 1212 | + }  | 
                                                        |
| 1213 | + // no dtts get deleted so we don't do any of that logic here.  | 
                                                        |
| 1214 | + // update tickets next  | 
                                                        |
| 1215 | +		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); | 
                                                        |
| 1216 | +		foreach ($data['edit_tickets'] as $row => $tkt) { | 
                                                        |
| 1217 | +			$incoming_date_formats = array('Y-m-d', 'h:i a'); | 
                                                        |
| 1218 | + $update_prices = false;  | 
                                                        |
| 1219 | + $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount'])  | 
                                                        |
| 1220 | + ? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0;  | 
                                                        |
| 1221 | + // trim inputs to ensure any excess whitespace is removed.  | 
                                                        |
| 1222 | +			$tkt = array_map('trim', $tkt); | 
                                                        |
| 1223 | +			if (empty($tkt['TKT_start_date'])) { | 
                                                        |
| 1224 | + // let's use now in the set timezone.  | 
                                                        |
| 1225 | +				$now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); | 
                                                        |
| 1226 | + $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);  | 
                                                        |
| 1227 | + }  | 
                                                        |
| 1228 | +			if (empty($tkt['TKT_end_date'])) { | 
                                                        |
| 1229 | + // use the start date of the first datetime  | 
                                                        |
| 1230 | + $dtt = $evtobj->first_datetime();  | 
                                                        |
| 1231 | + $tkt['TKT_end_date'] = $dtt->start_date_and_time(  | 
                                                        |
| 1232 | + $incoming_date_formats[0],  | 
                                                        |
| 1233 | + $incoming_date_formats[1]  | 
                                                        |
| 1234 | + );  | 
                                                        |
| 1235 | + }  | 
                                                        |
| 1236 | + $TKT_values = array(  | 
                                                        |
| 1237 | + 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,  | 
                                                        |
| 1238 | + 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,  | 
                                                        |
| 1239 | + 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',  | 
                                                        |
| 1240 | + 'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',  | 
                                                        |
| 1241 | + 'TKT_start_date' => $tkt['TKT_start_date'],  | 
                                                        |
| 1242 | + 'TKT_end_date' => $tkt['TKT_end_date'],  | 
                                                        |
| 1243 | + 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],  | 
                                                        |
| 1244 | + 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],  | 
                                                        |
| 1245 | + 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],  | 
                                                        |
| 1246 | + 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],  | 
                                                        |
| 1247 | + 'TKT_row' => $row,  | 
                                                        |
| 1248 | + 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,  | 
                                                        |
| 1249 | + 'TKT_price' => $ticket_price,  | 
                                                        |
| 1250 | + );  | 
                                                        |
| 1251 | + // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well.  | 
                                                        |
| 1252 | +			if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { | 
                                                        |
| 1253 | + $TKT_values['TKT_ID'] = 0;  | 
                                                        |
| 1254 | + $TKT_values['TKT_is_default'] = 0;  | 
                                                        |
| 1255 | + $TKT_values['TKT_price'] = $ticket_price;  | 
                                                        |
| 1256 | + $update_prices = true;  | 
                                                        |
| 1257 | + }  | 
                                                        |
| 1258 | + // if we have a TKT_ID then we need to get that existing TKT_obj and update it  | 
                                                        |
| 1259 | + // we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.  | 
                                                        |
| 1260 | + // keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived.  | 
                                                        |
| 1261 | +			if (! empty($tkt['TKT_ID'])) { | 
                                                        |
| 1262 | + $TKT = EE_Registry::instance()  | 
                                                        |
| 1263 | +								  ->load_model('Ticket', array($evtobj->get_timezone())) | 
                                                        |
| 1264 | + ->get_one_by_ID($tkt['TKT_ID']);  | 
                                                        |
| 1265 | +				if ($TKT instanceof EE_Ticket) { | 
                                                        |
| 1266 | + $ticket_sold = $TKT->count_related(  | 
                                                        |
| 1267 | + 'Registration',  | 
                                                        |
| 1268 | + array(  | 
                                                        |
| 1269 | + array(  | 
                                                        |
| 1270 | + 'STS_ID' => array(  | 
                                                        |
| 1271 | + 'NOT IN',  | 
                                                        |
| 1272 | + array(EEM_Registration::status_id_incomplete),  | 
                                                        |
| 1273 | + ),  | 
                                                        |
| 1274 | + ),  | 
                                                        |
| 1275 | + )  | 
                                                        |
| 1276 | + ) > 0 ? true : false;  | 
                                                        |
| 1277 | + // let's just check the total price for the existing ticket and determine if it matches the new total price. if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket.  | 
                                                        |
| 1278 | +					$create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price') | 
                                                        |
| 1279 | +									  && ! $TKT->get('TKT_deleted'); | 
                                                        |
| 1280 | + $TKT->set_date_format($incoming_date_formats[0]);  | 
                                                        |
| 1281 | + $TKT->set_time_format($incoming_date_formats[1]);  | 
                                                        |
| 1282 | + // set new values  | 
                                                        |
| 1283 | +					foreach ($TKT_values as $field => $value) { | 
                                                        |
| 1284 | +						if ($field == 'TKT_qty') { | 
                                                        |
| 1285 | + $TKT->set_qty($value);  | 
                                                        |
| 1286 | +						} else { | 
                                                        |
| 1287 | + $TKT->set($field, $value);  | 
                                                        |
| 1288 | + }  | 
                                                        |
| 1289 | + }  | 
                                                        |
| 1290 | + // if $create_new_TKT is false then we can safely update the existing ticket. Otherwise we have to create a new ticket.  | 
                                                        |
| 1291 | +					if ($create_new_TKT) { | 
                                                        |
| 1292 | + // archive the old ticket first  | 
                                                        |
| 1293 | +						$TKT->set('TKT_deleted', 1); | 
                                                        |
| 1294 | + $TKT->save();  | 
                                                        |
| 1295 | + // make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.  | 
                                                        |
| 1296 | + $saved_tickets[ $TKT->ID() ] = $TKT;  | 
                                                        |
| 1297 | + // create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it.  | 
                                                        |
| 1298 | + $TKT = clone $TKT;  | 
                                                        |
| 1299 | +						$TKT->set('TKT_ID', 0); | 
                                                        |
| 1300 | +						$TKT->set('TKT_deleted', 0); | 
                                                        |
| 1301 | +						$TKT->set('TKT_price', $ticket_price); | 
                                                        |
| 1302 | +						$TKT->set('TKT_sold', 0); | 
                                                        |
| 1303 | + // now we need to make sure that $new prices are created as well and attached to new ticket.  | 
                                                        |
| 1304 | + $update_prices = true;  | 
                                                        |
| 1305 | + }  | 
                                                        |
| 1306 | + // make sure price is set if it hasn't been already  | 
                                                        |
| 1307 | +					$TKT->set('TKT_price', $ticket_price); | 
                                                        |
| 1308 | + }  | 
                                                        |
| 1309 | +			} else { | 
                                                        |
| 1310 | + // no TKT_id so a new TKT  | 
                                                        |
| 1311 | + $TKT_values['TKT_price'] = $ticket_price;  | 
                                                        |
| 1312 | +				$TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false); | 
                                                        |
| 1313 | +				if ($TKT instanceof EE_Ticket) { | 
                                                        |
| 1314 | + // need to reset values to properly account for the date formats  | 
                                                        |
| 1315 | + $TKT->set_date_format($incoming_date_formats[0]);  | 
                                                        |
| 1316 | + $TKT->set_time_format($incoming_date_formats[1]);  | 
                                                        |
| 1317 | + $TKT->set_timezone($evtobj->get_timezone());  | 
                                                        |
| 1318 | + // set new values  | 
                                                        |
| 1319 | +					foreach ($TKT_values as $field => $value) { | 
                                                        |
| 1320 | +						if ($field == 'TKT_qty') { | 
                                                        |
| 1321 | + $TKT->set_qty($value);  | 
                                                        |
| 1322 | +						} else { | 
                                                        |
| 1323 | + $TKT->set($field, $value);  | 
                                                        |
| 1324 | + }  | 
                                                        |
| 1325 | + }  | 
                                                        |
| 1326 | + $update_prices = true;  | 
                                                        |
| 1327 | + }  | 
                                                        |
| 1328 | + }  | 
                                                        |
| 1329 | + // cap ticket qty by datetime reg limits  | 
                                                        |
| 1330 | +			$TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit'))); | 
                                                        |
| 1331 | + // update ticket.  | 
                                                        |
| 1332 | + $TKT->save();  | 
                                                        |
| 1333 | + // before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.  | 
                                                        |
| 1334 | +			if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) { | 
                                                        |
| 1335 | +				$TKT->set('TKT_end_date', $TKT->get('TKT_start_date')); | 
                                                        |
| 1336 | + $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');  | 
                                                        |
| 1337 | + $TKT->save();  | 
                                                        |
| 1338 | + }  | 
                                                        |
| 1339 | + // initially let's add the ticket to the dtt  | 
                                                        |
| 1340 | + $saved_dtt->_add_relation_to($TKT, 'Ticket');  | 
                                                        |
| 1341 | + $saved_tickets[ $TKT->ID() ] = $TKT;  | 
                                                        |
| 1342 | + // add prices to ticket  | 
                                                        |
| 1343 | + $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices);  | 
                                                        |
| 1344 | + }  | 
                                                        |
| 1345 | + // however now we need to handle permanently deleting tickets via the ui. Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db.  | 
                                                        |
| 1346 | + $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;  | 
                                                        |
| 1347 | + $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));  | 
                                                        |
| 1348 | +		foreach ($tickets_removed as $id) { | 
                                                        |
| 1349 | + $id = absint($id);  | 
                                                        |
| 1350 | + // get the ticket for this id  | 
                                                        |
| 1351 | +			$tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); | 
                                                        |
| 1352 | + // need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold)  | 
                                                        |
| 1353 | +			$dtts = $tkt_to_remove->get_many_related('Datetime'); | 
                                                        |
| 1354 | +			foreach ($dtts as $dtt) { | 
                                                        |
| 1355 | + $tkt_to_remove->_remove_relation_to($dtt, 'Datetime');  | 
                                                        |
| 1356 | + }  | 
                                                        |
| 1357 | + // need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))  | 
                                                        |
| 1358 | +			$tkt_to_remove->delete_related_permanently('Price'); | 
                                                        |
| 1359 | + // finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)  | 
                                                        |
| 1360 | + $tkt_to_remove->delete_permanently();  | 
                                                        |
| 1361 | + }  | 
                                                        |
| 1362 | + return array($saved_dtt, $saved_tickets);  | 
                                                        |
| 1363 | + }  | 
                                                        |
| 1364 | +  | 
                                                        |
| 1365 | +  | 
                                                        |
| 1366 | + /**  | 
                                                        |
| 1367 | + * This attaches a list of given prices to a ticket.  | 
                                                        |
| 1368 | + * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change  | 
                                                        |
| 1369 | + * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old  | 
                                                        |
| 1370 | + * price info and prices are automatically "archived" via the ticket.  | 
                                                        |
| 1371 | + *  | 
                                                        |
| 1372 | + * @access private  | 
                                                        |
| 1373 | + * @param array $prices Array of prices from the form.  | 
                                                        |
| 1374 | + * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to.  | 
                                                        |
| 1375 | + * @param bool $new_prices Whether attach existing incoming prices or create new ones.  | 
                                                        |
| 1376 | + * @return void  | 
                                                        |
| 1377 | + */  | 
                                                        |
| 1378 | + private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)  | 
                                                        |
| 1379 | +	{ | 
                                                        |
| 1380 | +		foreach ($prices as $row => $prc) { | 
                                                        |
| 1381 | + $PRC_values = array(  | 
                                                        |
| 1382 | + 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,  | 
                                                        |
| 1383 | + 'PRT_ID' => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,  | 
                                                        |
| 1384 | + 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,  | 
                                                        |
| 1385 | + 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',  | 
                                                        |
| 1386 | + 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',  | 
                                                        |
| 1387 | + 'PRC_is_default' => 0, // make sure prices are NOT set as default from this context  | 
                                                        |
| 1388 | + 'PRC_order' => $row,  | 
                                                        |
| 1389 | + );  | 
                                                        |
| 1390 | +			if ($new_prices || empty($PRC_values['PRC_ID'])) { | 
                                                        |
| 1391 | + $PRC_values['PRC_ID'] = 0;  | 
                                                        |
| 1392 | +				$PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false); | 
                                                        |
| 1393 | +			} else { | 
                                                        |
| 1394 | +				$PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); | 
                                                        |
| 1395 | + // update this price with new values  | 
                                                        |
| 1396 | +				foreach ($PRC_values as $field => $newprc) { | 
                                                        |
| 1397 | + $PRC->set($field, $newprc);  | 
                                                        |
| 1398 | + }  | 
                                                        |
| 1399 | + $PRC->save();  | 
                                                        |
| 1400 | + }  | 
                                                        |
| 1401 | + $ticket->_add_relation_to($PRC, 'Price');  | 
                                                        |
| 1402 | + }  | 
                                                        |
| 1403 | + }  | 
                                                        |
| 1404 | +  | 
                                                        |
| 1405 | +  | 
                                                        |
| 1406 | + /**  | 
                                                        |
| 1407 | + * Add in our autosave ajax handlers  | 
                                                        |
| 1408 | + *  | 
                                                        |
| 1409 | + */  | 
                                                        |
| 1410 | + protected function _ee_autosave_create_new()  | 
                                                        |
| 1411 | +	{ | 
                                                        |
| 1412 | + }  | 
                                                        |
| 1413 | +  | 
                                                        |
| 1414 | +  | 
                                                        |
| 1415 | + /**  | 
                                                        |
| 1416 | + * More autosave handlers.  | 
                                                        |
| 1417 | + */  | 
                                                        |
| 1418 | + protected function _ee_autosave_edit()  | 
                                                        |
| 1419 | +	{ | 
                                                        |
| 1420 | + return; // TEMPORARILY EXITING CAUSE THIS IS A TODO  | 
                                                        |
| 1421 | + }  | 
                                                        |
| 1422 | +  | 
                                                        |
| 1423 | +  | 
                                                        |
| 1424 | + /**  | 
                                                        |
| 1425 | + * _generate_publish_box_extra_content  | 
                                                        |
| 1426 | + */  | 
                                                        |
| 1427 | + private function _generate_publish_box_extra_content()  | 
                                                        |
| 1428 | +	{ | 
                                                        |
| 1429 | + // load formatter helper  | 
                                                        |
| 1430 | + // args for getting related registrations  | 
                                                        |
| 1431 | + $approved_query_args = array(  | 
                                                        |
| 1432 | + array(  | 
                                                        |
| 1433 | + 'REG_deleted' => 0,  | 
                                                        |
| 1434 | + 'STS_ID' => EEM_Registration::status_id_approved,  | 
                                                        |
| 1435 | + ),  | 
                                                        |
| 1436 | + );  | 
                                                        |
| 1437 | + $not_approved_query_args = array(  | 
                                                        |
| 1438 | + array(  | 
                                                        |
| 1439 | + 'REG_deleted' => 0,  | 
                                                        |
| 1440 | + 'STS_ID' => EEM_Registration::status_id_not_approved,  | 
                                                        |
| 1441 | + ),  | 
                                                        |
| 1442 | + );  | 
                                                        |
| 1443 | + $pending_payment_query_args = array(  | 
                                                        |
| 1444 | + array(  | 
                                                        |
| 1445 | + 'REG_deleted' => 0,  | 
                                                        |
| 1446 | + 'STS_ID' => EEM_Registration::status_id_pending_payment,  | 
                                                        |
| 1447 | + ),  | 
                                                        |
| 1448 | + );  | 
                                                        |
| 1449 | + // publish box  | 
                                                        |
| 1450 | + $publish_box_extra_args = array(  | 
                                                        |
| 1451 | + 'view_approved_reg_url' => add_query_arg(  | 
                                                        |
| 1452 | + array(  | 
                                                        |
| 1453 | + 'action' => 'default',  | 
                                                        |
| 1454 | + 'event_id' => $this->_cpt_model_obj->ID(),  | 
                                                        |
| 1455 | + '_reg_status' => EEM_Registration::status_id_approved,  | 
                                                        |
| 1456 | + ),  | 
                                                        |
| 1457 | + REG_ADMIN_URL  | 
                                                        |
| 1458 | + ),  | 
                                                        |
| 1459 | + 'view_not_approved_reg_url' => add_query_arg(  | 
                                                        |
| 1460 | + array(  | 
                                                        |
| 1461 | + 'action' => 'default',  | 
                                                        |
| 1462 | + 'event_id' => $this->_cpt_model_obj->ID(),  | 
                                                        |
| 1463 | + '_reg_status' => EEM_Registration::status_id_not_approved,  | 
                                                        |
| 1464 | + ),  | 
                                                        |
| 1465 | + REG_ADMIN_URL  | 
                                                        |
| 1466 | + ),  | 
                                                        |
| 1467 | + 'view_pending_payment_reg_url' => add_query_arg(  | 
                                                        |
| 1468 | + array(  | 
                                                        |
| 1469 | + 'action' => 'default',  | 
                                                        |
| 1470 | + 'event_id' => $this->_cpt_model_obj->ID(),  | 
                                                        |
| 1471 | + '_reg_status' => EEM_Registration::status_id_pending_payment,  | 
                                                        |
| 1472 | + ),  | 
                                                        |
| 1473 | + REG_ADMIN_URL  | 
                                                        |
| 1474 | + ),  | 
                                                        |
| 1475 | + 'approved_regs' => $this->_cpt_model_obj->count_related(  | 
                                                        |
| 1476 | + 'Registration',  | 
                                                        |
| 1477 | + $approved_query_args  | 
                                                        |
| 1478 | + ),  | 
                                                        |
| 1479 | + 'not_approved_regs' => $this->_cpt_model_obj->count_related(  | 
                                                        |
| 1480 | + 'Registration',  | 
                                                        |
| 1481 | + $not_approved_query_args  | 
                                                        |
| 1482 | + ),  | 
                                                        |
| 1483 | + 'pending_payment_regs' => $this->_cpt_model_obj->count_related(  | 
                                                        |
| 1484 | + 'Registration',  | 
                                                        |
| 1485 | + $pending_payment_query_args  | 
                                                        |
| 1486 | + ),  | 
                                                        |
| 1487 | + 'misc_pub_section_class' => apply_filters(  | 
                                                        |
| 1488 | + 'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',  | 
                                                        |
| 1489 | + 'misc-pub-section'  | 
                                                        |
| 1490 | + ),  | 
                                                        |
| 1491 | + );  | 
                                                        |
| 1492 | + ob_start();  | 
                                                        |
| 1493 | + do_action(  | 
                                                        |
| 1494 | + 'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',  | 
                                                        |
| 1495 | + $this->_cpt_model_obj  | 
                                                        |
| 1496 | + );  | 
                                                        |
| 1497 | + $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();  | 
                                                        |
| 1498 | + // load template  | 
                                                        |
| 1499 | + EEH_Template::display_template(  | 
                                                        |
| 1500 | + EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',  | 
                                                        |
| 1501 | + $publish_box_extra_args  | 
                                                        |
| 1502 | + );  | 
                                                        |
| 1503 | + }  | 
                                                        |
| 1504 | +  | 
                                                        |
| 1505 | +  | 
                                                        |
| 1506 | + /**  | 
                                                        |
| 1507 | + * @return EE_Event  | 
                                                        |
| 1508 | + */  | 
                                                        |
| 1509 | + public function get_event_object()  | 
                                                        |
| 1510 | +	{ | 
                                                        |
| 1511 | + return $this->_cpt_model_obj;  | 
                                                        |
| 1512 | + }  | 
                                                        |
| 1513 | +  | 
                                                        |
| 1514 | +  | 
                                                        |
| 1515 | +  | 
                                                        |
| 1516 | +  | 
                                                        |
| 1517 | + /** METABOXES * */  | 
                                                        |
| 1518 | + /**  | 
                                                        |
| 1519 | + * _register_event_editor_meta_boxes  | 
                                                        |
| 1520 | + * add all metaboxes related to the event_editor  | 
                                                        |
| 1521 | + *  | 
                                                        |
| 1522 | + * @return void  | 
                                                        |
| 1523 | + */  | 
                                                        |
| 1524 | + protected function _register_event_editor_meta_boxes()  | 
                                                        |
| 1525 | +	{ | 
                                                        |
| 1526 | + $this->verify_cpt_object();  | 
                                                        |
| 1527 | + add_meta_box(  | 
                                                        |
| 1528 | + 'espresso_event_editor_tickets',  | 
                                                        |
| 1529 | +			esc_html__('Event Datetime & Ticket', 'event_espresso'), | 
                                                        |
| 1530 | + array($this, 'ticket_metabox'),  | 
                                                        |
| 1531 | + $this->page_slug,  | 
                                                        |
| 1532 | + 'normal',  | 
                                                        |
| 1533 | + 'high'  | 
                                                        |
| 1534 | + );  | 
                                                        |
| 1535 | + add_meta_box(  | 
                                                        |
| 1536 | + 'espresso_event_editor_event_options',  | 
                                                        |
| 1537 | +			esc_html__('Event Registration Options', 'event_espresso'), | 
                                                        |
| 1538 | + array($this, 'registration_options_meta_box'),  | 
                                                        |
| 1539 | + $this->page_slug,  | 
                                                        |
| 1540 | + 'side',  | 
                                                        |
| 1541 | + 'default'  | 
                                                        |
| 1542 | + );  | 
                                                        |
| 1543 | + // NOTE: if you're looking for other metaboxes in here,  | 
                                                        |
| 1544 | + // where a metabox has a related management page in the admin  | 
                                                        |
| 1545 | + // you will find it setup in the related management page's "_Hooks" file.  | 
                                                        |
| 1546 | + // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".  | 
                                                        |
| 1547 | + }  | 
                                                        |
| 1548 | +  | 
                                                        |
| 1549 | +  | 
                                                        |
| 1550 | + /**  | 
                                                        |
| 1551 | + * @throws DomainException  | 
                                                        |
| 1552 | + * @throws EE_Error  | 
                                                        |
| 1553 | + */  | 
                                                        |
| 1554 | + public function ticket_metabox()  | 
                                                        |
| 1555 | +	{ | 
                                                        |
| 1556 | + $existing_datetime_ids = $existing_ticket_ids = array();  | 
                                                        |
| 1557 | + // defaults for template args  | 
                                                        |
| 1558 | + $template_args = array(  | 
                                                        |
| 1559 | + 'existing_datetime_ids' => '',  | 
                                                        |
| 1560 | + 'event_datetime_help_link' => '',  | 
                                                        |
| 1561 | + 'ticket_options_help_link' => '',  | 
                                                        |
| 1562 | + 'time' => null,  | 
                                                        |
| 1563 | + 'ticket_rows' => '',  | 
                                                        |
| 1564 | + 'existing_ticket_ids' => '',  | 
                                                        |
| 1565 | + 'total_ticket_rows' => 1,  | 
                                                        |
| 1566 | + 'ticket_js_structure' => '',  | 
                                                        |
| 1567 | + 'trash_icon' => 'ee-lock-icon',  | 
                                                        |
| 1568 | + 'disabled' => '',  | 
                                                        |
| 1569 | + );  | 
                                                        |
| 1570 | + $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;  | 
                                                        |
| 1571 | +		do_action('AHEE_log', __FILE__, __FUNCTION__, ''); | 
                                                        |
| 1572 | + /**  | 
                                                        |
| 1573 | + * 1. Start with retrieving Datetimes  | 
                                                        |
| 1574 | + * 2. Fore each datetime get related tickets  | 
                                                        |
| 1575 | + * 3. For each ticket get related prices  | 
                                                        |
| 1576 | + */  | 
                                                        |
| 1577 | +		$times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id); | 
                                                        |
| 1578 | + /** @type EE_Datetime $first_datetime */  | 
                                                        |
| 1579 | + $first_datetime = reset($times);  | 
                                                        |
| 1580 | + // do we get related tickets?  | 
                                                        |
| 1581 | + if ($first_datetime instanceof EE_Datetime  | 
                                                        |
| 1582 | + && $first_datetime->ID() !== 0  | 
                                                        |
| 1583 | +		) { | 
                                                        |
| 1584 | +			$existing_datetime_ids[] = $first_datetime->get('DTT_ID'); | 
                                                        |
| 1585 | + $template_args['time'] = $first_datetime;  | 
                                                        |
| 1586 | + $related_tickets = $first_datetime->tickets(  | 
                                                        |
| 1587 | + array(  | 
                                                        |
| 1588 | +					array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)), | 
                                                        |
| 1589 | + 'default_where_conditions' => 'none',  | 
                                                        |
| 1590 | + )  | 
                                                        |
| 1591 | + );  | 
                                                        |
| 1592 | +			if (! empty($related_tickets)) { | 
                                                        |
| 1593 | + $template_args['total_ticket_rows'] = count($related_tickets);  | 
                                                        |
| 1594 | + $row = 0;  | 
                                                        |
| 1595 | +				foreach ($related_tickets as $ticket) { | 
                                                        |
| 1596 | +					$existing_ticket_ids[] = $ticket->get('TKT_ID'); | 
                                                        |
| 1597 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);  | 
                                                        |
| 1598 | + $row++;  | 
                                                        |
| 1599 | + }  | 
                                                        |
| 1600 | +			} else { | 
                                                        |
| 1601 | + $template_args['total_ticket_rows'] = 1;  | 
                                                        |
| 1602 | + /** @type EE_Ticket $ticket */  | 
                                                        |
| 1603 | +				$ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object(); | 
                                                        |
| 1604 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);  | 
                                                        |
| 1605 | + }  | 
                                                        |
| 1606 | +		} else { | 
                                                        |
| 1607 | + $template_args['time'] = $times[0];  | 
                                                        |
| 1608 | + /** @type EE_Ticket $ticket */  | 
                                                        |
| 1609 | +			$ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets(); | 
                                                        |
| 1610 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]);  | 
                                                        |
| 1611 | + // NOTE: we're just sending the first default row  | 
                                                        |
| 1612 | + // (decaf can't manage default tickets so this should be sufficient);  | 
                                                        |
| 1613 | + }  | 
                                                        |
| 1614 | + $template_args['event_datetime_help_link'] = $this->_get_help_tab_link(  | 
                                                        |
| 1615 | + 'event_editor_event_datetimes_help_tab'  | 
                                                        |
| 1616 | + );  | 
                                                        |
| 1617 | +		$template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info'); | 
                                                        |
| 1618 | +		$template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); | 
                                                        |
| 1619 | +		$template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); | 
                                                        |
| 1620 | + $template_args['ticket_js_structure'] = $this->_get_ticket_row(  | 
                                                        |
| 1621 | +			EE_Registry::instance()->load_model('Ticket')->create_default_object(), | 
                                                        |
| 1622 | + true  | 
                                                        |
| 1623 | + );  | 
                                                        |
| 1624 | + $template = apply_filters(  | 
                                                        |
| 1625 | + 'FHEE__Events_Admin_Page__ticket_metabox__template',  | 
                                                        |
| 1626 | + EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'  | 
                                                        |
| 1627 | + );  | 
                                                        |
| 1628 | + EEH_Template::display_template($template, $template_args);  | 
                                                        |
| 1629 | + }  | 
                                                        |
| 1630 | +  | 
                                                        |
| 1631 | +  | 
                                                        |
| 1632 | + /**  | 
                                                        |
| 1633 | + * Setup an individual ticket form for the decaf event editor page  | 
                                                        |
| 1634 | + *  | 
                                                        |
| 1635 | + * @access private  | 
                                                        |
| 1636 | + * @param EE_Ticket $ticket the ticket object  | 
                                                        |
| 1637 | + * @param boolean $skeleton whether we're generating a skeleton for js manipulation  | 
                                                        |
| 1638 | + * @param int $row  | 
                                                        |
| 1639 | + * @return string generated html for the ticket row.  | 
                                                        |
| 1640 | + */  | 
                                                        |
| 1641 | + private function _get_ticket_row($ticket, $skeleton = false, $row = 0)  | 
                                                        |
| 1642 | +	{ | 
                                                        |
| 1643 | + $template_args = array(  | 
                                                        |
| 1644 | + 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(),  | 
                                                        |
| 1645 | + 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'  | 
                                                        |
| 1646 | + : '',  | 
                                                        |
| 1647 | + 'ticketrow' => $skeleton ? 'TICKETNUM' : $row,  | 
                                                        |
| 1648 | +			'TKT_ID'              => $ticket->get('TKT_ID'), | 
                                                        |
| 1649 | +			'TKT_name'            => $ticket->get('TKT_name'), | 
                                                        |
| 1650 | +			'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), | 
                                                        |
| 1651 | +			'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), | 
                                                        |
| 1652 | +			'TKT_is_default'      => $ticket->get('TKT_is_default'), | 
                                                        |
| 1653 | +			'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'), | 
                                                        |
| 1654 | + 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',  | 
                                                        |
| 1655 | +			'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'), | 
                                                        |
| 1656 | +			'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted'))) | 
                                                        |
| 1657 | +									 && (! empty($ticket) && $ticket->get('TKT_sold') === 0) | 
                                                        |
| 1658 | + ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',  | 
                                                        |
| 1659 | +			'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' | 
                                                        |
| 1660 | + : ' disabled=disabled',  | 
                                                        |
| 1661 | + );  | 
                                                        |
| 1662 | + $price = $ticket->ID() !== 0  | 
                                                        |
| 1663 | +			? $ticket->get_first_related('Price', array('default_where_conditions' => 'none')) | 
                                                        |
| 1664 | +			: EE_Registry::instance()->load_model('Price')->create_default_object(); | 
                                                        |
| 1665 | + $price_args = array(  | 
                                                        |
| 1666 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,  | 
                                                        |
| 1667 | +			'PRC_amount'            => $price->get('PRC_amount'), | 
                                                        |
| 1668 | +			'PRT_ID'                => $price->get('PRT_ID'), | 
                                                        |
| 1669 | +			'PRC_ID'                => $price->get('PRC_ID'), | 
                                                        |
| 1670 | +			'PRC_is_default'        => $price->get('PRC_is_default'), | 
                                                        |
| 1671 | + );  | 
                                                        |
| 1672 | + // make sure we have default start and end dates if skeleton  | 
                                                        |
| 1673 | + // handle rows that should NOT be empty  | 
                                                        |
| 1674 | +		if (empty($template_args['TKT_start_date'])) { | 
                                                        |
| 1675 | + // if empty then the start date will be now.  | 
                                                        |
| 1676 | +			$template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); | 
                                                        |
| 1677 | + }  | 
                                                        |
| 1678 | +		if (empty($template_args['TKT_end_date'])) { | 
                                                        |
| 1679 | + // get the earliest datetime (if present);  | 
                                                        |
| 1680 | + $earliest_dtt = $this->_cpt_model_obj->ID() > 0  | 
                                                        |
| 1681 | + ? $this->_cpt_model_obj->get_first_related(  | 
                                                        |
| 1682 | + 'Datetime',  | 
                                                        |
| 1683 | +					array('order_by' => array('DTT_EVT_start' => 'ASC')) | 
                                                        |
| 1684 | + )  | 
                                                        |
| 1685 | + : null;  | 
                                                        |
| 1686 | +			if (! empty($earliest_dtt)) { | 
                                                        |
| 1687 | +				$template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a'); | 
                                                        |
| 1688 | +			} else { | 
                                                        |
| 1689 | + $template_args['TKT_end_date'] = date(  | 
                                                        |
| 1690 | + 'Y-m-d h:i a',  | 
                                                        |
| 1691 | +					mktime(0, 0, 0, date("m"), date("d") + 7, date("Y")) | 
                                                        |
| 1692 | + );  | 
                                                        |
| 1693 | + }  | 
                                                        |
| 1694 | + }  | 
                                                        |
| 1695 | + $template_args = array_merge($template_args, $price_args);  | 
                                                        |
| 1696 | + $template = apply_filters(  | 
                                                        |
| 1697 | + 'FHEE__Events_Admin_Page__get_ticket_row__template',  | 
                                                        |
| 1698 | + EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',  | 
                                                        |
| 1699 | + $ticket  | 
                                                        |
| 1700 | + );  | 
                                                        |
| 1701 | + return EEH_Template::display_template($template, $template_args, true);  | 
                                                        |
| 1702 | + }  | 
                                                        |
| 1703 | +  | 
                                                        |
| 1704 | +  | 
                                                        |
| 1705 | + /**  | 
                                                        |
| 1706 | + * @throws DomainException  | 
                                                        |
| 1707 | + */  | 
                                                        |
| 1708 | + public function registration_options_meta_box()  | 
                                                        |
| 1709 | +	{ | 
                                                        |
| 1710 | + $yes_no_values = array(  | 
                                                        |
| 1711 | +			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), | 
                                                        |
| 1712 | +			array('id' => false, 'text' => esc_html__('No', 'event_espresso')), | 
                                                        |
| 1713 | + );  | 
                                                        |
| 1714 | + $default_reg_status_values = EEM_Registration::reg_status_array(  | 
                                                        |
| 1715 | + array(  | 
                                                        |
| 1716 | + EEM_Registration::status_id_cancelled,  | 
                                                        |
| 1717 | + EEM_Registration::status_id_declined,  | 
                                                        |
| 1718 | + EEM_Registration::status_id_incomplete,  | 
                                                        |
| 1719 | + ),  | 
                                                        |
| 1720 | + true  | 
                                                        |
| 1721 | + );  | 
                                                        |
| 1722 | +		// $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active()); | 
                                                        |
| 1723 | + $template_args['_event'] = $this->_cpt_model_obj;  | 
                                                        |
| 1724 | + $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);  | 
                                                        |
| 1725 | + $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();  | 
                                                        |
| 1726 | + $template_args['default_registration_status'] = EEH_Form_Fields::select_input(  | 
                                                        |
| 1727 | + 'default_reg_status',  | 
                                                        |
| 1728 | + $default_reg_status_values,  | 
                                                        |
| 1729 | + $this->_cpt_model_obj->default_registration_status()  | 
                                                        |
| 1730 | + );  | 
                                                        |
| 1731 | + $template_args['display_description'] = EEH_Form_Fields::select_input(  | 
                                                        |
| 1732 | + 'display_desc',  | 
                                                        |
| 1733 | + $yes_no_values,  | 
                                                        |
| 1734 | + $this->_cpt_model_obj->display_description()  | 
                                                        |
| 1735 | + );  | 
                                                        |
| 1736 | + $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(  | 
                                                        |
| 1737 | + 'display_ticket_selector',  | 
                                                        |
| 1738 | + $yes_no_values,  | 
                                                        |
| 1739 | + $this->_cpt_model_obj->display_ticket_selector(),  | 
                                                        |
| 1740 | + '',  | 
                                                        |
| 1741 | + '',  | 
                                                        |
| 1742 | + false  | 
                                                        |
| 1743 | + );  | 
                                                        |
| 1744 | + $template_args['additional_registration_options'] = apply_filters(  | 
                                                        |
| 1745 | + 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',  | 
                                                        |
| 1746 | + '',  | 
                                                        |
| 1747 | + $template_args,  | 
                                                        |
| 1748 | + $yes_no_values,  | 
                                                        |
| 1749 | + $default_reg_status_values  | 
                                                        |
| 1750 | + );  | 
                                                        |
| 1751 | + EEH_Template::display_template(  | 
                                                        |
| 1752 | + EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',  | 
                                                        |
| 1753 | + $template_args  | 
                                                        |
| 1754 | + );  | 
                                                        |
| 1755 | + }  | 
                                                        |
| 1756 | +  | 
                                                        |
| 1757 | +  | 
                                                        |
| 1758 | + /**  | 
                                                        |
| 1759 | + * _get_events()  | 
                                                        |
| 1760 | + * This method simply returns all the events (for the given _view and paging)  | 
                                                        |
| 1761 | + *  | 
                                                        |
| 1762 | + * @access public  | 
                                                        |
| 1763 | + * @param int $per_page count of items per page (20 default);  | 
                                                        |
| 1764 | + * @param int $current_page what is the current page being viewed.  | 
                                                        |
| 1765 | + * @param bool $count if TRUE then we just return a count of ALL events matching the given _view.  | 
                                                        |
| 1766 | + * If FALSE then we return an array of event objects  | 
                                                        |
| 1767 | + * that match the given _view and paging parameters.  | 
                                                        |
| 1768 | + * @return array an array of event objects.  | 
                                                        |
| 1769 | + */  | 
                                                        |
| 1770 | + public function get_events($per_page = 10, $current_page = 1, $count = false)  | 
                                                        |
| 1771 | +	{ | 
                                                        |
| 1772 | + $EEME = $this->_event_model();  | 
                                                        |
| 1773 | + $offset = ($current_page - 1) * $per_page;  | 
                                                        |
| 1774 | + $limit = $count ? null : $offset . ',' . $per_page;  | 
                                                        |
| 1775 | + $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';  | 
                                                        |
| 1776 | + $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";  | 
                                                        |
| 1777 | +		if (isset($this->_req_data['month_range'])) { | 
                                                        |
| 1778 | +			$pieces = explode(' ', $this->_req_data['month_range'], 3); | 
                                                        |
| 1779 | + // simulate the FIRST day of the month, that fixes issues for months like February  | 
                                                        |
| 1780 | + // where PHP doesn't know what to assume for date.  | 
                                                        |
| 1781 | + // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437  | 
                                                        |
| 1782 | +			$month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : ''; | 
                                                        |
| 1783 | + $year_r = ! empty($pieces[1]) ? $pieces[1] : '';  | 
                                                        |
| 1784 | + }  | 
                                                        |
| 1785 | + $where = array();  | 
                                                        |
| 1786 | + $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;  | 
                                                        |
| 1787 | + // determine what post_status our condition will have for the query.  | 
                                                        |
| 1788 | +		switch ($status) { | 
                                                        |
| 1789 | + case 'month':  | 
                                                        |
| 1790 | + case 'today':  | 
                                                        |
| 1791 | + case null:  | 
                                                        |
| 1792 | + case 'all':  | 
                                                        |
| 1793 | + break;  | 
                                                        |
| 1794 | + case 'draft':  | 
                                                        |
| 1795 | +				$where['status'] = array('IN', array('draft', 'auto-draft')); | 
                                                        |
| 1796 | + break;  | 
                                                        |
| 1797 | + default:  | 
                                                        |
| 1798 | + $where['status'] = $status;  | 
                                                        |
| 1799 | + }  | 
                                                        |
| 1800 | + // categories?  | 
                                                        |
| 1801 | + $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0  | 
                                                        |
| 1802 | + ? $this->_req_data['EVT_CAT'] : null;  | 
                                                        |
| 1803 | +		if (! empty($category)) { | 
                                                        |
| 1804 | + $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;  | 
                                                        |
| 1805 | + $where['Term_Taxonomy.term_id'] = $category;  | 
                                                        |
| 1806 | + }  | 
                                                        |
| 1807 | + // date where conditions  | 
                                                        |
| 1808 | +		$start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); | 
                                                        |
| 1809 | +		if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') { | 
                                                        |
| 1810 | + $DateTime = new DateTime(  | 
                                                        |
| 1811 | + $year_r . '-' . $month_r . '-01 00:00:00',  | 
                                                        |
| 1812 | + new DateTimeZone(EEM_Datetime::instance()->get_timezone())  | 
                                                        |
| 1813 | + );  | 
                                                        |
| 1814 | +			$start = $DateTime->format(implode(' ', $start_formats)); | 
                                                        |
| 1815 | + $end = $DateTime->setDate(  | 
                                                        |
| 1816 | + $year_r,  | 
                                                        |
| 1817 | + $month_r,  | 
                                                        |
| 1818 | + $DateTime  | 
                                                        |
| 1819 | +					->format('t') | 
                                                        |
| 1820 | + )->setTime(23, 59, 59)  | 
                                                        |
| 1821 | +							->format(implode(' ', $start_formats)); | 
                                                        |
| 1822 | +			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); | 
                                                        |
| 1823 | +		} elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') { | 
                                                        |
| 1824 | +			$DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone())); | 
                                                        |
| 1825 | +			$start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); | 
                                                        |
| 1826 | +			$end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats)); | 
                                                        |
| 1827 | +			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); | 
                                                        |
| 1828 | +		} elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') { | 
                                                        |
| 1829 | +			$now = date('Y-m-01'); | 
                                                        |
| 1830 | + $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));  | 
                                                        |
| 1831 | +			$start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); | 
                                                        |
| 1832 | +			$end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t')) | 
                                                        |
| 1833 | + ->setTime(23, 59, 59)  | 
                                                        |
| 1834 | +							->format(implode(' ', $start_formats)); | 
                                                        |
| 1835 | +			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); | 
                                                        |
| 1836 | + }  | 
                                                        |
| 1837 | +		if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { | 
                                                        |
| 1838 | + $where['EVT_wp_user'] = get_current_user_id();  | 
                                                        |
| 1839 | +		} else { | 
                                                        |
| 1840 | +			if (! isset($where['status'])) { | 
                                                        |
| 1841 | +				if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { | 
                                                        |
| 1842 | + $where['OR'] = array(  | 
                                                        |
| 1843 | +						'status*restrict_private' => array('!=', 'private'), | 
                                                        |
| 1844 | + 'AND' => array(  | 
                                                        |
| 1845 | +							'status*inclusive' => array('=', 'private'), | 
                                                        |
| 1846 | + 'EVT_wp_user' => get_current_user_id(),  | 
                                                        |
| 1847 | + ),  | 
                                                        |
| 1848 | + );  | 
                                                        |
| 1849 | + }  | 
                                                        |
| 1850 | + }  | 
                                                        |
| 1851 | + }  | 
                                                        |
| 1852 | +		if (isset($this->_req_data['EVT_wp_user'])) { | 
                                                        |
| 1853 | + if ($this->_req_data['EVT_wp_user'] != get_current_user_id()  | 
                                                        |
| 1854 | +				&& EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events') | 
                                                        |
| 1855 | +			) { | 
                                                        |
| 1856 | + $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];  | 
                                                        |
| 1857 | + }  | 
                                                        |
| 1858 | + }  | 
                                                        |
| 1859 | + // search query handling  | 
                                                        |
| 1860 | +		if (isset($this->_req_data['s'])) { | 
                                                        |
| 1861 | + $search_string = '%' . $this->_req_data['s'] . '%';  | 
                                                        |
| 1862 | + $where['OR'] = array(  | 
                                                        |
| 1863 | +				'EVT_name'       => array('LIKE', $search_string), | 
                                                        |
| 1864 | +				'EVT_desc'       => array('LIKE', $search_string), | 
                                                        |
| 1865 | +				'EVT_short_desc' => array('LIKE', $search_string), | 
                                                        |
| 1866 | + );  | 
                                                        |
| 1867 | + }  | 
                                                        |
| 1868 | + // filter events by venue.  | 
                                                        |
| 1869 | +		if (isset($this->_req_data['venue']) && ! empty($this->_req_data['venue'])) { | 
                                                        |
| 1870 | + $where['Venue.VNU_ID'] = absint($this->_req_data['venue']);  | 
                                                        |
| 1871 | + }  | 
                                                        |
| 1872 | +		$where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data); | 
                                                        |
| 1873 | + $query_params = apply_filters(  | 
                                                        |
| 1874 | + 'FHEE__Events_Admin_Page__get_events__query_params',  | 
                                                        |
| 1875 | + array(  | 
                                                        |
| 1876 | + $where,  | 
                                                        |
| 1877 | + 'limit' => $limit,  | 
                                                        |
| 1878 | + 'order_by' => $orderby,  | 
                                                        |
| 1879 | + 'order' => $order,  | 
                                                        |
| 1880 | + 'group_by' => 'EVT_ID',  | 
                                                        |
| 1881 | + ),  | 
                                                        |
| 1882 | + $this->_req_data  | 
                                                        |
| 1883 | + );  | 
                                                        |
| 1884 | + // let's first check if we have special requests coming in.  | 
                                                        |
| 1885 | +		if (isset($this->_req_data['active_status'])) { | 
                                                        |
| 1886 | +			switch ($this->_req_data['active_status']) { | 
                                                        |
| 1887 | + case 'upcoming':  | 
                                                        |
| 1888 | + return $EEME->get_upcoming_events($query_params, $count);  | 
                                                        |
| 1889 | + break;  | 
                                                        |
| 1890 | + case 'expired':  | 
                                                        |
| 1891 | + return $EEME->get_expired_events($query_params, $count);  | 
                                                        |
| 1892 | + break;  | 
                                                        |
| 1893 | + case 'active':  | 
                                                        |
| 1894 | + return $EEME->get_active_events($query_params, $count);  | 
                                                        |
| 1895 | + break;  | 
                                                        |
| 1896 | + case 'inactive':  | 
                                                        |
| 1897 | + return $EEME->get_inactive_events($query_params, $count);  | 
                                                        |
| 1898 | + break;  | 
                                                        |
| 1899 | + }  | 
                                                        |
| 1900 | + }  | 
                                                        |
| 1901 | +  | 
                                                        |
| 1902 | + $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params);  | 
                                                        |
| 1903 | + return $events;  | 
                                                        |
| 1904 | + }  | 
                                                        |
| 1905 | +  | 
                                                        |
| 1906 | +  | 
                                                        |
| 1907 | + /**  | 
                                                        |
| 1908 | + * handling for WordPress CPT actions (trash, restore, delete)  | 
                                                        |
| 1909 | + *  | 
                                                        |
| 1910 | + * @param string $post_id  | 
                                                        |
| 1911 | + */  | 
                                                        |
| 1912 | + public function trash_cpt_item($post_id)  | 
                                                        |
| 1913 | +	{ | 
                                                        |
| 1914 | + $this->_req_data['EVT_ID'] = $post_id;  | 
                                                        |
| 1915 | +		$this->_trash_or_restore_event('trash', false); | 
                                                        |
| 1916 | + }  | 
                                                        |
| 1917 | +  | 
                                                        |
| 1918 | +  | 
                                                        |
| 1919 | + /**  | 
                                                        |
| 1920 | + * @param string $post_id  | 
                                                        |
| 1921 | + */  | 
                                                        |
| 1922 | + public function restore_cpt_item($post_id)  | 
                                                        |
| 1923 | +	{ | 
                                                        |
| 1924 | + $this->_req_data['EVT_ID'] = $post_id;  | 
                                                        |
| 1925 | +		$this->_trash_or_restore_event('draft', false); | 
                                                        |
| 1926 | + }  | 
                                                        |
| 1927 | +  | 
                                                        |
| 1928 | +  | 
                                                        |
| 1929 | + /**  | 
                                                        |
| 1930 | + * @param string $post_id  | 
                                                        |
| 1931 | + */  | 
                                                        |
| 1932 | + public function delete_cpt_item($post_id)  | 
                                                        |
| 1933 | +	{ | 
                                                        |
| 1934 | +		throw new EE_Error(esc_html__('Please contact Event Espresso support with the details of what you did to produce this error.', 'event_espresso')); | 
                                                        |
| 1935 | + $this->_req_data['EVT_ID'] = $post_id;  | 
                                                        |
| 1936 | + $this->_delete_event();  | 
                                                        |
| 1937 | + }  | 
                                                        |
| 1938 | +  | 
                                                        |
| 1939 | +  | 
                                                        |
| 1940 | + /**  | 
                                                        |
| 1941 | + * _trash_or_restore_event  | 
                                                        |
| 1942 | + *  | 
                                                        |
| 1943 | + * @access protected  | 
                                                        |
| 1944 | + * @param string $event_status  | 
                                                        |
| 1945 | + * @param bool $redirect_after  | 
                                                        |
| 1946 | + */  | 
                                                        |
| 1947 | + protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)  | 
                                                        |
| 1948 | +	{ | 
                                                        |
| 1949 | + // determine the event id and set to array.  | 
                                                        |
| 1950 | + $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;  | 
                                                        |
| 1951 | + // loop thru events  | 
                                                        |
| 1952 | +		if ($EVT_ID) { | 
                                                        |
| 1953 | + // clean status  | 
                                                        |
| 1954 | + $event_status = sanitize_key($event_status);  | 
                                                        |
| 1955 | + // grab status  | 
                                                        |
| 1956 | +			if (! empty($event_status)) { | 
                                                        |
| 1957 | + $success = $this->_change_event_status($EVT_ID, $event_status);  | 
                                                        |
| 1958 | +			} else { | 
                                                        |
| 1959 | + $success = false;  | 
                                                        |
| 1960 | + $msg = esc_html__(  | 
                                                        |
| 1961 | + 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',  | 
                                                        |
| 1962 | + 'event_espresso'  | 
                                                        |
| 1963 | + );  | 
                                                        |
| 1964 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 1965 | + }  | 
                                                        |
| 1966 | +		} else { | 
                                                        |
| 1967 | + $success = false;  | 
                                                        |
| 1968 | + $msg = esc_html__(  | 
                                                        |
| 1969 | + 'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',  | 
                                                        |
| 1970 | + 'event_espresso'  | 
                                                        |
| 1971 | + );  | 
                                                        |
| 1972 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 1973 | + }  | 
                                                        |
| 1974 | + $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';  | 
                                                        |
| 1975 | +		if ($redirect_after) { | 
                                                        |
| 1976 | +			$this->_redirect_after_action($success, 'Event', $action, array('action' => 'default')); | 
                                                        |
| 1977 | + }  | 
                                                        |
| 1978 | + }  | 
                                                        |
| 1979 | +  | 
                                                        |
| 1980 | +  | 
                                                        |
| 1981 | + /**  | 
                                                        |
| 1982 | + * _trash_or_restore_events  | 
                                                        |
| 1983 | + *  | 
                                                        |
| 1984 | + * @access protected  | 
                                                        |
| 1985 | + * @param string $event_status  | 
                                                        |
| 1986 | + * @return void  | 
                                                        |
| 1987 | + */  | 
                                                        |
| 1988 | + protected function _trash_or_restore_events($event_status = 'trash')  | 
                                                        |
| 1989 | +	{ | 
                                                        |
| 1990 | + // clean status  | 
                                                        |
| 1991 | + $event_status = sanitize_key($event_status);  | 
                                                        |
| 1992 | + // grab status  | 
                                                        |
| 1993 | +		if (! empty($event_status)) { | 
                                                        |
| 1994 | + $success = true;  | 
                                                        |
| 1995 | + // determine the event id and set to array.  | 
                                                        |
| 1996 | + $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();  | 
                                                        |
| 1997 | + // loop thru events  | 
                                                        |
| 1998 | +			foreach ($EVT_IDs as $EVT_ID) { | 
                                                        |
| 1999 | +				if ($EVT_ID = absint($EVT_ID)) { | 
                                                        |
| 2000 | + $results = $this->_change_event_status($EVT_ID, $event_status);  | 
                                                        |
| 2001 | + $success = $results !== false ? $success : false;  | 
                                                        |
| 2002 | +				} else { | 
                                                        |
| 2003 | + $msg = sprintf(  | 
                                                        |
| 2004 | + esc_html__(  | 
                                                        |
| 2005 | + 'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',  | 
                                                        |
| 2006 | + 'event_espresso'  | 
                                                        |
| 2007 | + ),  | 
                                                        |
| 2008 | + $EVT_ID  | 
                                                        |
| 2009 | + );  | 
                                                        |
| 2010 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 2011 | + $success = false;  | 
                                                        |
| 2012 | + }  | 
                                                        |
| 2013 | + }  | 
                                                        |
| 2014 | +		} else { | 
                                                        |
| 2015 | + $success = false;  | 
                                                        |
| 2016 | + $msg = esc_html__(  | 
                                                        |
| 2017 | + 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',  | 
                                                        |
| 2018 | + 'event_espresso'  | 
                                                        |
| 2019 | + );  | 
                                                        |
| 2020 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 2021 | + }  | 
                                                        |
| 2022 | + // in order to force a pluralized result message we need to send back a success status greater than 1  | 
                                                        |
| 2023 | + $success = $success ? 2 : false;  | 
                                                        |
| 2024 | + $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';  | 
                                                        |
| 2025 | +		$this->_redirect_after_action($success, 'Events', $action, array('action' => 'default')); | 
                                                        |
| 2026 | + }  | 
                                                        |
| 2027 | +  | 
                                                        |
| 2028 | +  | 
                                                        |
| 2029 | + /**  | 
                                                        |
| 2030 | + * _trash_or_restore_events  | 
                                                        |
| 2031 | + *  | 
                                                        |
| 2032 | + * @access private  | 
                                                        |
| 2033 | + * @param int $EVT_ID  | 
                                                        |
| 2034 | + * @param string $event_status  | 
                                                        |
| 2035 | + * @return bool  | 
                                                        |
| 2036 | + */  | 
                                                        |
| 2037 | + private function _change_event_status($EVT_ID = 0, $event_status = '')  | 
                                                        |
| 2038 | +	{ | 
                                                        |
| 2039 | + // grab event id  | 
                                                        |
| 2040 | +		if (! $EVT_ID) { | 
                                                        |
| 2041 | + $msg = esc_html__(  | 
                                                        |
| 2042 | + 'An error occurred. No Event ID or an invalid Event ID was received.',  | 
                                                        |
| 2043 | + 'event_espresso'  | 
                                                        |
| 2044 | + );  | 
                                                        |
| 2045 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 2046 | + return false;  | 
                                                        |
| 2047 | + }  | 
                                                        |
| 2048 | + $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);  | 
                                                        |
| 2049 | + // clean status  | 
                                                        |
| 2050 | + $event_status = sanitize_key($event_status);  | 
                                                        |
| 2051 | + // grab status  | 
                                                        |
| 2052 | +		if (empty($event_status)) { | 
                                                        |
| 2053 | + $msg = esc_html__(  | 
                                                        |
| 2054 | + 'An error occurred. No Event Status or an invalid Event Status was received.',  | 
                                                        |
| 2055 | + 'event_espresso'  | 
                                                        |
| 2056 | + );  | 
                                                        |
| 2057 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 2058 | + return false;  | 
                                                        |
| 2059 | + }  | 
                                                        |
| 2060 | + // was event trashed or restored ?  | 
                                                        |
| 2061 | +		switch ($event_status) { | 
                                                        |
| 2062 | + case 'draft':  | 
                                                        |
| 2063 | + $action = 'restored from the trash';  | 
                                                        |
| 2064 | + $hook = 'AHEE_event_restored_from_trash';  | 
                                                        |
| 2065 | + break;  | 
                                                        |
| 2066 | + case 'trash':  | 
                                                        |
| 2067 | + $action = 'moved to the trash';  | 
                                                        |
| 2068 | + $hook = 'AHEE_event_moved_to_trash';  | 
                                                        |
| 2069 | + break;  | 
                                                        |
| 2070 | + default:  | 
                                                        |
| 2071 | + $action = 'updated';  | 
                                                        |
| 2072 | + $hook = false;  | 
                                                        |
| 2073 | + }  | 
                                                        |
| 2074 | + // use class to change status  | 
                                                        |
| 2075 | + $this->_cpt_model_obj->set_status($event_status);  | 
                                                        |
| 2076 | + $success = $this->_cpt_model_obj->save();  | 
                                                        |
| 2077 | +		if ($success === false) { | 
                                                        |
| 2078 | +			$msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); | 
                                                        |
| 2079 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 2080 | + return false;  | 
                                                        |
| 2081 | + }  | 
                                                        |
| 2082 | +		if ($hook) { | 
                                                        |
| 2083 | + do_action($hook);  | 
                                                        |
| 2084 | + }  | 
                                                        |
| 2085 | + return true;  | 
                                                        |
| 2086 | + }  | 
                                                        |
| 2087 | +  | 
                                                        |
| 2088 | +  | 
                                                        |
| 2089 | + /**  | 
                                                        |
| 2090 | + * _delete_event  | 
                                                        |
| 2091 | + *  | 
                                                        |
| 2092 | + * @access protected  | 
                                                        |
| 2093 | + * @param bool $redirect_after  | 
                                                        |
| 2094 | + */  | 
                                                        |
| 2095 | + protected function _delete_event()  | 
                                                        |
| 2096 | +	{ | 
                                                        |
| 2097 | + // determine the event id and set to array.  | 
                                                        |
| 2098 | + $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null;  | 
                                                        |
| 2099 | + wp_safe_redirect(  | 
                                                        |
| 2100 | + EE_Admin_Page::add_query_args_and_nonce(  | 
                                                        |
| 2101 | + [  | 
                                                        |
| 2102 | + 'action' => 'preview_deletion',  | 
                                                        |
| 2103 | + 'EVT_IDs[]' => $EVT_ID  | 
                                                        |
| 2104 | + ],  | 
                                                        |
| 2105 | + $this->_admin_base_url  | 
                                                        |
| 2106 | + )  | 
                                                        |
| 2107 | + );  | 
                                                        |
| 2108 | + }  | 
                                                        |
| 2109 | +  | 
                                                        |
| 2110 | +  | 
                                                        |
| 2111 | + /**  | 
                                                        |
| 2112 | + * _delete_events  | 
                                                        |
| 2113 | + *  | 
                                                        |
| 2114 | + * @access protected  | 
                                                        |
| 2115 | + * @return void  | 
                                                        |
| 2116 | + */  | 
                                                        |
| 2117 | + protected function _delete_events()  | 
                                                        |
| 2118 | +	{ | 
                                                        |
| 2119 | + $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();  | 
                                                        |
| 2120 | + $args = [  | 
                                                        |
| 2121 | + 'action' => 'preview_deletion',  | 
                                                        |
| 2122 | + ];  | 
                                                        |
| 2123 | +		foreach ($EVT_IDs as $EVT_ID) { | 
                                                        |
| 2124 | + $args['EVT_IDs[]'] = (int) $EVT_ID;  | 
                                                        |
| 2125 | + }  | 
                                                        |
| 2126 | + wp_safe_redirect(  | 
                                                        |
| 2127 | + EE_Admin_Page::add_query_args_and_nonce(  | 
                                                        |
| 2128 | + $args,  | 
                                                        |
| 2129 | + $this->_admin_base_url  | 
                                                        |
| 2130 | + )  | 
                                                        |
| 2131 | + );  | 
                                                        |
| 2132 | + }  | 
                                                        |
| 2133 | +  | 
                                                        |
| 2134 | + /**  | 
                                                        |
| 2135 | + * A page for users to preview what exactly will be deleted, and confirm they want to delete it.  | 
                                                        |
| 2136 | + * @since $VID:$  | 
                                                        |
| 2137 | + */  | 
                                                        |
| 2138 | + protected function previewDeletion()  | 
                                                        |
| 2139 | +	{ | 
                                                        |
| 2140 | + $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();  | 
                                                        |
| 2141 | + $confirm_deletion_args = [  | 
                                                        |
| 2142 | + 'action' => 'confirm_deletion',  | 
                                                        |
| 2143 | + ];  | 
                                                        |
| 2144 | +		foreach ($EVT_IDs as $EVT_ID) { | 
                                                        |
| 2145 | + $confirm_deletion_args['EVT_IDs[]'] = (int) $EVT_ID;  | 
                                                        |
| 2146 | + }  | 
                                                        |
| 2147 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template(  | 
                                                        |
| 2148 | + EVENTS_TEMPLATE_PATH . 'event_preview_deletion.template.php',  | 
                                                        |
| 2149 | + [  | 
                                                        |
| 2150 | + 'form_url' => EE_Admin_Page::add_query_args_and_nonce(  | 
                                                        |
| 2151 | + $confirm_deletion_args,  | 
                                                        |
| 2152 | + $this->admin_base_url()  | 
                                                        |
| 2153 | + )  | 
                                                        |
| 2154 | + ],  | 
                                                        |
| 2155 | + true  | 
                                                        |
| 2156 | + );  | 
                                                        |
| 2157 | + $this->display_admin_page_with_no_sidebar();  | 
                                                        |
| 2158 | + }  | 
                                                        |
| 2159 | +  | 
                                                        |
| 2160 | + protected function confirmDeletion()  | 
                                                        |
| 2161 | +	{ | 
                                                        |
| 2162 | + $event_ids = isset($this->_req_data['EVT_IDs']) ? $this->_req_data['EVT_IDs'] : array();  | 
                                                        |
| 2163 | + $success = $this->deleteEventsAndDependentData($event_ids);  | 
                                                        |
| 2164 | + $this->redirect_after_action(  | 
                                                        |
| 2165 | + $success,  | 
                                                        |
| 2166 | +			esc_html__('Events', 'event_espresso'), | 
                                                        |
| 2167 | +			esc_html__('deleted', 'event_espresso'), | 
                                                        |
| 2168 | + [  | 
                                                        |
| 2169 | + 'action' => 'default'  | 
                                                        |
| 2170 | + ]  | 
                                                        |
| 2171 | + );  | 
                                                        |
| 2172 | + }  | 
                                                        |
| 2173 | +  | 
                                                        |
| 2174 | + /**  | 
                                                        |
| 2175 | + * Deletes the events and all dependent data, plus those events' non-global/non-default tickets, prices, and  | 
                                                        |
| 2176 | + * message template groups.  | 
                                                        |
| 2177 | + * @since $VID:$  | 
                                                        |
| 2178 | + * @param $event_ids  | 
                                                        |
| 2179 | + * @return int  | 
                                                        |
| 2180 | + * @throws EE_Error  | 
                                                        |
| 2181 | + * @throws InvalidArgumentException  | 
                                                        |
| 2182 | + * @throws ReflectionException  | 
                                                        |
| 2183 | + * @throws InvalidDataTypeException  | 
                                                        |
| 2184 | + * @throws InvalidInterfaceException  | 
                                                        |
| 2185 | + */  | 
                                                        |
| 2186 | + protected function deleteEventsAndDependentData($event_ids)  | 
                                                        |
| 2187 | +	{ | 
                                                        |
| 2188 | + // Call me an optimist.  | 
                                                        |
| 2189 | + $success = true;  | 
                                                        |
| 2190 | +		$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); | 
                                                        |
| 2191 | +  | 
                                                        |
| 2192 | + // Find all the root nodes to delete (this isn't just events, because there's other data, like related tickets,  | 
                                                        |
| 2193 | + // prices, message templates, etc, whose model definition doesn't make them dependent on events. But,  | 
                                                        |
| 2194 | + // we have no UI to access them independent of events, so they may as well get deleted too.)  | 
                                                        |
| 2195 | + $model_objects_to_delete = [];  | 
                                                        |
| 2196 | +		foreach ($event_ids as $event_id) { | 
                                                        |
| 2197 | + $event = EEM_Event::instance()->get_one_by_ID($event_id);  | 
                                                        |
| 2198 | 2198 | // $model_objects_to_delete[] = $event;  | 
                                                        
| 2199 | - // Also, we want to delete their related, non-global, tickets, prices and message templates  | 
                                                        |
| 2200 | - $related_non_global_tickets = EEM_Ticket::instance()->get_all_deleted_and_undeleted(  | 
                                                        |
| 2201 | - [  | 
                                                        |
| 2202 | - [  | 
                                                        |
| 2203 | - 'TKT_is_default' => false,  | 
                                                        |
| 2204 | - 'Datetime.EVT_ID' => $event_id  | 
                                                        |
| 2205 | - ]  | 
                                                        |
| 2206 | - ]  | 
                                                        |
| 2207 | - );  | 
                                                        |
| 2208 | - $related_non_globa_prices = EEM_Price::instance()->get_all_deleted_and_undeleted(  | 
                                                        |
| 2209 | - [  | 
                                                        |
| 2210 | - [  | 
                                                        |
| 2211 | - 'PRC_is_default' => false,  | 
                                                        |
| 2212 | - 'Ticket.Datetime.EVT_ID' => $event_id  | 
                                                        |
| 2213 | - ]  | 
                                                        |
| 2214 | - ]  | 
                                                        |
| 2215 | - );  | 
                                                        |
| 2216 | - $related_message_templates = $event->get_many_related(  | 
                                                        |
| 2217 | - 'Message_Template_Group',  | 
                                                        |
| 2218 | - [  | 
                                                        |
| 2219 | - [  | 
                                                        |
| 2220 | - 'MTP_is_global' => false  | 
                                                        |
| 2221 | - ]  | 
                                                        |
| 2222 | - ]  | 
                                                        |
| 2223 | - );  | 
                                                        |
| 2224 | - $model_objects_to_delete = array_merge(  | 
                                                        |
| 2225 | - $model_objects_to_delete,  | 
                                                        |
| 2226 | - [$event],  | 
                                                        |
| 2227 | - $related_non_global_tickets,  | 
                                                        |
| 2228 | - $related_non_globa_prices,  | 
                                                        |
| 2229 | - $related_message_templates  | 
                                                        |
| 2230 | - );  | 
                                                        |
| 2231 | - }  | 
                                                        |
| 2232 | -  | 
                                                        |
| 2233 | - // Find all the dependent model objects we want to delete.  | 
                                                        |
| 2234 | - $ids_to_delete = [];  | 
                                                        |
| 2235 | -        foreach ($model_objects_to_delete as $model_object_to_delete) { | 
                                                        |
| 2236 | - $node = new ModelObjNode($model_object_to_delete);  | 
                                                        |
| 2237 | - $node->visit(9999);  | 
                                                        |
| 2238 | - $ids_to_delete = array_replace_recursive($ids_to_delete, $node->getIds());  | 
                                                        |
| 2239 | - }  | 
                                                        |
| 2240 | -  | 
                                                        |
| 2241 | - // Delete them all, one query per model.  | 
                                                        |
| 2242 | -        foreach ($ids_to_delete as $model_name => $ids) { | 
                                                        |
| 2243 | - $model = EE_Registry::instance()->load_model($model_name);  | 
                                                        |
| 2244 | -            if ($model->has_primary_key_field()) { | 
                                                        |
| 2245 | - $where_conditions = [  | 
                                                        |
| 2246 | - $model->primary_key_name() => [  | 
                                                        |
| 2247 | - 'IN',  | 
                                                        |
| 2248 | - $ids  | 
                                                        |
| 2249 | - ]  | 
                                                        |
| 2250 | - ];  | 
                                                        |
| 2251 | -            } else { | 
                                                        |
| 2252 | - $where_conditions = [  | 
                                                        |
| 2253 | - 'OR' => []  | 
                                                        |
| 2254 | - ];  | 
                                                        |
| 2255 | -                foreach ($ids as $index_primary_key_string) { | 
                                                        |
| 2256 | - $keys_n_values = $model->parse_index_primary_key_string($index_primary_key_string);  | 
                                                        |
| 2257 | - $where_conditions['OR'][ 'AND*' . $index_primary_key_string ] = $keys_n_values;  | 
                                                        |
| 2258 | - }  | 
                                                        |
| 2259 | - }  | 
                                                        |
| 2260 | - if (!$model->delete_permanently(  | 
                                                        |
| 2261 | - [  | 
                                                        |
| 2262 | - $where_conditions  | 
                                                        |
| 2263 | - ],  | 
                                                        |
| 2264 | - false  | 
                                                        |
| 2265 | -            )) { | 
                                                        |
| 2266 | - $success = false;  | 
                                                        |
| 2267 | - }  | 
                                                        |
| 2268 | - }  | 
                                                        |
| 2269 | -        if (isset($espresso_no_ticket_prices[ $event_id ])) { | 
                                                        |
| 2270 | - unset($espresso_no_ticket_prices[ $event_id ]);  | 
                                                        |
| 2271 | - }  | 
                                                        |
| 2272 | - // Fire a legacy action.  | 
                                                        |
| 2273 | -        foreach ($event_ids as $event_id) { | 
                                                        |
| 2274 | -            do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $event_id); | 
                                                        |
| 2275 | - }  | 
                                                        |
| 2276 | -        update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); | 
                                                        |
| 2277 | - return $success;  | 
                                                        |
| 2278 | - }  | 
                                                        |
| 2279 | -  | 
                                                        |
| 2280 | - /**  | 
                                                        |
| 2281 | - * _permanently_delete_event  | 
                                                        |
| 2282 | - *  | 
                                                        |
| 2283 | - * @access private  | 
                                                        |
| 2284 | - * @param int $EVT_ID  | 
                                                        |
| 2285 | - * @return bool  | 
                                                        |
| 2286 | - */  | 
                                                        |
| 2287 | - private function _permanently_delete_event($EVT_ID = 0)  | 
                                                        |
| 2288 | -    { | 
                                                        |
| 2289 | - // grab event id  | 
                                                        |
| 2290 | -        if (! $EVT_ID) { | 
                                                        |
| 2291 | - $msg = esc_html__(  | 
                                                        |
| 2292 | - 'An error occurred. No Event ID or an invalid Event ID was received.',  | 
                                                        |
| 2293 | - 'event_espresso'  | 
                                                        |
| 2294 | - );  | 
                                                        |
| 2295 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 2296 | - return false;  | 
                                                        |
| 2297 | - }  | 
                                                        |
| 2298 | - if (! $this->_cpt_model_obj instanceof EE_Event  | 
                                                        |
| 2299 | - || $this->_cpt_model_obj->ID() !== $EVT_ID  | 
                                                        |
| 2300 | -        ) { | 
                                                        |
| 2301 | - $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);  | 
                                                        |
| 2302 | - }  | 
                                                        |
| 2303 | -        if (! $this->_cpt_model_obj instanceof EE_Event) { | 
                                                        |
| 2304 | - return false;  | 
                                                        |
| 2305 | - }  | 
                                                        |
| 2306 | - // need to delete related tickets and prices first.  | 
                                                        |
| 2307 | -        $datetimes = $this->_cpt_model_obj->get_many_related('Datetime'); | 
                                                        |
| 2308 | -        foreach ($datetimes as $datetime) { | 
                                                        |
| 2309 | - $this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime');  | 
                                                        |
| 2310 | -            $tickets = $datetime->get_many_related('Ticket'); | 
                                                        |
| 2311 | -            foreach ($tickets as $ticket) { | 
                                                        |
| 2312 | - $ticket->_remove_relation_to($datetime, 'Datetime');  | 
                                                        |
| 2313 | -                $ticket->delete_related_permanently('Price'); | 
                                                        |
| 2314 | - $ticket->delete_permanently();  | 
                                                        |
| 2315 | - }  | 
                                                        |
| 2316 | - $datetime->delete();  | 
                                                        |
| 2317 | - }  | 
                                                        |
| 2318 | - // what about related venues or terms?  | 
                                                        |
| 2319 | -        $venues = $this->_cpt_model_obj->get_many_related('Venue'); | 
                                                        |
| 2320 | -        foreach ($venues as $venue) { | 
                                                        |
| 2321 | - $this->_cpt_model_obj->_remove_relation_to($venue, 'Venue');  | 
                                                        |
| 2322 | - }  | 
                                                        |
| 2323 | - // any attached question groups?  | 
                                                        |
| 2324 | -        $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group'); | 
                                                        |
| 2325 | -        if (! empty($question_groups)) { | 
                                                        |
| 2326 | -            foreach ($question_groups as $question_group) { | 
                                                        |
| 2327 | - $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group');  | 
                                                        |
| 2328 | - }  | 
                                                        |
| 2329 | - }  | 
                                                        |
| 2330 | - // Message Template Groups  | 
                                                        |
| 2331 | -        $this->_cpt_model_obj->_remove_relations('Message_Template_Group'); | 
                                                        |
| 2332 | - /** @type EE_Term_Taxonomy[] $term_taxonomies */  | 
                                                        |
| 2333 | - $term_taxonomies = $this->_cpt_model_obj->term_taxonomies();  | 
                                                        |
| 2334 | -        foreach ($term_taxonomies as $term_taxonomy) { | 
                                                        |
| 2335 | - $this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy);  | 
                                                        |
| 2336 | - }  | 
                                                        |
| 2337 | - $success = $this->_cpt_model_obj->delete_permanently();  | 
                                                        |
| 2338 | - // did it all go as planned ?  | 
                                                        |
| 2339 | -        if ($success) { | 
                                                        |
| 2340 | -            $msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID); | 
                                                        |
| 2341 | - EE_Error::add_success($msg);  | 
                                                        |
| 2342 | -        } else { | 
                                                        |
| 2343 | - $msg = sprintf(  | 
                                                        |
| 2344 | -                esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'), | 
                                                        |
| 2345 | - $EVT_ID  | 
                                                        |
| 2346 | - );  | 
                                                        |
| 2347 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 2348 | - return false;  | 
                                                        |
| 2349 | - }  | 
                                                        |
| 2350 | -        do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID); | 
                                                        |
| 2351 | - return true;  | 
                                                        |
| 2352 | - }  | 
                                                        |
| 2353 | -  | 
                                                        |
| 2354 | -  | 
                                                        |
| 2355 | - /**  | 
                                                        |
| 2356 | - * get total number of events  | 
                                                        |
| 2357 | - *  | 
                                                        |
| 2358 | - * @access public  | 
                                                        |
| 2359 | - * @return int  | 
                                                        |
| 2360 | - */  | 
                                                        |
| 2361 | - public function total_events()  | 
                                                        |
| 2362 | -    { | 
                                                        |
| 2363 | -        $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true); | 
                                                        |
| 2364 | - return $count;  | 
                                                        |
| 2365 | - }  | 
                                                        |
| 2366 | -  | 
                                                        |
| 2367 | -  | 
                                                        |
| 2368 | - /**  | 
                                                        |
| 2369 | - * get total number of draft events  | 
                                                        |
| 2370 | - *  | 
                                                        |
| 2371 | - * @access public  | 
                                                        |
| 2372 | - * @return int  | 
                                                        |
| 2373 | - */  | 
                                                        |
| 2374 | - public function total_events_draft()  | 
                                                        |
| 2375 | -    { | 
                                                        |
| 2376 | - $where = array(  | 
                                                        |
| 2377 | -            'status' => array('IN', array('draft', 'auto-draft')), | 
                                                        |
| 2378 | - );  | 
                                                        |
| 2379 | - $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);  | 
                                                        |
| 2380 | - return $count;  | 
                                                        |
| 2381 | - }  | 
                                                        |
| 2382 | -  | 
                                                        |
| 2383 | -  | 
                                                        |
| 2384 | - /**  | 
                                                        |
| 2385 | - * get total number of trashed events  | 
                                                        |
| 2386 | - *  | 
                                                        |
| 2387 | - * @access public  | 
                                                        |
| 2388 | - * @return int  | 
                                                        |
| 2389 | - */  | 
                                                        |
| 2390 | - public function total_trashed_events()  | 
                                                        |
| 2391 | -    { | 
                                                        |
| 2392 | - $where = array(  | 
                                                        |
| 2393 | - 'status' => 'trash',  | 
                                                        |
| 2394 | - );  | 
                                                        |
| 2395 | - $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);  | 
                                                        |
| 2396 | - return $count;  | 
                                                        |
| 2397 | - }  | 
                                                        |
| 2398 | -  | 
                                                        |
| 2399 | -  | 
                                                        |
| 2400 | - /**  | 
                                                        |
| 2401 | - * _default_event_settings  | 
                                                        |
| 2402 | - * This generates the Default Settings Tab  | 
                                                        |
| 2403 | - *  | 
                                                        |
| 2404 | - * @return void  | 
                                                        |
| 2405 | - * @throws EE_Error  | 
                                                        |
| 2406 | - */  | 
                                                        |
| 2407 | - protected function _default_event_settings()  | 
                                                        |
| 2408 | -    { | 
                                                        |
| 2409 | -        $this->_set_add_edit_form_tags('update_default_event_settings'); | 
                                                        |
| 2410 | - $this->_set_publish_post_box_vars(null, false, false, null, false);  | 
                                                        |
| 2411 | - $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();  | 
                                                        |
| 2412 | - $this->display_admin_page_with_sidebar();  | 
                                                        |
| 2413 | - }  | 
                                                        |
| 2414 | -  | 
                                                        |
| 2415 | -  | 
                                                        |
| 2416 | - /**  | 
                                                        |
| 2417 | - * Return the form for event settings.  | 
                                                        |
| 2418 | - *  | 
                                                        |
| 2419 | - * @return EE_Form_Section_Proper  | 
                                                        |
| 2420 | - * @throws EE_Error  | 
                                                        |
| 2421 | - */  | 
                                                        |
| 2422 | - protected function _default_event_settings_form()  | 
                                                        |
| 2423 | -    { | 
                                                        |
| 2424 | - $registration_config = EE_Registry::instance()->CFG->registration;  | 
                                                        |
| 2425 | - $registration_stati_for_selection = EEM_Registration::reg_status_array(  | 
                                                        |
| 2426 | - // exclude  | 
                                                        |
| 2427 | - array(  | 
                                                        |
| 2428 | - EEM_Registration::status_id_cancelled,  | 
                                                        |
| 2429 | - EEM_Registration::status_id_declined,  | 
                                                        |
| 2430 | - EEM_Registration::status_id_incomplete,  | 
                                                        |
| 2431 | - EEM_Registration::status_id_wait_list,  | 
                                                        |
| 2432 | - ),  | 
                                                        |
| 2433 | - true  | 
                                                        |
| 2434 | - );  | 
                                                        |
| 2435 | - return new EE_Form_Section_Proper(  | 
                                                        |
| 2436 | - array(  | 
                                                        |
| 2437 | - 'name' => 'update_default_event_settings',  | 
                                                        |
| 2438 | - 'html_id' => 'update_default_event_settings',  | 
                                                        |
| 2439 | - 'html_class' => 'form-table',  | 
                                                        |
| 2440 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(),  | 
                                                        |
| 2441 | - 'subsections' => apply_filters(  | 
                                                        |
| 2442 | - 'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',  | 
                                                        |
| 2443 | - array(  | 
                                                        |
| 2444 | - 'default_reg_status' => new EE_Select_Input(  | 
                                                        |
| 2445 | - $registration_stati_for_selection,  | 
                                                        |
| 2446 | - array(  | 
                                                        |
| 2447 | - 'default' => isset($registration_config->default_STS_ID)  | 
                                                        |
| 2448 | - && array_key_exists(  | 
                                                        |
| 2449 | - $registration_config->default_STS_ID,  | 
                                                        |
| 2450 | - $registration_stati_for_selection  | 
                                                        |
| 2451 | - )  | 
                                                        |
| 2452 | - ? sanitize_text_field($registration_config->default_STS_ID)  | 
                                                        |
| 2453 | - : EEM_Registration::status_id_pending_payment,  | 
                                                        |
| 2454 | -                                'html_label_text' => esc_html__('Default Registration Status', 'event_espresso') | 
                                                        |
| 2455 | - . EEH_Template::get_help_tab_link(  | 
                                                        |
| 2456 | - 'default_settings_status_help_tab'  | 
                                                        |
| 2457 | - ),  | 
                                                        |
| 2458 | - 'html_help_text' => esc_html__(  | 
                                                        |
| 2459 | - 'This setting allows you to preselect what the default registration status setting is when creating an event. Note that changing this setting does NOT retroactively apply it to existing events.',  | 
                                                        |
| 2460 | - 'event_espresso'  | 
                                                        |
| 2461 | - ),  | 
                                                        |
| 2462 | - )  | 
                                                        |
| 2463 | - ),  | 
                                                        |
| 2464 | - 'default_max_tickets' => new EE_Integer_Input(  | 
                                                        |
| 2465 | - array(  | 
                                                        |
| 2466 | - 'default' => isset($registration_config->default_maximum_number_of_tickets)  | 
                                                        |
| 2467 | - ? $registration_config->default_maximum_number_of_tickets  | 
                                                        |
| 2468 | - : EEM_Event::get_default_additional_limit(),  | 
                                                        |
| 2469 | - 'html_label_text' => esc_html__(  | 
                                                        |
| 2470 | - 'Default Maximum Tickets Allowed Per Order:',  | 
                                                        |
| 2471 | - 'event_espresso'  | 
                                                        |
| 2472 | - )  | 
                                                        |
| 2473 | - . EEH_Template::get_help_tab_link(  | 
                                                        |
| 2474 | - 'default_maximum_tickets_help_tab"'  | 
                                                        |
| 2475 | - ),  | 
                                                        |
| 2476 | - 'html_help_text' => esc_html__(  | 
                                                        |
| 2477 | - 'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',  | 
                                                        |
| 2478 | - 'event_espresso'  | 
                                                        |
| 2479 | - ),  | 
                                                        |
| 2480 | - )  | 
                                                        |
| 2481 | - ),  | 
                                                        |
| 2482 | - )  | 
                                                        |
| 2483 | - ),  | 
                                                        |
| 2484 | - )  | 
                                                        |
| 2485 | - );  | 
                                                        |
| 2486 | - }  | 
                                                        |
| 2487 | -  | 
                                                        |
| 2488 | -  | 
                                                        |
| 2489 | - /**  | 
                                                        |
| 2490 | - * _update_default_event_settings  | 
                                                        |
| 2491 | - *  | 
                                                        |
| 2492 | - * @access protected  | 
                                                        |
| 2493 | - * @return void  | 
                                                        |
| 2494 | - * @throws EE_Error  | 
                                                        |
| 2495 | - */  | 
                                                        |
| 2496 | - protected function _update_default_event_settings()  | 
                                                        |
| 2497 | -    { | 
                                                        |
| 2498 | - $registration_config = EE_Registry::instance()->CFG->registration;  | 
                                                        |
| 2499 | - $form = $this->_default_event_settings_form();  | 
                                                        |
| 2500 | -        if ($form->was_submitted()) { | 
                                                        |
| 2501 | - $form->receive_form_submission();  | 
                                                        |
| 2502 | -            if ($form->is_valid()) { | 
                                                        |
| 2503 | - $valid_data = $form->valid_data();  | 
                                                        |
| 2504 | -                if (isset($valid_data['default_reg_status'])) { | 
                                                        |
| 2505 | - $registration_config->default_STS_ID = $valid_data['default_reg_status'];  | 
                                                        |
| 2506 | - }  | 
                                                        |
| 2507 | -                if (isset($valid_data['default_max_tickets'])) { | 
                                                        |
| 2508 | - $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];  | 
                                                        |
| 2509 | - }  | 
                                                        |
| 2510 | - // update because data was valid!  | 
                                                        |
| 2511 | - EE_Registry::instance()->CFG->update_espresso_config();  | 
                                                        |
| 2512 | - EE_Error::overwrite_success();  | 
                                                        |
| 2513 | - EE_Error::add_success(  | 
                                                        |
| 2514 | -                    __('Default Event Settings were updated', 'event_espresso') | 
                                                        |
| 2515 | - );  | 
                                                        |
| 2516 | - }  | 
                                                        |
| 2517 | - }  | 
                                                        |
| 2518 | -        $this->_redirect_after_action(0, '', '', array('action' => 'default_event_settings'), true); | 
                                                        |
| 2519 | - }  | 
                                                        |
| 2520 | -  | 
                                                        |
| 2521 | -  | 
                                                        |
| 2522 | - /************* Templates *************/  | 
                                                        |
| 2523 | - protected function _template_settings()  | 
                                                        |
| 2524 | -    { | 
                                                        |
| 2525 | -        $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso'); | 
                                                        |
| 2526 | - $this->_template_args['preview_img'] = '<img src="'  | 
                                                        |
| 2527 | - . EVENTS_ASSETS_URL  | 
                                                        |
| 2528 | - . '/images/'  | 
                                                        |
| 2529 | - . 'caffeinated_template_features.jpg" alt="'  | 
                                                        |
| 2530 | -                                               . esc_attr__('Template Settings Preview screenshot', 'event_espresso') | 
                                                        |
| 2531 | - . '" />';  | 
                                                        |
| 2532 | - $this->_template_args['preview_text'] = '<strong>'  | 
                                                        |
| 2533 | - . esc_html__(  | 
                                                        |
| 2534 | - 'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',  | 
                                                        |
| 2535 | - 'event_espresso'  | 
                                                        |
| 2536 | - ) . '</strong>';  | 
                                                        |
| 2537 | -        $this->display_admin_caf_preview_page('template_settings_tab'); | 
                                                        |
| 2538 | - }  | 
                                                        |
| 2539 | -  | 
                                                        |
| 2540 | -  | 
                                                        |
| 2541 | - /** Event Category Stuff **/  | 
                                                        |
| 2542 | - /**  | 
                                                        |
| 2543 | - * set the _category property with the category object for the loaded page.  | 
                                                        |
| 2544 | - *  | 
                                                        |
| 2545 | - * @access private  | 
                                                        |
| 2546 | - * @return void  | 
                                                        |
| 2547 | - */  | 
                                                        |
| 2548 | - private function _set_category_object()  | 
                                                        |
| 2549 | -    { | 
                                                        |
| 2550 | -        if (isset($this->_category->id) && ! empty($this->_category->id)) { | 
                                                        |
| 2551 | - return;  | 
                                                        |
| 2552 | - } //already have the category object so get out.  | 
                                                        |
| 2553 | - // set default category object  | 
                                                        |
| 2554 | - $this->_set_empty_category_object();  | 
                                                        |
| 2555 | - // only set if we've got an id  | 
                                                        |
| 2556 | -        if (! isset($this->_req_data['EVT_CAT_ID'])) { | 
                                                        |
| 2557 | - return;  | 
                                                        |
| 2558 | - }  | 
                                                        |
| 2559 | - $category_id = absint($this->_req_data['EVT_CAT_ID']);  | 
                                                        |
| 2560 | - $term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);  | 
                                                        |
| 2561 | -        if (! empty($term)) { | 
                                                        |
| 2562 | - $this->_category->category_name = $term->name;  | 
                                                        |
| 2563 | - $this->_category->category_identifier = $term->slug;  | 
                                                        |
| 2564 | - $this->_category->category_desc = $term->description;  | 
                                                        |
| 2565 | - $this->_category->id = $term->term_id;  | 
                                                        |
| 2566 | - $this->_category->parent = $term->parent;  | 
                                                        |
| 2567 | - }  | 
                                                        |
| 2568 | - }  | 
                                                        |
| 2569 | -  | 
                                                        |
| 2570 | -  | 
                                                        |
| 2571 | - /**  | 
                                                        |
| 2572 | - * Clears out category properties.  | 
                                                        |
| 2573 | - */  | 
                                                        |
| 2574 | - private function _set_empty_category_object()  | 
                                                        |
| 2575 | -    { | 
                                                        |
| 2576 | - $this->_category = new stdClass();  | 
                                                        |
| 2577 | - $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';  | 
                                                        |
| 2578 | - $this->_category->id = $this->_category->parent = 0;  | 
                                                        |
| 2579 | - }  | 
                                                        |
| 2580 | -  | 
                                                        |
| 2581 | -  | 
                                                        |
| 2582 | - /**  | 
                                                        |
| 2583 | - * @throws EE_Error  | 
                                                        |
| 2584 | - */  | 
                                                        |
| 2585 | - protected function _category_list_table()  | 
                                                        |
| 2586 | -    { | 
                                                        |
| 2587 | -        do_action('AHEE_log', __FILE__, __FUNCTION__, ''); | 
                                                        |
| 2588 | -        $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); | 
                                                        |
| 2589 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(  | 
                                                        |
| 2590 | - 'add_category',  | 
                                                        |
| 2591 | - 'add_category',  | 
                                                        |
| 2592 | - array(),  | 
                                                        |
| 2593 | - 'add-new-h2'  | 
                                                        |
| 2594 | - );  | 
                                                        |
| 2595 | - $this->display_admin_list_table_page_with_sidebar();  | 
                                                        |
| 2596 | - }  | 
                                                        |
| 2597 | -  | 
                                                        |
| 2598 | -  | 
                                                        |
| 2599 | - /**  | 
                                                        |
| 2600 | - * Output category details view.  | 
                                                        |
| 2601 | - */  | 
                                                        |
| 2602 | - protected function _category_details($view)  | 
                                                        |
| 2603 | -    { | 
                                                        |
| 2604 | - // load formatter helper  | 
                                                        |
| 2605 | - // load field generator helper  | 
                                                        |
| 2606 | - $route = $view == 'edit' ? 'update_category' : 'insert_category';  | 
                                                        |
| 2607 | - $this->_set_add_edit_form_tags($route);  | 
                                                        |
| 2608 | - $this->_set_category_object();  | 
                                                        |
| 2609 | - $id = ! empty($this->_category->id) ? $this->_category->id : '';  | 
                                                        |
| 2610 | - $delete_action = 'delete_category';  | 
                                                        |
| 2611 | - // custom redirect  | 
                                                        |
| 2612 | - $redirect = EE_Admin_Page::add_query_args_and_nonce(  | 
                                                        |
| 2613 | -            array('action' => 'category_list'), | 
                                                        |
| 2614 | - $this->_admin_base_url  | 
                                                        |
| 2615 | - );  | 
                                                        |
| 2616 | -        $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect); | 
                                                        |
| 2617 | - // take care of contents  | 
                                                        |
| 2618 | - $this->_template_args['admin_page_content'] = $this->_category_details_content();  | 
                                                        |
| 2619 | - $this->display_admin_page_with_sidebar();  | 
                                                        |
| 2620 | - }  | 
                                                        |
| 2621 | -  | 
                                                        |
| 2622 | -  | 
                                                        |
| 2623 | - /**  | 
                                                        |
| 2624 | - * Output category details content.  | 
                                                        |
| 2625 | - */  | 
                                                        |
| 2626 | - protected function _category_details_content()  | 
                                                        |
| 2627 | -    { | 
                                                        |
| 2628 | - $editor_args['category_desc'] = array(  | 
                                                        |
| 2629 | - 'type' => 'wp_editor',  | 
                                                        |
| 2630 | - 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc),  | 
                                                        |
| 2631 | - 'class' => 'my_editor_custom',  | 
                                                        |
| 2632 | -            'wpeditor_args' => array('media_buttons' => false), | 
                                                        |
| 2633 | - );  | 
                                                        |
| 2634 | - $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');  | 
                                                        |
| 2635 | - $all_terms = get_terms(  | 
                                                        |
| 2636 | - array(EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY),  | 
                                                        |
| 2637 | -            array('hide_empty' => 0, 'exclude' => array($this->_category->id)) | 
                                                        |
| 2638 | - );  | 
                                                        |
| 2639 | - // setup category select for term parents.  | 
                                                        |
| 2640 | - $category_select_values[] = array(  | 
                                                        |
| 2641 | -            'text' => esc_html__('No Parent', 'event_espresso'), | 
                                                        |
| 2642 | - 'id' => 0,  | 
                                                        |
| 2643 | - );  | 
                                                        |
| 2644 | -        foreach ($all_terms as $term) { | 
                                                        |
| 2645 | - $category_select_values[] = array(  | 
                                                        |
| 2646 | - 'text' => $term->name,  | 
                                                        |
| 2647 | - 'id' => $term->term_id,  | 
                                                        |
| 2648 | - );  | 
                                                        |
| 2649 | - }  | 
                                                        |
| 2650 | - $category_select = EEH_Form_Fields::select_input(  | 
                                                        |
| 2651 | - 'category_parent',  | 
                                                        |
| 2652 | - $category_select_values,  | 
                                                        |
| 2653 | - $this->_category->parent  | 
                                                        |
| 2654 | - );  | 
                                                        |
| 2655 | - $template_args = array(  | 
                                                        |
| 2656 | - 'category' => $this->_category,  | 
                                                        |
| 2657 | - 'category_select' => $category_select,  | 
                                                        |
| 2658 | -            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), | 
                                                        |
| 2659 | - 'category_desc_editor' => $_wp_editor['category_desc']['field'],  | 
                                                        |
| 2660 | - 'disable' => '',  | 
                                                        |
| 2661 | - 'disabled_message' => false,  | 
                                                        |
| 2662 | - );  | 
                                                        |
| 2663 | - $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';  | 
                                                        |
| 2664 | - return EEH_Template::display_template($template, $template_args, true);  | 
                                                        |
| 2665 | - }  | 
                                                        |
| 2666 | -  | 
                                                        |
| 2667 | -  | 
                                                        |
| 2668 | - /**  | 
                                                        |
| 2669 | - * Handles deleting categories.  | 
                                                        |
| 2670 | - */  | 
                                                        |
| 2671 | - protected function _delete_categories()  | 
                                                        |
| 2672 | -    { | 
                                                        |
| 2673 | - $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID']  | 
                                                        |
| 2674 | - : (array) $this->_req_data['category_id'];  | 
                                                        |
| 2675 | -        foreach ($cat_ids as $cat_id) { | 
                                                        |
| 2676 | - $this->_delete_category($cat_id);  | 
                                                        |
| 2677 | - }  | 
                                                        |
| 2678 | - // doesn't matter what page we're coming from... we're going to the same place after delete.  | 
                                                        |
| 2679 | - $query_args = array(  | 
                                                        |
| 2680 | - 'action' => 'category_list',  | 
                                                        |
| 2681 | - );  | 
                                                        |
| 2682 | - $this->_redirect_after_action(0, '', '', $query_args);  | 
                                                        |
| 2683 | - }  | 
                                                        |
| 2684 | -  | 
                                                        |
| 2685 | -  | 
                                                        |
| 2686 | - /**  | 
                                                        |
| 2687 | - * Handles deleting specific category.  | 
                                                        |
| 2688 | - *  | 
                                                        |
| 2689 | - * @param int $cat_id  | 
                                                        |
| 2690 | - */  | 
                                                        |
| 2691 | - protected function _delete_category($cat_id)  | 
                                                        |
| 2692 | -    { | 
                                                        |
| 2693 | - $cat_id = absint($cat_id);  | 
                                                        |
| 2694 | - wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);  | 
                                                        |
| 2695 | - }  | 
                                                        |
| 2696 | -  | 
                                                        |
| 2697 | -  | 
                                                        |
| 2698 | - /**  | 
                                                        |
| 2699 | - * Handles triggering the update or insertion of a new category.  | 
                                                        |
| 2700 | - *  | 
                                                        |
| 2701 | - * @param bool $new_category true means we're triggering the insert of a new category.  | 
                                                        |
| 2702 | - */  | 
                                                        |
| 2703 | - protected function _insert_or_update_category($new_category)  | 
                                                        |
| 2704 | -    { | 
                                                        |
| 2705 | - $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);  | 
                                                        |
| 2706 | - $success = 0; // we already have a success message so lets not send another.  | 
                                                        |
| 2707 | -        if ($cat_id) { | 
                                                        |
| 2708 | - $query_args = array(  | 
                                                        |
| 2709 | - 'action' => 'edit_category',  | 
                                                        |
| 2710 | - 'EVT_CAT_ID' => $cat_id,  | 
                                                        |
| 2711 | - );  | 
                                                        |
| 2712 | -        } else { | 
                                                        |
| 2713 | -            $query_args = array('action' => 'add_category'); | 
                                                        |
| 2714 | - }  | 
                                                        |
| 2715 | - $this->_redirect_after_action($success, '', '', $query_args, true);  | 
                                                        |
| 2716 | - }  | 
                                                        |
| 2717 | -  | 
                                                        |
| 2718 | -  | 
                                                        |
| 2719 | - /**  | 
                                                        |
| 2720 | - * Inserts or updates category  | 
                                                        |
| 2721 | - *  | 
                                                        |
| 2722 | - * @param bool $update (true indicates we're updating a category).  | 
                                                        |
| 2723 | - * @return bool|mixed|string  | 
                                                        |
| 2724 | - */  | 
                                                        |
| 2725 | - private function _insert_category($update = false)  | 
                                                        |
| 2726 | -    { | 
                                                        |
| 2727 | - $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : '';  | 
                                                        |
| 2728 | - $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';  | 
                                                        |
| 2729 | - $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';  | 
                                                        |
| 2730 | - $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;  | 
                                                        |
| 2731 | -        if (empty($category_name)) { | 
                                                        |
| 2732 | -            $msg = esc_html__('You must add a name for the category.', 'event_espresso'); | 
                                                        |
| 2733 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 2734 | - return false;  | 
                                                        |
| 2735 | - }  | 
                                                        |
| 2736 | - $term_args = array(  | 
                                                        |
| 2737 | - 'name' => $category_name,  | 
                                                        |
| 2738 | - 'description' => $category_desc,  | 
                                                        |
| 2739 | - 'parent' => $category_parent,  | 
                                                        |
| 2740 | - );  | 
                                                        |
| 2741 | - // was the category_identifier input disabled?  | 
                                                        |
| 2742 | -        if (isset($this->_req_data['category_identifier'])) { | 
                                                        |
| 2743 | - $term_args['slug'] = $this->_req_data['category_identifier'];  | 
                                                        |
| 2744 | - }  | 
                                                        |
| 2745 | - $insert_ids = $update  | 
                                                        |
| 2746 | - ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)  | 
                                                        |
| 2747 | - : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);  | 
                                                        |
| 2748 | -        if (! is_array($insert_ids)) { | 
                                                        |
| 2749 | - $msg = esc_html__(  | 
                                                        |
| 2750 | - 'An error occurred and the category has not been saved to the database.',  | 
                                                        |
| 2751 | - 'event_espresso'  | 
                                                        |
| 2752 | - );  | 
                                                        |
| 2753 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 2754 | -        } else { | 
                                                        |
| 2755 | - $cat_id = $insert_ids['term_id'];  | 
                                                        |
| 2756 | -            $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name); | 
                                                        |
| 2757 | - EE_Error::add_success($msg);  | 
                                                        |
| 2758 | - }  | 
                                                        |
| 2759 | - return $cat_id;  | 
                                                        |
| 2760 | - }  | 
                                                        |
| 2761 | -  | 
                                                        |
| 2762 | -  | 
                                                        |
| 2763 | - /**  | 
                                                        |
| 2764 | - * Gets categories or count of categories matching the arguments in the request.  | 
                                                        |
| 2765 | - *  | 
                                                        |
| 2766 | - * @param int $per_page  | 
                                                        |
| 2767 | - * @param int $current_page  | 
                                                        |
| 2768 | - * @param bool $count  | 
                                                        |
| 2769 | - * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int  | 
                                                        |
| 2770 | - */  | 
                                                        |
| 2771 | - public function get_categories($per_page = 10, $current_page = 1, $count = false)  | 
                                                        |
| 2772 | -    { | 
                                                        |
| 2773 | - // testing term stuff  | 
                                                        |
| 2774 | - $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';  | 
                                                        |
| 2775 | - $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';  | 
                                                        |
| 2776 | - $limit = ($current_page - 1) * $per_page;  | 
                                                        |
| 2777 | -        $where = array('taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); | 
                                                        |
| 2778 | -        if (isset($this->_req_data['s'])) { | 
                                                        |
| 2779 | - $sstr = '%' . $this->_req_data['s'] . '%';  | 
                                                        |
| 2780 | - $where['OR'] = array(  | 
                                                        |
| 2781 | -                'Term.name'   => array('LIKE', $sstr), | 
                                                        |
| 2782 | -                'description' => array('LIKE', $sstr), | 
                                                        |
| 2783 | - );  | 
                                                        |
| 2784 | - }  | 
                                                        |
| 2785 | - $query_params = array(  | 
                                                        |
| 2786 | - $where,  | 
                                                        |
| 2787 | - 'order_by' => array($orderby => $order),  | 
                                                        |
| 2788 | - 'limit' => $limit . ',' . $per_page,  | 
                                                        |
| 2789 | -            'force_join' => array('Term'), | 
                                                        |
| 2790 | - );  | 
                                                        |
| 2791 | - $categories = $count  | 
                                                        |
| 2792 | - ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')  | 
                                                        |
| 2793 | - : EEM_Term_Taxonomy::instance()->get_all($query_params);  | 
                                                        |
| 2794 | - return $categories;  | 
                                                        |
| 2795 | - }  | 
                                                        |
| 2796 | -  | 
                                                        |
| 2797 | - /* end category stuff */  | 
                                                        |
| 2798 | - /**************/  | 
                                                        |
| 2799 | -  | 
                                                        |
| 2800 | -  | 
                                                        |
| 2801 | - /**  | 
                                                        |
| 2802 | - * Callback for the `ee_save_timezone_setting` ajax action.  | 
                                                        |
| 2803 | - *  | 
                                                        |
| 2804 | - * @throws EE_Error  | 
                                                        |
| 2805 | - */  | 
                                                        |
| 2806 | - public function save_timezonestring_setting()  | 
                                                        |
| 2807 | -    { | 
                                                        |
| 2808 | - $timezone_string = isset($this->_req_data['timezone_selected'])  | 
                                                        |
| 2809 | - ? $this->_req_data['timezone_selected']  | 
                                                        |
| 2810 | - : '';  | 
                                                        |
| 2811 | -        if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) { | 
                                                        |
| 2812 | - EE_Error::add_error(  | 
                                                        |
| 2813 | -                esc_html__('An invalid timezone string submitted.', 'event_espresso'), | 
                                                        |
| 2814 | - __FILE__,  | 
                                                        |
| 2815 | - __FUNCTION__,  | 
                                                        |
| 2816 | - __LINE__  | 
                                                        |
| 2817 | - );  | 
                                                        |
| 2818 | - $this->_template_args['error'] = true;  | 
                                                        |
| 2819 | - $this->_return_json();  | 
                                                        |
| 2820 | - }  | 
                                                        |
| 2821 | -  | 
                                                        |
| 2822 | -        update_option('timezone_string', $timezone_string); | 
                                                        |
| 2823 | - EE_Error::add_success(  | 
                                                        |
| 2824 | -            esc_html__('Your timezone string was updated.', 'event_espresso') | 
                                                        |
| 2825 | - );  | 
                                                        |
| 2826 | - $this->_template_args['success'] = true;  | 
                                                        |
| 2827 | -        $this->_return_json(true, array('action' => 'create_new')); | 
                                                        |
| 2828 | - }  | 
                                                        |
| 2199 | + // Also, we want to delete their related, non-global, tickets, prices and message templates  | 
                                                        |
| 2200 | + $related_non_global_tickets = EEM_Ticket::instance()->get_all_deleted_and_undeleted(  | 
                                                        |
| 2201 | + [  | 
                                                        |
| 2202 | + [  | 
                                                        |
| 2203 | + 'TKT_is_default' => false,  | 
                                                        |
| 2204 | + 'Datetime.EVT_ID' => $event_id  | 
                                                        |
| 2205 | + ]  | 
                                                        |
| 2206 | + ]  | 
                                                        |
| 2207 | + );  | 
                                                        |
| 2208 | + $related_non_globa_prices = EEM_Price::instance()->get_all_deleted_and_undeleted(  | 
                                                        |
| 2209 | + [  | 
                                                        |
| 2210 | + [  | 
                                                        |
| 2211 | + 'PRC_is_default' => false,  | 
                                                        |
| 2212 | + 'Ticket.Datetime.EVT_ID' => $event_id  | 
                                                        |
| 2213 | + ]  | 
                                                        |
| 2214 | + ]  | 
                                                        |
| 2215 | + );  | 
                                                        |
| 2216 | + $related_message_templates = $event->get_many_related(  | 
                                                        |
| 2217 | + 'Message_Template_Group',  | 
                                                        |
| 2218 | + [  | 
                                                        |
| 2219 | + [  | 
                                                        |
| 2220 | + 'MTP_is_global' => false  | 
                                                        |
| 2221 | + ]  | 
                                                        |
| 2222 | + ]  | 
                                                        |
| 2223 | + );  | 
                                                        |
| 2224 | + $model_objects_to_delete = array_merge(  | 
                                                        |
| 2225 | + $model_objects_to_delete,  | 
                                                        |
| 2226 | + [$event],  | 
                                                        |
| 2227 | + $related_non_global_tickets,  | 
                                                        |
| 2228 | + $related_non_globa_prices,  | 
                                                        |
| 2229 | + $related_message_templates  | 
                                                        |
| 2230 | + );  | 
                                                        |
| 2231 | + }  | 
                                                        |
| 2232 | +  | 
                                                        |
| 2233 | + // Find all the dependent model objects we want to delete.  | 
                                                        |
| 2234 | + $ids_to_delete = [];  | 
                                                        |
| 2235 | +		foreach ($model_objects_to_delete as $model_object_to_delete) { | 
                                                        |
| 2236 | + $node = new ModelObjNode($model_object_to_delete);  | 
                                                        |
| 2237 | + $node->visit(9999);  | 
                                                        |
| 2238 | + $ids_to_delete = array_replace_recursive($ids_to_delete, $node->getIds());  | 
                                                        |
| 2239 | + }  | 
                                                        |
| 2240 | +  | 
                                                        |
| 2241 | + // Delete them all, one query per model.  | 
                                                        |
| 2242 | +		foreach ($ids_to_delete as $model_name => $ids) { | 
                                                        |
| 2243 | + $model = EE_Registry::instance()->load_model($model_name);  | 
                                                        |
| 2244 | +			if ($model->has_primary_key_field()) { | 
                                                        |
| 2245 | + $where_conditions = [  | 
                                                        |
| 2246 | + $model->primary_key_name() => [  | 
                                                        |
| 2247 | + 'IN',  | 
                                                        |
| 2248 | + $ids  | 
                                                        |
| 2249 | + ]  | 
                                                        |
| 2250 | + ];  | 
                                                        |
| 2251 | +			} else { | 
                                                        |
| 2252 | + $where_conditions = [  | 
                                                        |
| 2253 | + 'OR' => []  | 
                                                        |
| 2254 | + ];  | 
                                                        |
| 2255 | +				foreach ($ids as $index_primary_key_string) { | 
                                                        |
| 2256 | + $keys_n_values = $model->parse_index_primary_key_string($index_primary_key_string);  | 
                                                        |
| 2257 | + $where_conditions['OR'][ 'AND*' . $index_primary_key_string ] = $keys_n_values;  | 
                                                        |
| 2258 | + }  | 
                                                        |
| 2259 | + }  | 
                                                        |
| 2260 | + if (!$model->delete_permanently(  | 
                                                        |
| 2261 | + [  | 
                                                        |
| 2262 | + $where_conditions  | 
                                                        |
| 2263 | + ],  | 
                                                        |
| 2264 | + false  | 
                                                        |
| 2265 | +			)) { | 
                                                        |
| 2266 | + $success = false;  | 
                                                        |
| 2267 | + }  | 
                                                        |
| 2268 | + }  | 
                                                        |
| 2269 | +		if (isset($espresso_no_ticket_prices[ $event_id ])) { | 
                                                        |
| 2270 | + unset($espresso_no_ticket_prices[ $event_id ]);  | 
                                                        |
| 2271 | + }  | 
                                                        |
| 2272 | + // Fire a legacy action.  | 
                                                        |
| 2273 | +		foreach ($event_ids as $event_id) { | 
                                                        |
| 2274 | +			do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $event_id); | 
                                                        |
| 2275 | + }  | 
                                                        |
| 2276 | +		update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); | 
                                                        |
| 2277 | + return $success;  | 
                                                        |
| 2278 | + }  | 
                                                        |
| 2279 | +  | 
                                                        |
| 2280 | + /**  | 
                                                        |
| 2281 | + * _permanently_delete_event  | 
                                                        |
| 2282 | + *  | 
                                                        |
| 2283 | + * @access private  | 
                                                        |
| 2284 | + * @param int $EVT_ID  | 
                                                        |
| 2285 | + * @return bool  | 
                                                        |
| 2286 | + */  | 
                                                        |
| 2287 | + private function _permanently_delete_event($EVT_ID = 0)  | 
                                                        |
| 2288 | +	{ | 
                                                        |
| 2289 | + // grab event id  | 
                                                        |
| 2290 | +		if (! $EVT_ID) { | 
                                                        |
| 2291 | + $msg = esc_html__(  | 
                                                        |
| 2292 | + 'An error occurred. No Event ID or an invalid Event ID was received.',  | 
                                                        |
| 2293 | + 'event_espresso'  | 
                                                        |
| 2294 | + );  | 
                                                        |
| 2295 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 2296 | + return false;  | 
                                                        |
| 2297 | + }  | 
                                                        |
| 2298 | + if (! $this->_cpt_model_obj instanceof EE_Event  | 
                                                        |
| 2299 | + || $this->_cpt_model_obj->ID() !== $EVT_ID  | 
                                                        |
| 2300 | +		) { | 
                                                        |
| 2301 | + $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);  | 
                                                        |
| 2302 | + }  | 
                                                        |
| 2303 | +		if (! $this->_cpt_model_obj instanceof EE_Event) { | 
                                                        |
| 2304 | + return false;  | 
                                                        |
| 2305 | + }  | 
                                                        |
| 2306 | + // need to delete related tickets and prices first.  | 
                                                        |
| 2307 | +		$datetimes = $this->_cpt_model_obj->get_many_related('Datetime'); | 
                                                        |
| 2308 | +		foreach ($datetimes as $datetime) { | 
                                                        |
| 2309 | + $this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime');  | 
                                                        |
| 2310 | +			$tickets = $datetime->get_many_related('Ticket'); | 
                                                        |
| 2311 | +			foreach ($tickets as $ticket) { | 
                                                        |
| 2312 | + $ticket->_remove_relation_to($datetime, 'Datetime');  | 
                                                        |
| 2313 | +				$ticket->delete_related_permanently('Price'); | 
                                                        |
| 2314 | + $ticket->delete_permanently();  | 
                                                        |
| 2315 | + }  | 
                                                        |
| 2316 | + $datetime->delete();  | 
                                                        |
| 2317 | + }  | 
                                                        |
| 2318 | + // what about related venues or terms?  | 
                                                        |
| 2319 | +		$venues = $this->_cpt_model_obj->get_many_related('Venue'); | 
                                                        |
| 2320 | +		foreach ($venues as $venue) { | 
                                                        |
| 2321 | + $this->_cpt_model_obj->_remove_relation_to($venue, 'Venue');  | 
                                                        |
| 2322 | + }  | 
                                                        |
| 2323 | + // any attached question groups?  | 
                                                        |
| 2324 | +		$question_groups = $this->_cpt_model_obj->get_many_related('Question_Group'); | 
                                                        |
| 2325 | +		if (! empty($question_groups)) { | 
                                                        |
| 2326 | +			foreach ($question_groups as $question_group) { | 
                                                        |
| 2327 | + $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group');  | 
                                                        |
| 2328 | + }  | 
                                                        |
| 2329 | + }  | 
                                                        |
| 2330 | + // Message Template Groups  | 
                                                        |
| 2331 | +		$this->_cpt_model_obj->_remove_relations('Message_Template_Group'); | 
                                                        |
| 2332 | + /** @type EE_Term_Taxonomy[] $term_taxonomies */  | 
                                                        |
| 2333 | + $term_taxonomies = $this->_cpt_model_obj->term_taxonomies();  | 
                                                        |
| 2334 | +		foreach ($term_taxonomies as $term_taxonomy) { | 
                                                        |
| 2335 | + $this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy);  | 
                                                        |
| 2336 | + }  | 
                                                        |
| 2337 | + $success = $this->_cpt_model_obj->delete_permanently();  | 
                                                        |
| 2338 | + // did it all go as planned ?  | 
                                                        |
| 2339 | +		if ($success) { | 
                                                        |
| 2340 | +			$msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID); | 
                                                        |
| 2341 | + EE_Error::add_success($msg);  | 
                                                        |
| 2342 | +		} else { | 
                                                        |
| 2343 | + $msg = sprintf(  | 
                                                        |
| 2344 | +				esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'), | 
                                                        |
| 2345 | + $EVT_ID  | 
                                                        |
| 2346 | + );  | 
                                                        |
| 2347 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 2348 | + return false;  | 
                                                        |
| 2349 | + }  | 
                                                        |
| 2350 | +		do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID); | 
                                                        |
| 2351 | + return true;  | 
                                                        |
| 2352 | + }  | 
                                                        |
| 2353 | +  | 
                                                        |
| 2354 | +  | 
                                                        |
| 2355 | + /**  | 
                                                        |
| 2356 | + * get total number of events  | 
                                                        |
| 2357 | + *  | 
                                                        |
| 2358 | + * @access public  | 
                                                        |
| 2359 | + * @return int  | 
                                                        |
| 2360 | + */  | 
                                                        |
| 2361 | + public function total_events()  | 
                                                        |
| 2362 | +	{ | 
                                                        |
| 2363 | +		$count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true); | 
                                                        |
| 2364 | + return $count;  | 
                                                        |
| 2365 | + }  | 
                                                        |
| 2366 | +  | 
                                                        |
| 2367 | +  | 
                                                        |
| 2368 | + /**  | 
                                                        |
| 2369 | + * get total number of draft events  | 
                                                        |
| 2370 | + *  | 
                                                        |
| 2371 | + * @access public  | 
                                                        |
| 2372 | + * @return int  | 
                                                        |
| 2373 | + */  | 
                                                        |
| 2374 | + public function total_events_draft()  | 
                                                        |
| 2375 | +	{ | 
                                                        |
| 2376 | + $where = array(  | 
                                                        |
| 2377 | +			'status' => array('IN', array('draft', 'auto-draft')), | 
                                                        |
| 2378 | + );  | 
                                                        |
| 2379 | + $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);  | 
                                                        |
| 2380 | + return $count;  | 
                                                        |
| 2381 | + }  | 
                                                        |
| 2382 | +  | 
                                                        |
| 2383 | +  | 
                                                        |
| 2384 | + /**  | 
                                                        |
| 2385 | + * get total number of trashed events  | 
                                                        |
| 2386 | + *  | 
                                                        |
| 2387 | + * @access public  | 
                                                        |
| 2388 | + * @return int  | 
                                                        |
| 2389 | + */  | 
                                                        |
| 2390 | + public function total_trashed_events()  | 
                                                        |
| 2391 | +	{ | 
                                                        |
| 2392 | + $where = array(  | 
                                                        |
| 2393 | + 'status' => 'trash',  | 
                                                        |
| 2394 | + );  | 
                                                        |
| 2395 | + $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);  | 
                                                        |
| 2396 | + return $count;  | 
                                                        |
| 2397 | + }  | 
                                                        |
| 2398 | +  | 
                                                        |
| 2399 | +  | 
                                                        |
| 2400 | + /**  | 
                                                        |
| 2401 | + * _default_event_settings  | 
                                                        |
| 2402 | + * This generates the Default Settings Tab  | 
                                                        |
| 2403 | + *  | 
                                                        |
| 2404 | + * @return void  | 
                                                        |
| 2405 | + * @throws EE_Error  | 
                                                        |
| 2406 | + */  | 
                                                        |
| 2407 | + protected function _default_event_settings()  | 
                                                        |
| 2408 | +	{ | 
                                                        |
| 2409 | +		$this->_set_add_edit_form_tags('update_default_event_settings'); | 
                                                        |
| 2410 | + $this->_set_publish_post_box_vars(null, false, false, null, false);  | 
                                                        |
| 2411 | + $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();  | 
                                                        |
| 2412 | + $this->display_admin_page_with_sidebar();  | 
                                                        |
| 2413 | + }  | 
                                                        |
| 2414 | +  | 
                                                        |
| 2415 | +  | 
                                                        |
| 2416 | + /**  | 
                                                        |
| 2417 | + * Return the form for event settings.  | 
                                                        |
| 2418 | + *  | 
                                                        |
| 2419 | + * @return EE_Form_Section_Proper  | 
                                                        |
| 2420 | + * @throws EE_Error  | 
                                                        |
| 2421 | + */  | 
                                                        |
| 2422 | + protected function _default_event_settings_form()  | 
                                                        |
| 2423 | +	{ | 
                                                        |
| 2424 | + $registration_config = EE_Registry::instance()->CFG->registration;  | 
                                                        |
| 2425 | + $registration_stati_for_selection = EEM_Registration::reg_status_array(  | 
                                                        |
| 2426 | + // exclude  | 
                                                        |
| 2427 | + array(  | 
                                                        |
| 2428 | + EEM_Registration::status_id_cancelled,  | 
                                                        |
| 2429 | + EEM_Registration::status_id_declined,  | 
                                                        |
| 2430 | + EEM_Registration::status_id_incomplete,  | 
                                                        |
| 2431 | + EEM_Registration::status_id_wait_list,  | 
                                                        |
| 2432 | + ),  | 
                                                        |
| 2433 | + true  | 
                                                        |
| 2434 | + );  | 
                                                        |
| 2435 | + return new EE_Form_Section_Proper(  | 
                                                        |
| 2436 | + array(  | 
                                                        |
| 2437 | + 'name' => 'update_default_event_settings',  | 
                                                        |
| 2438 | + 'html_id' => 'update_default_event_settings',  | 
                                                        |
| 2439 | + 'html_class' => 'form-table',  | 
                                                        |
| 2440 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(),  | 
                                                        |
| 2441 | + 'subsections' => apply_filters(  | 
                                                        |
| 2442 | + 'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',  | 
                                                        |
| 2443 | + array(  | 
                                                        |
| 2444 | + 'default_reg_status' => new EE_Select_Input(  | 
                                                        |
| 2445 | + $registration_stati_for_selection,  | 
                                                        |
| 2446 | + array(  | 
                                                        |
| 2447 | + 'default' => isset($registration_config->default_STS_ID)  | 
                                                        |
| 2448 | + && array_key_exists(  | 
                                                        |
| 2449 | + $registration_config->default_STS_ID,  | 
                                                        |
| 2450 | + $registration_stati_for_selection  | 
                                                        |
| 2451 | + )  | 
                                                        |
| 2452 | + ? sanitize_text_field($registration_config->default_STS_ID)  | 
                                                        |
| 2453 | + : EEM_Registration::status_id_pending_payment,  | 
                                                        |
| 2454 | +								'html_label_text' => esc_html__('Default Registration Status', 'event_espresso') | 
                                                        |
| 2455 | + . EEH_Template::get_help_tab_link(  | 
                                                        |
| 2456 | + 'default_settings_status_help_tab'  | 
                                                        |
| 2457 | + ),  | 
                                                        |
| 2458 | + 'html_help_text' => esc_html__(  | 
                                                        |
| 2459 | + 'This setting allows you to preselect what the default registration status setting is when creating an event. Note that changing this setting does NOT retroactively apply it to existing events.',  | 
                                                        |
| 2460 | + 'event_espresso'  | 
                                                        |
| 2461 | + ),  | 
                                                        |
| 2462 | + )  | 
                                                        |
| 2463 | + ),  | 
                                                        |
| 2464 | + 'default_max_tickets' => new EE_Integer_Input(  | 
                                                        |
| 2465 | + array(  | 
                                                        |
| 2466 | + 'default' => isset($registration_config->default_maximum_number_of_tickets)  | 
                                                        |
| 2467 | + ? $registration_config->default_maximum_number_of_tickets  | 
                                                        |
| 2468 | + : EEM_Event::get_default_additional_limit(),  | 
                                                        |
| 2469 | + 'html_label_text' => esc_html__(  | 
                                                        |
| 2470 | + 'Default Maximum Tickets Allowed Per Order:',  | 
                                                        |
| 2471 | + 'event_espresso'  | 
                                                        |
| 2472 | + )  | 
                                                        |
| 2473 | + . EEH_Template::get_help_tab_link(  | 
                                                        |
| 2474 | + 'default_maximum_tickets_help_tab"'  | 
                                                        |
| 2475 | + ),  | 
                                                        |
| 2476 | + 'html_help_text' => esc_html__(  | 
                                                        |
| 2477 | + 'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',  | 
                                                        |
| 2478 | + 'event_espresso'  | 
                                                        |
| 2479 | + ),  | 
                                                        |
| 2480 | + )  | 
                                                        |
| 2481 | + ),  | 
                                                        |
| 2482 | + )  | 
                                                        |
| 2483 | + ),  | 
                                                        |
| 2484 | + )  | 
                                                        |
| 2485 | + );  | 
                                                        |
| 2486 | + }  | 
                                                        |
| 2487 | +  | 
                                                        |
| 2488 | +  | 
                                                        |
| 2489 | + /**  | 
                                                        |
| 2490 | + * _update_default_event_settings  | 
                                                        |
| 2491 | + *  | 
                                                        |
| 2492 | + * @access protected  | 
                                                        |
| 2493 | + * @return void  | 
                                                        |
| 2494 | + * @throws EE_Error  | 
                                                        |
| 2495 | + */  | 
                                                        |
| 2496 | + protected function _update_default_event_settings()  | 
                                                        |
| 2497 | +	{ | 
                                                        |
| 2498 | + $registration_config = EE_Registry::instance()->CFG->registration;  | 
                                                        |
| 2499 | + $form = $this->_default_event_settings_form();  | 
                                                        |
| 2500 | +		if ($form->was_submitted()) { | 
                                                        |
| 2501 | + $form->receive_form_submission();  | 
                                                        |
| 2502 | +			if ($form->is_valid()) { | 
                                                        |
| 2503 | + $valid_data = $form->valid_data();  | 
                                                        |
| 2504 | +				if (isset($valid_data['default_reg_status'])) { | 
                                                        |
| 2505 | + $registration_config->default_STS_ID = $valid_data['default_reg_status'];  | 
                                                        |
| 2506 | + }  | 
                                                        |
| 2507 | +				if (isset($valid_data['default_max_tickets'])) { | 
                                                        |
| 2508 | + $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];  | 
                                                        |
| 2509 | + }  | 
                                                        |
| 2510 | + // update because data was valid!  | 
                                                        |
| 2511 | + EE_Registry::instance()->CFG->update_espresso_config();  | 
                                                        |
| 2512 | + EE_Error::overwrite_success();  | 
                                                        |
| 2513 | + EE_Error::add_success(  | 
                                                        |
| 2514 | +					__('Default Event Settings were updated', 'event_espresso') | 
                                                        |
| 2515 | + );  | 
                                                        |
| 2516 | + }  | 
                                                        |
| 2517 | + }  | 
                                                        |
| 2518 | +		$this->_redirect_after_action(0, '', '', array('action' => 'default_event_settings'), true); | 
                                                        |
| 2519 | + }  | 
                                                        |
| 2520 | +  | 
                                                        |
| 2521 | +  | 
                                                        |
| 2522 | + /************* Templates *************/  | 
                                                        |
| 2523 | + protected function _template_settings()  | 
                                                        |
| 2524 | +	{ | 
                                                        |
| 2525 | +		$this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso'); | 
                                                        |
| 2526 | + $this->_template_args['preview_img'] = '<img src="'  | 
                                                        |
| 2527 | + . EVENTS_ASSETS_URL  | 
                                                        |
| 2528 | + . '/images/'  | 
                                                        |
| 2529 | + . 'caffeinated_template_features.jpg" alt="'  | 
                                                        |
| 2530 | +											   . esc_attr__('Template Settings Preview screenshot', 'event_espresso') | 
                                                        |
| 2531 | + . '" />';  | 
                                                        |
| 2532 | + $this->_template_args['preview_text'] = '<strong>'  | 
                                                        |
| 2533 | + . esc_html__(  | 
                                                        |
| 2534 | + 'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',  | 
                                                        |
| 2535 | + 'event_espresso'  | 
                                                        |
| 2536 | + ) . '</strong>';  | 
                                                        |
| 2537 | +		$this->display_admin_caf_preview_page('template_settings_tab'); | 
                                                        |
| 2538 | + }  | 
                                                        |
| 2539 | +  | 
                                                        |
| 2540 | +  | 
                                                        |
| 2541 | + /** Event Category Stuff **/  | 
                                                        |
| 2542 | + /**  | 
                                                        |
| 2543 | + * set the _category property with the category object for the loaded page.  | 
                                                        |
| 2544 | + *  | 
                                                        |
| 2545 | + * @access private  | 
                                                        |
| 2546 | + * @return void  | 
                                                        |
| 2547 | + */  | 
                                                        |
| 2548 | + private function _set_category_object()  | 
                                                        |
| 2549 | +	{ | 
                                                        |
| 2550 | +		if (isset($this->_category->id) && ! empty($this->_category->id)) { | 
                                                        |
| 2551 | + return;  | 
                                                        |
| 2552 | + } //already have the category object so get out.  | 
                                                        |
| 2553 | + // set default category object  | 
                                                        |
| 2554 | + $this->_set_empty_category_object();  | 
                                                        |
| 2555 | + // only set if we've got an id  | 
                                                        |
| 2556 | +		if (! isset($this->_req_data['EVT_CAT_ID'])) { | 
                                                        |
| 2557 | + return;  | 
                                                        |
| 2558 | + }  | 
                                                        |
| 2559 | + $category_id = absint($this->_req_data['EVT_CAT_ID']);  | 
                                                        |
| 2560 | + $term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);  | 
                                                        |
| 2561 | +		if (! empty($term)) { | 
                                                        |
| 2562 | + $this->_category->category_name = $term->name;  | 
                                                        |
| 2563 | + $this->_category->category_identifier = $term->slug;  | 
                                                        |
| 2564 | + $this->_category->category_desc = $term->description;  | 
                                                        |
| 2565 | + $this->_category->id = $term->term_id;  | 
                                                        |
| 2566 | + $this->_category->parent = $term->parent;  | 
                                                        |
| 2567 | + }  | 
                                                        |
| 2568 | + }  | 
                                                        |
| 2569 | +  | 
                                                        |
| 2570 | +  | 
                                                        |
| 2571 | + /**  | 
                                                        |
| 2572 | + * Clears out category properties.  | 
                                                        |
| 2573 | + */  | 
                                                        |
| 2574 | + private function _set_empty_category_object()  | 
                                                        |
| 2575 | +	{ | 
                                                        |
| 2576 | + $this->_category = new stdClass();  | 
                                                        |
| 2577 | + $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';  | 
                                                        |
| 2578 | + $this->_category->id = $this->_category->parent = 0;  | 
                                                        |
| 2579 | + }  | 
                                                        |
| 2580 | +  | 
                                                        |
| 2581 | +  | 
                                                        |
| 2582 | + /**  | 
                                                        |
| 2583 | + * @throws EE_Error  | 
                                                        |
| 2584 | + */  | 
                                                        |
| 2585 | + protected function _category_list_table()  | 
                                                        |
| 2586 | +	{ | 
                                                        |
| 2587 | +		do_action('AHEE_log', __FILE__, __FUNCTION__, ''); | 
                                                        |
| 2588 | +		$this->_search_btn_label = esc_html__('Categories', 'event_espresso'); | 
                                                        |
| 2589 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(  | 
                                                        |
| 2590 | + 'add_category',  | 
                                                        |
| 2591 | + 'add_category',  | 
                                                        |
| 2592 | + array(),  | 
                                                        |
| 2593 | + 'add-new-h2'  | 
                                                        |
| 2594 | + );  | 
                                                        |
| 2595 | + $this->display_admin_list_table_page_with_sidebar();  | 
                                                        |
| 2596 | + }  | 
                                                        |
| 2597 | +  | 
                                                        |
| 2598 | +  | 
                                                        |
| 2599 | + /**  | 
                                                        |
| 2600 | + * Output category details view.  | 
                                                        |
| 2601 | + */  | 
                                                        |
| 2602 | + protected function _category_details($view)  | 
                                                        |
| 2603 | +	{ | 
                                                        |
| 2604 | + // load formatter helper  | 
                                                        |
| 2605 | + // load field generator helper  | 
                                                        |
| 2606 | + $route = $view == 'edit' ? 'update_category' : 'insert_category';  | 
                                                        |
| 2607 | + $this->_set_add_edit_form_tags($route);  | 
                                                        |
| 2608 | + $this->_set_category_object();  | 
                                                        |
| 2609 | + $id = ! empty($this->_category->id) ? $this->_category->id : '';  | 
                                                        |
| 2610 | + $delete_action = 'delete_category';  | 
                                                        |
| 2611 | + // custom redirect  | 
                                                        |
| 2612 | + $redirect = EE_Admin_Page::add_query_args_and_nonce(  | 
                                                        |
| 2613 | +			array('action' => 'category_list'), | 
                                                        |
| 2614 | + $this->_admin_base_url  | 
                                                        |
| 2615 | + );  | 
                                                        |
| 2616 | +		$this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect); | 
                                                        |
| 2617 | + // take care of contents  | 
                                                        |
| 2618 | + $this->_template_args['admin_page_content'] = $this->_category_details_content();  | 
                                                        |
| 2619 | + $this->display_admin_page_with_sidebar();  | 
                                                        |
| 2620 | + }  | 
                                                        |
| 2621 | +  | 
                                                        |
| 2622 | +  | 
                                                        |
| 2623 | + /**  | 
                                                        |
| 2624 | + * Output category details content.  | 
                                                        |
| 2625 | + */  | 
                                                        |
| 2626 | + protected function _category_details_content()  | 
                                                        |
| 2627 | +	{ | 
                                                        |
| 2628 | + $editor_args['category_desc'] = array(  | 
                                                        |
| 2629 | + 'type' => 'wp_editor',  | 
                                                        |
| 2630 | + 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc),  | 
                                                        |
| 2631 | + 'class' => 'my_editor_custom',  | 
                                                        |
| 2632 | +			'wpeditor_args' => array('media_buttons' => false), | 
                                                        |
| 2633 | + );  | 
                                                        |
| 2634 | + $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');  | 
                                                        |
| 2635 | + $all_terms = get_terms(  | 
                                                        |
| 2636 | + array(EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY),  | 
                                                        |
| 2637 | +			array('hide_empty' => 0, 'exclude' => array($this->_category->id)) | 
                                                        |
| 2638 | + );  | 
                                                        |
| 2639 | + // setup category select for term parents.  | 
                                                        |
| 2640 | + $category_select_values[] = array(  | 
                                                        |
| 2641 | +			'text' => esc_html__('No Parent', 'event_espresso'), | 
                                                        |
| 2642 | + 'id' => 0,  | 
                                                        |
| 2643 | + );  | 
                                                        |
| 2644 | +		foreach ($all_terms as $term) { | 
                                                        |
| 2645 | + $category_select_values[] = array(  | 
                                                        |
| 2646 | + 'text' => $term->name,  | 
                                                        |
| 2647 | + 'id' => $term->term_id,  | 
                                                        |
| 2648 | + );  | 
                                                        |
| 2649 | + }  | 
                                                        |
| 2650 | + $category_select = EEH_Form_Fields::select_input(  | 
                                                        |
| 2651 | + 'category_parent',  | 
                                                        |
| 2652 | + $category_select_values,  | 
                                                        |
| 2653 | + $this->_category->parent  | 
                                                        |
| 2654 | + );  | 
                                                        |
| 2655 | + $template_args = array(  | 
                                                        |
| 2656 | + 'category' => $this->_category,  | 
                                                        |
| 2657 | + 'category_select' => $category_select,  | 
                                                        |
| 2658 | +			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), | 
                                                        |
| 2659 | + 'category_desc_editor' => $_wp_editor['category_desc']['field'],  | 
                                                        |
| 2660 | + 'disable' => '',  | 
                                                        |
| 2661 | + 'disabled_message' => false,  | 
                                                        |
| 2662 | + );  | 
                                                        |
| 2663 | + $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';  | 
                                                        |
| 2664 | + return EEH_Template::display_template($template, $template_args, true);  | 
                                                        |
| 2665 | + }  | 
                                                        |
| 2666 | +  | 
                                                        |
| 2667 | +  | 
                                                        |
| 2668 | + /**  | 
                                                        |
| 2669 | + * Handles deleting categories.  | 
                                                        |
| 2670 | + */  | 
                                                        |
| 2671 | + protected function _delete_categories()  | 
                                                        |
| 2672 | +	{ | 
                                                        |
| 2673 | + $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID']  | 
                                                        |
| 2674 | + : (array) $this->_req_data['category_id'];  | 
                                                        |
| 2675 | +		foreach ($cat_ids as $cat_id) { | 
                                                        |
| 2676 | + $this->_delete_category($cat_id);  | 
                                                        |
| 2677 | + }  | 
                                                        |
| 2678 | + // doesn't matter what page we're coming from... we're going to the same place after delete.  | 
                                                        |
| 2679 | + $query_args = array(  | 
                                                        |
| 2680 | + 'action' => 'category_list',  | 
                                                        |
| 2681 | + );  | 
                                                        |
| 2682 | + $this->_redirect_after_action(0, '', '', $query_args);  | 
                                                        |
| 2683 | + }  | 
                                                        |
| 2684 | +  | 
                                                        |
| 2685 | +  | 
                                                        |
| 2686 | + /**  | 
                                                        |
| 2687 | + * Handles deleting specific category.  | 
                                                        |
| 2688 | + *  | 
                                                        |
| 2689 | + * @param int $cat_id  | 
                                                        |
| 2690 | + */  | 
                                                        |
| 2691 | + protected function _delete_category($cat_id)  | 
                                                        |
| 2692 | +	{ | 
                                                        |
| 2693 | + $cat_id = absint($cat_id);  | 
                                                        |
| 2694 | + wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);  | 
                                                        |
| 2695 | + }  | 
                                                        |
| 2696 | +  | 
                                                        |
| 2697 | +  | 
                                                        |
| 2698 | + /**  | 
                                                        |
| 2699 | + * Handles triggering the update or insertion of a new category.  | 
                                                        |
| 2700 | + *  | 
                                                        |
| 2701 | + * @param bool $new_category true means we're triggering the insert of a new category.  | 
                                                        |
| 2702 | + */  | 
                                                        |
| 2703 | + protected function _insert_or_update_category($new_category)  | 
                                                        |
| 2704 | +	{ | 
                                                        |
| 2705 | + $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);  | 
                                                        |
| 2706 | + $success = 0; // we already have a success message so lets not send another.  | 
                                                        |
| 2707 | +		if ($cat_id) { | 
                                                        |
| 2708 | + $query_args = array(  | 
                                                        |
| 2709 | + 'action' => 'edit_category',  | 
                                                        |
| 2710 | + 'EVT_CAT_ID' => $cat_id,  | 
                                                        |
| 2711 | + );  | 
                                                        |
| 2712 | +		} else { | 
                                                        |
| 2713 | +			$query_args = array('action' => 'add_category'); | 
                                                        |
| 2714 | + }  | 
                                                        |
| 2715 | + $this->_redirect_after_action($success, '', '', $query_args, true);  | 
                                                        |
| 2716 | + }  | 
                                                        |
| 2717 | +  | 
                                                        |
| 2718 | +  | 
                                                        |
| 2719 | + /**  | 
                                                        |
| 2720 | + * Inserts or updates category  | 
                                                        |
| 2721 | + *  | 
                                                        |
| 2722 | + * @param bool $update (true indicates we're updating a category).  | 
                                                        |
| 2723 | + * @return bool|mixed|string  | 
                                                        |
| 2724 | + */  | 
                                                        |
| 2725 | + private function _insert_category($update = false)  | 
                                                        |
| 2726 | +	{ | 
                                                        |
| 2727 | + $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : '';  | 
                                                        |
| 2728 | + $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';  | 
                                                        |
| 2729 | + $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';  | 
                                                        |
| 2730 | + $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;  | 
                                                        |
| 2731 | +		if (empty($category_name)) { | 
                                                        |
| 2732 | +			$msg = esc_html__('You must add a name for the category.', 'event_espresso'); | 
                                                        |
| 2733 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 2734 | + return false;  | 
                                                        |
| 2735 | + }  | 
                                                        |
| 2736 | + $term_args = array(  | 
                                                        |
| 2737 | + 'name' => $category_name,  | 
                                                        |
| 2738 | + 'description' => $category_desc,  | 
                                                        |
| 2739 | + 'parent' => $category_parent,  | 
                                                        |
| 2740 | + );  | 
                                                        |
| 2741 | + // was the category_identifier input disabled?  | 
                                                        |
| 2742 | +		if (isset($this->_req_data['category_identifier'])) { | 
                                                        |
| 2743 | + $term_args['slug'] = $this->_req_data['category_identifier'];  | 
                                                        |
| 2744 | + }  | 
                                                        |
| 2745 | + $insert_ids = $update  | 
                                                        |
| 2746 | + ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)  | 
                                                        |
| 2747 | + : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);  | 
                                                        |
| 2748 | +		if (! is_array($insert_ids)) { | 
                                                        |
| 2749 | + $msg = esc_html__(  | 
                                                        |
| 2750 | + 'An error occurred and the category has not been saved to the database.',  | 
                                                        |
| 2751 | + 'event_espresso'  | 
                                                        |
| 2752 | + );  | 
                                                        |
| 2753 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 2754 | +		} else { | 
                                                        |
| 2755 | + $cat_id = $insert_ids['term_id'];  | 
                                                        |
| 2756 | +			$msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name); | 
                                                        |
| 2757 | + EE_Error::add_success($msg);  | 
                                                        |
| 2758 | + }  | 
                                                        |
| 2759 | + return $cat_id;  | 
                                                        |
| 2760 | + }  | 
                                                        |
| 2761 | +  | 
                                                        |
| 2762 | +  | 
                                                        |
| 2763 | + /**  | 
                                                        |
| 2764 | + * Gets categories or count of categories matching the arguments in the request.  | 
                                                        |
| 2765 | + *  | 
                                                        |
| 2766 | + * @param int $per_page  | 
                                                        |
| 2767 | + * @param int $current_page  | 
                                                        |
| 2768 | + * @param bool $count  | 
                                                        |
| 2769 | + * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int  | 
                                                        |
| 2770 | + */  | 
                                                        |
| 2771 | + public function get_categories($per_page = 10, $current_page = 1, $count = false)  | 
                                                        |
| 2772 | +	{ | 
                                                        |
| 2773 | + // testing term stuff  | 
                                                        |
| 2774 | + $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';  | 
                                                        |
| 2775 | + $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';  | 
                                                        |
| 2776 | + $limit = ($current_page - 1) * $per_page;  | 
                                                        |
| 2777 | +		$where = array('taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); | 
                                                        |
| 2778 | +		if (isset($this->_req_data['s'])) { | 
                                                        |
| 2779 | + $sstr = '%' . $this->_req_data['s'] . '%';  | 
                                                        |
| 2780 | + $where['OR'] = array(  | 
                                                        |
| 2781 | +				'Term.name'   => array('LIKE', $sstr), | 
                                                        |
| 2782 | +				'description' => array('LIKE', $sstr), | 
                                                        |
| 2783 | + );  | 
                                                        |
| 2784 | + }  | 
                                                        |
| 2785 | + $query_params = array(  | 
                                                        |
| 2786 | + $where,  | 
                                                        |
| 2787 | + 'order_by' => array($orderby => $order),  | 
                                                        |
| 2788 | + 'limit' => $limit . ',' . $per_page,  | 
                                                        |
| 2789 | +			'force_join' => array('Term'), | 
                                                        |
| 2790 | + );  | 
                                                        |
| 2791 | + $categories = $count  | 
                                                        |
| 2792 | + ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')  | 
                                                        |
| 2793 | + : EEM_Term_Taxonomy::instance()->get_all($query_params);  | 
                                                        |
| 2794 | + return $categories;  | 
                                                        |
| 2795 | + }  | 
                                                        |
| 2796 | +  | 
                                                        |
| 2797 | + /* end category stuff */  | 
                                                        |
| 2798 | + /**************/  | 
                                                        |
| 2799 | +  | 
                                                        |
| 2800 | +  | 
                                                        |
| 2801 | + /**  | 
                                                        |
| 2802 | + * Callback for the `ee_save_timezone_setting` ajax action.  | 
                                                        |
| 2803 | + *  | 
                                                        |
| 2804 | + * @throws EE_Error  | 
                                                        |
| 2805 | + */  | 
                                                        |
| 2806 | + public function save_timezonestring_setting()  | 
                                                        |
| 2807 | +	{ | 
                                                        |
| 2808 | + $timezone_string = isset($this->_req_data['timezone_selected'])  | 
                                                        |
| 2809 | + ? $this->_req_data['timezone_selected']  | 
                                                        |
| 2810 | + : '';  | 
                                                        |
| 2811 | +		if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) { | 
                                                        |
| 2812 | + EE_Error::add_error(  | 
                                                        |
| 2813 | +				esc_html__('An invalid timezone string submitted.', 'event_espresso'), | 
                                                        |
| 2814 | + __FILE__,  | 
                                                        |
| 2815 | + __FUNCTION__,  | 
                                                        |
| 2816 | + __LINE__  | 
                                                        |
| 2817 | + );  | 
                                                        |
| 2818 | + $this->_template_args['error'] = true;  | 
                                                        |
| 2819 | + $this->_return_json();  | 
                                                        |
| 2820 | + }  | 
                                                        |
| 2821 | +  | 
                                                        |
| 2822 | +		update_option('timezone_string', $timezone_string); | 
                                                        |
| 2823 | + EE_Error::add_success(  | 
                                                        |
| 2824 | +			esc_html__('Your timezone string was updated.', 'event_espresso') | 
                                                        |
| 2825 | + );  | 
                                                        |
| 2826 | + $this->_template_args['success'] = true;  | 
                                                        |
| 2827 | +		$this->_return_json(true, array('action' => 'create_new')); | 
                                                        |
| 2828 | + }  | 
                                                        |
| 2829 | 2829 | }  | 
                                                        
@@ -577,11 +577,11 @@ discard block  | 
                                                    ||
| 577 | 577 |      { | 
                                                        
| 578 | 578 | wp_register_style(  | 
                                                        
| 579 | 579 | 'events-admin-css',  | 
                                                        
| 580 | - EVENTS_ASSETS_URL . 'events-admin-page.css',  | 
                                                        |
| 580 | + EVENTS_ASSETS_URL.'events-admin-page.css',  | 
                                                        |
| 581 | 581 | array(),  | 
                                                        
| 582 | 582 | EVENT_ESPRESSO_VERSION  | 
                                                        
| 583 | 583 | );  | 
                                                        
| 584 | -        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); | 
                                                        |
| 584 | +        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL.'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); | 
                                                        |
| 585 | 585 |          wp_enqueue_style('events-admin-css'); | 
                                                        
| 586 | 586 |          wp_enqueue_style('ee-cat-admin'); | 
                                                        
| 587 | 587 | // todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details  | 
                                                        
@@ -589,7 +589,7 @@ discard block  | 
                                                    ||
| 589 | 589 | // scripts  | 
                                                        
| 590 | 590 | wp_register_script(  | 
                                                        
| 591 | 591 | 'event_editor_js',  | 
                                                        
| 592 | - EVENTS_ASSETS_URL . 'event_editor.js',  | 
                                                        |
| 592 | + EVENTS_ASSETS_URL.'event_editor.js',  | 
                                                        |
| 593 | 593 |              array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'), | 
                                                        
| 594 | 594 | EVENT_ESPRESSO_VERSION,  | 
                                                        
| 595 | 595 | true  | 
                                                        
@@ -615,7 +615,7 @@ discard block  | 
                                                    ||
| 615 | 615 |          wp_enqueue_style('espresso-ui-theme'); | 
                                                        
| 616 | 616 | wp_register_style(  | 
                                                        
| 617 | 617 | 'event-editor-css',  | 
                                                        
| 618 | - EVENTS_ASSETS_URL . 'event-editor.css',  | 
                                                        |
| 618 | + EVENTS_ASSETS_URL.'event-editor.css',  | 
                                                        |
| 619 | 619 |              array('ee-admin-css'), | 
                                                        
| 620 | 620 | EVENT_ESPRESSO_VERSION  | 
                                                        
| 621 | 621 | );  | 
                                                        
@@ -623,7 +623,7 @@ discard block  | 
                                                    ||
| 623 | 623 | // scripts  | 
                                                        
| 624 | 624 | wp_register_script(  | 
                                                        
| 625 | 625 | 'event-datetime-metabox',  | 
                                                        
| 626 | - EVENTS_ASSETS_URL . 'event-datetime-metabox.js',  | 
                                                        |
| 626 | + EVENTS_ASSETS_URL.'event-datetime-metabox.js',  | 
                                                        |
| 627 | 627 |              array('event_editor_js', 'ee-datepicker'), | 
                                                        
| 628 | 628 | EVENT_ESPRESSO_VERSION  | 
                                                        
| 629 | 629 | );  | 
                                                        
@@ -692,7 +692,7 @@ discard block  | 
                                                    ||
| 692 | 692 | public function verify_event_edit($event = null, $req_type = '')  | 
                                                        
| 693 | 693 |      { | 
                                                        
| 694 | 694 | // don't need to do this when processing  | 
                                                        
| 695 | -        if (! empty($req_type)) { | 
                                                        |
| 695 | +        if ( ! empty($req_type)) { | 
                                                        |
| 696 | 696 | return;  | 
                                                        
| 697 | 697 | }  | 
                                                        
| 698 | 698 | // no event?  | 
                                                        
@@ -701,7 +701,7 @@ discard block  | 
                                                    ||
| 701 | 701 | $event = $this->_cpt_model_obj;  | 
                                                        
| 702 | 702 | }  | 
                                                        
| 703 | 703 | // STILL no event?  | 
                                                        
| 704 | -        if (! $event instanceof EE_Event) { | 
                                                        |
| 704 | +        if ( ! $event instanceof EE_Event) { | 
                                                        |
| 705 | 705 | return;  | 
                                                        
| 706 | 706 | }  | 
                                                        
| 707 | 707 | $orig_status = $event->status();  | 
                                                        
@@ -739,7 +739,7 @@ discard block  | 
                                                    ||
| 739 | 739 | );  | 
                                                        
| 740 | 740 | }  | 
                                                        
| 741 | 741 | // now we need to determine if the event has any tickets on sale. If not then we dont' show the error  | 
                                                        
| 742 | -        if (! $event->tickets_on_sale()) { | 
                                                        |
| 742 | +        if ( ! $event->tickets_on_sale()) { | 
                                                        |
| 743 | 743 | return;  | 
                                                        
| 744 | 744 | }  | 
                                                        
| 745 | 745 | // made it here so show warning  | 
                                                        
@@ -784,7 +784,7 @@ discard block  | 
                                                    ||
| 784 | 784 |      { | 
                                                        
| 785 | 785 |          $has_timezone_string = get_option('timezone_string'); | 
                                                        
| 786 | 786 | // only nag them about setting their timezone if it's their first event, and they haven't already done it  | 
                                                        
| 787 | -        if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) { | 
                                                        |
| 787 | +        if ( ! $has_timezone_string && ! EEM_Event::instance()->exists(array())) { | 
                                                        |
| 788 | 788 | EE_Error::add_attention(  | 
                                                        
| 789 | 789 | sprintf(  | 
                                                        
| 790 | 790 | __(  | 
                                                        
@@ -868,31 +868,31 @@ discard block  | 
                                                    ||
| 868 | 868 |          $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); | 
                                                        
| 869 | 869 | $statuses = array(  | 
                                                        
| 870 | 870 | 'sold_out_status' => array(  | 
                                                        
| 871 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,  | 
                                                        |
| 871 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::sold_out,  | 
                                                        |
| 872 | 872 | 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),  | 
                                                        
| 873 | 873 | ),  | 
                                                        
| 874 | 874 | 'active_status' => array(  | 
                                                        
| 875 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,  | 
                                                        |
| 875 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::active,  | 
                                                        |
| 876 | 876 | 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),  | 
                                                        
| 877 | 877 | ),  | 
                                                        
| 878 | 878 | 'upcoming_status' => array(  | 
                                                        
| 879 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,  | 
                                                        |
| 879 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::upcoming,  | 
                                                        |
| 880 | 880 | 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),  | 
                                                        
| 881 | 881 | ),  | 
                                                        
| 882 | 882 | 'postponed_status' => array(  | 
                                                        
| 883 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,  | 
                                                        |
| 883 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::postponed,  | 
                                                        |
| 884 | 884 | 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),  | 
                                                        
| 885 | 885 | ),  | 
                                                        
| 886 | 886 | 'cancelled_status' => array(  | 
                                                        
| 887 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,  | 
                                                        |
| 887 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::cancelled,  | 
                                                        |
| 888 | 888 | 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),  | 
                                                        
| 889 | 889 | ),  | 
                                                        
| 890 | 890 | 'expired_status' => array(  | 
                                                        
| 891 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,  | 
                                                        |
| 891 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::expired,  | 
                                                        |
| 892 | 892 | 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),  | 
                                                        
| 893 | 893 | ),  | 
                                                        
| 894 | 894 | 'inactive_status' => array(  | 
                                                        
| 895 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,  | 
                                                        |
| 895 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::inactive,  | 
                                                        |
| 896 | 896 | 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),  | 
                                                        
| 897 | 897 | ),  | 
                                                        
| 898 | 898 | );  | 
                                                        
@@ -906,7 +906,7 @@ discard block  | 
                                                    ||
| 906 | 906 | */  | 
                                                        
| 907 | 907 | private function _event_model()  | 
                                                        
| 908 | 908 |      { | 
                                                        
| 909 | -        if (! $this->_event_model instanceof EEM_Event) { | 
                                                        |
| 909 | +        if ( ! $this->_event_model instanceof EEM_Event) { | 
                                                        |
| 910 | 910 |              $this->_event_model = EE_Registry::instance()->load_model('Event'); | 
                                                        
| 911 | 911 | }  | 
                                                        
| 912 | 912 | return $this->_event_model;  | 
                                                        
@@ -926,7 +926,7 @@ discard block  | 
                                                    ||
| 926 | 926 | public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)  | 
                                                        
| 927 | 927 |      { | 
                                                        
| 928 | 928 | // make sure this is only when editing  | 
                                                        
| 929 | -        if (! empty($id)) { | 
                                                        |
| 929 | +        if ( ! empty($id)) { | 
                                                        |
| 930 | 930 | $post = get_post($id);  | 
                                                        
| 931 | 931 | $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">'  | 
                                                        
| 932 | 932 |                         . esc_html__('Shortcode', 'event_espresso') | 
                                                        
@@ -960,7 +960,7 @@ discard block  | 
                                                    ||
| 960 | 960 | 'button'  | 
                                                        
| 961 | 961 | );  | 
                                                        
| 962 | 962 | $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());  | 
                                                        
| 963 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(  | 
                                                        |
| 963 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button(  | 
                                                        |
| 964 | 964 | 'create_new',  | 
                                                        
| 965 | 965 | 'add',  | 
                                                        
| 966 | 966 | array(),  | 
                                                        
@@ -1100,7 +1100,7 @@ discard block  | 
                                                    ||
| 1100 | 1100 | */  | 
                                                        
| 1101 | 1101 | protected function _default_venue_update(\EE_Event $evtobj, $data)  | 
                                                        
| 1102 | 1102 |      { | 
                                                        
| 1103 | - require_once(EE_MODELS . 'EEM_Venue.model.php');  | 
                                                        |
| 1103 | + require_once(EE_MODELS.'EEM_Venue.model.php');  | 
                                                        |
| 1104 | 1104 |          $venue_model = EE_Registry::instance()->load_model('Venue'); | 
                                                        
| 1105 | 1105 | $rows_affected = null;  | 
                                                        
| 1106 | 1106 | $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;  | 
                                                        
@@ -1131,7 +1131,7 @@ discard block  | 
                                                    ||
| 1131 | 1131 | 'status' => 'publish',  | 
                                                        
| 1132 | 1132 | );  | 
                                                        
| 1133 | 1133 | // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.  | 
                                                        
| 1134 | -        if (! empty($venue_id)) { | 
                                                        |
| 1134 | +        if ( ! empty($venue_id)) { | 
                                                        |
| 1135 | 1135 | $update_where = array($venue_model->primary_key_name() => $venue_id);  | 
                                                        
| 1136 | 1136 | $rows_affected = $venue_model->update($venue_array, array($update_where));  | 
                                                        
| 1137 | 1137 | // we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.  | 
                                                        
@@ -1173,7 +1173,7 @@ discard block  | 
                                                    ||
| 1173 | 1173 | 'DTT_order' => $row,  | 
                                                        
| 1174 | 1174 | );  | 
                                                        
| 1175 | 1175 | // if we have an id then let's get existing object first and then set the new values. Otherwise we instantiate a new object for save.  | 
                                                        
| 1176 | -            if (! empty($dtt['DTT_ID'])) { | 
                                                        |
| 1176 | +            if ( ! empty($dtt['DTT_ID'])) { | 
                                                        |
| 1177 | 1177 | $DTM = EE_Registry::instance()  | 
                                                        
| 1178 | 1178 |                                    ->load_model('Datetime', array($evtobj->get_timezone())) | 
                                                        
| 1179 | 1179 | ->get_one_by_ID($dtt['DTT_ID']);  | 
                                                        
@@ -1183,7 +1183,7 @@ discard block  | 
                                                    ||
| 1183 | 1183 | $DTM->set($field, $value);  | 
                                                        
| 1184 | 1184 | }  | 
                                                        
| 1185 | 1185 | // make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it. We need to do this so we dont' TRASH the parent DTT.  | 
                                                        
| 1186 | - $saved_dtts[ $DTM->ID() ] = $DTM;  | 
                                                        |
| 1186 | + $saved_dtts[$DTM->ID()] = $DTM;  | 
                                                        |
| 1187 | 1187 |              } else { | 
                                                        
| 1188 | 1188 | $DTM = EE_Registry::instance()->load_class(  | 
                                                        
| 1189 | 1189 | 'Datetime',  | 
                                                        
@@ -1216,14 +1216,14 @@ discard block  | 
                                                    ||
| 1216 | 1216 |          foreach ($data['edit_tickets'] as $row => $tkt) { | 
                                                        
| 1217 | 1217 |              $incoming_date_formats = array('Y-m-d', 'h:i a'); | 
                                                        
| 1218 | 1218 | $update_prices = false;  | 
                                                        
| 1219 | - $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount'])  | 
                                                        |
| 1220 | - ? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0;  | 
                                                        |
| 1219 | + $ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount'])  | 
                                                        |
| 1220 | + ? $data['edit_prices'][$row][1]['PRC_amount'] : 0;  | 
                                                        |
| 1221 | 1221 | // trim inputs to ensure any excess whitespace is removed.  | 
                                                        
| 1222 | 1222 |              $tkt = array_map('trim', $tkt); | 
                                                        
| 1223 | 1223 |              if (empty($tkt['TKT_start_date'])) { | 
                                                        
| 1224 | 1224 | // let's use now in the set timezone.  | 
                                                        
| 1225 | 1225 |                  $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); | 
                                                        
| 1226 | - $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);  | 
                                                        |
| 1226 | + $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0].' '.$incoming_date_formats[1]);  | 
                                                        |
| 1227 | 1227 | }  | 
                                                        
| 1228 | 1228 |              if (empty($tkt['TKT_end_date'])) { | 
                                                        
| 1229 | 1229 | // use the start date of the first datetime  | 
                                                        
@@ -1258,7 +1258,7 @@ discard block  | 
                                                    ||
| 1258 | 1258 | // if we have a TKT_ID then we need to get that existing TKT_obj and update it  | 
                                                        
| 1259 | 1259 | // we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.  | 
                                                        
| 1260 | 1260 | // keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived.  | 
                                                        
| 1261 | -            if (! empty($tkt['TKT_ID'])) { | 
                                                        |
| 1261 | +            if ( ! empty($tkt['TKT_ID'])) { | 
                                                        |
| 1262 | 1262 | $TKT = EE_Registry::instance()  | 
                                                        
| 1263 | 1263 |                                    ->load_model('Ticket', array($evtobj->get_timezone())) | 
                                                        
| 1264 | 1264 | ->get_one_by_ID($tkt['TKT_ID']);  | 
                                                        
@@ -1293,7 +1293,7 @@ discard block  | 
                                                    ||
| 1293 | 1293 |                          $TKT->set('TKT_deleted', 1); | 
                                                        
| 1294 | 1294 | $TKT->save();  | 
                                                        
| 1295 | 1295 | // make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.  | 
                                                        
| 1296 | - $saved_tickets[ $TKT->ID() ] = $TKT;  | 
                                                        |
| 1296 | + $saved_tickets[$TKT->ID()] = $TKT;  | 
                                                        |
| 1297 | 1297 | // create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it.  | 
                                                        
| 1298 | 1298 | $TKT = clone $TKT;  | 
                                                        
| 1299 | 1299 |                          $TKT->set('TKT_ID', 0); | 
                                                        
@@ -1338,9 +1338,9 @@ discard block  | 
                                                    ||
| 1338 | 1338 | }  | 
                                                        
| 1339 | 1339 | // initially let's add the ticket to the dtt  | 
                                                        
| 1340 | 1340 | $saved_dtt->_add_relation_to($TKT, 'Ticket');  | 
                                                        
| 1341 | - $saved_tickets[ $TKT->ID() ] = $TKT;  | 
                                                        |
| 1341 | + $saved_tickets[$TKT->ID()] = $TKT;  | 
                                                        |
| 1342 | 1342 | // add prices to ticket  | 
                                                        
| 1343 | - $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices);  | 
                                                        |
| 1343 | + $this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices);  | 
                                                        |
| 1344 | 1344 | }  | 
                                                        
| 1345 | 1345 | // however now we need to handle permanently deleting tickets via the ui. Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db.  | 
                                                        
| 1346 | 1346 | $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;  | 
                                                        
@@ -1497,7 +1497,7 @@ discard block  | 
                                                    ||
| 1497 | 1497 | $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();  | 
                                                        
| 1498 | 1498 | // load template  | 
                                                        
| 1499 | 1499 | EEH_Template::display_template(  | 
                                                        
| 1500 | - EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',  | 
                                                        |
| 1500 | + EVENTS_TEMPLATE_PATH.'event_publish_box_extras.template.php',  | 
                                                        |
| 1501 | 1501 | $publish_box_extra_args  | 
                                                        
| 1502 | 1502 | );  | 
                                                        
| 1503 | 1503 | }  | 
                                                        
@@ -1589,7 +1589,7 @@ discard block  | 
                                                    ||
| 1589 | 1589 | 'default_where_conditions' => 'none',  | 
                                                        
| 1590 | 1590 | )  | 
                                                        
| 1591 | 1591 | );  | 
                                                        
| 1592 | -            if (! empty($related_tickets)) { | 
                                                        |
| 1592 | +            if ( ! empty($related_tickets)) { | 
                                                        |
| 1593 | 1593 | $template_args['total_ticket_rows'] = count($related_tickets);  | 
                                                        
| 1594 | 1594 | $row = 0;  | 
                                                        
| 1595 | 1595 |                  foreach ($related_tickets as $ticket) { | 
                                                        
@@ -1623,7 +1623,7 @@ discard block  | 
                                                    ||
| 1623 | 1623 | );  | 
                                                        
| 1624 | 1624 | $template = apply_filters(  | 
                                                        
| 1625 | 1625 | 'FHEE__Events_Admin_Page__ticket_metabox__template',  | 
                                                        
| 1626 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'  | 
                                                        |
| 1626 | + EVENTS_TEMPLATE_PATH.'event_tickets_metabox_main.template.php'  | 
                                                        |
| 1627 | 1627 | );  | 
                                                        
| 1628 | 1628 | EEH_Template::display_template($template, $template_args);  | 
                                                        
| 1629 | 1629 | }  | 
                                                        
@@ -1641,7 +1641,7 @@ discard block  | 
                                                    ||
| 1641 | 1641 | private function _get_ticket_row($ticket, $skeleton = false, $row = 0)  | 
                                                        
| 1642 | 1642 |      { | 
                                                        
| 1643 | 1643 | $template_args = array(  | 
                                                        
| 1644 | - 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(),  | 
                                                        |
| 1644 | + 'tkt_status_class' => ' tkt-status-'.$ticket->ticket_status(),  | 
                                                        |
| 1645 | 1645 | 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'  | 
                                                        
| 1646 | 1646 | : '',  | 
                                                        
| 1647 | 1647 | 'ticketrow' => $skeleton ? 'TICKETNUM' : $row,  | 
                                                        
@@ -1653,10 +1653,10 @@ discard block  | 
                                                    ||
| 1653 | 1653 |              'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'), | 
                                                        
| 1654 | 1654 | 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',  | 
                                                        
| 1655 | 1655 |              'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'), | 
                                                        
| 1656 | -            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted'))) | 
                                                        |
| 1657 | -                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0) | 
                                                        |
| 1656 | +            'trash_icon'          => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted'))) | 
                                                        |
| 1657 | +                                     && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0) | 
                                                        |
| 1658 | 1658 | ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',  | 
                                                        
| 1659 | -            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' | 
                                                        |
| 1659 | +            'disabled'            => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' | 
                                                        |
| 1660 | 1660 | : ' disabled=disabled',  | 
                                                        
| 1661 | 1661 | );  | 
                                                        
| 1662 | 1662 | $price = $ticket->ID() !== 0  | 
                                                        
@@ -1683,7 +1683,7 @@ discard block  | 
                                                    ||
| 1683 | 1683 |                      array('order_by' => array('DTT_EVT_start' => 'ASC')) | 
                                                        
| 1684 | 1684 | )  | 
                                                        
| 1685 | 1685 | : null;  | 
                                                        
| 1686 | -            if (! empty($earliest_dtt)) { | 
                                                        |
| 1686 | +            if ( ! empty($earliest_dtt)) { | 
                                                        |
| 1687 | 1687 |                  $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a'); | 
                                                        
| 1688 | 1688 |              } else { | 
                                                        
| 1689 | 1689 | $template_args['TKT_end_date'] = date(  | 
                                                        
@@ -1695,7 +1695,7 @@ discard block  | 
                                                    ||
| 1695 | 1695 | $template_args = array_merge($template_args, $price_args);  | 
                                                        
| 1696 | 1696 | $template = apply_filters(  | 
                                                        
| 1697 | 1697 | 'FHEE__Events_Admin_Page__get_ticket_row__template',  | 
                                                        
| 1698 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',  | 
                                                        |
| 1698 | + EVENTS_TEMPLATE_PATH.'event_tickets_metabox_ticket_row.template.php',  | 
                                                        |
| 1699 | 1699 | $ticket  | 
                                                        
| 1700 | 1700 | );  | 
                                                        
| 1701 | 1701 | return EEH_Template::display_template($template, $template_args, true);  | 
                                                        
@@ -1749,7 +1749,7 @@ discard block  | 
                                                    ||
| 1749 | 1749 | $default_reg_status_values  | 
                                                        
| 1750 | 1750 | );  | 
                                                        
| 1751 | 1751 | EEH_Template::display_template(  | 
                                                        
| 1752 | - EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',  | 
                                                        |
| 1752 | + EVENTS_TEMPLATE_PATH.'event_registration_options.template.php',  | 
                                                        |
| 1753 | 1753 | $template_args  | 
                                                        
| 1754 | 1754 | );  | 
                                                        
| 1755 | 1755 | }  | 
                                                        
@@ -1771,7 +1771,7 @@ discard block  | 
                                                    ||
| 1771 | 1771 |      { | 
                                                        
| 1772 | 1772 | $EEME = $this->_event_model();  | 
                                                        
| 1773 | 1773 | $offset = ($current_page - 1) * $per_page;  | 
                                                        
| 1774 | - $limit = $count ? null : $offset . ',' . $per_page;  | 
                                                        |
| 1774 | + $limit = $count ? null : $offset.','.$per_page;  | 
                                                        |
| 1775 | 1775 | $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';  | 
                                                        
| 1776 | 1776 | $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";  | 
                                                        
| 1777 | 1777 |          if (isset($this->_req_data['month_range'])) { | 
                                                        
@@ -1800,7 +1800,7 @@ discard block  | 
                                                    ||
| 1800 | 1800 | // categories?  | 
                                                        
| 1801 | 1801 | $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0  | 
                                                        
| 1802 | 1802 | ? $this->_req_data['EVT_CAT'] : null;  | 
                                                        
| 1803 | -        if (! empty($category)) { | 
                                                        |
| 1803 | +        if ( ! empty($category)) { | 
                                                        |
| 1804 | 1804 | $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;  | 
                                                        
| 1805 | 1805 | $where['Term_Taxonomy.term_id'] = $category;  | 
                                                        
| 1806 | 1806 | }  | 
                                                        
@@ -1808,7 +1808,7 @@ discard block  | 
                                                    ||
| 1808 | 1808 |          $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); | 
                                                        
| 1809 | 1809 |          if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') { | 
                                                        
| 1810 | 1810 | $DateTime = new DateTime(  | 
                                                        
| 1811 | - $year_r . '-' . $month_r . '-01 00:00:00',  | 
                                                        |
| 1811 | + $year_r.'-'.$month_r.'-01 00:00:00',  | 
                                                        |
| 1812 | 1812 | new DateTimeZone(EEM_Datetime::instance()->get_timezone())  | 
                                                        
| 1813 | 1813 | );  | 
                                                        
| 1814 | 1814 |              $start = $DateTime->format(implode(' ', $start_formats)); | 
                                                        
@@ -1834,11 +1834,11 @@ discard block  | 
                                                    ||
| 1834 | 1834 |                              ->format(implode(' ', $start_formats)); | 
                                                        
| 1835 | 1835 |              $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); | 
                                                        
| 1836 | 1836 | }  | 
                                                        
| 1837 | -        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { | 
                                                        |
| 1837 | +        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { | 
                                                        |
| 1838 | 1838 | $where['EVT_wp_user'] = get_current_user_id();  | 
                                                        
| 1839 | 1839 |          } else { | 
                                                        
| 1840 | -            if (! isset($where['status'])) { | 
                                                        |
| 1841 | -                if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { | 
                                                        |
| 1840 | +            if ( ! isset($where['status'])) { | 
                                                        |
| 1841 | +                if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { | 
                                                        |
| 1842 | 1842 | $where['OR'] = array(  | 
                                                        
| 1843 | 1843 |                          'status*restrict_private' => array('!=', 'private'), | 
                                                        
| 1844 | 1844 | 'AND' => array(  | 
                                                        
@@ -1858,7 +1858,7 @@ discard block  | 
                                                    ||
| 1858 | 1858 | }  | 
                                                        
| 1859 | 1859 | // search query handling  | 
                                                        
| 1860 | 1860 |          if (isset($this->_req_data['s'])) { | 
                                                        
| 1861 | - $search_string = '%' . $this->_req_data['s'] . '%';  | 
                                                        |
| 1861 | + $search_string = '%'.$this->_req_data['s'].'%';  | 
                                                        |
| 1862 | 1862 | $where['OR'] = array(  | 
                                                        
| 1863 | 1863 |                  'EVT_name'       => array('LIKE', $search_string), | 
                                                        
| 1864 | 1864 |                  'EVT_desc'       => array('LIKE', $search_string), | 
                                                        
@@ -1953,7 +1953,7 @@ discard block  | 
                                                    ||
| 1953 | 1953 | // clean status  | 
                                                        
| 1954 | 1954 | $event_status = sanitize_key($event_status);  | 
                                                        
| 1955 | 1955 | // grab status  | 
                                                        
| 1956 | -            if (! empty($event_status)) { | 
                                                        |
| 1956 | +            if ( ! empty($event_status)) { | 
                                                        |
| 1957 | 1957 | $success = $this->_change_event_status($EVT_ID, $event_status);  | 
                                                        
| 1958 | 1958 |              } else { | 
                                                        
| 1959 | 1959 | $success = false;  | 
                                                        
@@ -1990,7 +1990,7 @@ discard block  | 
                                                    ||
| 1990 | 1990 | // clean status  | 
                                                        
| 1991 | 1991 | $event_status = sanitize_key($event_status);  | 
                                                        
| 1992 | 1992 | // grab status  | 
                                                        
| 1993 | -        if (! empty($event_status)) { | 
                                                        |
| 1993 | +        if ( ! empty($event_status)) { | 
                                                        |
| 1994 | 1994 | $success = true;  | 
                                                        
| 1995 | 1995 | // determine the event id and set to array.  | 
                                                        
| 1996 | 1996 | $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();  | 
                                                        
@@ -2037,7 +2037,7 @@ discard block  | 
                                                    ||
| 2037 | 2037 | private function _change_event_status($EVT_ID = 0, $event_status = '')  | 
                                                        
| 2038 | 2038 |      { | 
                                                        
| 2039 | 2039 | // grab event id  | 
                                                        
| 2040 | -        if (! $EVT_ID) { | 
                                                        |
| 2040 | +        if ( ! $EVT_ID) { | 
                                                        |
| 2041 | 2041 | $msg = esc_html__(  | 
                                                        
| 2042 | 2042 | 'An error occurred. No Event ID or an invalid Event ID was received.',  | 
                                                        
| 2043 | 2043 | 'event_espresso'  | 
                                                        
@@ -2145,7 +2145,7 @@ discard block  | 
                                                    ||
| 2145 | 2145 | $confirm_deletion_args['EVT_IDs[]'] = (int) $EVT_ID;  | 
                                                        
| 2146 | 2146 | }  | 
                                                        
| 2147 | 2147 | $this->_template_args['admin_page_content'] = EEH_Template::display_template(  | 
                                                        
| 2148 | - EVENTS_TEMPLATE_PATH . 'event_preview_deletion.template.php',  | 
                                                        |
| 2148 | + EVENTS_TEMPLATE_PATH.'event_preview_deletion.template.php',  | 
                                                        |
| 2149 | 2149 | [  | 
                                                        
| 2150 | 2150 | 'form_url' => EE_Admin_Page::add_query_args_and_nonce(  | 
                                                        
| 2151 | 2151 | $confirm_deletion_args,  | 
                                                        
@@ -2254,10 +2254,10 @@ discard block  | 
                                                    ||
| 2254 | 2254 | ];  | 
                                                        
| 2255 | 2255 |                  foreach ($ids as $index_primary_key_string) { | 
                                                        
| 2256 | 2256 | $keys_n_values = $model->parse_index_primary_key_string($index_primary_key_string);  | 
                                                        
| 2257 | - $where_conditions['OR'][ 'AND*' . $index_primary_key_string ] = $keys_n_values;  | 
                                                        |
| 2257 | + $where_conditions['OR']['AND*'.$index_primary_key_string] = $keys_n_values;  | 
                                                        |
| 2258 | 2258 | }  | 
                                                        
| 2259 | 2259 | }  | 
                                                        
| 2260 | - if (!$model->delete_permanently(  | 
                                                        |
| 2260 | + if ( ! $model->delete_permanently(  | 
                                                        |
| 2261 | 2261 | [  | 
                                                        
| 2262 | 2262 | $where_conditions  | 
                                                        
| 2263 | 2263 | ],  | 
                                                        
@@ -2266,8 +2266,8 @@ discard block  | 
                                                    ||
| 2266 | 2266 | $success = false;  | 
                                                        
| 2267 | 2267 | }  | 
                                                        
| 2268 | 2268 | }  | 
                                                        
| 2269 | -        if (isset($espresso_no_ticket_prices[ $event_id ])) { | 
                                                        |
| 2270 | - unset($espresso_no_ticket_prices[ $event_id ]);  | 
                                                        |
| 2269 | +        if (isset($espresso_no_ticket_prices[$event_id])) { | 
                                                        |
| 2270 | + unset($espresso_no_ticket_prices[$event_id]);  | 
                                                        |
| 2271 | 2271 | }  | 
                                                        
| 2272 | 2272 | // Fire a legacy action.  | 
                                                        
| 2273 | 2273 |          foreach ($event_ids as $event_id) { | 
                                                        
@@ -2287,7 +2287,7 @@ discard block  | 
                                                    ||
| 2287 | 2287 | private function _permanently_delete_event($EVT_ID = 0)  | 
                                                        
| 2288 | 2288 |      { | 
                                                        
| 2289 | 2289 | // grab event id  | 
                                                        
| 2290 | -        if (! $EVT_ID) { | 
                                                        |
| 2290 | +        if ( ! $EVT_ID) { | 
                                                        |
| 2291 | 2291 | $msg = esc_html__(  | 
                                                        
| 2292 | 2292 | 'An error occurred. No Event ID or an invalid Event ID was received.',  | 
                                                        
| 2293 | 2293 | 'event_espresso'  | 
                                                        
@@ -2295,12 +2295,12 @@ discard block  | 
                                                    ||
| 2295 | 2295 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);  | 
                                                        
| 2296 | 2296 | return false;  | 
                                                        
| 2297 | 2297 | }  | 
                                                        
| 2298 | - if (! $this->_cpt_model_obj instanceof EE_Event  | 
                                                        |
| 2298 | + if ( ! $this->_cpt_model_obj instanceof EE_Event  | 
                                                        |
| 2299 | 2299 | || $this->_cpt_model_obj->ID() !== $EVT_ID  | 
                                                        
| 2300 | 2300 |          ) { | 
                                                        
| 2301 | 2301 | $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);  | 
                                                        
| 2302 | 2302 | }  | 
                                                        
| 2303 | -        if (! $this->_cpt_model_obj instanceof EE_Event) { | 
                                                        |
| 2303 | +        if ( ! $this->_cpt_model_obj instanceof EE_Event) { | 
                                                        |
| 2304 | 2304 | return false;  | 
                                                        
| 2305 | 2305 | }  | 
                                                        
| 2306 | 2306 | // need to delete related tickets and prices first.  | 
                                                        
@@ -2322,7 +2322,7 @@ discard block  | 
                                                    ||
| 2322 | 2322 | }  | 
                                                        
| 2323 | 2323 | // any attached question groups?  | 
                                                        
| 2324 | 2324 |          $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group'); | 
                                                        
| 2325 | -        if (! empty($question_groups)) { | 
                                                        |
| 2325 | +        if ( ! empty($question_groups)) { | 
                                                        |
| 2326 | 2326 |              foreach ($question_groups as $question_group) { | 
                                                        
| 2327 | 2327 | $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group');  | 
                                                        
| 2328 | 2328 | }  | 
                                                        
@@ -2533,7 +2533,7 @@ discard block  | 
                                                    ||
| 2533 | 2533 | . esc_html__(  | 
                                                        
| 2534 | 2534 | 'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',  | 
                                                        
| 2535 | 2535 | 'event_espresso'  | 
                                                        
| 2536 | - ) . '</strong>';  | 
                                                        |
| 2536 | + ).'</strong>';  | 
                                                        |
| 2537 | 2537 |          $this->display_admin_caf_preview_page('template_settings_tab'); | 
                                                        
| 2538 | 2538 | }  | 
                                                        
| 2539 | 2539 | |
@@ -2553,12 +2553,12 @@ discard block  | 
                                                    ||
| 2553 | 2553 | // set default category object  | 
                                                        
| 2554 | 2554 | $this->_set_empty_category_object();  | 
                                                        
| 2555 | 2555 | // only set if we've got an id  | 
                                                        
| 2556 | -        if (! isset($this->_req_data['EVT_CAT_ID'])) { | 
                                                        |
| 2556 | +        if ( ! isset($this->_req_data['EVT_CAT_ID'])) { | 
                                                        |
| 2557 | 2557 | return;  | 
                                                        
| 2558 | 2558 | }  | 
                                                        
| 2559 | 2559 | $category_id = absint($this->_req_data['EVT_CAT_ID']);  | 
                                                        
| 2560 | 2560 | $term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);  | 
                                                        
| 2561 | -        if (! empty($term)) { | 
                                                        |
| 2561 | +        if ( ! empty($term)) { | 
                                                        |
| 2562 | 2562 | $this->_category->category_name = $term->name;  | 
                                                        
| 2563 | 2563 | $this->_category->category_identifier = $term->slug;  | 
                                                        
| 2564 | 2564 | $this->_category->category_desc = $term->description;  | 
                                                        
@@ -2586,7 +2586,7 @@ discard block  | 
                                                    ||
| 2586 | 2586 |      { | 
                                                        
| 2587 | 2587 |          do_action('AHEE_log', __FILE__, __FUNCTION__, ''); | 
                                                        
| 2588 | 2588 |          $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); | 
                                                        
| 2589 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(  | 
                                                        |
| 2589 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button(  | 
                                                        |
| 2590 | 2590 | 'add_category',  | 
                                                        
| 2591 | 2591 | 'add_category',  | 
                                                        
| 2592 | 2592 | array(),  | 
                                                        
@@ -2660,7 +2660,7 @@ discard block  | 
                                                    ||
| 2660 | 2660 | 'disable' => '',  | 
                                                        
| 2661 | 2661 | 'disabled_message' => false,  | 
                                                        
| 2662 | 2662 | );  | 
                                                        
| 2663 | - $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';  | 
                                                        |
| 2663 | + $template = EVENTS_TEMPLATE_PATH.'event_category_details.template.php';  | 
                                                        |
| 2664 | 2664 | return EEH_Template::display_template($template, $template_args, true);  | 
                                                        
| 2665 | 2665 | }  | 
                                                        
| 2666 | 2666 | |
@@ -2745,7 +2745,7 @@ discard block  | 
                                                    ||
| 2745 | 2745 | $insert_ids = $update  | 
                                                        
| 2746 | 2746 | ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)  | 
                                                        
| 2747 | 2747 | : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);  | 
                                                        
| 2748 | -        if (! is_array($insert_ids)) { | 
                                                        |
| 2748 | +        if ( ! is_array($insert_ids)) { | 
                                                        |
| 2749 | 2749 | $msg = esc_html__(  | 
                                                        
| 2750 | 2750 | 'An error occurred and the category has not been saved to the database.',  | 
                                                        
| 2751 | 2751 | 'event_espresso'  | 
                                                        
@@ -2776,7 +2776,7 @@ discard block  | 
                                                    ||
| 2776 | 2776 | $limit = ($current_page - 1) * $per_page;  | 
                                                        
| 2777 | 2777 |          $where = array('taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); | 
                                                        
| 2778 | 2778 |          if (isset($this->_req_data['s'])) { | 
                                                        
| 2779 | - $sstr = '%' . $this->_req_data['s'] . '%';  | 
                                                        |
| 2779 | + $sstr = '%'.$this->_req_data['s'].'%';  | 
                                                        |
| 2780 | 2780 | $where['OR'] = array(  | 
                                                        
| 2781 | 2781 |                  'Term.name'   => array('LIKE', $sstr), | 
                                                        
| 2782 | 2782 |                  'description' => array('LIKE', $sstr), | 
                                                        
@@ -2785,7 +2785,7 @@ discard block  | 
                                                    ||
| 2785 | 2785 | $query_params = array(  | 
                                                        
| 2786 | 2786 | $where,  | 
                                                        
| 2787 | 2787 | 'order_by' => array($orderby => $order),  | 
                                                        
| 2788 | - 'limit' => $limit . ',' . $per_page,  | 
                                                        |
| 2788 | + 'limit' => $limit.','.$per_page,  | 
                                                        |
| 2789 | 2789 |              'force_join' => array('Term'), | 
                                                        
| 2790 | 2790 | );  | 
                                                        
| 2791 | 2791 | $categories = $count  | 
                                                        
@@ -15,548 +15,548 @@  | 
                                                    ||
| 15 | 15 | class Events_Admin_List_Table extends EE_Admin_List_Table  | 
                                                        
| 16 | 16 |  { | 
                                                        
| 17 | 17 | |
| 18 | - /**  | 
                                                        |
| 19 | - * @var EE_Datetime  | 
                                                        |
| 20 | - */  | 
                                                        |
| 21 | - private $_dtt;  | 
                                                        |
| 22 | -  | 
                                                        |
| 23 | -  | 
                                                        |
| 24 | - /**  | 
                                                        |
| 25 | - * Initial setup of data properties for the list table.  | 
                                                        |
| 26 | - */  | 
                                                        |
| 27 | - protected function _setup_data()  | 
                                                        |
| 28 | -    { | 
                                                        |
| 29 | - $this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page);  | 
                                                        |
| 30 | - $this->_all_data_count = $this->_admin_page->get_events(0, 0, true);  | 
                                                        |
| 31 | - }  | 
                                                        |
| 32 | -  | 
                                                        |
| 33 | -  | 
                                                        |
| 34 | - /**  | 
                                                        |
| 35 | - * Set up of additional properties for the list table.  | 
                                                        |
| 36 | - */  | 
                                                        |
| 37 | - protected function _set_properties()  | 
                                                        |
| 38 | -    { | 
                                                        |
| 39 | - $this->_wp_list_args = array(  | 
                                                        |
| 40 | -            'singular' => esc_html__('event', 'event_espresso'), | 
                                                        |
| 41 | -            'plural'   => esc_html__('events', 'event_espresso'), | 
                                                        |
| 42 | - 'ajax' => true, // for now  | 
                                                        |
| 43 | - 'screen' => $this->_admin_page->get_current_screen()->id,  | 
                                                        |
| 44 | - );  | 
                                                        |
| 45 | - $this->_columns = array(  | 
                                                        |
| 46 | - 'cb' => '<input type="checkbox" />',  | 
                                                        |
| 47 | -            'id'              => esc_html__('ID', 'event_espresso'), | 
                                                        |
| 48 | -            'name'            => esc_html__('Name', 'event_espresso'), | 
                                                        |
| 49 | -            'author'          => esc_html__('Author', 'event_espresso'), | 
                                                        |
| 50 | -            'venue'           => esc_html__('Venue', 'event_espresso'), | 
                                                        |
| 51 | -            'start_date_time' => esc_html__('Event Start', 'event_espresso'), | 
                                                        |
| 52 | -            'reg_begins'      => esc_html__('On Sale', 'event_espresso'), | 
                                                        |
| 53 | - 'attendees' => '<span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20">'  | 
                                                        |
| 54 | - . '<span class="screen-reader-text">'  | 
                                                        |
| 55 | -                                 . esc_html__('Approved Registrations', 'event_espresso') | 
                                                        |
| 56 | - . '</span>'  | 
                                                        |
| 57 | - . '</span>',  | 
                                                        |
| 58 | -            // 'tkts_sold' => esc_html__('Tickets Sold', 'event_espresso'), | 
                                                        |
| 59 | -            'actions'         => esc_html__('Actions', 'event_espresso'), | 
                                                        |
| 60 | - );  | 
                                                        |
| 61 | - $this->addConditionalColumns();  | 
                                                        |
| 62 | - $this->_sortable_columns = array(  | 
                                                        |
| 63 | -            'id'              => array('EVT_ID' => true), | 
                                                        |
| 64 | -            'name'            => array('EVT_name' => false), | 
                                                        |
| 65 | -            'author'          => array('EVT_wp_user' => false), | 
                                                        |
| 66 | -            'venue'           => array('Venue.VNU_name' => false), | 
                                                        |
| 67 | -            'start_date_time' => array('Datetime.DTT_EVT_start' => false), | 
                                                        |
| 68 | -            'reg_begins'      => array('Datetime.Ticket.TKT_start_date' => false), | 
                                                        |
| 69 | - );  | 
                                                        |
| 70 | -  | 
                                                        |
| 71 | - $this->_primary_column = 'id';  | 
                                                        |
| 72 | -        $this->_hidden_columns = array('author', 'event_category'); | 
                                                        |
| 73 | - }  | 
                                                        |
| 74 | -  | 
                                                        |
| 75 | -  | 
                                                        |
| 76 | - /**  | 
                                                        |
| 77 | - * @return array  | 
                                                        |
| 78 | - */  | 
                                                        |
| 79 | - protected function _get_table_filters()  | 
                                                        |
| 80 | -    { | 
                                                        |
| 81 | - return array(); // no filters with decaf  | 
                                                        |
| 82 | - }  | 
                                                        |
| 83 | -  | 
                                                        |
| 84 | -  | 
                                                        |
| 85 | - /**  | 
                                                        |
| 86 | - * Setup of views properties.  | 
                                                        |
| 87 | - *  | 
                                                        |
| 88 | - * @throws InvalidDataTypeException  | 
                                                        |
| 89 | - * @throws InvalidInterfaceException  | 
                                                        |
| 90 | - * @throws InvalidArgumentException  | 
                                                        |
| 91 | - */  | 
                                                        |
| 92 | - protected function _add_view_counts()  | 
                                                        |
| 93 | -    { | 
                                                        |
| 94 | - $this->_views['all']['count'] = $this->_admin_page->total_events();  | 
                                                        |
| 95 | - $this->_views['draft']['count'] = $this->_admin_page->total_events_draft();  | 
                                                        |
| 96 | - if (EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 97 | - 'ee_delete_events',  | 
                                                        |
| 98 | - 'espresso_events_trash_events'  | 
                                                        |
| 99 | -        )) { | 
                                                        |
| 100 | - $this->_views['trash']['count'] = $this->_admin_page->total_trashed_events();  | 
                                                        |
| 101 | - }  | 
                                                        |
| 102 | - }  | 
                                                        |
| 103 | -  | 
                                                        |
| 104 | -  | 
                                                        |
| 105 | - /**  | 
                                                        |
| 106 | - * @param EE_Event $item  | 
                                                        |
| 107 | - * @return string  | 
                                                        |
| 108 | - * @throws EE_Error  | 
                                                        |
| 109 | - */  | 
                                                        |
| 110 | - protected function _get_row_class($item)  | 
                                                        |
| 111 | -    { | 
                                                        |
| 112 | - $class = parent::_get_row_class($item);  | 
                                                        |
| 113 | - // add status class  | 
                                                        |
| 114 | - $class .= $item instanceof EE_Event  | 
                                                        |
| 115 | - ? ' ee-status-strip event-status-' . $item->get_active_status()  | 
                                                        |
| 116 | - : '';  | 
                                                        |
| 117 | -        if ($this->_has_checkbox_column) { | 
                                                        |
| 118 | - $class .= ' has-checkbox-column';  | 
                                                        |
| 119 | - }  | 
                                                        |
| 120 | - return $class;  | 
                                                        |
| 121 | - }  | 
                                                        |
| 122 | -  | 
                                                        |
| 123 | -  | 
                                                        |
| 124 | - /**  | 
                                                        |
| 125 | - * @param EE_Event $item  | 
                                                        |
| 126 | - * @return string  | 
                                                        |
| 127 | - * @throws EE_Error  | 
                                                        |
| 128 | - */  | 
                                                        |
| 129 | - public function column_status(EE_Event $item)  | 
                                                        |
| 130 | -    { | 
                                                        |
| 131 | - return '<span class="ee-status-strip ee-status-strip-td event-status-'  | 
                                                        |
| 132 | - . $item->get_active_status()  | 
                                                        |
| 133 | - . '"></span>';  | 
                                                        |
| 134 | - }  | 
                                                        |
| 135 | -  | 
                                                        |
| 136 | -  | 
                                                        |
| 137 | - /**  | 
                                                        |
| 138 | - * @param EE_Event $item  | 
                                                        |
| 139 | - * @return string  | 
                                                        |
| 140 | - * @throws EE_Error  | 
                                                        |
| 141 | - */  | 
                                                        |
| 142 | - public function column_cb($item)  | 
                                                        |
| 143 | -    { | 
                                                        |
| 144 | -        if (! $item instanceof EE_Event) { | 
                                                        |
| 145 | - return '';  | 
                                                        |
| 146 | - }  | 
                                                        |
| 147 | - $this->_dtt = $item->primary_datetime(); // set this for use in other columns  | 
                                                        |
| 148 | - return sprintf(  | 
                                                        |
| 149 | - '<input type="checkbox" name="EVT_IDs[]" value="%s" />',  | 
                                                        |
| 150 | - $item->ID()  | 
                                                        |
| 151 | - );  | 
                                                        |
| 152 | - }  | 
                                                        |
| 153 | -  | 
                                                        |
| 154 | -  | 
                                                        |
| 155 | - /**  | 
                                                        |
| 156 | - * @param EE_Event $item  | 
                                                        |
| 157 | - * @return mixed|string  | 
                                                        |
| 158 | - * @throws EE_Error  | 
                                                        |
| 159 | - */  | 
                                                        |
| 160 | - public function column_id(EE_Event $item)  | 
                                                        |
| 161 | -    { | 
                                                        |
| 162 | - $content = $item->ID();  | 
                                                        |
| 163 | - $content .= ' <span class="show-on-mobile-view-only">' . $item->name() . '</span>';  | 
                                                        |
| 164 | - return $content;  | 
                                                        |
| 165 | - }  | 
                                                        |
| 166 | -  | 
                                                        |
| 167 | -  | 
                                                        |
| 168 | - /**  | 
                                                        |
| 169 | - * @param EE_Event $item  | 
                                                        |
| 170 | - * @return string  | 
                                                        |
| 171 | - * @throws EE_Error  | 
                                                        |
| 172 | - * @throws InvalidArgumentException  | 
                                                        |
| 173 | - * @throws InvalidDataTypeException  | 
                                                        |
| 174 | - * @throws InvalidInterfaceException  | 
                                                        |
| 175 | - */  | 
                                                        |
| 176 | - public function column_name(EE_Event $item)  | 
                                                        |
| 177 | -    { | 
                                                        |
| 178 | - $edit_query_args = array(  | 
                                                        |
| 179 | - 'action' => 'edit',  | 
                                                        |
| 180 | - 'post' => $item->ID(),  | 
                                                        |
| 181 | - );  | 
                                                        |
| 182 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);  | 
                                                        |
| 183 | - $actions = $this->_column_name_action_setup($item);  | 
                                                        |
| 184 | -        $status = ''; // $item->status() !== 'publish' ? ' (' . $item->status() . ')' : ''; | 
                                                        |
| 185 | - $content = '<strong><a class="row-title" href="'  | 
                                                        |
| 186 | - . $edit_link . '">'  | 
                                                        |
| 187 | - . $item->name()  | 
                                                        |
| 188 | - . '</a></strong>'  | 
                                                        |
| 189 | - . $status;  | 
                                                        |
| 190 | - $content .= '<br><span class="ee-status-text-small">'  | 
                                                        |
| 191 | - . EEH_Template::pretty_status(  | 
                                                        |
| 192 | - $item->get_active_status(),  | 
                                                        |
| 193 | - false,  | 
                                                        |
| 194 | - 'sentence'  | 
                                                        |
| 195 | - )  | 
                                                        |
| 196 | - . '</span>';  | 
                                                        |
| 197 | - $content .= $this->row_actions($actions);  | 
                                                        |
| 198 | - return $content;  | 
                                                        |
| 199 | - }  | 
                                                        |
| 200 | -  | 
                                                        |
| 201 | -  | 
                                                        |
| 202 | - /**  | 
                                                        |
| 203 | - * Just a method for setting up the actions for the name column  | 
                                                        |
| 204 | - *  | 
                                                        |
| 205 | - * @param EE_Event $item  | 
                                                        |
| 206 | - * @return array array of actions  | 
                                                        |
| 207 | - * @throws EE_Error  | 
                                                        |
| 208 | - * @throws InvalidArgumentException  | 
                                                        |
| 209 | - * @throws InvalidDataTypeException  | 
                                                        |
| 210 | - * @throws InvalidInterfaceException  | 
                                                        |
| 211 | - */  | 
                                                        |
| 212 | - protected function _column_name_action_setup(EE_Event $item)  | 
                                                        |
| 213 | -    { | 
                                                        |
| 214 | - // todo: remove when attendees is active  | 
                                                        |
| 215 | -        if (! defined('REG_ADMIN_URL')) { | 
                                                        |
| 216 | -            define('REG_ADMIN_URL', EVENTS_ADMIN_URL); | 
                                                        |
| 217 | - }  | 
                                                        |
| 218 | - $actions = array();  | 
                                                        |
| 219 | - $restore_event_link = '';  | 
                                                        |
| 220 | - $delete_event_link = '';  | 
                                                        |
| 221 | - $trash_event_link = '';  | 
                                                        |
| 222 | - if (EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 223 | - 'ee_edit_event',  | 
                                                        |
| 224 | - 'espresso_events_edit',  | 
                                                        |
| 225 | - $item->ID()  | 
                                                        |
| 226 | -        )) { | 
                                                        |
| 227 | - $edit_query_args = array(  | 
                                                        |
| 228 | - 'action' => 'edit',  | 
                                                        |
| 229 | - 'post' => $item->ID(),  | 
                                                        |
| 230 | - );  | 
                                                        |
| 231 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);  | 
                                                        |
| 232 | - $actions['edit'] = '<a href="' . $edit_link . '"'  | 
                                                        |
| 233 | -                               . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' | 
                                                        |
| 234 | -                               . esc_html__('Edit', 'event_espresso') | 
                                                        |
| 235 | - . '</a>';  | 
                                                        |
| 236 | - }  | 
                                                        |
| 237 | - if (EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 238 | - 'ee_read_registrations',  | 
                                                        |
| 239 | - 'espresso_registrations_view_registration'  | 
                                                        |
| 240 | - )  | 
                                                        |
| 241 | - && EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 242 | - 'ee_read_event',  | 
                                                        |
| 243 | - 'espresso_registrations_view_registration',  | 
                                                        |
| 244 | - $item->ID()  | 
                                                        |
| 245 | - )  | 
                                                        |
| 246 | -        ) { | 
                                                        |
| 247 | - $attendees_query_args = array(  | 
                                                        |
| 248 | - 'action' => 'default',  | 
                                                        |
| 249 | - 'event_id' => $item->ID(),  | 
                                                        |
| 250 | - );  | 
                                                        |
| 251 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);  | 
                                                        |
| 252 | - $actions['attendees'] = '<a href="' . $attendees_link . '"'  | 
                                                        |
| 253 | -                                    . ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">' | 
                                                        |
| 254 | -                                    . esc_html__('Registrations', 'event_espresso') | 
                                                        |
| 255 | - . '</a>';  | 
                                                        |
| 256 | - }  | 
                                                        |
| 257 | - if (EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 258 | - 'ee_delete_event',  | 
                                                        |
| 259 | - 'espresso_events_trash_event',  | 
                                                        |
| 260 | - $item->ID()  | 
                                                        |
| 261 | -        )) { | 
                                                        |
| 262 | - $trash_event_query_args = array(  | 
                                                        |
| 263 | - 'action' => 'trash_event',  | 
                                                        |
| 264 | - 'EVT_ID' => $item->ID(),  | 
                                                        |
| 265 | - );  | 
                                                        |
| 266 | - $trash_event_link = EE_Admin_Page::add_query_args_and_nonce(  | 
                                                        |
| 267 | - $trash_event_query_args,  | 
                                                        |
| 268 | - EVENTS_ADMIN_URL  | 
                                                        |
| 269 | - );  | 
                                                        |
| 270 | - }  | 
                                                        |
| 271 | - if (EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 272 | - 'ee_delete_event',  | 
                                                        |
| 273 | - 'espresso_events_restore_event',  | 
                                                        |
| 274 | - $item->ID()  | 
                                                        |
| 275 | -        )) { | 
                                                        |
| 276 | - $restore_event_query_args = array(  | 
                                                        |
| 277 | - 'action' => 'restore_event',  | 
                                                        |
| 278 | - 'EVT_ID' => $item->ID(),  | 
                                                        |
| 279 | - );  | 
                                                        |
| 280 | - $restore_event_link = EE_Admin_Page::add_query_args_and_nonce(  | 
                                                        |
| 281 | - $restore_event_query_args,  | 
                                                        |
| 282 | - EVENTS_ADMIN_URL  | 
                                                        |
| 283 | - );  | 
                                                        |
| 284 | - }  | 
                                                        |
| 285 | - if (EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 286 | - 'ee_delete_event',  | 
                                                        |
| 287 | - 'espresso_events_delete_event',  | 
                                                        |
| 288 | - $item->ID()  | 
                                                        |
| 289 | -        )) { | 
                                                        |
| 290 | - $delete_event_query_args = array(  | 
                                                        |
| 291 | - 'action' => 'delete_event',  | 
                                                        |
| 292 | - 'EVT_ID' => $item->ID(),  | 
                                                        |
| 293 | - );  | 
                                                        |
| 294 | - $delete_event_link = EE_Admin_Page::add_query_args_and_nonce(  | 
                                                        |
| 295 | - $delete_event_query_args,  | 
                                                        |
| 296 | - EVENTS_ADMIN_URL  | 
                                                        |
| 297 | - );  | 
                                                        |
| 298 | - }  | 
                                                        |
| 299 | - $view_link = get_permalink($item->ID());  | 
                                                        |
| 300 | - $actions['view'] = '<a href="' . $view_link . '"'  | 
                                                        |
| 301 | -                           . ' title="' . esc_attr__('View Event', 'event_espresso') . '">' | 
                                                        |
| 302 | -                           . esc_html__('View', 'event_espresso') | 
                                                        |
| 303 | - . '</a>';  | 
                                                        |
| 304 | -        if ($item->get('status') === 'trash') { | 
                                                        |
| 305 | - if (EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 306 | - 'ee_delete_event',  | 
                                                        |
| 307 | - 'espresso_events_restore_event',  | 
                                                        |
| 308 | - $item->ID()  | 
                                                        |
| 309 | -            )) { | 
                                                        |
| 310 | - $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"'  | 
                                                        |
| 311 | -                                                 . ' title="' . esc_attr__('Restore from Trash', 'event_espresso') | 
                                                        |
| 312 | - . '">'  | 
                                                        |
| 313 | -                                                 . esc_html__('Restore from Trash', 'event_espresso') | 
                                                        |
| 314 | - . '</a>';  | 
                                                        |
| 315 | - }  | 
                                                        |
| 316 | - if (EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 317 | - 'ee_delete_event',  | 
                                                        |
| 318 | - 'espresso_events_delete_event',  | 
                                                        |
| 319 | - $item->ID()  | 
                                                        |
| 320 | - )  | 
                                                        |
| 321 | -            ) { | 
                                                        |
| 322 | - $actions['delete'] = '<a href="' . $delete_event_link . '"'  | 
                                                        |
| 323 | -                                     . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">' | 
                                                        |
| 324 | -                                     . esc_html__('Delete Permanently', 'event_espresso') | 
                                                        |
| 325 | - . '</a>';  | 
                                                        |
| 326 | - }  | 
                                                        |
| 327 | -        } else { | 
                                                        |
| 328 | - if (EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 329 | - 'ee_delete_event',  | 
                                                        |
| 330 | - 'espresso_events_trash_event',  | 
                                                        |
| 331 | - $item->ID()  | 
                                                        |
| 332 | -            )) { | 
                                                        |
| 333 | - $actions['move to trash'] = '<a href="' . $trash_event_link . '"'  | 
                                                        |
| 334 | -                                            . ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">' | 
                                                        |
| 335 | -                                            . esc_html__('Trash', 'event_espresso') | 
                                                        |
| 336 | - . '</a>';  | 
                                                        |
| 337 | - }  | 
                                                        |
| 338 | - }  | 
                                                        |
| 339 | - return $actions;  | 
                                                        |
| 340 | - }  | 
                                                        |
| 341 | -  | 
                                                        |
| 342 | -  | 
                                                        |
| 343 | - /**  | 
                                                        |
| 344 | - * @param EE_Event $item  | 
                                                        |
| 345 | - * @return string  | 
                                                        |
| 346 | - * @throws EE_Error  | 
                                                        |
| 347 | - */  | 
                                                        |
| 348 | - public function column_author(EE_Event $item)  | 
                                                        |
| 349 | -    { | 
                                                        |
| 350 | - // user author info  | 
                                                        |
| 351 | - $event_author = get_userdata($item->wp_user());  | 
                                                        |
| 352 | - $gravatar = get_avatar($item->wp_user(), '15');  | 
                                                        |
| 353 | - // filter link  | 
                                                        |
| 354 | - $query_args = array(  | 
                                                        |
| 355 | - 'action' => 'default',  | 
                                                        |
| 356 | - 'EVT_wp_user' => $item->wp_user(),  | 
                                                        |
| 357 | - );  | 
                                                        |
| 358 | - $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL);  | 
                                                        |
| 359 | - return $gravatar . ' <a href="' . $filter_url . '"'  | 
                                                        |
| 360 | -               . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">' | 
                                                        |
| 361 | - . $event_author->display_name  | 
                                                        |
| 362 | - . '</a>';  | 
                                                        |
| 363 | - }  | 
                                                        |
| 364 | -  | 
                                                        |
| 365 | -  | 
                                                        |
| 366 | - /**  | 
                                                        |
| 367 | - * @param EE_Event $event  | 
                                                        |
| 368 | - * @return string  | 
                                                        |
| 369 | - * @throws EE_Error  | 
                                                        |
| 370 | - */  | 
                                                        |
| 371 | - public function column_event_category(EE_Event $event)  | 
                                                        |
| 372 | -    { | 
                                                        |
| 373 | - $event_categories = $event->get_all_event_categories();  | 
                                                        |
| 374 | - return implode(  | 
                                                        |
| 375 | - ', ',  | 
                                                        |
| 376 | - array_map(  | 
                                                        |
| 377 | -                function (EE_Term $category) { | 
                                                        |
| 378 | - return $category->name();  | 
                                                        |
| 379 | - },  | 
                                                        |
| 380 | - $event_categories  | 
                                                        |
| 381 | - )  | 
                                                        |
| 382 | - );  | 
                                                        |
| 383 | - }  | 
                                                        |
| 384 | -  | 
                                                        |
| 385 | -  | 
                                                        |
| 386 | - /**  | 
                                                        |
| 387 | - * @param EE_Event $item  | 
                                                        |
| 388 | - * @return string  | 
                                                        |
| 389 | - * @throws EE_Error  | 
                                                        |
| 390 | - */  | 
                                                        |
| 391 | - public function column_venue(EE_Event $item)  | 
                                                        |
| 392 | -    { | 
                                                        |
| 393 | -        $venue = $item->get_first_related('Venue'); | 
                                                        |
| 394 | - return ! empty($venue)  | 
                                                        |
| 395 | - ? $venue->name()  | 
                                                        |
| 396 | - : '';  | 
                                                        |
| 397 | - }  | 
                                                        |
| 398 | -  | 
                                                        |
| 399 | -  | 
                                                        |
| 400 | - /**  | 
                                                        |
| 401 | - * @param EE_Event $item  | 
                                                        |
| 402 | - * @return string  | 
                                                        |
| 403 | - * @throws EE_Error  | 
                                                        |
| 404 | - */  | 
                                                        |
| 405 | - public function column_start_date_time(EE_Event $item)  | 
                                                        |
| 406 | -    { | 
                                                        |
| 407 | - return $this->_dtt instanceof EE_Datetime  | 
                                                        |
| 408 | -            ? $this->_dtt->get_i18n_datetime('DTT_EVT_start') | 
                                                        |
| 409 | -            : esc_html__('No Date was saved for this Event', 'event_espresso'); | 
                                                        |
| 410 | - }  | 
                                                        |
| 411 | -  | 
                                                        |
| 412 | -  | 
                                                        |
| 413 | - /**  | 
                                                        |
| 414 | - * @param EE_Event $item  | 
                                                        |
| 415 | - * @return string  | 
                                                        |
| 416 | - * @throws EE_Error  | 
                                                        |
| 417 | - */  | 
                                                        |
| 418 | - public function column_reg_begins(EE_Event $item)  | 
                                                        |
| 419 | -    { | 
                                                        |
| 420 | - $reg_start = $item->get_ticket_with_earliest_start_time();  | 
                                                        |
| 421 | - return $reg_start instanceof EE_Ticket  | 
                                                        |
| 422 | -            ? $reg_start->get_i18n_datetime('TKT_start_date') | 
                                                        |
| 423 | -            : esc_html__('No Tickets have been setup for this Event', 'event_espresso'); | 
                                                        |
| 424 | - }  | 
                                                        |
| 425 | -  | 
                                                        |
| 426 | -  | 
                                                        |
| 427 | - /**  | 
                                                        |
| 428 | - * @param EE_Event $item  | 
                                                        |
| 429 | - * @return int|string  | 
                                                        |
| 430 | - * @throws EE_Error  | 
                                                        |
| 431 | - * @throws InvalidArgumentException  | 
                                                        |
| 432 | - * @throws InvalidDataTypeException  | 
                                                        |
| 433 | - * @throws InvalidInterfaceException  | 
                                                        |
| 434 | - */  | 
                                                        |
| 435 | - public function column_attendees(EE_Event $item)  | 
                                                        |
| 436 | -    { | 
                                                        |
| 437 | - $attendees_query_args = array(  | 
                                                        |
| 438 | - 'action' => 'default',  | 
                                                        |
| 439 | - 'event_id' => $item->ID(),  | 
                                                        |
| 440 | - );  | 
                                                        |
| 441 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);  | 
                                                        |
| 442 | - $registered_attendees = EEM_Registration::instance()->get_event_registration_count($item->ID());  | 
                                                        |
| 443 | - return EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 444 | - 'ee_read_event',  | 
                                                        |
| 445 | - 'espresso_registrations_view_registration',  | 
                                                        |
| 446 | - $item->ID()  | 
                                                        |
| 447 | - )  | 
                                                        |
| 448 | - && EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 449 | - 'ee_read_registrations',  | 
                                                        |
| 450 | - 'espresso_registrations_view_registration'  | 
                                                        |
| 451 | - )  | 
                                                        |
| 452 | - ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>'  | 
                                                        |
| 453 | - : $registered_attendees;  | 
                                                        |
| 454 | - }  | 
                                                        |
| 455 | -  | 
                                                        |
| 456 | -  | 
                                                        |
| 457 | - /**  | 
                                                        |
| 458 | - * @param EE_Event $item  | 
                                                        |
| 459 | - * @return float  | 
                                                        |
| 460 | - * @throws EE_Error  | 
                                                        |
| 461 | - * @throws InvalidArgumentException  | 
                                                        |
| 462 | - * @throws InvalidDataTypeException  | 
                                                        |
| 463 | - * @throws InvalidInterfaceException  | 
                                                        |
| 464 | - */  | 
                                                        |
| 465 | - public function column_tkts_sold(EE_Event $item)  | 
                                                        |
| 466 | -    { | 
                                                        |
| 467 | -        return EEM_Ticket::instance()->sum(array(array('Datetime.EVT_ID' => $item->ID())), 'TKT_sold'); | 
                                                        |
| 468 | - }  | 
                                                        |
| 469 | -  | 
                                                        |
| 470 | -  | 
                                                        |
| 471 | - /**  | 
                                                        |
| 472 | - * @param EE_Event $item  | 
                                                        |
| 473 | - * @return string  | 
                                                        |
| 474 | - * @throws EE_Error  | 
                                                        |
| 475 | - * @throws InvalidArgumentException  | 
                                                        |
| 476 | - * @throws InvalidDataTypeException  | 
                                                        |
| 477 | - * @throws InvalidInterfaceException  | 
                                                        |
| 478 | - */  | 
                                                        |
| 479 | - public function column_actions(EE_Event $item)  | 
                                                        |
| 480 | -    { | 
                                                        |
| 481 | - // todo: remove when attendees is active  | 
                                                        |
| 482 | -        if (! defined('REG_ADMIN_URL')) { | 
                                                        |
| 483 | -            define('REG_ADMIN_URL', EVENTS_ADMIN_URL); | 
                                                        |
| 484 | - }  | 
                                                        |
| 485 | - $action_links = array();  | 
                                                        |
| 486 | - $view_link = get_permalink($item->ID());  | 
                                                        |
| 487 | - $action_links[] = '<a href="' . $view_link . '"'  | 
                                                        |
| 488 | -                          . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">'; | 
                                                        |
| 489 | - $action_links[] = '<div class="dashicons dashicons-search"></div></a>';  | 
                                                        |
| 490 | - if (EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 491 | - 'ee_edit_event',  | 
                                                        |
| 492 | - 'espresso_events_edit',  | 
                                                        |
| 493 | - $item->ID()  | 
                                                        |
| 494 | -        )) { | 
                                                        |
| 495 | - $edit_query_args = array(  | 
                                                        |
| 496 | - 'action' => 'edit',  | 
                                                        |
| 497 | - 'post' => $item->ID(),  | 
                                                        |
| 498 | - );  | 
                                                        |
| 499 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);  | 
                                                        |
| 500 | - $action_links[] = '<a href="' . $edit_link . '"'  | 
                                                        |
| 501 | -                              . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' | 
                                                        |
| 502 | - . '<div class="ee-icon ee-icon-calendar-edit"></div>'  | 
                                                        |
| 503 | - . '</a>';  | 
                                                        |
| 504 | - }  | 
                                                        |
| 505 | - if (EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 506 | - 'ee_read_registrations',  | 
                                                        |
| 507 | - 'espresso_registrations_view_registration'  | 
                                                        |
| 508 | - ) && EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 509 | - 'ee_read_event',  | 
                                                        |
| 510 | - 'espresso_registrations_view_registration',  | 
                                                        |
| 511 | - $item->ID()  | 
                                                        |
| 512 | - )  | 
                                                        |
| 513 | -        ) { | 
                                                        |
| 514 | - $attendees_query_args = array(  | 
                                                        |
| 515 | - 'action' => 'default',  | 
                                                        |
| 516 | - 'event_id' => $item->ID(),  | 
                                                        |
| 517 | - );  | 
                                                        |
| 518 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);  | 
                                                        |
| 519 | - $action_links[] = '<a href="' . $attendees_link . '"'  | 
                                                        |
| 520 | -                              . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">' | 
                                                        |
| 521 | - . '<div class="dashicons dashicons-groups"></div>'  | 
                                                        |
| 522 | - . '</a>';  | 
                                                        |
| 523 | - }  | 
                                                        |
| 524 | - $action_links = apply_filters(  | 
                                                        |
| 525 | - 'FHEE__Events_Admin_List_Table__column_actions__action_links',  | 
                                                        |
| 526 | - $action_links,  | 
                                                        |
| 527 | - $item  | 
                                                        |
| 528 | - );  | 
                                                        |
| 529 | - return $this->_action_string(  | 
                                                        |
| 530 | -            implode("\n\t", $action_links), | 
                                                        |
| 531 | - $item,  | 
                                                        |
| 532 | - 'div'  | 
                                                        |
| 533 | - );  | 
                                                        |
| 534 | - }  | 
                                                        |
| 535 | -  | 
                                                        |
| 536 | -  | 
                                                        |
| 537 | - /**  | 
                                                        |
| 538 | - * Helper for adding columns conditionally  | 
                                                        |
| 539 | - *  | 
                                                        |
| 540 | - * @throws EE_Error  | 
                                                        |
| 541 | - * @throws InvalidArgumentException  | 
                                                        |
| 542 | - * @throws InvalidDataTypeException  | 
                                                        |
| 543 | - * @throws InvalidInterfaceException  | 
                                                        |
| 544 | - */  | 
                                                        |
| 545 | - private function addConditionalColumns()  | 
                                                        |
| 546 | -    { | 
                                                        |
| 547 | - $event_category_count = EEM_Term::instance()->count(  | 
                                                        |
| 548 | - [['Term_Taxonomy.taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]]  | 
                                                        |
| 549 | - );  | 
                                                        |
| 550 | -        if ($event_category_count === 0) { | 
                                                        |
| 551 | - return;  | 
                                                        |
| 552 | - }  | 
                                                        |
| 553 | - $column_array = [];  | 
                                                        |
| 554 | -        foreach ($this->_columns as $column => $column_label) { | 
                                                        |
| 555 | - $column_array[ $column ] = $column_label;  | 
                                                        |
| 556 | -            if ($column === 'venue') { | 
                                                        |
| 557 | -                $column_array['event_category'] = esc_html__('Event Category', 'event_espresso'); | 
                                                        |
| 558 | - }  | 
                                                        |
| 559 | - }  | 
                                                        |
| 560 | - $this->_columns = $column_array;  | 
                                                        |
| 561 | - }  | 
                                                        |
| 18 | + /**  | 
                                                        |
| 19 | + * @var EE_Datetime  | 
                                                        |
| 20 | + */  | 
                                                        |
| 21 | + private $_dtt;  | 
                                                        |
| 22 | +  | 
                                                        |
| 23 | +  | 
                                                        |
| 24 | + /**  | 
                                                        |
| 25 | + * Initial setup of data properties for the list table.  | 
                                                        |
| 26 | + */  | 
                                                        |
| 27 | + protected function _setup_data()  | 
                                                        |
| 28 | +	{ | 
                                                        |
| 29 | + $this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page);  | 
                                                        |
| 30 | + $this->_all_data_count = $this->_admin_page->get_events(0, 0, true);  | 
                                                        |
| 31 | + }  | 
                                                        |
| 32 | +  | 
                                                        |
| 33 | +  | 
                                                        |
| 34 | + /**  | 
                                                        |
| 35 | + * Set up of additional properties for the list table.  | 
                                                        |
| 36 | + */  | 
                                                        |
| 37 | + protected function _set_properties()  | 
                                                        |
| 38 | +	{ | 
                                                        |
| 39 | + $this->_wp_list_args = array(  | 
                                                        |
| 40 | +			'singular' => esc_html__('event', 'event_espresso'), | 
                                                        |
| 41 | +			'plural'   => esc_html__('events', 'event_espresso'), | 
                                                        |
| 42 | + 'ajax' => true, // for now  | 
                                                        |
| 43 | + 'screen' => $this->_admin_page->get_current_screen()->id,  | 
                                                        |
| 44 | + );  | 
                                                        |
| 45 | + $this->_columns = array(  | 
                                                        |
| 46 | + 'cb' => '<input type="checkbox" />',  | 
                                                        |
| 47 | +			'id'              => esc_html__('ID', 'event_espresso'), | 
                                                        |
| 48 | +			'name'            => esc_html__('Name', 'event_espresso'), | 
                                                        |
| 49 | +			'author'          => esc_html__('Author', 'event_espresso'), | 
                                                        |
| 50 | +			'venue'           => esc_html__('Venue', 'event_espresso'), | 
                                                        |
| 51 | +			'start_date_time' => esc_html__('Event Start', 'event_espresso'), | 
                                                        |
| 52 | +			'reg_begins'      => esc_html__('On Sale', 'event_espresso'), | 
                                                        |
| 53 | + 'attendees' => '<span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20">'  | 
                                                        |
| 54 | + . '<span class="screen-reader-text">'  | 
                                                        |
| 55 | +								 . esc_html__('Approved Registrations', 'event_espresso') | 
                                                        |
| 56 | + . '</span>'  | 
                                                        |
| 57 | + . '</span>',  | 
                                                        |
| 58 | +			// 'tkts_sold' => esc_html__('Tickets Sold', 'event_espresso'), | 
                                                        |
| 59 | +			'actions'         => esc_html__('Actions', 'event_espresso'), | 
                                                        |
| 60 | + );  | 
                                                        |
| 61 | + $this->addConditionalColumns();  | 
                                                        |
| 62 | + $this->_sortable_columns = array(  | 
                                                        |
| 63 | +			'id'              => array('EVT_ID' => true), | 
                                                        |
| 64 | +			'name'            => array('EVT_name' => false), | 
                                                        |
| 65 | +			'author'          => array('EVT_wp_user' => false), | 
                                                        |
| 66 | +			'venue'           => array('Venue.VNU_name' => false), | 
                                                        |
| 67 | +			'start_date_time' => array('Datetime.DTT_EVT_start' => false), | 
                                                        |
| 68 | +			'reg_begins'      => array('Datetime.Ticket.TKT_start_date' => false), | 
                                                        |
| 69 | + );  | 
                                                        |
| 70 | +  | 
                                                        |
| 71 | + $this->_primary_column = 'id';  | 
                                                        |
| 72 | +		$this->_hidden_columns = array('author', 'event_category'); | 
                                                        |
| 73 | + }  | 
                                                        |
| 74 | +  | 
                                                        |
| 75 | +  | 
                                                        |
| 76 | + /**  | 
                                                        |
| 77 | + * @return array  | 
                                                        |
| 78 | + */  | 
                                                        |
| 79 | + protected function _get_table_filters()  | 
                                                        |
| 80 | +	{ | 
                                                        |
| 81 | + return array(); // no filters with decaf  | 
                                                        |
| 82 | + }  | 
                                                        |
| 83 | +  | 
                                                        |
| 84 | +  | 
                                                        |
| 85 | + /**  | 
                                                        |
| 86 | + * Setup of views properties.  | 
                                                        |
| 87 | + *  | 
                                                        |
| 88 | + * @throws InvalidDataTypeException  | 
                                                        |
| 89 | + * @throws InvalidInterfaceException  | 
                                                        |
| 90 | + * @throws InvalidArgumentException  | 
                                                        |
| 91 | + */  | 
                                                        |
| 92 | + protected function _add_view_counts()  | 
                                                        |
| 93 | +	{ | 
                                                        |
| 94 | + $this->_views['all']['count'] = $this->_admin_page->total_events();  | 
                                                        |
| 95 | + $this->_views['draft']['count'] = $this->_admin_page->total_events_draft();  | 
                                                        |
| 96 | + if (EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 97 | + 'ee_delete_events',  | 
                                                        |
| 98 | + 'espresso_events_trash_events'  | 
                                                        |
| 99 | +		)) { | 
                                                        |
| 100 | + $this->_views['trash']['count'] = $this->_admin_page->total_trashed_events();  | 
                                                        |
| 101 | + }  | 
                                                        |
| 102 | + }  | 
                                                        |
| 103 | +  | 
                                                        |
| 104 | +  | 
                                                        |
| 105 | + /**  | 
                                                        |
| 106 | + * @param EE_Event $item  | 
                                                        |
| 107 | + * @return string  | 
                                                        |
| 108 | + * @throws EE_Error  | 
                                                        |
| 109 | + */  | 
                                                        |
| 110 | + protected function _get_row_class($item)  | 
                                                        |
| 111 | +	{ | 
                                                        |
| 112 | + $class = parent::_get_row_class($item);  | 
                                                        |
| 113 | + // add status class  | 
                                                        |
| 114 | + $class .= $item instanceof EE_Event  | 
                                                        |
| 115 | + ? ' ee-status-strip event-status-' . $item->get_active_status()  | 
                                                        |
| 116 | + : '';  | 
                                                        |
| 117 | +		if ($this->_has_checkbox_column) { | 
                                                        |
| 118 | + $class .= ' has-checkbox-column';  | 
                                                        |
| 119 | + }  | 
                                                        |
| 120 | + return $class;  | 
                                                        |
| 121 | + }  | 
                                                        |
| 122 | +  | 
                                                        |
| 123 | +  | 
                                                        |
| 124 | + /**  | 
                                                        |
| 125 | + * @param EE_Event $item  | 
                                                        |
| 126 | + * @return string  | 
                                                        |
| 127 | + * @throws EE_Error  | 
                                                        |
| 128 | + */  | 
                                                        |
| 129 | + public function column_status(EE_Event $item)  | 
                                                        |
| 130 | +	{ | 
                                                        |
| 131 | + return '<span class="ee-status-strip ee-status-strip-td event-status-'  | 
                                                        |
| 132 | + . $item->get_active_status()  | 
                                                        |
| 133 | + . '"></span>';  | 
                                                        |
| 134 | + }  | 
                                                        |
| 135 | +  | 
                                                        |
| 136 | +  | 
                                                        |
| 137 | + /**  | 
                                                        |
| 138 | + * @param EE_Event $item  | 
                                                        |
| 139 | + * @return string  | 
                                                        |
| 140 | + * @throws EE_Error  | 
                                                        |
| 141 | + */  | 
                                                        |
| 142 | + public function column_cb($item)  | 
                                                        |
| 143 | +	{ | 
                                                        |
| 144 | +		if (! $item instanceof EE_Event) { | 
                                                        |
| 145 | + return '';  | 
                                                        |
| 146 | + }  | 
                                                        |
| 147 | + $this->_dtt = $item->primary_datetime(); // set this for use in other columns  | 
                                                        |
| 148 | + return sprintf(  | 
                                                        |
| 149 | + '<input type="checkbox" name="EVT_IDs[]" value="%s" />',  | 
                                                        |
| 150 | + $item->ID()  | 
                                                        |
| 151 | + );  | 
                                                        |
| 152 | + }  | 
                                                        |
| 153 | +  | 
                                                        |
| 154 | +  | 
                                                        |
| 155 | + /**  | 
                                                        |
| 156 | + * @param EE_Event $item  | 
                                                        |
| 157 | + * @return mixed|string  | 
                                                        |
| 158 | + * @throws EE_Error  | 
                                                        |
| 159 | + */  | 
                                                        |
| 160 | + public function column_id(EE_Event $item)  | 
                                                        |
| 161 | +	{ | 
                                                        |
| 162 | + $content = $item->ID();  | 
                                                        |
| 163 | + $content .= ' <span class="show-on-mobile-view-only">' . $item->name() . '</span>';  | 
                                                        |
| 164 | + return $content;  | 
                                                        |
| 165 | + }  | 
                                                        |
| 166 | +  | 
                                                        |
| 167 | +  | 
                                                        |
| 168 | + /**  | 
                                                        |
| 169 | + * @param EE_Event $item  | 
                                                        |
| 170 | + * @return string  | 
                                                        |
| 171 | + * @throws EE_Error  | 
                                                        |
| 172 | + * @throws InvalidArgumentException  | 
                                                        |
| 173 | + * @throws InvalidDataTypeException  | 
                                                        |
| 174 | + * @throws InvalidInterfaceException  | 
                                                        |
| 175 | + */  | 
                                                        |
| 176 | + public function column_name(EE_Event $item)  | 
                                                        |
| 177 | +	{ | 
                                                        |
| 178 | + $edit_query_args = array(  | 
                                                        |
| 179 | + 'action' => 'edit',  | 
                                                        |
| 180 | + 'post' => $item->ID(),  | 
                                                        |
| 181 | + );  | 
                                                        |
| 182 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);  | 
                                                        |
| 183 | + $actions = $this->_column_name_action_setup($item);  | 
                                                        |
| 184 | +		$status = ''; // $item->status() !== 'publish' ? ' (' . $item->status() . ')' : ''; | 
                                                        |
| 185 | + $content = '<strong><a class="row-title" href="'  | 
                                                        |
| 186 | + . $edit_link . '">'  | 
                                                        |
| 187 | + . $item->name()  | 
                                                        |
| 188 | + . '</a></strong>'  | 
                                                        |
| 189 | + . $status;  | 
                                                        |
| 190 | + $content .= '<br><span class="ee-status-text-small">'  | 
                                                        |
| 191 | + . EEH_Template::pretty_status(  | 
                                                        |
| 192 | + $item->get_active_status(),  | 
                                                        |
| 193 | + false,  | 
                                                        |
| 194 | + 'sentence'  | 
                                                        |
| 195 | + )  | 
                                                        |
| 196 | + . '</span>';  | 
                                                        |
| 197 | + $content .= $this->row_actions($actions);  | 
                                                        |
| 198 | + return $content;  | 
                                                        |
| 199 | + }  | 
                                                        |
| 200 | +  | 
                                                        |
| 201 | +  | 
                                                        |
| 202 | + /**  | 
                                                        |
| 203 | + * Just a method for setting up the actions for the name column  | 
                                                        |
| 204 | + *  | 
                                                        |
| 205 | + * @param EE_Event $item  | 
                                                        |
| 206 | + * @return array array of actions  | 
                                                        |
| 207 | + * @throws EE_Error  | 
                                                        |
| 208 | + * @throws InvalidArgumentException  | 
                                                        |
| 209 | + * @throws InvalidDataTypeException  | 
                                                        |
| 210 | + * @throws InvalidInterfaceException  | 
                                                        |
| 211 | + */  | 
                                                        |
| 212 | + protected function _column_name_action_setup(EE_Event $item)  | 
                                                        |
| 213 | +	{ | 
                                                        |
| 214 | + // todo: remove when attendees is active  | 
                                                        |
| 215 | +		if (! defined('REG_ADMIN_URL')) { | 
                                                        |
| 216 | +			define('REG_ADMIN_URL', EVENTS_ADMIN_URL); | 
                                                        |
| 217 | + }  | 
                                                        |
| 218 | + $actions = array();  | 
                                                        |
| 219 | + $restore_event_link = '';  | 
                                                        |
| 220 | + $delete_event_link = '';  | 
                                                        |
| 221 | + $trash_event_link = '';  | 
                                                        |
| 222 | + if (EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 223 | + 'ee_edit_event',  | 
                                                        |
| 224 | + 'espresso_events_edit',  | 
                                                        |
| 225 | + $item->ID()  | 
                                                        |
| 226 | +		)) { | 
                                                        |
| 227 | + $edit_query_args = array(  | 
                                                        |
| 228 | + 'action' => 'edit',  | 
                                                        |
| 229 | + 'post' => $item->ID(),  | 
                                                        |
| 230 | + );  | 
                                                        |
| 231 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);  | 
                                                        |
| 232 | + $actions['edit'] = '<a href="' . $edit_link . '"'  | 
                                                        |
| 233 | +							   . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' | 
                                                        |
| 234 | +							   . esc_html__('Edit', 'event_espresso') | 
                                                        |
| 235 | + . '</a>';  | 
                                                        |
| 236 | + }  | 
                                                        |
| 237 | + if (EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 238 | + 'ee_read_registrations',  | 
                                                        |
| 239 | + 'espresso_registrations_view_registration'  | 
                                                        |
| 240 | + )  | 
                                                        |
| 241 | + && EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 242 | + 'ee_read_event',  | 
                                                        |
| 243 | + 'espresso_registrations_view_registration',  | 
                                                        |
| 244 | + $item->ID()  | 
                                                        |
| 245 | + )  | 
                                                        |
| 246 | +		) { | 
                                                        |
| 247 | + $attendees_query_args = array(  | 
                                                        |
| 248 | + 'action' => 'default',  | 
                                                        |
| 249 | + 'event_id' => $item->ID(),  | 
                                                        |
| 250 | + );  | 
                                                        |
| 251 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);  | 
                                                        |
| 252 | + $actions['attendees'] = '<a href="' . $attendees_link . '"'  | 
                                                        |
| 253 | +									. ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">' | 
                                                        |
| 254 | +									. esc_html__('Registrations', 'event_espresso') | 
                                                        |
| 255 | + . '</a>';  | 
                                                        |
| 256 | + }  | 
                                                        |
| 257 | + if (EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 258 | + 'ee_delete_event',  | 
                                                        |
| 259 | + 'espresso_events_trash_event',  | 
                                                        |
| 260 | + $item->ID()  | 
                                                        |
| 261 | +		)) { | 
                                                        |
| 262 | + $trash_event_query_args = array(  | 
                                                        |
| 263 | + 'action' => 'trash_event',  | 
                                                        |
| 264 | + 'EVT_ID' => $item->ID(),  | 
                                                        |
| 265 | + );  | 
                                                        |
| 266 | + $trash_event_link = EE_Admin_Page::add_query_args_and_nonce(  | 
                                                        |
| 267 | + $trash_event_query_args,  | 
                                                        |
| 268 | + EVENTS_ADMIN_URL  | 
                                                        |
| 269 | + );  | 
                                                        |
| 270 | + }  | 
                                                        |
| 271 | + if (EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 272 | + 'ee_delete_event',  | 
                                                        |
| 273 | + 'espresso_events_restore_event',  | 
                                                        |
| 274 | + $item->ID()  | 
                                                        |
| 275 | +		)) { | 
                                                        |
| 276 | + $restore_event_query_args = array(  | 
                                                        |
| 277 | + 'action' => 'restore_event',  | 
                                                        |
| 278 | + 'EVT_ID' => $item->ID(),  | 
                                                        |
| 279 | + );  | 
                                                        |
| 280 | + $restore_event_link = EE_Admin_Page::add_query_args_and_nonce(  | 
                                                        |
| 281 | + $restore_event_query_args,  | 
                                                        |
| 282 | + EVENTS_ADMIN_URL  | 
                                                        |
| 283 | + );  | 
                                                        |
| 284 | + }  | 
                                                        |
| 285 | + if (EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 286 | + 'ee_delete_event',  | 
                                                        |
| 287 | + 'espresso_events_delete_event',  | 
                                                        |
| 288 | + $item->ID()  | 
                                                        |
| 289 | +		)) { | 
                                                        |
| 290 | + $delete_event_query_args = array(  | 
                                                        |
| 291 | + 'action' => 'delete_event',  | 
                                                        |
| 292 | + 'EVT_ID' => $item->ID(),  | 
                                                        |
| 293 | + );  | 
                                                        |
| 294 | + $delete_event_link = EE_Admin_Page::add_query_args_and_nonce(  | 
                                                        |
| 295 | + $delete_event_query_args,  | 
                                                        |
| 296 | + EVENTS_ADMIN_URL  | 
                                                        |
| 297 | + );  | 
                                                        |
| 298 | + }  | 
                                                        |
| 299 | + $view_link = get_permalink($item->ID());  | 
                                                        |
| 300 | + $actions['view'] = '<a href="' . $view_link . '"'  | 
                                                        |
| 301 | +						   . ' title="' . esc_attr__('View Event', 'event_espresso') . '">' | 
                                                        |
| 302 | +						   . esc_html__('View', 'event_espresso') | 
                                                        |
| 303 | + . '</a>';  | 
                                                        |
| 304 | +		if ($item->get('status') === 'trash') { | 
                                                        |
| 305 | + if (EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 306 | + 'ee_delete_event',  | 
                                                        |
| 307 | + 'espresso_events_restore_event',  | 
                                                        |
| 308 | + $item->ID()  | 
                                                        |
| 309 | +			)) { | 
                                                        |
| 310 | + $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"'  | 
                                                        |
| 311 | +												 . ' title="' . esc_attr__('Restore from Trash', 'event_espresso') | 
                                                        |
| 312 | + . '">'  | 
                                                        |
| 313 | +												 . esc_html__('Restore from Trash', 'event_espresso') | 
                                                        |
| 314 | + . '</a>';  | 
                                                        |
| 315 | + }  | 
                                                        |
| 316 | + if (EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 317 | + 'ee_delete_event',  | 
                                                        |
| 318 | + 'espresso_events_delete_event',  | 
                                                        |
| 319 | + $item->ID()  | 
                                                        |
| 320 | + )  | 
                                                        |
| 321 | +			) { | 
                                                        |
| 322 | + $actions['delete'] = '<a href="' . $delete_event_link . '"'  | 
                                                        |
| 323 | +									 . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">' | 
                                                        |
| 324 | +									 . esc_html__('Delete Permanently', 'event_espresso') | 
                                                        |
| 325 | + . '</a>';  | 
                                                        |
| 326 | + }  | 
                                                        |
| 327 | +		} else { | 
                                                        |
| 328 | + if (EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 329 | + 'ee_delete_event',  | 
                                                        |
| 330 | + 'espresso_events_trash_event',  | 
                                                        |
| 331 | + $item->ID()  | 
                                                        |
| 332 | +			)) { | 
                                                        |
| 333 | + $actions['move to trash'] = '<a href="' . $trash_event_link . '"'  | 
                                                        |
| 334 | +											. ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">' | 
                                                        |
| 335 | +											. esc_html__('Trash', 'event_espresso') | 
                                                        |
| 336 | + . '</a>';  | 
                                                        |
| 337 | + }  | 
                                                        |
| 338 | + }  | 
                                                        |
| 339 | + return $actions;  | 
                                                        |
| 340 | + }  | 
                                                        |
| 341 | +  | 
                                                        |
| 342 | +  | 
                                                        |
| 343 | + /**  | 
                                                        |
| 344 | + * @param EE_Event $item  | 
                                                        |
| 345 | + * @return string  | 
                                                        |
| 346 | + * @throws EE_Error  | 
                                                        |
| 347 | + */  | 
                                                        |
| 348 | + public function column_author(EE_Event $item)  | 
                                                        |
| 349 | +	{ | 
                                                        |
| 350 | + // user author info  | 
                                                        |
| 351 | + $event_author = get_userdata($item->wp_user());  | 
                                                        |
| 352 | + $gravatar = get_avatar($item->wp_user(), '15');  | 
                                                        |
| 353 | + // filter link  | 
                                                        |
| 354 | + $query_args = array(  | 
                                                        |
| 355 | + 'action' => 'default',  | 
                                                        |
| 356 | + 'EVT_wp_user' => $item->wp_user(),  | 
                                                        |
| 357 | + );  | 
                                                        |
| 358 | + $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL);  | 
                                                        |
| 359 | + return $gravatar . ' <a href="' . $filter_url . '"'  | 
                                                        |
| 360 | +			   . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">' | 
                                                        |
| 361 | + . $event_author->display_name  | 
                                                        |
| 362 | + . '</a>';  | 
                                                        |
| 363 | + }  | 
                                                        |
| 364 | +  | 
                                                        |
| 365 | +  | 
                                                        |
| 366 | + /**  | 
                                                        |
| 367 | + * @param EE_Event $event  | 
                                                        |
| 368 | + * @return string  | 
                                                        |
| 369 | + * @throws EE_Error  | 
                                                        |
| 370 | + */  | 
                                                        |
| 371 | + public function column_event_category(EE_Event $event)  | 
                                                        |
| 372 | +	{ | 
                                                        |
| 373 | + $event_categories = $event->get_all_event_categories();  | 
                                                        |
| 374 | + return implode(  | 
                                                        |
| 375 | + ', ',  | 
                                                        |
| 376 | + array_map(  | 
                                                        |
| 377 | +				function (EE_Term $category) { | 
                                                        |
| 378 | + return $category->name();  | 
                                                        |
| 379 | + },  | 
                                                        |
| 380 | + $event_categories  | 
                                                        |
| 381 | + )  | 
                                                        |
| 382 | + );  | 
                                                        |
| 383 | + }  | 
                                                        |
| 384 | +  | 
                                                        |
| 385 | +  | 
                                                        |
| 386 | + /**  | 
                                                        |
| 387 | + * @param EE_Event $item  | 
                                                        |
| 388 | + * @return string  | 
                                                        |
| 389 | + * @throws EE_Error  | 
                                                        |
| 390 | + */  | 
                                                        |
| 391 | + public function column_venue(EE_Event $item)  | 
                                                        |
| 392 | +	{ | 
                                                        |
| 393 | +		$venue = $item->get_first_related('Venue'); | 
                                                        |
| 394 | + return ! empty($venue)  | 
                                                        |
| 395 | + ? $venue->name()  | 
                                                        |
| 396 | + : '';  | 
                                                        |
| 397 | + }  | 
                                                        |
| 398 | +  | 
                                                        |
| 399 | +  | 
                                                        |
| 400 | + /**  | 
                                                        |
| 401 | + * @param EE_Event $item  | 
                                                        |
| 402 | + * @return string  | 
                                                        |
| 403 | + * @throws EE_Error  | 
                                                        |
| 404 | + */  | 
                                                        |
| 405 | + public function column_start_date_time(EE_Event $item)  | 
                                                        |
| 406 | +	{ | 
                                                        |
| 407 | + return $this->_dtt instanceof EE_Datetime  | 
                                                        |
| 408 | +			? $this->_dtt->get_i18n_datetime('DTT_EVT_start') | 
                                                        |
| 409 | +			: esc_html__('No Date was saved for this Event', 'event_espresso'); | 
                                                        |
| 410 | + }  | 
                                                        |
| 411 | +  | 
                                                        |
| 412 | +  | 
                                                        |
| 413 | + /**  | 
                                                        |
| 414 | + * @param EE_Event $item  | 
                                                        |
| 415 | + * @return string  | 
                                                        |
| 416 | + * @throws EE_Error  | 
                                                        |
| 417 | + */  | 
                                                        |
| 418 | + public function column_reg_begins(EE_Event $item)  | 
                                                        |
| 419 | +	{ | 
                                                        |
| 420 | + $reg_start = $item->get_ticket_with_earliest_start_time();  | 
                                                        |
| 421 | + return $reg_start instanceof EE_Ticket  | 
                                                        |
| 422 | +			? $reg_start->get_i18n_datetime('TKT_start_date') | 
                                                        |
| 423 | +			: esc_html__('No Tickets have been setup for this Event', 'event_espresso'); | 
                                                        |
| 424 | + }  | 
                                                        |
| 425 | +  | 
                                                        |
| 426 | +  | 
                                                        |
| 427 | + /**  | 
                                                        |
| 428 | + * @param EE_Event $item  | 
                                                        |
| 429 | + * @return int|string  | 
                                                        |
| 430 | + * @throws EE_Error  | 
                                                        |
| 431 | + * @throws InvalidArgumentException  | 
                                                        |
| 432 | + * @throws InvalidDataTypeException  | 
                                                        |
| 433 | + * @throws InvalidInterfaceException  | 
                                                        |
| 434 | + */  | 
                                                        |
| 435 | + public function column_attendees(EE_Event $item)  | 
                                                        |
| 436 | +	{ | 
                                                        |
| 437 | + $attendees_query_args = array(  | 
                                                        |
| 438 | + 'action' => 'default',  | 
                                                        |
| 439 | + 'event_id' => $item->ID(),  | 
                                                        |
| 440 | + );  | 
                                                        |
| 441 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);  | 
                                                        |
| 442 | + $registered_attendees = EEM_Registration::instance()->get_event_registration_count($item->ID());  | 
                                                        |
| 443 | + return EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 444 | + 'ee_read_event',  | 
                                                        |
| 445 | + 'espresso_registrations_view_registration',  | 
                                                        |
| 446 | + $item->ID()  | 
                                                        |
| 447 | + )  | 
                                                        |
| 448 | + && EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 449 | + 'ee_read_registrations',  | 
                                                        |
| 450 | + 'espresso_registrations_view_registration'  | 
                                                        |
| 451 | + )  | 
                                                        |
| 452 | + ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>'  | 
                                                        |
| 453 | + : $registered_attendees;  | 
                                                        |
| 454 | + }  | 
                                                        |
| 455 | +  | 
                                                        |
| 456 | +  | 
                                                        |
| 457 | + /**  | 
                                                        |
| 458 | + * @param EE_Event $item  | 
                                                        |
| 459 | + * @return float  | 
                                                        |
| 460 | + * @throws EE_Error  | 
                                                        |
| 461 | + * @throws InvalidArgumentException  | 
                                                        |
| 462 | + * @throws InvalidDataTypeException  | 
                                                        |
| 463 | + * @throws InvalidInterfaceException  | 
                                                        |
| 464 | + */  | 
                                                        |
| 465 | + public function column_tkts_sold(EE_Event $item)  | 
                                                        |
| 466 | +	{ | 
                                                        |
| 467 | +		return EEM_Ticket::instance()->sum(array(array('Datetime.EVT_ID' => $item->ID())), 'TKT_sold'); | 
                                                        |
| 468 | + }  | 
                                                        |
| 469 | +  | 
                                                        |
| 470 | +  | 
                                                        |
| 471 | + /**  | 
                                                        |
| 472 | + * @param EE_Event $item  | 
                                                        |
| 473 | + * @return string  | 
                                                        |
| 474 | + * @throws EE_Error  | 
                                                        |
| 475 | + * @throws InvalidArgumentException  | 
                                                        |
| 476 | + * @throws InvalidDataTypeException  | 
                                                        |
| 477 | + * @throws InvalidInterfaceException  | 
                                                        |
| 478 | + */  | 
                                                        |
| 479 | + public function column_actions(EE_Event $item)  | 
                                                        |
| 480 | +	{ | 
                                                        |
| 481 | + // todo: remove when attendees is active  | 
                                                        |
| 482 | +		if (! defined('REG_ADMIN_URL')) { | 
                                                        |
| 483 | +			define('REG_ADMIN_URL', EVENTS_ADMIN_URL); | 
                                                        |
| 484 | + }  | 
                                                        |
| 485 | + $action_links = array();  | 
                                                        |
| 486 | + $view_link = get_permalink($item->ID());  | 
                                                        |
| 487 | + $action_links[] = '<a href="' . $view_link . '"'  | 
                                                        |
| 488 | +						  . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">'; | 
                                                        |
| 489 | + $action_links[] = '<div class="dashicons dashicons-search"></div></a>';  | 
                                                        |
| 490 | + if (EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 491 | + 'ee_edit_event',  | 
                                                        |
| 492 | + 'espresso_events_edit',  | 
                                                        |
| 493 | + $item->ID()  | 
                                                        |
| 494 | +		)) { | 
                                                        |
| 495 | + $edit_query_args = array(  | 
                                                        |
| 496 | + 'action' => 'edit',  | 
                                                        |
| 497 | + 'post' => $item->ID(),  | 
                                                        |
| 498 | + );  | 
                                                        |
| 499 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);  | 
                                                        |
| 500 | + $action_links[] = '<a href="' . $edit_link . '"'  | 
                                                        |
| 501 | +							  . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' | 
                                                        |
| 502 | + . '<div class="ee-icon ee-icon-calendar-edit"></div>'  | 
                                                        |
| 503 | + . '</a>';  | 
                                                        |
| 504 | + }  | 
                                                        |
| 505 | + if (EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 506 | + 'ee_read_registrations',  | 
                                                        |
| 507 | + 'espresso_registrations_view_registration'  | 
                                                        |
| 508 | + ) && EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 509 | + 'ee_read_event',  | 
                                                        |
| 510 | + 'espresso_registrations_view_registration',  | 
                                                        |
| 511 | + $item->ID()  | 
                                                        |
| 512 | + )  | 
                                                        |
| 513 | +		) { | 
                                                        |
| 514 | + $attendees_query_args = array(  | 
                                                        |
| 515 | + 'action' => 'default',  | 
                                                        |
| 516 | + 'event_id' => $item->ID(),  | 
                                                        |
| 517 | + );  | 
                                                        |
| 518 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);  | 
                                                        |
| 519 | + $action_links[] = '<a href="' . $attendees_link . '"'  | 
                                                        |
| 520 | +							  . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">' | 
                                                        |
| 521 | + . '<div class="dashicons dashicons-groups"></div>'  | 
                                                        |
| 522 | + . '</a>';  | 
                                                        |
| 523 | + }  | 
                                                        |
| 524 | + $action_links = apply_filters(  | 
                                                        |
| 525 | + 'FHEE__Events_Admin_List_Table__column_actions__action_links',  | 
                                                        |
| 526 | + $action_links,  | 
                                                        |
| 527 | + $item  | 
                                                        |
| 528 | + );  | 
                                                        |
| 529 | + return $this->_action_string(  | 
                                                        |
| 530 | +			implode("\n\t", $action_links), | 
                                                        |
| 531 | + $item,  | 
                                                        |
| 532 | + 'div'  | 
                                                        |
| 533 | + );  | 
                                                        |
| 534 | + }  | 
                                                        |
| 535 | +  | 
                                                        |
| 536 | +  | 
                                                        |
| 537 | + /**  | 
                                                        |
| 538 | + * Helper for adding columns conditionally  | 
                                                        |
| 539 | + *  | 
                                                        |
| 540 | + * @throws EE_Error  | 
                                                        |
| 541 | + * @throws InvalidArgumentException  | 
                                                        |
| 542 | + * @throws InvalidDataTypeException  | 
                                                        |
| 543 | + * @throws InvalidInterfaceException  | 
                                                        |
| 544 | + */  | 
                                                        |
| 545 | + private function addConditionalColumns()  | 
                                                        |
| 546 | +	{ | 
                                                        |
| 547 | + $event_category_count = EEM_Term::instance()->count(  | 
                                                        |
| 548 | + [['Term_Taxonomy.taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]]  | 
                                                        |
| 549 | + );  | 
                                                        |
| 550 | +		if ($event_category_count === 0) { | 
                                                        |
| 551 | + return;  | 
                                                        |
| 552 | + }  | 
                                                        |
| 553 | + $column_array = [];  | 
                                                        |
| 554 | +		foreach ($this->_columns as $column => $column_label) { | 
                                                        |
| 555 | + $column_array[ $column ] = $column_label;  | 
                                                        |
| 556 | +			if ($column === 'venue') { | 
                                                        |
| 557 | +				$column_array['event_category'] = esc_html__('Event Category', 'event_espresso'); | 
                                                        |
| 558 | + }  | 
                                                        |
| 559 | + }  | 
                                                        |
| 560 | + $this->_columns = $column_array;  | 
                                                        |
| 561 | + }  | 
                                                        |
| 562 | 562 | }  | 
                                                        
@@ -112,7 +112,7 @@ discard block  | 
                                                    ||
| 112 | 112 | $class = parent::_get_row_class($item);  | 
                                                        
| 113 | 113 | // add status class  | 
                                                        
| 114 | 114 | $class .= $item instanceof EE_Event  | 
                                                        
| 115 | - ? ' ee-status-strip event-status-' . $item->get_active_status()  | 
                                                        |
| 115 | + ? ' ee-status-strip event-status-'.$item->get_active_status()  | 
                                                        |
| 116 | 116 | : '';  | 
                                                        
| 117 | 117 |          if ($this->_has_checkbox_column) { | 
                                                        
| 118 | 118 | $class .= ' has-checkbox-column';  | 
                                                        
@@ -141,7 +141,7 @@ discard block  | 
                                                    ||
| 141 | 141 | */  | 
                                                        
| 142 | 142 | public function column_cb($item)  | 
                                                        
| 143 | 143 |      { | 
                                                        
| 144 | -        if (! $item instanceof EE_Event) { | 
                                                        |
| 144 | +        if ( ! $item instanceof EE_Event) { | 
                                                        |
| 145 | 145 | return '';  | 
                                                        
| 146 | 146 | }  | 
                                                        
| 147 | 147 | $this->_dtt = $item->primary_datetime(); // set this for use in other columns  | 
                                                        
@@ -160,7 +160,7 @@ discard block  | 
                                                    ||
| 160 | 160 | public function column_id(EE_Event $item)  | 
                                                        
| 161 | 161 |      { | 
                                                        
| 162 | 162 | $content = $item->ID();  | 
                                                        
| 163 | - $content .= ' <span class="show-on-mobile-view-only">' . $item->name() . '</span>';  | 
                                                        |
| 163 | + $content .= ' <span class="show-on-mobile-view-only">'.$item->name().'</span>';  | 
                                                        |
| 164 | 164 | return $content;  | 
                                                        
| 165 | 165 | }  | 
                                                        
| 166 | 166 | |
@@ -183,7 +183,7 @@ discard block  | 
                                                    ||
| 183 | 183 | $actions = $this->_column_name_action_setup($item);  | 
                                                        
| 184 | 184 |          $status = ''; // $item->status() !== 'publish' ? ' (' . $item->status() . ')' : ''; | 
                                                        
| 185 | 185 | $content = '<strong><a class="row-title" href="'  | 
                                                        
| 186 | - . $edit_link . '">'  | 
                                                        |
| 186 | + . $edit_link.'">'  | 
                                                        |
| 187 | 187 | . $item->name()  | 
                                                        
| 188 | 188 | . '</a></strong>'  | 
                                                        
| 189 | 189 | . $status;  | 
                                                        
@@ -212,7 +212,7 @@ discard block  | 
                                                    ||
| 212 | 212 | protected function _column_name_action_setup(EE_Event $item)  | 
                                                        
| 213 | 213 |      { | 
                                                        
| 214 | 214 | // todo: remove when attendees is active  | 
                                                        
| 215 | -        if (! defined('REG_ADMIN_URL')) { | 
                                                        |
| 215 | +        if ( ! defined('REG_ADMIN_URL')) { | 
                                                        |
| 216 | 216 |              define('REG_ADMIN_URL', EVENTS_ADMIN_URL); | 
                                                        
| 217 | 217 | }  | 
                                                        
| 218 | 218 | $actions = array();  | 
                                                        
@@ -229,8 +229,8 @@ discard block  | 
                                                    ||
| 229 | 229 | 'post' => $item->ID(),  | 
                                                        
| 230 | 230 | );  | 
                                                        
| 231 | 231 | $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);  | 
                                                        
| 232 | - $actions['edit'] = '<a href="' . $edit_link . '"'  | 
                                                        |
| 233 | -                               . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' | 
                                                        |
| 232 | + $actions['edit'] = '<a href="'.$edit_link.'"'  | 
                                                        |
| 233 | +                               . ' title="'.esc_attr__('Edit Event', 'event_espresso').'">' | 
                                                        |
| 234 | 234 |                                 . esc_html__('Edit', 'event_espresso') | 
                                                        
| 235 | 235 | . '</a>';  | 
                                                        
| 236 | 236 | }  | 
                                                        
@@ -249,8 +249,8 @@ discard block  | 
                                                    ||
| 249 | 249 | 'event_id' => $item->ID(),  | 
                                                        
| 250 | 250 | );  | 
                                                        
| 251 | 251 | $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);  | 
                                                        
| 252 | - $actions['attendees'] = '<a href="' . $attendees_link . '"'  | 
                                                        |
| 253 | -                                    . ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">' | 
                                                        |
| 252 | + $actions['attendees'] = '<a href="'.$attendees_link.'"'  | 
                                                        |
| 253 | +                                    . ' title="'.esc_attr__('View Registrations', 'event_espresso').'">' | 
                                                        |
| 254 | 254 |                                      . esc_html__('Registrations', 'event_espresso') | 
                                                        
| 255 | 255 | . '</a>';  | 
                                                        
| 256 | 256 | }  | 
                                                        
@@ -297,8 +297,8 @@ discard block  | 
                                                    ||
| 297 | 297 | );  | 
                                                        
| 298 | 298 | }  | 
                                                        
| 299 | 299 | $view_link = get_permalink($item->ID());  | 
                                                        
| 300 | - $actions['view'] = '<a href="' . $view_link . '"'  | 
                                                        |
| 301 | -                           . ' title="' . esc_attr__('View Event', 'event_espresso') . '">' | 
                                                        |
| 300 | + $actions['view'] = '<a href="'.$view_link.'"'  | 
                                                        |
| 301 | +                           . ' title="'.esc_attr__('View Event', 'event_espresso').'">' | 
                                                        |
| 302 | 302 |                             . esc_html__('View', 'event_espresso') | 
                                                        
| 303 | 303 | . '</a>';  | 
                                                        
| 304 | 304 |          if ($item->get('status') === 'trash') { | 
                                                        
@@ -307,8 +307,8 @@ discard block  | 
                                                    ||
| 307 | 307 | 'espresso_events_restore_event',  | 
                                                        
| 308 | 308 | $item->ID()  | 
                                                        
| 309 | 309 |              )) { | 
                                                        
| 310 | - $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"'  | 
                                                        |
| 311 | -                                                 . ' title="' . esc_attr__('Restore from Trash', 'event_espresso') | 
                                                        |
| 310 | + $actions['restore_from_trash'] = '<a href="'.$restore_event_link.'"'  | 
                                                        |
| 311 | +                                                 . ' title="'.esc_attr__('Restore from Trash', 'event_espresso') | 
                                                        |
| 312 | 312 | . '">'  | 
                                                        
| 313 | 313 |                                                   . esc_html__('Restore from Trash', 'event_espresso') | 
                                                        
| 314 | 314 | . '</a>';  | 
                                                        
@@ -319,8 +319,8 @@ discard block  | 
                                                    ||
| 319 | 319 | $item->ID()  | 
                                                        
| 320 | 320 | )  | 
                                                        
| 321 | 321 |              ) { | 
                                                        
| 322 | - $actions['delete'] = '<a href="' . $delete_event_link . '"'  | 
                                                        |
| 323 | -                                     . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">' | 
                                                        |
| 322 | + $actions['delete'] = '<a href="'.$delete_event_link.'"'  | 
                                                        |
| 323 | +                                     . ' title="'.esc_attr__('Delete Permanently', 'event_espresso').'">' | 
                                                        |
| 324 | 324 |                                       . esc_html__('Delete Permanently', 'event_espresso') | 
                                                        
| 325 | 325 | . '</a>';  | 
                                                        
| 326 | 326 | }  | 
                                                        
@@ -330,8 +330,8 @@ discard block  | 
                                                    ||
| 330 | 330 | 'espresso_events_trash_event',  | 
                                                        
| 331 | 331 | $item->ID()  | 
                                                        
| 332 | 332 |              )) { | 
                                                        
| 333 | - $actions['move to trash'] = '<a href="' . $trash_event_link . '"'  | 
                                                        |
| 334 | -                                            . ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">' | 
                                                        |
| 333 | + $actions['move to trash'] = '<a href="'.$trash_event_link.'"'  | 
                                                        |
| 334 | +                                            . ' title="'.esc_attr__('Trash Event', 'event_espresso').'">' | 
                                                        |
| 335 | 335 |                                              . esc_html__('Trash', 'event_espresso') | 
                                                        
| 336 | 336 | . '</a>';  | 
                                                        
| 337 | 337 | }  | 
                                                        
@@ -356,8 +356,8 @@ discard block  | 
                                                    ||
| 356 | 356 | 'EVT_wp_user' => $item->wp_user(),  | 
                                                        
| 357 | 357 | );  | 
                                                        
| 358 | 358 | $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL);  | 
                                                        
| 359 | - return $gravatar . ' <a href="' . $filter_url . '"'  | 
                                                        |
| 360 | -               . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">' | 
                                                        |
| 359 | + return $gravatar.' <a href="'.$filter_url.'"'  | 
                                                        |
| 360 | +               . ' title="'.esc_attr__('Click to filter events by this author.', 'event_espresso').'">' | 
                                                        |
| 361 | 361 | . $event_author->display_name  | 
                                                        
| 362 | 362 | . '</a>';  | 
                                                        
| 363 | 363 | }  | 
                                                        
@@ -374,7 +374,7 @@ discard block  | 
                                                    ||
| 374 | 374 | return implode(  | 
                                                        
| 375 | 375 | ', ',  | 
                                                        
| 376 | 376 | array_map(  | 
                                                        
| 377 | -                function (EE_Term $category) { | 
                                                        |
| 377 | +                function(EE_Term $category) { | 
                                                        |
| 378 | 378 | return $category->name();  | 
                                                        
| 379 | 379 | },  | 
                                                        
| 380 | 380 | $event_categories  | 
                                                        
@@ -449,7 +449,7 @@ discard block  | 
                                                    ||
| 449 | 449 | 'ee_read_registrations',  | 
                                                        
| 450 | 450 | 'espresso_registrations_view_registration'  | 
                                                        
| 451 | 451 | )  | 
                                                        
| 452 | - ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>'  | 
                                                        |
| 452 | + ? '<a href="'.$attendees_link.'">'.$registered_attendees.'</a>'  | 
                                                        |
| 453 | 453 | : $registered_attendees;  | 
                                                        
| 454 | 454 | }  | 
                                                        
| 455 | 455 | |
@@ -479,13 +479,13 @@ discard block  | 
                                                    ||
| 479 | 479 | public function column_actions(EE_Event $item)  | 
                                                        
| 480 | 480 |      { | 
                                                        
| 481 | 481 | // todo: remove when attendees is active  | 
                                                        
| 482 | -        if (! defined('REG_ADMIN_URL')) { | 
                                                        |
| 482 | +        if ( ! defined('REG_ADMIN_URL')) { | 
                                                        |
| 483 | 483 |              define('REG_ADMIN_URL', EVENTS_ADMIN_URL); | 
                                                        
| 484 | 484 | }  | 
                                                        
| 485 | 485 | $action_links = array();  | 
                                                        
| 486 | 486 | $view_link = get_permalink($item->ID());  | 
                                                        
| 487 | - $action_links[] = '<a href="' . $view_link . '"'  | 
                                                        |
| 488 | -                          . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">'; | 
                                                        |
| 487 | + $action_links[] = '<a href="'.$view_link.'"'  | 
                                                        |
| 488 | +                          . ' title="'.esc_attr__('View Event', 'event_espresso').'" target="_blank">'; | 
                                                        |
| 489 | 489 | $action_links[] = '<div class="dashicons dashicons-search"></div></a>';  | 
                                                        
| 490 | 490 | if (EE_Registry::instance()->CAP->current_user_can(  | 
                                                        
| 491 | 491 | 'ee_edit_event',  | 
                                                        
@@ -497,8 +497,8 @@ discard block  | 
                                                    ||
| 497 | 497 | 'post' => $item->ID(),  | 
                                                        
| 498 | 498 | );  | 
                                                        
| 499 | 499 | $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);  | 
                                                        
| 500 | - $action_links[] = '<a href="' . $edit_link . '"'  | 
                                                        |
| 501 | -                              . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' | 
                                                        |
| 500 | + $action_links[] = '<a href="'.$edit_link.'"'  | 
                                                        |
| 501 | +                              . ' title="'.esc_attr__('Edit Event', 'event_espresso').'">' | 
                                                        |
| 502 | 502 | . '<div class="ee-icon ee-icon-calendar-edit"></div>'  | 
                                                        
| 503 | 503 | . '</a>';  | 
                                                        
| 504 | 504 | }  | 
                                                        
@@ -516,8 +516,8 @@ discard block  | 
                                                    ||
| 516 | 516 | 'event_id' => $item->ID(),  | 
                                                        
| 517 | 517 | );  | 
                                                        
| 518 | 518 | $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);  | 
                                                        
| 519 | - $action_links[] = '<a href="' . $attendees_link . '"'  | 
                                                        |
| 520 | -                              . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">' | 
                                                        |
| 519 | + $action_links[] = '<a href="'.$attendees_link.'"'  | 
                                                        |
| 520 | +                              . ' title="'.esc_attr__('View Registrants', 'event_espresso').'">' | 
                                                        |
| 521 | 521 | . '<div class="dashicons dashicons-groups"></div>'  | 
                                                        
| 522 | 522 | . '</a>';  | 
                                                        
| 523 | 523 | }  | 
                                                        
@@ -552,7 +552,7 @@ discard block  | 
                                                    ||
| 552 | 552 | }  | 
                                                        
| 553 | 553 | $column_array = [];  | 
                                                        
| 554 | 554 |          foreach ($this->_columns as $column => $column_label) { | 
                                                        
| 555 | - $column_array[ $column ] = $column_label;  | 
                                                        |
| 555 | + $column_array[$column] = $column_label;  | 
                                                        |
| 556 | 556 |              if ($column === 'venue') { | 
                                                        
| 557 | 557 |                  $column_array['event_category'] = esc_html__('Event Category', 'event_espresso'); | 
                                                        
| 558 | 558 | }  |