Completed
Branch CASC/initial-ui (c5e0e6)
by
unknown
32:13 queued 24:29
created
core/services/orm/tree_traversal/RelationNode.php 4 patches
Doc Comments   +5 added lines, -1 removed lines patch added patch discarded remove patch
@@ -43,6 +43,10 @@  discard block
 block discarded – undo
43 43
 
44 44
     protected $model_obj_nodes;
45 45
 
46
+    /**
47
+     * @param EE_Base_Class $main_model_obj
48
+     * @param EEM_Base|null $related_model
49
+     */
46 50
     public function __construct($main_model_obj, $related_model)
47 51
     {
48 52
         $this->main_model_obj = $main_model_obj;
@@ -119,7 +123,7 @@  discard block
 block discarded – undo
119 123
      * Visits the provided nodes and keeps track of how much work was done, making sure to not go over budget.
120 124
      * @since $VID:$
121 125
      * @param ModelObjNode[] $model_obj_nodes
122
-     * @param $work_budget
126
+     * @param integer $work_budget
123 127
      * @return int
124 128
      */
125 129
     protected function visitAlreadyDiscoveredNodes($model_obj_nodes, $work_budget)
Please login to merge, or discard this patch.
Unused Use Statements   -2 removed lines patch added patch discarded remove patch
@@ -4,11 +4,9 @@
 block discarded – undo
4 4
 
5 5
 use EE_Base_Class;
6 6
 use EE_Error;
7
-use EE_Model_Relation_Base;
8 7
 use EEM_Base;
9 8
 use EventEspresso\core\exceptions\InvalidDataTypeException;
10 9
 use EventEspresso\core\exceptions\InvalidInterfaceException;
11
-use EventEspresso\core\services\payment_methods\forms\PayPalSettingsForm;
12 10
 use InvalidArgumentException;
13 11
 use ReflectionException;
14 12
 
Please login to merge, or discard this patch.
Indentation   +184 added lines, -184 removed lines patch added patch discarded remove patch
@@ -25,190 +25,190 @@
 block discarded – undo
25 25
  */
26 26
 class RelationNode extends BaseNode
27 27
 {
28
-    /**
29
-     * @var EE_Base_Class
30
-     */
31
-    protected $main_model_obj;
32
-
33
-    /**
34
-     * @var int
35
-     */
36
-    protected $count;
37
-
38
-    /**
39
-     * @var EEM_Base
40
-     */
41
-    protected $related_model;
42
-
43
-
44
-    protected $model_obj_nodes;
45
-
46
-    public function __construct($main_model_obj, $related_model)
47
-    {
48
-        $this->main_model_obj = $main_model_obj;
49
-        $this->related_model = $related_model;
50
-        $this->model_obj_nodes = [];
51
-    }
52
-
53
-
54
-    /**
55
-     * Here is where most of the work happens. We've counted how many related model objects exist, here we identify
56
-     * them (ie, learn their IDs). But its recursive, so we'll also find their related dependent model objects etc.
57
-     * @since $VID:$
58
-     * @param int $model_objects_to_identify
59
-     * @return int
60
-     * @throws EE_Error
61
-     * @throws InvalidArgumentException
62
-     * @throws InvalidDataTypeException
63
-     * @throws InvalidInterfaceException
64
-     * @throws ReflectionException
65
-     */
66
-    protected function work($model_objects_to_identify)
67
-    {
68
-        $num_identified = $this->visitAlreadyDiscoveredNodes($this->model_obj_nodes, $model_objects_to_identify);
69
-        if ($num_identified < $model_objects_to_identify) {
70
-            $related_model_objs = $this->related_model->get_all(
71
-                [
72
-                    $this->whereQueryParams(),
73
-                    'limit' => [
74
-                        count($this->model_obj_nodes),
75
-                        $model_objects_to_identify
76
-                    ]
77
-                ]
78
-            );
79
-            $new_item_nodes = [];
80
-
81
-            // Add entity nodes for each of the model objects we fetched.
82
-            foreach ($related_model_objs as $related_model_obj) {
83
-                $entity_node = new ModelObjNode($related_model_obj);
84
-                $this->model_obj_nodes[ $related_model_obj->ID() ] = $entity_node;
85
-                $new_item_nodes[ $related_model_obj->ID() ] = $entity_node;
86
-            }
87
-            $num_identified += count($new_item_nodes);
88
-            if ($num_identified < $model_objects_to_identify) {
89
-                // And lastly do the work.
90
-                $num_identified += $this->visitAlreadyDiscoveredNodes(
91
-                    $new_item_nodes,
92
-                    $model_objects_to_identify - $num_identified
93
-                );
94
-            }
95
-        }
96
-
97
-        if (count($this->model_obj_nodes) >= $this->count && $this->allChildrenComplete()) {
98
-            $this->complete = true;
99
-        }
100
-        return $num_identified;
101
-    }
102
-
103
-    /**
104
-     * Checks if all the identified child nodes are complete or not.
105
-     * @since $VID:$
106
-     * @return bool
107
-     */
108
-    protected function allChildrenComplete()
109
-    {
110
-        foreach ($this->model_obj_nodes as $model_obj_node) {
111
-            if (! $model_obj_node->isComplete()) {
112
-                return false;
113
-            }
114
-        }
115
-        return true;
116
-    }
117
-
118
-    /**
119
-     * Visits the provided nodes and keeps track of how much work was done, making sure to not go over budget.
120
-     * @since $VID:$
121
-     * @param ModelObjNode[] $model_obj_nodes
122
-     * @param $work_budget
123
-     * @return int
124
-     */
125
-    protected function visitAlreadyDiscoveredNodes($model_obj_nodes, $work_budget)
126
-    {
127
-        $work_done = 0;
128
-        if (! $model_obj_nodes) {
129
-            return 0;
130
-        }
131
-        foreach ($model_obj_nodes as $model_obj_node) {
132
-            if ($work_done >= $work_budget) {
133
-                break;
134
-            }
135
-            $work_done += $model_obj_node->visit($work_budget - $work_done);
136
-        }
137
-        return $work_done;
138
-    }
139
-
140
-    /**
141
-     * Whether this item has already been initialized
142
-     */
143
-    protected function isDiscovered()
144
-    {
145
-        return $this->count !== null;
146
-    }
147
-
148
-    /**
149
-     * @since $VID:$
150
-     * @return boolean
151
-     */
152
-    public function isComplete()
153
-    {
154
-        if ($this->complete === null) {
155
-            if (count($this->model_obj_nodes) === $this->count) {
156
-                $this->complete = true;
157
-            } else {
158
-                $this->complete = false;
159
-            }
160
-        }
161
-        return $this->complete;
162
-    }
163
-
164
-    /**
165
-     * Discovers how many related model objects exist.
166
-     * @since $VID:$
167
-     * @return mixed|void
168
-     * @throws EE_Error
169
-     * @throws InvalidArgumentException
170
-     * @throws InvalidDataTypeException
171
-     * @throws InvalidInterfaceException
172
-     * @throws ReflectionException
173
-     */
174
-    protected function discover()
175
-    {
176
-        $this->count = $this->related_model->count([$this->whereQueryParams()]);
177
-    }
178
-
179
-    /**
180
-     * @since $VID:$
181
-     * @return array
182
-     * @throws EE_Error
183
-     * @throws InvalidDataTypeException
184
-     * @throws InvalidInterfaceException
185
-     * @throws InvalidArgumentException
186
-     * @throws ReflectionException
187
-     */
188
-    protected function whereQueryParams()
189
-    {
190
-        return [
191
-            $this->related_model->get_foreign_key_to(
192
-                $this->main_model_obj->get_model()->get_this_model_name()
193
-            )->get_name() => $this->main_model_obj->ID()
194
-        ];
195
-    }
196
-    /**
197
-     * @since $VID:$
198
-     * @return array
199
-     */
200
-    public function toArray()
201
-    {
202
-        $tree = [
203
-            'count' => $this->count,
204
-            'complete' => $this->isComplete(),
205
-            'objs' => []
206
-        ];
207
-        foreach ($this->model_obj_nodes as $id => $model_obj_node) {
208
-            $tree['objs'][ $id ] = $model_obj_node->toArray();
209
-        }
210
-        return $tree;
211
-    }
28
+	/**
29
+	 * @var EE_Base_Class
30
+	 */
31
+	protected $main_model_obj;
32
+
33
+	/**
34
+	 * @var int
35
+	 */
36
+	protected $count;
37
+
38
+	/**
39
+	 * @var EEM_Base
40
+	 */
41
+	protected $related_model;
42
+
43
+
44
+	protected $model_obj_nodes;
45
+
46
+	public function __construct($main_model_obj, $related_model)
47
+	{
48
+		$this->main_model_obj = $main_model_obj;
49
+		$this->related_model = $related_model;
50
+		$this->model_obj_nodes = [];
51
+	}
52
+
53
+
54
+	/**
55
+	 * Here is where most of the work happens. We've counted how many related model objects exist, here we identify
56
+	 * them (ie, learn their IDs). But its recursive, so we'll also find their related dependent model objects etc.
57
+	 * @since $VID:$
58
+	 * @param int $model_objects_to_identify
59
+	 * @return int
60
+	 * @throws EE_Error
61
+	 * @throws InvalidArgumentException
62
+	 * @throws InvalidDataTypeException
63
+	 * @throws InvalidInterfaceException
64
+	 * @throws ReflectionException
65
+	 */
66
+	protected function work($model_objects_to_identify)
67
+	{
68
+		$num_identified = $this->visitAlreadyDiscoveredNodes($this->model_obj_nodes, $model_objects_to_identify);
69
+		if ($num_identified < $model_objects_to_identify) {
70
+			$related_model_objs = $this->related_model->get_all(
71
+				[
72
+					$this->whereQueryParams(),
73
+					'limit' => [
74
+						count($this->model_obj_nodes),
75
+						$model_objects_to_identify
76
+					]
77
+				]
78
+			);
79
+			$new_item_nodes = [];
80
+
81
+			// Add entity nodes for each of the model objects we fetched.
82
+			foreach ($related_model_objs as $related_model_obj) {
83
+				$entity_node = new ModelObjNode($related_model_obj);
84
+				$this->model_obj_nodes[ $related_model_obj->ID() ] = $entity_node;
85
+				$new_item_nodes[ $related_model_obj->ID() ] = $entity_node;
86
+			}
87
+			$num_identified += count($new_item_nodes);
88
+			if ($num_identified < $model_objects_to_identify) {
89
+				// And lastly do the work.
90
+				$num_identified += $this->visitAlreadyDiscoveredNodes(
91
+					$new_item_nodes,
92
+					$model_objects_to_identify - $num_identified
93
+				);
94
+			}
95
+		}
96
+
97
+		if (count($this->model_obj_nodes) >= $this->count && $this->allChildrenComplete()) {
98
+			$this->complete = true;
99
+		}
100
+		return $num_identified;
101
+	}
102
+
103
+	/**
104
+	 * Checks if all the identified child nodes are complete or not.
105
+	 * @since $VID:$
106
+	 * @return bool
107
+	 */
108
+	protected function allChildrenComplete()
109
+	{
110
+		foreach ($this->model_obj_nodes as $model_obj_node) {
111
+			if (! $model_obj_node->isComplete()) {
112
+				return false;
113
+			}
114
+		}
115
+		return true;
116
+	}
117
+
118
+	/**
119
+	 * Visits the provided nodes and keeps track of how much work was done, making sure to not go over budget.
120
+	 * @since $VID:$
121
+	 * @param ModelObjNode[] $model_obj_nodes
122
+	 * @param $work_budget
123
+	 * @return int
124
+	 */
125
+	protected function visitAlreadyDiscoveredNodes($model_obj_nodes, $work_budget)
126
+	{
127
+		$work_done = 0;
128
+		if (! $model_obj_nodes) {
129
+			return 0;
130
+		}
131
+		foreach ($model_obj_nodes as $model_obj_node) {
132
+			if ($work_done >= $work_budget) {
133
+				break;
134
+			}
135
+			$work_done += $model_obj_node->visit($work_budget - $work_done);
136
+		}
137
+		return $work_done;
138
+	}
139
+
140
+	/**
141
+	 * Whether this item has already been initialized
142
+	 */
143
+	protected function isDiscovered()
144
+	{
145
+		return $this->count !== null;
146
+	}
147
+
148
+	/**
149
+	 * @since $VID:$
150
+	 * @return boolean
151
+	 */
152
+	public function isComplete()
153
+	{
154
+		if ($this->complete === null) {
155
+			if (count($this->model_obj_nodes) === $this->count) {
156
+				$this->complete = true;
157
+			} else {
158
+				$this->complete = false;
159
+			}
160
+		}
161
+		return $this->complete;
162
+	}
163
+
164
+	/**
165
+	 * Discovers how many related model objects exist.
166
+	 * @since $VID:$
167
+	 * @return mixed|void
168
+	 * @throws EE_Error
169
+	 * @throws InvalidArgumentException
170
+	 * @throws InvalidDataTypeException
171
+	 * @throws InvalidInterfaceException
172
+	 * @throws ReflectionException
173
+	 */
174
+	protected function discover()
175
+	{
176
+		$this->count = $this->related_model->count([$this->whereQueryParams()]);
177
+	}
178
+
179
+	/**
180
+	 * @since $VID:$
181
+	 * @return array
182
+	 * @throws EE_Error
183
+	 * @throws InvalidDataTypeException
184
+	 * @throws InvalidInterfaceException
185
+	 * @throws InvalidArgumentException
186
+	 * @throws ReflectionException
187
+	 */
188
+	protected function whereQueryParams()
189
+	{
190
+		return [
191
+			$this->related_model->get_foreign_key_to(
192
+				$this->main_model_obj->get_model()->get_this_model_name()
193
+			)->get_name() => $this->main_model_obj->ID()
194
+		];
195
+	}
196
+	/**
197
+	 * @since $VID:$
198
+	 * @return array
199
+	 */
200
+	public function toArray()
201
+	{
202
+		$tree = [
203
+			'count' => $this->count,
204
+			'complete' => $this->isComplete(),
205
+			'objs' => []
206
+		];
207
+		foreach ($this->model_obj_nodes as $id => $model_obj_node) {
208
+			$tree['objs'][ $id ] = $model_obj_node->toArray();
209
+		}
210
+		return $tree;
211
+	}
212 212
 }
213 213
 // End of file RelationNode.php
214 214
 // Location: EventEspresso\core\services\orm\tree_traversal/RelationNode.php
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -81,8 +81,8 @@  discard block
 block discarded – undo
81 81
             // Add entity nodes for each of the model objects we fetched.
82 82
             foreach ($related_model_objs as $related_model_obj) {
83 83
                 $entity_node = new ModelObjNode($related_model_obj);
84
-                $this->model_obj_nodes[ $related_model_obj->ID() ] = $entity_node;
85
-                $new_item_nodes[ $related_model_obj->ID() ] = $entity_node;
84
+                $this->model_obj_nodes[$related_model_obj->ID()] = $entity_node;
85
+                $new_item_nodes[$related_model_obj->ID()] = $entity_node;
86 86
             }
87 87
             $num_identified += count($new_item_nodes);
88 88
             if ($num_identified < $model_objects_to_identify) {
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
     protected function allChildrenComplete()
109 109
     {
110 110
         foreach ($this->model_obj_nodes as $model_obj_node) {
111
-            if (! $model_obj_node->isComplete()) {
111
+            if ( ! $model_obj_node->isComplete()) {
112 112
                 return false;
113 113
             }
114 114
         }
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
     protected function visitAlreadyDiscoveredNodes($model_obj_nodes, $work_budget)
126 126
     {
127 127
         $work_done = 0;
128
-        if (! $model_obj_nodes) {
128
+        if ( ! $model_obj_nodes) {
129 129
             return 0;
130 130
         }
131 131
         foreach ($model_obj_nodes as $model_obj_node) {
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
             'objs' => []
206 206
         ];
207 207
         foreach ($this->model_obj_nodes as $id => $model_obj_node) {
208
-            $tree['objs'][ $id ] = $model_obj_node->toArray();
208
+            $tree['objs'][$id] = $model_obj_node->toArray();
209 209
         }
210 210
         return $tree;
211 211
     }
Please login to merge, or discard this patch.
core/services/orm/tree_traversal/BaseNode.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@
 block discarded – undo
68 68
      */
69 69
     public function visit($model_objects_to_identify)
70 70
     {
71
-        if (! $this->isDiscovered()) {
71
+        if ( ! $this->isDiscovered()) {
72 72
             $this->discover();
73 73
         }
74 74
         if ($this->isComplete()) {
Please login to merge, or discard this patch.
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -31,66 +31,66 @@
 block discarded – undo
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 95
 // End of file BaseNode.php
96 96
 // Location: EventEspresso\core\services\orm\tree_traversal/BaseNode.php
Please login to merge, or discard this patch.
core/services/orm/tree_traversal/ModelObjNode.php 2 patches
Indentation   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -21,112 +21,112 @@
 block discarded – undo
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 131
 // End of file Visitor.php
132 132
 // Location: EventEspresso\core\services\orm\tree_traversal/Visitor.php
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -51,9 +51,9 @@  discard block
 block discarded – undo
51 51
         $this->relation_nodes = [];
52 52
         foreach ($this->model_obj->get_model()->relation_settings() as $relationName => $relation) {
53 53
             if ($relation instanceof EE_Has_Many_Relation) {
54
-                $this->relation_nodes[ $relationName ] = new RelationNode($this->model_obj, $relation->get_other_model());
54
+                $this->relation_nodes[$relationName] = new RelationNode($this->model_obj, $relation->get_other_model());
55 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());
56
+                $this->relation_nodes[$relation->get_join_model()->get_this_model_name()] = new RelationNode($this->model_obj, $relation->get_join_model());
57 57
             }
58 58
         }
59 59
         ksort($this->relation_nodes);
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
             $tree['rels'] = null;
123 123
         } else {
124 124
             foreach ($this->relation_nodes as $relation_name => $relation_node) {
125
-                $tree['rels'][ $relation_name ] = $relation_node->toArray();
125
+                $tree['rels'][$relation_name] = $relation_node->toArray();
126 126
             }
127 127
         }
128 128
         return $tree;
Please login to merge, or discard this patch.
admin_pages/events/Events_Admin_Page.core.php 3 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -2086,7 +2086,6 @@
 block discarded – undo
2086 2086
      * _delete_event
2087 2087
      *
2088 2088
      * @access protected
2089
-     * @param bool $redirect_after
2090 2089
      */
2091 2090
     protected function _delete_event()
2092 2091
     {
Please login to merge, or discard this patch.
Indentation   +2694 added lines, -2694 removed lines patch added patch discarded remove patch
@@ -12,509 +12,509 @@  discard block
 block discarded – undo
12 12
 class Events_Admin_Page extends EE_Admin_Page_CPT
13 13
 {
14 14
 
15
-    /**
16
-     * This will hold the event object for event_details screen.
17
-     *
18
-     * @access protected
19
-     * @var EE_Event $_event
20
-     */
21
-    protected $_event;
22
-
23
-
24
-    /**
25
-     * This will hold the category object for category_details screen.
26
-     *
27
-     * @var stdClass $_category
28
-     */
29
-    protected $_category;
30
-
31
-
32
-    /**
33
-     * This will hold the event model instance
34
-     *
35
-     * @var EEM_Event $_event_model
36
-     */
37
-    protected $_event_model;
38
-
39
-
40
-    /**
41
-     * @var EE_Event
42
-     */
43
-    protected $_cpt_model_obj = false;
44
-
45
-
46
-    /**
47
-     * Initialize page props for this admin page group.
48
-     */
49
-    protected function _init_page_props()
50
-    {
51
-        $this->page_slug = EVENTS_PG_SLUG;
52
-        $this->page_label = EVENTS_LABEL;
53
-        $this->_admin_base_url = EVENTS_ADMIN_URL;
54
-        $this->_admin_base_path = EVENTS_ADMIN;
55
-        $this->_cpt_model_names = array(
56
-            'create_new' => 'EEM_Event',
57
-            'edit'       => 'EEM_Event',
58
-        );
59
-        $this->_cpt_edit_routes = array(
60
-            'espresso_events' => 'edit',
61
-        );
62
-        add_action(
63
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
64
-            array($this, 'verify_event_edit'),
65
-            10,
66
-            2
67
-        );
68
-    }
69
-
70
-
71
-    /**
72
-     * Sets the ajax hooks used for this admin page group.
73
-     */
74
-    protected function _ajax_hooks()
75
-    {
76
-        add_action('wp_ajax_ee_save_timezone_setting', array($this, 'save_timezonestring_setting'));
77
-    }
78
-
79
-
80
-    /**
81
-     * Sets the page properties for this admin page group.
82
-     */
83
-    protected function _define_page_props()
84
-    {
85
-        $this->_admin_page_title = EVENTS_LABEL;
86
-        $this->_labels = array(
87
-            'buttons'      => array(
88
-                'add'             => esc_html__('Add New Event', 'event_espresso'),
89
-                'edit'            => esc_html__('Edit Event', 'event_espresso'),
90
-                'delete'          => esc_html__('Delete Event', 'event_espresso'),
91
-                'add_category'    => esc_html__('Add New Category', 'event_espresso'),
92
-                'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
93
-                'delete_category' => esc_html__('Delete Category', 'event_espresso'),
94
-            ),
95
-            'editor_title' => array(
96
-                'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
97
-            ),
98
-            'publishbox'   => array(
99
-                'create_new'        => esc_html__('Save New Event', 'event_espresso'),
100
-                'edit'              => esc_html__('Update Event', 'event_espresso'),
101
-                'add_category'      => esc_html__('Save New Category', 'event_espresso'),
102
-                'edit_category'     => esc_html__('Update Category', 'event_espresso'),
103
-                'template_settings' => esc_html__('Update Settings', 'event_espresso'),
104
-            ),
105
-        );
106
-    }
107
-
108
-
109
-    /**
110
-     * Sets the page routes property for this admin page group.
111
-     */
112
-    protected function _set_page_routes()
113
-    {
114
-        // load formatter helper
115
-        // load field generator helper
116
-        // is there a evt_id in the request?
117
-        $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
118
-            ? $this->_req_data['EVT_ID']
119
-            : 0;
120
-        $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
121
-        $this->_page_routes = array(
122
-            'default'                       => array(
123
-                'func'       => '_events_overview_list_table',
124
-                'capability' => 'ee_read_events',
125
-            ),
126
-            'create_new'                    => array(
127
-                'func'       => '_create_new_cpt_item',
128
-                'capability' => 'ee_edit_events',
129
-            ),
130
-            'edit'                          => array(
131
-                'func'       => '_edit_cpt_item',
132
-                'capability' => 'ee_edit_event',
133
-                'obj_id'     => $evt_id,
134
-            ),
135
-            'copy_event'                    => array(
136
-                'func'       => '_copy_events',
137
-                'capability' => 'ee_edit_event',
138
-                'obj_id'     => $evt_id,
139
-                'noheader'   => true,
140
-            ),
141
-            'trash_event'                   => array(
142
-                'func'       => '_trash_or_restore_event',
143
-                'args'       => array('event_status' => 'trash'),
144
-                'capability' => 'ee_delete_event',
145
-                'obj_id'     => $evt_id,
146
-                'noheader'   => true,
147
-            ),
148
-            'trash_events'                  => array(
149
-                'func'       => '_trash_or_restore_events',
150
-                'args'       => array('event_status' => 'trash'),
151
-                'capability' => 'ee_delete_events',
152
-                'noheader'   => true,
153
-            ),
154
-            'restore_event'                 => array(
155
-                'func'       => '_trash_or_restore_event',
156
-                'args'       => array('event_status' => 'draft'),
157
-                'capability' => 'ee_delete_event',
158
-                'obj_id'     => $evt_id,
159
-                'noheader'   => true,
160
-            ),
161
-            'restore_events'                => array(
162
-                'func'       => '_trash_or_restore_events',
163
-                'args'       => array('event_status' => 'draft'),
164
-                'capability' => 'ee_delete_events',
165
-                'noheader'   => true,
166
-            ),
167
-            'delete_event'                  => array(
168
-                'func'       => '_delete_event',
169
-                'capability' => 'ee_delete_event',
170
-                'obj_id'     => $evt_id,
171
-                'noheader'   => true,
172
-            ),
173
-            'delete_events'                 => array(
174
-                'func'       => '_delete_events',
175
-                'capability' => 'ee_delete_events',
176
-                'noheader'   => true,
177
-            ),
178
-            'view_report'                   => array(
179
-                'func'      => '_view_report',
180
-                'capablity' => 'ee_edit_events',
181
-            ),
182
-            'default_event_settings'        => array(
183
-                'func'       => '_default_event_settings',
184
-                'capability' => 'manage_options',
185
-            ),
186
-            'update_default_event_settings' => array(
187
-                'func'       => '_update_default_event_settings',
188
-                'capability' => 'manage_options',
189
-                'noheader'   => true,
190
-            ),
191
-            'template_settings'             => array(
192
-                'func'       => '_template_settings',
193
-                'capability' => 'manage_options',
194
-            ),
195
-            // event category tab related
196
-            'add_category'                  => array(
197
-                'func'       => '_category_details',
198
-                'capability' => 'ee_edit_event_category',
199
-                'args'       => array('add'),
200
-            ),
201
-            'edit_category'                 => array(
202
-                'func'       => '_category_details',
203
-                'capability' => 'ee_edit_event_category',
204
-                'args'       => array('edit'),
205
-            ),
206
-            'delete_categories'             => array(
207
-                'func'       => '_delete_categories',
208
-                'capability' => 'ee_delete_event_category',
209
-                'noheader'   => true,
210
-            ),
211
-            'delete_category'               => array(
212
-                'func'       => '_delete_categories',
213
-                'capability' => 'ee_delete_event_category',
214
-                'noheader'   => true,
215
-            ),
216
-            'insert_category'               => array(
217
-                'func'       => '_insert_or_update_category',
218
-                'args'       => array('new_category' => true),
219
-                'capability' => 'ee_edit_event_category',
220
-                'noheader'   => true,
221
-            ),
222
-            'update_category'               => array(
223
-                'func'       => '_insert_or_update_category',
224
-                'args'       => array('new_category' => false),
225
-                'capability' => 'ee_edit_event_category',
226
-                'noheader'   => true,
227
-            ),
228
-            'category_list'                 => array(
229
-                'func'       => '_category_list_table',
230
-                'capability' => 'ee_manage_event_categories',
231
-            ),
232
-            'preview_deletion' => [
233
-                'func' => 'previewDeletion',
234
-                'capability' => 'ee_delete_events'
235
-            ],
236
-            'confirm_deletion' => [
237
-                'func' => 'confirmDeletion',
238
-                'capability' => 'ee_delete_events',
239
-                'noheader' => true
240
-            ]
241
-        );
242
-    }
243
-
244
-
245
-    /**
246
-     * Set the _page_config property for this admin page group.
247
-     */
248
-    protected function _set_page_config()
249
-    {
250
-        $this->_page_config = array(
251
-            'default'                => array(
252
-                'nav'           => array(
253
-                    'label' => esc_html__('Overview', 'event_espresso'),
254
-                    'order' => 10,
255
-                ),
256
-                'list_table'    => 'Events_Admin_List_Table',
257
-                'help_tabs'     => array(
258
-                    'events_overview_help_tab'                       => array(
259
-                        'title'    => esc_html__('Events Overview', 'event_espresso'),
260
-                        'filename' => 'events_overview',
261
-                    ),
262
-                    'events_overview_table_column_headings_help_tab' => array(
263
-                        'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
264
-                        'filename' => 'events_overview_table_column_headings',
265
-                    ),
266
-                    'events_overview_filters_help_tab'               => array(
267
-                        'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
268
-                        'filename' => 'events_overview_filters',
269
-                    ),
270
-                    'events_overview_view_help_tab'                  => array(
271
-                        'title'    => esc_html__('Events Overview Views', 'event_espresso'),
272
-                        'filename' => 'events_overview_views',
273
-                    ),
274
-                    'events_overview_other_help_tab'                 => array(
275
-                        'title'    => esc_html__('Events Overview Other', 'event_espresso'),
276
-                        'filename' => 'events_overview_other',
277
-                    ),
278
-                ),
279
-                'help_tour'     => array(
280
-                    'Event_Overview_Help_Tour',
281
-                    // 'New_Features_Test_Help_Tour' for testing multiple help tour
282
-                ),
283
-                'qtips'         => array(
284
-                    'EE_Event_List_Table_Tips',
285
-                ),
286
-                'require_nonce' => false,
287
-            ),
288
-            'create_new'             => array(
289
-                'nav'           => array(
290
-                    'label'      => esc_html__('Add Event', 'event_espresso'),
291
-                    'order'      => 5,
292
-                    'persistent' => false,
293
-                ),
294
-                'metaboxes'     => array('_register_event_editor_meta_boxes'),
295
-                'help_tabs'     => array(
296
-                    'event_editor_help_tab'                            => array(
297
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
298
-                        'filename' => 'event_editor',
299
-                    ),
300
-                    'event_editor_title_richtexteditor_help_tab'       => array(
301
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
302
-                        'filename' => 'event_editor_title_richtexteditor',
303
-                    ),
304
-                    'event_editor_venue_details_help_tab'              => array(
305
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
306
-                        'filename' => 'event_editor_venue_details',
307
-                    ),
308
-                    'event_editor_event_datetimes_help_tab'            => array(
309
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
310
-                        'filename' => 'event_editor_event_datetimes',
311
-                    ),
312
-                    'event_editor_event_tickets_help_tab'              => array(
313
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
314
-                        'filename' => 'event_editor_event_tickets',
315
-                    ),
316
-                    'event_editor_event_registration_options_help_tab' => array(
317
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
318
-                        'filename' => 'event_editor_event_registration_options',
319
-                    ),
320
-                    'event_editor_tags_categories_help_tab'            => array(
321
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
322
-                        'filename' => 'event_editor_tags_categories',
323
-                    ),
324
-                    'event_editor_questions_registrants_help_tab'      => array(
325
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
326
-                        'filename' => 'event_editor_questions_registrants',
327
-                    ),
328
-                    'event_editor_save_new_event_help_tab'             => array(
329
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
330
-                        'filename' => 'event_editor_save_new_event',
331
-                    ),
332
-                    'event_editor_other_help_tab'                      => array(
333
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
334
-                        'filename' => 'event_editor_other',
335
-                    ),
336
-                ),
337
-                'help_tour'     => array(
338
-                    'Event_Editor_Help_Tour',
339
-                ),
340
-                'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
341
-                'require_nonce' => false,
342
-            ),
343
-            'edit'                   => array(
344
-                'nav'           => array(
345
-                    'label'      => esc_html__('Edit Event', 'event_espresso'),
346
-                    'order'      => 5,
347
-                    'persistent' => false,
348
-                    'url'        => isset($this->_req_data['post'])
349
-                        ? EE_Admin_Page::add_query_args_and_nonce(
350
-                            array('post' => $this->_req_data['post'], 'action' => 'edit'),
351
-                            $this->_current_page_view_url
352
-                        )
353
-                        : $this->_admin_base_url,
354
-                ),
355
-                'metaboxes'     => array('_register_event_editor_meta_boxes'),
356
-                'help_tabs'     => array(
357
-                    'event_editor_help_tab'                            => array(
358
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
359
-                        'filename' => 'event_editor',
360
-                    ),
361
-                    'event_editor_title_richtexteditor_help_tab'       => array(
362
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
363
-                        'filename' => 'event_editor_title_richtexteditor',
364
-                    ),
365
-                    'event_editor_venue_details_help_tab'              => array(
366
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
367
-                        'filename' => 'event_editor_venue_details',
368
-                    ),
369
-                    'event_editor_event_datetimes_help_tab'            => array(
370
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
371
-                        'filename' => 'event_editor_event_datetimes',
372
-                    ),
373
-                    'event_editor_event_tickets_help_tab'              => array(
374
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
375
-                        'filename' => 'event_editor_event_tickets',
376
-                    ),
377
-                    'event_editor_event_registration_options_help_tab' => array(
378
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
379
-                        'filename' => 'event_editor_event_registration_options',
380
-                    ),
381
-                    'event_editor_tags_categories_help_tab'            => array(
382
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
383
-                        'filename' => 'event_editor_tags_categories',
384
-                    ),
385
-                    'event_editor_questions_registrants_help_tab'      => array(
386
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
387
-                        'filename' => 'event_editor_questions_registrants',
388
-                    ),
389
-                    'event_editor_save_new_event_help_tab'             => array(
390
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
391
-                        'filename' => 'event_editor_save_new_event',
392
-                    ),
393
-                    'event_editor_other_help_tab'                      => array(
394
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
395
-                        'filename' => 'event_editor_other',
396
-                    ),
397
-                ),
398
-                'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
399
-                'require_nonce' => false,
400
-            ),
401
-            'default_event_settings' => array(
402
-                'nav'           => array(
403
-                    'label' => esc_html__('Default Settings', 'event_espresso'),
404
-                    'order' => 40,
405
-                ),
406
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
407
-                'labels'        => array(
408
-                    'publishbox' => esc_html__('Update Settings', 'event_espresso'),
409
-                ),
410
-                'help_tabs'     => array(
411
-                    'default_settings_help_tab'        => array(
412
-                        'title'    => esc_html__('Default Event Settings', 'event_espresso'),
413
-                        'filename' => 'events_default_settings',
414
-                    ),
415
-                    'default_settings_status_help_tab' => array(
416
-                        'title'    => esc_html__('Default Registration Status', 'event_espresso'),
417
-                        'filename' => 'events_default_settings_status',
418
-                    ),
419
-                    'default_maximum_tickets_help_tab' => array(
420
-                        'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
421
-                        'filename' => 'events_default_settings_max_tickets',
422
-                    ),
423
-                ),
424
-                'help_tour'     => array('Event_Default_Settings_Help_Tour'),
425
-                'require_nonce' => false,
426
-            ),
427
-            // template settings
428
-            'template_settings'      => array(
429
-                'nav'           => array(
430
-                    'label' => esc_html__('Templates', 'event_espresso'),
431
-                    'order' => 30,
432
-                ),
433
-                'metaboxes'     => $this->_default_espresso_metaboxes,
434
-                'help_tabs'     => array(
435
-                    'general_settings_templates_help_tab' => array(
436
-                        'title'    => esc_html__('Templates', 'event_espresso'),
437
-                        'filename' => 'general_settings_templates',
438
-                    ),
439
-                ),
440
-                'help_tour'     => array('Templates_Help_Tour'),
441
-                'require_nonce' => false,
442
-            ),
443
-            // event category stuff
444
-            'add_category'           => array(
445
-                'nav'           => array(
446
-                    'label'      => esc_html__('Add Category', 'event_espresso'),
447
-                    'order'      => 15,
448
-                    'persistent' => false,
449
-                ),
450
-                'help_tabs'     => array(
451
-                    'add_category_help_tab' => array(
452
-                        'title'    => esc_html__('Add New Event Category', 'event_espresso'),
453
-                        'filename' => 'events_add_category',
454
-                    ),
455
-                ),
456
-                'help_tour'     => array('Event_Add_Category_Help_Tour'),
457
-                'metaboxes'     => array('_publish_post_box'),
458
-                'require_nonce' => false,
459
-            ),
460
-            'edit_category'          => array(
461
-                'nav'           => array(
462
-                    'label'      => esc_html__('Edit Category', 'event_espresso'),
463
-                    'order'      => 15,
464
-                    'persistent' => false,
465
-                    'url'        => isset($this->_req_data['EVT_CAT_ID'])
466
-                        ? add_query_arg(
467
-                            array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']),
468
-                            $this->_current_page_view_url
469
-                        )
470
-                        : $this->_admin_base_url,
471
-                ),
472
-                'help_tabs'     => array(
473
-                    'edit_category_help_tab' => array(
474
-                        'title'    => esc_html__('Edit Event Category', 'event_espresso'),
475
-                        'filename' => 'events_edit_category',
476
-                    ),
477
-                ),
478
-                /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/
479
-                'metaboxes'     => array('_publish_post_box'),
480
-                'require_nonce' => false,
481
-            ),
482
-            'category_list'          => array(
483
-                'nav'           => array(
484
-                    'label' => esc_html__('Categories', 'event_espresso'),
485
-                    'order' => 20,
486
-                ),
487
-                'list_table'    => 'Event_Categories_Admin_List_Table',
488
-                'help_tabs'     => array(
489
-                    'events_categories_help_tab'                       => array(
490
-                        'title'    => esc_html__('Event Categories', 'event_espresso'),
491
-                        'filename' => 'events_categories',
492
-                    ),
493
-                    'events_categories_table_column_headings_help_tab' => array(
494
-                        'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
495
-                        'filename' => 'events_categories_table_column_headings',
496
-                    ),
497
-                    'events_categories_view_help_tab'                  => array(
498
-                        'title'    => esc_html__('Event Categories Views', 'event_espresso'),
499
-                        'filename' => 'events_categories_views',
500
-                    ),
501
-                    'events_categories_other_help_tab'                 => array(
502
-                        'title'    => esc_html__('Event Categories Other', 'event_espresso'),
503
-                        'filename' => 'events_categories_other',
504
-                    ),
505
-                ),
506
-                'help_tour'     => array(
507
-                    'Event_Categories_Help_Tour',
508
-                ),
509
-                'metaboxes'     => $this->_default_espresso_metaboxes,
510
-                'require_nonce' => false,
511
-            ),
512
-            'preview_deletion'           => array(
513
-                'nav'           => array(
514
-                    'label'      => esc_html__('Preview Deletion', 'event_espresso'),
515
-                    'order'      => 15,
516
-                    'persistent' => false,
517
-                ),
15
+	/**
16
+	 * This will hold the event object for event_details screen.
17
+	 *
18
+	 * @access protected
19
+	 * @var EE_Event $_event
20
+	 */
21
+	protected $_event;
22
+
23
+
24
+	/**
25
+	 * This will hold the category object for category_details screen.
26
+	 *
27
+	 * @var stdClass $_category
28
+	 */
29
+	protected $_category;
30
+
31
+
32
+	/**
33
+	 * This will hold the event model instance
34
+	 *
35
+	 * @var EEM_Event $_event_model
36
+	 */
37
+	protected $_event_model;
38
+
39
+
40
+	/**
41
+	 * @var EE_Event
42
+	 */
43
+	protected $_cpt_model_obj = false;
44
+
45
+
46
+	/**
47
+	 * Initialize page props for this admin page group.
48
+	 */
49
+	protected function _init_page_props()
50
+	{
51
+		$this->page_slug = EVENTS_PG_SLUG;
52
+		$this->page_label = EVENTS_LABEL;
53
+		$this->_admin_base_url = EVENTS_ADMIN_URL;
54
+		$this->_admin_base_path = EVENTS_ADMIN;
55
+		$this->_cpt_model_names = array(
56
+			'create_new' => 'EEM_Event',
57
+			'edit'       => 'EEM_Event',
58
+		);
59
+		$this->_cpt_edit_routes = array(
60
+			'espresso_events' => 'edit',
61
+		);
62
+		add_action(
63
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
64
+			array($this, 'verify_event_edit'),
65
+			10,
66
+			2
67
+		);
68
+	}
69
+
70
+
71
+	/**
72
+	 * Sets the ajax hooks used for this admin page group.
73
+	 */
74
+	protected function _ajax_hooks()
75
+	{
76
+		add_action('wp_ajax_ee_save_timezone_setting', array($this, 'save_timezonestring_setting'));
77
+	}
78
+
79
+
80
+	/**
81
+	 * Sets the page properties for this admin page group.
82
+	 */
83
+	protected function _define_page_props()
84
+	{
85
+		$this->_admin_page_title = EVENTS_LABEL;
86
+		$this->_labels = array(
87
+			'buttons'      => array(
88
+				'add'             => esc_html__('Add New Event', 'event_espresso'),
89
+				'edit'            => esc_html__('Edit Event', 'event_espresso'),
90
+				'delete'          => esc_html__('Delete Event', 'event_espresso'),
91
+				'add_category'    => esc_html__('Add New Category', 'event_espresso'),
92
+				'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
93
+				'delete_category' => esc_html__('Delete Category', 'event_espresso'),
94
+			),
95
+			'editor_title' => array(
96
+				'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
97
+			),
98
+			'publishbox'   => array(
99
+				'create_new'        => esc_html__('Save New Event', 'event_espresso'),
100
+				'edit'              => esc_html__('Update Event', 'event_espresso'),
101
+				'add_category'      => esc_html__('Save New Category', 'event_espresso'),
102
+				'edit_category'     => esc_html__('Update Category', 'event_espresso'),
103
+				'template_settings' => esc_html__('Update Settings', 'event_espresso'),
104
+			),
105
+		);
106
+	}
107
+
108
+
109
+	/**
110
+	 * Sets the page routes property for this admin page group.
111
+	 */
112
+	protected function _set_page_routes()
113
+	{
114
+		// load formatter helper
115
+		// load field generator helper
116
+		// is there a evt_id in the request?
117
+		$evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
118
+			? $this->_req_data['EVT_ID']
119
+			: 0;
120
+		$evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
121
+		$this->_page_routes = array(
122
+			'default'                       => array(
123
+				'func'       => '_events_overview_list_table',
124
+				'capability' => 'ee_read_events',
125
+			),
126
+			'create_new'                    => array(
127
+				'func'       => '_create_new_cpt_item',
128
+				'capability' => 'ee_edit_events',
129
+			),
130
+			'edit'                          => array(
131
+				'func'       => '_edit_cpt_item',
132
+				'capability' => 'ee_edit_event',
133
+				'obj_id'     => $evt_id,
134
+			),
135
+			'copy_event'                    => array(
136
+				'func'       => '_copy_events',
137
+				'capability' => 'ee_edit_event',
138
+				'obj_id'     => $evt_id,
139
+				'noheader'   => true,
140
+			),
141
+			'trash_event'                   => array(
142
+				'func'       => '_trash_or_restore_event',
143
+				'args'       => array('event_status' => 'trash'),
144
+				'capability' => 'ee_delete_event',
145
+				'obj_id'     => $evt_id,
146
+				'noheader'   => true,
147
+			),
148
+			'trash_events'                  => array(
149
+				'func'       => '_trash_or_restore_events',
150
+				'args'       => array('event_status' => 'trash'),
151
+				'capability' => 'ee_delete_events',
152
+				'noheader'   => true,
153
+			),
154
+			'restore_event'                 => array(
155
+				'func'       => '_trash_or_restore_event',
156
+				'args'       => array('event_status' => 'draft'),
157
+				'capability' => 'ee_delete_event',
158
+				'obj_id'     => $evt_id,
159
+				'noheader'   => true,
160
+			),
161
+			'restore_events'                => array(
162
+				'func'       => '_trash_or_restore_events',
163
+				'args'       => array('event_status' => 'draft'),
164
+				'capability' => 'ee_delete_events',
165
+				'noheader'   => true,
166
+			),
167
+			'delete_event'                  => array(
168
+				'func'       => '_delete_event',
169
+				'capability' => 'ee_delete_event',
170
+				'obj_id'     => $evt_id,
171
+				'noheader'   => true,
172
+			),
173
+			'delete_events'                 => array(
174
+				'func'       => '_delete_events',
175
+				'capability' => 'ee_delete_events',
176
+				'noheader'   => true,
177
+			),
178
+			'view_report'                   => array(
179
+				'func'      => '_view_report',
180
+				'capablity' => 'ee_edit_events',
181
+			),
182
+			'default_event_settings'        => array(
183
+				'func'       => '_default_event_settings',
184
+				'capability' => 'manage_options',
185
+			),
186
+			'update_default_event_settings' => array(
187
+				'func'       => '_update_default_event_settings',
188
+				'capability' => 'manage_options',
189
+				'noheader'   => true,
190
+			),
191
+			'template_settings'             => array(
192
+				'func'       => '_template_settings',
193
+				'capability' => 'manage_options',
194
+			),
195
+			// event category tab related
196
+			'add_category'                  => array(
197
+				'func'       => '_category_details',
198
+				'capability' => 'ee_edit_event_category',
199
+				'args'       => array('add'),
200
+			),
201
+			'edit_category'                 => array(
202
+				'func'       => '_category_details',
203
+				'capability' => 'ee_edit_event_category',
204
+				'args'       => array('edit'),
205
+			),
206
+			'delete_categories'             => array(
207
+				'func'       => '_delete_categories',
208
+				'capability' => 'ee_delete_event_category',
209
+				'noheader'   => true,
210
+			),
211
+			'delete_category'               => array(
212
+				'func'       => '_delete_categories',
213
+				'capability' => 'ee_delete_event_category',
214
+				'noheader'   => true,
215
+			),
216
+			'insert_category'               => array(
217
+				'func'       => '_insert_or_update_category',
218
+				'args'       => array('new_category' => true),
219
+				'capability' => 'ee_edit_event_category',
220
+				'noheader'   => true,
221
+			),
222
+			'update_category'               => array(
223
+				'func'       => '_insert_or_update_category',
224
+				'args'       => array('new_category' => false),
225
+				'capability' => 'ee_edit_event_category',
226
+				'noheader'   => true,
227
+			),
228
+			'category_list'                 => array(
229
+				'func'       => '_category_list_table',
230
+				'capability' => 'ee_manage_event_categories',
231
+			),
232
+			'preview_deletion' => [
233
+				'func' => 'previewDeletion',
234
+				'capability' => 'ee_delete_events'
235
+			],
236
+			'confirm_deletion' => [
237
+				'func' => 'confirmDeletion',
238
+				'capability' => 'ee_delete_events',
239
+				'noheader' => true
240
+			]
241
+		);
242
+	}
243
+
244
+
245
+	/**
246
+	 * Set the _page_config property for this admin page group.
247
+	 */
248
+	protected function _set_page_config()
249
+	{
250
+		$this->_page_config = array(
251
+			'default'                => array(
252
+				'nav'           => array(
253
+					'label' => esc_html__('Overview', 'event_espresso'),
254
+					'order' => 10,
255
+				),
256
+				'list_table'    => 'Events_Admin_List_Table',
257
+				'help_tabs'     => array(
258
+					'events_overview_help_tab'                       => array(
259
+						'title'    => esc_html__('Events Overview', 'event_espresso'),
260
+						'filename' => 'events_overview',
261
+					),
262
+					'events_overview_table_column_headings_help_tab' => array(
263
+						'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
264
+						'filename' => 'events_overview_table_column_headings',
265
+					),
266
+					'events_overview_filters_help_tab'               => array(
267
+						'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
268
+						'filename' => 'events_overview_filters',
269
+					),
270
+					'events_overview_view_help_tab'                  => array(
271
+						'title'    => esc_html__('Events Overview Views', 'event_espresso'),
272
+						'filename' => 'events_overview_views',
273
+					),
274
+					'events_overview_other_help_tab'                 => array(
275
+						'title'    => esc_html__('Events Overview Other', 'event_espresso'),
276
+						'filename' => 'events_overview_other',
277
+					),
278
+				),
279
+				'help_tour'     => array(
280
+					'Event_Overview_Help_Tour',
281
+					// 'New_Features_Test_Help_Tour' for testing multiple help tour
282
+				),
283
+				'qtips'         => array(
284
+					'EE_Event_List_Table_Tips',
285
+				),
286
+				'require_nonce' => false,
287
+			),
288
+			'create_new'             => array(
289
+				'nav'           => array(
290
+					'label'      => esc_html__('Add Event', 'event_espresso'),
291
+					'order'      => 5,
292
+					'persistent' => false,
293
+				),
294
+				'metaboxes'     => array('_register_event_editor_meta_boxes'),
295
+				'help_tabs'     => array(
296
+					'event_editor_help_tab'                            => array(
297
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
298
+						'filename' => 'event_editor',
299
+					),
300
+					'event_editor_title_richtexteditor_help_tab'       => array(
301
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
302
+						'filename' => 'event_editor_title_richtexteditor',
303
+					),
304
+					'event_editor_venue_details_help_tab'              => array(
305
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
306
+						'filename' => 'event_editor_venue_details',
307
+					),
308
+					'event_editor_event_datetimes_help_tab'            => array(
309
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
310
+						'filename' => 'event_editor_event_datetimes',
311
+					),
312
+					'event_editor_event_tickets_help_tab'              => array(
313
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
314
+						'filename' => 'event_editor_event_tickets',
315
+					),
316
+					'event_editor_event_registration_options_help_tab' => array(
317
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
318
+						'filename' => 'event_editor_event_registration_options',
319
+					),
320
+					'event_editor_tags_categories_help_tab'            => array(
321
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
322
+						'filename' => 'event_editor_tags_categories',
323
+					),
324
+					'event_editor_questions_registrants_help_tab'      => array(
325
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
326
+						'filename' => 'event_editor_questions_registrants',
327
+					),
328
+					'event_editor_save_new_event_help_tab'             => array(
329
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
330
+						'filename' => 'event_editor_save_new_event',
331
+					),
332
+					'event_editor_other_help_tab'                      => array(
333
+						'title'    => esc_html__('Event Other', 'event_espresso'),
334
+						'filename' => 'event_editor_other',
335
+					),
336
+				),
337
+				'help_tour'     => array(
338
+					'Event_Editor_Help_Tour',
339
+				),
340
+				'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
341
+				'require_nonce' => false,
342
+			),
343
+			'edit'                   => array(
344
+				'nav'           => array(
345
+					'label'      => esc_html__('Edit Event', 'event_espresso'),
346
+					'order'      => 5,
347
+					'persistent' => false,
348
+					'url'        => isset($this->_req_data['post'])
349
+						? EE_Admin_Page::add_query_args_and_nonce(
350
+							array('post' => $this->_req_data['post'], 'action' => 'edit'),
351
+							$this->_current_page_view_url
352
+						)
353
+						: $this->_admin_base_url,
354
+				),
355
+				'metaboxes'     => array('_register_event_editor_meta_boxes'),
356
+				'help_tabs'     => array(
357
+					'event_editor_help_tab'                            => array(
358
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
359
+						'filename' => 'event_editor',
360
+					),
361
+					'event_editor_title_richtexteditor_help_tab'       => array(
362
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
363
+						'filename' => 'event_editor_title_richtexteditor',
364
+					),
365
+					'event_editor_venue_details_help_tab'              => array(
366
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
367
+						'filename' => 'event_editor_venue_details',
368
+					),
369
+					'event_editor_event_datetimes_help_tab'            => array(
370
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
371
+						'filename' => 'event_editor_event_datetimes',
372
+					),
373
+					'event_editor_event_tickets_help_tab'              => array(
374
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
375
+						'filename' => 'event_editor_event_tickets',
376
+					),
377
+					'event_editor_event_registration_options_help_tab' => array(
378
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
379
+						'filename' => 'event_editor_event_registration_options',
380
+					),
381
+					'event_editor_tags_categories_help_tab'            => array(
382
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
383
+						'filename' => 'event_editor_tags_categories',
384
+					),
385
+					'event_editor_questions_registrants_help_tab'      => array(
386
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
387
+						'filename' => 'event_editor_questions_registrants',
388
+					),
389
+					'event_editor_save_new_event_help_tab'             => array(
390
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
391
+						'filename' => 'event_editor_save_new_event',
392
+					),
393
+					'event_editor_other_help_tab'                      => array(
394
+						'title'    => esc_html__('Event Other', 'event_espresso'),
395
+						'filename' => 'event_editor_other',
396
+					),
397
+				),
398
+				'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
399
+				'require_nonce' => false,
400
+			),
401
+			'default_event_settings' => array(
402
+				'nav'           => array(
403
+					'label' => esc_html__('Default Settings', 'event_espresso'),
404
+					'order' => 40,
405
+				),
406
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
407
+				'labels'        => array(
408
+					'publishbox' => esc_html__('Update Settings', 'event_espresso'),
409
+				),
410
+				'help_tabs'     => array(
411
+					'default_settings_help_tab'        => array(
412
+						'title'    => esc_html__('Default Event Settings', 'event_espresso'),
413
+						'filename' => 'events_default_settings',
414
+					),
415
+					'default_settings_status_help_tab' => array(
416
+						'title'    => esc_html__('Default Registration Status', 'event_espresso'),
417
+						'filename' => 'events_default_settings_status',
418
+					),
419
+					'default_maximum_tickets_help_tab' => array(
420
+						'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
421
+						'filename' => 'events_default_settings_max_tickets',
422
+					),
423
+				),
424
+				'help_tour'     => array('Event_Default_Settings_Help_Tour'),
425
+				'require_nonce' => false,
426
+			),
427
+			// template settings
428
+			'template_settings'      => array(
429
+				'nav'           => array(
430
+					'label' => esc_html__('Templates', 'event_espresso'),
431
+					'order' => 30,
432
+				),
433
+				'metaboxes'     => $this->_default_espresso_metaboxes,
434
+				'help_tabs'     => array(
435
+					'general_settings_templates_help_tab' => array(
436
+						'title'    => esc_html__('Templates', 'event_espresso'),
437
+						'filename' => 'general_settings_templates',
438
+					),
439
+				),
440
+				'help_tour'     => array('Templates_Help_Tour'),
441
+				'require_nonce' => false,
442
+			),
443
+			// event category stuff
444
+			'add_category'           => array(
445
+				'nav'           => array(
446
+					'label'      => esc_html__('Add Category', 'event_espresso'),
447
+					'order'      => 15,
448
+					'persistent' => false,
449
+				),
450
+				'help_tabs'     => array(
451
+					'add_category_help_tab' => array(
452
+						'title'    => esc_html__('Add New Event Category', 'event_espresso'),
453
+						'filename' => 'events_add_category',
454
+					),
455
+				),
456
+				'help_tour'     => array('Event_Add_Category_Help_Tour'),
457
+				'metaboxes'     => array('_publish_post_box'),
458
+				'require_nonce' => false,
459
+			),
460
+			'edit_category'          => array(
461
+				'nav'           => array(
462
+					'label'      => esc_html__('Edit Category', 'event_espresso'),
463
+					'order'      => 15,
464
+					'persistent' => false,
465
+					'url'        => isset($this->_req_data['EVT_CAT_ID'])
466
+						? add_query_arg(
467
+							array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']),
468
+							$this->_current_page_view_url
469
+						)
470
+						: $this->_admin_base_url,
471
+				),
472
+				'help_tabs'     => array(
473
+					'edit_category_help_tab' => array(
474
+						'title'    => esc_html__('Edit Event Category', 'event_espresso'),
475
+						'filename' => 'events_edit_category',
476
+					),
477
+				),
478
+				/*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/
479
+				'metaboxes'     => array('_publish_post_box'),
480
+				'require_nonce' => false,
481
+			),
482
+			'category_list'          => array(
483
+				'nav'           => array(
484
+					'label' => esc_html__('Categories', 'event_espresso'),
485
+					'order' => 20,
486
+				),
487
+				'list_table'    => 'Event_Categories_Admin_List_Table',
488
+				'help_tabs'     => array(
489
+					'events_categories_help_tab'                       => array(
490
+						'title'    => esc_html__('Event Categories', 'event_espresso'),
491
+						'filename' => 'events_categories',
492
+					),
493
+					'events_categories_table_column_headings_help_tab' => array(
494
+						'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
495
+						'filename' => 'events_categories_table_column_headings',
496
+					),
497
+					'events_categories_view_help_tab'                  => array(
498
+						'title'    => esc_html__('Event Categories Views', 'event_espresso'),
499
+						'filename' => 'events_categories_views',
500
+					),
501
+					'events_categories_other_help_tab'                 => array(
502
+						'title'    => esc_html__('Event Categories Other', 'event_espresso'),
503
+						'filename' => 'events_categories_other',
504
+					),
505
+				),
506
+				'help_tour'     => array(
507
+					'Event_Categories_Help_Tour',
508
+				),
509
+				'metaboxes'     => $this->_default_espresso_metaboxes,
510
+				'require_nonce' => false,
511
+			),
512
+			'preview_deletion'           => array(
513
+				'nav'           => array(
514
+					'label'      => esc_html__('Preview Deletion', 'event_espresso'),
515
+					'order'      => 15,
516
+					'persistent' => false,
517
+				),
518 518
 //                'help_tabs'     => array(
519 519
 //                    'add_category_help_tab' => array(
520 520
 //                        'title'    => esc_html__('Add New Event Category', 'event_espresso'),
@@ -524,2195 +524,2195 @@  discard block
 block discarded – undo
524 524
 //                'help_tour'     => array('Event_Add_Category_Help_Tour'),
525 525
 //                'metaboxes'     => array('_publish_post_box'),
526 526
 //                'require_nonce' => false,
527
-            )
528
-        );
529
-    }
530
-
531
-
532
-    /**
533
-     * Used to register any global screen options if necessary for every route in this admin page group.
534
-     */
535
-    protected function _add_screen_options()
536
-    {
537
-    }
538
-
539
-
540
-    /**
541
-     * Implementing the screen options for the 'default' route.
542
-     */
543
-    protected function _add_screen_options_default()
544
-    {
545
-        $this->_per_page_screen_option();
546
-    }
547
-
548
-
549
-    /**
550
-     * Implementing screen options for the category list route.
551
-     */
552
-    protected function _add_screen_options_category_list()
553
-    {
554
-        $page_title = $this->_admin_page_title;
555
-        $this->_admin_page_title = esc_html__('Categories', 'event_espresso');
556
-        $this->_per_page_screen_option();
557
-        $this->_admin_page_title = $page_title;
558
-    }
559
-
560
-
561
-    /**
562
-     * Used to register any global feature pointers for the admin page group.
563
-     */
564
-    protected function _add_feature_pointers()
565
-    {
566
-    }
567
-
568
-
569
-    /**
570
-     * Registers and enqueues any global scripts and styles for the entire admin page group.
571
-     */
572
-    public function load_scripts_styles()
573
-    {
574
-        wp_register_style(
575
-            'events-admin-css',
576
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
577
-            array(),
578
-            EVENT_ESPRESSO_VERSION
579
-        );
580
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
581
-        wp_enqueue_style('events-admin-css');
582
-        wp_enqueue_style('ee-cat-admin');
583
-        // todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
584
-        // registers for all views
585
-        // scripts
586
-        wp_register_script(
587
-            'event_editor_js',
588
-            EVENTS_ASSETS_URL . 'event_editor.js',
589
-            array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
590
-            EVENT_ESPRESSO_VERSION,
591
-            true
592
-        );
593
-    }
594
-
595
-
596
-    /**
597
-     * Enqueuing scripts and styles specific to this view
598
-     */
599
-    public function load_scripts_styles_create_new()
600
-    {
601
-        $this->load_scripts_styles_edit();
602
-    }
603
-
604
-
605
-    /**
606
-     * Enqueuing scripts and styles specific to this view
607
-     */
608
-    public function load_scripts_styles_edit()
609
-    {
610
-        // styles
611
-        wp_enqueue_style('espresso-ui-theme');
612
-        wp_register_style(
613
-            'event-editor-css',
614
-            EVENTS_ASSETS_URL . 'event-editor.css',
615
-            array('ee-admin-css'),
616
-            EVENT_ESPRESSO_VERSION
617
-        );
618
-        wp_enqueue_style('event-editor-css');
619
-        // scripts
620
-        wp_register_script(
621
-            'event-datetime-metabox',
622
-            EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
623
-            array('event_editor_js', 'ee-datepicker'),
624
-            EVENT_ESPRESSO_VERSION
625
-        );
626
-        wp_enqueue_script('event-datetime-metabox');
627
-    }
628
-
629
-
630
-    /**
631
-     * Populating the _views property for the category list table view.
632
-     */
633
-    protected function _set_list_table_views_category_list()
634
-    {
635
-        $this->_views = array(
636
-            'all' => array(
637
-                'slug'        => 'all',
638
-                'label'       => esc_html__('All', 'event_espresso'),
639
-                'count'       => 0,
640
-                'bulk_action' => array(
641
-                    'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
642
-                ),
643
-            ),
644
-        );
645
-    }
646
-
647
-
648
-    /**
649
-     * For adding anything that fires on the admin_init hook for any route within this admin page group.
650
-     */
651
-    public function admin_init()
652
-    {
653
-        EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
654
-            'Do you really want to delete this image? Please remember to update your event to complete the removal.',
655
-            'event_espresso'
656
-        );
657
-    }
658
-
659
-
660
-    /**
661
-     * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
662
-     * group.
663
-     */
664
-    public function admin_notices()
665
-    {
666
-    }
667
-
668
-
669
-    /**
670
-     * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
671
-     * this admin page group.
672
-     */
673
-    public function admin_footer_scripts()
674
-    {
675
-    }
676
-
677
-
678
-    /**
679
-     * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
680
-     * warning (via EE_Error::add_error());
681
-     *
682
-     * @param  EE_Event $event Event object
683
-     * @param string    $req_type
684
-     * @return void
685
-     * @throws EE_Error
686
-     * @access public
687
-     */
688
-    public function verify_event_edit($event = null, $req_type = '')
689
-    {
690
-        // don't need to do this when processing
691
-        if (! empty($req_type)) {
692
-            return;
693
-        }
694
-        // no event?
695
-        if (empty($event)) {
696
-            // set event
697
-            $event = $this->_cpt_model_obj;
698
-        }
699
-        // STILL no event?
700
-        if (! $event instanceof EE_Event) {
701
-            return;
702
-        }
703
-        $orig_status = $event->status();
704
-        // first check if event is active.
705
-        if ($orig_status === EEM_Event::cancelled
706
-            || $orig_status === EEM_Event::postponed
707
-            || $event->is_expired()
708
-            || $event->is_inactive()
709
-        ) {
710
-            return;
711
-        }
712
-        // made it here so it IS active... next check that any of the tickets are sold.
713
-        if ($event->is_sold_out(true)) {
714
-            if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
715
-                EE_Error::add_attention(
716
-                    sprintf(
717
-                        esc_html__(
718
-                            '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.',
719
-                            'event_espresso'
720
-                        ),
721
-                        EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
722
-                    )
723
-                );
724
-            }
725
-            return;
726
-        } elseif ($orig_status === EEM_Event::sold_out) {
727
-            EE_Error::add_attention(
728
-                sprintf(
729
-                    esc_html__(
730
-                        '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.',
731
-                        'event_espresso'
732
-                    ),
733
-                    EEH_Template::pretty_status($event->status(), false, 'sentence')
734
-                )
735
-            );
736
-        }
737
-        // now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
738
-        if (! $event->tickets_on_sale()) {
739
-            return;
740
-        }
741
-        // made it here so show warning
742
-        $this->_edit_event_warning();
743
-    }
744
-
745
-
746
-    /**
747
-     * This is the text used for when an event is being edited that is public and has tickets for sale.
748
-     * When needed, hook this into a EE_Error::add_error() notice.
749
-     *
750
-     * @access protected
751
-     * @return void
752
-     */
753
-    protected function _edit_event_warning()
754
-    {
755
-        // we don't want to add warnings during these requests
756
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
757
-            return;
758
-        }
759
-        EE_Error::add_attention(
760
-            sprintf(
761
-                esc_html__(
762
-                    'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
763
-                    'event_espresso'
764
-                ),
765
-                '<a class="espresso-help-tab-lnk">',
766
-                '</a>'
767
-            )
768
-        );
769
-    }
770
-
771
-
772
-    /**
773
-     * When a user is creating a new event, notify them if they haven't set their timezone.
774
-     * Otherwise, do the normal logic
775
-     *
776
-     * @return string
777
-     * @throws \EE_Error
778
-     */
779
-    protected function _create_new_cpt_item()
780
-    {
781
-        $has_timezone_string = get_option('timezone_string');
782
-        // only nag them about setting their timezone if it's their first event, and they haven't already done it
783
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) {
784
-            EE_Error::add_attention(
785
-                sprintf(
786
-                    __(
787
-                        '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',
788
-                        'event_espresso'
789
-                    ),
790
-                    '<br>',
791
-                    '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
792
-                    . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
793
-                    . '</select>',
794
-                    '<button class="button button-secondary timezone-submit">',
795
-                    '</button><span class="spinner"></span>'
796
-                ),
797
-                __FILE__,
798
-                __FUNCTION__,
799
-                __LINE__
800
-            );
801
-        }
802
-        return parent::_create_new_cpt_item();
803
-    }
804
-
805
-
806
-    /**
807
-     * Sets the _views property for the default route in this admin page group.
808
-     */
809
-    protected function _set_list_table_views_default()
810
-    {
811
-        $this->_views = array(
812
-            'all'   => array(
813
-                'slug'        => 'all',
814
-                'label'       => esc_html__('View All Events', 'event_espresso'),
815
-                'count'       => 0,
816
-                'bulk_action' => array(
817
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
818
-                ),
819
-            ),
820
-            'draft' => array(
821
-                'slug'        => 'draft',
822
-                'label'       => esc_html__('Draft', 'event_espresso'),
823
-                'count'       => 0,
824
-                'bulk_action' => array(
825
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
826
-                ),
827
-            ),
828
-        );
829
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
830
-            $this->_views['trash'] = array(
831
-                'slug'        => 'trash',
832
-                'label'       => esc_html__('Trash', 'event_espresso'),
833
-                'count'       => 0,
834
-                'bulk_action' => array(
835
-                    'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
836
-                    'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
837
-                ),
838
-            );
839
-        }
840
-    }
841
-
842
-
843
-    /**
844
-     * Provides the legend item array for the default list table view.
845
-     *
846
-     * @return array
847
-     */
848
-    protected function _event_legend_items()
849
-    {
850
-        $items = array(
851
-            'view_details'   => array(
852
-                'class' => 'dashicons dashicons-search',
853
-                'desc'  => esc_html__('View Event', 'event_espresso'),
854
-            ),
855
-            'edit_event'     => array(
856
-                'class' => 'ee-icon ee-icon-calendar-edit',
857
-                'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
858
-            ),
859
-            'view_attendees' => array(
860
-                'class' => 'dashicons dashicons-groups',
861
-                'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
862
-            ),
863
-        );
864
-        $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
865
-        $statuses = array(
866
-            'sold_out_status'  => array(
867
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
868
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
869
-            ),
870
-            'active_status'    => array(
871
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
872
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
873
-            ),
874
-            'upcoming_status'  => array(
875
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
876
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
877
-            ),
878
-            'postponed_status' => array(
879
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
880
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
881
-            ),
882
-            'cancelled_status' => array(
883
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
884
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
885
-            ),
886
-            'expired_status'   => array(
887
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
888
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
889
-            ),
890
-            'inactive_status'  => array(
891
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
892
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
893
-            ),
894
-        );
895
-        $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
896
-        return array_merge($items, $statuses);
897
-    }
898
-
899
-
900
-    /**
901
-     * @return EEM_Event
902
-     */
903
-    private function _event_model()
904
-    {
905
-        if (! $this->_event_model instanceof EEM_Event) {
906
-            $this->_event_model = EE_Registry::instance()->load_model('Event');
907
-        }
908
-        return $this->_event_model;
909
-    }
910
-
911
-
912
-    /**
913
-     * Adds extra buttons to the WP CPT permalink field row.
914
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
915
-     *
916
-     * @param  string $return    the current html
917
-     * @param  int    $id        the post id for the page
918
-     * @param  string $new_title What the title is
919
-     * @param  string $new_slug  what the slug is
920
-     * @return string            The new html string for the permalink area
921
-     */
922
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
923
-    {
924
-        // make sure this is only when editing
925
-        if (! empty($id)) {
926
-            $post = get_post($id);
927
-            $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
928
-                       . esc_html__('Shortcode', 'event_espresso')
929
-                       . '</a> ';
930
-            $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
931
-                       . $post->ID
932
-                       . ']">';
933
-        }
934
-        return $return;
935
-    }
936
-
937
-
938
-    /**
939
-     * _events_overview_list_table
940
-     * This contains the logic for showing the events_overview list
941
-     *
942
-     * @access protected
943
-     * @return void
944
-     * @throws \EE_Error
945
-     */
946
-    protected function _events_overview_list_table()
947
-    {
948
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
949
-        $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table'])
950
-            ? (array) $this->_template_args['after_list_table']
951
-            : array();
952
-        $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
953
-                . EEH_Template::get_button_or_link(
954
-                    get_post_type_archive_link('espresso_events'),
955
-                    esc_html__("View Event Archive Page", "event_espresso"),
956
-                    'button'
957
-                );
958
-        $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
959
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
960
-            'create_new',
961
-            'add',
962
-            array(),
963
-            'add-new-h2'
964
-        );
965
-        $this->display_admin_list_table_page_with_no_sidebar();
966
-    }
967
-
968
-
969
-    /**
970
-     * this allows for extra misc actions in the default WP publish box
971
-     *
972
-     * @return void
973
-     */
974
-    public function extra_misc_actions_publish_box()
975
-    {
976
-        $this->_generate_publish_box_extra_content();
977
-    }
978
-
979
-
980
-    /**
981
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
982
-     * saved.
983
-     * Typically you would use this to save any additional data.
984
-     * Keep in mind also that "save_post" runs on EVERY post update to the database.
985
-     * ALSO very important.  When a post transitions from scheduled to published,
986
-     * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
987
-     * other meta saves. So MAKE sure that you handle this accordingly.
988
-     *
989
-     * @access protected
990
-     * @abstract
991
-     * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
992
-     * @param  object $post    The post object of the cpt that was saved.
993
-     * @return void
994
-     * @throws \EE_Error
995
-     */
996
-    protected function _insert_update_cpt_item($post_id, $post)
997
-    {
998
-        if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
999
-            // get out we're not processing an event save.
1000
-            return;
1001
-        }
1002
-        $event_values = array(
1003
-            'EVT_display_desc'                => ! empty($this->_req_data['display_desc']) ? 1 : 0,
1004
-            'EVT_display_ticket_selector'     => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0,
1005
-            'EVT_additional_limit'            => min(
1006
-                apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1007
-                ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null
1008
-            ),
1009
-            'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status'])
1010
-                ? $this->_req_data['EVT_default_registration_status']
1011
-                : EE_Registry::instance()->CFG->registration->default_STS_ID,
1012
-            'EVT_member_only'                 => ! empty($this->_req_data['member_only']) ? 1 : 0,
1013
-            'EVT_allow_overflow'              => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
1014
-            'EVT_timezone_string'             => ! empty($this->_req_data['timezone_string'])
1015
-                ? $this->_req_data['timezone_string'] : null,
1016
-            'EVT_external_URL'                => ! empty($this->_req_data['externalURL'])
1017
-                ? $this->_req_data['externalURL'] : null,
1018
-            'EVT_phone'                       => ! empty($this->_req_data['event_phone'])
1019
-                ? $this->_req_data['event_phone'] : null,
1020
-        );
1021
-        // update event
1022
-        $success = $this->_event_model()->update_by_ID($event_values, $post_id);
1023
-        // 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!
1024
-        $get_one_where = array(
1025
-            $this->_event_model()->primary_key_name() => $post_id,
1026
-            'OR'                                      => array(
1027
-                'status'   => $post->post_status,
1028
-                // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1029
-                // but the returned object here has a status of "publish", so use the original post status as well
1030
-                'status*1' => $this->_req_data['original_post_status'],
1031
-            ),
1032
-        );
1033
-        $event = $this->_event_model()->get_one(array($get_one_where));
1034
-        // the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
1035
-        $event_update_callbacks = apply_filters(
1036
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1037
-            array(
1038
-                array($this, '_default_venue_update'),
1039
-                array($this, '_default_tickets_update'),
1040
-            )
1041
-        );
1042
-        $att_success = true;
1043
-        foreach ($event_update_callbacks as $e_callback) {
1044
-            $_success = is_callable($e_callback)
1045
-                ? call_user_func($e_callback, $event, $this->_req_data)
1046
-                : false;
1047
-            // if ANY of these updates fail then we want the appropriate global error message
1048
-            $att_success = ! $att_success ? $att_success : $_success;
1049
-        }
1050
-        // any errors?
1051
-        if ($success && false === $att_success) {
1052
-            EE_Error::add_error(
1053
-                esc_html__(
1054
-                    'Event Details saved successfully but something went wrong with saving attachments.',
1055
-                    'event_espresso'
1056
-                ),
1057
-                __FILE__,
1058
-                __FUNCTION__,
1059
-                __LINE__
1060
-            );
1061
-        } elseif ($success === false) {
1062
-            EE_Error::add_error(
1063
-                esc_html__('Event Details did not save successfully.', 'event_espresso'),
1064
-                __FILE__,
1065
-                __FUNCTION__,
1066
-                __LINE__
1067
-            );
1068
-        }
1069
-    }
1070
-
1071
-
1072
-    /**
1073
-     * @see parent::restore_item()
1074
-     * @param int $post_id
1075
-     * @param int $revision_id
1076
-     */
1077
-    protected function _restore_cpt_item($post_id, $revision_id)
1078
-    {
1079
-        // copy existing event meta to new post
1080
-        $post_evt = $this->_event_model()->get_one_by_ID($post_id);
1081
-        if ($post_evt instanceof EE_Event) {
1082
-            // meta revision restore
1083
-            $post_evt->restore_revision($revision_id);
1084
-            // related objs restore
1085
-            $post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price'));
1086
-        }
1087
-    }
1088
-
1089
-
1090
-    /**
1091
-     * Attach the venue to the Event
1092
-     *
1093
-     * @param  \EE_Event $evtobj Event Object to add the venue to
1094
-     * @param  array     $data   The request data from the form
1095
-     * @return bool           Success or fail.
1096
-     */
1097
-    protected function _default_venue_update(\EE_Event $evtobj, $data)
1098
-    {
1099
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1100
-        $venue_model = EE_Registry::instance()->load_model('Venue');
1101
-        $rows_affected = null;
1102
-        $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1103
-        // very important.  If we don't have a venue name...
1104
-        // then we'll get out because not necessary to create empty venue
1105
-        if (empty($data['venue_title'])) {
1106
-            return false;
1107
-        }
1108
-        $venue_array = array(
1109
-            'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1110
-            'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1111
-            'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1112
-            'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1113
-            'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1114
-                : null,
1115
-            'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1116
-            'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1117
-            'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1118
-            'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1119
-            'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1120
-            'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1121
-            'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1122
-            'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1123
-            'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1124
-            'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1125
-            'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1126
-            'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1127
-            'status'              => 'publish',
1128
-        );
1129
-        // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1130
-        if (! empty($venue_id)) {
1131
-            $update_where = array($venue_model->primary_key_name() => $venue_id);
1132
-            $rows_affected = $venue_model->update($venue_array, array($update_where));
1133
-            // 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.
1134
-            $evtobj->_add_relation_to($venue_id, 'Venue');
1135
-            return $rows_affected > 0 ? true : false;
1136
-        } else {
1137
-            // we insert the venue
1138
-            $venue_id = $venue_model->insert($venue_array);
1139
-            $evtobj->_add_relation_to($venue_id, 'Venue');
1140
-            return ! empty($venue_id) ? true : false;
1141
-        }
1142
-        // when we have the ancestor come in it's already been handled by the revision save.
1143
-    }
1144
-
1145
-
1146
-    /**
1147
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
1148
-     *
1149
-     * @param  EE_Event $evtobj The Event object we're attaching data to
1150
-     * @param  array    $data   The request data from the form
1151
-     * @return array
1152
-     */
1153
-    protected function _default_tickets_update(EE_Event $evtobj, $data)
1154
-    {
1155
-        $success = true;
1156
-        $saved_dtt = null;
1157
-        $saved_tickets = array();
1158
-        $incoming_date_formats = array('Y-m-d', 'h:i a');
1159
-        foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1160
-            // trim all values to ensure any excess whitespace is removed.
1161
-            $dtt = array_map('trim', $dtt);
1162
-            $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']
1163
-                : $dtt['DTT_EVT_start'];
1164
-            $datetime_values = array(
1165
-                'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1166
-                'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1167
-                'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1168
-                'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1169
-                'DTT_order'     => $row,
1170
-            );
1171
-            // 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.
1172
-            if (! empty($dtt['DTT_ID'])) {
1173
-                $DTM = EE_Registry::instance()
1174
-                                  ->load_model('Datetime', array($evtobj->get_timezone()))
1175
-                                  ->get_one_by_ID($dtt['DTT_ID']);
1176
-                $DTM->set_date_format($incoming_date_formats[0]);
1177
-                $DTM->set_time_format($incoming_date_formats[1]);
1178
-                foreach ($datetime_values as $field => $value) {
1179
-                    $DTM->set($field, $value);
1180
-                }
1181
-                // 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.
1182
-                $saved_dtts[ $DTM->ID() ] = $DTM;
1183
-            } else {
1184
-                $DTM = EE_Registry::instance()->load_class(
1185
-                    'Datetime',
1186
-                    array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats),
1187
-                    false,
1188
-                    false
1189
-                );
1190
-                foreach ($datetime_values as $field => $value) {
1191
-                    $DTM->set($field, $value);
1192
-                }
1193
-            }
1194
-            $DTM->save();
1195
-            $DTT = $evtobj->_add_relation_to($DTM, 'Datetime');
1196
-            // load DTT helper
1197
-            // 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.
1198
-            if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) {
1199
-                $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start'));
1200
-                $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');
1201
-                $DTT->save();
1202
-            }
1203
-            // 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.
1204
-            $saved_dtt = $DTT;
1205
-            $success = ! $success ? $success : $DTT;
1206
-            // if ANY of these updates fail then we want the appropriate global error message.
1207
-            // //todo this is actually sucky we need a better error message but this is what it is for now.
1208
-        }
1209
-        // no dtts get deleted so we don't do any of that logic here.
1210
-        // update tickets next
1211
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
1212
-        foreach ($data['edit_tickets'] as $row => $tkt) {
1213
-            $incoming_date_formats = array('Y-m-d', 'h:i a');
1214
-            $update_prices = false;
1215
-            $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1216
-                ? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0;
1217
-            // trim inputs to ensure any excess whitespace is removed.
1218
-            $tkt = array_map('trim', $tkt);
1219
-            if (empty($tkt['TKT_start_date'])) {
1220
-                // let's use now in the set timezone.
1221
-                $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1222
-                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1223
-            }
1224
-            if (empty($tkt['TKT_end_date'])) {
1225
-                // use the start date of the first datetime
1226
-                $dtt = $evtobj->first_datetime();
1227
-                $tkt['TKT_end_date'] = $dtt->start_date_and_time(
1228
-                    $incoming_date_formats[0],
1229
-                    $incoming_date_formats[1]
1230
-                );
1231
-            }
1232
-            $TKT_values = array(
1233
-                'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1234
-                'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1235
-                'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1236
-                'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1237
-                'TKT_start_date'  => $tkt['TKT_start_date'],
1238
-                'TKT_end_date'    => $tkt['TKT_end_date'],
1239
-                'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1240
-                'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1241
-                'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1242
-                'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1243
-                'TKT_row'         => $row,
1244
-                'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1245
-                'TKT_price'       => $ticket_price,
1246
-            );
1247
-            // 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.
1248
-            if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1249
-                $TKT_values['TKT_ID'] = 0;
1250
-                $TKT_values['TKT_is_default'] = 0;
1251
-                $TKT_values['TKT_price'] = $ticket_price;
1252
-                $update_prices = true;
1253
-            }
1254
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
1255
-            // 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.
1256
-            // 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.
1257
-            if (! empty($tkt['TKT_ID'])) {
1258
-                $TKT = EE_Registry::instance()
1259
-                                  ->load_model('Ticket', array($evtobj->get_timezone()))
1260
-                                  ->get_one_by_ID($tkt['TKT_ID']);
1261
-                if ($TKT instanceof EE_Ticket) {
1262
-                    $ticket_sold = $TKT->count_related(
1263
-                        'Registration',
1264
-                        array(
1265
-                            array(
1266
-                                'STS_ID' => array(
1267
-                                    'NOT IN',
1268
-                                    array(EEM_Registration::status_id_incomplete),
1269
-                                ),
1270
-                            ),
1271
-                        )
1272
-                    ) > 0 ? true : false;
1273
-                    // 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.
1274
-                    $create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price')
1275
-                                      && ! $TKT->get('TKT_deleted');
1276
-                    $TKT->set_date_format($incoming_date_formats[0]);
1277
-                    $TKT->set_time_format($incoming_date_formats[1]);
1278
-                    // set new values
1279
-                    foreach ($TKT_values as $field => $value) {
1280
-                        if ($field == 'TKT_qty') {
1281
-                            $TKT->set_qty($value);
1282
-                        } else {
1283
-                            $TKT->set($field, $value);
1284
-                        }
1285
-                    }
1286
-                    // if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
1287
-                    if ($create_new_TKT) {
1288
-                        // archive the old ticket first
1289
-                        $TKT->set('TKT_deleted', 1);
1290
-                        $TKT->save();
1291
-                        // make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1292
-                        $saved_tickets[ $TKT->ID() ] = $TKT;
1293
-                        // 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.
1294
-                        $TKT = clone $TKT;
1295
-                        $TKT->set('TKT_ID', 0);
1296
-                        $TKT->set('TKT_deleted', 0);
1297
-                        $TKT->set('TKT_price', $ticket_price);
1298
-                        $TKT->set('TKT_sold', 0);
1299
-                        // now we need to make sure that $new prices are created as well and attached to new ticket.
1300
-                        $update_prices = true;
1301
-                    }
1302
-                    // make sure price is set if it hasn't been already
1303
-                    $TKT->set('TKT_price', $ticket_price);
1304
-                }
1305
-            } else {
1306
-                // no TKT_id so a new TKT
1307
-                $TKT_values['TKT_price'] = $ticket_price;
1308
-                $TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false);
1309
-                if ($TKT instanceof EE_Ticket) {
1310
-                    // need to reset values to properly account for the date formats
1311
-                    $TKT->set_date_format($incoming_date_formats[0]);
1312
-                    $TKT->set_time_format($incoming_date_formats[1]);
1313
-                    $TKT->set_timezone($evtobj->get_timezone());
1314
-                    // set new values
1315
-                    foreach ($TKT_values as $field => $value) {
1316
-                        if ($field == 'TKT_qty') {
1317
-                            $TKT->set_qty($value);
1318
-                        } else {
1319
-                            $TKT->set($field, $value);
1320
-                        }
1321
-                    }
1322
-                    $update_prices = true;
1323
-                }
1324
-            }
1325
-            // cap ticket qty by datetime reg limits
1326
-            $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1327
-            // update ticket.
1328
-            $TKT->save();
1329
-            // 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.
1330
-            if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1331
-                $TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1332
-                $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1333
-                $TKT->save();
1334
-            }
1335
-            // initially let's add the ticket to the dtt
1336
-            $saved_dtt->_add_relation_to($TKT, 'Ticket');
1337
-            $saved_tickets[ $TKT->ID() ] = $TKT;
1338
-            // add prices to ticket
1339
-            $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices);
1340
-        }
1341
-        // 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.
1342
-        $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
1343
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1344
-        foreach ($tickets_removed as $id) {
1345
-            $id = absint($id);
1346
-            // get the ticket for this id
1347
-            $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1348
-            // 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)
1349
-            $dtts = $tkt_to_remove->get_many_related('Datetime');
1350
-            foreach ($dtts as $dtt) {
1351
-                $tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1352
-            }
1353
-            // 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))
1354
-            $tkt_to_remove->delete_related_permanently('Price');
1355
-            // finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1356
-            $tkt_to_remove->delete_permanently();
1357
-        }
1358
-        return array($saved_dtt, $saved_tickets);
1359
-    }
1360
-
1361
-
1362
-    /**
1363
-     * This attaches a list of given prices to a ticket.
1364
-     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1365
-     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1366
-     * price info and prices are automatically "archived" via the ticket.
1367
-     *
1368
-     * @access  private
1369
-     * @param array     $prices     Array of prices from the form.
1370
-     * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1371
-     * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1372
-     * @return  void
1373
-     */
1374
-    private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1375
-    {
1376
-        foreach ($prices as $row => $prc) {
1377
-            $PRC_values = array(
1378
-                'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1379
-                'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1380
-                'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1381
-                'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1382
-                'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1383
-                'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1384
-                'PRC_order'      => $row,
1385
-            );
1386
-            if ($new_prices || empty($PRC_values['PRC_ID'])) {
1387
-                $PRC_values['PRC_ID'] = 0;
1388
-                $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false);
1389
-            } else {
1390
-                $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
1391
-                // update this price with new values
1392
-                foreach ($PRC_values as $field => $newprc) {
1393
-                    $PRC->set($field, $newprc);
1394
-                }
1395
-                $PRC->save();
1396
-            }
1397
-            $ticket->_add_relation_to($PRC, 'Price');
1398
-        }
1399
-    }
1400
-
1401
-
1402
-    /**
1403
-     * Add in our autosave ajax handlers
1404
-     *
1405
-     */
1406
-    protected function _ee_autosave_create_new()
1407
-    {
1408
-    }
1409
-
1410
-
1411
-    /**
1412
-     * More autosave handlers.
1413
-     */
1414
-    protected function _ee_autosave_edit()
1415
-    {
1416
-        return; // TEMPORARILY EXITING CAUSE THIS IS A TODO
1417
-    }
1418
-
1419
-
1420
-    /**
1421
-     *    _generate_publish_box_extra_content
1422
-     */
1423
-    private function _generate_publish_box_extra_content()
1424
-    {
1425
-        // load formatter helper
1426
-        // args for getting related registrations
1427
-        $approved_query_args = array(
1428
-            array(
1429
-                'REG_deleted' => 0,
1430
-                'STS_ID'      => EEM_Registration::status_id_approved,
1431
-            ),
1432
-        );
1433
-        $not_approved_query_args = array(
1434
-            array(
1435
-                'REG_deleted' => 0,
1436
-                'STS_ID'      => EEM_Registration::status_id_not_approved,
1437
-            ),
1438
-        );
1439
-        $pending_payment_query_args = array(
1440
-            array(
1441
-                'REG_deleted' => 0,
1442
-                'STS_ID'      => EEM_Registration::status_id_pending_payment,
1443
-            ),
1444
-        );
1445
-        // publish box
1446
-        $publish_box_extra_args = array(
1447
-            'view_approved_reg_url'        => add_query_arg(
1448
-                array(
1449
-                    'action'      => 'default',
1450
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1451
-                    '_reg_status' => EEM_Registration::status_id_approved,
1452
-                ),
1453
-                REG_ADMIN_URL
1454
-            ),
1455
-            'view_not_approved_reg_url'    => add_query_arg(
1456
-                array(
1457
-                    'action'      => 'default',
1458
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1459
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1460
-                ),
1461
-                REG_ADMIN_URL
1462
-            ),
1463
-            'view_pending_payment_reg_url' => add_query_arg(
1464
-                array(
1465
-                    'action'      => 'default',
1466
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1467
-                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1468
-                ),
1469
-                REG_ADMIN_URL
1470
-            ),
1471
-            'approved_regs'                => $this->_cpt_model_obj->count_related(
1472
-                'Registration',
1473
-                $approved_query_args
1474
-            ),
1475
-            'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1476
-                'Registration',
1477
-                $not_approved_query_args
1478
-            ),
1479
-            'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1480
-                'Registration',
1481
-                $pending_payment_query_args
1482
-            ),
1483
-            'misc_pub_section_class'       => apply_filters(
1484
-                'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1485
-                'misc-pub-section'
1486
-            ),
1487
-        );
1488
-        ob_start();
1489
-        do_action(
1490
-            'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1491
-            $this->_cpt_model_obj
1492
-        );
1493
-        $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1494
-        // load template
1495
-        EEH_Template::display_template(
1496
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1497
-            $publish_box_extra_args
1498
-        );
1499
-    }
1500
-
1501
-
1502
-    /**
1503
-     * @return EE_Event
1504
-     */
1505
-    public function get_event_object()
1506
-    {
1507
-        return $this->_cpt_model_obj;
1508
-    }
1509
-
1510
-
1511
-
1512
-
1513
-    /** METABOXES * */
1514
-    /**
1515
-     * _register_event_editor_meta_boxes
1516
-     * add all metaboxes related to the event_editor
1517
-     *
1518
-     * @return void
1519
-     */
1520
-    protected function _register_event_editor_meta_boxes()
1521
-    {
1522
-        $this->verify_cpt_object();
1523
-        add_meta_box(
1524
-            'espresso_event_editor_tickets',
1525
-            esc_html__('Event Datetime & Ticket', 'event_espresso'),
1526
-            array($this, 'ticket_metabox'),
1527
-            $this->page_slug,
1528
-            'normal',
1529
-            'high'
1530
-        );
1531
-        add_meta_box(
1532
-            'espresso_event_editor_event_options',
1533
-            esc_html__('Event Registration Options', 'event_espresso'),
1534
-            array($this, 'registration_options_meta_box'),
1535
-            $this->page_slug,
1536
-            'side',
1537
-            'default'
1538
-        );
1539
-        // NOTE: if you're looking for other metaboxes in here,
1540
-        // where a metabox has a related management page in the admin
1541
-        // you will find it setup in the related management page's "_Hooks" file.
1542
-        // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1543
-    }
1544
-
1545
-
1546
-    /**
1547
-     * @throws DomainException
1548
-     * @throws EE_Error
1549
-     */
1550
-    public function ticket_metabox()
1551
-    {
1552
-        $existing_datetime_ids = $existing_ticket_ids = array();
1553
-        // defaults for template args
1554
-        $template_args = array(
1555
-            'existing_datetime_ids'    => '',
1556
-            'event_datetime_help_link' => '',
1557
-            'ticket_options_help_link' => '',
1558
-            'time'                     => null,
1559
-            'ticket_rows'              => '',
1560
-            'existing_ticket_ids'      => '',
1561
-            'total_ticket_rows'        => 1,
1562
-            'ticket_js_structure'      => '',
1563
-            'trash_icon'               => 'ee-lock-icon',
1564
-            'disabled'                 => '',
1565
-        );
1566
-        $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1567
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1568
-        /**
1569
-         * 1. Start with retrieving Datetimes
1570
-         * 2. Fore each datetime get related tickets
1571
-         * 3. For each ticket get related prices
1572
-         */
1573
-        $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id);
1574
-        /** @type EE_Datetime $first_datetime */
1575
-        $first_datetime = reset($times);
1576
-        // do we get related tickets?
1577
-        if ($first_datetime instanceof EE_Datetime
1578
-            && $first_datetime->ID() !== 0
1579
-        ) {
1580
-            $existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1581
-            $template_args['time'] = $first_datetime;
1582
-            $related_tickets = $first_datetime->tickets(
1583
-                array(
1584
-                    array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)),
1585
-                    'default_where_conditions' => 'none',
1586
-                )
1587
-            );
1588
-            if (! empty($related_tickets)) {
1589
-                $template_args['total_ticket_rows'] = count($related_tickets);
1590
-                $row = 0;
1591
-                foreach ($related_tickets as $ticket) {
1592
-                    $existing_ticket_ids[] = $ticket->get('TKT_ID');
1593
-                    $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1594
-                    $row++;
1595
-                }
1596
-            } else {
1597
-                $template_args['total_ticket_rows'] = 1;
1598
-                /** @type EE_Ticket $ticket */
1599
-                $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1600
-                $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1601
-            }
1602
-        } else {
1603
-            $template_args['time'] = $times[0];
1604
-            /** @type EE_Ticket $ticket */
1605
-            $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
1606
-            $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]);
1607
-            // NOTE: we're just sending the first default row
1608
-            // (decaf can't manage default tickets so this should be sufficient);
1609
-        }
1610
-        $template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1611
-            'event_editor_event_datetimes_help_tab'
1612
-        );
1613
-        $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1614
-        $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1615
-        $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1616
-        $template_args['ticket_js_structure'] = $this->_get_ticket_row(
1617
-            EE_Registry::instance()->load_model('Ticket')->create_default_object(),
1618
-            true
1619
-        );
1620
-        $template = apply_filters(
1621
-            'FHEE__Events_Admin_Page__ticket_metabox__template',
1622
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1623
-        );
1624
-        EEH_Template::display_template($template, $template_args);
1625
-    }
1626
-
1627
-
1628
-    /**
1629
-     * Setup an individual ticket form for the decaf event editor page
1630
-     *
1631
-     * @access private
1632
-     * @param  EE_Ticket $ticket   the ticket object
1633
-     * @param  boolean   $skeleton whether we're generating a skeleton for js manipulation
1634
-     * @param int        $row
1635
-     * @return string generated html for the ticket row.
1636
-     */
1637
-    private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1638
-    {
1639
-        $template_args = array(
1640
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1641
-            'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1642
-                : '',
1643
-            'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1644
-            'TKT_ID'              => $ticket->get('TKT_ID'),
1645
-            'TKT_name'            => $ticket->get('TKT_name'),
1646
-            'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1647
-            'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1648
-            'TKT_is_default'      => $ticket->get('TKT_is_default'),
1649
-            'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1650
-            'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1651
-            'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1652
-            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1653
-                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1654
-                ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1655
-            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1656
-                : ' disabled=disabled',
1657
-        );
1658
-        $price = $ticket->ID() !== 0
1659
-            ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none'))
1660
-            : EE_Registry::instance()->load_model('Price')->create_default_object();
1661
-        $price_args = array(
1662
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1663
-            'PRC_amount'            => $price->get('PRC_amount'),
1664
-            'PRT_ID'                => $price->get('PRT_ID'),
1665
-            'PRC_ID'                => $price->get('PRC_ID'),
1666
-            'PRC_is_default'        => $price->get('PRC_is_default'),
1667
-        );
1668
-        // make sure we have default start and end dates if skeleton
1669
-        // handle rows that should NOT be empty
1670
-        if (empty($template_args['TKT_start_date'])) {
1671
-            // if empty then the start date will be now.
1672
-            $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1673
-        }
1674
-        if (empty($template_args['TKT_end_date'])) {
1675
-            // get the earliest datetime (if present);
1676
-            $earliest_dtt = $this->_cpt_model_obj->ID() > 0
1677
-                ? $this->_cpt_model_obj->get_first_related(
1678
-                    'Datetime',
1679
-                    array('order_by' => array('DTT_EVT_start' => 'ASC'))
1680
-                )
1681
-                : null;
1682
-            if (! empty($earliest_dtt)) {
1683
-                $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1684
-            } else {
1685
-                $template_args['TKT_end_date'] = date(
1686
-                    'Y-m-d h:i a',
1687
-                    mktime(0, 0, 0, date("m"), date("d") + 7, date("Y"))
1688
-                );
1689
-            }
1690
-        }
1691
-        $template_args = array_merge($template_args, $price_args);
1692
-        $template = apply_filters(
1693
-            'FHEE__Events_Admin_Page__get_ticket_row__template',
1694
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1695
-            $ticket
1696
-        );
1697
-        return EEH_Template::display_template($template, $template_args, true);
1698
-    }
1699
-
1700
-
1701
-    /**
1702
-     * @throws DomainException
1703
-     */
1704
-    public function registration_options_meta_box()
1705
-    {
1706
-        $yes_no_values = array(
1707
-            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
1708
-            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
1709
-        );
1710
-        $default_reg_status_values = EEM_Registration::reg_status_array(
1711
-            array(
1712
-                EEM_Registration::status_id_cancelled,
1713
-                EEM_Registration::status_id_declined,
1714
-                EEM_Registration::status_id_incomplete,
1715
-            ),
1716
-            true
1717
-        );
1718
-        // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1719
-        $template_args['_event'] = $this->_cpt_model_obj;
1720
-        $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1721
-        $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1722
-        $template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1723
-            'default_reg_status',
1724
-            $default_reg_status_values,
1725
-            $this->_cpt_model_obj->default_registration_status()
1726
-        );
1727
-        $template_args['display_description'] = EEH_Form_Fields::select_input(
1728
-            'display_desc',
1729
-            $yes_no_values,
1730
-            $this->_cpt_model_obj->display_description()
1731
-        );
1732
-        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1733
-            'display_ticket_selector',
1734
-            $yes_no_values,
1735
-            $this->_cpt_model_obj->display_ticket_selector(),
1736
-            '',
1737
-            '',
1738
-            false
1739
-        );
1740
-        $template_args['additional_registration_options'] = apply_filters(
1741
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1742
-            '',
1743
-            $template_args,
1744
-            $yes_no_values,
1745
-            $default_reg_status_values
1746
-        );
1747
-        EEH_Template::display_template(
1748
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1749
-            $template_args
1750
-        );
1751
-    }
1752
-
1753
-
1754
-    /**
1755
-     * _get_events()
1756
-     * This method simply returns all the events (for the given _view and paging)
1757
-     *
1758
-     * @access public
1759
-     * @param int  $per_page     count of items per page (20 default);
1760
-     * @param int  $current_page what is the current page being viewed.
1761
-     * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1762
-     *                           If FALSE then we return an array of event objects
1763
-     *                           that match the given _view and paging parameters.
1764
-     * @return array an array of event objects.
1765
-     */
1766
-    public function get_events($per_page = 10, $current_page = 1, $count = false)
1767
-    {
1768
-        $EEME = $this->_event_model();
1769
-        $offset = ($current_page - 1) * $per_page;
1770
-        $limit = $count ? null : $offset . ',' . $per_page;
1771
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1772
-        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1773
-        if (isset($this->_req_data['month_range'])) {
1774
-            $pieces = explode(' ', $this->_req_data['month_range'], 3);
1775
-            // simulate the FIRST day of the month, that fixes issues for months like February
1776
-            // where PHP doesn't know what to assume for date.
1777
-            // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1778
-            $month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1779
-            $year_r = ! empty($pieces[1]) ? $pieces[1] : '';
1780
-        }
1781
-        $where = array();
1782
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1783
-        // determine what post_status our condition will have for the query.
1784
-        switch ($status) {
1785
-            case 'month':
1786
-            case 'today':
1787
-            case null:
1788
-            case 'all':
1789
-                break;
1790
-            case 'draft':
1791
-                $where['status'] = array('IN', array('draft', 'auto-draft'));
1792
-                break;
1793
-            default:
1794
-                $where['status'] = $status;
1795
-        }
1796
-        // categories?
1797
-        $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1798
-            ? $this->_req_data['EVT_CAT'] : null;
1799
-        if (! empty($category)) {
1800
-            $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1801
-            $where['Term_Taxonomy.term_id'] = $category;
1802
-        }
1803
-        // date where conditions
1804
-        $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1805
-        if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1806
-            $DateTime = new DateTime(
1807
-                $year_r . '-' . $month_r . '-01 00:00:00',
1808
-                new DateTimeZone(EEM_Datetime::instance()->get_timezone())
1809
-            );
1810
-            $start = $DateTime->format(implode(' ', $start_formats));
1811
-            $end = $DateTime->setDate(
1812
-                $year_r,
1813
-                $month_r,
1814
-                $DateTime
1815
-                    ->format('t')
1816
-            )->setTime(23, 59, 59)
1817
-                            ->format(implode(' ', $start_formats));
1818
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1819
-        } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') {
1820
-            $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1821
-            $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1822
-            $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1823
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1824
-        } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') {
1825
-            $now = date('Y-m-01');
1826
-            $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1827
-            $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1828
-            $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1829
-                            ->setTime(23, 59, 59)
1830
-                            ->format(implode(' ', $start_formats));
1831
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1832
-        }
1833
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1834
-            $where['EVT_wp_user'] = get_current_user_id();
1835
-        } else {
1836
-            if (! isset($where['status'])) {
1837
-                if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1838
-                    $where['OR'] = array(
1839
-                        'status*restrict_private' => array('!=', 'private'),
1840
-                        'AND'                     => array(
1841
-                            'status*inclusive' => array('=', 'private'),
1842
-                            'EVT_wp_user'      => get_current_user_id(),
1843
-                        ),
1844
-                    );
1845
-                }
1846
-            }
1847
-        }
1848
-        if (isset($this->_req_data['EVT_wp_user'])) {
1849
-            if ($this->_req_data['EVT_wp_user'] != get_current_user_id()
1850
-                && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1851
-            ) {
1852
-                $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
1853
-            }
1854
-        }
1855
-        // search query handling
1856
-        if (isset($this->_req_data['s'])) {
1857
-            $search_string = '%' . $this->_req_data['s'] . '%';
1858
-            $where['OR'] = array(
1859
-                'EVT_name'       => array('LIKE', $search_string),
1860
-                'EVT_desc'       => array('LIKE', $search_string),
1861
-                'EVT_short_desc' => array('LIKE', $search_string),
1862
-            );
1863
-        }
1864
-        // filter events by venue.
1865
-        if (isset($this->_req_data['venue']) && ! empty($this->_req_data['venue'])) {
1866
-            $where['Venue.VNU_ID'] = absint($this->_req_data['venue']);
1867
-        }
1868
-        $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
1869
-        $query_params = apply_filters(
1870
-            'FHEE__Events_Admin_Page__get_events__query_params',
1871
-            array(
1872
-                $where,
1873
-                'limit'    => $limit,
1874
-                'order_by' => $orderby,
1875
-                'order'    => $order,
1876
-                'group_by' => 'EVT_ID',
1877
-            ),
1878
-            $this->_req_data
1879
-        );
1880
-        // let's first check if we have special requests coming in.
1881
-        if (isset($this->_req_data['active_status'])) {
1882
-            switch ($this->_req_data['active_status']) {
1883
-                case 'upcoming':
1884
-                    return $EEME->get_upcoming_events($query_params, $count);
1885
-                    break;
1886
-                case 'expired':
1887
-                    return $EEME->get_expired_events($query_params, $count);
1888
-                    break;
1889
-                case 'active':
1890
-                    return $EEME->get_active_events($query_params, $count);
1891
-                    break;
1892
-                case 'inactive':
1893
-                    return $EEME->get_inactive_events($query_params, $count);
1894
-                    break;
1895
-            }
1896
-        }
1897
-
1898
-        $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params);
1899
-        return $events;
1900
-    }
1901
-
1902
-
1903
-    /**
1904
-     * handling for WordPress CPT actions (trash, restore, delete)
1905
-     *
1906
-     * @param string $post_id
1907
-     */
1908
-    public function trash_cpt_item($post_id)
1909
-    {
1910
-        $this->_req_data['EVT_ID'] = $post_id;
1911
-        $this->_trash_or_restore_event('trash', false);
1912
-    }
1913
-
1914
-
1915
-    /**
1916
-     * @param string $post_id
1917
-     */
1918
-    public function restore_cpt_item($post_id)
1919
-    {
1920
-        $this->_req_data['EVT_ID'] = $post_id;
1921
-        $this->_trash_or_restore_event('draft', false);
1922
-    }
1923
-
1924
-
1925
-    /**
1926
-     * @param string $post_id
1927
-     */
1928
-    public function delete_cpt_item($post_id)
1929
-    {
1930
-        throw new EE_Error(esc_html__('Please contact Event Espresso support with the details of what you did to produce this error.', 'event_espresso'));
1931
-        $this->_req_data['EVT_ID'] = $post_id;
1932
-        $this->_delete_event();
1933
-    }
1934
-
1935
-
1936
-    /**
1937
-     * _trash_or_restore_event
1938
-     *
1939
-     * @access protected
1940
-     * @param  string $event_status
1941
-     * @param bool    $redirect_after
1942
-     */
1943
-    protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
1944
-    {
1945
-        // determine the event id and set to array.
1946
-        $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
1947
-        // loop thru events
1948
-        if ($EVT_ID) {
1949
-            // clean status
1950
-            $event_status = sanitize_key($event_status);
1951
-            // grab status
1952
-            if (! empty($event_status)) {
1953
-                $success = $this->_change_event_status($EVT_ID, $event_status);
1954
-            } else {
1955
-                $success = false;
1956
-                $msg = esc_html__(
1957
-                    'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1958
-                    'event_espresso'
1959
-                );
1960
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1961
-            }
1962
-        } else {
1963
-            $success = false;
1964
-            $msg = esc_html__(
1965
-                'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
1966
-                'event_espresso'
1967
-            );
1968
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1969
-        }
1970
-        $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1971
-        if ($redirect_after) {
1972
-            $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default'));
1973
-        }
1974
-    }
1975
-
1976
-
1977
-    /**
1978
-     * _trash_or_restore_events
1979
-     *
1980
-     * @access protected
1981
-     * @param  string $event_status
1982
-     * @return void
1983
-     */
1984
-    protected function _trash_or_restore_events($event_status = 'trash')
1985
-    {
1986
-        // clean status
1987
-        $event_status = sanitize_key($event_status);
1988
-        // grab status
1989
-        if (! empty($event_status)) {
1990
-            $success = true;
1991
-            // determine the event id and set to array.
1992
-            $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();
1993
-            // loop thru events
1994
-            foreach ($EVT_IDs as $EVT_ID) {
1995
-                if ($EVT_ID = absint($EVT_ID)) {
1996
-                    $results = $this->_change_event_status($EVT_ID, $event_status);
1997
-                    $success = $results !== false ? $success : false;
1998
-                } else {
1999
-                    $msg = sprintf(
2000
-                        esc_html__(
2001
-                            'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2002
-                            'event_espresso'
2003
-                        ),
2004
-                        $EVT_ID
2005
-                    );
2006
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2007
-                    $success = false;
2008
-                }
2009
-            }
2010
-        } else {
2011
-            $success = false;
2012
-            $msg = esc_html__(
2013
-                'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2014
-                'event_espresso'
2015
-            );
2016
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2017
-        }
2018
-        // in order to force a pluralized result message we need to send back a success status greater than 1
2019
-        $success = $success ? 2 : false;
2020
-        $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
2021
-        $this->_redirect_after_action($success, 'Events', $action, array('action' => 'default'));
2022
-    }
2023
-
2024
-
2025
-    /**
2026
-     * _trash_or_restore_events
2027
-     *
2028
-     * @access  private
2029
-     * @param  int    $EVT_ID
2030
-     * @param  string $event_status
2031
-     * @return bool
2032
-     */
2033
-    private function _change_event_status($EVT_ID = 0, $event_status = '')
2034
-    {
2035
-        // grab event id
2036
-        if (! $EVT_ID) {
2037
-            $msg = esc_html__(
2038
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2039
-                'event_espresso'
2040
-            );
2041
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2042
-            return false;
2043
-        }
2044
-        $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2045
-        // clean status
2046
-        $event_status = sanitize_key($event_status);
2047
-        // grab status
2048
-        if (empty($event_status)) {
2049
-            $msg = esc_html__(
2050
-                'An error occurred. No Event Status or an invalid Event Status was received.',
2051
-                'event_espresso'
2052
-            );
2053
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2054
-            return false;
2055
-        }
2056
-        // was event trashed or restored ?
2057
-        switch ($event_status) {
2058
-            case 'draft':
2059
-                $action = 'restored from the trash';
2060
-                $hook = 'AHEE_event_restored_from_trash';
2061
-                break;
2062
-            case 'trash':
2063
-                $action = 'moved to the trash';
2064
-                $hook = 'AHEE_event_moved_to_trash';
2065
-                break;
2066
-            default:
2067
-                $action = 'updated';
2068
-                $hook = false;
2069
-        }
2070
-        // use class to change status
2071
-        $this->_cpt_model_obj->set_status($event_status);
2072
-        $success = $this->_cpt_model_obj->save();
2073
-        if ($success === false) {
2074
-            $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2075
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2076
-            return false;
2077
-        }
2078
-        if ($hook) {
2079
-            do_action($hook);
2080
-        }
2081
-        return true;
2082
-    }
2083
-
2084
-
2085
-    /**
2086
-     * _delete_event
2087
-     *
2088
-     * @access protected
2089
-     * @param bool $redirect_after
2090
-     */
2091
-    protected function _delete_event()
2092
-    {
2093
-        // determine the event id and set to array.
2094
-        $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null;
2095
-        wp_safe_redirect(
2096
-            EE_Admin_Page::add_query_args_and_nonce(
2097
-                [
2098
-                    'action' => 'preview_deletion',
2099
-                    'EVT_IDs[]' => $EVT_ID
2100
-                ],
2101
-                $this->_admin_base_url
2102
-            )
2103
-        );
2104
-    }
2105
-
2106
-
2107
-    /**
2108
-     * _delete_events
2109
-     *
2110
-     * @access protected
2111
-     * @return void
2112
-     */
2113
-    protected function _delete_events()
2114
-    {
2115
-        $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
2116
-        $args = [
2117
-            'action' => 'preview_deletion',
2118
-        ];
2119
-        foreach($EVT_IDs as $EVT_ID){
2120
-            $args['EVT_IDs[]'] = (int)$EVT_ID;
2121
-        }
2122
-        wp_safe_redirect(
2123
-            EE_Admin_Page::add_query_args_and_nonce(
2124
-                $args,
2125
-                $this->_admin_base_url
2126
-            )
2127
-        );
2128
-    }
2129
-
2130
-    /**
2131
-     * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2132
-     * @since $VID:$
2133
-     */
2134
-    protected function previewDeletion()
2135
-    {
2136
-        $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
2137
-        $confirm_deletion_args = [
2138
-            'action' => 'confirm_deletion',
2139
-        ];
2140
-        foreach($EVT_IDs as $EVT_ID){
2141
-            $confirm_deletion_args['EVT_ID[]'] = (int)$EVT_ID;
2142
-        }
2143
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2144
-            EVENTS_TEMPLATE_PATH . 'event_preview_deletion.template.php',
2145
-            [
2146
-                'form_url' => EE_Admin_Page::add_query_args_and_nonce(
2147
-                    $confirm_deletion_args,
2148
-                    $this->admin_base_url()
2149
-                )
2150
-            ],
2151
-            true
2152
-        );
2153
-        $this->display_admin_page_with_no_sidebar();
2154
-    }
2155
-
2156
-    protected function confirmDeletion()
2157
-    {
2158
-        echo "event deleted here";
2159
-
2160
-        // code from original _delete_event, which I assume we want to keep
2161
-        $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2162
-        // remove this event from the list of events with no prices
2163
-        if (isset($espresso_no_ticket_prices[ $EVT_ID ])) {
2164
-            unset($espresso_no_ticket_prices[ $EVT_ID ]);
2165
-        }
2166
-        update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2167
-    }
2168
-
2169
-    /**
2170
-     * _permanently_delete_event
2171
-     *
2172
-     * @access  private
2173
-     * @param  int $EVT_ID
2174
-     * @return bool
2175
-     */
2176
-    private function _permanently_delete_event($EVT_ID = 0)
2177
-    {
2178
-        // grab event id
2179
-        if (! $EVT_ID) {
2180
-            $msg = esc_html__(
2181
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2182
-                'event_espresso'
2183
-            );
2184
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2185
-            return false;
2186
-        }
2187
-        if (! $this->_cpt_model_obj instanceof EE_Event
2188
-            || $this->_cpt_model_obj->ID() !== $EVT_ID
2189
-        ) {
2190
-            $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2191
-        }
2192
-        if (! $this->_cpt_model_obj instanceof EE_Event) {
2193
-            return false;
2194
-        }
2195
-        // need to delete related tickets and prices first.
2196
-        $datetimes = $this->_cpt_model_obj->get_many_related('Datetime');
2197
-        foreach ($datetimes as $datetime) {
2198
-            $this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime');
2199
-            $tickets = $datetime->get_many_related('Ticket');
2200
-            foreach ($tickets as $ticket) {
2201
-                $ticket->_remove_relation_to($datetime, 'Datetime');
2202
-                $ticket->delete_related_permanently('Price');
2203
-                $ticket->delete_permanently();
2204
-            }
2205
-            $datetime->delete();
2206
-        }
2207
-        // what about related venues or terms?
2208
-        $venues = $this->_cpt_model_obj->get_many_related('Venue');
2209
-        foreach ($venues as $venue) {
2210
-            $this->_cpt_model_obj->_remove_relation_to($venue, 'Venue');
2211
-        }
2212
-        // any attached question groups?
2213
-        $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group');
2214
-        if (! empty($question_groups)) {
2215
-            foreach ($question_groups as $question_group) {
2216
-                $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group');
2217
-            }
2218
-        }
2219
-        // Message Template Groups
2220
-        $this->_cpt_model_obj->_remove_relations('Message_Template_Group');
2221
-        /** @type EE_Term_Taxonomy[] $term_taxonomies */
2222
-        $term_taxonomies = $this->_cpt_model_obj->term_taxonomies();
2223
-        foreach ($term_taxonomies as $term_taxonomy) {
2224
-            $this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy);
2225
-        }
2226
-        $success = $this->_cpt_model_obj->delete_permanently();
2227
-        // did it all go as planned ?
2228
-        if ($success) {
2229
-            $msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID);
2230
-            EE_Error::add_success($msg);
2231
-        } else {
2232
-            $msg = sprintf(
2233
-                esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'),
2234
-                $EVT_ID
2235
-            );
2236
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2237
-            return false;
2238
-        }
2239
-        do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID);
2240
-        return true;
2241
-    }
2242
-
2243
-
2244
-    /**
2245
-     * get total number of events
2246
-     *
2247
-     * @access public
2248
-     * @return int
2249
-     */
2250
-    public function total_events()
2251
-    {
2252
-        $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true);
2253
-        return $count;
2254
-    }
2255
-
2256
-
2257
-    /**
2258
-     * get total number of draft events
2259
-     *
2260
-     * @access public
2261
-     * @return int
2262
-     */
2263
-    public function total_events_draft()
2264
-    {
2265
-        $where = array(
2266
-            'status' => array('IN', array('draft', 'auto-draft')),
2267
-        );
2268
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2269
-        return $count;
2270
-    }
2271
-
2272
-
2273
-    /**
2274
-     * get total number of trashed events
2275
-     *
2276
-     * @access public
2277
-     * @return int
2278
-     */
2279
-    public function total_trashed_events()
2280
-    {
2281
-        $where = array(
2282
-            'status' => 'trash',
2283
-        );
2284
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2285
-        return $count;
2286
-    }
2287
-
2288
-
2289
-    /**
2290
-     *    _default_event_settings
2291
-     *    This generates the Default Settings Tab
2292
-     *
2293
-     * @return void
2294
-     * @throws EE_Error
2295
-     */
2296
-    protected function _default_event_settings()
2297
-    {
2298
-        $this->_set_add_edit_form_tags('update_default_event_settings');
2299
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
2300
-        $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2301
-        $this->display_admin_page_with_sidebar();
2302
-    }
2303
-
2304
-
2305
-    /**
2306
-     * Return the form for event settings.
2307
-     *
2308
-     * @return EE_Form_Section_Proper
2309
-     * @throws EE_Error
2310
-     */
2311
-    protected function _default_event_settings_form()
2312
-    {
2313
-        $registration_config = EE_Registry::instance()->CFG->registration;
2314
-        $registration_stati_for_selection = EEM_Registration::reg_status_array(
2315
-            // exclude
2316
-            array(
2317
-                EEM_Registration::status_id_cancelled,
2318
-                EEM_Registration::status_id_declined,
2319
-                EEM_Registration::status_id_incomplete,
2320
-                EEM_Registration::status_id_wait_list,
2321
-            ),
2322
-            true
2323
-        );
2324
-        return new EE_Form_Section_Proper(
2325
-            array(
2326
-                'name'            => 'update_default_event_settings',
2327
-                'html_id'         => 'update_default_event_settings',
2328
-                'html_class'      => 'form-table',
2329
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2330
-                'subsections'     => apply_filters(
2331
-                    'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2332
-                    array(
2333
-                        'default_reg_status'  => new EE_Select_Input(
2334
-                            $registration_stati_for_selection,
2335
-                            array(
2336
-                                'default'         => isset($registration_config->default_STS_ID)
2337
-                                                     && array_key_exists(
2338
-                                                         $registration_config->default_STS_ID,
2339
-                                                         $registration_stati_for_selection
2340
-                                                     )
2341
-                                    ? sanitize_text_field($registration_config->default_STS_ID)
2342
-                                    : EEM_Registration::status_id_pending_payment,
2343
-                                'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2344
-                                                     . EEH_Template::get_help_tab_link(
2345
-                                                         'default_settings_status_help_tab'
2346
-                                                     ),
2347
-                                'html_help_text'  => esc_html__(
2348
-                                    '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.',
2349
-                                    'event_espresso'
2350
-                                ),
2351
-                            )
2352
-                        ),
2353
-                        'default_max_tickets' => new EE_Integer_Input(
2354
-                            array(
2355
-                                'default'         => isset($registration_config->default_maximum_number_of_tickets)
2356
-                                    ? $registration_config->default_maximum_number_of_tickets
2357
-                                    : EEM_Event::get_default_additional_limit(),
2358
-                                'html_label_text' => esc_html__(
2359
-                                    'Default Maximum Tickets Allowed Per Order:',
2360
-                                    'event_espresso'
2361
-                                )
2362
-                                                     . EEH_Template::get_help_tab_link(
2363
-                                                         'default_maximum_tickets_help_tab"'
2364
-                                                     ),
2365
-                                'html_help_text'  => esc_html__(
2366
-                                    'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2367
-                                    'event_espresso'
2368
-                                ),
2369
-                            )
2370
-                        ),
2371
-                    )
2372
-                ),
2373
-            )
2374
-        );
2375
-    }
2376
-
2377
-
2378
-    /**
2379
-     * _update_default_event_settings
2380
-     *
2381
-     * @access protected
2382
-     * @return void
2383
-     * @throws EE_Error
2384
-     */
2385
-    protected function _update_default_event_settings()
2386
-    {
2387
-        $registration_config = EE_Registry::instance()->CFG->registration;
2388
-        $form = $this->_default_event_settings_form();
2389
-        if ($form->was_submitted()) {
2390
-            $form->receive_form_submission();
2391
-            if ($form->is_valid()) {
2392
-                $valid_data = $form->valid_data();
2393
-                if (isset($valid_data['default_reg_status'])) {
2394
-                    $registration_config->default_STS_ID = $valid_data['default_reg_status'];
2395
-                }
2396
-                if (isset($valid_data['default_max_tickets'])) {
2397
-                    $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2398
-                }
2399
-                // update because data was valid!
2400
-                EE_Registry::instance()->CFG->update_espresso_config();
2401
-                EE_Error::overwrite_success();
2402
-                EE_Error::add_success(
2403
-                    __('Default Event Settings were updated', 'event_espresso')
2404
-                );
2405
-            }
2406
-        }
2407
-        $this->_redirect_after_action(0, '', '', array('action' => 'default_event_settings'), true);
2408
-    }
2409
-
2410
-
2411
-    /*************        Templates        *************/
2412
-    protected function _template_settings()
2413
-    {
2414
-        $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso');
2415
-        $this->_template_args['preview_img'] = '<img src="'
2416
-                                               . EVENTS_ASSETS_URL
2417
-                                               . '/images/'
2418
-                                               . 'caffeinated_template_features.jpg" alt="'
2419
-                                               . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2420
-                                               . '" />';
2421
-        $this->_template_args['preview_text'] = '<strong>'
2422
-                                                . esc_html__(
2423
-                                                    '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.',
2424
-                                                    'event_espresso'
2425
-                                                ) . '</strong>';
2426
-        $this->display_admin_caf_preview_page('template_settings_tab');
2427
-    }
2428
-
2429
-
2430
-    /** Event Category Stuff **/
2431
-    /**
2432
-     * set the _category property with the category object for the loaded page.
2433
-     *
2434
-     * @access private
2435
-     * @return void
2436
-     */
2437
-    private function _set_category_object()
2438
-    {
2439
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
2440
-            return;
2441
-        } //already have the category object so get out.
2442
-        // set default category object
2443
-        $this->_set_empty_category_object();
2444
-        // only set if we've got an id
2445
-        if (! isset($this->_req_data['EVT_CAT_ID'])) {
2446
-            return;
2447
-        }
2448
-        $category_id = absint($this->_req_data['EVT_CAT_ID']);
2449
-        $term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2450
-        if (! empty($term)) {
2451
-            $this->_category->category_name = $term->name;
2452
-            $this->_category->category_identifier = $term->slug;
2453
-            $this->_category->category_desc = $term->description;
2454
-            $this->_category->id = $term->term_id;
2455
-            $this->_category->parent = $term->parent;
2456
-        }
2457
-    }
2458
-
2459
-
2460
-    /**
2461
-     * Clears out category properties.
2462
-     */
2463
-    private function _set_empty_category_object()
2464
-    {
2465
-        $this->_category = new stdClass();
2466
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2467
-        $this->_category->id = $this->_category->parent = 0;
2468
-    }
2469
-
2470
-
2471
-    /**
2472
-     * @throws EE_Error
2473
-     */
2474
-    protected function _category_list_table()
2475
-    {
2476
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2477
-        $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2478
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2479
-            'add_category',
2480
-            'add_category',
2481
-            array(),
2482
-            'add-new-h2'
2483
-        );
2484
-        $this->display_admin_list_table_page_with_sidebar();
2485
-    }
2486
-
2487
-
2488
-    /**
2489
-     * Output category details view.
2490
-     */
2491
-    protected function _category_details($view)
2492
-    {
2493
-        // load formatter helper
2494
-        // load field generator helper
2495
-        $route = $view == 'edit' ? 'update_category' : 'insert_category';
2496
-        $this->_set_add_edit_form_tags($route);
2497
-        $this->_set_category_object();
2498
-        $id = ! empty($this->_category->id) ? $this->_category->id : '';
2499
-        $delete_action = 'delete_category';
2500
-        // custom redirect
2501
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(
2502
-            array('action' => 'category_list'),
2503
-            $this->_admin_base_url
2504
-        );
2505
-        $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2506
-        // take care of contents
2507
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
2508
-        $this->display_admin_page_with_sidebar();
2509
-    }
2510
-
2511
-
2512
-    /**
2513
-     * Output category details content.
2514
-     */
2515
-    protected function _category_details_content()
2516
-    {
2517
-        $editor_args['category_desc'] = array(
2518
-            'type'          => 'wp_editor',
2519
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2520
-            'class'         => 'my_editor_custom',
2521
-            'wpeditor_args' => array('media_buttons' => false),
2522
-        );
2523
-        $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
2524
-        $all_terms = get_terms(
2525
-            array(EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY),
2526
-            array('hide_empty' => 0, 'exclude' => array($this->_category->id))
2527
-        );
2528
-        // setup category select for term parents.
2529
-        $category_select_values[] = array(
2530
-            'text' => esc_html__('No Parent', 'event_espresso'),
2531
-            'id'   => 0,
2532
-        );
2533
-        foreach ($all_terms as $term) {
2534
-            $category_select_values[] = array(
2535
-                'text' => $term->name,
2536
-                'id'   => $term->term_id,
2537
-            );
2538
-        }
2539
-        $category_select = EEH_Form_Fields::select_input(
2540
-            'category_parent',
2541
-            $category_select_values,
2542
-            $this->_category->parent
2543
-        );
2544
-        $template_args = array(
2545
-            'category'                 => $this->_category,
2546
-            'category_select'          => $category_select,
2547
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2548
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2549
-            'disable'                  => '',
2550
-            'disabled_message'         => false,
2551
-        );
2552
-        $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2553
-        return EEH_Template::display_template($template, $template_args, true);
2554
-    }
2555
-
2556
-
2557
-    /**
2558
-     * Handles deleting categories.
2559
-     */
2560
-    protected function _delete_categories()
2561
-    {
2562
-        $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID']
2563
-            : (array) $this->_req_data['category_id'];
2564
-        foreach ($cat_ids as $cat_id) {
2565
-            $this->_delete_category($cat_id);
2566
-        }
2567
-        // doesn't matter what page we're coming from... we're going to the same place after delete.
2568
-        $query_args = array(
2569
-            'action' => 'category_list',
2570
-        );
2571
-        $this->_redirect_after_action(0, '', '', $query_args);
2572
-    }
2573
-
2574
-
2575
-    /**
2576
-     * Handles deleting specific category.
2577
-     *
2578
-     * @param int $cat_id
2579
-     */
2580
-    protected function _delete_category($cat_id)
2581
-    {
2582
-        $cat_id = absint($cat_id);
2583
-        wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2584
-    }
2585
-
2586
-
2587
-    /**
2588
-     * Handles triggering the update or insertion of a new category.
2589
-     *
2590
-     * @param bool $new_category true means we're triggering the insert of a new category.
2591
-     */
2592
-    protected function _insert_or_update_category($new_category)
2593
-    {
2594
-        $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2595
-        $success = 0; // we already have a success message so lets not send another.
2596
-        if ($cat_id) {
2597
-            $query_args = array(
2598
-                'action'     => 'edit_category',
2599
-                'EVT_CAT_ID' => $cat_id,
2600
-            );
2601
-        } else {
2602
-            $query_args = array('action' => 'add_category');
2603
-        }
2604
-        $this->_redirect_after_action($success, '', '', $query_args, true);
2605
-    }
2606
-
2607
-
2608
-    /**
2609
-     * Inserts or updates category
2610
-     *
2611
-     * @param bool $update (true indicates we're updating a category).
2612
-     * @return bool|mixed|string
2613
-     */
2614
-    private function _insert_category($update = false)
2615
-    {
2616
-        $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2617
-        $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2618
-        $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2619
-        $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2620
-        if (empty($category_name)) {
2621
-            $msg = esc_html__('You must add a name for the category.', 'event_espresso');
2622
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2623
-            return false;
2624
-        }
2625
-        $term_args = array(
2626
-            'name'        => $category_name,
2627
-            'description' => $category_desc,
2628
-            'parent'      => $category_parent,
2629
-        );
2630
-        // was the category_identifier input disabled?
2631
-        if (isset($this->_req_data['category_identifier'])) {
2632
-            $term_args['slug'] = $this->_req_data['category_identifier'];
2633
-        }
2634
-        $insert_ids = $update
2635
-            ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2636
-            : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2637
-        if (! is_array($insert_ids)) {
2638
-            $msg = esc_html__(
2639
-                'An error occurred and the category has not been saved to the database.',
2640
-                'event_espresso'
2641
-            );
2642
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2643
-        } else {
2644
-            $cat_id = $insert_ids['term_id'];
2645
-            $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2646
-            EE_Error::add_success($msg);
2647
-        }
2648
-        return $cat_id;
2649
-    }
2650
-
2651
-
2652
-    /**
2653
-     * Gets categories or count of categories matching the arguments in the request.
2654
-     *
2655
-     * @param int  $per_page
2656
-     * @param int  $current_page
2657
-     * @param bool $count
2658
-     * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int
2659
-     */
2660
-    public function get_categories($per_page = 10, $current_page = 1, $count = false)
2661
-    {
2662
-        // testing term stuff
2663
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2664
-        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2665
-        $limit = ($current_page - 1) * $per_page;
2666
-        $where = array('taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2667
-        if (isset($this->_req_data['s'])) {
2668
-            $sstr = '%' . $this->_req_data['s'] . '%';
2669
-            $where['OR'] = array(
2670
-                'Term.name'   => array('LIKE', $sstr),
2671
-                'description' => array('LIKE', $sstr),
2672
-            );
2673
-        }
2674
-        $query_params = array(
2675
-            $where,
2676
-            'order_by'   => array($orderby => $order),
2677
-            'limit'      => $limit . ',' . $per_page,
2678
-            'force_join' => array('Term'),
2679
-        );
2680
-        $categories = $count
2681
-            ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2682
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
2683
-        return $categories;
2684
-    }
2685
-
2686
-    /* end category stuff */
2687
-    /**************/
2688
-
2689
-
2690
-    /**
2691
-     * Callback for the `ee_save_timezone_setting` ajax action.
2692
-     *
2693
-     * @throws EE_Error
2694
-     */
2695
-    public function save_timezonestring_setting()
2696
-    {
2697
-        $timezone_string = isset($this->_req_data['timezone_selected'])
2698
-            ? $this->_req_data['timezone_selected']
2699
-            : '';
2700
-        if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2701
-            EE_Error::add_error(
2702
-                esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2703
-                __FILE__,
2704
-                __FUNCTION__,
2705
-                __LINE__
2706
-            );
2707
-            $this->_template_args['error'] = true;
2708
-            $this->_return_json();
2709
-        }
2710
-
2711
-        update_option('timezone_string', $timezone_string);
2712
-        EE_Error::add_success(
2713
-            esc_html__('Your timezone string was updated.', 'event_espresso')
2714
-        );
2715
-        $this->_template_args['success'] = true;
2716
-        $this->_return_json(true, array('action' => 'create_new'));
2717
-    }
527
+			)
528
+		);
529
+	}
530
+
531
+
532
+	/**
533
+	 * Used to register any global screen options if necessary for every route in this admin page group.
534
+	 */
535
+	protected function _add_screen_options()
536
+	{
537
+	}
538
+
539
+
540
+	/**
541
+	 * Implementing the screen options for the 'default' route.
542
+	 */
543
+	protected function _add_screen_options_default()
544
+	{
545
+		$this->_per_page_screen_option();
546
+	}
547
+
548
+
549
+	/**
550
+	 * Implementing screen options for the category list route.
551
+	 */
552
+	protected function _add_screen_options_category_list()
553
+	{
554
+		$page_title = $this->_admin_page_title;
555
+		$this->_admin_page_title = esc_html__('Categories', 'event_espresso');
556
+		$this->_per_page_screen_option();
557
+		$this->_admin_page_title = $page_title;
558
+	}
559
+
560
+
561
+	/**
562
+	 * Used to register any global feature pointers for the admin page group.
563
+	 */
564
+	protected function _add_feature_pointers()
565
+	{
566
+	}
567
+
568
+
569
+	/**
570
+	 * Registers and enqueues any global scripts and styles for the entire admin page group.
571
+	 */
572
+	public function load_scripts_styles()
573
+	{
574
+		wp_register_style(
575
+			'events-admin-css',
576
+			EVENTS_ASSETS_URL . 'events-admin-page.css',
577
+			array(),
578
+			EVENT_ESPRESSO_VERSION
579
+		);
580
+		wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
581
+		wp_enqueue_style('events-admin-css');
582
+		wp_enqueue_style('ee-cat-admin');
583
+		// todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
584
+		// registers for all views
585
+		// scripts
586
+		wp_register_script(
587
+			'event_editor_js',
588
+			EVENTS_ASSETS_URL . 'event_editor.js',
589
+			array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
590
+			EVENT_ESPRESSO_VERSION,
591
+			true
592
+		);
593
+	}
594
+
595
+
596
+	/**
597
+	 * Enqueuing scripts and styles specific to this view
598
+	 */
599
+	public function load_scripts_styles_create_new()
600
+	{
601
+		$this->load_scripts_styles_edit();
602
+	}
603
+
604
+
605
+	/**
606
+	 * Enqueuing scripts and styles specific to this view
607
+	 */
608
+	public function load_scripts_styles_edit()
609
+	{
610
+		// styles
611
+		wp_enqueue_style('espresso-ui-theme');
612
+		wp_register_style(
613
+			'event-editor-css',
614
+			EVENTS_ASSETS_URL . 'event-editor.css',
615
+			array('ee-admin-css'),
616
+			EVENT_ESPRESSO_VERSION
617
+		);
618
+		wp_enqueue_style('event-editor-css');
619
+		// scripts
620
+		wp_register_script(
621
+			'event-datetime-metabox',
622
+			EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
623
+			array('event_editor_js', 'ee-datepicker'),
624
+			EVENT_ESPRESSO_VERSION
625
+		);
626
+		wp_enqueue_script('event-datetime-metabox');
627
+	}
628
+
629
+
630
+	/**
631
+	 * Populating the _views property for the category list table view.
632
+	 */
633
+	protected function _set_list_table_views_category_list()
634
+	{
635
+		$this->_views = array(
636
+			'all' => array(
637
+				'slug'        => 'all',
638
+				'label'       => esc_html__('All', 'event_espresso'),
639
+				'count'       => 0,
640
+				'bulk_action' => array(
641
+					'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
642
+				),
643
+			),
644
+		);
645
+	}
646
+
647
+
648
+	/**
649
+	 * For adding anything that fires on the admin_init hook for any route within this admin page group.
650
+	 */
651
+	public function admin_init()
652
+	{
653
+		EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
654
+			'Do you really want to delete this image? Please remember to update your event to complete the removal.',
655
+			'event_espresso'
656
+		);
657
+	}
658
+
659
+
660
+	/**
661
+	 * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
662
+	 * group.
663
+	 */
664
+	public function admin_notices()
665
+	{
666
+	}
667
+
668
+
669
+	/**
670
+	 * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
671
+	 * this admin page group.
672
+	 */
673
+	public function admin_footer_scripts()
674
+	{
675
+	}
676
+
677
+
678
+	/**
679
+	 * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
680
+	 * warning (via EE_Error::add_error());
681
+	 *
682
+	 * @param  EE_Event $event Event object
683
+	 * @param string    $req_type
684
+	 * @return void
685
+	 * @throws EE_Error
686
+	 * @access public
687
+	 */
688
+	public function verify_event_edit($event = null, $req_type = '')
689
+	{
690
+		// don't need to do this when processing
691
+		if (! empty($req_type)) {
692
+			return;
693
+		}
694
+		// no event?
695
+		if (empty($event)) {
696
+			// set event
697
+			$event = $this->_cpt_model_obj;
698
+		}
699
+		// STILL no event?
700
+		if (! $event instanceof EE_Event) {
701
+			return;
702
+		}
703
+		$orig_status = $event->status();
704
+		// first check if event is active.
705
+		if ($orig_status === EEM_Event::cancelled
706
+			|| $orig_status === EEM_Event::postponed
707
+			|| $event->is_expired()
708
+			|| $event->is_inactive()
709
+		) {
710
+			return;
711
+		}
712
+		// made it here so it IS active... next check that any of the tickets are sold.
713
+		if ($event->is_sold_out(true)) {
714
+			if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
715
+				EE_Error::add_attention(
716
+					sprintf(
717
+						esc_html__(
718
+							'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.',
719
+							'event_espresso'
720
+						),
721
+						EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
722
+					)
723
+				);
724
+			}
725
+			return;
726
+		} elseif ($orig_status === EEM_Event::sold_out) {
727
+			EE_Error::add_attention(
728
+				sprintf(
729
+					esc_html__(
730
+						'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.',
731
+						'event_espresso'
732
+					),
733
+					EEH_Template::pretty_status($event->status(), false, 'sentence')
734
+				)
735
+			);
736
+		}
737
+		// now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
738
+		if (! $event->tickets_on_sale()) {
739
+			return;
740
+		}
741
+		// made it here so show warning
742
+		$this->_edit_event_warning();
743
+	}
744
+
745
+
746
+	/**
747
+	 * This is the text used for when an event is being edited that is public and has tickets for sale.
748
+	 * When needed, hook this into a EE_Error::add_error() notice.
749
+	 *
750
+	 * @access protected
751
+	 * @return void
752
+	 */
753
+	protected function _edit_event_warning()
754
+	{
755
+		// we don't want to add warnings during these requests
756
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
757
+			return;
758
+		}
759
+		EE_Error::add_attention(
760
+			sprintf(
761
+				esc_html__(
762
+					'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
763
+					'event_espresso'
764
+				),
765
+				'<a class="espresso-help-tab-lnk">',
766
+				'</a>'
767
+			)
768
+		);
769
+	}
770
+
771
+
772
+	/**
773
+	 * When a user is creating a new event, notify them if they haven't set their timezone.
774
+	 * Otherwise, do the normal logic
775
+	 *
776
+	 * @return string
777
+	 * @throws \EE_Error
778
+	 */
779
+	protected function _create_new_cpt_item()
780
+	{
781
+		$has_timezone_string = get_option('timezone_string');
782
+		// only nag them about setting their timezone if it's their first event, and they haven't already done it
783
+		if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) {
784
+			EE_Error::add_attention(
785
+				sprintf(
786
+					__(
787
+						'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',
788
+						'event_espresso'
789
+					),
790
+					'<br>',
791
+					'<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
792
+					. EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
793
+					. '</select>',
794
+					'<button class="button button-secondary timezone-submit">',
795
+					'</button><span class="spinner"></span>'
796
+				),
797
+				__FILE__,
798
+				__FUNCTION__,
799
+				__LINE__
800
+			);
801
+		}
802
+		return parent::_create_new_cpt_item();
803
+	}
804
+
805
+
806
+	/**
807
+	 * Sets the _views property for the default route in this admin page group.
808
+	 */
809
+	protected function _set_list_table_views_default()
810
+	{
811
+		$this->_views = array(
812
+			'all'   => array(
813
+				'slug'        => 'all',
814
+				'label'       => esc_html__('View All Events', 'event_espresso'),
815
+				'count'       => 0,
816
+				'bulk_action' => array(
817
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
818
+				),
819
+			),
820
+			'draft' => array(
821
+				'slug'        => 'draft',
822
+				'label'       => esc_html__('Draft', 'event_espresso'),
823
+				'count'       => 0,
824
+				'bulk_action' => array(
825
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
826
+				),
827
+			),
828
+		);
829
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
830
+			$this->_views['trash'] = array(
831
+				'slug'        => 'trash',
832
+				'label'       => esc_html__('Trash', 'event_espresso'),
833
+				'count'       => 0,
834
+				'bulk_action' => array(
835
+					'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
836
+					'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
837
+				),
838
+			);
839
+		}
840
+	}
841
+
842
+
843
+	/**
844
+	 * Provides the legend item array for the default list table view.
845
+	 *
846
+	 * @return array
847
+	 */
848
+	protected function _event_legend_items()
849
+	{
850
+		$items = array(
851
+			'view_details'   => array(
852
+				'class' => 'dashicons dashicons-search',
853
+				'desc'  => esc_html__('View Event', 'event_espresso'),
854
+			),
855
+			'edit_event'     => array(
856
+				'class' => 'ee-icon ee-icon-calendar-edit',
857
+				'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
858
+			),
859
+			'view_attendees' => array(
860
+				'class' => 'dashicons dashicons-groups',
861
+				'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
862
+			),
863
+		);
864
+		$items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
865
+		$statuses = array(
866
+			'sold_out_status'  => array(
867
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
868
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
869
+			),
870
+			'active_status'    => array(
871
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
872
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
873
+			),
874
+			'upcoming_status'  => array(
875
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
876
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
877
+			),
878
+			'postponed_status' => array(
879
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
880
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
881
+			),
882
+			'cancelled_status' => array(
883
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
884
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
885
+			),
886
+			'expired_status'   => array(
887
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
888
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
889
+			),
890
+			'inactive_status'  => array(
891
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
892
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
893
+			),
894
+		);
895
+		$statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
896
+		return array_merge($items, $statuses);
897
+	}
898
+
899
+
900
+	/**
901
+	 * @return EEM_Event
902
+	 */
903
+	private function _event_model()
904
+	{
905
+		if (! $this->_event_model instanceof EEM_Event) {
906
+			$this->_event_model = EE_Registry::instance()->load_model('Event');
907
+		}
908
+		return $this->_event_model;
909
+	}
910
+
911
+
912
+	/**
913
+	 * Adds extra buttons to the WP CPT permalink field row.
914
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
915
+	 *
916
+	 * @param  string $return    the current html
917
+	 * @param  int    $id        the post id for the page
918
+	 * @param  string $new_title What the title is
919
+	 * @param  string $new_slug  what the slug is
920
+	 * @return string            The new html string for the permalink area
921
+	 */
922
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
923
+	{
924
+		// make sure this is only when editing
925
+		if (! empty($id)) {
926
+			$post = get_post($id);
927
+			$return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
928
+					   . esc_html__('Shortcode', 'event_espresso')
929
+					   . '</a> ';
930
+			$return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
931
+					   . $post->ID
932
+					   . ']">';
933
+		}
934
+		return $return;
935
+	}
936
+
937
+
938
+	/**
939
+	 * _events_overview_list_table
940
+	 * This contains the logic for showing the events_overview list
941
+	 *
942
+	 * @access protected
943
+	 * @return void
944
+	 * @throws \EE_Error
945
+	 */
946
+	protected function _events_overview_list_table()
947
+	{
948
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
949
+		$this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table'])
950
+			? (array) $this->_template_args['after_list_table']
951
+			: array();
952
+		$this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
953
+				. EEH_Template::get_button_or_link(
954
+					get_post_type_archive_link('espresso_events'),
955
+					esc_html__("View Event Archive Page", "event_espresso"),
956
+					'button'
957
+				);
958
+		$this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
959
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
960
+			'create_new',
961
+			'add',
962
+			array(),
963
+			'add-new-h2'
964
+		);
965
+		$this->display_admin_list_table_page_with_no_sidebar();
966
+	}
967
+
968
+
969
+	/**
970
+	 * this allows for extra misc actions in the default WP publish box
971
+	 *
972
+	 * @return void
973
+	 */
974
+	public function extra_misc_actions_publish_box()
975
+	{
976
+		$this->_generate_publish_box_extra_content();
977
+	}
978
+
979
+
980
+	/**
981
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
982
+	 * saved.
983
+	 * Typically you would use this to save any additional data.
984
+	 * Keep in mind also that "save_post" runs on EVERY post update to the database.
985
+	 * ALSO very important.  When a post transitions from scheduled to published,
986
+	 * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
987
+	 * other meta saves. So MAKE sure that you handle this accordingly.
988
+	 *
989
+	 * @access protected
990
+	 * @abstract
991
+	 * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
992
+	 * @param  object $post    The post object of the cpt that was saved.
993
+	 * @return void
994
+	 * @throws \EE_Error
995
+	 */
996
+	protected function _insert_update_cpt_item($post_id, $post)
997
+	{
998
+		if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
999
+			// get out we're not processing an event save.
1000
+			return;
1001
+		}
1002
+		$event_values = array(
1003
+			'EVT_display_desc'                => ! empty($this->_req_data['display_desc']) ? 1 : 0,
1004
+			'EVT_display_ticket_selector'     => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0,
1005
+			'EVT_additional_limit'            => min(
1006
+				apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1007
+				! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null
1008
+			),
1009
+			'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status'])
1010
+				? $this->_req_data['EVT_default_registration_status']
1011
+				: EE_Registry::instance()->CFG->registration->default_STS_ID,
1012
+			'EVT_member_only'                 => ! empty($this->_req_data['member_only']) ? 1 : 0,
1013
+			'EVT_allow_overflow'              => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
1014
+			'EVT_timezone_string'             => ! empty($this->_req_data['timezone_string'])
1015
+				? $this->_req_data['timezone_string'] : null,
1016
+			'EVT_external_URL'                => ! empty($this->_req_data['externalURL'])
1017
+				? $this->_req_data['externalURL'] : null,
1018
+			'EVT_phone'                       => ! empty($this->_req_data['event_phone'])
1019
+				? $this->_req_data['event_phone'] : null,
1020
+		);
1021
+		// update event
1022
+		$success = $this->_event_model()->update_by_ID($event_values, $post_id);
1023
+		// 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!
1024
+		$get_one_where = array(
1025
+			$this->_event_model()->primary_key_name() => $post_id,
1026
+			'OR'                                      => array(
1027
+				'status'   => $post->post_status,
1028
+				// if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1029
+				// but the returned object here has a status of "publish", so use the original post status as well
1030
+				'status*1' => $this->_req_data['original_post_status'],
1031
+			),
1032
+		);
1033
+		$event = $this->_event_model()->get_one(array($get_one_where));
1034
+		// the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
1035
+		$event_update_callbacks = apply_filters(
1036
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1037
+			array(
1038
+				array($this, '_default_venue_update'),
1039
+				array($this, '_default_tickets_update'),
1040
+			)
1041
+		);
1042
+		$att_success = true;
1043
+		foreach ($event_update_callbacks as $e_callback) {
1044
+			$_success = is_callable($e_callback)
1045
+				? call_user_func($e_callback, $event, $this->_req_data)
1046
+				: false;
1047
+			// if ANY of these updates fail then we want the appropriate global error message
1048
+			$att_success = ! $att_success ? $att_success : $_success;
1049
+		}
1050
+		// any errors?
1051
+		if ($success && false === $att_success) {
1052
+			EE_Error::add_error(
1053
+				esc_html__(
1054
+					'Event Details saved successfully but something went wrong with saving attachments.',
1055
+					'event_espresso'
1056
+				),
1057
+				__FILE__,
1058
+				__FUNCTION__,
1059
+				__LINE__
1060
+			);
1061
+		} elseif ($success === false) {
1062
+			EE_Error::add_error(
1063
+				esc_html__('Event Details did not save successfully.', 'event_espresso'),
1064
+				__FILE__,
1065
+				__FUNCTION__,
1066
+				__LINE__
1067
+			);
1068
+		}
1069
+	}
1070
+
1071
+
1072
+	/**
1073
+	 * @see parent::restore_item()
1074
+	 * @param int $post_id
1075
+	 * @param int $revision_id
1076
+	 */
1077
+	protected function _restore_cpt_item($post_id, $revision_id)
1078
+	{
1079
+		// copy existing event meta to new post
1080
+		$post_evt = $this->_event_model()->get_one_by_ID($post_id);
1081
+		if ($post_evt instanceof EE_Event) {
1082
+			// meta revision restore
1083
+			$post_evt->restore_revision($revision_id);
1084
+			// related objs restore
1085
+			$post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price'));
1086
+		}
1087
+	}
1088
+
1089
+
1090
+	/**
1091
+	 * Attach the venue to the Event
1092
+	 *
1093
+	 * @param  \EE_Event $evtobj Event Object to add the venue to
1094
+	 * @param  array     $data   The request data from the form
1095
+	 * @return bool           Success or fail.
1096
+	 */
1097
+	protected function _default_venue_update(\EE_Event $evtobj, $data)
1098
+	{
1099
+		require_once(EE_MODELS . 'EEM_Venue.model.php');
1100
+		$venue_model = EE_Registry::instance()->load_model('Venue');
1101
+		$rows_affected = null;
1102
+		$venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1103
+		// very important.  If we don't have a venue name...
1104
+		// then we'll get out because not necessary to create empty venue
1105
+		if (empty($data['venue_title'])) {
1106
+			return false;
1107
+		}
1108
+		$venue_array = array(
1109
+			'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1110
+			'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1111
+			'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1112
+			'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1113
+			'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1114
+				: null,
1115
+			'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1116
+			'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1117
+			'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1118
+			'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1119
+			'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1120
+			'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1121
+			'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1122
+			'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1123
+			'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1124
+			'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1125
+			'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1126
+			'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1127
+			'status'              => 'publish',
1128
+		);
1129
+		// if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1130
+		if (! empty($venue_id)) {
1131
+			$update_where = array($venue_model->primary_key_name() => $venue_id);
1132
+			$rows_affected = $venue_model->update($venue_array, array($update_where));
1133
+			// 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.
1134
+			$evtobj->_add_relation_to($venue_id, 'Venue');
1135
+			return $rows_affected > 0 ? true : false;
1136
+		} else {
1137
+			// we insert the venue
1138
+			$venue_id = $venue_model->insert($venue_array);
1139
+			$evtobj->_add_relation_to($venue_id, 'Venue');
1140
+			return ! empty($venue_id) ? true : false;
1141
+		}
1142
+		// when we have the ancestor come in it's already been handled by the revision save.
1143
+	}
1144
+
1145
+
1146
+	/**
1147
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
1148
+	 *
1149
+	 * @param  EE_Event $evtobj The Event object we're attaching data to
1150
+	 * @param  array    $data   The request data from the form
1151
+	 * @return array
1152
+	 */
1153
+	protected function _default_tickets_update(EE_Event $evtobj, $data)
1154
+	{
1155
+		$success = true;
1156
+		$saved_dtt = null;
1157
+		$saved_tickets = array();
1158
+		$incoming_date_formats = array('Y-m-d', 'h:i a');
1159
+		foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1160
+			// trim all values to ensure any excess whitespace is removed.
1161
+			$dtt = array_map('trim', $dtt);
1162
+			$dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']
1163
+				: $dtt['DTT_EVT_start'];
1164
+			$datetime_values = array(
1165
+				'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1166
+				'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1167
+				'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1168
+				'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1169
+				'DTT_order'     => $row,
1170
+			);
1171
+			// 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.
1172
+			if (! empty($dtt['DTT_ID'])) {
1173
+				$DTM = EE_Registry::instance()
1174
+								  ->load_model('Datetime', array($evtobj->get_timezone()))
1175
+								  ->get_one_by_ID($dtt['DTT_ID']);
1176
+				$DTM->set_date_format($incoming_date_formats[0]);
1177
+				$DTM->set_time_format($incoming_date_formats[1]);
1178
+				foreach ($datetime_values as $field => $value) {
1179
+					$DTM->set($field, $value);
1180
+				}
1181
+				// 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.
1182
+				$saved_dtts[ $DTM->ID() ] = $DTM;
1183
+			} else {
1184
+				$DTM = EE_Registry::instance()->load_class(
1185
+					'Datetime',
1186
+					array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats),
1187
+					false,
1188
+					false
1189
+				);
1190
+				foreach ($datetime_values as $field => $value) {
1191
+					$DTM->set($field, $value);
1192
+				}
1193
+			}
1194
+			$DTM->save();
1195
+			$DTT = $evtobj->_add_relation_to($DTM, 'Datetime');
1196
+			// load DTT helper
1197
+			// 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.
1198
+			if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) {
1199
+				$DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start'));
1200
+				$DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');
1201
+				$DTT->save();
1202
+			}
1203
+			// 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.
1204
+			$saved_dtt = $DTT;
1205
+			$success = ! $success ? $success : $DTT;
1206
+			// if ANY of these updates fail then we want the appropriate global error message.
1207
+			// //todo this is actually sucky we need a better error message but this is what it is for now.
1208
+		}
1209
+		// no dtts get deleted so we don't do any of that logic here.
1210
+		// update tickets next
1211
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
1212
+		foreach ($data['edit_tickets'] as $row => $tkt) {
1213
+			$incoming_date_formats = array('Y-m-d', 'h:i a');
1214
+			$update_prices = false;
1215
+			$ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1216
+				? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0;
1217
+			// trim inputs to ensure any excess whitespace is removed.
1218
+			$tkt = array_map('trim', $tkt);
1219
+			if (empty($tkt['TKT_start_date'])) {
1220
+				// let's use now in the set timezone.
1221
+				$now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1222
+				$tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1223
+			}
1224
+			if (empty($tkt['TKT_end_date'])) {
1225
+				// use the start date of the first datetime
1226
+				$dtt = $evtobj->first_datetime();
1227
+				$tkt['TKT_end_date'] = $dtt->start_date_and_time(
1228
+					$incoming_date_formats[0],
1229
+					$incoming_date_formats[1]
1230
+				);
1231
+			}
1232
+			$TKT_values = array(
1233
+				'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1234
+				'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1235
+				'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1236
+				'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1237
+				'TKT_start_date'  => $tkt['TKT_start_date'],
1238
+				'TKT_end_date'    => $tkt['TKT_end_date'],
1239
+				'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1240
+				'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1241
+				'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1242
+				'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1243
+				'TKT_row'         => $row,
1244
+				'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1245
+				'TKT_price'       => $ticket_price,
1246
+			);
1247
+			// 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.
1248
+			if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1249
+				$TKT_values['TKT_ID'] = 0;
1250
+				$TKT_values['TKT_is_default'] = 0;
1251
+				$TKT_values['TKT_price'] = $ticket_price;
1252
+				$update_prices = true;
1253
+			}
1254
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
1255
+			// 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.
1256
+			// 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.
1257
+			if (! empty($tkt['TKT_ID'])) {
1258
+				$TKT = EE_Registry::instance()
1259
+								  ->load_model('Ticket', array($evtobj->get_timezone()))
1260
+								  ->get_one_by_ID($tkt['TKT_ID']);
1261
+				if ($TKT instanceof EE_Ticket) {
1262
+					$ticket_sold = $TKT->count_related(
1263
+						'Registration',
1264
+						array(
1265
+							array(
1266
+								'STS_ID' => array(
1267
+									'NOT IN',
1268
+									array(EEM_Registration::status_id_incomplete),
1269
+								),
1270
+							),
1271
+						)
1272
+					) > 0 ? true : false;
1273
+					// 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.
1274
+					$create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price')
1275
+									  && ! $TKT->get('TKT_deleted');
1276
+					$TKT->set_date_format($incoming_date_formats[0]);
1277
+					$TKT->set_time_format($incoming_date_formats[1]);
1278
+					// set new values
1279
+					foreach ($TKT_values as $field => $value) {
1280
+						if ($field == 'TKT_qty') {
1281
+							$TKT->set_qty($value);
1282
+						} else {
1283
+							$TKT->set($field, $value);
1284
+						}
1285
+					}
1286
+					// if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
1287
+					if ($create_new_TKT) {
1288
+						// archive the old ticket first
1289
+						$TKT->set('TKT_deleted', 1);
1290
+						$TKT->save();
1291
+						// make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1292
+						$saved_tickets[ $TKT->ID() ] = $TKT;
1293
+						// 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.
1294
+						$TKT = clone $TKT;
1295
+						$TKT->set('TKT_ID', 0);
1296
+						$TKT->set('TKT_deleted', 0);
1297
+						$TKT->set('TKT_price', $ticket_price);
1298
+						$TKT->set('TKT_sold', 0);
1299
+						// now we need to make sure that $new prices are created as well and attached to new ticket.
1300
+						$update_prices = true;
1301
+					}
1302
+					// make sure price is set if it hasn't been already
1303
+					$TKT->set('TKT_price', $ticket_price);
1304
+				}
1305
+			} else {
1306
+				// no TKT_id so a new TKT
1307
+				$TKT_values['TKT_price'] = $ticket_price;
1308
+				$TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false);
1309
+				if ($TKT instanceof EE_Ticket) {
1310
+					// need to reset values to properly account for the date formats
1311
+					$TKT->set_date_format($incoming_date_formats[0]);
1312
+					$TKT->set_time_format($incoming_date_formats[1]);
1313
+					$TKT->set_timezone($evtobj->get_timezone());
1314
+					// set new values
1315
+					foreach ($TKT_values as $field => $value) {
1316
+						if ($field == 'TKT_qty') {
1317
+							$TKT->set_qty($value);
1318
+						} else {
1319
+							$TKT->set($field, $value);
1320
+						}
1321
+					}
1322
+					$update_prices = true;
1323
+				}
1324
+			}
1325
+			// cap ticket qty by datetime reg limits
1326
+			$TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1327
+			// update ticket.
1328
+			$TKT->save();
1329
+			// 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.
1330
+			if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1331
+				$TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1332
+				$TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1333
+				$TKT->save();
1334
+			}
1335
+			// initially let's add the ticket to the dtt
1336
+			$saved_dtt->_add_relation_to($TKT, 'Ticket');
1337
+			$saved_tickets[ $TKT->ID() ] = $TKT;
1338
+			// add prices to ticket
1339
+			$this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices);
1340
+		}
1341
+		// 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.
1342
+		$old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
1343
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1344
+		foreach ($tickets_removed as $id) {
1345
+			$id = absint($id);
1346
+			// get the ticket for this id
1347
+			$tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1348
+			// 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)
1349
+			$dtts = $tkt_to_remove->get_many_related('Datetime');
1350
+			foreach ($dtts as $dtt) {
1351
+				$tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1352
+			}
1353
+			// 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))
1354
+			$tkt_to_remove->delete_related_permanently('Price');
1355
+			// finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1356
+			$tkt_to_remove->delete_permanently();
1357
+		}
1358
+		return array($saved_dtt, $saved_tickets);
1359
+	}
1360
+
1361
+
1362
+	/**
1363
+	 * This attaches a list of given prices to a ticket.
1364
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1365
+	 * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1366
+	 * price info and prices are automatically "archived" via the ticket.
1367
+	 *
1368
+	 * @access  private
1369
+	 * @param array     $prices     Array of prices from the form.
1370
+	 * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1371
+	 * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1372
+	 * @return  void
1373
+	 */
1374
+	private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1375
+	{
1376
+		foreach ($prices as $row => $prc) {
1377
+			$PRC_values = array(
1378
+				'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1379
+				'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1380
+				'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1381
+				'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1382
+				'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1383
+				'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1384
+				'PRC_order'      => $row,
1385
+			);
1386
+			if ($new_prices || empty($PRC_values['PRC_ID'])) {
1387
+				$PRC_values['PRC_ID'] = 0;
1388
+				$PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false);
1389
+			} else {
1390
+				$PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
1391
+				// update this price with new values
1392
+				foreach ($PRC_values as $field => $newprc) {
1393
+					$PRC->set($field, $newprc);
1394
+				}
1395
+				$PRC->save();
1396
+			}
1397
+			$ticket->_add_relation_to($PRC, 'Price');
1398
+		}
1399
+	}
1400
+
1401
+
1402
+	/**
1403
+	 * Add in our autosave ajax handlers
1404
+	 *
1405
+	 */
1406
+	protected function _ee_autosave_create_new()
1407
+	{
1408
+	}
1409
+
1410
+
1411
+	/**
1412
+	 * More autosave handlers.
1413
+	 */
1414
+	protected function _ee_autosave_edit()
1415
+	{
1416
+		return; // TEMPORARILY EXITING CAUSE THIS IS A TODO
1417
+	}
1418
+
1419
+
1420
+	/**
1421
+	 *    _generate_publish_box_extra_content
1422
+	 */
1423
+	private function _generate_publish_box_extra_content()
1424
+	{
1425
+		// load formatter helper
1426
+		// args for getting related registrations
1427
+		$approved_query_args = array(
1428
+			array(
1429
+				'REG_deleted' => 0,
1430
+				'STS_ID'      => EEM_Registration::status_id_approved,
1431
+			),
1432
+		);
1433
+		$not_approved_query_args = array(
1434
+			array(
1435
+				'REG_deleted' => 0,
1436
+				'STS_ID'      => EEM_Registration::status_id_not_approved,
1437
+			),
1438
+		);
1439
+		$pending_payment_query_args = array(
1440
+			array(
1441
+				'REG_deleted' => 0,
1442
+				'STS_ID'      => EEM_Registration::status_id_pending_payment,
1443
+			),
1444
+		);
1445
+		// publish box
1446
+		$publish_box_extra_args = array(
1447
+			'view_approved_reg_url'        => add_query_arg(
1448
+				array(
1449
+					'action'      => 'default',
1450
+					'event_id'    => $this->_cpt_model_obj->ID(),
1451
+					'_reg_status' => EEM_Registration::status_id_approved,
1452
+				),
1453
+				REG_ADMIN_URL
1454
+			),
1455
+			'view_not_approved_reg_url'    => add_query_arg(
1456
+				array(
1457
+					'action'      => 'default',
1458
+					'event_id'    => $this->_cpt_model_obj->ID(),
1459
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1460
+				),
1461
+				REG_ADMIN_URL
1462
+			),
1463
+			'view_pending_payment_reg_url' => add_query_arg(
1464
+				array(
1465
+					'action'      => 'default',
1466
+					'event_id'    => $this->_cpt_model_obj->ID(),
1467
+					'_reg_status' => EEM_Registration::status_id_pending_payment,
1468
+				),
1469
+				REG_ADMIN_URL
1470
+			),
1471
+			'approved_regs'                => $this->_cpt_model_obj->count_related(
1472
+				'Registration',
1473
+				$approved_query_args
1474
+			),
1475
+			'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1476
+				'Registration',
1477
+				$not_approved_query_args
1478
+			),
1479
+			'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1480
+				'Registration',
1481
+				$pending_payment_query_args
1482
+			),
1483
+			'misc_pub_section_class'       => apply_filters(
1484
+				'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1485
+				'misc-pub-section'
1486
+			),
1487
+		);
1488
+		ob_start();
1489
+		do_action(
1490
+			'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1491
+			$this->_cpt_model_obj
1492
+		);
1493
+		$publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1494
+		// load template
1495
+		EEH_Template::display_template(
1496
+			EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1497
+			$publish_box_extra_args
1498
+		);
1499
+	}
1500
+
1501
+
1502
+	/**
1503
+	 * @return EE_Event
1504
+	 */
1505
+	public function get_event_object()
1506
+	{
1507
+		return $this->_cpt_model_obj;
1508
+	}
1509
+
1510
+
1511
+
1512
+
1513
+	/** METABOXES * */
1514
+	/**
1515
+	 * _register_event_editor_meta_boxes
1516
+	 * add all metaboxes related to the event_editor
1517
+	 *
1518
+	 * @return void
1519
+	 */
1520
+	protected function _register_event_editor_meta_boxes()
1521
+	{
1522
+		$this->verify_cpt_object();
1523
+		add_meta_box(
1524
+			'espresso_event_editor_tickets',
1525
+			esc_html__('Event Datetime & Ticket', 'event_espresso'),
1526
+			array($this, 'ticket_metabox'),
1527
+			$this->page_slug,
1528
+			'normal',
1529
+			'high'
1530
+		);
1531
+		add_meta_box(
1532
+			'espresso_event_editor_event_options',
1533
+			esc_html__('Event Registration Options', 'event_espresso'),
1534
+			array($this, 'registration_options_meta_box'),
1535
+			$this->page_slug,
1536
+			'side',
1537
+			'default'
1538
+		);
1539
+		// NOTE: if you're looking for other metaboxes in here,
1540
+		// where a metabox has a related management page in the admin
1541
+		// you will find it setup in the related management page's "_Hooks" file.
1542
+		// i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1543
+	}
1544
+
1545
+
1546
+	/**
1547
+	 * @throws DomainException
1548
+	 * @throws EE_Error
1549
+	 */
1550
+	public function ticket_metabox()
1551
+	{
1552
+		$existing_datetime_ids = $existing_ticket_ids = array();
1553
+		// defaults for template args
1554
+		$template_args = array(
1555
+			'existing_datetime_ids'    => '',
1556
+			'event_datetime_help_link' => '',
1557
+			'ticket_options_help_link' => '',
1558
+			'time'                     => null,
1559
+			'ticket_rows'              => '',
1560
+			'existing_ticket_ids'      => '',
1561
+			'total_ticket_rows'        => 1,
1562
+			'ticket_js_structure'      => '',
1563
+			'trash_icon'               => 'ee-lock-icon',
1564
+			'disabled'                 => '',
1565
+		);
1566
+		$event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1567
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1568
+		/**
1569
+		 * 1. Start with retrieving Datetimes
1570
+		 * 2. Fore each datetime get related tickets
1571
+		 * 3. For each ticket get related prices
1572
+		 */
1573
+		$times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id);
1574
+		/** @type EE_Datetime $first_datetime */
1575
+		$first_datetime = reset($times);
1576
+		// do we get related tickets?
1577
+		if ($first_datetime instanceof EE_Datetime
1578
+			&& $first_datetime->ID() !== 0
1579
+		) {
1580
+			$existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1581
+			$template_args['time'] = $first_datetime;
1582
+			$related_tickets = $first_datetime->tickets(
1583
+				array(
1584
+					array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)),
1585
+					'default_where_conditions' => 'none',
1586
+				)
1587
+			);
1588
+			if (! empty($related_tickets)) {
1589
+				$template_args['total_ticket_rows'] = count($related_tickets);
1590
+				$row = 0;
1591
+				foreach ($related_tickets as $ticket) {
1592
+					$existing_ticket_ids[] = $ticket->get('TKT_ID');
1593
+					$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1594
+					$row++;
1595
+				}
1596
+			} else {
1597
+				$template_args['total_ticket_rows'] = 1;
1598
+				/** @type EE_Ticket $ticket */
1599
+				$ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1600
+				$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1601
+			}
1602
+		} else {
1603
+			$template_args['time'] = $times[0];
1604
+			/** @type EE_Ticket $ticket */
1605
+			$ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
1606
+			$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]);
1607
+			// NOTE: we're just sending the first default row
1608
+			// (decaf can't manage default tickets so this should be sufficient);
1609
+		}
1610
+		$template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1611
+			'event_editor_event_datetimes_help_tab'
1612
+		);
1613
+		$template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1614
+		$template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1615
+		$template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1616
+		$template_args['ticket_js_structure'] = $this->_get_ticket_row(
1617
+			EE_Registry::instance()->load_model('Ticket')->create_default_object(),
1618
+			true
1619
+		);
1620
+		$template = apply_filters(
1621
+			'FHEE__Events_Admin_Page__ticket_metabox__template',
1622
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1623
+		);
1624
+		EEH_Template::display_template($template, $template_args);
1625
+	}
1626
+
1627
+
1628
+	/**
1629
+	 * Setup an individual ticket form for the decaf event editor page
1630
+	 *
1631
+	 * @access private
1632
+	 * @param  EE_Ticket $ticket   the ticket object
1633
+	 * @param  boolean   $skeleton whether we're generating a skeleton for js manipulation
1634
+	 * @param int        $row
1635
+	 * @return string generated html for the ticket row.
1636
+	 */
1637
+	private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1638
+	{
1639
+		$template_args = array(
1640
+			'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1641
+			'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1642
+				: '',
1643
+			'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1644
+			'TKT_ID'              => $ticket->get('TKT_ID'),
1645
+			'TKT_name'            => $ticket->get('TKT_name'),
1646
+			'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1647
+			'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1648
+			'TKT_is_default'      => $ticket->get('TKT_is_default'),
1649
+			'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1650
+			'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1651
+			'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1652
+			'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1653
+									 && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1654
+				? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1655
+			'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1656
+				: ' disabled=disabled',
1657
+		);
1658
+		$price = $ticket->ID() !== 0
1659
+			? $ticket->get_first_related('Price', array('default_where_conditions' => 'none'))
1660
+			: EE_Registry::instance()->load_model('Price')->create_default_object();
1661
+		$price_args = array(
1662
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1663
+			'PRC_amount'            => $price->get('PRC_amount'),
1664
+			'PRT_ID'                => $price->get('PRT_ID'),
1665
+			'PRC_ID'                => $price->get('PRC_ID'),
1666
+			'PRC_is_default'        => $price->get('PRC_is_default'),
1667
+		);
1668
+		// make sure we have default start and end dates if skeleton
1669
+		// handle rows that should NOT be empty
1670
+		if (empty($template_args['TKT_start_date'])) {
1671
+			// if empty then the start date will be now.
1672
+			$template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1673
+		}
1674
+		if (empty($template_args['TKT_end_date'])) {
1675
+			// get the earliest datetime (if present);
1676
+			$earliest_dtt = $this->_cpt_model_obj->ID() > 0
1677
+				? $this->_cpt_model_obj->get_first_related(
1678
+					'Datetime',
1679
+					array('order_by' => array('DTT_EVT_start' => 'ASC'))
1680
+				)
1681
+				: null;
1682
+			if (! empty($earliest_dtt)) {
1683
+				$template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1684
+			} else {
1685
+				$template_args['TKT_end_date'] = date(
1686
+					'Y-m-d h:i a',
1687
+					mktime(0, 0, 0, date("m"), date("d") + 7, date("Y"))
1688
+				);
1689
+			}
1690
+		}
1691
+		$template_args = array_merge($template_args, $price_args);
1692
+		$template = apply_filters(
1693
+			'FHEE__Events_Admin_Page__get_ticket_row__template',
1694
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1695
+			$ticket
1696
+		);
1697
+		return EEH_Template::display_template($template, $template_args, true);
1698
+	}
1699
+
1700
+
1701
+	/**
1702
+	 * @throws DomainException
1703
+	 */
1704
+	public function registration_options_meta_box()
1705
+	{
1706
+		$yes_no_values = array(
1707
+			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
1708
+			array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
1709
+		);
1710
+		$default_reg_status_values = EEM_Registration::reg_status_array(
1711
+			array(
1712
+				EEM_Registration::status_id_cancelled,
1713
+				EEM_Registration::status_id_declined,
1714
+				EEM_Registration::status_id_incomplete,
1715
+			),
1716
+			true
1717
+		);
1718
+		// $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1719
+		$template_args['_event'] = $this->_cpt_model_obj;
1720
+		$template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1721
+		$template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1722
+		$template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1723
+			'default_reg_status',
1724
+			$default_reg_status_values,
1725
+			$this->_cpt_model_obj->default_registration_status()
1726
+		);
1727
+		$template_args['display_description'] = EEH_Form_Fields::select_input(
1728
+			'display_desc',
1729
+			$yes_no_values,
1730
+			$this->_cpt_model_obj->display_description()
1731
+		);
1732
+		$template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1733
+			'display_ticket_selector',
1734
+			$yes_no_values,
1735
+			$this->_cpt_model_obj->display_ticket_selector(),
1736
+			'',
1737
+			'',
1738
+			false
1739
+		);
1740
+		$template_args['additional_registration_options'] = apply_filters(
1741
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1742
+			'',
1743
+			$template_args,
1744
+			$yes_no_values,
1745
+			$default_reg_status_values
1746
+		);
1747
+		EEH_Template::display_template(
1748
+			EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1749
+			$template_args
1750
+		);
1751
+	}
1752
+
1753
+
1754
+	/**
1755
+	 * _get_events()
1756
+	 * This method simply returns all the events (for the given _view and paging)
1757
+	 *
1758
+	 * @access public
1759
+	 * @param int  $per_page     count of items per page (20 default);
1760
+	 * @param int  $current_page what is the current page being viewed.
1761
+	 * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1762
+	 *                           If FALSE then we return an array of event objects
1763
+	 *                           that match the given _view and paging parameters.
1764
+	 * @return array an array of event objects.
1765
+	 */
1766
+	public function get_events($per_page = 10, $current_page = 1, $count = false)
1767
+	{
1768
+		$EEME = $this->_event_model();
1769
+		$offset = ($current_page - 1) * $per_page;
1770
+		$limit = $count ? null : $offset . ',' . $per_page;
1771
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1772
+		$order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1773
+		if (isset($this->_req_data['month_range'])) {
1774
+			$pieces = explode(' ', $this->_req_data['month_range'], 3);
1775
+			// simulate the FIRST day of the month, that fixes issues for months like February
1776
+			// where PHP doesn't know what to assume for date.
1777
+			// @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1778
+			$month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1779
+			$year_r = ! empty($pieces[1]) ? $pieces[1] : '';
1780
+		}
1781
+		$where = array();
1782
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1783
+		// determine what post_status our condition will have for the query.
1784
+		switch ($status) {
1785
+			case 'month':
1786
+			case 'today':
1787
+			case null:
1788
+			case 'all':
1789
+				break;
1790
+			case 'draft':
1791
+				$where['status'] = array('IN', array('draft', 'auto-draft'));
1792
+				break;
1793
+			default:
1794
+				$where['status'] = $status;
1795
+		}
1796
+		// categories?
1797
+		$category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1798
+			? $this->_req_data['EVT_CAT'] : null;
1799
+		if (! empty($category)) {
1800
+			$where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1801
+			$where['Term_Taxonomy.term_id'] = $category;
1802
+		}
1803
+		// date where conditions
1804
+		$start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1805
+		if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1806
+			$DateTime = new DateTime(
1807
+				$year_r . '-' . $month_r . '-01 00:00:00',
1808
+				new DateTimeZone(EEM_Datetime::instance()->get_timezone())
1809
+			);
1810
+			$start = $DateTime->format(implode(' ', $start_formats));
1811
+			$end = $DateTime->setDate(
1812
+				$year_r,
1813
+				$month_r,
1814
+				$DateTime
1815
+					->format('t')
1816
+			)->setTime(23, 59, 59)
1817
+							->format(implode(' ', $start_formats));
1818
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1819
+		} elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') {
1820
+			$DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1821
+			$start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1822
+			$end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1823
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1824
+		} elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') {
1825
+			$now = date('Y-m-01');
1826
+			$DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1827
+			$start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1828
+			$end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1829
+							->setTime(23, 59, 59)
1830
+							->format(implode(' ', $start_formats));
1831
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1832
+		}
1833
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1834
+			$where['EVT_wp_user'] = get_current_user_id();
1835
+		} else {
1836
+			if (! isset($where['status'])) {
1837
+				if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1838
+					$where['OR'] = array(
1839
+						'status*restrict_private' => array('!=', 'private'),
1840
+						'AND'                     => array(
1841
+							'status*inclusive' => array('=', 'private'),
1842
+							'EVT_wp_user'      => get_current_user_id(),
1843
+						),
1844
+					);
1845
+				}
1846
+			}
1847
+		}
1848
+		if (isset($this->_req_data['EVT_wp_user'])) {
1849
+			if ($this->_req_data['EVT_wp_user'] != get_current_user_id()
1850
+				&& EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1851
+			) {
1852
+				$where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
1853
+			}
1854
+		}
1855
+		// search query handling
1856
+		if (isset($this->_req_data['s'])) {
1857
+			$search_string = '%' . $this->_req_data['s'] . '%';
1858
+			$where['OR'] = array(
1859
+				'EVT_name'       => array('LIKE', $search_string),
1860
+				'EVT_desc'       => array('LIKE', $search_string),
1861
+				'EVT_short_desc' => array('LIKE', $search_string),
1862
+			);
1863
+		}
1864
+		// filter events by venue.
1865
+		if (isset($this->_req_data['venue']) && ! empty($this->_req_data['venue'])) {
1866
+			$where['Venue.VNU_ID'] = absint($this->_req_data['venue']);
1867
+		}
1868
+		$where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
1869
+		$query_params = apply_filters(
1870
+			'FHEE__Events_Admin_Page__get_events__query_params',
1871
+			array(
1872
+				$where,
1873
+				'limit'    => $limit,
1874
+				'order_by' => $orderby,
1875
+				'order'    => $order,
1876
+				'group_by' => 'EVT_ID',
1877
+			),
1878
+			$this->_req_data
1879
+		);
1880
+		// let's first check if we have special requests coming in.
1881
+		if (isset($this->_req_data['active_status'])) {
1882
+			switch ($this->_req_data['active_status']) {
1883
+				case 'upcoming':
1884
+					return $EEME->get_upcoming_events($query_params, $count);
1885
+					break;
1886
+				case 'expired':
1887
+					return $EEME->get_expired_events($query_params, $count);
1888
+					break;
1889
+				case 'active':
1890
+					return $EEME->get_active_events($query_params, $count);
1891
+					break;
1892
+				case 'inactive':
1893
+					return $EEME->get_inactive_events($query_params, $count);
1894
+					break;
1895
+			}
1896
+		}
1897
+
1898
+		$events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params);
1899
+		return $events;
1900
+	}
1901
+
1902
+
1903
+	/**
1904
+	 * handling for WordPress CPT actions (trash, restore, delete)
1905
+	 *
1906
+	 * @param string $post_id
1907
+	 */
1908
+	public function trash_cpt_item($post_id)
1909
+	{
1910
+		$this->_req_data['EVT_ID'] = $post_id;
1911
+		$this->_trash_or_restore_event('trash', false);
1912
+	}
1913
+
1914
+
1915
+	/**
1916
+	 * @param string $post_id
1917
+	 */
1918
+	public function restore_cpt_item($post_id)
1919
+	{
1920
+		$this->_req_data['EVT_ID'] = $post_id;
1921
+		$this->_trash_or_restore_event('draft', false);
1922
+	}
1923
+
1924
+
1925
+	/**
1926
+	 * @param string $post_id
1927
+	 */
1928
+	public function delete_cpt_item($post_id)
1929
+	{
1930
+		throw new EE_Error(esc_html__('Please contact Event Espresso support with the details of what you did to produce this error.', 'event_espresso'));
1931
+		$this->_req_data['EVT_ID'] = $post_id;
1932
+		$this->_delete_event();
1933
+	}
1934
+
1935
+
1936
+	/**
1937
+	 * _trash_or_restore_event
1938
+	 *
1939
+	 * @access protected
1940
+	 * @param  string $event_status
1941
+	 * @param bool    $redirect_after
1942
+	 */
1943
+	protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
1944
+	{
1945
+		// determine the event id and set to array.
1946
+		$EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
1947
+		// loop thru events
1948
+		if ($EVT_ID) {
1949
+			// clean status
1950
+			$event_status = sanitize_key($event_status);
1951
+			// grab status
1952
+			if (! empty($event_status)) {
1953
+				$success = $this->_change_event_status($EVT_ID, $event_status);
1954
+			} else {
1955
+				$success = false;
1956
+				$msg = esc_html__(
1957
+					'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1958
+					'event_espresso'
1959
+				);
1960
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1961
+			}
1962
+		} else {
1963
+			$success = false;
1964
+			$msg = esc_html__(
1965
+				'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
1966
+				'event_espresso'
1967
+			);
1968
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1969
+		}
1970
+		$action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1971
+		if ($redirect_after) {
1972
+			$this->_redirect_after_action($success, 'Event', $action, array('action' => 'default'));
1973
+		}
1974
+	}
1975
+
1976
+
1977
+	/**
1978
+	 * _trash_or_restore_events
1979
+	 *
1980
+	 * @access protected
1981
+	 * @param  string $event_status
1982
+	 * @return void
1983
+	 */
1984
+	protected function _trash_or_restore_events($event_status = 'trash')
1985
+	{
1986
+		// clean status
1987
+		$event_status = sanitize_key($event_status);
1988
+		// grab status
1989
+		if (! empty($event_status)) {
1990
+			$success = true;
1991
+			// determine the event id and set to array.
1992
+			$EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();
1993
+			// loop thru events
1994
+			foreach ($EVT_IDs as $EVT_ID) {
1995
+				if ($EVT_ID = absint($EVT_ID)) {
1996
+					$results = $this->_change_event_status($EVT_ID, $event_status);
1997
+					$success = $results !== false ? $success : false;
1998
+				} else {
1999
+					$msg = sprintf(
2000
+						esc_html__(
2001
+							'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2002
+							'event_espresso'
2003
+						),
2004
+						$EVT_ID
2005
+					);
2006
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2007
+					$success = false;
2008
+				}
2009
+			}
2010
+		} else {
2011
+			$success = false;
2012
+			$msg = esc_html__(
2013
+				'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2014
+				'event_espresso'
2015
+			);
2016
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2017
+		}
2018
+		// in order to force a pluralized result message we need to send back a success status greater than 1
2019
+		$success = $success ? 2 : false;
2020
+		$action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
2021
+		$this->_redirect_after_action($success, 'Events', $action, array('action' => 'default'));
2022
+	}
2023
+
2024
+
2025
+	/**
2026
+	 * _trash_or_restore_events
2027
+	 *
2028
+	 * @access  private
2029
+	 * @param  int    $EVT_ID
2030
+	 * @param  string $event_status
2031
+	 * @return bool
2032
+	 */
2033
+	private function _change_event_status($EVT_ID = 0, $event_status = '')
2034
+	{
2035
+		// grab event id
2036
+		if (! $EVT_ID) {
2037
+			$msg = esc_html__(
2038
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2039
+				'event_espresso'
2040
+			);
2041
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2042
+			return false;
2043
+		}
2044
+		$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2045
+		// clean status
2046
+		$event_status = sanitize_key($event_status);
2047
+		// grab status
2048
+		if (empty($event_status)) {
2049
+			$msg = esc_html__(
2050
+				'An error occurred. No Event Status or an invalid Event Status was received.',
2051
+				'event_espresso'
2052
+			);
2053
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2054
+			return false;
2055
+		}
2056
+		// was event trashed or restored ?
2057
+		switch ($event_status) {
2058
+			case 'draft':
2059
+				$action = 'restored from the trash';
2060
+				$hook = 'AHEE_event_restored_from_trash';
2061
+				break;
2062
+			case 'trash':
2063
+				$action = 'moved to the trash';
2064
+				$hook = 'AHEE_event_moved_to_trash';
2065
+				break;
2066
+			default:
2067
+				$action = 'updated';
2068
+				$hook = false;
2069
+		}
2070
+		// use class to change status
2071
+		$this->_cpt_model_obj->set_status($event_status);
2072
+		$success = $this->_cpt_model_obj->save();
2073
+		if ($success === false) {
2074
+			$msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2075
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2076
+			return false;
2077
+		}
2078
+		if ($hook) {
2079
+			do_action($hook);
2080
+		}
2081
+		return true;
2082
+	}
2083
+
2084
+
2085
+	/**
2086
+	 * _delete_event
2087
+	 *
2088
+	 * @access protected
2089
+	 * @param bool $redirect_after
2090
+	 */
2091
+	protected function _delete_event()
2092
+	{
2093
+		// determine the event id and set to array.
2094
+		$EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null;
2095
+		wp_safe_redirect(
2096
+			EE_Admin_Page::add_query_args_and_nonce(
2097
+				[
2098
+					'action' => 'preview_deletion',
2099
+					'EVT_IDs[]' => $EVT_ID
2100
+				],
2101
+				$this->_admin_base_url
2102
+			)
2103
+		);
2104
+	}
2105
+
2106
+
2107
+	/**
2108
+	 * _delete_events
2109
+	 *
2110
+	 * @access protected
2111
+	 * @return void
2112
+	 */
2113
+	protected function _delete_events()
2114
+	{
2115
+		$EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
2116
+		$args = [
2117
+			'action' => 'preview_deletion',
2118
+		];
2119
+		foreach($EVT_IDs as $EVT_ID){
2120
+			$args['EVT_IDs[]'] = (int)$EVT_ID;
2121
+		}
2122
+		wp_safe_redirect(
2123
+			EE_Admin_Page::add_query_args_and_nonce(
2124
+				$args,
2125
+				$this->_admin_base_url
2126
+			)
2127
+		);
2128
+	}
2129
+
2130
+	/**
2131
+	 * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2132
+	 * @since $VID:$
2133
+	 */
2134
+	protected function previewDeletion()
2135
+	{
2136
+		$EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
2137
+		$confirm_deletion_args = [
2138
+			'action' => 'confirm_deletion',
2139
+		];
2140
+		foreach($EVT_IDs as $EVT_ID){
2141
+			$confirm_deletion_args['EVT_ID[]'] = (int)$EVT_ID;
2142
+		}
2143
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2144
+			EVENTS_TEMPLATE_PATH . 'event_preview_deletion.template.php',
2145
+			[
2146
+				'form_url' => EE_Admin_Page::add_query_args_and_nonce(
2147
+					$confirm_deletion_args,
2148
+					$this->admin_base_url()
2149
+				)
2150
+			],
2151
+			true
2152
+		);
2153
+		$this->display_admin_page_with_no_sidebar();
2154
+	}
2155
+
2156
+	protected function confirmDeletion()
2157
+	{
2158
+		echo "event deleted here";
2159
+
2160
+		// code from original _delete_event, which I assume we want to keep
2161
+		$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2162
+		// remove this event from the list of events with no prices
2163
+		if (isset($espresso_no_ticket_prices[ $EVT_ID ])) {
2164
+			unset($espresso_no_ticket_prices[ $EVT_ID ]);
2165
+		}
2166
+		update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2167
+	}
2168
+
2169
+	/**
2170
+	 * _permanently_delete_event
2171
+	 *
2172
+	 * @access  private
2173
+	 * @param  int $EVT_ID
2174
+	 * @return bool
2175
+	 */
2176
+	private function _permanently_delete_event($EVT_ID = 0)
2177
+	{
2178
+		// grab event id
2179
+		if (! $EVT_ID) {
2180
+			$msg = esc_html__(
2181
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2182
+				'event_espresso'
2183
+			);
2184
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2185
+			return false;
2186
+		}
2187
+		if (! $this->_cpt_model_obj instanceof EE_Event
2188
+			|| $this->_cpt_model_obj->ID() !== $EVT_ID
2189
+		) {
2190
+			$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2191
+		}
2192
+		if (! $this->_cpt_model_obj instanceof EE_Event) {
2193
+			return false;
2194
+		}
2195
+		// need to delete related tickets and prices first.
2196
+		$datetimes = $this->_cpt_model_obj->get_many_related('Datetime');
2197
+		foreach ($datetimes as $datetime) {
2198
+			$this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime');
2199
+			$tickets = $datetime->get_many_related('Ticket');
2200
+			foreach ($tickets as $ticket) {
2201
+				$ticket->_remove_relation_to($datetime, 'Datetime');
2202
+				$ticket->delete_related_permanently('Price');
2203
+				$ticket->delete_permanently();
2204
+			}
2205
+			$datetime->delete();
2206
+		}
2207
+		// what about related venues or terms?
2208
+		$venues = $this->_cpt_model_obj->get_many_related('Venue');
2209
+		foreach ($venues as $venue) {
2210
+			$this->_cpt_model_obj->_remove_relation_to($venue, 'Venue');
2211
+		}
2212
+		// any attached question groups?
2213
+		$question_groups = $this->_cpt_model_obj->get_many_related('Question_Group');
2214
+		if (! empty($question_groups)) {
2215
+			foreach ($question_groups as $question_group) {
2216
+				$this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group');
2217
+			}
2218
+		}
2219
+		// Message Template Groups
2220
+		$this->_cpt_model_obj->_remove_relations('Message_Template_Group');
2221
+		/** @type EE_Term_Taxonomy[] $term_taxonomies */
2222
+		$term_taxonomies = $this->_cpt_model_obj->term_taxonomies();
2223
+		foreach ($term_taxonomies as $term_taxonomy) {
2224
+			$this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy);
2225
+		}
2226
+		$success = $this->_cpt_model_obj->delete_permanently();
2227
+		// did it all go as planned ?
2228
+		if ($success) {
2229
+			$msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID);
2230
+			EE_Error::add_success($msg);
2231
+		} else {
2232
+			$msg = sprintf(
2233
+				esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'),
2234
+				$EVT_ID
2235
+			);
2236
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2237
+			return false;
2238
+		}
2239
+		do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID);
2240
+		return true;
2241
+	}
2242
+
2243
+
2244
+	/**
2245
+	 * get total number of events
2246
+	 *
2247
+	 * @access public
2248
+	 * @return int
2249
+	 */
2250
+	public function total_events()
2251
+	{
2252
+		$count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true);
2253
+		return $count;
2254
+	}
2255
+
2256
+
2257
+	/**
2258
+	 * get total number of draft events
2259
+	 *
2260
+	 * @access public
2261
+	 * @return int
2262
+	 */
2263
+	public function total_events_draft()
2264
+	{
2265
+		$where = array(
2266
+			'status' => array('IN', array('draft', 'auto-draft')),
2267
+		);
2268
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2269
+		return $count;
2270
+	}
2271
+
2272
+
2273
+	/**
2274
+	 * get total number of trashed events
2275
+	 *
2276
+	 * @access public
2277
+	 * @return int
2278
+	 */
2279
+	public function total_trashed_events()
2280
+	{
2281
+		$where = array(
2282
+			'status' => 'trash',
2283
+		);
2284
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2285
+		return $count;
2286
+	}
2287
+
2288
+
2289
+	/**
2290
+	 *    _default_event_settings
2291
+	 *    This generates the Default Settings Tab
2292
+	 *
2293
+	 * @return void
2294
+	 * @throws EE_Error
2295
+	 */
2296
+	protected function _default_event_settings()
2297
+	{
2298
+		$this->_set_add_edit_form_tags('update_default_event_settings');
2299
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
2300
+		$this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2301
+		$this->display_admin_page_with_sidebar();
2302
+	}
2303
+
2304
+
2305
+	/**
2306
+	 * Return the form for event settings.
2307
+	 *
2308
+	 * @return EE_Form_Section_Proper
2309
+	 * @throws EE_Error
2310
+	 */
2311
+	protected function _default_event_settings_form()
2312
+	{
2313
+		$registration_config = EE_Registry::instance()->CFG->registration;
2314
+		$registration_stati_for_selection = EEM_Registration::reg_status_array(
2315
+			// exclude
2316
+			array(
2317
+				EEM_Registration::status_id_cancelled,
2318
+				EEM_Registration::status_id_declined,
2319
+				EEM_Registration::status_id_incomplete,
2320
+				EEM_Registration::status_id_wait_list,
2321
+			),
2322
+			true
2323
+		);
2324
+		return new EE_Form_Section_Proper(
2325
+			array(
2326
+				'name'            => 'update_default_event_settings',
2327
+				'html_id'         => 'update_default_event_settings',
2328
+				'html_class'      => 'form-table',
2329
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2330
+				'subsections'     => apply_filters(
2331
+					'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2332
+					array(
2333
+						'default_reg_status'  => new EE_Select_Input(
2334
+							$registration_stati_for_selection,
2335
+							array(
2336
+								'default'         => isset($registration_config->default_STS_ID)
2337
+													 && array_key_exists(
2338
+														 $registration_config->default_STS_ID,
2339
+														 $registration_stati_for_selection
2340
+													 )
2341
+									? sanitize_text_field($registration_config->default_STS_ID)
2342
+									: EEM_Registration::status_id_pending_payment,
2343
+								'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2344
+													 . EEH_Template::get_help_tab_link(
2345
+														 'default_settings_status_help_tab'
2346
+													 ),
2347
+								'html_help_text'  => esc_html__(
2348
+									'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.',
2349
+									'event_espresso'
2350
+								),
2351
+							)
2352
+						),
2353
+						'default_max_tickets' => new EE_Integer_Input(
2354
+							array(
2355
+								'default'         => isset($registration_config->default_maximum_number_of_tickets)
2356
+									? $registration_config->default_maximum_number_of_tickets
2357
+									: EEM_Event::get_default_additional_limit(),
2358
+								'html_label_text' => esc_html__(
2359
+									'Default Maximum Tickets Allowed Per Order:',
2360
+									'event_espresso'
2361
+								)
2362
+													 . EEH_Template::get_help_tab_link(
2363
+														 'default_maximum_tickets_help_tab"'
2364
+													 ),
2365
+								'html_help_text'  => esc_html__(
2366
+									'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2367
+									'event_espresso'
2368
+								),
2369
+							)
2370
+						),
2371
+					)
2372
+				),
2373
+			)
2374
+		);
2375
+	}
2376
+
2377
+
2378
+	/**
2379
+	 * _update_default_event_settings
2380
+	 *
2381
+	 * @access protected
2382
+	 * @return void
2383
+	 * @throws EE_Error
2384
+	 */
2385
+	protected function _update_default_event_settings()
2386
+	{
2387
+		$registration_config = EE_Registry::instance()->CFG->registration;
2388
+		$form = $this->_default_event_settings_form();
2389
+		if ($form->was_submitted()) {
2390
+			$form->receive_form_submission();
2391
+			if ($form->is_valid()) {
2392
+				$valid_data = $form->valid_data();
2393
+				if (isset($valid_data['default_reg_status'])) {
2394
+					$registration_config->default_STS_ID = $valid_data['default_reg_status'];
2395
+				}
2396
+				if (isset($valid_data['default_max_tickets'])) {
2397
+					$registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2398
+				}
2399
+				// update because data was valid!
2400
+				EE_Registry::instance()->CFG->update_espresso_config();
2401
+				EE_Error::overwrite_success();
2402
+				EE_Error::add_success(
2403
+					__('Default Event Settings were updated', 'event_espresso')
2404
+				);
2405
+			}
2406
+		}
2407
+		$this->_redirect_after_action(0, '', '', array('action' => 'default_event_settings'), true);
2408
+	}
2409
+
2410
+
2411
+	/*************        Templates        *************/
2412
+	protected function _template_settings()
2413
+	{
2414
+		$this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso');
2415
+		$this->_template_args['preview_img'] = '<img src="'
2416
+											   . EVENTS_ASSETS_URL
2417
+											   . '/images/'
2418
+											   . 'caffeinated_template_features.jpg" alt="'
2419
+											   . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2420
+											   . '" />';
2421
+		$this->_template_args['preview_text'] = '<strong>'
2422
+												. esc_html__(
2423
+													'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.',
2424
+													'event_espresso'
2425
+												) . '</strong>';
2426
+		$this->display_admin_caf_preview_page('template_settings_tab');
2427
+	}
2428
+
2429
+
2430
+	/** Event Category Stuff **/
2431
+	/**
2432
+	 * set the _category property with the category object for the loaded page.
2433
+	 *
2434
+	 * @access private
2435
+	 * @return void
2436
+	 */
2437
+	private function _set_category_object()
2438
+	{
2439
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
2440
+			return;
2441
+		} //already have the category object so get out.
2442
+		// set default category object
2443
+		$this->_set_empty_category_object();
2444
+		// only set if we've got an id
2445
+		if (! isset($this->_req_data['EVT_CAT_ID'])) {
2446
+			return;
2447
+		}
2448
+		$category_id = absint($this->_req_data['EVT_CAT_ID']);
2449
+		$term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2450
+		if (! empty($term)) {
2451
+			$this->_category->category_name = $term->name;
2452
+			$this->_category->category_identifier = $term->slug;
2453
+			$this->_category->category_desc = $term->description;
2454
+			$this->_category->id = $term->term_id;
2455
+			$this->_category->parent = $term->parent;
2456
+		}
2457
+	}
2458
+
2459
+
2460
+	/**
2461
+	 * Clears out category properties.
2462
+	 */
2463
+	private function _set_empty_category_object()
2464
+	{
2465
+		$this->_category = new stdClass();
2466
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2467
+		$this->_category->id = $this->_category->parent = 0;
2468
+	}
2469
+
2470
+
2471
+	/**
2472
+	 * @throws EE_Error
2473
+	 */
2474
+	protected function _category_list_table()
2475
+	{
2476
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2477
+		$this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2478
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2479
+			'add_category',
2480
+			'add_category',
2481
+			array(),
2482
+			'add-new-h2'
2483
+		);
2484
+		$this->display_admin_list_table_page_with_sidebar();
2485
+	}
2486
+
2487
+
2488
+	/**
2489
+	 * Output category details view.
2490
+	 */
2491
+	protected function _category_details($view)
2492
+	{
2493
+		// load formatter helper
2494
+		// load field generator helper
2495
+		$route = $view == 'edit' ? 'update_category' : 'insert_category';
2496
+		$this->_set_add_edit_form_tags($route);
2497
+		$this->_set_category_object();
2498
+		$id = ! empty($this->_category->id) ? $this->_category->id : '';
2499
+		$delete_action = 'delete_category';
2500
+		// custom redirect
2501
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(
2502
+			array('action' => 'category_list'),
2503
+			$this->_admin_base_url
2504
+		);
2505
+		$this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2506
+		// take care of contents
2507
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
2508
+		$this->display_admin_page_with_sidebar();
2509
+	}
2510
+
2511
+
2512
+	/**
2513
+	 * Output category details content.
2514
+	 */
2515
+	protected function _category_details_content()
2516
+	{
2517
+		$editor_args['category_desc'] = array(
2518
+			'type'          => 'wp_editor',
2519
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2520
+			'class'         => 'my_editor_custom',
2521
+			'wpeditor_args' => array('media_buttons' => false),
2522
+		);
2523
+		$_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
2524
+		$all_terms = get_terms(
2525
+			array(EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY),
2526
+			array('hide_empty' => 0, 'exclude' => array($this->_category->id))
2527
+		);
2528
+		// setup category select for term parents.
2529
+		$category_select_values[] = array(
2530
+			'text' => esc_html__('No Parent', 'event_espresso'),
2531
+			'id'   => 0,
2532
+		);
2533
+		foreach ($all_terms as $term) {
2534
+			$category_select_values[] = array(
2535
+				'text' => $term->name,
2536
+				'id'   => $term->term_id,
2537
+			);
2538
+		}
2539
+		$category_select = EEH_Form_Fields::select_input(
2540
+			'category_parent',
2541
+			$category_select_values,
2542
+			$this->_category->parent
2543
+		);
2544
+		$template_args = array(
2545
+			'category'                 => $this->_category,
2546
+			'category_select'          => $category_select,
2547
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2548
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2549
+			'disable'                  => '',
2550
+			'disabled_message'         => false,
2551
+		);
2552
+		$template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2553
+		return EEH_Template::display_template($template, $template_args, true);
2554
+	}
2555
+
2556
+
2557
+	/**
2558
+	 * Handles deleting categories.
2559
+	 */
2560
+	protected function _delete_categories()
2561
+	{
2562
+		$cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID']
2563
+			: (array) $this->_req_data['category_id'];
2564
+		foreach ($cat_ids as $cat_id) {
2565
+			$this->_delete_category($cat_id);
2566
+		}
2567
+		// doesn't matter what page we're coming from... we're going to the same place after delete.
2568
+		$query_args = array(
2569
+			'action' => 'category_list',
2570
+		);
2571
+		$this->_redirect_after_action(0, '', '', $query_args);
2572
+	}
2573
+
2574
+
2575
+	/**
2576
+	 * Handles deleting specific category.
2577
+	 *
2578
+	 * @param int $cat_id
2579
+	 */
2580
+	protected function _delete_category($cat_id)
2581
+	{
2582
+		$cat_id = absint($cat_id);
2583
+		wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2584
+	}
2585
+
2586
+
2587
+	/**
2588
+	 * Handles triggering the update or insertion of a new category.
2589
+	 *
2590
+	 * @param bool $new_category true means we're triggering the insert of a new category.
2591
+	 */
2592
+	protected function _insert_or_update_category($new_category)
2593
+	{
2594
+		$cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2595
+		$success = 0; // we already have a success message so lets not send another.
2596
+		if ($cat_id) {
2597
+			$query_args = array(
2598
+				'action'     => 'edit_category',
2599
+				'EVT_CAT_ID' => $cat_id,
2600
+			);
2601
+		} else {
2602
+			$query_args = array('action' => 'add_category');
2603
+		}
2604
+		$this->_redirect_after_action($success, '', '', $query_args, true);
2605
+	}
2606
+
2607
+
2608
+	/**
2609
+	 * Inserts or updates category
2610
+	 *
2611
+	 * @param bool $update (true indicates we're updating a category).
2612
+	 * @return bool|mixed|string
2613
+	 */
2614
+	private function _insert_category($update = false)
2615
+	{
2616
+		$cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2617
+		$category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2618
+		$category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2619
+		$category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2620
+		if (empty($category_name)) {
2621
+			$msg = esc_html__('You must add a name for the category.', 'event_espresso');
2622
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2623
+			return false;
2624
+		}
2625
+		$term_args = array(
2626
+			'name'        => $category_name,
2627
+			'description' => $category_desc,
2628
+			'parent'      => $category_parent,
2629
+		);
2630
+		// was the category_identifier input disabled?
2631
+		if (isset($this->_req_data['category_identifier'])) {
2632
+			$term_args['slug'] = $this->_req_data['category_identifier'];
2633
+		}
2634
+		$insert_ids = $update
2635
+			? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2636
+			: wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2637
+		if (! is_array($insert_ids)) {
2638
+			$msg = esc_html__(
2639
+				'An error occurred and the category has not been saved to the database.',
2640
+				'event_espresso'
2641
+			);
2642
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2643
+		} else {
2644
+			$cat_id = $insert_ids['term_id'];
2645
+			$msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2646
+			EE_Error::add_success($msg);
2647
+		}
2648
+		return $cat_id;
2649
+	}
2650
+
2651
+
2652
+	/**
2653
+	 * Gets categories or count of categories matching the arguments in the request.
2654
+	 *
2655
+	 * @param int  $per_page
2656
+	 * @param int  $current_page
2657
+	 * @param bool $count
2658
+	 * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int
2659
+	 */
2660
+	public function get_categories($per_page = 10, $current_page = 1, $count = false)
2661
+	{
2662
+		// testing term stuff
2663
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2664
+		$order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2665
+		$limit = ($current_page - 1) * $per_page;
2666
+		$where = array('taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2667
+		if (isset($this->_req_data['s'])) {
2668
+			$sstr = '%' . $this->_req_data['s'] . '%';
2669
+			$where['OR'] = array(
2670
+				'Term.name'   => array('LIKE', $sstr),
2671
+				'description' => array('LIKE', $sstr),
2672
+			);
2673
+		}
2674
+		$query_params = array(
2675
+			$where,
2676
+			'order_by'   => array($orderby => $order),
2677
+			'limit'      => $limit . ',' . $per_page,
2678
+			'force_join' => array('Term'),
2679
+		);
2680
+		$categories = $count
2681
+			? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2682
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
2683
+		return $categories;
2684
+	}
2685
+
2686
+	/* end category stuff */
2687
+	/**************/
2688
+
2689
+
2690
+	/**
2691
+	 * Callback for the `ee_save_timezone_setting` ajax action.
2692
+	 *
2693
+	 * @throws EE_Error
2694
+	 */
2695
+	public function save_timezonestring_setting()
2696
+	{
2697
+		$timezone_string = isset($this->_req_data['timezone_selected'])
2698
+			? $this->_req_data['timezone_selected']
2699
+			: '';
2700
+		if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2701
+			EE_Error::add_error(
2702
+				esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2703
+				__FILE__,
2704
+				__FUNCTION__,
2705
+				__LINE__
2706
+			);
2707
+			$this->_template_args['error'] = true;
2708
+			$this->_return_json();
2709
+		}
2710
+
2711
+		update_option('timezone_string', $timezone_string);
2712
+		EE_Error::add_success(
2713
+			esc_html__('Your timezone string was updated.', 'event_espresso')
2714
+		);
2715
+		$this->_template_args['success'] = true;
2716
+		$this->_return_json(true, array('action' => 'create_new'));
2717
+	}
2718 2718
 }
Please login to merge, or discard this patch.
Spacing   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -573,11 +573,11 @@  discard block
 block discarded – undo
573 573
     {
574 574
         wp_register_style(
575 575
             'events-admin-css',
576
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
576
+            EVENTS_ASSETS_URL.'events-admin-page.css',
577 577
             array(),
578 578
             EVENT_ESPRESSO_VERSION
579 579
         );
580
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
580
+        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL.'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
581 581
         wp_enqueue_style('events-admin-css');
582 582
         wp_enqueue_style('ee-cat-admin');
583 583
         // todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
@@ -585,7 +585,7 @@  discard block
 block discarded – undo
585 585
         // scripts
586 586
         wp_register_script(
587 587
             'event_editor_js',
588
-            EVENTS_ASSETS_URL . 'event_editor.js',
588
+            EVENTS_ASSETS_URL.'event_editor.js',
589 589
             array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
590 590
             EVENT_ESPRESSO_VERSION,
591 591
             true
@@ -611,7 +611,7 @@  discard block
 block discarded – undo
611 611
         wp_enqueue_style('espresso-ui-theme');
612 612
         wp_register_style(
613 613
             'event-editor-css',
614
-            EVENTS_ASSETS_URL . 'event-editor.css',
614
+            EVENTS_ASSETS_URL.'event-editor.css',
615 615
             array('ee-admin-css'),
616 616
             EVENT_ESPRESSO_VERSION
617 617
         );
@@ -619,7 +619,7 @@  discard block
 block discarded – undo
619 619
         // scripts
620 620
         wp_register_script(
621 621
             'event-datetime-metabox',
622
-            EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
622
+            EVENTS_ASSETS_URL.'event-datetime-metabox.js',
623 623
             array('event_editor_js', 'ee-datepicker'),
624 624
             EVENT_ESPRESSO_VERSION
625 625
         );
@@ -688,7 +688,7 @@  discard block
 block discarded – undo
688 688
     public function verify_event_edit($event = null, $req_type = '')
689 689
     {
690 690
         // don't need to do this when processing
691
-        if (! empty($req_type)) {
691
+        if ( ! empty($req_type)) {
692 692
             return;
693 693
         }
694 694
         // no event?
@@ -697,7 +697,7 @@  discard block
 block discarded – undo
697 697
             $event = $this->_cpt_model_obj;
698 698
         }
699 699
         // STILL no event?
700
-        if (! $event instanceof EE_Event) {
700
+        if ( ! $event instanceof EE_Event) {
701 701
             return;
702 702
         }
703 703
         $orig_status = $event->status();
@@ -735,7 +735,7 @@  discard block
 block discarded – undo
735 735
             );
736 736
         }
737 737
         // now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
738
-        if (! $event->tickets_on_sale()) {
738
+        if ( ! $event->tickets_on_sale()) {
739 739
             return;
740 740
         }
741 741
         // made it here so show warning
@@ -780,7 +780,7 @@  discard block
 block discarded – undo
780 780
     {
781 781
         $has_timezone_string = get_option('timezone_string');
782 782
         // only nag them about setting their timezone if it's their first event, and they haven't already done it
783
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) {
783
+        if ( ! $has_timezone_string && ! EEM_Event::instance()->exists(array())) {
784 784
             EE_Error::add_attention(
785 785
                 sprintf(
786 786
                     __(
@@ -864,31 +864,31 @@  discard block
 block discarded – undo
864 864
         $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
865 865
         $statuses = array(
866 866
             'sold_out_status'  => array(
867
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
867
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::sold_out,
868 868
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
869 869
             ),
870 870
             'active_status'    => array(
871
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
871
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::active,
872 872
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
873 873
             ),
874 874
             'upcoming_status'  => array(
875
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
875
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::upcoming,
876 876
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
877 877
             ),
878 878
             'postponed_status' => array(
879
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
879
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::postponed,
880 880
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
881 881
             ),
882 882
             'cancelled_status' => array(
883
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
883
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::cancelled,
884 884
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
885 885
             ),
886 886
             'expired_status'   => array(
887
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
887
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::expired,
888 888
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
889 889
             ),
890 890
             'inactive_status'  => array(
891
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
891
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::inactive,
892 892
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
893 893
             ),
894 894
         );
@@ -902,7 +902,7 @@  discard block
 block discarded – undo
902 902
      */
903 903
     private function _event_model()
904 904
     {
905
-        if (! $this->_event_model instanceof EEM_Event) {
905
+        if ( ! $this->_event_model instanceof EEM_Event) {
906 906
             $this->_event_model = EE_Registry::instance()->load_model('Event');
907 907
         }
908 908
         return $this->_event_model;
@@ -922,7 +922,7 @@  discard block
 block discarded – undo
922 922
     public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
923 923
     {
924 924
         // make sure this is only when editing
925
-        if (! empty($id)) {
925
+        if ( ! empty($id)) {
926 926
             $post = get_post($id);
927 927
             $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
928 928
                        . esc_html__('Shortcode', 'event_espresso')
@@ -956,7 +956,7 @@  discard block
 block discarded – undo
956 956
                     'button'
957 957
                 );
958 958
         $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
959
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
959
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
960 960
             'create_new',
961 961
             'add',
962 962
             array(),
@@ -1096,7 +1096,7 @@  discard block
 block discarded – undo
1096 1096
      */
1097 1097
     protected function _default_venue_update(\EE_Event $evtobj, $data)
1098 1098
     {
1099
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1099
+        require_once(EE_MODELS.'EEM_Venue.model.php');
1100 1100
         $venue_model = EE_Registry::instance()->load_model('Venue');
1101 1101
         $rows_affected = null;
1102 1102
         $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
@@ -1127,7 +1127,7 @@  discard block
 block discarded – undo
1127 1127
             'status'              => 'publish',
1128 1128
         );
1129 1129
         // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1130
-        if (! empty($venue_id)) {
1130
+        if ( ! empty($venue_id)) {
1131 1131
             $update_where = array($venue_model->primary_key_name() => $venue_id);
1132 1132
             $rows_affected = $venue_model->update($venue_array, array($update_where));
1133 1133
             // 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.
@@ -1169,7 +1169,7 @@  discard block
 block discarded – undo
1169 1169
                 'DTT_order'     => $row,
1170 1170
             );
1171 1171
             // 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.
1172
-            if (! empty($dtt['DTT_ID'])) {
1172
+            if ( ! empty($dtt['DTT_ID'])) {
1173 1173
                 $DTM = EE_Registry::instance()
1174 1174
                                   ->load_model('Datetime', array($evtobj->get_timezone()))
1175 1175
                                   ->get_one_by_ID($dtt['DTT_ID']);
@@ -1179,7 +1179,7 @@  discard block
 block discarded – undo
1179 1179
                     $DTM->set($field, $value);
1180 1180
                 }
1181 1181
                 // 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.
1182
-                $saved_dtts[ $DTM->ID() ] = $DTM;
1182
+                $saved_dtts[$DTM->ID()] = $DTM;
1183 1183
             } else {
1184 1184
                 $DTM = EE_Registry::instance()->load_class(
1185 1185
                     'Datetime',
@@ -1212,14 +1212,14 @@  discard block
 block discarded – undo
1212 1212
         foreach ($data['edit_tickets'] as $row => $tkt) {
1213 1213
             $incoming_date_formats = array('Y-m-d', 'h:i a');
1214 1214
             $update_prices = false;
1215
-            $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1216
-                ? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0;
1215
+            $ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount'])
1216
+                ? $data['edit_prices'][$row][1]['PRC_amount'] : 0;
1217 1217
             // trim inputs to ensure any excess whitespace is removed.
1218 1218
             $tkt = array_map('trim', $tkt);
1219 1219
             if (empty($tkt['TKT_start_date'])) {
1220 1220
                 // let's use now in the set timezone.
1221 1221
                 $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1222
-                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1222
+                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0].' '.$incoming_date_formats[1]);
1223 1223
             }
1224 1224
             if (empty($tkt['TKT_end_date'])) {
1225 1225
                 // use the start date of the first datetime
@@ -1254,7 +1254,7 @@  discard block
 block discarded – undo
1254 1254
             // if we have a TKT_ID then we need to get that existing TKT_obj and update it
1255 1255
             // 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.
1256 1256
             // 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.
1257
-            if (! empty($tkt['TKT_ID'])) {
1257
+            if ( ! empty($tkt['TKT_ID'])) {
1258 1258
                 $TKT = EE_Registry::instance()
1259 1259
                                   ->load_model('Ticket', array($evtobj->get_timezone()))
1260 1260
                                   ->get_one_by_ID($tkt['TKT_ID']);
@@ -1289,7 +1289,7 @@  discard block
 block discarded – undo
1289 1289
                         $TKT->set('TKT_deleted', 1);
1290 1290
                         $TKT->save();
1291 1291
                         // make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1292
-                        $saved_tickets[ $TKT->ID() ] = $TKT;
1292
+                        $saved_tickets[$TKT->ID()] = $TKT;
1293 1293
                         // 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.
1294 1294
                         $TKT = clone $TKT;
1295 1295
                         $TKT->set('TKT_ID', 0);
@@ -1334,9 +1334,9 @@  discard block
 block discarded – undo
1334 1334
             }
1335 1335
             // initially let's add the ticket to the dtt
1336 1336
             $saved_dtt->_add_relation_to($TKT, 'Ticket');
1337
-            $saved_tickets[ $TKT->ID() ] = $TKT;
1337
+            $saved_tickets[$TKT->ID()] = $TKT;
1338 1338
             // add prices to ticket
1339
-            $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices);
1339
+            $this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices);
1340 1340
         }
1341 1341
         // 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.
1342 1342
         $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
@@ -1493,7 +1493,7 @@  discard block
 block discarded – undo
1493 1493
         $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1494 1494
         // load template
1495 1495
         EEH_Template::display_template(
1496
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1496
+            EVENTS_TEMPLATE_PATH.'event_publish_box_extras.template.php',
1497 1497
             $publish_box_extra_args
1498 1498
         );
1499 1499
     }
@@ -1585,7 +1585,7 @@  discard block
 block discarded – undo
1585 1585
                     'default_where_conditions' => 'none',
1586 1586
                 )
1587 1587
             );
1588
-            if (! empty($related_tickets)) {
1588
+            if ( ! empty($related_tickets)) {
1589 1589
                 $template_args['total_ticket_rows'] = count($related_tickets);
1590 1590
                 $row = 0;
1591 1591
                 foreach ($related_tickets as $ticket) {
@@ -1619,7 +1619,7 @@  discard block
 block discarded – undo
1619 1619
         );
1620 1620
         $template = apply_filters(
1621 1621
             'FHEE__Events_Admin_Page__ticket_metabox__template',
1622
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1622
+            EVENTS_TEMPLATE_PATH.'event_tickets_metabox_main.template.php'
1623 1623
         );
1624 1624
         EEH_Template::display_template($template, $template_args);
1625 1625
     }
@@ -1637,7 +1637,7 @@  discard block
 block discarded – undo
1637 1637
     private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1638 1638
     {
1639 1639
         $template_args = array(
1640
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1640
+            'tkt_status_class'    => ' tkt-status-'.$ticket->ticket_status(),
1641 1641
             'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1642 1642
                 : '',
1643 1643
             'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
@@ -1649,10 +1649,10 @@  discard block
 block discarded – undo
1649 1649
             'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1650 1650
             'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1651 1651
             'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1652
-            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1653
-                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1652
+            'trash_icon'          => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')))
1653
+                                     && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0)
1654 1654
                 ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1655
-            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1655
+            'disabled'            => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1656 1656
                 : ' disabled=disabled',
1657 1657
         );
1658 1658
         $price = $ticket->ID() !== 0
@@ -1679,7 +1679,7 @@  discard block
 block discarded – undo
1679 1679
                     array('order_by' => array('DTT_EVT_start' => 'ASC'))
1680 1680
                 )
1681 1681
                 : null;
1682
-            if (! empty($earliest_dtt)) {
1682
+            if ( ! empty($earliest_dtt)) {
1683 1683
                 $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1684 1684
             } else {
1685 1685
                 $template_args['TKT_end_date'] = date(
@@ -1691,7 +1691,7 @@  discard block
 block discarded – undo
1691 1691
         $template_args = array_merge($template_args, $price_args);
1692 1692
         $template = apply_filters(
1693 1693
             'FHEE__Events_Admin_Page__get_ticket_row__template',
1694
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1694
+            EVENTS_TEMPLATE_PATH.'event_tickets_metabox_ticket_row.template.php',
1695 1695
             $ticket
1696 1696
         );
1697 1697
         return EEH_Template::display_template($template, $template_args, true);
@@ -1745,7 +1745,7 @@  discard block
 block discarded – undo
1745 1745
             $default_reg_status_values
1746 1746
         );
1747 1747
         EEH_Template::display_template(
1748
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1748
+            EVENTS_TEMPLATE_PATH.'event_registration_options.template.php',
1749 1749
             $template_args
1750 1750
         );
1751 1751
     }
@@ -1767,7 +1767,7 @@  discard block
 block discarded – undo
1767 1767
     {
1768 1768
         $EEME = $this->_event_model();
1769 1769
         $offset = ($current_page - 1) * $per_page;
1770
-        $limit = $count ? null : $offset . ',' . $per_page;
1770
+        $limit = $count ? null : $offset.','.$per_page;
1771 1771
         $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1772 1772
         $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1773 1773
         if (isset($this->_req_data['month_range'])) {
@@ -1796,7 +1796,7 @@  discard block
 block discarded – undo
1796 1796
         // categories?
1797 1797
         $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1798 1798
             ? $this->_req_data['EVT_CAT'] : null;
1799
-        if (! empty($category)) {
1799
+        if ( ! empty($category)) {
1800 1800
             $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1801 1801
             $where['Term_Taxonomy.term_id'] = $category;
1802 1802
         }
@@ -1804,7 +1804,7 @@  discard block
 block discarded – undo
1804 1804
         $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1805 1805
         if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1806 1806
             $DateTime = new DateTime(
1807
-                $year_r . '-' . $month_r . '-01 00:00:00',
1807
+                $year_r.'-'.$month_r.'-01 00:00:00',
1808 1808
                 new DateTimeZone(EEM_Datetime::instance()->get_timezone())
1809 1809
             );
1810 1810
             $start = $DateTime->format(implode(' ', $start_formats));
@@ -1830,11 +1830,11 @@  discard block
 block discarded – undo
1830 1830
                             ->format(implode(' ', $start_formats));
1831 1831
             $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1832 1832
         }
1833
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1833
+        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1834 1834
             $where['EVT_wp_user'] = get_current_user_id();
1835 1835
         } else {
1836
-            if (! isset($where['status'])) {
1837
-                if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1836
+            if ( ! isset($where['status'])) {
1837
+                if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1838 1838
                     $where['OR'] = array(
1839 1839
                         'status*restrict_private' => array('!=', 'private'),
1840 1840
                         'AND'                     => array(
@@ -1854,7 +1854,7 @@  discard block
 block discarded – undo
1854 1854
         }
1855 1855
         // search query handling
1856 1856
         if (isset($this->_req_data['s'])) {
1857
-            $search_string = '%' . $this->_req_data['s'] . '%';
1857
+            $search_string = '%'.$this->_req_data['s'].'%';
1858 1858
             $where['OR'] = array(
1859 1859
                 'EVT_name'       => array('LIKE', $search_string),
1860 1860
                 'EVT_desc'       => array('LIKE', $search_string),
@@ -1949,7 +1949,7 @@  discard block
 block discarded – undo
1949 1949
             // clean status
1950 1950
             $event_status = sanitize_key($event_status);
1951 1951
             // grab status
1952
-            if (! empty($event_status)) {
1952
+            if ( ! empty($event_status)) {
1953 1953
                 $success = $this->_change_event_status($EVT_ID, $event_status);
1954 1954
             } else {
1955 1955
                 $success = false;
@@ -1986,7 +1986,7 @@  discard block
 block discarded – undo
1986 1986
         // clean status
1987 1987
         $event_status = sanitize_key($event_status);
1988 1988
         // grab status
1989
-        if (! empty($event_status)) {
1989
+        if ( ! empty($event_status)) {
1990 1990
             $success = true;
1991 1991
             // determine the event id and set to array.
1992 1992
             $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();
@@ -2033,7 +2033,7 @@  discard block
 block discarded – undo
2033 2033
     private function _change_event_status($EVT_ID = 0, $event_status = '')
2034 2034
     {
2035 2035
         // grab event id
2036
-        if (! $EVT_ID) {
2036
+        if ( ! $EVT_ID) {
2037 2037
             $msg = esc_html__(
2038 2038
                 'An error occurred. No Event ID or an invalid Event ID was received.',
2039 2039
                 'event_espresso'
@@ -2112,12 +2112,12 @@  discard block
 block discarded – undo
2112 2112
      */
2113 2113
     protected function _delete_events()
2114 2114
     {
2115
-        $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
2115
+        $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();
2116 2116
         $args = [
2117 2117
             'action' => 'preview_deletion',
2118 2118
         ];
2119
-        foreach($EVT_IDs as $EVT_ID){
2120
-            $args['EVT_IDs[]'] = (int)$EVT_ID;
2119
+        foreach ($EVT_IDs as $EVT_ID) {
2120
+            $args['EVT_IDs[]'] = (int) $EVT_ID;
2121 2121
         }
2122 2122
         wp_safe_redirect(
2123 2123
             EE_Admin_Page::add_query_args_and_nonce(
@@ -2133,15 +2133,15 @@  discard block
 block discarded – undo
2133 2133
      */
2134 2134
     protected function previewDeletion()
2135 2135
     {
2136
-        $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
2136
+        $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();
2137 2137
         $confirm_deletion_args = [
2138 2138
             'action' => 'confirm_deletion',
2139 2139
         ];
2140
-        foreach($EVT_IDs as $EVT_ID){
2141
-            $confirm_deletion_args['EVT_ID[]'] = (int)$EVT_ID;
2140
+        foreach ($EVT_IDs as $EVT_ID) {
2141
+            $confirm_deletion_args['EVT_ID[]'] = (int) $EVT_ID;
2142 2142
         }
2143 2143
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2144
-            EVENTS_TEMPLATE_PATH . 'event_preview_deletion.template.php',
2144
+            EVENTS_TEMPLATE_PATH.'event_preview_deletion.template.php',
2145 2145
             [
2146 2146
                 'form_url' => EE_Admin_Page::add_query_args_and_nonce(
2147 2147
                     $confirm_deletion_args,
@@ -2160,8 +2160,8 @@  discard block
 block discarded – undo
2160 2160
         // code from original _delete_event, which I assume we want to keep
2161 2161
         $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2162 2162
         // remove this event from the list of events with no prices
2163
-        if (isset($espresso_no_ticket_prices[ $EVT_ID ])) {
2164
-            unset($espresso_no_ticket_prices[ $EVT_ID ]);
2163
+        if (isset($espresso_no_ticket_prices[$EVT_ID])) {
2164
+            unset($espresso_no_ticket_prices[$EVT_ID]);
2165 2165
         }
2166 2166
         update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2167 2167
     }
@@ -2176,7 +2176,7 @@  discard block
 block discarded – undo
2176 2176
     private function _permanently_delete_event($EVT_ID = 0)
2177 2177
     {
2178 2178
         // grab event id
2179
-        if (! $EVT_ID) {
2179
+        if ( ! $EVT_ID) {
2180 2180
             $msg = esc_html__(
2181 2181
                 'An error occurred. No Event ID or an invalid Event ID was received.',
2182 2182
                 'event_espresso'
@@ -2184,12 +2184,12 @@  discard block
 block discarded – undo
2184 2184
             EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2185 2185
             return false;
2186 2186
         }
2187
-        if (! $this->_cpt_model_obj instanceof EE_Event
2187
+        if ( ! $this->_cpt_model_obj instanceof EE_Event
2188 2188
             || $this->_cpt_model_obj->ID() !== $EVT_ID
2189 2189
         ) {
2190 2190
             $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2191 2191
         }
2192
-        if (! $this->_cpt_model_obj instanceof EE_Event) {
2192
+        if ( ! $this->_cpt_model_obj instanceof EE_Event) {
2193 2193
             return false;
2194 2194
         }
2195 2195
         // need to delete related tickets and prices first.
@@ -2211,7 +2211,7 @@  discard block
 block discarded – undo
2211 2211
         }
2212 2212
         // any attached question groups?
2213 2213
         $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group');
2214
-        if (! empty($question_groups)) {
2214
+        if ( ! empty($question_groups)) {
2215 2215
             foreach ($question_groups as $question_group) {
2216 2216
                 $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group');
2217 2217
             }
@@ -2422,7 +2422,7 @@  discard block
 block discarded – undo
2422 2422
                                                 . esc_html__(
2423 2423
                                                     '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.',
2424 2424
                                                     'event_espresso'
2425
-                                                ) . '</strong>';
2425
+                                                ).'</strong>';
2426 2426
         $this->display_admin_caf_preview_page('template_settings_tab');
2427 2427
     }
2428 2428
 
@@ -2442,12 +2442,12 @@  discard block
 block discarded – undo
2442 2442
         // set default category object
2443 2443
         $this->_set_empty_category_object();
2444 2444
         // only set if we've got an id
2445
-        if (! isset($this->_req_data['EVT_CAT_ID'])) {
2445
+        if ( ! isset($this->_req_data['EVT_CAT_ID'])) {
2446 2446
             return;
2447 2447
         }
2448 2448
         $category_id = absint($this->_req_data['EVT_CAT_ID']);
2449 2449
         $term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2450
-        if (! empty($term)) {
2450
+        if ( ! empty($term)) {
2451 2451
             $this->_category->category_name = $term->name;
2452 2452
             $this->_category->category_identifier = $term->slug;
2453 2453
             $this->_category->category_desc = $term->description;
@@ -2475,7 +2475,7 @@  discard block
 block discarded – undo
2475 2475
     {
2476 2476
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2477 2477
         $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2478
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2478
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
2479 2479
             'add_category',
2480 2480
             'add_category',
2481 2481
             array(),
@@ -2549,7 +2549,7 @@  discard block
 block discarded – undo
2549 2549
             'disable'                  => '',
2550 2550
             'disabled_message'         => false,
2551 2551
         );
2552
-        $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2552
+        $template = EVENTS_TEMPLATE_PATH.'event_category_details.template.php';
2553 2553
         return EEH_Template::display_template($template, $template_args, true);
2554 2554
     }
2555 2555
 
@@ -2634,7 +2634,7 @@  discard block
 block discarded – undo
2634 2634
         $insert_ids = $update
2635 2635
             ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2636 2636
             : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2637
-        if (! is_array($insert_ids)) {
2637
+        if ( ! is_array($insert_ids)) {
2638 2638
             $msg = esc_html__(
2639 2639
                 'An error occurred and the category has not been saved to the database.',
2640 2640
                 'event_espresso'
@@ -2665,7 +2665,7 @@  discard block
 block discarded – undo
2665 2665
         $limit = ($current_page - 1) * $per_page;
2666 2666
         $where = array('taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2667 2667
         if (isset($this->_req_data['s'])) {
2668
-            $sstr = '%' . $this->_req_data['s'] . '%';
2668
+            $sstr = '%'.$this->_req_data['s'].'%';
2669 2669
             $where['OR'] = array(
2670 2670
                 'Term.name'   => array('LIKE', $sstr),
2671 2671
                 'description' => array('LIKE', $sstr),
@@ -2674,7 +2674,7 @@  discard block
 block discarded – undo
2674 2674
         $query_params = array(
2675 2675
             $where,
2676 2676
             'order_by'   => array($orderby => $order),
2677
-            'limit'      => $limit . ',' . $per_page,
2677
+            'limit'      => $limit.','.$per_page,
2678 2678
             'force_join' => array('Term'),
2679 2679
         );
2680 2680
         $categories = $count
Please login to merge, or discard this patch.
admin_pages/events/templates/event_preview_deletion.template.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@
 block discarded – undo
1 1
 <h2><?php esc_html_e('Please Confirm You Want to Permanently Delete the Following Data', 'event_espresso'); ?></h2>
2 2
 A bunch of events
3
-<form action="<?php echo $form_url;?>" method="POST">
3
+<form action="<?php echo $form_url; ?>" method="POST">
4 4
     <input type="submit" value="<?php echo esc_attr(esc_html__('Confirm', 'event_espresso')); ?>">
5 5
 </form>
Please login to merge, or discard this patch.
admin_pages/events/Events_Admin_List_Table.class.php 2 patches
Indentation   +544 added lines, -544 removed lines patch added patch discarded remove patch
@@ -15,548 +15,548 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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,20 +307,20 @@  discard block
 block discarded – undo
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>';
315 315
             }
316
-            if ( EE_Registry::instance()->CAP->current_user_can(
316
+            if (EE_Registry::instance()->CAP->current_user_can(
317 317
                     'ee_delete_event',
318 318
                     'espresso_events_delete_event',
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
             }
Please login to merge, or discard this patch.