Completed
Branch BUG-10532-replace-hooks-for-ts (65130e)
by
unknown
28:48 queued 15:20
created
core/services/formatters/Windows1252.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -28,8 +28,8 @@
 block discarded – undo
28 28
     public function format($input)
29 29
     {
30 30
         //in case an int or float etc was passed in
31
-        $input = (string)$input;
32
-        $input = iconv('utf-8','cp1252//TRANSLIT', $input);
31
+        $input = (string) $input;
32
+        $input = iconv('utf-8', 'cp1252//TRANSLIT', $input);
33 33
         return $input;
34 34
     }
35 35
 }
Please login to merge, or discard this patch.
Indentation   +13 added lines, -14 removed lines patch added patch discarded remove patch
@@ -11,7 +11,6 @@  discard block
 block discarded – undo
11 11
  * Class Windows1252
12 12
  * Converts from utf8 encoding to windows 1252 (aka cp1252, aka ISO-8859-1, see https://en.wikipedia.org/wiki/Windows-1252).
13 13
  * This is useful if you need to send a string to a site using windows 1252 character encoding
14
-
15 14
  *
16 15
 *@package        Event Espresso
17 16
  * @author         Mike Nelson
@@ -20,19 +19,19 @@  discard block
 block discarded – undo
20 19
 class Windows1252 extends FormatterBase
21 20
 {
22 21
 
23
-    /**
24
-     * Converts the string to windows-1252 encoding.
25
-     *
26
-     * @param string|int|float $input anything easily cast into a string
27
-     * @return string
28
-     */
29
-    public function format($input)
30
-    {
31
-        //in case an int or float etc was passed in
32
-        $input = (string)$input;
33
-        $input = iconv('utf-8','cp1252//TRANSLIT', $input);
34
-        return $input;
35
-    }
22
+	/**
23
+	 * Converts the string to windows-1252 encoding.
24
+	 *
25
+	 * @param string|int|float $input anything easily cast into a string
26
+	 * @return string
27
+	 */
28
+	public function format($input)
29
+	{
30
+		//in case an int or float etc was passed in
31
+		$input = (string)$input;
32
+		$input = iconv('utf-8','cp1252//TRANSLIT', $input);
33
+		return $input;
34
+	}
36 35
 }
37 36
 // End of file EmojiRemoval.php
38 37
 // Location: core\services\formatters/EmojiRemoval.php
39 38
\ No newline at end of file
Please login to merge, or discard this patch.
admin/new/pricing/templates/event_tickets_datetime_ticket_row.template.php 2 patches
Braces   +40 added lines, -16 removed lines patch added patch discarded remove patch
@@ -6,24 +6,33 @@  discard block
 block discarded – undo
6 6
 		<?php if ( $disabled ) : ?>
7 7
 			<input type="hidden" id="edit-ticket-TKT_start_date-<?php echo $tkt_row; ?>"  name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_start_date]" class="edit-ticket-TKT_start_date ee-text-inp" value="<?php echo $TKT_start_date; ?>" >
8 8
 			<input type="text" name="archived_ticket[TKT_start_date]" class="edit-ticket-TKT_start_date ee-text-inp" value="<?php echo $TKT_start_date; ?>" disabled>
9
-		<?php else : ?>
10
-			<input id="edit-ticket-TKT_start_date-<?php echo $tkt_row; ?>" type="text" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_start_date]" class="edit-ticket-TKT_start_date ee-text-inp ee-datepicker" value="<?php echo $TKT_start_date; ?>" data-context="start-ticket" data-date-field-context="#display-ticketrow-<?php echo $tkt_row; ?>" data-related-field=".edit-ticket-TKT_end_date" data-next-field=".edit-ticket-TKT_end_date">
9
+		<?php else {
10
+	: ?>
11
+			<input id="edit-ticket-TKT_start_date-<?php echo $tkt_row;
12
+}
13
+?>" type="text" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_start_date]" class="edit-ticket-TKT_start_date ee-text-inp ee-datepicker" value="<?php echo $TKT_start_date; ?>" data-context="start-ticket" data-date-field-context="#display-ticketrow-<?php echo $tkt_row; ?>" data-related-field=".edit-ticket-TKT_end_date" data-next-field=".edit-ticket-TKT_end_date">
11 14
 		<?php endif; ?>
12 15
 	</td>
13 16
 	<td>
14 17
 		<?php if ( $disabled ) : ?>
15 18
 			<input type="hidden" id="edit-ticket-TKT_end_date-<?php echo $tkt_row; ?>"  name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_end_date]" class="edit-ticket-TKT_end_date ee-text-inp" value="<?php echo $TKT_end_date; ?>" >
16 19
 			<input type="text" name="archived_ticket[TKT_end_date]" class="edit-ticket-TKT_end_date ee-text-inp" value="<?php echo $TKT_end_date; ?>" disabled>
17
-		<?php else : ?>
18
-			<input id="edit-ticket-TKT_end_date-<?php echo $tkt_row; ?>" type="text" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_end_date]" class="edit-ticket-TKT_end_date ee-text-inp ee-datepicker" value="<?php echo $TKT_end_date; ?>" data-context="end-ticket" data-date-field-context="#display-ticketrow-<?php echo $tkt_row; ?>" data-related-field=".edit-ticket-TKT_start_date" data-next-field=".edit-ticket-TKT_qty">
20
+		<?php else {
21
+	: ?>
22
+			<input id="edit-ticket-TKT_end_date-<?php echo $tkt_row;
23
+}
24
+?>" type="text" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_end_date]" class="edit-ticket-TKT_end_date ee-text-inp ee-datepicker" value="<?php echo $TKT_end_date; ?>" data-context="end-ticket" data-date-field-context="#display-ticketrow-<?php echo $tkt_row; ?>" data-related-field=".edit-ticket-TKT_start_date" data-next-field=".edit-ticket-TKT_qty">
19 25
 		<?php endif; ?>
20 26
 	</td>
21 27
 	<td>
22 28
 		<?php if ( $disabled ) : ?>
23 29
 			<input id="edit-ticket-TKT_base_price-<?php echo $tkt_row; ?>" type="hidden" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_base_price]" class="edit-ticket-TKT_base_price ee-small-text-inp edit-price-PRC_amount ee-numeric" value="<?php echo $TKT_base_price; ?>">
24 30
 			<input type="text" name="archived_ticket[<?php echo $tkt_row; ?>][TKT_base_price]" class="edit-ticket-TKT_base_price ee-small-text-inp edit-price-PRC_amount ee-numeric" value="<?php echo $TKT_base_price; ?>" disabled>
25
-		<?php else : ?>
26
-			<input id="edit-ticket-TKT_base_price-<?php echo $tkt_row; ?>" type="text" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_base_price]" class="edit-ticket-TKT_base_price ee-small-text-inp edit-price-PRC_amount ee-numeric" value="<?php echo $TKT_base_price; ?>">
31
+		<?php else {
32
+	: ?>
33
+			<input id="edit-ticket-TKT_base_price-<?php echo $tkt_row;
34
+}
35
+?>" type="text" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_base_price]" class="edit-ticket-TKT_base_price ee-small-text-inp edit-price-PRC_amount ee-numeric" value="<?php echo $TKT_base_price; ?>">
27 36
 		<?php endif; ?>
28 37
 		<input type="hidden" id="edit-ticket-TKT_base_price_ID-<?php echo $tkt_row; ?>" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_base_price_ID]" value="<?php echo $TKT_base_price_ID; ?>">
29 38
 	</td>
@@ -31,8 +40,11 @@  discard block
 block discarded – undo
31 40
 		<?php if ( $disabled ) : ?>
32 41
 			<input type="hidden" class="edit-ticket-TKT_qty ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_qty]" value="<?php echo $TKT_qty_for_input; ?>">
33 42
 			<input type="text" class="edit-ticket-TKT_qty ee-small-text-inp ee-numeric" name="archived_ticket[<?php echo $tkt_row; ?>][TKT_qty]" value="<?php echo $TKT_qty_for_input; ?>" disabled>
34
-		<?php else : ?>
35
-			<input type="text" id="edit-ticket-TKT_qty-<?php echo $tkt_row; ?>"class="edit-ticket-TKT_qty ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_qty]" value="<?php echo $TKT_qty_for_input; ?>">
43
+		<?php else {
44
+	: ?>
45
+			<input type="text" id="edit-ticket-TKT_qty-<?php echo $tkt_row;
46
+}
47
+?>"class="edit-ticket-TKT_qty ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_qty]" value="<?php echo $TKT_qty_for_input; ?>">
36 48
 		<?php endif; ?>
37 49
 	</td>
38 50
 	<!--<td><span class="ticket-display-row-TKT_price"><?php //echo $TKT_price; ?></span></td>-->
@@ -79,24 +91,33 @@  discard block
 block discarded – undo
79 91
 								<?php if ( $disabled ) : ?>
80 92
 									<input type="hidden" class="edit-ticket-TKT_uses ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_uses]" value="<?php echo $TKT_uses; ?>">
81 93
 									<input type="text" class="edit-ticket-TKT_uses ee-small-text-inp ee-numeric" name="archived_ticket[<?php echo $tkt_row; ?>][TKT_uses]" value="<?php echo $TKT_uses; ?>" disabled>
82
-								<?php else : ?>
83
-									<input type="text" class="edit-ticket-TKT_uses ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_uses]" value="<?php echo $TKT_uses; ?>">
94
+								<?php else {
95
+	: ?>
96
+									<input type="text" class="edit-ticket-TKT_uses ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name;
97
+}
98
+?>[<?php echo $tkt_row; ?>][TKT_uses]" value="<?php echo $TKT_uses; ?>">
84 99
 								<?php endif; ?>
85 100
 							</td>
86 101
 							<td>
87 102
 								<?php if ( $disabled ) : ?>
88 103
 									<input type="hidden" class="edit-ticket-TKT_min ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_min]" value="<?php echo $TKT_min; ?>">
89 104
 									<input type="text" class="edit-ticket-TKT_min ee-small-text-inp ee-numeric" name="archived_ticket[<?php echo $tkt_row; ?>][TKT_min]" value="<?php echo $TKT_min; ?>" disabled>
90
-								<?php else: ?>
91
-									<input type="text" class="edit-ticket-TKT_min ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_min]" value="<?php echo $TKT_min; ?>">
105
+								<?php else {
106
+	: ?>
107
+									<input type="text" class="edit-ticket-TKT_min ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name;
108
+}
109
+?>[<?php echo $tkt_row; ?>][TKT_min]" value="<?php echo $TKT_min; ?>">
92 110
 								<?php endif; ?>
93 111
 							</td>
94 112
 							<td>
95 113
 								<?php if ( $disabled ) : ?>
96 114
 									<input type="hidden" class="edit-ticket-TKT_max ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_max]" value="<?php echo $TKT_max; ?>">
97 115
 									<input type="text" class="edit-ticket-TKT_max ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_max]" value="<?php echo $TKT_max; ?>" disabled>
98
-								<?php else : ?>
99
-									<input type="text" class="edit-ticket-TKT_max ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_max]" value="<?php echo $TKT_max; ?>">
116
+								<?php else {
117
+	: ?>
118
+									<input type="text" class="edit-ticket-TKT_max ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name;
119
+}
120
+?>[<?php echo $tkt_row; ?>][TKT_max]" value="<?php echo $TKT_max; ?>">
100 121
 								<?php endif; ?>
101 122
 							</td>
102 123
 						</tr>
@@ -117,8 +138,11 @@  discard block
 block discarded – undo
117 138
 							?>
118 139
 							<input class="TKT-taxable-checkbox" type="hidden" name="<?php echo $edit_tickets_name;?>[<?php echo $tkt_row; ?>][TKT_taxable]" value="<?php echo $tax_value; ?>">
119 140
 							<input class="TKT-taxable-checkbox" id="edit-ticket-TKT_taxable-<?php echo $tkt_row; ?>" type="checkbox" name="archived_ticket[<?php echo $tkt_row; ?>][TKT_taxable]" value="1"<?php echo $TKT_taxable; ?> disabled>
120
-						<?php else : ?>
121
-							<input class="TKT-taxable-checkbox" id="edit-ticket-TKT_taxable-<?php echo $tkt_row; ?>" type="checkbox" name="<?php echo $edit_tickets_name;?>[<?php echo $tkt_row; ?>][TKT_taxable]" value="1"<?php echo $TKT_taxable; ?>>
141
+						<?php else {
142
+	: ?>
143
+							<input class="TKT-taxable-checkbox" id="edit-ticket-TKT_taxable-<?php echo $tkt_row;
144
+}
145
+?>" type="checkbox" name="<?php echo $edit_tickets_name;?>[<?php echo $tkt_row; ?>][TKT_taxable]" value="1"<?php echo $TKT_taxable; ?>>
122 146
 						<?php endif; ?>
123 147
 						<label for="edit-ticket-TKT_taxable-<?php echo $tkt_row; ?>"> <?php esc_html_e('This ticket is taxable.', 'event_espresso'); ?>
124 148
 					<?php } //end tax_rows check ?>
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@  discard block
 block discarded – undo
1
-    <tr valign="top" class="ee-ticket-sortable ticket-row<?php echo $ticket_archive_class; if(WP_DEBUG){ echo ' ee-wp-debug'; } ?>" id="display-ticketrow-<?php echo $tkt_row; ?>">
1
+    <tr valign="top" class="ee-ticket-sortable ticket-row<?php echo $ticket_archive_class; if (WP_DEBUG) { echo ' ee-wp-debug'; } ?>" id="display-ticketrow-<?php echo $tkt_row; ?>">
2 2
 	<!--<td class="ee-tkt-order-field"><span class="dashicons dashicons-sort<?php echo $tkt_status_class; ?>"><input type="hidden" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_order]" class="edit-ticket-TKT_order" value ="<?php echo $TKT_order; ?>" ></span></td>-->
3 3
 	<td class="ee-tkt-order-field"><span class="ee-status-strip-td ee-status-strip<?php echo $tkt_status_class; ?>"></span><input type="hidden" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_order]" class="edit-ticket-TKT_order" value ="<?php echo $TKT_order; ?>"></td>
4 4
 	<td><input maxlength="245" type="text" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_name]" class="edit-ticket-TKT_name ee-large-text-inp" placeholder="Ticket Title" value="<?php echo $TKT_name; ?>"></td>
5 5
 	<td>
6
-		<?php if ( $disabled ) : ?>
6
+		<?php if ($disabled) : ?>
7 7
 			<input type="hidden" id="edit-ticket-TKT_start_date-<?php echo $tkt_row; ?>"  name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_start_date]" class="edit-ticket-TKT_start_date ee-text-inp" value="<?php echo $TKT_start_date; ?>" >
8 8
 			<input type="text" name="archived_ticket[TKT_start_date]" class="edit-ticket-TKT_start_date ee-text-inp" value="<?php echo $TKT_start_date; ?>" disabled>
9 9
 		<?php else : ?>
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 		<?php endif; ?>
12 12
 	</td>
13 13
 	<td>
14
-		<?php if ( $disabled ) : ?>
14
+		<?php if ($disabled) : ?>
15 15
 			<input type="hidden" id="edit-ticket-TKT_end_date-<?php echo $tkt_row; ?>"  name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_end_date]" class="edit-ticket-TKT_end_date ee-text-inp" value="<?php echo $TKT_end_date; ?>" >
16 16
 			<input type="text" name="archived_ticket[TKT_end_date]" class="edit-ticket-TKT_end_date ee-text-inp" value="<?php echo $TKT_end_date; ?>" disabled>
17 17
 		<?php else : ?>
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 		<?php endif; ?>
20 20
 	</td>
21 21
 	<td>
22
-		<?php if ( $disabled ) : ?>
22
+		<?php if ($disabled) : ?>
23 23
 			<input id="edit-ticket-TKT_base_price-<?php echo $tkt_row; ?>" type="hidden" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_base_price]" class="edit-ticket-TKT_base_price ee-small-text-inp edit-price-PRC_amount ee-numeric" value="<?php echo $TKT_base_price; ?>">
24 24
 			<input type="text" name="archived_ticket[<?php echo $tkt_row; ?>][TKT_base_price]" class="edit-ticket-TKT_base_price ee-small-text-inp edit-price-PRC_amount ee-numeric" value="<?php echo $TKT_base_price; ?>" disabled>
25 25
 		<?php else : ?>
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 		<input type="hidden" id="edit-ticket-TKT_base_price_ID-<?php echo $tkt_row; ?>" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_base_price_ID]" value="<?php echo $TKT_base_price_ID; ?>">
29 29
 	</td>
30 30
 	<td>
31
-		<?php if ( $disabled ) : ?>
31
+		<?php if ($disabled) : ?>
32 32
 			<input type="hidden" class="edit-ticket-TKT_qty ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_qty]" value="<?php echo $TKT_qty_for_input; ?>">
33 33
 			<input type="text" class="edit-ticket-TKT_qty ee-small-text-inp ee-numeric" name="archived_ticket[<?php echo $tkt_row; ?>][TKT_qty]" value="<?php echo $TKT_qty_for_input; ?>" disabled>
34 34
 		<?php else : ?>
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 	</td>
38 38
 	<!--<td><span class="ticket-display-row-TKT_price"><?php //echo $TKT_price; ?></span></td>-->
39 39
 	<td><span class="ticket-display-row-TKT_sold"><?php echo $TKT_sold; ?></span></td>
40
-    <?php if(WP_DEBUG):  // for now we are only showing reserved counts if WP_DEBUG is on?>
40
+    <?php if (WP_DEBUG):  // for now we are only showing reserved counts if WP_DEBUG is on?>
41 41
 	<td><span class="ticket-display-row-TKT_reserved"><?php echo $TKT_reserved; ?></span></td>
42 42
     <?php endif; ?>
43 43
     <td><span class="ticket-display-row-TKT_registrations"><?php echo $TKT_registrations; ?></span></td>
@@ -56,10 +56,10 @@  discard block
 block discarded – undo
56 56
 			<input type="hidden" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_ID]" class="edit-ticket-TKT_ID" value="<?php echo $TKT_ID; ?>">
57 57
 			<input type="hidden" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_row]" class="edit-ticket-TKT_row" value="<?php echo $tkt_row; ?>">
58 58
 
59
-			<!--<div class="total-price-container"><?php printf( esc_html__('Total Final Price: %s', 'event_espresso'), '<span class="ticket-price-amount">' . $TKT_price . '</span>'); ?> </div>-->
59
+			<!--<div class="total-price-container"><?php printf(esc_html__('Total Final Price: %s', 'event_espresso'), '<span class="ticket-price-amount">'.$TKT_price.'</span>'); ?> </div>-->
60 60
 			<textarea name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_description]" class="edit-ticket-TKT_description ee-full-textarea-inp" placeholder="Ticket Description"><?php echo $TKT_description; ?></textarea>
61 61
 
62
-			<?php do_action( 'AHEE__event_tickets_datetime_ticket_row_template_after_desc', $tkt_row, $TKT_ID ); ?>
62
+			<?php do_action('AHEE__event_tickets_datetime_ticket_row_template_after_desc', $tkt_row, $TKT_ID); ?>
63 63
 
64 64
 			<div class="basic-ticket-container">
65 65
 				<h4 class="tickets-heading"><?php esc_html_e('Ticket Details', 'event_espresso'); ?></h4>
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 					<tbody>
76 76
 						<tr>
77 77
 							<td>
78
-								<?php if ( $disabled ) : ?>
78
+								<?php if ($disabled) : ?>
79 79
 									<input type="hidden" class="edit-ticket-TKT_uses ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_uses]" value="<?php echo $TKT_uses; ?>">
80 80
 									<input type="text" class="edit-ticket-TKT_uses ee-small-text-inp ee-numeric" name="archived_ticket[<?php echo $tkt_row; ?>][TKT_uses]" value="<?php echo $TKT_uses; ?>" disabled>
81 81
 								<?php else : ?>
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 								<?php endif; ?>
84 84
 							</td>
85 85
 							<td>
86
-								<?php if ( $disabled ) : ?>
86
+								<?php if ($disabled) : ?>
87 87
 									<input type="hidden" class="edit-ticket-TKT_min ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_min]" value="<?php echo $TKT_min; ?>">
88 88
 									<input type="text" class="edit-ticket-TKT_min ee-small-text-inp ee-numeric" name="archived_ticket[<?php echo $tkt_row; ?>][TKT_min]" value="<?php echo $TKT_min; ?>" disabled>
89 89
 								<?php else: ?>
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 								<?php endif; ?>
92 92
 							</td>
93 93
 							<td>
94
-								<?php if ( $disabled ) : ?>
94
+								<?php if ($disabled) : ?>
95 95
 									<input type="hidden" class="edit-ticket-TKT_max ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_max]" value="<?php echo $TKT_max; ?>">
96 96
 									<input type="text" class="edit-ticket-TKT_max ee-small-text-inp ee-numeric" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_max]" value="<?php echo $TKT_max; ?>" disabled>
97 97
 								<?php else : ?>
@@ -109,15 +109,15 @@  discard block
 block discarded – undo
109 109
 					<label for="edit-ticket-TKT_required"><?php esc_html_e('This ticket is required (will appear first in frontend ticket lists).', 'event_espresso'); ?></label>
110 110
 				</div>
111 111
 				<div class="ticket-is-taxable-container">
112
-					<?php if ( !empty($tax_rows) ) { ?>
113
-						<?php if ( $disabled ) : ?>
112
+					<?php if ( ! empty($tax_rows)) { ?>
113
+						<?php if ($disabled) : ?>
114 114
 							<?php
115
-								$tax_value = !empty( $TKT_taxable ) ? 1 : 0;
115
+								$tax_value = ! empty($TKT_taxable) ? 1 : 0;
116 116
 							?>
117
-							<input class="TKT-taxable-checkbox" type="hidden" name="<?php echo $edit_tickets_name;?>[<?php echo $tkt_row; ?>][TKT_taxable]" value="<?php echo $tax_value; ?>">
117
+							<input class="TKT-taxable-checkbox" type="hidden" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_taxable]" value="<?php echo $tax_value; ?>">
118 118
 							<input class="TKT-taxable-checkbox" id="edit-ticket-TKT_taxable-<?php echo $tkt_row; ?>" type="checkbox" name="archived_ticket[<?php echo $tkt_row; ?>][TKT_taxable]" value="1"<?php echo $TKT_taxable; ?> disabled>
119 119
 						<?php else : ?>
120
-							<input class="TKT-taxable-checkbox" id="edit-ticket-TKT_taxable-<?php echo $tkt_row; ?>" type="checkbox" name="<?php echo $edit_tickets_name;?>[<?php echo $tkt_row; ?>][TKT_taxable]" value="1"<?php echo $TKT_taxable; ?>>
120
+							<input class="TKT-taxable-checkbox" id="edit-ticket-TKT_taxable-<?php echo $tkt_row; ?>" type="checkbox" name="<?php echo $edit_tickets_name; ?>[<?php echo $tkt_row; ?>][TKT_taxable]" value="1"<?php echo $TKT_taxable; ?>>
121 121
 						<?php endif; ?>
122 122
 						<label for="edit-ticket-TKT_taxable-<?php echo $tkt_row; ?>"> <?php esc_html_e('This ticket is taxable.', 'event_espresso'); ?>
123 123
 					<?php } //end tax_rows check ?>
@@ -174,10 +174,10 @@  discard block
 block discarded – undo
174 174
 				<?php echo $ticket_datetimes_list; ?>
175 175
 			</ul>
176 176
 
177
-			<?php do_action( 'AHEE__event_tickets_datetime_ticket_row_template__advanced_details_end', $tkt_row, $TKT_ID ); ?>
177
+			<?php do_action('AHEE__event_tickets_datetime_ticket_row_template__advanced_details_end', $tkt_row, $TKT_ID); ?>
178 178
 			<div class="ee-editor-footer-container">
179 179
 				<div class="ee-editor-id-container">
180
-					<span class="ee-item-id"><?php echo $TKT_ID ? sprintf( esc_html__( 'Ticket ID: %d', 'event_espresso' ), $TKT_ID ) : ''; ?></span>
180
+					<span class="ee-item-id"><?php echo $TKT_ID ? sprintf(esc_html__('Ticket ID: %d', 'event_espresso'), $TKT_ID) : ''; ?></span>
181 181
 				</div>
182 182
 				<div class="save-cancel-button-container">
183 183
 					<label for="edit-ticket-TKT_is_default_selector"><?php esc_html_e('use this new ticket as a default ticket for any new events', 'event_espresso'); ?></label>
Please login to merge, or discard this patch.
caffeinated/admin/new/pricing/espresso_events_Pricing_Hooks.class.php 1 patch
Indentation   +1530 added lines, -1530 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 
6 6
 /**
@@ -31,1535 +31,1535 @@  discard block
 block discarded – undo
31 31
 class espresso_events_Pricing_Hooks extends EE_Admin_Hooks
32 32
 {
33 33
 
34
-    /**
35
-     * This property is just used to hold the status of whether an event is currently being
36
-     * created (true) or edited (false)
37
-     * @access protected
38
-     * @var bool
39
-     */
40
-    protected $_is_creating_event;
41
-
42
-
43
-    /**
44
-     * Used to contain the format strings for date and time that will be used for php date and
45
-     * time.
46
-     *
47
-     * Is set in the _set_hooks_properties() method.
48
-     *
49
-     * @var array
50
-     */
51
-    protected $_date_format_strings;
52
-
53
-
54
-    protected function _set_hooks_properties()
55
-    {
56
-        $this->_name = 'pricing';
57
-
58
-        //capability check
59
-        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_default_prices',
60
-            'advanced_ticket_datetime_metabox')
61
-        ) {
62
-            return;
63
-        }
64
-
65
-
66
-        //if we were going to add our own metaboxes we'd use the below.
67
-        $this->_metaboxes = array(
68
-            0 => array(
69
-                'page_route' => array('edit', 'create_new'),
70
-                'func'       => 'pricing_metabox',
71
-                'label'      => __('Event Tickets & Datetimes', 'event_espresso'),
72
-                'priority'   => 'high',
73
-                'context'    => 'normal'
74
-            ),
75
-
76
-        );/**/
77
-
78
-        $this->_remove_metaboxes = array(
79
-            0 => array(
80
-                'page_route' => array('edit', 'create_new'),
81
-                'id'         => 'espresso_event_editor_tickets',
82
-                'context'    => 'normal'
83
-            )
84
-        );
85
-
86
-        /**
87
-         * Format strings for date and time.  Defaults are existing behaviour from 4.1.
88
-         * Note, that if you return null as the value for 'date', and 'time' in the array, then
89
-         * EE will automatically use the set wp_options, 'date_format', and 'time_format'.
90
-         *
91
-         * @since 4.6.7
92
-         *
93
-         * @var array  Expected an array returned with 'date' and 'time' keys.
94
-         */
95
-        $this->_date_format_strings = apply_filters('FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings',
96
-            array(
97
-                'date' => 'Y-m-d',
98
-                'time' => 'h:i a'
99
-            ));
100
-
101
-        //validate
102
-        $this->_date_format_strings['date'] = isset($this->_date_format_strings['date']) ? $this->_date_format_strings['date'] : null;
103
-        $this->_date_format_strings['time'] = isset($this->_date_format_strings['time']) ? $this->_date_format_strings['time'] : null;
104
-
105
-        //validate format strings
106
-        $format_validation = EEH_DTT_Helper::validate_format_string($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']);
107
-        if (is_array($format_validation)) {
108
-            $msg = '<p>' . sprintf(__('The format "%s" was likely added via a filter and is invalid for the following reasons:',
109
-                    'event_espresso'),
110
-                    $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']) . '</p><ul>';
111
-            foreach ($format_validation as $error) {
112
-                $msg .= '<li>' . $error . '</li>';
113
-            }
114
-            $msg .= '</ul></p><p>' . sprintf(__('%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s',
115
-                    'event_espresso'), '<span style="color:#D54E21;">', '</span>') . '</p>';
116
-            EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
117
-            $this->_date_format_strings = array(
118
-                'date' => 'Y-m-d',
119
-                'time' => 'h:i a'
120
-            );
121
-        }
122
-
123
-
124
-        $this->_scripts_styles = array(
125
-            'registers'   => array(
126
-                'ee-tickets-datetimes-css' => array(
127
-                    'url'  => PRICING_ASSETS_URL . 'event-tickets-datetimes.css',
128
-                    'type' => 'css'
129
-                ),
130
-                'ee-dtt-ticket-metabox'    => array(
131
-                    'url'     => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js',
132
-                    'depends' => array('ee-datepicker', 'ee-dialog', 'underscore')
133
-                )
134
-            ),
135
-            'deregisters' => array(
136
-                'event-editor-css'       => array('type' => 'css'),
137
-                'event-datetime-metabox' => array('type' => 'js')
138
-            ),
139
-            'enqueues'    => array(
140
-                'ee-tickets-datetimes-css' => array('edit', 'create_new'),
141
-                'ee-dtt-ticket-metabox'    => array('edit', 'create_new')
142
-            ),
143
-            'localize'    => array(
144
-                'ee-dtt-ticket-metabox' => array(
145
-                    'DTT_TRASH_BLOCK'       => array(
146
-                        'main_warning'            => __('The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):',
147
-                            'event_espresso'),
148
-                        'after_warning'           => __('In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.',
149
-                            'event_espresso'),
150
-                        'cancel_button'           => '<button class="button-secondary ee-modal-cancel">' . __('Cancel',
151
-                                'event_espresso') . '</button>',
152
-                        'close_button'            => '<button class="button-secondary ee-modal-cancel">' . __('Close',
153
-                                'event_espresso') . '</button>',
154
-                        'single_warning_from_tkt' => __('The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.',
155
-                            'event_espresso'),
156
-                        'single_warning_from_dtt' => __('The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket.  Tickets must always have at least one datetime assigned to them.',
157
-                            'event_espresso'),
158
-                        'dismiss_button'          => '<button class="button-secondary ee-modal-cancel">' . __('Dismiss',
159
-                                'event_espresso') . '</button>'
160
-                    ),
161
-                    'DTT_ERROR_MSG'         => array(
162
-                        'no_ticket_name' => __('General Admission', 'event_espresso'),
163
-                        'dismiss_button' => '<div class="save-cancel-button-container"><button class="button-secondary ee-modal-cancel">' . __('Dismiss',
164
-                                'event_espresso') . '</button></div>'
165
-                    ),
166
-                    'DTT_OVERSELL_WARNING'  => array(
167
-                        'datetime_ticket' => __('You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.',
168
-                            'event_espresso'),
169
-                        'ticket_datetime' => __('You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.',
170
-                            'event_espresso')
171
-                    ),
172
-                    'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats($this->_date_format_strings['date'],
173
-                        $this->_date_format_strings['time']),
174
-                    'DTT_START_OF_WEEK'     => array('dayValue' => (int)get_option('start_of_week'))
175
-                )
176
-            )
177
-        );
178
-
179
-
180
-        add_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page',
181
-            array($this, 'autosave_handling'), 10);
182
-        add_filter('FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
183
-            array($this, 'caf_updates'), 10);
184
-    }
185
-
186
-
187
-    public function caf_updates($update_callbacks)
188
-    {
189
-        foreach ($update_callbacks as $key => $callback) {
190
-            if ($callback[1] == '_default_tickets_update') {
191
-                unset($update_callbacks[$key]);
192
-            }
193
-        }
194
-
195
-        $update_callbacks[] = array($this, 'dtt_and_tickets_caf_update');
196
-
197
-        return $update_callbacks;
198
-    }
199
-
200
-
201
-    /**
202
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
203
-     *
204
-     * @param  EE_Event $evtobj The Event object we're attaching data to
205
-     * @param  array    $data   The request data from the form
206
-     *
207
-     * @return bool             success or fail
208
-     */
209
-    public function dtt_and_tickets_caf_update($evtobj, $data)
210
-    {
211
-        //first we need to start with datetimes cause they are the "root" items attached to events.
212
-        $saved_dtts = $this->_update_dtts($evtobj, $data);
213
-        //next tackle the tickets (and prices?)
214
-        $this->_update_tkts($evtobj, $saved_dtts, $data);
215
-    }
216
-
217
-
218
-    /**
219
-     * update event_datetimes
220
-     *
221
-     * @param  EE_Event $evt_obj Event being updated
222
-     * @param  array    $data    the request data from the form
223
-     *
224
-     * @return EE_Datetime[]
225
-     */
226
-    protected function _update_dtts($evt_obj, $data)
227
-    {
228
-        $timezone       = isset($data['timezone_string']) ? $data['timezone_string'] : null;
229
-        $saved_dtt_ids  = array();
230
-        $saved_dtt_objs = array();
231
-
232
-        foreach ($data['edit_event_datetimes'] as $row => $dtt) {
233
-            //trim all values to ensure any excess whitespace is removed.
234
-            $dtt                = array_map(
235
-                function ($datetime_data) {
236
-                    return is_array($datetime_data) ? $datetime_data : trim($datetime_data);
237
-                },
238
-                $dtt
239
-            );
240
-            $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end'] : $dtt['DTT_EVT_start'];
241
-            $datetime_values    = array(
242
-                'DTT_ID'          => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
243
-                'DTT_name'        => ! empty($dtt['DTT_name']) ? $dtt['DTT_name'] : '',
244
-                'DTT_description' => ! empty($dtt['DTT_description']) ? $dtt['DTT_description'] : '',
245
-                'DTT_EVT_start'   => $dtt['DTT_EVT_start'],
246
-                'DTT_EVT_end'     => $dtt['DTT_EVT_end'],
247
-                'DTT_reg_limit'   => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
248
-                'DTT_order'       => ! isset($dtt['DTT_order']) ? $row : $dtt['DTT_order'],
249
-            );
250
-
251
-            //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.
252
-
253
-            if ( ! empty($dtt['DTT_ID'])) {
254
-                $DTM = EE_Registry::instance()->load_model('Datetime', array($timezone))->get_one_by_ID($dtt['DTT_ID']);
255
-
256
-                //set date and time format according to what is set in this class.
257
-                $DTM->set_date_format($this->_date_format_strings['date']);
258
-                $DTM->set_time_format($this->_date_format_strings['time']);
259
-
260
-                foreach ($datetime_values as $field => $value) {
261
-                    $DTM->set($field, $value);
262
-                }
263
-
264
-                // make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.
265
-                // We need to do this so we dont' TRASH the parent DTT.(save the ID for both key and value to avoid duplications)
266
-                $saved_dtt_ids[$DTM->ID()] = $DTM->ID();
267
-
268
-            } else {
269
-                $DTM = EE_Registry::instance()->load_class(
270
-                    'Datetime',
271
-                    array(
272
-                        $datetime_values,
273
-                        $timezone,
274
-                        array($this->_date_format_strings['date'], $this->_date_format_strings['time'])
275
-                    ),
276
-                    false,
277
-                    false
278
-                );
279
-
280
-                foreach ($datetime_values as $field => $value) {
281
-                    $DTM->set($field, $value);
282
-                }
283
-            }
284
-
285
-
286
-            $DTM->save();
287
-            $DTM = $evt_obj->_add_relation_to($DTM, 'Datetime');
288
-            $evt_obj->save();
289
-
290
-            //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.
291
-            if ($DTM->get_raw('DTT_EVT_start') > $DTM->get_raw('DTT_EVT_end')) {
292
-                $DTM->set('DTT_EVT_end', $DTM->get('DTT_EVT_start'));
293
-                $DTM = EEH_DTT_Helper::date_time_add($DTM, 'DTT_EVT_end', 'days');
294
-                $DTM->save();
295
-            }
296
-
297
-            //	now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array
298
-            // because it is possible there was a new one created for the autosave.
299
-            // (save the ID for both key and value to avoid duplications)
300
-            $saved_dtt_ids[$DTM->ID()] = $DTM->ID();
301
-            $saved_dtt_objs[$row]      = $DTM;
302
-
303
-            //todo if ANY of these updates fail then we want the appropriate global error message.
304
-        }
305
-
306
-        //now we need to REMOVE any dtts that got deleted.  Keep in mind that this process will only kick in for DTT's that don't have any DTT_sold on them. So its safe to permanently delete at this point.
307
-        $old_datetimes = explode(',', $data['datetime_IDs']);
308
-        $old_datetimes = $old_datetimes[0] == '' ? array() : $old_datetimes;
309
-
310
-        if (is_array($old_datetimes)) {
311
-            $dtts_to_delete = array_diff($old_datetimes, $saved_dtt_ids);
312
-            foreach ($dtts_to_delete as $id) {
313
-                $id = absint($id);
314
-                if (empty($id)) {
315
-                    continue;
316
-                }
317
-
318
-                $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id);
319
-
320
-                //remove tkt relationships.
321
-                $related_tickets = $dtt_to_remove->get_many_related('Ticket');
322
-                foreach ($related_tickets as $tkt) {
323
-                    $dtt_to_remove->_remove_relation_to($tkt, 'Ticket');
324
-                }
325
-
326
-                $evt_obj->_remove_relation_to($id, 'Datetime');
327
-                $dtt_to_remove->refresh_cache_of_related_objects();
328
-
329
-            }
330
-        }
331
-
332
-        return $saved_dtt_objs;
333
-    }
334
-
335
-
336
-    /**
337
-     * update tickets
338
-     *
339
-     * @param  EE_Event      $evtobj     Event object being updated
340
-     * @param  EE_Datetime[] $saved_dtts an array of datetime ids being updated
341
-     * @param  array         $data       incoming request data
342
-     *
343
-     * @return EE_Ticket[]
344
-     */
345
-    protected function _update_tkts($evtobj, $saved_dtts, $data)
346
-    {
347
-
348
-        $new_tkt     = null;
349
-        $new_default = null;
350
-        //stripslashes because WP filtered the $_POST ($data) array to add slashes
351
-        $data          = stripslashes_deep($data);
352
-        $timezone      = isset($data['timezone_string']) ? $data['timezone_string'] : null;
353
-        $saved_tickets = $dtts_on_existing = array();
354
-        $old_tickets   = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
355
-
356
-        //load money helper
357
-
358
-        foreach ($data['edit_tickets'] as $row => $tkt) {
359
-
360
-            $update_prices = $create_new_TKT = false;
361
-
362
-            //figure out what dtts were added to the ticket and what dtts were removed from the ticket in the session.
363
-
364
-            $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][$row]);
365
-            $tkt_dtt_rows          = explode(',', $data['ticket_datetime_rows'][$row]);
366
-            $dtts_added            = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows);
367
-            $dtts_removed          = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows);
368
-
369
-            // trim inputs to ensure any excess whitespace is removed.
370
-            $tkt = array_map(
371
-                function ($ticket_data) {
372
-                    return is_array($ticket_data) ? $ticket_data : trim($ticket_data);
373
-                },
374
-                $tkt
375
-            );
376
-
377
-            //note we are doing conversions to floats here instead of allowing EE_Money_Field to handle because we're doing calcs prior to using the models.
378
-            //note incoming ['TKT_price'] value is already in standard notation (via js).
379
-            $ticket_price = isset($tkt['TKT_price']) ? round((float)$tkt['TKT_price'], 3) : 0;
380
-
381
-            //note incoming base price needs converted from localized value.
382
-            $base_price = isset($tkt['TKT_base_price']) ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price']) : 0;
383
-            //if ticket price == 0 and $base_price != 0 then ticket price == base_price
384
-            $ticket_price  = $ticket_price === 0 && $base_price !== 0 ? $base_price : $ticket_price;
385
-            $base_price_id = isset($tkt['TKT_base_price_ID']) ? $tkt['TKT_base_price_ID'] : 0;
386
-
387
-            $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][$row]) ? $data['edit_prices'][$row] : array();
388
-
389
-            $now = null;
390
-            if (empty($tkt['TKT_start_date'])) {
391
-                //lets' use now in the set timezone.
392
-                $now                   = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
393
-                $tkt['TKT_start_date'] = $now->format($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']);
394
-            }
395
-
396
-            if (empty($tkt['TKT_end_date'])) {
397
-                /**
398
-                 * set the TKT_end_date to the first datetime attached to the ticket.
399
-                 */
400
-                $first_dtt           = $saved_dtts[reset($tkt_dtt_rows)];
401
-                $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_format_strings['date'] . ' ' . $this->_date_format_string['time']);
402
-            }
403
-
404
-            $TKT_values = array(
405
-                'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
406
-                'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
407
-                'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
408
-                'TKT_description' => ! empty($tkt['TKT_description']) && $tkt['TKT_description'] != __('You can modify this description',
409
-                    'event_espresso') ? $tkt['TKT_description'] : '',
410
-                'TKT_start_date'  => $tkt['TKT_start_date'],
411
-                'TKT_end_date'    => $tkt['TKT_end_date'],
412
-                'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
413
-                'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
414
-                'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
415
-                'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
416
-                'TKT_row'         => $row,
417
-                'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0,
418
-                'TKT_taxable'     => ! empty($tkt['TKT_taxable']) ? 1 : 0,
419
-                'TKT_required'    => ! empty($tkt['TKT_required']) ? 1 : 0,
420
-                'TKT_price'       => $ticket_price
421
-            );
422
-
423
-
424
-            //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.
425
-            if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
426
-                $TKT_values['TKT_ID']         = 0;
427
-                $TKT_values['TKT_is_default'] = 0;
428
-                $update_prices                = true;
429
-            }
430
-
431
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
432
-            // we actually do our saves ahead of doing any add_relations to
433
-            // because its entirely possible that this ticket wasn't removed or added to any datetime in the session
434
-            // but DID have it's items modified.
435
-            // keep in mind that if the TKT has been sold (and we have changed pricing information),
436
-            // then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
437
-            if (absint($TKT_values['TKT_ID'])) {
438
-                $TKT = EE_Registry::instance()->load_model('Ticket', array($timezone))->get_one_by_ID($tkt['TKT_ID']);
439
-                if ($TKT instanceof EE_Ticket) {
440
-
441
-                    $TKT = $this->_update_ticket_datetimes($TKT, $saved_dtts, $dtts_added, $dtts_removed);
442
-                    // are there any registrations using this ticket ?
443
-                    $tickets_sold = $TKT->count_related(
444
-                        'Registration',
445
-                        array(
446
-                            array(
447
-                                'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete))
448
-                            )
449
-                        )
450
-                    );
451
-                    //set ticket formats
452
-                    $TKT->set_date_format($this->_date_format_strings['date']);
453
-                    $TKT->set_time_format($this->_date_format_strings['time']);
454
-
455
-                    // let's just check the total price for the existing ticket
456
-                    // and determine if it matches the new total price.
457
-                    // if they are different then we create a new ticket (if tkts sold)
458
-                    // if they aren't different then we go ahead and modify existing ticket.
459
-                    $create_new_TKT = $tickets_sold > 0 && $ticket_price != $TKT->price() && ! $TKT->deleted()
460
-                        ? true : false;
461
-
462
-                    //set new values
463
-                    foreach ($TKT_values as $field => $value) {
464
-                        if ($field === 'TKT_qty') {
465
-                            $TKT->set_qty($value);
466
-                        } else {
467
-                            $TKT->set($field, $value);
468
-                        }
469
-                    }
470
-
471
-                    //if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
472
-                    if ($create_new_TKT) {
473
-                        $new_tkt = $this->_duplicate_ticket($TKT, $price_rows, $ticket_price, $base_price,
474
-                            $base_price_id);
475
-                    }
476
-                }
477
-
478
-            } else {
479
-                // no TKT_id so a new TKT
480
-                $TKT = EE_Ticket::new_instance(
481
-                    $TKT_values,
482
-                    $timezone,
483
-                    array($this->_date_format_strings['date'], $this->_date_format_strings['time'])
484
-                );
485
-                if ($TKT instanceof EE_Ticket) {
486
-                    // make sure ticket has an ID of setting relations won't work
487
-                    $TKT->save();
488
-                    $TKT           = $this->_update_ticket_datetimes($TKT, $saved_dtts, $dtts_added, $dtts_removed);
489
-                    $update_prices = true;
490
-                }
491
-            }
492
-            //make sure any current values have been saved.
493
-            //$TKT->save();
494
-
495
-            //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.
496
-            if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
497
-                $TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
498
-                $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
499
-            }
500
-
501
-            //let's make sure the base price is handled
502
-            $TKT = ! $create_new_TKT ? $this->_add_prices_to_ticket(array(), $TKT, $update_prices, $base_price,
503
-                $base_price_id) : $TKT;
504
-
505
-            //add/update price_modifiers
506
-            $TKT = ! $create_new_TKT ? $this->_add_prices_to_ticket($price_rows, $TKT, $update_prices) : $TKT;
507
-
508
-            //need to make sue that the TKT_price is accurate after saving the prices.
509
-            $TKT->ensure_TKT_Price_correct();
510
-
511
-            //handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave.
512
-            if ( ! defined('DOING_AUTOSAVE')) {
513
-                if ( ! empty($tkt['TKT_is_default_selector'])) {
514
-                    $update_prices = true;
515
-                    $new_default   = clone $TKT;
516
-                    $new_default->set('TKT_ID', 0);
517
-                    $new_default->set('TKT_is_default', 1);
518
-                    $new_default->set('TKT_row', 1);
519
-                    $new_default->set('TKT_price', $ticket_price);
520
-                    //remove any dtt relations cause we DON'T want dtt relations attached (note this is just removing the cached relations in the object)
521
-                    $new_default->_remove_relations('Datetime');
522
-                    //todo we need to add the current attached prices as new prices to the new default ticket.
523
-                    $new_default = $this->_add_prices_to_ticket($price_rows, $new_default, $update_prices);
524
-                    //don't forget the base price!
525
-                    $new_default = $this->_add_prices_to_ticket(array(), $new_default, $update_prices, $base_price,
526
-                        $base_price_id);
527
-                    $new_default->save();
528
-                    do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket', $new_default,
529
-                        $row, $TKT, $data);
530
-                }
531
-            }
532
-
533
-
534
-            //DO ALL dtt relationships for both current tickets and any archived tickets for the given dtt that are related to the current ticket. TODO... not sure exactly how we're going to do this considering we don't know what current ticket the archived tickets are related to (and TKT_parent is used for autosaves so that's not a field we can reliably use).
535
-
536
-
537
-            //let's assign any tickets that have been setup to the saved_tickets tracker
538
-            //save existing TKT
539
-            $TKT->save();
540
-            if ($create_new_TKT && $new_tkt instanceof EE_Ticket) {
541
-                //save new TKT
542
-                $new_tkt->save();
543
-                //add new ticket to array
544
-                $saved_tickets[$new_tkt->ID()] = $new_tkt;
545
-
546
-                do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket', $new_tkt, $row, $tkt, $data);
547
-
548
-            } else {
549
-                //add tkt to saved tkts
550
-                $saved_tickets[$TKT->ID()] = $TKT;
551
-
552
-                do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket', $TKT, $row, $tkt, $data);
553
-            }
554
-
555
-        }
556
-
557
-        // now we need to handle tickets actually "deleted permanently".
558
-        // There are cases where we'd want this to happen
559
-        // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket).
560
-        // Or a draft event was saved and in the process of editing a ticket is trashed.
561
-        // No sense in keeping all the related data in the db!
562
-        $old_tickets     = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
563
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
564
-
565
-        foreach ($tickets_removed as $id) {
566
-            $id = absint($id);
567
-
568
-            //get the ticket for this id
569
-            $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
570
-
571
-            //if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime
572
-            if ($tkt_to_remove->get('TKT_is_default')) {
573
-                continue;
574
-            }
575
-
576
-            // if this tkt has any registrations attached so then we just ARCHIVE
577
-            // because we don't actually permanently delete these tickets.
578
-            if ($tkt_to_remove->count_related('Registration') > 0) {
579
-                $tkt_to_remove->delete();
580
-                continue;
581
-            }
582
-
583
-            // need to get all the related datetimes on this ticket and remove from every single one of them
584
-            // (remember this process can ONLY kick off if there are NO tkts_sold)
585
-            $dtts = $tkt_to_remove->get_many_related('Datetime');
586
-
587
-            foreach ($dtts as $dtt) {
588
-                $tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
589
-            }
590
-
591
-            // need to do the same for prices (except these prices can also be deleted because again,
592
-            // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
593
-            $tkt_to_remove->delete_related_permanently('Price');
594
-
595
-            do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove);
596
-
597
-            // finally let's delete this ticket
598
-            // (which should not be blocked at this point b/c we've removed all our relationships)
599
-            $tkt_to_remove->delete_permanently();
600
-        }
601
-
602
-        return $saved_tickets;
603
-    }
604
-
605
-
606
-    /**
607
-     *
608
-     * @access  protected
609
-     *
610
-     * @param \EE_Ticket     $ticket
611
-     * @param \EE_Datetime[] $saved_datetimes
612
-     * @param \EE_Datetime[] $added_datetimes
613
-     * @param \EE_Datetime[] $removed_datetimes
614
-     *
615
-     * @return \EE_Ticket
616
-     * @throws \EE_Error
617
-     */
618
-    protected function _update_ticket_datetimes(
619
-        EE_Ticket $ticket,
620
-        $saved_datetimes = array(),
621
-        $added_datetimes = array(),
622
-        $removed_datetimes = array()
623
-    ) {
624
-
625
-        // to start we have to add the ticket to all the datetimes its supposed to be with,
626
-        // and removing the ticket from datetimes it got removed from.
627
-
628
-        // first let's add datetimes
629
-        if ( ! empty($added_datetimes) && is_array($added_datetimes)) {
630
-            foreach ($added_datetimes as $row_id) {
631
-                $row_id = (int)$row_id;
632
-                if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) {
633
-                    $ticket->_add_relation_to($saved_datetimes[$row_id], 'Datetime');
634
-                    // Is this an existing ticket (has an ID) and does it have any sold?
635
-                    // If so, then we need to add that to the DTT sold because this DTT is getting added.
636
-                    if ($ticket->ID() && $ticket->sold() > 0) {
637
-                        $saved_datetimes[$row_id]->increase_sold($ticket->sold());
638
-                        $saved_datetimes[$row_id]->save();
639
-                    }
640
-                }
641
-            }
642
-        }
643
-        // then remove datetimes
644
-        if ( ! empty($removed_datetimes) && is_array($removed_datetimes)) {
645
-            foreach ($removed_datetimes as $row_id) {
646
-                $row_id = (int)$row_id;
647
-                // its entirely possible that a datetime got deleted (instead of just removed from relationship.
648
-                // So make sure we skip over this if the dtt isn't in the $saved_datetimes array)
649
-                if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) {
650
-                    $ticket->_remove_relation_to($saved_datetimes[$row_id], 'Datetime');
651
-                    // Is this an existing ticket (has an ID) and does it have any sold?
652
-                    // If so, then we need to remove it's sold from the DTT_sold.
653
-                    if ($ticket->ID() && $ticket->sold() > 0) {
654
-                        $saved_datetimes[$row_id]->decrease_sold($ticket->sold());
655
-                        $saved_datetimes[$row_id]->save();
656
-                    }
657
-                }
658
-            }
659
-        }
660
-        // cap ticket qty by datetime reg limits
661
-        $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
662
-
663
-        return $ticket;
664
-    }
665
-
666
-
667
-    /**
668
-     *
669
-     * @access  protected
670
-     *
671
-     * @param \EE_Ticket $ticket
672
-     * @param array      $price_rows
673
-     * @param int        $ticket_price
674
-     * @param int        $base_price
675
-     * @param int        $base_price_id
676
-     *
677
-     * @return \EE_Ticket
678
-     * @throws \EE_Error
679
-     */
680
-    protected function _duplicate_ticket(
681
-        EE_Ticket $ticket,
682
-        $price_rows = array(),
683
-        $ticket_price = 0,
684
-        $base_price = 0,
685
-        $base_price_id = 0
686
-    ) {
687
-
688
-        // create new ticket that's a copy of the existing
689
-        // except a new id of course (and not archived)
690
-        // AND has the new TKT_price associated with it.
691
-        $new_ticket = clone $ticket;
692
-        $new_ticket->set('TKT_ID', 0);
693
-        $new_ticket->set('TKT_deleted', 0);
694
-        $new_ticket->set('TKT_price', $ticket_price);
695
-        $new_ticket->set('TKT_sold', 0);
696
-        // let's get a new ID for this ticket
697
-        $new_ticket->save();
698
-        // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket
699
-        $datetimes_on_existing = $ticket->get_many_related('Datetime');
700
-        $new_ticket            = $this->_update_ticket_datetimes(
701
-            $new_ticket,
702
-            $datetimes_on_existing,
703
-            array_keys($datetimes_on_existing)
704
-        );
705
-
706
-        // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array.
707
-        // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining
708
-        // available.
709
-        if ($ticket->sold() > 0) {
710
-            $new_qty = $ticket->qty() - $ticket->sold();
711
-            $new_ticket->set_qty($new_qty);
712
-        }
713
-        //now we update the prices just for this ticket
714
-        $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true);
715
-        //and we update the base price
716
-        $new_ticket = $this->_add_prices_to_ticket(array(), $new_ticket, true, $base_price, $base_price_id);
717
-
718
-        return $new_ticket;
719
-    }
720
-
721
-
722
-    /**
723
-     * This attaches a list of given prices to a ticket.
724
-     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
725
-     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
726
-     * price info and prices are automatically "archived" via the ticket.
727
-     *
728
-     * @access  private
729
-     *
730
-     * @param array     $prices        Array of prices from the form.
731
-     * @param EE_Ticket $ticket        EE_Ticket object that prices are being attached to.
732
-     * @param bool      $new_prices    Whether attach existing incoming prices or create new ones.
733
-     * @param int|bool  $base_price    if FALSE then NOT doing a base price add.
734
-     * @param int|bool  $base_price_id if present then this is the base_price_id being updated.
735
-     *
736
-     * @return EE_Ticket
737
-     */
738
-    protected function _add_prices_to_ticket(
739
-        $prices = array(),
740
-        EE_Ticket $ticket,
741
-        $new_prices = false,
742
-        $base_price = false,
743
-        $base_price_id = false
744
-    ) {
745
-
746
-        //let's just get any current prices that may exist on the given ticket so we can remove any prices that got trashed in this session.
747
-        $current_prices_on_ticket = $base_price !== false ? $ticket->base_price(true) : $ticket->price_modifiers();
748
-
749
-        $updated_prices = array();
750
-
751
-        // if $base_price ! FALSE then updating a base price.
752
-        if ($base_price !== false) {
753
-            $prices[1] = array(
754
-                'PRC_ID'     => $new_prices || $base_price_id === 1 ? null : $base_price_id,
755
-                'PRT_ID'     => 1,
756
-                'PRC_amount' => $base_price,
757
-                'PRC_name'   => $ticket->get('TKT_name'),
758
-                'PRC_desc'   => $ticket->get('TKT_description')
759
-            );
760
-        }
761
-
762
-        //possibly need to save tkt
763
-        if ( ! $ticket->ID()) {
764
-            $ticket->save();
765
-        }
766
-
767
-        foreach ($prices as $row => $prc) {
768
-            $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null;
769
-            if (empty($prt_id)) {
770
-                continue;
771
-            } //prices MUST have a price type id.
772
-            $PRC_values = array(
773
-                'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
774
-                'PRT_ID'         => $prt_id,
775
-                'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
776
-                'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
777
-                'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
778
-                'PRC_is_default' => false,
779
-                //make sure we set PRC_is_default to false for all ticket saves from event_editor
780
-                'PRC_order'      => $row
781
-            );
782
-            if ($new_prices || empty($PRC_values['PRC_ID'])) {
783
-                $PRC_values['PRC_ID'] = 0;
784
-                $PRC                  = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false);
785
-            } else {
786
-                $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
787
-                //update this price with new values
788
-                foreach ($PRC_values as $field => $newprc) {
789
-                    $PRC->set($field, $newprc);
790
-                }
791
-            }
792
-            $PRC->save();
793
-            $prcid                  = $PRC->ID();
794
-            $updated_prices[$prcid] = $PRC;
795
-            $ticket->_add_relation_to($PRC, 'Price');
796
-        }
797
-
798
-        //now let's remove any prices that got removed from the ticket
799
-        if ( ! empty ($current_prices_on_ticket)) {
800
-            $current          = array_keys($current_prices_on_ticket);
801
-            $updated          = array_keys($updated_prices);
802
-            $prices_to_remove = array_diff($current, $updated);
803
-            if ( ! empty($prices_to_remove)) {
804
-                foreach ($prices_to_remove as $prc_id) {
805
-                    $p = $current_prices_on_ticket[$prc_id];
806
-                    $ticket->_remove_relation_to($p, 'Price');
807
-
808
-                    //delete permanently the price
809
-                    $p->delete_permanently();
810
-                }
811
-            }
812
-        }
813
-
814
-        return $ticket;
815
-    }
816
-
817
-
818
-    public function autosave_handling($event_admin_obj)
819
-    {
820
-        return $event_admin_obj; //doing nothing for the moment.
821
-        //todo when I get to this remember that I need to set the template args on the $event_admin_obj (use the set_template_args() method)
822
-
823
-        /**
824
-         * need to remember to handle TICKET DEFAULT saves correctly:  I've got two input fields in the dom:
825
-         *
826
-         * 1. TKT_is_default_selector (visible)
827
-         * 2. TKT_is_default (hidden)
828
-         *
829
-         * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want this ticket to be saved as a default.
830
-         *
831
-         * The tricky part is, on an initial display on create or edit (or after manually updating), the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true if this is a create.  However, after an autosave, users will want some sort of indicator that the TKT HAS been saved as a default.. in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking.
832
-         * On Autosave:
833
-         * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements, then set the TKT_is_default to false.
834
-         * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well).  We do NOT create a new default ticket.  The checkbox stays selected after autosave.
835
-         * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket.
836
-         */
837
-    }
838
-
839
-
840
-    public function pricing_metabox()
841
-    {
842
-        $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array();
843
-
844
-        $evtobj = $this->_adminpage_obj->get_cpt_model_obj();
845
-
846
-        //set is_creating_event property.
847
-        $evtID                    = $evtobj->ID();
848
-        $this->_is_creating_event = absint($evtID) != 0 ? false : true;
849
-
850
-        //default main template args
851
-        $main_template_args = array(
852
-            'event_datetime_help_link' => EEH_Template::get_help_tab_link('event_editor_event_datetimes_help_tab',
853
-                $this->_adminpage_obj->page_slug, $this->_adminpage_obj->get_req_action(), false, false),
854
-            //todo need to add a filter to the template for the help text in the Events_Admin_Page core file so we can add further help
855
-            'existing_datetime_ids'    => '',
856
-            'total_dtt_rows'           => 1,
857
-            'add_new_dtt_help_link'    => EEH_Template::get_help_tab_link('add_new_dtt_info',
858
-                $this->_adminpage_obj->page_slug, $this->_adminpage_obj->get_req_action(), false, false),
859
-            //todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
860
-            'datetime_rows'            => '',
861
-            'show_tickets_container'   => '',
862
-            //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '',
863
-            'ticket_rows'              => '',
864
-            'existing_ticket_ids'      => '',
865
-            'total_ticket_rows'        => 1,
866
-            'ticket_js_structure'      => '',
867
-            'ee_collapsible_status'    => ' ee-collapsible-open'
868
-            //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open'
869
-        );
870
-
871
-        $timezone = $evtobj instanceof EE_Event ? $evtobj->timezone_string() : null;
872
-
873
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
874
-
875
-        /**
876
-         * 1. Start with retrieving Datetimes
877
-         * 2. For each datetime get related tickets
878
-         * 3. For each ticket get related prices
879
-         */
880
-
881
-        $DTM   = EE_Registry::instance()->load_model('Datetime', array($timezone));
882
-        $times = $DTM->get_all_event_dates($evtID);
883
-
884
-
885
-        $main_template_args['total_dtt_rows'] = count($times);
886
-
887
-        /** @see https://events.codebasehq.com/projects/event-espresso/tickets/9486 for why we are counting $dttrow and then setting that on the Datetime object */
888
-        $dttrow = 1;
889
-        foreach ($times as $time) {
890
-            $dttid = $time->get('DTT_ID');
891
-            $time->set('DTT_order', $dttrow);
892
-            $existing_datetime_ids[] = $dttid;
893
-
894
-            //tickets attached
895
-            $related_tickets = $time->ID() > 0 ? $time->get_many_related('Ticket', array(
896
-                array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)),
897
-                'default_where_conditions' => 'none',
898
-                'order_by'                 => array('TKT_order' => 'ASC')
899
-            )) : array();
900
-
901
-            //if there are no related tickets this is likely a new event OR autodraft
902
-            // event so we need to generate the default tickets because dtts
903
-            // ALWAYS have at least one related ticket!!.  EXCEPT, we dont' do this if there is already more than one
904
-            // datetime on the event.
905
-            if (empty ($related_tickets) && count($times) < 2) {
906
-                $related_tickets = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
907
-
908
-                //this should be ordered by TKT_ID, so let's grab the first default ticket (which will be the main default) and ensure it has any default prices added to it (but do NOT save).
909
-                $default_prices = EEM_Price::instance()->get_all_default_prices();
910
-
911
-                $main_default_ticket = reset($related_tickets);
912
-                if ($main_default_ticket instanceof EE_Ticket) {
913
-                    foreach ($default_prices as $default_price) {
914
-                        if ($default_price->is_base_price()) {
915
-                            continue;
916
-                        }
917
-                        $main_default_ticket->cache('Price', $default_price);
918
-                    }
919
-                }
920
-            }
921
-
922
-
923
-            //we can't actually setup rows in this loop yet cause we don't know all the unique tickets for this event yet (tickets are linked through all datetimes). So we're going to temporarily cache some of that information.
924
-
925
-            //loop through and setup the ticket rows and make sure the order is set.
926
-            foreach ($related_tickets as $ticket) {
927
-                $tktid  = $ticket->get('TKT_ID');
928
-                $tktrow = $ticket->get('TKT_row');
929
-                //we only want unique tickets in our final display!!
930
-                if ( ! in_array($tktid, $existing_ticket_ids)) {
931
-                    $existing_ticket_ids[] = $tktid;
932
-                    $all_tickets[]         = $ticket;
933
-                }
934
-
935
-                //temporary cache of this ticket info for this datetime for later processing of datetime rows.
936
-                $datetime_tickets[$dttid][] = $tktrow;
937
-
938
-                //temporary cache of this datetime info for this ticket for later processing of ticket rows.
939
-                if ( ! isset($ticket_datetimes[$tktid]) || ! in_array($dttrow, $ticket_datetimes[$tktid])) {
940
-                    $ticket_datetimes[$tktid][] = $dttrow;
941
-                }
942
-            }
943
-            $dttrow++;
944
-        }
945
-
946
-        $main_template_args['total_ticket_rows']     = count($existing_ticket_ids);
947
-        $main_template_args['existing_ticket_ids']   = implode(',', $existing_ticket_ids);
948
-        $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
949
-
950
-        //sort $all_tickets by order
951
-        usort($all_tickets, function ($a, $b) {
952
-            $a_order = (int)$a->get('TKT_order');
953
-            $b_order = (int)$b->get('TKT_order');
954
-            if ($a_order == $b_order) {
955
-                return 0;
956
-            }
957
-
958
-            return ($a_order < $b_order) ? -1 : 1;
959
-        });
960
-
961
-        //k NOW we have all the data we need for setting up the dtt rows and ticket rows so we start our dtt loop again.
962
-        $dttrow = 1;
963
-        foreach ($times as $time) {
964
-            $main_template_args['datetime_rows'] .= $this->_get_datetime_row($dttrow, $time, $datetime_tickets,
965
-                $all_tickets, false, $times);
966
-            $dttrow++;
967
-        }
968
-
969
-        //then loop through all tickets for the ticket rows.
970
-        $tktrow = 1;
971
-        foreach ($all_tickets as $ticket) {
972
-            $main_template_args['ticket_rows'] .= $this->_get_ticket_row($tktrow, $ticket, $ticket_datetimes, $times,
973
-                false, $all_tickets);
974
-            $tktrow++;
975
-        }
976
-
977
-        $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($times, $all_tickets);
978
-        $template                                  = PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php';
979
-        EEH_Template::display_template($template, $main_template_args);
980
-
981
-        return;
982
-    }
983
-
984
-
985
-    protected function _get_datetime_row(
986
-        $dttrow,
987
-        EE_Datetime $dtt,
988
-        $datetime_tickets,
989
-        $all_tickets,
990
-        $default = false,
991
-        $all_dtts = array()
992
-    ) {
993
-
994
-        $dtt_display_template_args = array(
995
-            'dtt_edit_row'             => $this->_get_dtt_edit_row($dttrow, $dtt, $default, $all_dtts),
996
-            'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row($dttrow, $dtt, $datetime_tickets,
997
-                $all_tickets, $default),
998
-            'dtt_row'                  => $default ? 'DTTNUM' : $dttrow
999
-        );
1000
-        $template                  = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php';
1001
-
1002
-        return EEH_Template::display_template($template, $dtt_display_template_args, true);
1003
-    }
1004
-
1005
-
1006
-    /**
1007
-     * This method is used to generate a dtt fields  edit row.
1008
-     * The same row is used to generate a row with valid DTT objects and the default row that is used as the
1009
-     * skeleton by the js.
1010
-     *
1011
-     * @param int           $dttrow                         The row number for the row being generated.
1012
-     * @param               mixed                           EE_Datetime|null $dtt      If not default row being
1013
-     *                                                                       generated, this must be a EE_Datetime
1014
-     *                                                                       object.
1015
-     * @param bool          $default                        Whether a default row is being generated or not.
1016
-     * @param EE_Datetime[] $all_dtts                       This is the array of all datetimes used in the editor.
1017
-     *
1018
-     * @return string Generated edit row.
1019
-     */
1020
-    protected function _get_dtt_edit_row($dttrow, $dtt, $default, $all_dtts)
1021
-    {
1022
-
1023
-        // if the incoming $dtt object is NOT an instance of EE_Datetime then force default to true.
1024
-        $default = ! $dtt instanceof EE_Datetime ? true : false;
1025
-
1026
-        $template_args = array(
1027
-            'dtt_row'              => $default ? 'DTTNUM' : $dttrow,
1028
-            'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1029
-            'edit_dtt_expanded'    => '',
1030
-            //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? '' : ' ee-edit-editing',
1031
-            'DTT_ID'               => $default ? '' : $dtt->ID(),
1032
-            'DTT_name'             => $default ? '' : $dtt->name(),
1033
-            'DTT_description'      => $default ? '' : $dtt->description(),
1034
-            'DTT_EVT_start'        => $default ? '' : $dtt->start_date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']),
1035
-            'DTT_EVT_end'          => $default ? '' : $dtt->end_date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']),
1036
-            'DTT_reg_limit'        => $default ? '' : $dtt->get_pretty('DTT_reg_limit', 'input'),
1037
-            'DTT_order'            => $default ? 'DTTNUM' : $dttrow,
1038
-            'dtt_sold'             => $default ? '0' : $dtt->get('DTT_sold'),
1039
-            'dtt_reserved'         => $default ? '0' : $dtt->reserved(),
1040
-            'clone_icon'           => ! empty($dtt) && $dtt->get('DTT_sold') > 0 ? '' : 'clone-icon ee-icon ee-icon-clone clickable',
1041
-            'trash_icon'           => ! empty($dtt) && $dtt->get('DTT_sold') > 0 ? 'ee-lock-icon' : 'trash-icon dashicons dashicons-post-trash clickable',
1042
-            'reg_list_url'         => $default || ! $dtt->event() instanceof \EE_Event
1043
-                ? ''
1044
-                : EE_Admin_Page::add_query_args_and_nonce(
1045
-                    array('event_id' => $dtt->event()->ID(), 'datetime_id' => $dtt->ID()),
1046
-                    REG_ADMIN_URL
1047
-                )
1048
-        );
1049
-
1050
-        $template_args['show_trash'] = count($all_dtts) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' ? ' style="display:none"' : '';
1051
-
1052
-        //allow filtering of template args at this point.
1053
-        $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args',
1054
-            $template_args, $dttrow, $dtt, $default, $all_dtts, $this->_is_creating_event);
1055
-
1056
-        $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php';
1057
-
1058
-        return EEH_Template::display_template($template, $template_args, true);
1059
-    }
1060
-
1061
-
1062
-    protected function _get_dtt_attached_tickets_row($dttrow, $dtt, $datetime_tickets, $all_tickets, $default)
1063
-    {
1064
-
1065
-        $template_args = array(
1066
-            'dtt_row'                           => $default ? 'DTTNUM' : $dttrow,
1067
-            'event_datetimes_name'              => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1068
-            'DTT_description'                   => $default ? '' : $dtt->description(),
1069
-            'datetime_tickets_list'             => $default ? '<li class="hidden"></li>' : '',
1070
-            'show_tickets_row'                  => ' style="display:none;"',
1071
-            //$default || $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' style="display:none;"' : '',
1072
-            'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link('add_new_ticket_via_datetime',
1073
-                $this->_adminpage_obj->page_slug, $this->_adminpage_obj->get_req_action(), false, false),
1074
-            //todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1075
-            'DTT_ID'                            => $default ? '' : $dtt->ID()
1076
-        );
1077
-
1078
-        //need to setup the list items (but only if this isnt' a default skeleton setup)
1079
-        if ( ! $default) {
1080
-            $tktrow = 1;
1081
-            foreach ($all_tickets as $ticket) {
1082
-                $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item($dttrow, $tktrow,
1083
-                    $dtt, $ticket, $datetime_tickets, $default);
1084
-                $tktrow++;
1085
-            }
1086
-        }
1087
-
1088
-        //filter template args at this point
1089
-        $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args',
1090
-            $template_args, $dttrow, $dtt, $datetime_tickets, $all_tickets, $default, $this->_is_creating_event);
1091
-
1092
-        $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php';
1093
-
1094
-        return EEH_Template::display_template($template, $template_args, true);
1095
-    }
1096
-
1097
-
1098
-    protected function _get_datetime_tickets_list_item($dttrow, $tktrow, $dtt, $ticket, $datetime_tickets, $default)
1099
-    {
1100
-        $tktid    = ! empty($ticket) ? $ticket->ID() : 0;
1101
-        $dtt_tkts = $dtt instanceof EE_Datetime && isset($datetime_tickets[$dtt->ID()]) ? $datetime_tickets[$dtt->ID()] : array();
1102
-
1103
-        $displayrow    = ! empty($ticket) ? $ticket->get('TKT_row') : 0;
1104
-        $template_args = array(
1105
-            'dtt_row'                 => $default ? 'DTTNUM' : $dttrow,
1106
-            'tkt_row'                 => $default && empty($ticket) ? 'TICKETNUM' : $tktrow,
1107
-            'datetime_ticket_checked' => in_array($displayrow, $dtt_tkts) ? ' checked="checked"' : '',
1108
-            'ticket_selected'         => in_array($displayrow, $dtt_tkts) ? ' ticket-selected' : '',
1109
-            'TKT_name'                => $default && empty($ticket) ? 'TKTNAME' : $ticket->get('TKT_name'),
1110
-            'tkt_status_class'        => ($default && empty($ticket)) || $this->_is_creating_event ? ' tkt-status-' . EE_Ticket::onsale : ' tkt-status-' . $ticket->ticket_status(),
1111
-        );
1112
-
1113
-        //filter template args
1114
-        $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args',
1115
-            $template_args, $dttrow, $tktrow, $dtt, $ticket, $datetime_tickets, $default, $this->_is_creating_event);
1116
-
1117
-        $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php';
1118
-
1119
-        return EEH_Template::display_template($template, $template_args, true);
1120
-    }
1121
-
1122
-
1123
-    /**
1124
-     * This generates the ticket row for tickets.
1125
-     * This same method is used to generate both the actual rows and the js skeleton row (when default ==
1126
-     * true)
1127
-     *
1128
-     * @param int           $tktrow                          Represents the row number being generated.
1129
-     * @param               mixed                            null|EE_Ticket $ticket           If default then this will
1130
-     *                                                                      be null.
1131
-     * @param EE_Datetime[] $ticket_datetimes                Either an array of all datetimes on all tickets indexed by
1132
-     *                                                       each ticket or empty for  default
1133
-     * @param EE_Datetime[] $all_dtts                        All Datetimes on the event or empty for default.
1134
-     * @param bool          $default                         Whether default row being generated or not.
1135
-     * @param EE_Ticket[]   $all_tickets                     This is an array of all tickets attached to the event (or
1136
-     *                                                       empty in the case of defaults)
1137
-     *
1138
-     * @return [type] [description]
1139
-     */
1140
-    protected function _get_ticket_row(
1141
-        $tktrow,
1142
-        $ticket,
1143
-        $ticket_datetimes,
1144
-        $all_dtts,
1145
-        $default = false,
1146
-        $all_tickets = array()
1147
-    ) {
1148
-
1149
-        //if $ticket is not an instance of EE_Ticket then force default to true.
1150
-        $default = ! $ticket instanceof EE_Ticket ? true : false;
1151
-
1152
-        $prices = ! empty($ticket) && ! $default ? $ticket->get_many_related('Price',
1153
-            array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))) : array();
1154
-
1155
-        //if there is only one price (which would be the base price) or NO prices and this ticket is a default ticket, let's just make sure there are no cached default prices on
1156
-        //the object.  This is done by not including any query_params.
1157
-        if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) {
1158
-            $prices = $ticket->get_many_related('Price');
1159
-        }
1160
-
1161
-        // check if we're dealing with a default ticket in which case we don't want any starting_ticket_datetime_row values set (otherwise there won't be any new relationships created for tickets based off of the default ticket).  This will future proof in case there is ever any behaviour change between what the primary_key defaults to.
1162
-        $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->get('TKT_is_default')) ? true : false;
1163
-
1164
-        $tkt_dtts = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) ? $ticket_datetimes[$ticket->ID()] : array();
1165
-
1166
-        $ticket_subtotal  = $default ? 0 : $ticket->get_ticket_subtotal();
1167
-        $base_price       = $default ? null : $ticket->base_price();
1168
-        $count_price_mods = EEM_Price::instance()->get_all_default_prices(true);
1169
-
1170
-        //breaking out complicated condition for ticket_status
1171
-        if ($default) {
1172
-            $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale;
1173
-        } else {
1174
-            $ticket_status_class = $ticket->is_default() ? ' tkt-status-' . EE_Ticket::onsale : ' tkt-status-' . $ticket->ticket_status();
1175
-        }
1176
-
1177
-        //breaking out complicated condition for TKT_taxable
1178
-        if ($default) {
1179
-            $TKT_taxable = '';
1180
-        } else {
1181
-            $TKT_taxable = $ticket->get('TKT_taxable') ? ' checked="checked"' : '';
1182
-        }
1183
-
1184
-
1185
-        $template_args = array(
1186
-            'tkt_row'                       => $default ? 'TICKETNUM' : $tktrow,
1187
-            'TKT_order'                     => $default ? 'TICKETNUM' : $tktrow,
1188
-            //on initial page load this will always be the correct order.
1189
-            'tkt_status_class'              => $ticket_status_class,
1190
-            'display_edit_tkt_row'          => ' style="display:none;"',
1191
-            'edit_tkt_expanded'             => '',
1192
-            'edit_tickets_name'             => $default ? 'TICKETNAMEATTR' : 'edit_tickets',
1193
-            'TKT_name'                      => $default ? '' : $ticket->get('TKT_name'),
1194
-            'TKT_start_date'                => $default ? '' : $ticket->get_date('TKT_start_date',
1195
-                $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']),
1196
-            'TKT_end_date'                  => $default ? '' : $ticket->get_date('TKT_end_date',
1197
-                $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']),
1198
-            'TKT_status'                    => $default ? EEH_Template::pretty_status(EE_Ticket::onsale, false,
1199
-                'sentence') : $ticket->is_default() ? EEH_Template::pretty_status(EE_Ticket::onsale, false,
1200
-                'sentence') : $ticket->ticket_status(true),
1201
-            'TKT_price'                     => $default ? '' : EEH_Template::format_currency($ticket->get_ticket_total_with_taxes(),
1202
-                false, false),
1203
-            'TKT_price_code'                => EE_Registry::instance()->CFG->currency->code,
1204
-            'TKT_price_amount'              => $default ? 0 : $ticket_subtotal,
1205
-            'TKT_qty'                       => $default ? '' : $ticket->get_pretty('TKT_qty', 'symbol'),
1206
-            'TKT_qty_for_input'             => $default ? '' : $ticket->get_pretty('TKT_qty', 'input'),
1207
-            'TKT_uses'                      => $default ? '' : $ticket->get_pretty('TKT_uses', 'input'),
1208
-            'TKT_min'                       => $default ? '' : ($ticket->get('TKT_min') === -1 || $ticket->get('TKT_min') === 0 ? '' : $ticket->get('TKT_min')),
1209
-            'TKT_max'                       => $default ? '' : $ticket->get_pretty('TKT_max', 'input'),
1210
-            'TKT_sold'                      => $default ? 0 : $ticket->tickets_sold('ticket'),
1211
-            'TKT_reserved'                      => $default ? 0 : $ticket->reserved(),
1212
-            'TKT_registrations'             => $default ? 0 : $ticket->count_registrations(array(
1213
-                array(
1214
-                    'STS_ID' => array(
1215
-                        '!=',
1216
-                        EEM_Registration::status_id_incomplete
1217
-                    )
1218
-                )
1219
-            )),
1220
-            'TKT_ID'                        => $default ? 0 : $ticket->get('TKT_ID'),
1221
-            'TKT_description'               => $default ? '' : $ticket->get('TKT_description'),
1222
-            'TKT_is_default'                => $default ? 0 : $ticket->get('TKT_is_default'),
1223
-            'TKT_required'                  => $default ? 0 : $ticket->required(),
1224
-            'TKT_is_default_selector'       => '',
1225
-            'ticket_price_rows'             => '',
1226
-            'TKT_base_price'                => $default || ! $base_price instanceof EE_Price ? '' : $base_price->get_pretty('PRC_amount',
1227
-                'localized_float'),
1228
-            'TKT_base_price_ID'             => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(),
1229
-            'show_price_modifier'           => count($prices) > 1 || ($default && $count_price_mods > 0) ? '' : ' style="display:none;"',
1230
-            'show_price_mod_button'         => count($prices) > 1 || ($default && $count_price_mods > 0) || ( ! $default && $ticket->get('TKT_deleted')) ? ' style="display:none;"' : '',
1231
-            'total_price_rows'              => count($prices) > 1 ? count($prices) : 1,
1232
-            'ticket_datetimes_list'         => $default ? '<li class="hidden"></li>' : '',
1233
-            'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_dtts),
1234
-            'ticket_datetime_rows'          => $default ? '' : implode(',', $tkt_dtts),
1235
-            'existing_ticket_price_ids'     => $default ? '' : implode(',', array_keys($prices)),
1236
-            'ticket_template_id'            => $default ? 0 : $ticket->get('TTM_ID'),
1237
-            'TKT_taxable'                   => $TKT_taxable,
1238
-            'display_subtotal'              => $ticket instanceof EE_Ticket && $ticket->get('TKT_taxable') ? '' : ' style="display:none"',
1239
-            'price_currency_symbol'         => EE_Registry::instance()->CFG->currency->sign,
1240
-            'TKT_subtotal_amount_display'   => EEH_Template::format_currency($ticket_subtotal, false, false),
1241
-            'TKT_subtotal_amount'           => $ticket_subtotal,
1242
-            'tax_rows'                      => $this->_get_tax_rows($tktrow, $ticket),
1243
-            'disabled'                      => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? true : false,
1244
-            'ticket_archive_class'          => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? ' ticket-archived' : '',
1245
-            'trash_icon'                    => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? 'ee-lock-icon ' : 'trash-icon dashicons dashicons-post-trash clickable',
1246
-            'clone_icon'                    => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? '' : 'clone-icon ee-icon ee-icon-clone clickable'
1247
-        );
1248
-
1249
-        $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] != 'ee-lock-icon' ? ' style="display:none"' : '';
1250
-
1251
-        //handle rows that should NOT be empty
1252
-        if (empty($template_args['TKT_start_date'])) {
1253
-            //if empty then the start date will be now.
1254
-            $template_args['TKT_start_date']   = date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time'],
1255
-                current_time('timestamp'));
1256
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1257
-        }
1258
-
1259
-        if (empty($template_args['TKT_end_date'])) {
1260
-
1261
-            //get the earliest datetime (if present);
1262
-            $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related('Datetime',
1263
-                array('order_by' => array('DTT_EVT_start' => 'ASC'))) : null;
1264
-
1265
-            if ( ! empty($earliest_dtt)) {
1266
-                $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start',
1267
-                    $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']);
1268
-            } else {
1269
-                //default so let's just use what's been set for the default date-time which is 30 days from now.
1270
-                $template_args['TKT_end_date'] = date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time'],
1271
-                    mktime(24, 0, 0, date("m"), date("d") + 29, date("Y")));
1272
-            }
1273
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1274
-        }
1275
-
1276
-        //generate ticket_datetime items
1277
-        if ( ! $default) {
1278
-            $dttrow = 1;
1279
-            foreach ($all_dtts as $dtt) {
1280
-                $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item($dttrow, $tktrow, $dtt,
1281
-                    $ticket, $ticket_datetimes, $default);
1282
-                $dttrow++;
1283
-            }
1284
-        }
1285
-
1286
-        $prcrow = 1;
1287
-        foreach ($prices as $price) {
1288
-            if ($price->is_base_price()) {
1289
-                $prcrow++;
1290
-                continue;
1291
-            }
1292
-            $show_trash  = (count($prices) > 1 && $prcrow === 1) || count($prices) === 1 ? false : true;
1293
-            $show_create = count($prices) > 1 && count($prices) !== $prcrow ? false : true;
1294
-            $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row($tktrow, $prcrow, $price, $default,
1295
-                $ticket, $show_trash, $show_create);
1296
-            $prcrow++;
1297
-        }
1298
-
1299
-        //filter $template_args
1300
-        $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args',
1301
-            $template_args, $tktrow, $ticket, $ticket_datetimes, $all_dtts, $default, $all_tickets,
1302
-            $this->_is_creating_event);
1303
-
1304
-        $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php';
1305
-
1306
-        return EEH_Template::display_template($template, $template_args, true);
1307
-    }
1308
-
1309
-
1310
-    protected function _get_tax_rows($tktrow, $ticket)
1311
-    {
1312
-        $tax_rows      = '';
1313
-        $template      = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php';
1314
-        $template_args = array();
1315
-        $taxes         = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin();
1316
-        foreach ($taxes as $tax) {
1317
-            $tax_added     = $this->_get_tax_added($tax, $ticket);
1318
-            $template_args = array(
1319
-                'display_tax'       => ! empty($ticket) && $ticket->get('TKT_taxable') ? '' : ' style="display:none;"',
1320
-                'tax_id'            => $tax->ID(),
1321
-                'tkt_row'           => $tktrow,
1322
-                'tax_label'         => $tax->get('PRC_name'),
1323
-                'tax_added'         => $tax_added,
1324
-                'tax_added_display' => EEH_Template::format_currency($tax_added, false, false),
1325
-                'tax_amount'        => $tax->get('PRC_amount')
1326
-            );
1327
-            $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args',
1328
-                $template_args, $tktrow, $ticket, $this->_is_creating_event);
1329
-            $tax_rows .= EEH_Template::display_template($template, $template_args, true);
1330
-        }
1331
-
1332
-
1333
-        return $tax_rows;
1334
-    }
1335
-
1336
-
1337
-    protected function _get_tax_added(EE_Price $tax, $ticket)
1338
-    {
1339
-        $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal();
1340
-
1341
-        return $subtotal * $tax->get('PRC_amount') / 100;
1342
-    }
1343
-
1344
-
1345
-    protected function _get_ticket_price_row(
1346
-        $tktrow,
1347
-        $prcrow,
1348
-        $price,
1349
-        $default,
1350
-        $ticket,
1351
-        $show_trash = true,
1352
-        $show_create = true
1353
-    ) {
1354
-        $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted') ? true : false;
1355
-        $template_args = array(
1356
-            'tkt_row'               => $default && empty($ticket) ? 'TICKETNUM' : $tktrow,
1357
-            'PRC_order'             => $default && empty($price) ? 'PRICENUM' : $prcrow,
1358
-            'edit_prices_name'      => $default && empty($price) ? 'PRICENAMEATTR' : 'edit_prices',
1359
-            'price_type_selector'   => $default && empty($price) ? $this->_get_base_price_template($tktrow, $prcrow,
1360
-                $price, $default) : $this->_get_price_type_selector($tktrow, $prcrow, $price, $default, $send_disabled),
1361
-            'PRC_ID'                => $default && empty($price) ? 0 : $price->ID(),
1362
-            'PRC_is_default'        => $default && empty($price) ? 0 : $price->get('PRC_is_default'),
1363
-            'PRC_name'              => $default && empty($price) ? '' : $price->get('PRC_name'),
1364
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1365
-            'show_plus_or_minus'    => $default && empty($price) ? '' : ' style="display:none;"',
1366
-            'show_plus'             => $default && empty($price) ? ' style="display:none;"' : ($price->is_discount() || $price->is_base_price() ? ' style="display:none;"' : ''),
1367
-            'show_minus'            => $default && empty($price) ? ' style="display:none;"' : ($price->is_discount() ? '' : ' style="display:none;"'),
1368
-            'show_currency_symbol'  => $default && empty($price) ? ' style="display:none"' : ($price->is_percent() ? ' style="display:none"' : ''),
1369
-            'PRC_amount'            => $default && empty($price) ? 0 : $price->get_pretty('PRC_amount',
1370
-                'localized_float'),
1371
-            'show_percentage'       => $default && empty($price) ? ' style="display:none;"' : ($price->is_percent() ? '' : ' style="display:none;"'),
1372
-            'show_trash_icon'       => $show_trash ? '' : ' style="display:none;"',
1373
-            'show_create_button'    => $show_create ? '' : ' style="display:none;"',
1374
-            'PRC_desc'              => $default && empty($price) ? '' : $price->get('PRC_desc'),
1375
-            'disabled'              => ! empty($ticket) && $ticket->get('TKT_deleted') ? true : false
1376
-        );
1377
-
1378
-        $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args',
1379
-            $template_args, $tktrow, $prcrow, $price, $default, $ticket, $show_trash, $show_create,
1380
-            $this->_is_creating_event);
1381
-
1382
-        $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php';
1383
-
1384
-        return EEH_Template::display_template($template, $template_args, true);
1385
-    }
1386
-
1387
-
1388
-    protected function _get_price_type_selector($tktrow, $prcrow, $price, $default, $disabled = false)
1389
-    {
1390
-        if ($price->is_base_price()) {
1391
-            return $this->_get_base_price_template($tktrow, $prcrow, $price, $default);
1392
-        } else {
1393
-            return $this->_get_price_modifier_template($tktrow, $prcrow, $price, $default, $disabled);
1394
-        }
1395
-
1396
-    }
1397
-
1398
-
1399
-    protected function _get_base_price_template($tktrow, $prcrow, $price, $default)
1400
-    {
1401
-        $template_args = array(
1402
-            'tkt_row'                   => $default ? 'TICKETNUM' : $tktrow,
1403
-            'PRC_order'                 => $default && empty($price) ? 'PRICENUM' : $prcrow,
1404
-            'PRT_ID'                    => $default && empty($price) ? 1 : $price->get('PRT_ID'),
1405
-            'PRT_name'                  => __('Price', 'event_espresso'),
1406
-            'price_selected_operator'   => '+',
1407
-            'price_selected_is_percent' => 0
1408
-        );
1409
-        $template      = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php';
1410
-
1411
-        $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args',
1412
-            $template_args, $tktrow, $prcrow, $price, $default, $this->_is_creating_event);
1413
-
1414
-        return EEH_Template::display_template($template, $template_args, true);
1415
-    }
1416
-
1417
-
1418
-    protected function _get_price_modifier_template($tktrow, $prcrow, $price, $default, $disabled = false)
1419
-    {
1420
-        $select_name                = $default && empty($price) ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' : 'edit_prices[' . $tktrow . '][' . $prcrow . '][PRT_ID]';
1421
-        $price_types                = EE_Registry::instance()->load_model('Price_Type')->get_all(array(
1422
-            array(
1423
-                'OR' => array(
1424
-                    'PBT_ID'  => '2',
1425
-                    'PBT_ID*' => '3'
1426
-                )
1427
-            )
1428
-        ));
1429
-        $price_option_span_template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php';
1430
-        $all_price_types            = $default && empty($price) ? array(
1431
-            array(
1432
-                'id'   => 0,
1433
-                'text' => __('Select Modifier', 'event_espresso')
1434
-            )
1435
-        ) : array();
1436
-        $selected_price_type_id     = $default && empty($price) ? 0 : $price->type();
1437
-        $price_option_spans         = '';
1438
-        //setup pricetypes for selector
1439
-        foreach ($price_types as $price_type) {
1440
-            $all_price_types[] = array(
1441
-                'id'   => $price_type->ID(),
1442
-                'text' => $price_type->get('PRT_name'),
1443
-            );
1444
-
1445
-            //while we're in the loop let's setup the option spans used by js
1446
-            $spanargs = array(
1447
-                'PRT_ID'         => $price_type->ID(),
1448
-                'PRT_operator'   => $price_type->is_discount() ? '-' : '+',
1449
-                'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0
1450
-            );
1451
-            $price_option_spans .= EEH_Template::display_template($price_option_span_template, $spanargs, true);
1452
-        }
1453
-
1454
-        $select_params = $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"';
1455
-        $main_name     = $select_name;
1456
-        $select_name   = $disabled ? 'archive_price[' . $tktrow . '][' . $prcrow . '][PRT_ID]' : $main_name;
1457
-
1458
-        $template_args = array(
1459
-            'tkt_row'                   => $default ? 'TICKETNUM' : $tktrow,
1460
-            'PRC_order'                 => $default && empty($price) ? 'PRICENUM' : $prcrow,
1461
-            'price_modifier_selector'   => EEH_Form_Fields::select_input($select_name, $all_price_types,
1462
-                $selected_price_type_id, $select_params, 'edit-price-PRT_ID'),
1463
-            'main_name'                 => $main_name,
1464
-            'selected_price_type_id'    => $selected_price_type_id,
1465
-            'price_option_spans'        => $price_option_spans,
1466
-            'price_selected_operator'   => $default && empty($price) ? '' : ($price->is_discount() ? '-' : '+'),
1467
-            'price_selected_is_percent' => $default && empty($price) ? '' : ($price->is_percent() ? 1 : 0),
1468
-            'disabled'                  => $disabled
1469
-        );
1470
-
1471
-        $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args',
1472
-            $template_args, $tktrow, $prcrow, $price, $default, $disabled, $this->_is_creating_event);
1473
-
1474
-        $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php';
1475
-
1476
-        return EEH_Template::display_template($template, $template_args, true);
1477
-    }
1478
-
1479
-
1480
-    protected function _get_ticket_datetime_list_item($dttrow, $tktrow, $dtt, $ticket, $ticket_datetimes, $default)
1481
-    {
1482
-        $tkt_dtts      = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) ? $ticket_datetimes[$ticket->ID()] : array();
1483
-        $template_args = array(
1484
-            'dtt_row'                  => $default && ! $dtt instanceof EE_Datetime ? 'DTTNUM' : $dttrow,
1485
-            'tkt_row'                  => $default ? 'TICKETNUM' : $tktrow,
1486
-            'ticket_datetime_selected' => in_array($dttrow, $tkt_dtts) ? ' ticket-selected' : '',
1487
-            'ticket_datetime_checked'  => in_array($dttrow, $tkt_dtts) ? ' checked="checked"' : '',
1488
-            'DTT_name'                 => $default && empty($dtt) ? 'DTTNAME' : $dtt->get_dtt_display_name(true),
1489
-            'tkt_status_class'         => '',
1490
-        );
1491
-
1492
-        $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args',
1493
-            $template_args, $dttrow, $tktrow, $dtt, $ticket, $ticket_datetimes, $default, $this->_is_creating_event);
1494
-        $template      = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php';
1495
-
1496
-        return EEH_Template::display_template($template, $template_args, true);
1497
-    }
1498
-
1499
-
1500
-    protected function _get_ticket_js_structure($all_dtts, $all_tickets)
1501
-    {
1502
-        $template_args = array(
1503
-            'default_datetime_edit_row'                => $this->_get_dtt_edit_row('DTTNUM', null, true, $all_dtts),
1504
-            'default_ticket_row'                       => $this->_get_ticket_row('TICKETNUM', null, array(), array(),
1505
-                true),
1506
-            'default_price_row'                        => $this->_get_ticket_price_row('TICKETNUM', 'PRICENUM', null,
1507
-                true, null),
1508
-            'default_price_rows'                       => '',
1509
-            'default_base_price_amount'                => 0,
1510
-            'default_base_price_name'                  => '',
1511
-            'default_base_price_description'           => '',
1512
-            'default_price_modifier_selector_row'      => $this->_get_price_modifier_template('TICKETNUM', 'PRICENUM',
1513
-                null, true),
1514
-            'default_available_tickets_for_datetime'   => $this->_get_dtt_attached_tickets_row('DTTNUM', null, array(),
1515
-                array(), true),
1516
-            'existing_available_datetime_tickets_list' => '',
1517
-            'existing_available_ticket_datetimes_list' => '',
1518
-            'new_available_datetime_ticket_list_item'  => $this->_get_datetime_tickets_list_item('DTTNUM', 'TICKETNUM',
1519
-                null, null, array(), true),
1520
-            'new_available_ticket_datetime_list_item'  => $this->_get_ticket_datetime_list_item('DTTNUM', 'TICKETNUM',
1521
-                null, null, array(), true)
1522
-        );
1523
-
1524
-        $tktrow = 1;
1525
-        foreach ($all_tickets as $ticket) {
1526
-            $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item('DTTNUM',
1527
-                $tktrow, null, $ticket, array(), true);
1528
-            $tktrow++;
1529
-        }
1530
-
1531
-
1532
-        $dttrow = 1;
1533
-        foreach ($all_dtts as $dtt) {
1534
-            $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item($dttrow,
1535
-                'TICKETNUM', $dtt, null, array(), true);
1536
-            $dttrow++;
1537
-        }
1538
-
1539
-        $default_prices = EE_Registry::instance()->load_model('Price')->get_all_default_prices();
1540
-        $prcrow         = 1;
1541
-        foreach ($default_prices as $price) {
1542
-            if ($price->is_base_price()) {
1543
-                $template_args['default_base_price_amount']      = $price->get_pretty('PRC_amount', 'localized_float');
1544
-                $template_args['default_base_price_name']        = $price->get('PRC_name');
1545
-                $template_args['default_base_price_description'] = $price->get('PRC_desc');
1546
-                $prcrow++;
1547
-                continue;
1548
-            }
1549
-            $show_trash  = (count($default_prices) > 1 && $prcrow === 1) || count($default_prices) === 1 ? false : true;
1550
-            $show_create = count($default_prices) > 1 && count($default_prices) !== $prcrow ? false : true;
1551
-            $template_args['default_price_rows'] .= $this->_get_ticket_price_row('TICKETNUM', $prcrow, $price, true,
1552
-                null, $show_trash, $show_create);
1553
-            $prcrow++;
1554
-        }
1555
-
1556
-        $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args',
1557
-            $template_args, $all_dtts, $all_tickets, $this->_is_creating_event);
1558
-
1559
-        $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php';
1560
-
1561
-        return EEH_Template::display_template($template, $template_args, true);
1562
-    }
34
+	/**
35
+	 * This property is just used to hold the status of whether an event is currently being
36
+	 * created (true) or edited (false)
37
+	 * @access protected
38
+	 * @var bool
39
+	 */
40
+	protected $_is_creating_event;
41
+
42
+
43
+	/**
44
+	 * Used to contain the format strings for date and time that will be used for php date and
45
+	 * time.
46
+	 *
47
+	 * Is set in the _set_hooks_properties() method.
48
+	 *
49
+	 * @var array
50
+	 */
51
+	protected $_date_format_strings;
52
+
53
+
54
+	protected function _set_hooks_properties()
55
+	{
56
+		$this->_name = 'pricing';
57
+
58
+		//capability check
59
+		if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_default_prices',
60
+			'advanced_ticket_datetime_metabox')
61
+		) {
62
+			return;
63
+		}
64
+
65
+
66
+		//if we were going to add our own metaboxes we'd use the below.
67
+		$this->_metaboxes = array(
68
+			0 => array(
69
+				'page_route' => array('edit', 'create_new'),
70
+				'func'       => 'pricing_metabox',
71
+				'label'      => __('Event Tickets & Datetimes', 'event_espresso'),
72
+				'priority'   => 'high',
73
+				'context'    => 'normal'
74
+			),
75
+
76
+		);/**/
77
+
78
+		$this->_remove_metaboxes = array(
79
+			0 => array(
80
+				'page_route' => array('edit', 'create_new'),
81
+				'id'         => 'espresso_event_editor_tickets',
82
+				'context'    => 'normal'
83
+			)
84
+		);
85
+
86
+		/**
87
+		 * Format strings for date and time.  Defaults are existing behaviour from 4.1.
88
+		 * Note, that if you return null as the value for 'date', and 'time' in the array, then
89
+		 * EE will automatically use the set wp_options, 'date_format', and 'time_format'.
90
+		 *
91
+		 * @since 4.6.7
92
+		 *
93
+		 * @var array  Expected an array returned with 'date' and 'time' keys.
94
+		 */
95
+		$this->_date_format_strings = apply_filters('FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings',
96
+			array(
97
+				'date' => 'Y-m-d',
98
+				'time' => 'h:i a'
99
+			));
100
+
101
+		//validate
102
+		$this->_date_format_strings['date'] = isset($this->_date_format_strings['date']) ? $this->_date_format_strings['date'] : null;
103
+		$this->_date_format_strings['time'] = isset($this->_date_format_strings['time']) ? $this->_date_format_strings['time'] : null;
104
+
105
+		//validate format strings
106
+		$format_validation = EEH_DTT_Helper::validate_format_string($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']);
107
+		if (is_array($format_validation)) {
108
+			$msg = '<p>' . sprintf(__('The format "%s" was likely added via a filter and is invalid for the following reasons:',
109
+					'event_espresso'),
110
+					$this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']) . '</p><ul>';
111
+			foreach ($format_validation as $error) {
112
+				$msg .= '<li>' . $error . '</li>';
113
+			}
114
+			$msg .= '</ul></p><p>' . sprintf(__('%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s',
115
+					'event_espresso'), '<span style="color:#D54E21;">', '</span>') . '</p>';
116
+			EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
117
+			$this->_date_format_strings = array(
118
+				'date' => 'Y-m-d',
119
+				'time' => 'h:i a'
120
+			);
121
+		}
122
+
123
+
124
+		$this->_scripts_styles = array(
125
+			'registers'   => array(
126
+				'ee-tickets-datetimes-css' => array(
127
+					'url'  => PRICING_ASSETS_URL . 'event-tickets-datetimes.css',
128
+					'type' => 'css'
129
+				),
130
+				'ee-dtt-ticket-metabox'    => array(
131
+					'url'     => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js',
132
+					'depends' => array('ee-datepicker', 'ee-dialog', 'underscore')
133
+				)
134
+			),
135
+			'deregisters' => array(
136
+				'event-editor-css'       => array('type' => 'css'),
137
+				'event-datetime-metabox' => array('type' => 'js')
138
+			),
139
+			'enqueues'    => array(
140
+				'ee-tickets-datetimes-css' => array('edit', 'create_new'),
141
+				'ee-dtt-ticket-metabox'    => array('edit', 'create_new')
142
+			),
143
+			'localize'    => array(
144
+				'ee-dtt-ticket-metabox' => array(
145
+					'DTT_TRASH_BLOCK'       => array(
146
+						'main_warning'            => __('The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):',
147
+							'event_espresso'),
148
+						'after_warning'           => __('In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.',
149
+							'event_espresso'),
150
+						'cancel_button'           => '<button class="button-secondary ee-modal-cancel">' . __('Cancel',
151
+								'event_espresso') . '</button>',
152
+						'close_button'            => '<button class="button-secondary ee-modal-cancel">' . __('Close',
153
+								'event_espresso') . '</button>',
154
+						'single_warning_from_tkt' => __('The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.',
155
+							'event_espresso'),
156
+						'single_warning_from_dtt' => __('The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket.  Tickets must always have at least one datetime assigned to them.',
157
+							'event_espresso'),
158
+						'dismiss_button'          => '<button class="button-secondary ee-modal-cancel">' . __('Dismiss',
159
+								'event_espresso') . '</button>'
160
+					),
161
+					'DTT_ERROR_MSG'         => array(
162
+						'no_ticket_name' => __('General Admission', 'event_espresso'),
163
+						'dismiss_button' => '<div class="save-cancel-button-container"><button class="button-secondary ee-modal-cancel">' . __('Dismiss',
164
+								'event_espresso') . '</button></div>'
165
+					),
166
+					'DTT_OVERSELL_WARNING'  => array(
167
+						'datetime_ticket' => __('You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.',
168
+							'event_espresso'),
169
+						'ticket_datetime' => __('You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.',
170
+							'event_espresso')
171
+					),
172
+					'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats($this->_date_format_strings['date'],
173
+						$this->_date_format_strings['time']),
174
+					'DTT_START_OF_WEEK'     => array('dayValue' => (int)get_option('start_of_week'))
175
+				)
176
+			)
177
+		);
178
+
179
+
180
+		add_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page',
181
+			array($this, 'autosave_handling'), 10);
182
+		add_filter('FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
183
+			array($this, 'caf_updates'), 10);
184
+	}
185
+
186
+
187
+	public function caf_updates($update_callbacks)
188
+	{
189
+		foreach ($update_callbacks as $key => $callback) {
190
+			if ($callback[1] == '_default_tickets_update') {
191
+				unset($update_callbacks[$key]);
192
+			}
193
+		}
194
+
195
+		$update_callbacks[] = array($this, 'dtt_and_tickets_caf_update');
196
+
197
+		return $update_callbacks;
198
+	}
199
+
200
+
201
+	/**
202
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
203
+	 *
204
+	 * @param  EE_Event $evtobj The Event object we're attaching data to
205
+	 * @param  array    $data   The request data from the form
206
+	 *
207
+	 * @return bool             success or fail
208
+	 */
209
+	public function dtt_and_tickets_caf_update($evtobj, $data)
210
+	{
211
+		//first we need to start with datetimes cause they are the "root" items attached to events.
212
+		$saved_dtts = $this->_update_dtts($evtobj, $data);
213
+		//next tackle the tickets (and prices?)
214
+		$this->_update_tkts($evtobj, $saved_dtts, $data);
215
+	}
216
+
217
+
218
+	/**
219
+	 * update event_datetimes
220
+	 *
221
+	 * @param  EE_Event $evt_obj Event being updated
222
+	 * @param  array    $data    the request data from the form
223
+	 *
224
+	 * @return EE_Datetime[]
225
+	 */
226
+	protected function _update_dtts($evt_obj, $data)
227
+	{
228
+		$timezone       = isset($data['timezone_string']) ? $data['timezone_string'] : null;
229
+		$saved_dtt_ids  = array();
230
+		$saved_dtt_objs = array();
231
+
232
+		foreach ($data['edit_event_datetimes'] as $row => $dtt) {
233
+			//trim all values to ensure any excess whitespace is removed.
234
+			$dtt                = array_map(
235
+				function ($datetime_data) {
236
+					return is_array($datetime_data) ? $datetime_data : trim($datetime_data);
237
+				},
238
+				$dtt
239
+			);
240
+			$dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end'] : $dtt['DTT_EVT_start'];
241
+			$datetime_values    = array(
242
+				'DTT_ID'          => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
243
+				'DTT_name'        => ! empty($dtt['DTT_name']) ? $dtt['DTT_name'] : '',
244
+				'DTT_description' => ! empty($dtt['DTT_description']) ? $dtt['DTT_description'] : '',
245
+				'DTT_EVT_start'   => $dtt['DTT_EVT_start'],
246
+				'DTT_EVT_end'     => $dtt['DTT_EVT_end'],
247
+				'DTT_reg_limit'   => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
248
+				'DTT_order'       => ! isset($dtt['DTT_order']) ? $row : $dtt['DTT_order'],
249
+			);
250
+
251
+			//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.
252
+
253
+			if ( ! empty($dtt['DTT_ID'])) {
254
+				$DTM = EE_Registry::instance()->load_model('Datetime', array($timezone))->get_one_by_ID($dtt['DTT_ID']);
255
+
256
+				//set date and time format according to what is set in this class.
257
+				$DTM->set_date_format($this->_date_format_strings['date']);
258
+				$DTM->set_time_format($this->_date_format_strings['time']);
259
+
260
+				foreach ($datetime_values as $field => $value) {
261
+					$DTM->set($field, $value);
262
+				}
263
+
264
+				// make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.
265
+				// We need to do this so we dont' TRASH the parent DTT.(save the ID for both key and value to avoid duplications)
266
+				$saved_dtt_ids[$DTM->ID()] = $DTM->ID();
267
+
268
+			} else {
269
+				$DTM = EE_Registry::instance()->load_class(
270
+					'Datetime',
271
+					array(
272
+						$datetime_values,
273
+						$timezone,
274
+						array($this->_date_format_strings['date'], $this->_date_format_strings['time'])
275
+					),
276
+					false,
277
+					false
278
+				);
279
+
280
+				foreach ($datetime_values as $field => $value) {
281
+					$DTM->set($field, $value);
282
+				}
283
+			}
284
+
285
+
286
+			$DTM->save();
287
+			$DTM = $evt_obj->_add_relation_to($DTM, 'Datetime');
288
+			$evt_obj->save();
289
+
290
+			//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.
291
+			if ($DTM->get_raw('DTT_EVT_start') > $DTM->get_raw('DTT_EVT_end')) {
292
+				$DTM->set('DTT_EVT_end', $DTM->get('DTT_EVT_start'));
293
+				$DTM = EEH_DTT_Helper::date_time_add($DTM, 'DTT_EVT_end', 'days');
294
+				$DTM->save();
295
+			}
296
+
297
+			//	now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array
298
+			// because it is possible there was a new one created for the autosave.
299
+			// (save the ID for both key and value to avoid duplications)
300
+			$saved_dtt_ids[$DTM->ID()] = $DTM->ID();
301
+			$saved_dtt_objs[$row]      = $DTM;
302
+
303
+			//todo if ANY of these updates fail then we want the appropriate global error message.
304
+		}
305
+
306
+		//now we need to REMOVE any dtts that got deleted.  Keep in mind that this process will only kick in for DTT's that don't have any DTT_sold on them. So its safe to permanently delete at this point.
307
+		$old_datetimes = explode(',', $data['datetime_IDs']);
308
+		$old_datetimes = $old_datetimes[0] == '' ? array() : $old_datetimes;
309
+
310
+		if (is_array($old_datetimes)) {
311
+			$dtts_to_delete = array_diff($old_datetimes, $saved_dtt_ids);
312
+			foreach ($dtts_to_delete as $id) {
313
+				$id = absint($id);
314
+				if (empty($id)) {
315
+					continue;
316
+				}
317
+
318
+				$dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id);
319
+
320
+				//remove tkt relationships.
321
+				$related_tickets = $dtt_to_remove->get_many_related('Ticket');
322
+				foreach ($related_tickets as $tkt) {
323
+					$dtt_to_remove->_remove_relation_to($tkt, 'Ticket');
324
+				}
325
+
326
+				$evt_obj->_remove_relation_to($id, 'Datetime');
327
+				$dtt_to_remove->refresh_cache_of_related_objects();
328
+
329
+			}
330
+		}
331
+
332
+		return $saved_dtt_objs;
333
+	}
334
+
335
+
336
+	/**
337
+	 * update tickets
338
+	 *
339
+	 * @param  EE_Event      $evtobj     Event object being updated
340
+	 * @param  EE_Datetime[] $saved_dtts an array of datetime ids being updated
341
+	 * @param  array         $data       incoming request data
342
+	 *
343
+	 * @return EE_Ticket[]
344
+	 */
345
+	protected function _update_tkts($evtobj, $saved_dtts, $data)
346
+	{
347
+
348
+		$new_tkt     = null;
349
+		$new_default = null;
350
+		//stripslashes because WP filtered the $_POST ($data) array to add slashes
351
+		$data          = stripslashes_deep($data);
352
+		$timezone      = isset($data['timezone_string']) ? $data['timezone_string'] : null;
353
+		$saved_tickets = $dtts_on_existing = array();
354
+		$old_tickets   = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
355
+
356
+		//load money helper
357
+
358
+		foreach ($data['edit_tickets'] as $row => $tkt) {
359
+
360
+			$update_prices = $create_new_TKT = false;
361
+
362
+			//figure out what dtts were added to the ticket and what dtts were removed from the ticket in the session.
363
+
364
+			$starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][$row]);
365
+			$tkt_dtt_rows          = explode(',', $data['ticket_datetime_rows'][$row]);
366
+			$dtts_added            = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows);
367
+			$dtts_removed          = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows);
368
+
369
+			// trim inputs to ensure any excess whitespace is removed.
370
+			$tkt = array_map(
371
+				function ($ticket_data) {
372
+					return is_array($ticket_data) ? $ticket_data : trim($ticket_data);
373
+				},
374
+				$tkt
375
+			);
376
+
377
+			//note we are doing conversions to floats here instead of allowing EE_Money_Field to handle because we're doing calcs prior to using the models.
378
+			//note incoming ['TKT_price'] value is already in standard notation (via js).
379
+			$ticket_price = isset($tkt['TKT_price']) ? round((float)$tkt['TKT_price'], 3) : 0;
380
+
381
+			//note incoming base price needs converted from localized value.
382
+			$base_price = isset($tkt['TKT_base_price']) ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price']) : 0;
383
+			//if ticket price == 0 and $base_price != 0 then ticket price == base_price
384
+			$ticket_price  = $ticket_price === 0 && $base_price !== 0 ? $base_price : $ticket_price;
385
+			$base_price_id = isset($tkt['TKT_base_price_ID']) ? $tkt['TKT_base_price_ID'] : 0;
386
+
387
+			$price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][$row]) ? $data['edit_prices'][$row] : array();
388
+
389
+			$now = null;
390
+			if (empty($tkt['TKT_start_date'])) {
391
+				//lets' use now in the set timezone.
392
+				$now                   = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
393
+				$tkt['TKT_start_date'] = $now->format($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']);
394
+			}
395
+
396
+			if (empty($tkt['TKT_end_date'])) {
397
+				/**
398
+				 * set the TKT_end_date to the first datetime attached to the ticket.
399
+				 */
400
+				$first_dtt           = $saved_dtts[reset($tkt_dtt_rows)];
401
+				$tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_format_strings['date'] . ' ' . $this->_date_format_string['time']);
402
+			}
403
+
404
+			$TKT_values = array(
405
+				'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
406
+				'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
407
+				'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
408
+				'TKT_description' => ! empty($tkt['TKT_description']) && $tkt['TKT_description'] != __('You can modify this description',
409
+					'event_espresso') ? $tkt['TKT_description'] : '',
410
+				'TKT_start_date'  => $tkt['TKT_start_date'],
411
+				'TKT_end_date'    => $tkt['TKT_end_date'],
412
+				'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
413
+				'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
414
+				'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
415
+				'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
416
+				'TKT_row'         => $row,
417
+				'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0,
418
+				'TKT_taxable'     => ! empty($tkt['TKT_taxable']) ? 1 : 0,
419
+				'TKT_required'    => ! empty($tkt['TKT_required']) ? 1 : 0,
420
+				'TKT_price'       => $ticket_price
421
+			);
422
+
423
+
424
+			//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.
425
+			if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
426
+				$TKT_values['TKT_ID']         = 0;
427
+				$TKT_values['TKT_is_default'] = 0;
428
+				$update_prices                = true;
429
+			}
430
+
431
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
432
+			// we actually do our saves ahead of doing any add_relations to
433
+			// because its entirely possible that this ticket wasn't removed or added to any datetime in the session
434
+			// but DID have it's items modified.
435
+			// keep in mind that if the TKT has been sold (and we have changed pricing information),
436
+			// then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
437
+			if (absint($TKT_values['TKT_ID'])) {
438
+				$TKT = EE_Registry::instance()->load_model('Ticket', array($timezone))->get_one_by_ID($tkt['TKT_ID']);
439
+				if ($TKT instanceof EE_Ticket) {
440
+
441
+					$TKT = $this->_update_ticket_datetimes($TKT, $saved_dtts, $dtts_added, $dtts_removed);
442
+					// are there any registrations using this ticket ?
443
+					$tickets_sold = $TKT->count_related(
444
+						'Registration',
445
+						array(
446
+							array(
447
+								'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete))
448
+							)
449
+						)
450
+					);
451
+					//set ticket formats
452
+					$TKT->set_date_format($this->_date_format_strings['date']);
453
+					$TKT->set_time_format($this->_date_format_strings['time']);
454
+
455
+					// let's just check the total price for the existing ticket
456
+					// and determine if it matches the new total price.
457
+					// if they are different then we create a new ticket (if tkts sold)
458
+					// if they aren't different then we go ahead and modify existing ticket.
459
+					$create_new_TKT = $tickets_sold > 0 && $ticket_price != $TKT->price() && ! $TKT->deleted()
460
+						? true : false;
461
+
462
+					//set new values
463
+					foreach ($TKT_values as $field => $value) {
464
+						if ($field === 'TKT_qty') {
465
+							$TKT->set_qty($value);
466
+						} else {
467
+							$TKT->set($field, $value);
468
+						}
469
+					}
470
+
471
+					//if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
472
+					if ($create_new_TKT) {
473
+						$new_tkt = $this->_duplicate_ticket($TKT, $price_rows, $ticket_price, $base_price,
474
+							$base_price_id);
475
+					}
476
+				}
477
+
478
+			} else {
479
+				// no TKT_id so a new TKT
480
+				$TKT = EE_Ticket::new_instance(
481
+					$TKT_values,
482
+					$timezone,
483
+					array($this->_date_format_strings['date'], $this->_date_format_strings['time'])
484
+				);
485
+				if ($TKT instanceof EE_Ticket) {
486
+					// make sure ticket has an ID of setting relations won't work
487
+					$TKT->save();
488
+					$TKT           = $this->_update_ticket_datetimes($TKT, $saved_dtts, $dtts_added, $dtts_removed);
489
+					$update_prices = true;
490
+				}
491
+			}
492
+			//make sure any current values have been saved.
493
+			//$TKT->save();
494
+
495
+			//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.
496
+			if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
497
+				$TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
498
+				$TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
499
+			}
500
+
501
+			//let's make sure the base price is handled
502
+			$TKT = ! $create_new_TKT ? $this->_add_prices_to_ticket(array(), $TKT, $update_prices, $base_price,
503
+				$base_price_id) : $TKT;
504
+
505
+			//add/update price_modifiers
506
+			$TKT = ! $create_new_TKT ? $this->_add_prices_to_ticket($price_rows, $TKT, $update_prices) : $TKT;
507
+
508
+			//need to make sue that the TKT_price is accurate after saving the prices.
509
+			$TKT->ensure_TKT_Price_correct();
510
+
511
+			//handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave.
512
+			if ( ! defined('DOING_AUTOSAVE')) {
513
+				if ( ! empty($tkt['TKT_is_default_selector'])) {
514
+					$update_prices = true;
515
+					$new_default   = clone $TKT;
516
+					$new_default->set('TKT_ID', 0);
517
+					$new_default->set('TKT_is_default', 1);
518
+					$new_default->set('TKT_row', 1);
519
+					$new_default->set('TKT_price', $ticket_price);
520
+					//remove any dtt relations cause we DON'T want dtt relations attached (note this is just removing the cached relations in the object)
521
+					$new_default->_remove_relations('Datetime');
522
+					//todo we need to add the current attached prices as new prices to the new default ticket.
523
+					$new_default = $this->_add_prices_to_ticket($price_rows, $new_default, $update_prices);
524
+					//don't forget the base price!
525
+					$new_default = $this->_add_prices_to_ticket(array(), $new_default, $update_prices, $base_price,
526
+						$base_price_id);
527
+					$new_default->save();
528
+					do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket', $new_default,
529
+						$row, $TKT, $data);
530
+				}
531
+			}
532
+
533
+
534
+			//DO ALL dtt relationships for both current tickets and any archived tickets for the given dtt that are related to the current ticket. TODO... not sure exactly how we're going to do this considering we don't know what current ticket the archived tickets are related to (and TKT_parent is used for autosaves so that's not a field we can reliably use).
535
+
536
+
537
+			//let's assign any tickets that have been setup to the saved_tickets tracker
538
+			//save existing TKT
539
+			$TKT->save();
540
+			if ($create_new_TKT && $new_tkt instanceof EE_Ticket) {
541
+				//save new TKT
542
+				$new_tkt->save();
543
+				//add new ticket to array
544
+				$saved_tickets[$new_tkt->ID()] = $new_tkt;
545
+
546
+				do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket', $new_tkt, $row, $tkt, $data);
547
+
548
+			} else {
549
+				//add tkt to saved tkts
550
+				$saved_tickets[$TKT->ID()] = $TKT;
551
+
552
+				do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket', $TKT, $row, $tkt, $data);
553
+			}
554
+
555
+		}
556
+
557
+		// now we need to handle tickets actually "deleted permanently".
558
+		// There are cases where we'd want this to happen
559
+		// (i.e. autosaves are happening and then in between autosaves the user trashes a ticket).
560
+		// Or a draft event was saved and in the process of editing a ticket is trashed.
561
+		// No sense in keeping all the related data in the db!
562
+		$old_tickets     = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
563
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
564
+
565
+		foreach ($tickets_removed as $id) {
566
+			$id = absint($id);
567
+
568
+			//get the ticket for this id
569
+			$tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
570
+
571
+			//if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime
572
+			if ($tkt_to_remove->get('TKT_is_default')) {
573
+				continue;
574
+			}
575
+
576
+			// if this tkt has any registrations attached so then we just ARCHIVE
577
+			// because we don't actually permanently delete these tickets.
578
+			if ($tkt_to_remove->count_related('Registration') > 0) {
579
+				$tkt_to_remove->delete();
580
+				continue;
581
+			}
582
+
583
+			// need to get all the related datetimes on this ticket and remove from every single one of them
584
+			// (remember this process can ONLY kick off if there are NO tkts_sold)
585
+			$dtts = $tkt_to_remove->get_many_related('Datetime');
586
+
587
+			foreach ($dtts as $dtt) {
588
+				$tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
589
+			}
590
+
591
+			// need to do the same for prices (except these prices can also be deleted because again,
592
+			// tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
593
+			$tkt_to_remove->delete_related_permanently('Price');
594
+
595
+			do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove);
596
+
597
+			// finally let's delete this ticket
598
+			// (which should not be blocked at this point b/c we've removed all our relationships)
599
+			$tkt_to_remove->delete_permanently();
600
+		}
601
+
602
+		return $saved_tickets;
603
+	}
604
+
605
+
606
+	/**
607
+	 *
608
+	 * @access  protected
609
+	 *
610
+	 * @param \EE_Ticket     $ticket
611
+	 * @param \EE_Datetime[] $saved_datetimes
612
+	 * @param \EE_Datetime[] $added_datetimes
613
+	 * @param \EE_Datetime[] $removed_datetimes
614
+	 *
615
+	 * @return \EE_Ticket
616
+	 * @throws \EE_Error
617
+	 */
618
+	protected function _update_ticket_datetimes(
619
+		EE_Ticket $ticket,
620
+		$saved_datetimes = array(),
621
+		$added_datetimes = array(),
622
+		$removed_datetimes = array()
623
+	) {
624
+
625
+		// to start we have to add the ticket to all the datetimes its supposed to be with,
626
+		// and removing the ticket from datetimes it got removed from.
627
+
628
+		// first let's add datetimes
629
+		if ( ! empty($added_datetimes) && is_array($added_datetimes)) {
630
+			foreach ($added_datetimes as $row_id) {
631
+				$row_id = (int)$row_id;
632
+				if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) {
633
+					$ticket->_add_relation_to($saved_datetimes[$row_id], 'Datetime');
634
+					// Is this an existing ticket (has an ID) and does it have any sold?
635
+					// If so, then we need to add that to the DTT sold because this DTT is getting added.
636
+					if ($ticket->ID() && $ticket->sold() > 0) {
637
+						$saved_datetimes[$row_id]->increase_sold($ticket->sold());
638
+						$saved_datetimes[$row_id]->save();
639
+					}
640
+				}
641
+			}
642
+		}
643
+		// then remove datetimes
644
+		if ( ! empty($removed_datetimes) && is_array($removed_datetimes)) {
645
+			foreach ($removed_datetimes as $row_id) {
646
+				$row_id = (int)$row_id;
647
+				// its entirely possible that a datetime got deleted (instead of just removed from relationship.
648
+				// So make sure we skip over this if the dtt isn't in the $saved_datetimes array)
649
+				if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) {
650
+					$ticket->_remove_relation_to($saved_datetimes[$row_id], 'Datetime');
651
+					// Is this an existing ticket (has an ID) and does it have any sold?
652
+					// If so, then we need to remove it's sold from the DTT_sold.
653
+					if ($ticket->ID() && $ticket->sold() > 0) {
654
+						$saved_datetimes[$row_id]->decrease_sold($ticket->sold());
655
+						$saved_datetimes[$row_id]->save();
656
+					}
657
+				}
658
+			}
659
+		}
660
+		// cap ticket qty by datetime reg limits
661
+		$ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
662
+
663
+		return $ticket;
664
+	}
665
+
666
+
667
+	/**
668
+	 *
669
+	 * @access  protected
670
+	 *
671
+	 * @param \EE_Ticket $ticket
672
+	 * @param array      $price_rows
673
+	 * @param int        $ticket_price
674
+	 * @param int        $base_price
675
+	 * @param int        $base_price_id
676
+	 *
677
+	 * @return \EE_Ticket
678
+	 * @throws \EE_Error
679
+	 */
680
+	protected function _duplicate_ticket(
681
+		EE_Ticket $ticket,
682
+		$price_rows = array(),
683
+		$ticket_price = 0,
684
+		$base_price = 0,
685
+		$base_price_id = 0
686
+	) {
687
+
688
+		// create new ticket that's a copy of the existing
689
+		// except a new id of course (and not archived)
690
+		// AND has the new TKT_price associated with it.
691
+		$new_ticket = clone $ticket;
692
+		$new_ticket->set('TKT_ID', 0);
693
+		$new_ticket->set('TKT_deleted', 0);
694
+		$new_ticket->set('TKT_price', $ticket_price);
695
+		$new_ticket->set('TKT_sold', 0);
696
+		// let's get a new ID for this ticket
697
+		$new_ticket->save();
698
+		// we also need to make sure this new ticket gets the same datetime attachments as the archived ticket
699
+		$datetimes_on_existing = $ticket->get_many_related('Datetime');
700
+		$new_ticket            = $this->_update_ticket_datetimes(
701
+			$new_ticket,
702
+			$datetimes_on_existing,
703
+			array_keys($datetimes_on_existing)
704
+		);
705
+
706
+		// $ticket will get archived later b/c we are NOT adding it to the saved_tickets array.
707
+		// if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining
708
+		// available.
709
+		if ($ticket->sold() > 0) {
710
+			$new_qty = $ticket->qty() - $ticket->sold();
711
+			$new_ticket->set_qty($new_qty);
712
+		}
713
+		//now we update the prices just for this ticket
714
+		$new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true);
715
+		//and we update the base price
716
+		$new_ticket = $this->_add_prices_to_ticket(array(), $new_ticket, true, $base_price, $base_price_id);
717
+
718
+		return $new_ticket;
719
+	}
720
+
721
+
722
+	/**
723
+	 * This attaches a list of given prices to a ticket.
724
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
725
+	 * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
726
+	 * price info and prices are automatically "archived" via the ticket.
727
+	 *
728
+	 * @access  private
729
+	 *
730
+	 * @param array     $prices        Array of prices from the form.
731
+	 * @param EE_Ticket $ticket        EE_Ticket object that prices are being attached to.
732
+	 * @param bool      $new_prices    Whether attach existing incoming prices or create new ones.
733
+	 * @param int|bool  $base_price    if FALSE then NOT doing a base price add.
734
+	 * @param int|bool  $base_price_id if present then this is the base_price_id being updated.
735
+	 *
736
+	 * @return EE_Ticket
737
+	 */
738
+	protected function _add_prices_to_ticket(
739
+		$prices = array(),
740
+		EE_Ticket $ticket,
741
+		$new_prices = false,
742
+		$base_price = false,
743
+		$base_price_id = false
744
+	) {
745
+
746
+		//let's just get any current prices that may exist on the given ticket so we can remove any prices that got trashed in this session.
747
+		$current_prices_on_ticket = $base_price !== false ? $ticket->base_price(true) : $ticket->price_modifiers();
748
+
749
+		$updated_prices = array();
750
+
751
+		// if $base_price ! FALSE then updating a base price.
752
+		if ($base_price !== false) {
753
+			$prices[1] = array(
754
+				'PRC_ID'     => $new_prices || $base_price_id === 1 ? null : $base_price_id,
755
+				'PRT_ID'     => 1,
756
+				'PRC_amount' => $base_price,
757
+				'PRC_name'   => $ticket->get('TKT_name'),
758
+				'PRC_desc'   => $ticket->get('TKT_description')
759
+			);
760
+		}
761
+
762
+		//possibly need to save tkt
763
+		if ( ! $ticket->ID()) {
764
+			$ticket->save();
765
+		}
766
+
767
+		foreach ($prices as $row => $prc) {
768
+			$prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null;
769
+			if (empty($prt_id)) {
770
+				continue;
771
+			} //prices MUST have a price type id.
772
+			$PRC_values = array(
773
+				'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
774
+				'PRT_ID'         => $prt_id,
775
+				'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
776
+				'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
777
+				'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
778
+				'PRC_is_default' => false,
779
+				//make sure we set PRC_is_default to false for all ticket saves from event_editor
780
+				'PRC_order'      => $row
781
+			);
782
+			if ($new_prices || empty($PRC_values['PRC_ID'])) {
783
+				$PRC_values['PRC_ID'] = 0;
784
+				$PRC                  = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false);
785
+			} else {
786
+				$PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
787
+				//update this price with new values
788
+				foreach ($PRC_values as $field => $newprc) {
789
+					$PRC->set($field, $newprc);
790
+				}
791
+			}
792
+			$PRC->save();
793
+			$prcid                  = $PRC->ID();
794
+			$updated_prices[$prcid] = $PRC;
795
+			$ticket->_add_relation_to($PRC, 'Price');
796
+		}
797
+
798
+		//now let's remove any prices that got removed from the ticket
799
+		if ( ! empty ($current_prices_on_ticket)) {
800
+			$current          = array_keys($current_prices_on_ticket);
801
+			$updated          = array_keys($updated_prices);
802
+			$prices_to_remove = array_diff($current, $updated);
803
+			if ( ! empty($prices_to_remove)) {
804
+				foreach ($prices_to_remove as $prc_id) {
805
+					$p = $current_prices_on_ticket[$prc_id];
806
+					$ticket->_remove_relation_to($p, 'Price');
807
+
808
+					//delete permanently the price
809
+					$p->delete_permanently();
810
+				}
811
+			}
812
+		}
813
+
814
+		return $ticket;
815
+	}
816
+
817
+
818
+	public function autosave_handling($event_admin_obj)
819
+	{
820
+		return $event_admin_obj; //doing nothing for the moment.
821
+		//todo when I get to this remember that I need to set the template args on the $event_admin_obj (use the set_template_args() method)
822
+
823
+		/**
824
+		 * need to remember to handle TICKET DEFAULT saves correctly:  I've got two input fields in the dom:
825
+		 *
826
+		 * 1. TKT_is_default_selector (visible)
827
+		 * 2. TKT_is_default (hidden)
828
+		 *
829
+		 * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want this ticket to be saved as a default.
830
+		 *
831
+		 * The tricky part is, on an initial display on create or edit (or after manually updating), the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true if this is a create.  However, after an autosave, users will want some sort of indicator that the TKT HAS been saved as a default.. in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking.
832
+		 * On Autosave:
833
+		 * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements, then set the TKT_is_default to false.
834
+		 * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well).  We do NOT create a new default ticket.  The checkbox stays selected after autosave.
835
+		 * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket.
836
+		 */
837
+	}
838
+
839
+
840
+	public function pricing_metabox()
841
+	{
842
+		$existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array();
843
+
844
+		$evtobj = $this->_adminpage_obj->get_cpt_model_obj();
845
+
846
+		//set is_creating_event property.
847
+		$evtID                    = $evtobj->ID();
848
+		$this->_is_creating_event = absint($evtID) != 0 ? false : true;
849
+
850
+		//default main template args
851
+		$main_template_args = array(
852
+			'event_datetime_help_link' => EEH_Template::get_help_tab_link('event_editor_event_datetimes_help_tab',
853
+				$this->_adminpage_obj->page_slug, $this->_adminpage_obj->get_req_action(), false, false),
854
+			//todo need to add a filter to the template for the help text in the Events_Admin_Page core file so we can add further help
855
+			'existing_datetime_ids'    => '',
856
+			'total_dtt_rows'           => 1,
857
+			'add_new_dtt_help_link'    => EEH_Template::get_help_tab_link('add_new_dtt_info',
858
+				$this->_adminpage_obj->page_slug, $this->_adminpage_obj->get_req_action(), false, false),
859
+			//todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
860
+			'datetime_rows'            => '',
861
+			'show_tickets_container'   => '',
862
+			//$this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '',
863
+			'ticket_rows'              => '',
864
+			'existing_ticket_ids'      => '',
865
+			'total_ticket_rows'        => 1,
866
+			'ticket_js_structure'      => '',
867
+			'ee_collapsible_status'    => ' ee-collapsible-open'
868
+			//$this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open'
869
+		);
870
+
871
+		$timezone = $evtobj instanceof EE_Event ? $evtobj->timezone_string() : null;
872
+
873
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
874
+
875
+		/**
876
+		 * 1. Start with retrieving Datetimes
877
+		 * 2. For each datetime get related tickets
878
+		 * 3. For each ticket get related prices
879
+		 */
880
+
881
+		$DTM   = EE_Registry::instance()->load_model('Datetime', array($timezone));
882
+		$times = $DTM->get_all_event_dates($evtID);
883
+
884
+
885
+		$main_template_args['total_dtt_rows'] = count($times);
886
+
887
+		/** @see https://events.codebasehq.com/projects/event-espresso/tickets/9486 for why we are counting $dttrow and then setting that on the Datetime object */
888
+		$dttrow = 1;
889
+		foreach ($times as $time) {
890
+			$dttid = $time->get('DTT_ID');
891
+			$time->set('DTT_order', $dttrow);
892
+			$existing_datetime_ids[] = $dttid;
893
+
894
+			//tickets attached
895
+			$related_tickets = $time->ID() > 0 ? $time->get_many_related('Ticket', array(
896
+				array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)),
897
+				'default_where_conditions' => 'none',
898
+				'order_by'                 => array('TKT_order' => 'ASC')
899
+			)) : array();
900
+
901
+			//if there are no related tickets this is likely a new event OR autodraft
902
+			// event so we need to generate the default tickets because dtts
903
+			// ALWAYS have at least one related ticket!!.  EXCEPT, we dont' do this if there is already more than one
904
+			// datetime on the event.
905
+			if (empty ($related_tickets) && count($times) < 2) {
906
+				$related_tickets = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
907
+
908
+				//this should be ordered by TKT_ID, so let's grab the first default ticket (which will be the main default) and ensure it has any default prices added to it (but do NOT save).
909
+				$default_prices = EEM_Price::instance()->get_all_default_prices();
910
+
911
+				$main_default_ticket = reset($related_tickets);
912
+				if ($main_default_ticket instanceof EE_Ticket) {
913
+					foreach ($default_prices as $default_price) {
914
+						if ($default_price->is_base_price()) {
915
+							continue;
916
+						}
917
+						$main_default_ticket->cache('Price', $default_price);
918
+					}
919
+				}
920
+			}
921
+
922
+
923
+			//we can't actually setup rows in this loop yet cause we don't know all the unique tickets for this event yet (tickets are linked through all datetimes). So we're going to temporarily cache some of that information.
924
+
925
+			//loop through and setup the ticket rows and make sure the order is set.
926
+			foreach ($related_tickets as $ticket) {
927
+				$tktid  = $ticket->get('TKT_ID');
928
+				$tktrow = $ticket->get('TKT_row');
929
+				//we only want unique tickets in our final display!!
930
+				if ( ! in_array($tktid, $existing_ticket_ids)) {
931
+					$existing_ticket_ids[] = $tktid;
932
+					$all_tickets[]         = $ticket;
933
+				}
934
+
935
+				//temporary cache of this ticket info for this datetime for later processing of datetime rows.
936
+				$datetime_tickets[$dttid][] = $tktrow;
937
+
938
+				//temporary cache of this datetime info for this ticket for later processing of ticket rows.
939
+				if ( ! isset($ticket_datetimes[$tktid]) || ! in_array($dttrow, $ticket_datetimes[$tktid])) {
940
+					$ticket_datetimes[$tktid][] = $dttrow;
941
+				}
942
+			}
943
+			$dttrow++;
944
+		}
945
+
946
+		$main_template_args['total_ticket_rows']     = count($existing_ticket_ids);
947
+		$main_template_args['existing_ticket_ids']   = implode(',', $existing_ticket_ids);
948
+		$main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
949
+
950
+		//sort $all_tickets by order
951
+		usort($all_tickets, function ($a, $b) {
952
+			$a_order = (int)$a->get('TKT_order');
953
+			$b_order = (int)$b->get('TKT_order');
954
+			if ($a_order == $b_order) {
955
+				return 0;
956
+			}
957
+
958
+			return ($a_order < $b_order) ? -1 : 1;
959
+		});
960
+
961
+		//k NOW we have all the data we need for setting up the dtt rows and ticket rows so we start our dtt loop again.
962
+		$dttrow = 1;
963
+		foreach ($times as $time) {
964
+			$main_template_args['datetime_rows'] .= $this->_get_datetime_row($dttrow, $time, $datetime_tickets,
965
+				$all_tickets, false, $times);
966
+			$dttrow++;
967
+		}
968
+
969
+		//then loop through all tickets for the ticket rows.
970
+		$tktrow = 1;
971
+		foreach ($all_tickets as $ticket) {
972
+			$main_template_args['ticket_rows'] .= $this->_get_ticket_row($tktrow, $ticket, $ticket_datetimes, $times,
973
+				false, $all_tickets);
974
+			$tktrow++;
975
+		}
976
+
977
+		$main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($times, $all_tickets);
978
+		$template                                  = PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php';
979
+		EEH_Template::display_template($template, $main_template_args);
980
+
981
+		return;
982
+	}
983
+
984
+
985
+	protected function _get_datetime_row(
986
+		$dttrow,
987
+		EE_Datetime $dtt,
988
+		$datetime_tickets,
989
+		$all_tickets,
990
+		$default = false,
991
+		$all_dtts = array()
992
+	) {
993
+
994
+		$dtt_display_template_args = array(
995
+			'dtt_edit_row'             => $this->_get_dtt_edit_row($dttrow, $dtt, $default, $all_dtts),
996
+			'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row($dttrow, $dtt, $datetime_tickets,
997
+				$all_tickets, $default),
998
+			'dtt_row'                  => $default ? 'DTTNUM' : $dttrow
999
+		);
1000
+		$template                  = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php';
1001
+
1002
+		return EEH_Template::display_template($template, $dtt_display_template_args, true);
1003
+	}
1004
+
1005
+
1006
+	/**
1007
+	 * This method is used to generate a dtt fields  edit row.
1008
+	 * The same row is used to generate a row with valid DTT objects and the default row that is used as the
1009
+	 * skeleton by the js.
1010
+	 *
1011
+	 * @param int           $dttrow                         The row number for the row being generated.
1012
+	 * @param               mixed                           EE_Datetime|null $dtt      If not default row being
1013
+	 *                                                                       generated, this must be a EE_Datetime
1014
+	 *                                                                       object.
1015
+	 * @param bool          $default                        Whether a default row is being generated or not.
1016
+	 * @param EE_Datetime[] $all_dtts                       This is the array of all datetimes used in the editor.
1017
+	 *
1018
+	 * @return string Generated edit row.
1019
+	 */
1020
+	protected function _get_dtt_edit_row($dttrow, $dtt, $default, $all_dtts)
1021
+	{
1022
+
1023
+		// if the incoming $dtt object is NOT an instance of EE_Datetime then force default to true.
1024
+		$default = ! $dtt instanceof EE_Datetime ? true : false;
1025
+
1026
+		$template_args = array(
1027
+			'dtt_row'              => $default ? 'DTTNUM' : $dttrow,
1028
+			'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1029
+			'edit_dtt_expanded'    => '',
1030
+			//$this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? '' : ' ee-edit-editing',
1031
+			'DTT_ID'               => $default ? '' : $dtt->ID(),
1032
+			'DTT_name'             => $default ? '' : $dtt->name(),
1033
+			'DTT_description'      => $default ? '' : $dtt->description(),
1034
+			'DTT_EVT_start'        => $default ? '' : $dtt->start_date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']),
1035
+			'DTT_EVT_end'          => $default ? '' : $dtt->end_date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']),
1036
+			'DTT_reg_limit'        => $default ? '' : $dtt->get_pretty('DTT_reg_limit', 'input'),
1037
+			'DTT_order'            => $default ? 'DTTNUM' : $dttrow,
1038
+			'dtt_sold'             => $default ? '0' : $dtt->get('DTT_sold'),
1039
+			'dtt_reserved'         => $default ? '0' : $dtt->reserved(),
1040
+			'clone_icon'           => ! empty($dtt) && $dtt->get('DTT_sold') > 0 ? '' : 'clone-icon ee-icon ee-icon-clone clickable',
1041
+			'trash_icon'           => ! empty($dtt) && $dtt->get('DTT_sold') > 0 ? 'ee-lock-icon' : 'trash-icon dashicons dashicons-post-trash clickable',
1042
+			'reg_list_url'         => $default || ! $dtt->event() instanceof \EE_Event
1043
+				? ''
1044
+				: EE_Admin_Page::add_query_args_and_nonce(
1045
+					array('event_id' => $dtt->event()->ID(), 'datetime_id' => $dtt->ID()),
1046
+					REG_ADMIN_URL
1047
+				)
1048
+		);
1049
+
1050
+		$template_args['show_trash'] = count($all_dtts) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' ? ' style="display:none"' : '';
1051
+
1052
+		//allow filtering of template args at this point.
1053
+		$template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args',
1054
+			$template_args, $dttrow, $dtt, $default, $all_dtts, $this->_is_creating_event);
1055
+
1056
+		$template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php';
1057
+
1058
+		return EEH_Template::display_template($template, $template_args, true);
1059
+	}
1060
+
1061
+
1062
+	protected function _get_dtt_attached_tickets_row($dttrow, $dtt, $datetime_tickets, $all_tickets, $default)
1063
+	{
1064
+
1065
+		$template_args = array(
1066
+			'dtt_row'                           => $default ? 'DTTNUM' : $dttrow,
1067
+			'event_datetimes_name'              => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1068
+			'DTT_description'                   => $default ? '' : $dtt->description(),
1069
+			'datetime_tickets_list'             => $default ? '<li class="hidden"></li>' : '',
1070
+			'show_tickets_row'                  => ' style="display:none;"',
1071
+			//$default || $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' style="display:none;"' : '',
1072
+			'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link('add_new_ticket_via_datetime',
1073
+				$this->_adminpage_obj->page_slug, $this->_adminpage_obj->get_req_action(), false, false),
1074
+			//todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1075
+			'DTT_ID'                            => $default ? '' : $dtt->ID()
1076
+		);
1077
+
1078
+		//need to setup the list items (but only if this isnt' a default skeleton setup)
1079
+		if ( ! $default) {
1080
+			$tktrow = 1;
1081
+			foreach ($all_tickets as $ticket) {
1082
+				$template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item($dttrow, $tktrow,
1083
+					$dtt, $ticket, $datetime_tickets, $default);
1084
+				$tktrow++;
1085
+			}
1086
+		}
1087
+
1088
+		//filter template args at this point
1089
+		$template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args',
1090
+			$template_args, $dttrow, $dtt, $datetime_tickets, $all_tickets, $default, $this->_is_creating_event);
1091
+
1092
+		$template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php';
1093
+
1094
+		return EEH_Template::display_template($template, $template_args, true);
1095
+	}
1096
+
1097
+
1098
+	protected function _get_datetime_tickets_list_item($dttrow, $tktrow, $dtt, $ticket, $datetime_tickets, $default)
1099
+	{
1100
+		$tktid    = ! empty($ticket) ? $ticket->ID() : 0;
1101
+		$dtt_tkts = $dtt instanceof EE_Datetime && isset($datetime_tickets[$dtt->ID()]) ? $datetime_tickets[$dtt->ID()] : array();
1102
+
1103
+		$displayrow    = ! empty($ticket) ? $ticket->get('TKT_row') : 0;
1104
+		$template_args = array(
1105
+			'dtt_row'                 => $default ? 'DTTNUM' : $dttrow,
1106
+			'tkt_row'                 => $default && empty($ticket) ? 'TICKETNUM' : $tktrow,
1107
+			'datetime_ticket_checked' => in_array($displayrow, $dtt_tkts) ? ' checked="checked"' : '',
1108
+			'ticket_selected'         => in_array($displayrow, $dtt_tkts) ? ' ticket-selected' : '',
1109
+			'TKT_name'                => $default && empty($ticket) ? 'TKTNAME' : $ticket->get('TKT_name'),
1110
+			'tkt_status_class'        => ($default && empty($ticket)) || $this->_is_creating_event ? ' tkt-status-' . EE_Ticket::onsale : ' tkt-status-' . $ticket->ticket_status(),
1111
+		);
1112
+
1113
+		//filter template args
1114
+		$template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args',
1115
+			$template_args, $dttrow, $tktrow, $dtt, $ticket, $datetime_tickets, $default, $this->_is_creating_event);
1116
+
1117
+		$template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php';
1118
+
1119
+		return EEH_Template::display_template($template, $template_args, true);
1120
+	}
1121
+
1122
+
1123
+	/**
1124
+	 * This generates the ticket row for tickets.
1125
+	 * This same method is used to generate both the actual rows and the js skeleton row (when default ==
1126
+	 * true)
1127
+	 *
1128
+	 * @param int           $tktrow                          Represents the row number being generated.
1129
+	 * @param               mixed                            null|EE_Ticket $ticket           If default then this will
1130
+	 *                                                                      be null.
1131
+	 * @param EE_Datetime[] $ticket_datetimes                Either an array of all datetimes on all tickets indexed by
1132
+	 *                                                       each ticket or empty for  default
1133
+	 * @param EE_Datetime[] $all_dtts                        All Datetimes on the event or empty for default.
1134
+	 * @param bool          $default                         Whether default row being generated or not.
1135
+	 * @param EE_Ticket[]   $all_tickets                     This is an array of all tickets attached to the event (or
1136
+	 *                                                       empty in the case of defaults)
1137
+	 *
1138
+	 * @return [type] [description]
1139
+	 */
1140
+	protected function _get_ticket_row(
1141
+		$tktrow,
1142
+		$ticket,
1143
+		$ticket_datetimes,
1144
+		$all_dtts,
1145
+		$default = false,
1146
+		$all_tickets = array()
1147
+	) {
1148
+
1149
+		//if $ticket is not an instance of EE_Ticket then force default to true.
1150
+		$default = ! $ticket instanceof EE_Ticket ? true : false;
1151
+
1152
+		$prices = ! empty($ticket) && ! $default ? $ticket->get_many_related('Price',
1153
+			array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))) : array();
1154
+
1155
+		//if there is only one price (which would be the base price) or NO prices and this ticket is a default ticket, let's just make sure there are no cached default prices on
1156
+		//the object.  This is done by not including any query_params.
1157
+		if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) {
1158
+			$prices = $ticket->get_many_related('Price');
1159
+		}
1160
+
1161
+		// check if we're dealing with a default ticket in which case we don't want any starting_ticket_datetime_row values set (otherwise there won't be any new relationships created for tickets based off of the default ticket).  This will future proof in case there is ever any behaviour change between what the primary_key defaults to.
1162
+		$default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->get('TKT_is_default')) ? true : false;
1163
+
1164
+		$tkt_dtts = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) ? $ticket_datetimes[$ticket->ID()] : array();
1165
+
1166
+		$ticket_subtotal  = $default ? 0 : $ticket->get_ticket_subtotal();
1167
+		$base_price       = $default ? null : $ticket->base_price();
1168
+		$count_price_mods = EEM_Price::instance()->get_all_default_prices(true);
1169
+
1170
+		//breaking out complicated condition for ticket_status
1171
+		if ($default) {
1172
+			$ticket_status_class = ' tkt-status-' . EE_Ticket::onsale;
1173
+		} else {
1174
+			$ticket_status_class = $ticket->is_default() ? ' tkt-status-' . EE_Ticket::onsale : ' tkt-status-' . $ticket->ticket_status();
1175
+		}
1176
+
1177
+		//breaking out complicated condition for TKT_taxable
1178
+		if ($default) {
1179
+			$TKT_taxable = '';
1180
+		} else {
1181
+			$TKT_taxable = $ticket->get('TKT_taxable') ? ' checked="checked"' : '';
1182
+		}
1183
+
1184
+
1185
+		$template_args = array(
1186
+			'tkt_row'                       => $default ? 'TICKETNUM' : $tktrow,
1187
+			'TKT_order'                     => $default ? 'TICKETNUM' : $tktrow,
1188
+			//on initial page load this will always be the correct order.
1189
+			'tkt_status_class'              => $ticket_status_class,
1190
+			'display_edit_tkt_row'          => ' style="display:none;"',
1191
+			'edit_tkt_expanded'             => '',
1192
+			'edit_tickets_name'             => $default ? 'TICKETNAMEATTR' : 'edit_tickets',
1193
+			'TKT_name'                      => $default ? '' : $ticket->get('TKT_name'),
1194
+			'TKT_start_date'                => $default ? '' : $ticket->get_date('TKT_start_date',
1195
+				$this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']),
1196
+			'TKT_end_date'                  => $default ? '' : $ticket->get_date('TKT_end_date',
1197
+				$this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']),
1198
+			'TKT_status'                    => $default ? EEH_Template::pretty_status(EE_Ticket::onsale, false,
1199
+				'sentence') : $ticket->is_default() ? EEH_Template::pretty_status(EE_Ticket::onsale, false,
1200
+				'sentence') : $ticket->ticket_status(true),
1201
+			'TKT_price'                     => $default ? '' : EEH_Template::format_currency($ticket->get_ticket_total_with_taxes(),
1202
+				false, false),
1203
+			'TKT_price_code'                => EE_Registry::instance()->CFG->currency->code,
1204
+			'TKT_price_amount'              => $default ? 0 : $ticket_subtotal,
1205
+			'TKT_qty'                       => $default ? '' : $ticket->get_pretty('TKT_qty', 'symbol'),
1206
+			'TKT_qty_for_input'             => $default ? '' : $ticket->get_pretty('TKT_qty', 'input'),
1207
+			'TKT_uses'                      => $default ? '' : $ticket->get_pretty('TKT_uses', 'input'),
1208
+			'TKT_min'                       => $default ? '' : ($ticket->get('TKT_min') === -1 || $ticket->get('TKT_min') === 0 ? '' : $ticket->get('TKT_min')),
1209
+			'TKT_max'                       => $default ? '' : $ticket->get_pretty('TKT_max', 'input'),
1210
+			'TKT_sold'                      => $default ? 0 : $ticket->tickets_sold('ticket'),
1211
+			'TKT_reserved'                      => $default ? 0 : $ticket->reserved(),
1212
+			'TKT_registrations'             => $default ? 0 : $ticket->count_registrations(array(
1213
+				array(
1214
+					'STS_ID' => array(
1215
+						'!=',
1216
+						EEM_Registration::status_id_incomplete
1217
+					)
1218
+				)
1219
+			)),
1220
+			'TKT_ID'                        => $default ? 0 : $ticket->get('TKT_ID'),
1221
+			'TKT_description'               => $default ? '' : $ticket->get('TKT_description'),
1222
+			'TKT_is_default'                => $default ? 0 : $ticket->get('TKT_is_default'),
1223
+			'TKT_required'                  => $default ? 0 : $ticket->required(),
1224
+			'TKT_is_default_selector'       => '',
1225
+			'ticket_price_rows'             => '',
1226
+			'TKT_base_price'                => $default || ! $base_price instanceof EE_Price ? '' : $base_price->get_pretty('PRC_amount',
1227
+				'localized_float'),
1228
+			'TKT_base_price_ID'             => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(),
1229
+			'show_price_modifier'           => count($prices) > 1 || ($default && $count_price_mods > 0) ? '' : ' style="display:none;"',
1230
+			'show_price_mod_button'         => count($prices) > 1 || ($default && $count_price_mods > 0) || ( ! $default && $ticket->get('TKT_deleted')) ? ' style="display:none;"' : '',
1231
+			'total_price_rows'              => count($prices) > 1 ? count($prices) : 1,
1232
+			'ticket_datetimes_list'         => $default ? '<li class="hidden"></li>' : '',
1233
+			'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_dtts),
1234
+			'ticket_datetime_rows'          => $default ? '' : implode(',', $tkt_dtts),
1235
+			'existing_ticket_price_ids'     => $default ? '' : implode(',', array_keys($prices)),
1236
+			'ticket_template_id'            => $default ? 0 : $ticket->get('TTM_ID'),
1237
+			'TKT_taxable'                   => $TKT_taxable,
1238
+			'display_subtotal'              => $ticket instanceof EE_Ticket && $ticket->get('TKT_taxable') ? '' : ' style="display:none"',
1239
+			'price_currency_symbol'         => EE_Registry::instance()->CFG->currency->sign,
1240
+			'TKT_subtotal_amount_display'   => EEH_Template::format_currency($ticket_subtotal, false, false),
1241
+			'TKT_subtotal_amount'           => $ticket_subtotal,
1242
+			'tax_rows'                      => $this->_get_tax_rows($tktrow, $ticket),
1243
+			'disabled'                      => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? true : false,
1244
+			'ticket_archive_class'          => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? ' ticket-archived' : '',
1245
+			'trash_icon'                    => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? 'ee-lock-icon ' : 'trash-icon dashicons dashicons-post-trash clickable',
1246
+			'clone_icon'                    => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? '' : 'clone-icon ee-icon ee-icon-clone clickable'
1247
+		);
1248
+
1249
+		$template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] != 'ee-lock-icon' ? ' style="display:none"' : '';
1250
+
1251
+		//handle rows that should NOT be empty
1252
+		if (empty($template_args['TKT_start_date'])) {
1253
+			//if empty then the start date will be now.
1254
+			$template_args['TKT_start_date']   = date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time'],
1255
+				current_time('timestamp'));
1256
+			$template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1257
+		}
1258
+
1259
+		if (empty($template_args['TKT_end_date'])) {
1260
+
1261
+			//get the earliest datetime (if present);
1262
+			$earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related('Datetime',
1263
+				array('order_by' => array('DTT_EVT_start' => 'ASC'))) : null;
1264
+
1265
+			if ( ! empty($earliest_dtt)) {
1266
+				$template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start',
1267
+					$this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']);
1268
+			} else {
1269
+				//default so let's just use what's been set for the default date-time which is 30 days from now.
1270
+				$template_args['TKT_end_date'] = date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time'],
1271
+					mktime(24, 0, 0, date("m"), date("d") + 29, date("Y")));
1272
+			}
1273
+			$template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1274
+		}
1275
+
1276
+		//generate ticket_datetime items
1277
+		if ( ! $default) {
1278
+			$dttrow = 1;
1279
+			foreach ($all_dtts as $dtt) {
1280
+				$template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item($dttrow, $tktrow, $dtt,
1281
+					$ticket, $ticket_datetimes, $default);
1282
+				$dttrow++;
1283
+			}
1284
+		}
1285
+
1286
+		$prcrow = 1;
1287
+		foreach ($prices as $price) {
1288
+			if ($price->is_base_price()) {
1289
+				$prcrow++;
1290
+				continue;
1291
+			}
1292
+			$show_trash  = (count($prices) > 1 && $prcrow === 1) || count($prices) === 1 ? false : true;
1293
+			$show_create = count($prices) > 1 && count($prices) !== $prcrow ? false : true;
1294
+			$template_args['ticket_price_rows'] .= $this->_get_ticket_price_row($tktrow, $prcrow, $price, $default,
1295
+				$ticket, $show_trash, $show_create);
1296
+			$prcrow++;
1297
+		}
1298
+
1299
+		//filter $template_args
1300
+		$template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args',
1301
+			$template_args, $tktrow, $ticket, $ticket_datetimes, $all_dtts, $default, $all_tickets,
1302
+			$this->_is_creating_event);
1303
+
1304
+		$template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php';
1305
+
1306
+		return EEH_Template::display_template($template, $template_args, true);
1307
+	}
1308
+
1309
+
1310
+	protected function _get_tax_rows($tktrow, $ticket)
1311
+	{
1312
+		$tax_rows      = '';
1313
+		$template      = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php';
1314
+		$template_args = array();
1315
+		$taxes         = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin();
1316
+		foreach ($taxes as $tax) {
1317
+			$tax_added     = $this->_get_tax_added($tax, $ticket);
1318
+			$template_args = array(
1319
+				'display_tax'       => ! empty($ticket) && $ticket->get('TKT_taxable') ? '' : ' style="display:none;"',
1320
+				'tax_id'            => $tax->ID(),
1321
+				'tkt_row'           => $tktrow,
1322
+				'tax_label'         => $tax->get('PRC_name'),
1323
+				'tax_added'         => $tax_added,
1324
+				'tax_added_display' => EEH_Template::format_currency($tax_added, false, false),
1325
+				'tax_amount'        => $tax->get('PRC_amount')
1326
+			);
1327
+			$template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args',
1328
+				$template_args, $tktrow, $ticket, $this->_is_creating_event);
1329
+			$tax_rows .= EEH_Template::display_template($template, $template_args, true);
1330
+		}
1331
+
1332
+
1333
+		return $tax_rows;
1334
+	}
1335
+
1336
+
1337
+	protected function _get_tax_added(EE_Price $tax, $ticket)
1338
+	{
1339
+		$subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal();
1340
+
1341
+		return $subtotal * $tax->get('PRC_amount') / 100;
1342
+	}
1343
+
1344
+
1345
+	protected function _get_ticket_price_row(
1346
+		$tktrow,
1347
+		$prcrow,
1348
+		$price,
1349
+		$default,
1350
+		$ticket,
1351
+		$show_trash = true,
1352
+		$show_create = true
1353
+	) {
1354
+		$send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted') ? true : false;
1355
+		$template_args = array(
1356
+			'tkt_row'               => $default && empty($ticket) ? 'TICKETNUM' : $tktrow,
1357
+			'PRC_order'             => $default && empty($price) ? 'PRICENUM' : $prcrow,
1358
+			'edit_prices_name'      => $default && empty($price) ? 'PRICENAMEATTR' : 'edit_prices',
1359
+			'price_type_selector'   => $default && empty($price) ? $this->_get_base_price_template($tktrow, $prcrow,
1360
+				$price, $default) : $this->_get_price_type_selector($tktrow, $prcrow, $price, $default, $send_disabled),
1361
+			'PRC_ID'                => $default && empty($price) ? 0 : $price->ID(),
1362
+			'PRC_is_default'        => $default && empty($price) ? 0 : $price->get('PRC_is_default'),
1363
+			'PRC_name'              => $default && empty($price) ? '' : $price->get('PRC_name'),
1364
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1365
+			'show_plus_or_minus'    => $default && empty($price) ? '' : ' style="display:none;"',
1366
+			'show_plus'             => $default && empty($price) ? ' style="display:none;"' : ($price->is_discount() || $price->is_base_price() ? ' style="display:none;"' : ''),
1367
+			'show_minus'            => $default && empty($price) ? ' style="display:none;"' : ($price->is_discount() ? '' : ' style="display:none;"'),
1368
+			'show_currency_symbol'  => $default && empty($price) ? ' style="display:none"' : ($price->is_percent() ? ' style="display:none"' : ''),
1369
+			'PRC_amount'            => $default && empty($price) ? 0 : $price->get_pretty('PRC_amount',
1370
+				'localized_float'),
1371
+			'show_percentage'       => $default && empty($price) ? ' style="display:none;"' : ($price->is_percent() ? '' : ' style="display:none;"'),
1372
+			'show_trash_icon'       => $show_trash ? '' : ' style="display:none;"',
1373
+			'show_create_button'    => $show_create ? '' : ' style="display:none;"',
1374
+			'PRC_desc'              => $default && empty($price) ? '' : $price->get('PRC_desc'),
1375
+			'disabled'              => ! empty($ticket) && $ticket->get('TKT_deleted') ? true : false
1376
+		);
1377
+
1378
+		$template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args',
1379
+			$template_args, $tktrow, $prcrow, $price, $default, $ticket, $show_trash, $show_create,
1380
+			$this->_is_creating_event);
1381
+
1382
+		$template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php';
1383
+
1384
+		return EEH_Template::display_template($template, $template_args, true);
1385
+	}
1386
+
1387
+
1388
+	protected function _get_price_type_selector($tktrow, $prcrow, $price, $default, $disabled = false)
1389
+	{
1390
+		if ($price->is_base_price()) {
1391
+			return $this->_get_base_price_template($tktrow, $prcrow, $price, $default);
1392
+		} else {
1393
+			return $this->_get_price_modifier_template($tktrow, $prcrow, $price, $default, $disabled);
1394
+		}
1395
+
1396
+	}
1397
+
1398
+
1399
+	protected function _get_base_price_template($tktrow, $prcrow, $price, $default)
1400
+	{
1401
+		$template_args = array(
1402
+			'tkt_row'                   => $default ? 'TICKETNUM' : $tktrow,
1403
+			'PRC_order'                 => $default && empty($price) ? 'PRICENUM' : $prcrow,
1404
+			'PRT_ID'                    => $default && empty($price) ? 1 : $price->get('PRT_ID'),
1405
+			'PRT_name'                  => __('Price', 'event_espresso'),
1406
+			'price_selected_operator'   => '+',
1407
+			'price_selected_is_percent' => 0
1408
+		);
1409
+		$template      = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php';
1410
+
1411
+		$template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args',
1412
+			$template_args, $tktrow, $prcrow, $price, $default, $this->_is_creating_event);
1413
+
1414
+		return EEH_Template::display_template($template, $template_args, true);
1415
+	}
1416
+
1417
+
1418
+	protected function _get_price_modifier_template($tktrow, $prcrow, $price, $default, $disabled = false)
1419
+	{
1420
+		$select_name                = $default && empty($price) ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' : 'edit_prices[' . $tktrow . '][' . $prcrow . '][PRT_ID]';
1421
+		$price_types                = EE_Registry::instance()->load_model('Price_Type')->get_all(array(
1422
+			array(
1423
+				'OR' => array(
1424
+					'PBT_ID'  => '2',
1425
+					'PBT_ID*' => '3'
1426
+				)
1427
+			)
1428
+		));
1429
+		$price_option_span_template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php';
1430
+		$all_price_types            = $default && empty($price) ? array(
1431
+			array(
1432
+				'id'   => 0,
1433
+				'text' => __('Select Modifier', 'event_espresso')
1434
+			)
1435
+		) : array();
1436
+		$selected_price_type_id     = $default && empty($price) ? 0 : $price->type();
1437
+		$price_option_spans         = '';
1438
+		//setup pricetypes for selector
1439
+		foreach ($price_types as $price_type) {
1440
+			$all_price_types[] = array(
1441
+				'id'   => $price_type->ID(),
1442
+				'text' => $price_type->get('PRT_name'),
1443
+			);
1444
+
1445
+			//while we're in the loop let's setup the option spans used by js
1446
+			$spanargs = array(
1447
+				'PRT_ID'         => $price_type->ID(),
1448
+				'PRT_operator'   => $price_type->is_discount() ? '-' : '+',
1449
+				'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0
1450
+			);
1451
+			$price_option_spans .= EEH_Template::display_template($price_option_span_template, $spanargs, true);
1452
+		}
1453
+
1454
+		$select_params = $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"';
1455
+		$main_name     = $select_name;
1456
+		$select_name   = $disabled ? 'archive_price[' . $tktrow . '][' . $prcrow . '][PRT_ID]' : $main_name;
1457
+
1458
+		$template_args = array(
1459
+			'tkt_row'                   => $default ? 'TICKETNUM' : $tktrow,
1460
+			'PRC_order'                 => $default && empty($price) ? 'PRICENUM' : $prcrow,
1461
+			'price_modifier_selector'   => EEH_Form_Fields::select_input($select_name, $all_price_types,
1462
+				$selected_price_type_id, $select_params, 'edit-price-PRT_ID'),
1463
+			'main_name'                 => $main_name,
1464
+			'selected_price_type_id'    => $selected_price_type_id,
1465
+			'price_option_spans'        => $price_option_spans,
1466
+			'price_selected_operator'   => $default && empty($price) ? '' : ($price->is_discount() ? '-' : '+'),
1467
+			'price_selected_is_percent' => $default && empty($price) ? '' : ($price->is_percent() ? 1 : 0),
1468
+			'disabled'                  => $disabled
1469
+		);
1470
+
1471
+		$template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args',
1472
+			$template_args, $tktrow, $prcrow, $price, $default, $disabled, $this->_is_creating_event);
1473
+
1474
+		$template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php';
1475
+
1476
+		return EEH_Template::display_template($template, $template_args, true);
1477
+	}
1478
+
1479
+
1480
+	protected function _get_ticket_datetime_list_item($dttrow, $tktrow, $dtt, $ticket, $ticket_datetimes, $default)
1481
+	{
1482
+		$tkt_dtts      = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) ? $ticket_datetimes[$ticket->ID()] : array();
1483
+		$template_args = array(
1484
+			'dtt_row'                  => $default && ! $dtt instanceof EE_Datetime ? 'DTTNUM' : $dttrow,
1485
+			'tkt_row'                  => $default ? 'TICKETNUM' : $tktrow,
1486
+			'ticket_datetime_selected' => in_array($dttrow, $tkt_dtts) ? ' ticket-selected' : '',
1487
+			'ticket_datetime_checked'  => in_array($dttrow, $tkt_dtts) ? ' checked="checked"' : '',
1488
+			'DTT_name'                 => $default && empty($dtt) ? 'DTTNAME' : $dtt->get_dtt_display_name(true),
1489
+			'tkt_status_class'         => '',
1490
+		);
1491
+
1492
+		$template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args',
1493
+			$template_args, $dttrow, $tktrow, $dtt, $ticket, $ticket_datetimes, $default, $this->_is_creating_event);
1494
+		$template      = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php';
1495
+
1496
+		return EEH_Template::display_template($template, $template_args, true);
1497
+	}
1498
+
1499
+
1500
+	protected function _get_ticket_js_structure($all_dtts, $all_tickets)
1501
+	{
1502
+		$template_args = array(
1503
+			'default_datetime_edit_row'                => $this->_get_dtt_edit_row('DTTNUM', null, true, $all_dtts),
1504
+			'default_ticket_row'                       => $this->_get_ticket_row('TICKETNUM', null, array(), array(),
1505
+				true),
1506
+			'default_price_row'                        => $this->_get_ticket_price_row('TICKETNUM', 'PRICENUM', null,
1507
+				true, null),
1508
+			'default_price_rows'                       => '',
1509
+			'default_base_price_amount'                => 0,
1510
+			'default_base_price_name'                  => '',
1511
+			'default_base_price_description'           => '',
1512
+			'default_price_modifier_selector_row'      => $this->_get_price_modifier_template('TICKETNUM', 'PRICENUM',
1513
+				null, true),
1514
+			'default_available_tickets_for_datetime'   => $this->_get_dtt_attached_tickets_row('DTTNUM', null, array(),
1515
+				array(), true),
1516
+			'existing_available_datetime_tickets_list' => '',
1517
+			'existing_available_ticket_datetimes_list' => '',
1518
+			'new_available_datetime_ticket_list_item'  => $this->_get_datetime_tickets_list_item('DTTNUM', 'TICKETNUM',
1519
+				null, null, array(), true),
1520
+			'new_available_ticket_datetime_list_item'  => $this->_get_ticket_datetime_list_item('DTTNUM', 'TICKETNUM',
1521
+				null, null, array(), true)
1522
+		);
1523
+
1524
+		$tktrow = 1;
1525
+		foreach ($all_tickets as $ticket) {
1526
+			$template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item('DTTNUM',
1527
+				$tktrow, null, $ticket, array(), true);
1528
+			$tktrow++;
1529
+		}
1530
+
1531
+
1532
+		$dttrow = 1;
1533
+		foreach ($all_dtts as $dtt) {
1534
+			$template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item($dttrow,
1535
+				'TICKETNUM', $dtt, null, array(), true);
1536
+			$dttrow++;
1537
+		}
1538
+
1539
+		$default_prices = EE_Registry::instance()->load_model('Price')->get_all_default_prices();
1540
+		$prcrow         = 1;
1541
+		foreach ($default_prices as $price) {
1542
+			if ($price->is_base_price()) {
1543
+				$template_args['default_base_price_amount']      = $price->get_pretty('PRC_amount', 'localized_float');
1544
+				$template_args['default_base_price_name']        = $price->get('PRC_name');
1545
+				$template_args['default_base_price_description'] = $price->get('PRC_desc');
1546
+				$prcrow++;
1547
+				continue;
1548
+			}
1549
+			$show_trash  = (count($default_prices) > 1 && $prcrow === 1) || count($default_prices) === 1 ? false : true;
1550
+			$show_create = count($default_prices) > 1 && count($default_prices) !== $prcrow ? false : true;
1551
+			$template_args['default_price_rows'] .= $this->_get_ticket_price_row('TICKETNUM', $prcrow, $price, true,
1552
+				null, $show_trash, $show_create);
1553
+			$prcrow++;
1554
+		}
1555
+
1556
+		$template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args',
1557
+			$template_args, $all_dtts, $all_tickets, $this->_is_creating_event);
1558
+
1559
+		$template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php';
1560
+
1561
+		return EEH_Template::display_template($template, $template_args, true);
1562
+	}
1563 1563
 
1564 1564
 
1565 1565
 } //end class espresso_events_Pricing_Hooks
Please login to merge, or discard this patch.
core/business/EE_Registration_Processor.class.php 2 patches
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
 			}
216 216
 			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
217 217
 			if ( ! EE_Processor_Base::$IPN ) {
218
-                // otherwise, send out notifications
218
+				// otherwise, send out notifications
219 219
 				add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10 );
220 220
 			}
221 221
 			// DEBUG LOG
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
 			}
263 263
 			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
264 264
 			if ( ! EE_Processor_Base::$IPN ) {
265
-                // otherwise, send out notifications
265
+				// otherwise, send out notifications
266 266
 				add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10 );
267 267
 			}
268 268
 			// DEBUG LOG
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
 			}
350 350
 			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
351 351
 			if ( ! EE_Processor_Base::$IPN ) {
352
-                // otherwise, send out notifications
352
+				// otherwise, send out notifications
353 353
 				add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10 );
354 354
 			}
355 355
 			// DEBUG LOG
@@ -390,10 +390,10 @@  discard block
 block discarded – undo
390 390
 			// 	false,
391 391
 			// 	'EE_Transaction: ' . $registration->transaction()->ID()
392 392
 			// );
393
-            if ( ! $registration->is_primary_registrant()) {
394
-                return;
395
-            }
396
-            do_action(
393
+			if ( ! $registration->is_primary_registrant()) {
394
+				return;
395
+			}
396
+			do_action(
397 397
 				'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
398 398
 				$registration,
399 399
 				$additional_details
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
 		// set new  REG_Status
429 429
 		$this->set_new_reg_status( $registration->ID(), $registration->status_ID() );
430 430
 		return $this->reg_status_updated( $registration->ID() )
431
-		       && $this->new_reg_status( $registration->ID() ) === EEM_Registration::status_id_approved
431
+			   && $this->new_reg_status( $registration->ID() ) === EEM_Registration::status_id_approved
432 432
 			? true
433 433
 			: false;
434 434
 	}
@@ -508,15 +508,15 @@  discard block
 block discarded – undo
508 508
 
509 509
 
510 510
 
511
-    /**
512
-     * update_registration_after_being_canceled_or_declined
513
-     *
514
-     * @param \EE_Registration $registration
515
-     * @param array            $closed_reg_statuses
516
-     * @param bool             $update_reg
517
-     * @return bool
518
-     * @throws \EE_Error
519
-     */
511
+	/**
512
+	 * update_registration_after_being_canceled_or_declined
513
+	 *
514
+	 * @param \EE_Registration $registration
515
+	 * @param array            $closed_reg_statuses
516
+	 * @param bool             $update_reg
517
+	 * @return bool
518
+	 * @throws \EE_Error
519
+	 */
520 520
 	public function update_registration_after_being_canceled_or_declined(
521 521
 		EE_Registration $registration,
522 522
 		$closed_reg_statuses = array(),
@@ -524,14 +524,14 @@  discard block
 block discarded – undo
524 524
 	) {
525 525
 		// these reg statuses should not be considered in any calculations involving monies owing
526 526
 		$closed_reg_statuses = ! empty( $closed_reg_statuses )
527
-            ? $closed_reg_statuses
527
+			? $closed_reg_statuses
528 528
 			: EEM_Registration::closed_reg_statuses();
529 529
 		if ( ! in_array( $registration->status_ID(), $closed_reg_statuses, true ) ) {
530 530
 			return false;
531 531
 		}
532
-        // release a reserved ticket by decrementing ticket and datetime reserved values
533
-        $registration->release_reserved_ticket(true);
534
-        $registration->set_final_price(0);
532
+		// release a reserved ticket by decrementing ticket and datetime reserved values
533
+		$registration->release_reserved_ticket(true);
534
+		$registration->set_final_price(0);
535 535
 		if ( $update_reg ) {
536 536
 			$registration->save();
537 537
 		}
Please login to merge, or discard this patch.
Spacing   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -3,8 +3,8 @@  discard block
 block discarded – undo
3 3
 use EventEspresso\core\domain\entities\RegUrlLink;
4 4
 use EventEspresso\core\domain\services\registration\CreateRegistrationService;
5 5
 
6
-if ( ! defined( 'EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); }
7
-EE_Registry::instance()->load_class( 'Processor_Base' );
6
+if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); }
7
+EE_Registry::instance()->load_class('Processor_Base');
8 8
 
9 9
 /**
10 10
  * Class EE_Registration_Processor
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 	 */
67 67
 	public static function instance() {
68 68
 		// check if class object is instantiated
69
-		if ( ! self::$_instance instanceof EE_Registration_Processor ) {
69
+		if ( ! self::$_instance instanceof EE_Registration_Processor) {
70 70
 			self::$_instance = new self();
71 71
 		}
72 72
 		return self::$_instance;
@@ -86,8 +86,8 @@  discard block
 block discarded – undo
86 86
 	 * @param int $REG_ID
87 87
 	 * @return string
88 88
 	 */
89
-	public function old_reg_status( $REG_ID ) {
90
-		return isset( $this->_old_reg_status[ $REG_ID ] ) ? $this->_old_reg_status[ $REG_ID ] : null;
89
+	public function old_reg_status($REG_ID) {
90
+		return isset($this->_old_reg_status[$REG_ID]) ? $this->_old_reg_status[$REG_ID] : null;
91 91
 	}
92 92
 
93 93
 
@@ -96,10 +96,10 @@  discard block
 block discarded – undo
96 96
 	 * @param int $REG_ID
97 97
 	 * @param string $old_reg_status
98 98
 	 */
99
-	public function set_old_reg_status( $REG_ID, $old_reg_status ) {
99
+	public function set_old_reg_status($REG_ID, $old_reg_status) {
100 100
 		// only set the first time
101
-		if ( ! isset( $this->_old_reg_status[ $REG_ID ] ) ) {
102
-			$this->_old_reg_status[ $REG_ID ] = $old_reg_status;
101
+		if ( ! isset($this->_old_reg_status[$REG_ID])) {
102
+			$this->_old_reg_status[$REG_ID] = $old_reg_status;
103 103
 		}
104 104
 	}
105 105
 
@@ -109,8 +109,8 @@  discard block
 block discarded – undo
109 109
 	 * @param int $REG_ID
110 110
 	 * @return string
111 111
 	 */
112
-	public function new_reg_status( $REG_ID ) {
113
-		return isset( $this->_new_reg_status[ $REG_ID ] ) ? $this->_new_reg_status[ $REG_ID ] : null;
112
+	public function new_reg_status($REG_ID) {
113
+		return isset($this->_new_reg_status[$REG_ID]) ? $this->_new_reg_status[$REG_ID] : null;
114 114
 	}
115 115
 
116 116
 
@@ -119,8 +119,8 @@  discard block
 block discarded – undo
119 119
 	 * @param int $REG_ID
120 120
 	 * @param string $new_reg_status
121 121
 	 */
122
-	public function set_new_reg_status( $REG_ID, $new_reg_status ) {
123
-		$this->_new_reg_status[ $REG_ID ] = $new_reg_status;
122
+	public function set_new_reg_status($REG_ID, $new_reg_status) {
123
+		$this->_new_reg_status[$REG_ID] = $new_reg_status;
124 124
 	}
125 125
 
126 126
 
@@ -131,8 +131,8 @@  discard block
 block discarded – undo
131 131
 	 * @param int $REG_ID
132 132
 	 * @return bool
133 133
 	 */
134
-	public function reg_status_updated( $REG_ID ) {
135
-		return $this->new_reg_status( $REG_ID ) !== $this->old_reg_status( $REG_ID ) ? true : false;
134
+	public function reg_status_updated($REG_ID) {
135
+		return $this->new_reg_status($REG_ID) !== $this->old_reg_status($REG_ID) ? true : false;
136 136
 	}
137 137
 
138 138
 
@@ -141,13 +141,13 @@  discard block
 block discarded – undo
141 141
 	 * @param \EE_Registration $registration
142 142
 	 * @throws \EE_Error
143 143
 	 */
144
-	public function update_registration_status_and_trigger_notifications( \EE_Registration $registration ) {
145
-		$this->toggle_incomplete_registration_status_to_default( $registration, false );
146
-		$this->toggle_registration_status_for_default_approved_events( $registration, false );
147
-		$this->toggle_registration_status_if_no_monies_owing( $registration, false );
144
+	public function update_registration_status_and_trigger_notifications(\EE_Registration $registration) {
145
+		$this->toggle_incomplete_registration_status_to_default($registration, false);
146
+		$this->toggle_registration_status_for_default_approved_events($registration, false);
147
+		$this->toggle_registration_status_if_no_monies_owing($registration, false);
148 148
 		$registration->save();
149 149
 		// trigger notifications
150
-		$this->trigger_registration_update_notifications( $registration );
150
+		$this->trigger_registration_update_notifications($registration);
151 151
 	}
152 152
 
153 153
 
@@ -162,18 +162,18 @@  discard block
 block discarded – undo
162 162
 	 * @return boolean
163 163
 	 * @throws \EE_Error
164 164
 	 */
165
-	public function manually_update_registration_status( EE_Registration $registration, $new_reg_status = '', $save = true ) {
165
+	public function manually_update_registration_status(EE_Registration $registration, $new_reg_status = '', $save = true) {
166 166
 		// set initial REG_Status
167
-		$this->set_old_reg_status( $registration->ID(), $registration->status_ID() );
167
+		$this->set_old_reg_status($registration->ID(), $registration->status_ID());
168 168
 		// set incoming REG_Status
169
-		$this->set_new_reg_status( $registration->ID(), $new_reg_status );
169
+		$this->set_new_reg_status($registration->ID(), $new_reg_status);
170 170
 		// toggle reg status but only if it has changed and the user can do so
171 171
 		if (
172
-			$this->reg_status_updated( $registration->ID() ) &&
173
-			EE_Registry::instance()->CAP->current_user_can( 'ee_edit_registration', 'toggle_registration_status', $registration->ID() )
172
+			$this->reg_status_updated($registration->ID()) &&
173
+			EE_Registry::instance()->CAP->current_user_can('ee_edit_registration', 'toggle_registration_status', $registration->ID())
174 174
 		) {
175 175
 			// change status to new value
176
-			if ( $registration->set_status( $this->new_reg_status( $registration->ID() ) ) && $save ) {
176
+			if ($registration->set_status($this->new_reg_status($registration->ID())) && $save) {
177 177
 				$registration->save();
178 178
 			}
179 179
 			return TRUE;
@@ -193,30 +193,30 @@  discard block
 block discarded – undo
193 193
 	 * @return void
194 194
 	 * @throws \EE_Error
195 195
 	 */
196
-	public function toggle_incomplete_registration_status_to_default( EE_Registration $registration, $save = TRUE ) {
196
+	public function toggle_incomplete_registration_status_to_default(EE_Registration $registration, $save = TRUE) {
197 197
 		$existing_reg_status = $registration->status_ID();
198 198
 		// set initial REG_Status
199
-		$this->set_old_reg_status( $registration->ID(), $existing_reg_status );
199
+		$this->set_old_reg_status($registration->ID(), $existing_reg_status);
200 200
 		// is the registration currently incomplete ?
201
-		if ( $registration->status_ID() === EEM_Registration::status_id_incomplete ) {
201
+		if ($registration->status_ID() === EEM_Registration::status_id_incomplete) {
202 202
 			// grab default reg status for the event, if set
203 203
 			$event_default_registration_status = $registration->event()->default_registration_status();
204 204
 			// if no default reg status is set for the event, then use the global value
205
-			$STS_ID = ! empty( $event_default_registration_status )
205
+			$STS_ID = ! empty($event_default_registration_status)
206 206
 				? $event_default_registration_status
207 207
 				: EE_Registry::instance()->CFG->registration->default_STS_ID;
208 208
 			// if the event default reg status is approved, then downgrade temporarily to payment pending to ensure that payments are triggered
209 209
 			$STS_ID = $STS_ID === EEM_Registration::status_id_approved ? EEM_Registration::status_id_pending_payment : $STS_ID;
210 210
 			// set incoming REG_Status
211
-			$this->set_new_reg_status( $registration->ID(), $STS_ID );
212
-			$registration->set_status( $STS_ID );
213
-			if ( $save ) {
211
+			$this->set_new_reg_status($registration->ID(), $STS_ID);
212
+			$registration->set_status($STS_ID);
213
+			if ($save) {
214 214
 				$registration->save();
215 215
 			}
216 216
 			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
217
-			if ( ! EE_Processor_Base::$IPN ) {
217
+			if ( ! EE_Processor_Base::$IPN) {
218 218
                 // otherwise, send out notifications
219
-				add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10 );
219
+				add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
220 220
 			}
221 221
 			// DEBUG LOG
222 222
 			//$this->log(
@@ -241,10 +241,10 @@  discard block
 block discarded – undo
241 241
 	 * @return boolean
242 242
 	 * @throws \EE_Error
243 243
 	 */
244
-	public function toggle_registration_status_for_default_approved_events( EE_Registration $registration, $save = TRUE ) {
244
+	public function toggle_registration_status_for_default_approved_events(EE_Registration $registration, $save = TRUE) {
245 245
 		$reg_status = $registration->status_ID();
246 246
 		// set initial REG_Status
247
-		$this->set_old_reg_status( $registration->ID(), $reg_status );
247
+		$this->set_old_reg_status($registration->ID(), $reg_status);
248 248
 		// if not already, toggle reg status to approved IF the event default reg status is approved
249 249
 		// ( as long as the registration wasn't cancelled or declined at some point )
250 250
 		if (
@@ -254,16 +254,16 @@  discard block
 block discarded – undo
254 254
 			$registration->event()->default_registration_status() === EEM_Registration::status_id_approved
255 255
 		) {
256 256
 			// set incoming REG_Status
257
-			$this->set_new_reg_status( $registration->ID(), EEM_Registration::status_id_approved );
257
+			$this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved);
258 258
 			// toggle status to approved
259
-			$registration->set_status( EEM_Registration::status_id_approved );
260
-			if ( $save ) {
259
+			$registration->set_status(EEM_Registration::status_id_approved);
260
+			if ($save) {
261 261
 				$registration->save();
262 262
 			}
263 263
 			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
264
-			if ( ! EE_Processor_Base::$IPN ) {
264
+			if ( ! EE_Processor_Base::$IPN) {
265 265
                 // otherwise, send out notifications
266
-				add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10 );
266
+				add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
267 267
 			}
268 268
 			// DEBUG LOG
269 269
 			//$this->log(
@@ -291,19 +291,19 @@  discard block
 block discarded – undo
291 291
 	 * @return bool
292 292
 	 * @throws \EE_Error
293 293
 	 */
294
-	public function toggle_registration_status_if_no_monies_owing( EE_Registration $registration, $save = TRUE, $additional_details = array() ) {
294
+	public function toggle_registration_status_if_no_monies_owing(EE_Registration $registration, $save = TRUE, $additional_details = array()) {
295 295
 		// set initial REG_Status
296
-		$this->set_old_reg_status( $registration->ID(), $registration->status_ID() );
296
+		$this->set_old_reg_status($registration->ID(), $registration->status_ID());
297 297
 		//EEH_Debug_Tools::printr( $additional_details, '$additional_details', __FILE__, __LINE__ );
298 298
 		// was a payment just made ?
299 299
 		if (
300
-			isset( $additional_details[ 'payment_updates' ], $additional_details[ 'last_payment' ] ) &&
301
-			$additional_details[ 'payment_updates' ] &&
302
-			$additional_details[ 'last_payment' ] instanceof EE_Payment
300
+			isset($additional_details['payment_updates'], $additional_details['last_payment']) &&
301
+			$additional_details['payment_updates'] &&
302
+			$additional_details['last_payment'] instanceof EE_Payment
303 303
 		) {
304
-			$payment = $additional_details[ 'last_payment' ];
304
+			$payment = $additional_details['last_payment'];
305 305
 			$total_paid = 0;
306
-			foreach ( self::$_amount_paid as $reg => $amount_paid ) {
306
+			foreach (self::$_amount_paid as $reg => $amount_paid) {
307 307
 				$total_paid += $amount_paid;
308 308
 			}
309 309
 		} else {
@@ -327,30 +327,30 @@  discard block
 block discarded – undo
327 327
 					$registration->transaction()->is_completed() ||
328 328
 					$registration->transaction()->is_overpaid() ||
329 329
 					$registration->transaction()->is_free() ||
330
-					apply_filters( 'FHEE__EE_Registration_Processor__toggle_registration_status_if_no_monies_owing', false, $registration )
330
+					apply_filters('FHEE__EE_Registration_Processor__toggle_registration_status_if_no_monies_owing', false, $registration)
331 331
 				) || (
332 332
 					$payment instanceof EE_Payment &&
333 333
 					$payment->is_approved() &&
334 334
 					// this specific registration has not yet been paid for
335
-					! isset( self::$_amount_paid[ $registration->ID() ] ) &&
335
+					! isset(self::$_amount_paid[$registration->ID()]) &&
336 336
 					// payment amount, less what we have already attributed to other registrations, is greater than this reg's final price
337 337
 					$payment->amount() - $total_paid >= $registration->final_price()
338 338
 				)
339 339
 			)
340 340
 		) {
341 341
 			// mark as paid
342
-			self::$_amount_paid[ $registration->ID() ] = $registration->final_price();
342
+			self::$_amount_paid[$registration->ID()] = $registration->final_price();
343 343
 			// track new REG_Status
344
-			$this->set_new_reg_status( $registration->ID(), EEM_Registration::status_id_approved );
344
+			$this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved);
345 345
 			// toggle status to approved
346
-			$registration->set_status( EEM_Registration::status_id_approved );
347
-			if ( $save ) {
346
+			$registration->set_status(EEM_Registration::status_id_approved);
347
+			if ($save) {
348 348
 				$registration->save();
349 349
 			}
350 350
 			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
351
-			if ( ! EE_Processor_Base::$IPN ) {
351
+			if ( ! EE_Processor_Base::$IPN) {
352 352
                 // otherwise, send out notifications
353
-				add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10 );
353
+				add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
354 354
 			}
355 355
 			// DEBUG LOG
356 356
 			//$this->log(
@@ -376,10 +376,10 @@  discard block
 block discarded – undo
376 376
 	 * @param array 	$additional_details
377 377
 	 * @return void
378 378
 	 */
379
-	public function trigger_registration_update_notifications( $registration, $additional_details = array() ) {
379
+	public function trigger_registration_update_notifications($registration, $additional_details = array()) {
380 380
 		try {
381
-			if ( ! $registration instanceof EE_Registration ) {
382
-				throw new EE_Error( __( 'An invalid registration was received.', 'event_espresso' ) );
381
+			if ( ! $registration instanceof EE_Registration) {
382
+				throw new EE_Error(__('An invalid registration was received.', 'event_espresso'));
383 383
 			}
384 384
 			// EE_Registry::instance()->load_helper( 'Debug_Tools' );
385 385
 			// EEH_Debug_Tools::log(
@@ -398,8 +398,8 @@  discard block
 block discarded – undo
398 398
 				$registration,
399 399
 				$additional_details
400 400
 			);
401
-		} catch( Exception $e ) {
402
-			EE_Error::add_error( $e->getMessage(), $e->getFile(), 'unknown_function_from_exception', $e->getLine() );
401
+		} catch (Exception $e) {
402
+			EE_Error::add_error($e->getMessage(), $e->getFile(), 'unknown_function_from_exception', $e->getLine());
403 403
 		}
404 404
 	}
405 405
 
@@ -413,22 +413,22 @@  discard block
 block discarded – undo
413 413
 	 * @return bool
414 414
 	 * @throws \EE_Error
415 415
 	 */
416
-	public function update_registration_after_checkout_or_payment(  EE_Registration $registration, $additional_details = array() ) {
416
+	public function update_registration_after_checkout_or_payment(EE_Registration $registration, $additional_details = array()) {
417 417
 		// set initial REG_Status
418
-		$this->set_old_reg_status( $registration->ID(), $registration->status_ID() );
418
+		$this->set_old_reg_status($registration->ID(), $registration->status_ID());
419 419
 
420 420
 		// if the registration status gets updated, then save the registration
421 421
 		if (
422
-			$this->toggle_registration_status_for_default_approved_events( $registration, false )
423
-			|| $this->toggle_registration_status_if_no_monies_owing( $registration, false, $additional_details )
422
+			$this->toggle_registration_status_for_default_approved_events($registration, false)
423
+			|| $this->toggle_registration_status_if_no_monies_owing($registration, false, $additional_details)
424 424
 		) {
425 425
 			$registration->save();
426 426
 		}
427 427
 
428 428
 		// set new  REG_Status
429
-		$this->set_new_reg_status( $registration->ID(), $registration->status_ID() );
430
-		return $this->reg_status_updated( $registration->ID() )
431
-		       && $this->new_reg_status( $registration->ID() ) === EEM_Registration::status_id_approved
429
+		$this->set_new_reg_status($registration->ID(), $registration->status_ID());
430
+		return $this->reg_status_updated($registration->ID())
431
+		       && $this->new_reg_status($registration->ID()) === EEM_Registration::status_id_approved
432 432
 			? true
433 433
 			: false;
434 434
 	}
@@ -444,20 +444,20 @@  discard block
 block discarded – undo
444 444
 	 * @return void
445 445
 	 * @throws \EE_Error
446 446
 	 */
447
-	public function update_registration_final_prices( $transaction, $save_regs = true ) {
448
-		$reg_final_price_per_ticket_line_item = EEH_Line_Item::calculate_reg_final_prices_per_line_item( $transaction->total_line_item() );
449
-		foreach( $transaction->registrations() as $registration ) {
447
+	public function update_registration_final_prices($transaction, $save_regs = true) {
448
+		$reg_final_price_per_ticket_line_item = EEH_Line_Item::calculate_reg_final_prices_per_line_item($transaction->total_line_item());
449
+		foreach ($transaction->registrations() as $registration) {
450 450
 			/** @var EE_Line_Item $line_item */
451
-			$line_item = EEM_Line_Item::instance()->get_line_item_for_registration( $registration );
452
-			if( isset( $reg_final_price_per_ticket_line_item[ $line_item->ID() ] ) ) {
453
-				$registration->set_final_price( $reg_final_price_per_ticket_line_item[ $line_item->ID() ] );
454
-				if( $save_regs ) {
451
+			$line_item = EEM_Line_Item::instance()->get_line_item_for_registration($registration);
452
+			if (isset($reg_final_price_per_ticket_line_item[$line_item->ID()])) {
453
+				$registration->set_final_price($reg_final_price_per_ticket_line_item[$line_item->ID()]);
454
+				if ($save_regs) {
455 455
 					$registration->save();
456 456
 				}
457 457
 			}
458 458
 		}
459 459
 		//and make sure there's no rounding problem
460
-		$this->fix_reg_final_price_rounding_issue( $transaction );
460
+		$this->fix_reg_final_price_rounding_issue($transaction);
461 461
 	}
462 462
 
463 463
 
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
 	 * @return boolean success verifying that there is NO difference after this method is done
478 478
 	 * @throws \EE_Error
479 479
 	 */
480
-	public function fix_reg_final_price_rounding_issue( $transaction ) {
480
+	public function fix_reg_final_price_rounding_issue($transaction) {
481 481
 		$reg_final_price_sum = EEM_Registration::instance()->sum(
482 482
 			array(
483 483
 				array(
@@ -486,9 +486,9 @@  discard block
 block discarded – undo
486 486
 			),
487 487
 			'REG_final_price'
488 488
 		);
489
-		$diff =  $transaction->total() - (float) $reg_final_price_sum;
489
+		$diff = $transaction->total() - (float) $reg_final_price_sum;
490 490
 		//ok then, just grab one of the registrations
491
-		if( $diff !== 0 ) {
491
+		if ($diff !== 0) {
492 492
 			$a_reg = EEM_Registration::instance()->get_one(
493 493
 					array(
494 494
 						array(
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
 					));
498 498
 			$success = $a_reg instanceof EE_Registration
499 499
 				? $a_reg->save(
500
-					array( 'REG_final_price' => $a_reg->final_price() + $diff )
500
+					array('REG_final_price' => $a_reg->final_price() + $diff)
501 501
 				)
502 502
 				: false;
503 503
 			return $success ? true : false;
@@ -523,16 +523,16 @@  discard block
 block discarded – undo
523 523
 		$update_reg = true
524 524
 	) {
525 525
 		// these reg statuses should not be considered in any calculations involving monies owing
526
-		$closed_reg_statuses = ! empty( $closed_reg_statuses )
526
+		$closed_reg_statuses = ! empty($closed_reg_statuses)
527 527
             ? $closed_reg_statuses
528 528
 			: EEM_Registration::closed_reg_statuses();
529
-		if ( ! in_array( $registration->status_ID(), $closed_reg_statuses, true ) ) {
529
+		if ( ! in_array($registration->status_ID(), $closed_reg_statuses, true)) {
530 530
 			return false;
531 531
 		}
532 532
         // release a reserved ticket by decrementing ticket and datetime reserved values
533 533
         $registration->release_reserved_ticket(true);
534 534
         $registration->set_final_price(0);
535
-		if ( $update_reg ) {
535
+		if ($update_reg) {
536 536
 			$registration->save();
537 537
 		}
538 538
 		return true;
@@ -555,23 +555,23 @@  discard block
 block discarded – undo
555 555
 		$update_reg = true
556 556
 	) {
557 557
 		// these reg statuses should not be considered in any calculations involving monies owing
558
-		$closed_reg_statuses = ! empty( $closed_reg_statuses ) ? $closed_reg_statuses
558
+		$closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses
559 559
 			: EEM_Registration::closed_reg_statuses();
560
-		if ( in_array( $registration->status_ID(), $closed_reg_statuses ) ) {
560
+		if (in_array($registration->status_ID(), $closed_reg_statuses)) {
561 561
 			return false;
562 562
 		}
563 563
 		$ticket = $registration->ticket();
564
-		if ( ! $ticket instanceof EE_Ticket ) {
564
+		if ( ! $ticket instanceof EE_Ticket) {
565 565
 			throw new EE_Error(
566 566
 				sprintf(
567
-					__( 'The Ticket for Registration %1$d was not found or is invalid.',
568
-						'event_espresso' ),
567
+					__('The Ticket for Registration %1$d was not found or is invalid.',
568
+						'event_espresso'),
569 569
 					$registration->ticket_ID()
570 570
 				)
571 571
 			);
572 572
 		}
573
-		$registration->set_final_price( $ticket->price() );
574
-		if ( $update_reg ) {
573
+		$registration->set_final_price($ticket->price());
574
+		if ($update_reg) {
575 575
 			$registration->save();
576 576
 		}
577 577
 		return true;
@@ -609,7 +609,7 @@  discard block
 block discarded – undo
609 609
 		$total_ticket_count = 1
610 610
 	) {
611 611
 		EE_Error::doing_it_wrong(
612
-			__CLASS__ . '::' . __FUNCTION__,
612
+			__CLASS__.'::'.__FUNCTION__,
613 613
 			sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
614 614
 				'\EventEspresso\core\domain\services\registration\CreateRegistrationService::create()'),
615 615
 			'4.9.1',
@@ -652,7 +652,7 @@  discard block
 block discarded – undo
652 652
 	public function generate_reg_url_link($att_nmbr, $item)
653 653
 	{
654 654
 		EE_Error::doing_it_wrong(
655
-			__CLASS__ . '::' . __FUNCTION__,
655
+			__CLASS__.'::'.__FUNCTION__,
656 656
 			sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
657 657
 				'EventEspresso\core\domain\entities\RegUrlLink'),
658 658
 			'4.9.1',
@@ -672,11 +672,11 @@  discard block
 block discarded – undo
672 672
 	 * @return string
673 673
 	 * @throws \EE_Error
674 674
 	 */
675
-	public function generate_reg_code( EE_Registration $registration ) {
675
+	public function generate_reg_code(EE_Registration $registration) {
676 676
 		EE_Error::doing_it_wrong(
677
-			__CLASS__ . '::' . __FUNCTION__,
677
+			__CLASS__.'::'.__FUNCTION__,
678 678
 			sprintf(
679
-				__( 'This method is deprecated. Please use "%s" instead', 'event_espresso' ),
679
+				__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
680 680
 				'EventEspresso\core\domain\entities\RegCode'
681 681
 			),
682 682
 			'4.9.1',
@@ -685,7 +685,7 @@  discard block
 block discarded – undo
685 685
 		return apply_filters(
686 686
 			'FHEE__EE_Registration_Processor___generate_reg_code__new_reg_code',
687 687
 			new RegCode(
688
-				RegUrlLink::fromRegistration( $registration ),
688
+				RegUrlLink::fromRegistration($registration),
689 689
 				$registration->transaction(),
690 690
 				$registration->ticket()
691 691
 			),
Please login to merge, or discard this patch.
core/domain/services/registration/CreateRegistrationService.php 1 patch
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 use EventEspresso\core\exceptions\UnexpectedEntityException;
8 8
 
9 9
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
10
-    exit('No direct script access allowed');
10
+	exit('No direct script access allowed');
11 11
 }
12 12
 
13 13
 
@@ -24,101 +24,101 @@  discard block
 block discarded – undo
24 24
 {
25 25
 
26 26
 
27
-    /**
28
-     * @param \EE_Event       $event
29
-     * @param \EE_Transaction $transaction
30
-     * @param \EE_Ticket      $ticket
31
-     * @param \EE_Line_Item   $ticket_line_item
32
-     * @param                 $reg_count
33
-     * @param                 $reg_group_size
34
-     * @return \EE_Registration
35
-     * @throws \EE_Error
36
-     * @throws UnexpectedEntityException
37
-     */
38
-    public function create(
39
-        \EE_Event $event,
40
-        \EE_Transaction $transaction,
41
-        \EE_Ticket $ticket,
42
-        \EE_Line_Item $ticket_line_item,
43
-        $reg_count,
44
-        $reg_group_size
45
-    ) {
46
-        $registrations = $transaction->registrations();
47
-        $reg_count = $reg_count ? $reg_count : count($registrations) + 1;
48
-        $reg_url_link = new RegUrlLink($reg_count, $ticket_line_item);
49
-        $reg_code = new RegCode($reg_url_link, $transaction, $ticket);
50
-        // generate new EE_Registration
51
-        $registration = \EE_Registration::new_instance(
52
-            array(
53
-                'EVT_ID'          => $event->ID(),
54
-                'TXN_ID'          => $transaction->ID(),
55
-                'TKT_ID'          => $ticket->ID(),
56
-                'STS_ID'          => \EEM_Registration::status_id_incomplete,
57
-                'REG_final_price' => $this->resolveFinalPrice($transaction, $ticket, $ticket_line_item),
58
-                'REG_session'     => \EE_Registry::instance()->SSN->id(),
59
-                'REG_count'       => $reg_count,
60
-                'REG_group_size'  => $reg_group_size ? $reg_group_size : $this->incrementRegCount($registrations),
61
-                'REG_url_link'    => $reg_url_link,
62
-                'REG_code'        => $reg_code,
63
-            )
64
-        );
65
-        if ( ! $registration instanceof \EE_Registration) {
66
-            throw new UnexpectedEntityException($registration, 'EE_Registration');
67
-        }
68
-        // save registration so that we have an ID
69
-        $registration->save();
70
-        // track reservation on reg but don't adjust ticket and datetime reserved counts
71
-        // because that is done as soon as the tickets are added/removed from the cart
72
-        $registration->reserve_ticket();
73
-        $registration->_add_relation_to($event, 'Event', array(), $event->ID());
74
-        $registration->_add_relation_to($ticket, 'Ticket', array(), $ticket->ID());
75
-        $transaction->_add_relation_to($registration, 'Registration', array(), $registration->ID());
76
-        $registration->save();
77
-        return $registration;
78
-    }
27
+	/**
28
+	 * @param \EE_Event       $event
29
+	 * @param \EE_Transaction $transaction
30
+	 * @param \EE_Ticket      $ticket
31
+	 * @param \EE_Line_Item   $ticket_line_item
32
+	 * @param                 $reg_count
33
+	 * @param                 $reg_group_size
34
+	 * @return \EE_Registration
35
+	 * @throws \EE_Error
36
+	 * @throws UnexpectedEntityException
37
+	 */
38
+	public function create(
39
+		\EE_Event $event,
40
+		\EE_Transaction $transaction,
41
+		\EE_Ticket $ticket,
42
+		\EE_Line_Item $ticket_line_item,
43
+		$reg_count,
44
+		$reg_group_size
45
+	) {
46
+		$registrations = $transaction->registrations();
47
+		$reg_count = $reg_count ? $reg_count : count($registrations) + 1;
48
+		$reg_url_link = new RegUrlLink($reg_count, $ticket_line_item);
49
+		$reg_code = new RegCode($reg_url_link, $transaction, $ticket);
50
+		// generate new EE_Registration
51
+		$registration = \EE_Registration::new_instance(
52
+			array(
53
+				'EVT_ID'          => $event->ID(),
54
+				'TXN_ID'          => $transaction->ID(),
55
+				'TKT_ID'          => $ticket->ID(),
56
+				'STS_ID'          => \EEM_Registration::status_id_incomplete,
57
+				'REG_final_price' => $this->resolveFinalPrice($transaction, $ticket, $ticket_line_item),
58
+				'REG_session'     => \EE_Registry::instance()->SSN->id(),
59
+				'REG_count'       => $reg_count,
60
+				'REG_group_size'  => $reg_group_size ? $reg_group_size : $this->incrementRegCount($registrations),
61
+				'REG_url_link'    => $reg_url_link,
62
+				'REG_code'        => $reg_code,
63
+			)
64
+		);
65
+		if ( ! $registration instanceof \EE_Registration) {
66
+			throw new UnexpectedEntityException($registration, 'EE_Registration');
67
+		}
68
+		// save registration so that we have an ID
69
+		$registration->save();
70
+		// track reservation on reg but don't adjust ticket and datetime reserved counts
71
+		// because that is done as soon as the tickets are added/removed from the cart
72
+		$registration->reserve_ticket();
73
+		$registration->_add_relation_to($event, 'Event', array(), $event->ID());
74
+		$registration->_add_relation_to($ticket, 'Ticket', array(), $ticket->ID());
75
+		$transaction->_add_relation_to($registration, 'Registration', array(), $registration->ID());
76
+		$registration->save();
77
+		return $registration;
78
+	}
79 79
 
80 80
 
81 81
 
82
-    /**
83
-     * @param \EE_Transaction $transaction
84
-     * @param \EE_Ticket      $ticket
85
-     * @param \EE_Line_Item   $ticket_line_item
86
-     * @return float
87
-     */
88
-    protected function resolveFinalPrice(
89
-        \EE_Transaction $transaction,
90
-        \EE_Ticket $ticket,
91
-        \EE_Line_Item $ticket_line_item
92
-    ) {
93
-        $final_price = \EEH_Line_Item::calculate_final_price_for_ticket_line_item(
94
-            $transaction->total_line_item(),
95
-            $ticket_line_item
96
-        );
97
-        $final_price = $final_price !== null ? $final_price : $ticket->get_ticket_total_with_taxes();
98
-        return (float)$final_price;
99
-    }
82
+	/**
83
+	 * @param \EE_Transaction $transaction
84
+	 * @param \EE_Ticket      $ticket
85
+	 * @param \EE_Line_Item   $ticket_line_item
86
+	 * @return float
87
+	 */
88
+	protected function resolveFinalPrice(
89
+		\EE_Transaction $transaction,
90
+		\EE_Ticket $ticket,
91
+		\EE_Line_Item $ticket_line_item
92
+	) {
93
+		$final_price = \EEH_Line_Item::calculate_final_price_for_ticket_line_item(
94
+			$transaction->total_line_item(),
95
+			$ticket_line_item
96
+		);
97
+		$final_price = $final_price !== null ? $final_price : $ticket->get_ticket_total_with_taxes();
98
+		return (float)$final_price;
99
+	}
100 100
 
101 101
 
102 102
 
103
-    /**
104
-     * @param  \EE_Registration[] $registrations
105
-     * @param  boolean            $update_existing_registrations
106
-     * @return int
107
-     * @throws \EE_Error
108
-     */
109
-    protected function incrementRegCount(array $registrations, $update_existing_registrations = true)
110
-    {
111
-        $new_reg_count = count($registrations) + 1;
112
-        if ($update_existing_registrations) {
113
-            foreach ($registrations as $registration) {
114
-                if ($registration instanceof \EE_Registration) {
115
-                    $registration->set_count($new_reg_count);
116
-                    $registration->save();
117
-                }
118
-            }
119
-        }
120
-        return $new_reg_count;
121
-    }
103
+	/**
104
+	 * @param  \EE_Registration[] $registrations
105
+	 * @param  boolean            $update_existing_registrations
106
+	 * @return int
107
+	 * @throws \EE_Error
108
+	 */
109
+	protected function incrementRegCount(array $registrations, $update_existing_registrations = true)
110
+	{
111
+		$new_reg_count = count($registrations) + 1;
112
+		if ($update_existing_registrations) {
113
+			foreach ($registrations as $registration) {
114
+				if ($registration instanceof \EE_Registration) {
115
+					$registration->set_count($new_reg_count);
116
+					$registration->save();
117
+				}
118
+			}
119
+		}
120
+		return $new_reg_count;
121
+	}
122 122
 
123 123
 
124 124
 }
Please login to merge, or discard this patch.
caffeinated/payment_methods/Aim/EE_PMT_Aim.pm.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@
 block discarded – undo
22 22
 	public function __construct($pm_instance = NULL) {
23 23
 		$this->_setup_properties();
24 24
 		parent::__construct($pm_instance);
25
-        $this->_gateway->set_unsupported_character_remover(new \EventEspresso\core\services\formatters\Windows1252());
25
+		$this->_gateway->set_unsupported_character_remover(new \EventEspresso\core\services\formatters\Windows1252());
26 26
 	}
27 27
 	
28 28
 	/**
Please login to merge, or discard this patch.
core/libraries/payment_methods/EE_PMT_Base.lib.php 2 patches
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -106,9 +106,9 @@  discard block
 block discarded – undo
106 106
 			$this->_gateway->set_template_helper( new EEH_Template() );
107 107
 			$this->_gateway->set_line_item_helper( new EEH_Line_Item() );
108 108
 			$this->_gateway->set_money_helper( new EEH_Money() );
109
-            $this->_gateway->set_gateway_data_formatter(new GatewayDataFormatter());
110
-            $this->_gateway->set_unsupported_character_remover(new AsciiOnly());
111
-            do_action( 'AHEE__EE_PMT_Base___construct__done_initializing_gateway_class',$this,$this->_gateway);
109
+			$this->_gateway->set_gateway_data_formatter(new GatewayDataFormatter());
110
+			$this->_gateway->set_unsupported_character_remover(new AsciiOnly());
111
+			do_action( 'AHEE__EE_PMT_Base___construct__done_initializing_gateway_class',$this,$this->_gateway);
112 112
 		}
113 113
 		if ( ! isset( $this->_has_billing_form ) ) {
114 114
 			// by default, On Site gateways have a billing form
@@ -282,17 +282,17 @@  discard block
 block discarded – undo
282 282
 		//if we know who the attendee is, and this is a billing form
283 283
 		//that uses attendee info, populate it
284 284
 		if (
285
-            apply_filters(
286
-                'FHEE__populate_billing_form_fields_from_attendee',
287
-                (
288
-                    $this->_billing_form instanceof EE_Billing_Attendee_Info_Form
289
-                    && $transaction instanceof EE_Transaction
290
-                    && $transaction->primary_registration() instanceof EE_Registration
291
-                    && $transaction->primary_registration()->attendee() instanceof EE_Attendee
292
-                ),
293
-                $this->_billing_form,
294
-                $transaction
295
-            )
285
+			apply_filters(
286
+				'FHEE__populate_billing_form_fields_from_attendee',
287
+				(
288
+					$this->_billing_form instanceof EE_Billing_Attendee_Info_Form
289
+					&& $transaction instanceof EE_Transaction
290
+					&& $transaction->primary_registration() instanceof EE_Registration
291
+					&& $transaction->primary_registration()->attendee() instanceof EE_Attendee
292
+				),
293
+				$this->_billing_form,
294
+				$transaction
295
+			)
296 296
 		){
297 297
 			$this->_billing_form->populate_from_attendee( $transaction->primary_registration()->attendee() );
298 298
 		}
Please login to merge, or discard this patch.
Spacing   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @since 				$VID:$
17 17
  *
18 18
  */
19
-abstract class EE_PMT_Base{
19
+abstract class EE_PMT_Base {
20 20
 
21 21
 	const onsite = 'on-site';
22 22
 	const offsite = 'off-site';
@@ -97,34 +97,34 @@  discard block
 block discarded – undo
97 97
 	 * @return EE_PMT_Base
98 98
 	 */
99 99
 	function __construct($pm_instance = NULL) {
100
-		if ( $pm_instance instanceof EE_Payment_Method ){
100
+		if ($pm_instance instanceof EE_Payment_Method) {
101 101
 			$this->set_instance($pm_instance);
102 102
 		}
103
-		if($this->_gateway){
104
-			$this->_gateway->set_payment_model( EEM_Payment::instance() );
105
-			$this->_gateway->set_payment_log( EEM_Change_Log::instance() );
106
-			$this->_gateway->set_template_helper( new EEH_Template() );
107
-			$this->_gateway->set_line_item_helper( new EEH_Line_Item() );
108
-			$this->_gateway->set_money_helper( new EEH_Money() );
103
+		if ($this->_gateway) {
104
+			$this->_gateway->set_payment_model(EEM_Payment::instance());
105
+			$this->_gateway->set_payment_log(EEM_Change_Log::instance());
106
+			$this->_gateway->set_template_helper(new EEH_Template());
107
+			$this->_gateway->set_line_item_helper(new EEH_Line_Item());
108
+			$this->_gateway->set_money_helper(new EEH_Money());
109 109
             $this->_gateway->set_gateway_data_formatter(new GatewayDataFormatter());
110 110
             $this->_gateway->set_unsupported_character_remover(new AsciiOnly());
111
-            do_action( 'AHEE__EE_PMT_Base___construct__done_initializing_gateway_class',$this,$this->_gateway);
111
+            do_action('AHEE__EE_PMT_Base___construct__done_initializing_gateway_class', $this, $this->_gateway);
112 112
 		}
113
-		if ( ! isset( $this->_has_billing_form ) ) {
113
+		if ( ! isset($this->_has_billing_form)) {
114 114
 			// by default, On Site gateways have a billing form
115
-			if ( $this->payment_occurs() == EE_PMT_Base::onsite ) {
116
-				$this->set_has_billing_form( true );
115
+			if ($this->payment_occurs() == EE_PMT_Base::onsite) {
116
+				$this->set_has_billing_form(true);
117 117
 			} else {
118
-				$this->set_has_billing_form( false );
118
+				$this->set_has_billing_form(false);
119 119
 			}
120 120
 		}
121 121
 
122
-		if( ! $this->_pretty_name){
122
+		if ( ! $this->_pretty_name) {
123 123
 			throw new EE_Error(sprintf(__("You must set the pretty name for the Payment Method Type in the constructor (_pretty_name), and please make it internationalized", "event_espresso")));
124 124
 		}
125 125
 		//if the child didn't specify a default button, use the credit card one
126
-		if( $this->_default_button_url === NULL){
127
-			$this->_default_button_url = EE_PLUGIN_DIR_URL . 'payment_methods' . DS . 'pay-by-credit-card.png';
126
+		if ($this->_default_button_url === NULL) {
127
+			$this->_default_button_url = EE_PLUGIN_DIR_URL.'payment_methods'.DS.'pay-by-credit-card.png';
128 128
 		}
129 129
 	}
130 130
 
@@ -133,8 +133,8 @@  discard block
 block discarded – undo
133 133
 	/**
134 134
 	 * @param boolean $has_billing_form
135 135
 	 */
136
-	public function set_has_billing_form( $has_billing_form ) {
137
-		$this->_has_billing_form = filter_var( $has_billing_form, FILTER_VALIDATE_BOOLEAN );
136
+	public function set_has_billing_form($has_billing_form) {
137
+		$this->_has_billing_form = filter_var($has_billing_form, FILTER_VALIDATE_BOOLEAN);
138 138
 	}
139 139
 
140 140
 
@@ -142,10 +142,10 @@  discard block
 block discarded – undo
142 142
 	/**
143 143
 	 * sets the file_folder property
144 144
 	 */
145
-	protected function _set_file_folder(){
145
+	protected function _set_file_folder() {
146 146
 		$reflector = new ReflectionClass(get_class($this));
147 147
 		$fn = $reflector->getFileName();
148
-		$this->_file_folder =  dirname($fn).DS;
148
+		$this->_file_folder = dirname($fn).DS;
149 149
 	}
150 150
 
151 151
 
@@ -153,10 +153,10 @@  discard block
 block discarded – undo
153 153
 	/**
154 154
 	 * sets the file URL with a trailing slash for this PMT
155 155
 	 */
156
-	protected function _set_file_url(){
157
-		$plugins_dir_fixed = str_replace('\\',DS,WP_PLUGIN_DIR);
158
-		$file_folder_fixed = str_replace('\\',DS,$this->file_folder());
159
-		$file_path = str_replace($plugins_dir_fixed,WP_PLUGIN_URL,$file_folder_fixed);
156
+	protected function _set_file_url() {
157
+		$plugins_dir_fixed = str_replace('\\', DS, WP_PLUGIN_DIR);
158
+		$file_folder_fixed = str_replace('\\', DS, $this->file_folder());
159
+		$file_path = str_replace($plugins_dir_fixed, WP_PLUGIN_URL, $file_folder_fixed);
160 160
 		$this->_file_url = $file_path;
161 161
 	}
162 162
 
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
 	 * Gets the default description on all payment methods of this type
165 165
 	 * @return string
166 166
 	 */
167
-	public function default_description(){
167
+	public function default_description() {
168 168
 		return $this->_default_description;
169 169
 	}
170 170
 
@@ -174,8 +174,8 @@  discard block
 block discarded – undo
174 174
 	 * Returns the folder containing the PMT child class, with a trailing slash
175 175
 	 * @return string
176 176
 	 */
177
-	public function file_folder(){
178
-		if( ! $this->_file_folder ) {
177
+	public function file_folder() {
178
+		if ( ! $this->_file_folder) {
179 179
 			$this->_set_file_folder();
180 180
 		}
181 181
 		return $this->_file_folder;
@@ -186,8 +186,8 @@  discard block
 block discarded – undo
186 186
 	/**
187 187
 	 * @return string
188 188
 	 */
189
-	public function file_url(){
190
-		if( ! $this->_file_url ) {
189
+	public function file_url() {
190
+		if ( ! $this->_file_url) {
191 191
 			$this->_set_file_url();
192 192
 		}
193 193
 		return $this->_file_url;
@@ -200,14 +200,14 @@  discard block
 block discarded – undo
200 200
 	 * Its important teh payment method instance is set before
201 201
 	 * @param EE_Payment_Method $payment_method_instance
202 202
 	 */
203
-	function set_instance($payment_method_instance){
203
+	function set_instance($payment_method_instance) {
204 204
 		$this->_pm_instance = $payment_method_instance;
205 205
 		//if they have already requested the settings form, make sure its
206 206
 		//data matches this model object
207
-		if($this->_settings_form){
207
+		if ($this->_settings_form) {
208 208
 			$this->settings_form()->populate_model_obj($payment_method_instance);
209 209
 		}
210
-		if($this->_gateway && $this->_gateway instanceof EE_Gateway){
210
+		if ($this->_gateway && $this->_gateway instanceof EE_Gateway) {
211 211
 			$this->_gateway->set_settings($payment_method_instance->settings_array());
212 212
 		}
213 213
 	}
@@ -218,13 +218,13 @@  discard block
 block discarded – undo
218 218
 	 * Gets teh form for displaying to admins where they setup the payment method
219 219
 	 * @return EE_Payment_Method_Form
220 220
 	 */
221
-	function settings_form(){
222
-		if( ! $this->_settings_form){
221
+	function settings_form() {
222
+		if ( ! $this->_settings_form) {
223 223
 			$this->_settings_form = $this->generate_new_settings_form();
224
-			$this->_settings_form->set_payment_method_type( $this );
224
+			$this->_settings_form->set_payment_method_type($this);
225 225
 			//if we have already assigned a model object to this pmt, make
226 226
 			//sure its reflected in teh form we just generated
227
-			if($this->_pm_instance){
227
+			if ($this->_pm_instance) {
228 228
 				$this->_settings_form->populate_model_obj($this->_pm_instance);
229 229
 			}
230 230
 		}
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
 	 * this payment method type's settings form later in the request
251 251
 	 * @param EE_Payment_Method_Form $form
252 252
 	 */
253
-	public function set_settings_form($form){
253
+	public function set_settings_form($form) {
254 254
 		$this->_settings_form = $form;
255 255
 	}
256 256
 
@@ -273,10 +273,10 @@  discard block
 block discarded – undo
273 273
 	 * @param array $extra_args
274 274
 	 * @return \EE_Billing_Attendee_Info_Form|\EE_Billing_Info_Form|null
275 275
 	 */
276
-	public function billing_form( EE_Transaction $transaction = NULL, $extra_args = array() ){
276
+	public function billing_form(EE_Transaction $transaction = NULL, $extra_args = array()) {
277 277
 		// has billing form already been regenerated ? or overwrite cache?
278
-		if ( ! $this->_billing_form instanceof EE_Billing_Info_Form || ! $this->_cache_billing_form ){
279
-			$this->_billing_form = $this->generate_new_billing_form( $transaction, $extra_args );
278
+		if ( ! $this->_billing_form instanceof EE_Billing_Info_Form || ! $this->_cache_billing_form) {
279
+			$this->_billing_form = $this->generate_new_billing_form($transaction, $extra_args);
280 280
 		}
281 281
 		//if we know who the attendee is, and this is a billing form
282 282
 		//that uses attendee info, populate it
@@ -292,8 +292,8 @@  discard block
 block discarded – undo
292 292
                 $this->_billing_form,
293 293
                 $transaction
294 294
             )
295
-		){
296
-			$this->_billing_form->populate_from_attendee( $transaction->primary_registration()->attendee() );
295
+		) {
296
+			$this->_billing_form->populate_from_attendee($transaction->primary_registration()->attendee());
297 297
 		}
298 298
 		return $this->_billing_form;
299 299
 	}
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
 	 * @param \EE_Transaction $transaction
305 305
 	 * @return \EE_Billing_Info_Form
306 306
 	 */
307
-	abstract function generate_new_billing_form( EE_Transaction $transaction = NULL );
307
+	abstract function generate_new_billing_form(EE_Transaction $transaction = NULL);
308 308
 
309 309
 
310 310
 
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
 	 * @param \EE_Billing_Info_Form $billing_form
316 316
 	 * @return \EE_Billing_Info_Form
317 317
 	 */
318
-	public function apply_billing_form_debug_settings( EE_Billing_Info_Form $billing_form ) {
318
+	public function apply_billing_form_debug_settings(EE_Billing_Info_Form $billing_form) {
319 319
 		return $billing_form;
320 320
 	}
321 321
 
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
 	 * if you have form
327 327
 	 * @param EE_Payment_Method $form
328 328
 	 */
329
-	public function set_billing_form($form){
329
+	public function set_billing_form($form) {
330 330
 		$this->_billing_form = $form;
331 331
 	}
332 332
 
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
 	 * Returns whether or not this payment method requires HTTPS to be used
337 337
 	 * @return boolean
338 338
 	 */
339
-	function requires_https(){
339
+	function requires_https() {
340 340
 		return $this->_requires_https;
341 341
 	}
342 342
 
@@ -354,9 +354,9 @@  discard block
 block discarded – undo
354 354
 	 * @return EE_Payment
355 355
 	 * @throws EE_Error
356 356
 	 */
357
-	function process_payment( EE_Transaction $transaction, $amount = null, $billing_info = null, $return_url = null,$fail_url = '', $method = 'CART', $by_admin = false ){
357
+	function process_payment(EE_Transaction $transaction, $amount = null, $billing_info = null, $return_url = null, $fail_url = '', $method = 'CART', $by_admin = false) {
358 358
 		// @todo: add surcharge for the payment method, if any
359
-		if ( $this->_gateway ) {
359
+		if ($this->_gateway) {
360 360
 			//there is a gateway, so we're going to make a payment object
361 361
 			//but wait! do they already have a payment in progress that we thought was failed?
362 362
 			$duplicate_properties = array(
@@ -367,10 +367,10 @@  discard block
 block discarded – undo
367 367
 				'PAY_amount' 					=> $amount !== null ? $amount : $transaction->remaining(),
368 368
 				'PAY_gateway_response' 	=> null,
369 369
 			);
370
-			$payment = EEM_Payment::instance()->get_one( array( $duplicate_properties ));
370
+			$payment = EEM_Payment::instance()->get_one(array($duplicate_properties));
371 371
 			//if we didn't already have a payment in progress for the same thing,
372 372
 			//then we actually want to make a new payment
373
-			if ( ! $payment instanceof EE_Payment ){
373
+			if ( ! $payment instanceof EE_Payment) {
374 374
 				$payment = EE_Payment::new_instance(
375 375
 					array_merge(
376 376
 						$duplicate_properties,
@@ -386,10 +386,10 @@  discard block
 block discarded – undo
386 386
 			}
387 387
 			//make sure the payment has been saved to show we started it, and so it has an ID should the gateway try to log it
388 388
 			$payment->save();
389
-			$billing_values = $this->_get_billing_values_from_form( $billing_info );
389
+			$billing_values = $this->_get_billing_values_from_form($billing_info);
390 390
 
391 391
 			//  Offsite Gateway
392
-			if( $this->_gateway instanceof EE_Offsite_Gateway ){
392
+			if ($this->_gateway instanceof EE_Offsite_Gateway) {
393 393
 
394 394
 				$payment = $this->_gateway->set_redirection_info(
395 395
 					$payment,
@@ -405,17 +405,17 @@  discard block
 block discarded – undo
405 405
 				);
406 406
 				$payment->save();
407 407
 			//  Onsite Gateway
408
-			} elseif ( $this->_gateway instanceof EE_Onsite_Gateway ) {
408
+			} elseif ($this->_gateway instanceof EE_Onsite_Gateway) {
409 409
 
410
-				$payment = $this->_gateway->do_direct_payment($payment,$billing_values);
410
+				$payment = $this->_gateway->do_direct_payment($payment, $billing_values);
411 411
 				$payment->save();
412 412
 
413 413
 			} else {
414 414
 				throw new EE_Error(
415 415
 					sprintf(
416
-						__('Gateway for payment method type "%s" is "%s", not a subclass of either EE_Offsite_Gateway or EE_Onsite_Gateway, or null (to indicate NO gateway)', 'event_espresso' ),
416
+						__('Gateway for payment method type "%s" is "%s", not a subclass of either EE_Offsite_Gateway or EE_Onsite_Gateway, or null (to indicate NO gateway)', 'event_espresso'),
417 417
 						get_class($this),
418
-						gettype( $this->_gateway )
418
+						gettype($this->_gateway)
419 419
 					)
420 420
 				);
421 421
 			}
@@ -437,8 +437,8 @@  discard block
 block discarded – undo
437 437
 		}
438 438
 
439 439
 		// if there is billing info, clean it and save it now
440
-		if( $billing_info instanceof EE_Billing_Attendee_Info_Form ){
441
-			$this->_save_billing_info_to_attendee( $billing_info, $transaction );
440
+		if ($billing_info instanceof EE_Billing_Attendee_Info_Form) {
441
+			$this->_save_billing_info_to_attendee($billing_info, $transaction);
442 442
 		}
443 443
 
444 444
 		return $payment;
@@ -451,10 +451,10 @@  discard block
 block discarded – undo
451 451
 	 * @param EE_Billing_Info_Form $billing_form
452 452
 	 * @return array
453 453
 	 */
454
-	protected function _get_billing_values_from_form( $billing_form ){
455
-		if($billing_form instanceof EE_Form_Section_Proper ){
456
-			return $billing_form->input_pretty_values( true );
457
-		}else{
454
+	protected function _get_billing_values_from_form($billing_form) {
455
+		if ($billing_form instanceof EE_Form_Section_Proper) {
456
+			return $billing_form->input_pretty_values(true);
457
+		} else {
458 458
 			return NULL;
459 459
 		}
460 460
 	}
@@ -468,13 +468,13 @@  discard block
 block discarded – undo
468 468
 	 * @return EE_Payment
469 469
 	 * @throws EE_Error
470 470
 	 */
471
-	public function handle_ipn($req_data,$transaction){
471
+	public function handle_ipn($req_data, $transaction) {
472 472
 		$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
473
-		if( ! $this->_gateway instanceof EE_Offsite_Gateway){
474
-			throw new EE_Error(sprintf(__("Could not handle IPN because '%s' is not an offsite gateway", "event_espresso"), print_r( $this->_gateway, TRUE )));
473
+		if ( ! $this->_gateway instanceof EE_Offsite_Gateway) {
474
+			throw new EE_Error(sprintf(__("Could not handle IPN because '%s' is not an offsite gateway", "event_espresso"), print_r($this->_gateway, TRUE)));
475 475
 
476 476
 		}
477
-		$payment = $this->_gateway->handle_payment_update( $req_data, $transaction );
477
+		$payment = $this->_gateway->handle_payment_update($req_data, $transaction);
478 478
 		return $payment;
479 479
 	}
480 480
 
@@ -487,22 +487,22 @@  discard block
 block discarded – undo
487 487
 	 * @param EE_Transaction $transaction
488 488
 	 * @return boolean success
489 489
 	 */
490
-	protected function _save_billing_info_to_attendee($billing_form, $transaction){
491
-		if( ! $transaction || ! $transaction instanceof EE_Transaction){
490
+	protected function _save_billing_info_to_attendee($billing_form, $transaction) {
491
+		if ( ! $transaction || ! $transaction instanceof EE_Transaction) {
492 492
 			EE_Error::add_error(__("Cannot save billing info because no transaction was specified", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
493 493
 			return false;
494 494
 		}
495 495
 		$primary_reg = $transaction->primary_registration();
496
-		if( ! $primary_reg ){
496
+		if ( ! $primary_reg) {
497 497
 			EE_Error::add_error(__("Cannot save billing info because the transaction has no primary registration", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
498 498
 			return false;
499 499
 		}
500 500
 		$attendee = $primary_reg->attendee();
501
-		if( ! $attendee ){
501
+		if ( ! $attendee) {
502 502
 			EE_Error::add_error(__("Cannot save billing info because the transaction's primary registration has no attendee!", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
503 503
 			return false;
504 504
 		}
505
-		return $attendee->save_and_clean_billing_info_for_payment_method($billing_form, $transaction->payment_method() );
505
+		return $attendee->save_and_clean_billing_info_for_payment_method($billing_form, $transaction->payment_method());
506 506
 
507 507
 	}
508 508
 
@@ -515,7 +515,7 @@  discard block
 block discarded – undo
515 515
 	 * @param array $req_data
516 516
 	 * @return EE_Payment
517 517
 	 */
518
-	protected function find_payment_for_ipn( EE_Transaction $transaction, $req_data = array() ){
518
+	protected function find_payment_for_ipn(EE_Transaction $transaction, $req_data = array()) {
519 519
 		return $transaction->last_payment();
520 520
 	}
521 521
 
@@ -532,8 +532,8 @@  discard block
 block discarded – undo
532 532
 	 * and identifies the IPN as being for this payment method (not just fo ra payment method of this type)
533 533
 	 * @throws EE_Error
534 534
 	 */
535
-	public function handle_unclaimed_ipn( $req_data = array() ){
536
-		throw new EE_Error(sprintf(__("Payment Method '%s' cannot handle unclaimed IPNs", "event_espresso"), get_class($this) ));
535
+	public function handle_unclaimed_ipn($req_data = array()) {
536
+		throw new EE_Error(sprintf(__("Payment Method '%s' cannot handle unclaimed IPNs", "event_espresso"), get_class($this)));
537 537
 	}
538 538
 
539 539
 
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
 	 * @param EE_Transaction $transaction
550 550
 	 * @return EE_Payment
551 551
 	 */
552
-	public function finalize_payment_for($transaction){
552
+	public function finalize_payment_for($transaction) {
553 553
 		return $transaction->last_payment();
554 554
 	}
555 555
 
@@ -559,10 +559,10 @@  discard block
 block discarded – undo
559 559
 	 * Whether or not this payment method's gateway supports sending refund requests
560 560
 	 * @return boolean
561 561
 	 */
562
-	public function supports_sending_refunds(){
563
-		if($this->_gateway && $this->_gateway instanceof EE_Gateway){
562
+	public function supports_sending_refunds() {
563
+		if ($this->_gateway && $this->_gateway instanceof EE_Gateway) {
564 564
 			return $this->_gateway->supports_sending_refunds();
565
-		}else{
565
+		} else {
566 566
 			return false;
567 567
 		}
568 568
 	}
@@ -576,14 +576,14 @@  discard block
 block discarded – undo
576 576
 	 * @throws EE_Error
577 577
 	 * @return EE_Payment
578 578
 	 */
579
-	public function process_refund( EE_Payment $payment, $refund_info = array()){
580
-		if ( $this->_gateway && $this->_gateway instanceof EE_Gateway ) {
581
-			return $this->_gateway->do_direct_refund( $payment, $refund_info );
579
+	public function process_refund(EE_Payment $payment, $refund_info = array()) {
580
+		if ($this->_gateway && $this->_gateway instanceof EE_Gateway) {
581
+			return $this->_gateway->do_direct_refund($payment, $refund_info);
582 582
 		} else {
583 583
 			throw new EE_Error(
584 584
 				sprintf(
585
-					__( 'Payment Method Type "%s" does not support sending refund requests', 'event_espresso' ),
586
-					get_class( $this )
585
+					__('Payment Method Type "%s" does not support sending refund requests', 'event_espresso'),
586
+					get_class($this)
587 587
 				)
588 588
 			);
589 589
 		}
@@ -597,15 +597,15 @@  discard block
 block discarded – undo
597 597
 	 * @return string
598 598
 	 * @throws EE_Error
599 599
 	 */
600
-	public function payment_occurs(){
601
-		if( ! $this->_gateway){
600
+	public function payment_occurs() {
601
+		if ( ! $this->_gateway) {
602 602
 			return EE_PMT_Base::offline;
603
-		}elseif($this->_gateway instanceof EE_Onsite_Gateway){
603
+		}elseif ($this->_gateway instanceof EE_Onsite_Gateway) {
604 604
 			return EE_PMT_Base::onsite;
605
-		}elseif($this->_gateway instanceof EE_Offsite_Gateway){
605
+		}elseif ($this->_gateway instanceof EE_Offsite_Gateway) {
606 606
 			return EE_PMT_Base::offsite;
607
-		}else{
608
-			throw new EE_Error(sprintf(__("Payment method type '%s's gateway isn't an instance of EE_Onsite_Gateway, EE_Offsite_Gateway, or null. It must be one of those", "event_espresso"),get_class($this)));
607
+		} else {
608
+			throw new EE_Error(sprintf(__("Payment method type '%s's gateway isn't an instance of EE_Onsite_Gateway, EE_Offsite_Gateway, or null. It must be one of those", "event_espresso"), get_class($this)));
609 609
 		}
610 610
 	}
611 611
 
@@ -618,8 +618,8 @@  discard block
 block discarded – undo
618 618
 	 * @param EE_Payment $payment
619 619
 	 * @return string
620 620
 	 */
621
-	public function payment_overview_content(EE_Payment $payment){
622
-		return EEH_Template::display_template(EE_LIBRARIES.'payment_methods'.DS.'templates'.DS.'payment_details_content.template.php', array('payment_method'=>$this->_pm_instance,'payment'=>$payment) , true);
621
+	public function payment_overview_content(EE_Payment $payment) {
622
+		return EEH_Template::display_template(EE_LIBRARIES.'payment_methods'.DS.'templates'.DS.'payment_details_content.template.php', array('payment_method'=>$this->_pm_instance, 'payment'=>$payment), true);
623 623
 	}
624 624
 
625 625
 
@@ -632,7 +632,7 @@  discard block
 block discarded – undo
632 632
 	 *	@type array $template_args any arguments you want passed to the template file while rendering.
633 633
 	 *				Keys will be variable names and values with be their values.
634 634
 	 */
635
-	public function help_tabs_config(){
635
+	public function help_tabs_config() {
636 636
 		return array();
637 637
 	}
638 638
 
@@ -643,9 +643,9 @@  discard block
 block discarded – undo
643 643
 	 * the payment method's table's PMT_type column)
644 644
 	 * @return string
645 645
 	 */
646
-	public function system_name(){
646
+	public function system_name() {
647 647
 		$classname = get_class($this);
648
-		return str_replace("EE_PMT_",'',$classname);
648
+		return str_replace("EE_PMT_", '', $classname);
649 649
 	}
650 650
 
651 651
 
@@ -654,7 +654,7 @@  discard block
 block discarded – undo
654 654
 	 * A pretty i18n version of the PMT name
655 655
 	 * @return string
656 656
 	 */
657
-	public function pretty_name(){
657
+	public function pretty_name() {
658 658
 		return $this->_pretty_name;
659 659
 	}
660 660
 
@@ -664,7 +664,7 @@  discard block
 block discarded – undo
664 664
 	 * Gets the default absolute URL to the payment method type's button
665 665
 	 * @return string
666 666
 	 */
667
-	public function default_button_url(){
667
+	public function default_button_url() {
668 668
 		return $this->_default_button_url;
669 669
 	}
670 670
 
@@ -674,7 +674,7 @@  discard block
 block discarded – undo
674 674
 	 * Gets the gateway used by this payment method (if any)
675 675
 	 * @return EE_Gateway
676 676
 	 */
677
-	public function get_gateway(){
677
+	public function get_gateway() {
678 678
 		return $this->_gateway;
679 679
 	}
680 680
 
@@ -683,8 +683,8 @@  discard block
 block discarded – undo
683 683
 	/**
684 684
 	 * @return string html for the link to a help tab
685 685
 	 */
686
-	public function get_help_tab_link(){
687
-		return EEH_Template::get_help_tab_link( $this->get_help_tab_name() );
686
+	public function get_help_tab_link() {
687
+		return EEH_Template::get_help_tab_link($this->get_help_tab_name());
688 688
 	}
689 689
 
690 690
 
@@ -693,8 +693,8 @@  discard block
 block discarded – undo
693 693
 	 * Returns the name of the help tab for this PMT
694 694
 	 * @return string
695 695
 	 */
696
-	public function get_help_tab_name(){
697
-		return 'ee_' . strtolower( $this->system_name() ) . '_help_tab';
696
+	public function get_help_tab_name() {
697
+		return 'ee_'.strtolower($this->system_name()).'_help_tab';
698 698
 	}
699 699
 
700 700
 	/**
@@ -702,8 +702,8 @@  discard block
 block discarded – undo
702 702
 	 * this PMT by an admin
703 703
 	 * @return string
704 704
 	 */
705
-	public function cap_name(){
706
-		return 'ee_payment_method_' . strtolower( $this->system_name() );
705
+	public function cap_name() {
706
+		return 'ee_payment_method_'.strtolower($this->system_name());
707 707
 	}
708 708
 
709 709
 	/**
@@ -715,9 +715,9 @@  discard block
 block discarded – undo
715 715
 	 * @param EE_Payment $payment
716 716
 	 * @return void
717 717
 	 */
718
-	public function update_txn_based_on_payment( $payment ){
719
-		if( $this->_gateway instanceof EE_Gateway ){
720
-			$this->_gateway->update_txn_based_on_payment( $payment );
718
+	public function update_txn_based_on_payment($payment) {
719
+		if ($this->_gateway instanceof EE_Gateway) {
720
+			$this->_gateway->update_txn_based_on_payment($payment);
721 721
 		}
722 722
 	}
723 723
 
@@ -732,7 +732,7 @@  discard block
 block discarded – undo
732 732
 	 * @return string
733 733
 	 */
734 734
 	public function introductory_html() {
735
-		return EEH_Template::locate_template( $this->file_folder() . 'templates' . DS . strtolower( $this->system_name() ) . '_intro.template.php', array( 'pmt_obj' => $this, 'pm_instance' => $this->_pm_instance ) );
735
+		return EEH_Template::locate_template($this->file_folder().'templates'.DS.strtolower($this->system_name()).'_intro.template.php', array('pmt_obj' => $this, 'pm_instance' => $this->_pm_instance));
736 736
 	}
737 737
 
738 738
 
Please login to merge, or discard this patch.
modules/ticket_selector/TicketSelectorRowStandard.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -232,7 +232,7 @@
 block discarded – undo
232 232
      * setTicketMinAndMax
233 233
      *
234 234
      * @param int $remaining
235
-     * @return array
235
+     * @return integer[]
236 236
      * @throws EE_Error
237 237
      */
238 238
     protected function setTicketMinAndMax($remaining)
Please login to merge, or discard this patch.
Indentation   +398 added lines, -398 removed lines patch added patch discarded remove patch
@@ -19,404 +19,404 @@
 block discarded – undo
19 19
 class TicketSelectorRowStandard extends TicketSelectorRow
20 20
 {
21 21
 
22
-    /**
23
-     * @var TicketDetails $ticket_details
24
-     */
25
-    protected $ticket_details;
26
-
27
-    /**
28
-     * @var \EE_Ticket_Selector_Config $template_settings
29
-     */
30
-    protected $template_settings;
31
-
32
-    /**
33
-     * @var \EE_Tax_Config $tax_settings
34
-     */
35
-    protected $tax_settings;
36
-
37
-    /**
38
-     * @var boolean $prices_displayed_including_taxes
39
-     */
40
-    protected $prices_displayed_including_taxes;
41
-
42
-    /**
43
-     * @var int $row
44
-     */
45
-    protected $row;
46
-
47
-    /**
48
-     * @var int $cols
49
-     */
50
-    protected $cols;
51
-
52
-    /**
53
-     * @var boolean $hidden_input_qty
54
-     */
55
-    protected $hidden_input_qty;
56
-
57
-    /**
58
-     * @var string $ticket_datetime_classes
59
-     */
60
-    protected $ticket_datetime_classes;
61
-
62
-
63
-
64
-    /**
65
-     * TicketDetails constructor.
66
-     *
67
-     * @param TicketDetails  $ticket_details
68
-     * @param \EE_Tax_Config $tax_settings
69
-     * @param int            $total_tickets
70
-     * @param int            $max_atndz
71
-     * @param int            $row
72
-     * @param int            $cols
73
-     * @param boolean        $required_ticket_sold_out
74
-     * @param string         $event_status
75
-     * @param string         $ticket_datetime_classes
76
-     * @throws EE_Error
77
-     * @throws UnexpectedEntityException
78
-     */
79
-    public function __construct(
80
-        TicketDetails $ticket_details,
81
-        \EE_Tax_Config $tax_settings,
82
-        $total_tickets,
83
-        $max_atndz,
84
-        $row,
85
-        $cols,
86
-        $required_ticket_sold_out,
87
-        $event_status,
88
-        $ticket_datetime_classes
89
-    ) {
90
-        $this->ticket = $ticket_details->getTicket();
91
-        $this->ticket_details = $ticket_details;
92
-        $this->template_settings = $ticket_details->getTemplateSettings();
93
-        $this->tax_settings = $tax_settings;
94
-        $this->total_tickets = $total_tickets;
95
-        $this->max_atndz = $max_atndz;
96
-        $this->row = $row;
97
-        $this->cols = $cols;
98
-        $this->date_format = $ticket_details->getDateFormat();
99
-        $this->ticket_datetime_classes = $ticket_datetime_classes;
100
-        parent::__construct($this->ticket, $max_atndz, $this->date_format, $event_status, $required_ticket_sold_out);
101
-    }
102
-
103
-
104
-
105
-    /**
106
-     * other ticket rows will need to know if a required ticket is sold out,
107
-     * so that they are not offered for sale
108
-     *
109
-     * @return boolean
110
-     */
111
-    public function getRequiredTicketSoldOut()
112
-    {
113
-        return $this->required_ticket_sold_out;
114
-    }
115
-
116
-
117
-
118
-    /**
119
-     * @return int
120
-     */
121
-    public function getCols()
122
-    {
123
-        return $this->cols;
124
-    }
125
-
126
-
127
-
128
-    /**
129
-     * getHtml
130
-     *
131
-     * @return string
132
-     * @throws EE_Error
133
-     */
134
-    public function getHtml()
135
-    {
136
-        $min = 0;
137
-        $max = $this->ticket->max();
138
-        $remaining = $this->ticket->remaining();
139
-        if ($this->ticket->is_on_sale() && $this->ticket->is_remaining()) {
140
-            list($min, $max) = $this->setTicketMinAndMax($remaining);
141
-        } else {
142
-            // set flag if ticket is required (flag is set to start date so that future tickets are not blocked)
143
-            $this->required_ticket_sold_out = $this->ticket->required() && ! $remaining
144
-                ? $this->ticket->start_date()
145
-                : $this->required_ticket_sold_out;
146
-        }
147
-        list($ticket_price, $ticket_bundle) = $this->getTicketPriceDetails();
148
-        list($tkt_status, $ticket_status, $status_class) = $this->getTicketStatusClasses($remaining);
149
-        /**
150
-         * Allow plugins to hook in and abort the generation and display of this row to do
151
-         * something else if they want.
152
-         * For an addon to abort things, all they have to do is register a filter with this hook, and
153
-         * return a value that is NOT false.  Whatever is returned gets echoed instead of the
154
-         * current row.
155
-         *
156
-         * @var string|bool
157
-         */
158
-        $ticket_selector_row_html = apply_filters(
159
-            'FHEE__ticket_selector_chart_template__do_ticket_entire_row',
160
-            false,
161
-            $this->ticket,
162
-            $max,
163
-            $min,
164
-            $this->required_ticket_sold_out,
165
-            $ticket_price,
166
-            $ticket_bundle,
167
-            $ticket_status,
168
-            $status_class
169
-        );
170
-        if ($ticket_selector_row_html !== false) {
171
-            return $ticket_selector_row_html;
172
-        }
173
-        $ticket_selector_row_html = \EEH_HTML::tr(
174
-            '', '',
175
-            "tckt-slctr-tbl-tr {$status_class}{$this->ticket_datetime_classes} " . espresso_get_object_css_class($this->ticket)
176
-        );
177
-        /**
178
-         * Allow plugins to hook in and abort the generation and display of the contents of this
179
-         * row to do something else if they want.
180
-         * For an addon to abort things, all they have to do is register a filter with this hook, and
181
-         * return a value that is NOT false.  Whatever is returned gets echoed instead of the
182
-         * current row.
183
-         *
184
-         * @var string|bool
185
-         */
186
-        $new_row_cells_content = apply_filters(
187
-            'FHEE__ticket_selector_chart_template__do_ticket_inside_row',
188
-            false,
189
-            $this->ticket,
190
-            $max,
191
-            $min,
192
-            $this->required_ticket_sold_out,
193
-            $ticket_price,
194
-            $ticket_bundle,
195
-            $ticket_status,
196
-            $status_class
197
-        );
198
-        if ($new_row_cells_content !== false && $this->max_atndz === 1) {
199
-            return $ticket_selector_row_html
200
-                   . $new_row_cells_content
201
-                   . $this->ticketQtyAndIdHiddenInputs()
202
-                   . \EEH_HTML::trx();
203
-        }
204
-        if ($new_row_cells_content !== false) {
205
-            return $ticket_selector_row_html
206
-                   . $new_row_cells_content
207
-                   . \EEH_HTML::trx();
208
-        }
209
-        $this->hidden_input_qty = $this->max_atndz > 1 ? true : false;
210
-
211
-        $ticket_selector_row_html .= $this->ticketNameTableCell();
212
-        $ticket_selector_row_html .= $this->ticketPriceTableCell($ticket_price, $ticket_bundle);
213
-        $ticket_selector_row_html .= \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-qty cntr');
214
-        $this->setTicketStatusDisplay($tkt_status, $ticket_status, $remaining);
215
-        if (empty($this->ticket_status_display)) {
216
-            if ($this->max_atndz === 1) {
217
-                // only ONE attendee is allowed to register at a time
218
-                $ticket_selector_row_html .= $this->onlyOneAttendeeCanRegister();
219
-            } else if ($max > 0) {
220
-                $ticket_selector_row_html .= $this->ticketQuantitySelector($min, $max);
221
-            }
222
-        }
223
-        $ticket_selector_row_html .= $this->ticket_status_display;
224
-        $ticket_selector_row_html .= $this->ticketQtyAndIdHiddenInputs();
225
-        $ticket_selector_row_html .= $this->ticket_details->display($ticket_price, $remaining, $this->cols);
226
-        $ticket_selector_row_html .= \EEH_HTML::tdx();
227
-        $ticket_selector_row_html .= \EEH_HTML::trx();
228
-
229
-
230
-        $this->row++;
231
-        return $ticket_selector_row_html;
232
-    }
233
-
234
-
235
-
236
-    /**
237
-     * setTicketMinAndMax
238
-     *
239
-     * @param int $remaining
240
-     * @return array
241
-     * @throws EE_Error
242
-     */
243
-    protected function setTicketMinAndMax($remaining)
244
-    {
245
-        // offer the number of $tickets_remaining or $this->max_atndz, whichever is smaller
246
-        $max = min($remaining, $this->max_atndz);
247
-        // but... we also want to restrict the number of tickets by the ticket max setting,
248
-        // however, the max still can't be higher than what was just set above
249
-        $max = $this->ticket->max() > 0 ? min($this->ticket->max(), $max) : $max;
250
-        // and we also want to restrict the minimum number of tickets by the ticket min setting
251
-        $min = $this->ticket->min() > 0 ? $this->ticket->min() : 0;
252
-        // and if the ticket is required, then make sure that min qty is at least 1
253
-        $min = $this->ticket->required() ? max($min, 1) : $min;
254
-        return array($min, $max);
255
-    }
256
-
257
-
258
-
259
-    /**
260
-     * getTicketPriceDetails
261
-     *
262
-     * @return array
263
-     * @throws EE_Error
264
-     */
265
-    protected function getTicketPriceDetails()
266
-    {
267
-        $ticket_price = $this->tax_settings->prices_displayed_including_taxes
268
-            ? $this->ticket->get_ticket_total_with_taxes()
269
-            : $this->ticket->get_ticket_subtotal();
270
-        $ticket_bundle = false;
271
-        $ticket_min = $this->ticket->min();
272
-        // for ticket bundles, set min and max qty the same
273
-        if ($ticket_min !== 0 && $ticket_min === $this->ticket->max()) {
274
-            $ticket_price *= $ticket_min;
275
-            $ticket_bundle = true;
276
-        }
277
-        $ticket_price = apply_filters(
278
-            'FHEE__ticket_selector_chart_template__ticket_price',
279
-            $ticket_price,
280
-            $this->ticket
281
-        );
282
-        return array($ticket_price, $ticket_bundle);
283
-    }
284
-
285
-
286
-
287
-
288
-    /**
289
-     * ticketNameTableCell
290
-     *
291
-     * @return string
292
-     * @throws EE_Error
293
-     */
294
-    protected function ticketNameTableCell()
295
-    {
296
-        $html = \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-name');
297
-        $html .= \EEH_HTML::strong($this->ticket->get_pretty('TKT_name'));
298
-        $html .= $this->ticket_details->getShowHideLinks();
299
-        if ($this->ticket->required()) {
300
-            $html .= \EEH_HTML::p(
301
-                    apply_filters(
302
-                            'FHEE__ticket_selector_chart_template__ticket_required_message',
303
-                            esc_html__('This ticket is required and must be purchased.', 'event_espresso')
304
-                    ),
305
-                    '', 'ticket-required-pg'
306
-            );
307
-        }
308
-        $html .= \EEH_HTML::tdx();
309
-        return $html;
310
-    }
311
-
312
-
313
-
314
-    /**
315
-     * ticketPriceTableCell
316
-     *
317
-     * @param float $ticket_price
318
-     * @param bool  $ticket_bundle
319
-     * @return string
320
-     * @throws EE_Error
321
-     */
322
-    protected function ticketPriceTableCell($ticket_price, $ticket_bundle)
323
-    {
324
-        $html = '';
325
-        if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) {
326
-            $html .= \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-price jst-rght');
327
-            $html .= \EEH_Template::format_currency($ticket_price);
328
-            $html .= $this->ticket->taxable()
329
-                ? \EEH_HTML::span( '*', '', 'taxable-tickets-asterisk grey-text' )
330
-                : '';
331
-            $html .= '&nbsp;';
332
-            $html .= \EEH_HTML::span(
333
-                $ticket_bundle
334
-                    ? apply_filters(
335
-                        'FHEE__ticket_selector_chart_template__per_ticket_bundle_text',
336
-                        __(' / bundle', 'event_espresso')
337
-                    )
338
-                    : apply_filters(
339
-                        'FHEE__ticket_selector_chart_template__per_ticket_text',
340
-                        __('', 'event_espresso')
341
-                    ),
342
-                '', 'smaller-text no-bold'
343
-            );
344
-            $html .= '&nbsp;';
345
-            $html .= \EEH_HTML::tdx();
346
-            $this->cols++;
347
-        }
348
-        return $html;
349
-    }
350
-
351
-
352
-
353
-    /**
354
-     * onlyOneAttendeeCanRegister
355
-     *
356
-     * @return string
357
-     */
358
-    protected function onlyOneAttendeeCanRegister()
359
-    {
360
-        // display submit button since we have tickets available
361
-        add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
362
-        $this->hidden_input_qty = false;
363
-        $html = '<input type="radio" name="tkt-slctr-qty-' . $this->EVT_ID . '"';
364
-        $html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"';
365
-        $html .= ' class="ticket-selector-tbl-qty-slct" value="' . $this->row . '-1"';
366
-        $html .= $this->total_tickets === 1 ? ' checked="checked"' : '';
367
-        $html .= ' title=""/>';
368
-        return $html;
369
-    }
370
-
371
-
372
-
373
-    /**
374
-     * ticketQuantitySelector
375
-     *
376
-     * @param int $min
377
-     * @param int $max
378
-     * @return string
379
-     * @throws EE_Error
380
-     */
381
-    protected function ticketQuantitySelector($min = 0, $max = 0)
382
-    {
383
-        // display submit button since we have tickets available
384
-        add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
385
-        $this->hidden_input_qty = false;
386
-        $html = '<select name="tkt-slctr-qty-' . $this->EVT_ID . '[]"';
387
-        $html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"';
388
-        $html .= ' class="ticket-selector-tbl-qty-slct">';
389
-        // this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased
390
-        if ($min !== 0 && ! $this->ticket->required()) {
391
-            $html .= '<option value="0">&nbsp;0&nbsp;</option>';
392
-        }
393
-        // offer ticket quantities from the min to the max
394
-        for ($i = $min; $i <= $max; $i++) {
395
-            $html .= '<option value="' . $i . '">&nbsp;' . $i . '&nbsp;</option>';
396
-        }
397
-        $html .= '</select>';
398
-        return $html;
399
-    }
400
-
401
-
402
-
403
-    /**
404
-     * getHiddenInputs
405
-     *
406
-     * @return string
407
-     * @throws EE_Error
408
-     */
409
-    protected function ticketQtyAndIdHiddenInputs()
410
-    {
411
-        $html = '';
412
-        // depending on group reg we need to change the format for qty
413
-        if ($this->hidden_input_qty) {
414
-            $html .= '<input type="hidden" name="tkt-slctr-qty-' . $this->EVT_ID . '[]" value="0"/>';
415
-        }
416
-        $html .= '<input type="hidden" name="tkt-slctr-ticket-id-' . $this->EVT_ID . '[]"';
417
-        $html .= ' value="' . $this->ticket->ID() . '"/>';
418
-        return $html;
419
-    }
22
+	/**
23
+	 * @var TicketDetails $ticket_details
24
+	 */
25
+	protected $ticket_details;
26
+
27
+	/**
28
+	 * @var \EE_Ticket_Selector_Config $template_settings
29
+	 */
30
+	protected $template_settings;
31
+
32
+	/**
33
+	 * @var \EE_Tax_Config $tax_settings
34
+	 */
35
+	protected $tax_settings;
36
+
37
+	/**
38
+	 * @var boolean $prices_displayed_including_taxes
39
+	 */
40
+	protected $prices_displayed_including_taxes;
41
+
42
+	/**
43
+	 * @var int $row
44
+	 */
45
+	protected $row;
46
+
47
+	/**
48
+	 * @var int $cols
49
+	 */
50
+	protected $cols;
51
+
52
+	/**
53
+	 * @var boolean $hidden_input_qty
54
+	 */
55
+	protected $hidden_input_qty;
56
+
57
+	/**
58
+	 * @var string $ticket_datetime_classes
59
+	 */
60
+	protected $ticket_datetime_classes;
61
+
62
+
63
+
64
+	/**
65
+	 * TicketDetails constructor.
66
+	 *
67
+	 * @param TicketDetails  $ticket_details
68
+	 * @param \EE_Tax_Config $tax_settings
69
+	 * @param int            $total_tickets
70
+	 * @param int            $max_atndz
71
+	 * @param int            $row
72
+	 * @param int            $cols
73
+	 * @param boolean        $required_ticket_sold_out
74
+	 * @param string         $event_status
75
+	 * @param string         $ticket_datetime_classes
76
+	 * @throws EE_Error
77
+	 * @throws UnexpectedEntityException
78
+	 */
79
+	public function __construct(
80
+		TicketDetails $ticket_details,
81
+		\EE_Tax_Config $tax_settings,
82
+		$total_tickets,
83
+		$max_atndz,
84
+		$row,
85
+		$cols,
86
+		$required_ticket_sold_out,
87
+		$event_status,
88
+		$ticket_datetime_classes
89
+	) {
90
+		$this->ticket = $ticket_details->getTicket();
91
+		$this->ticket_details = $ticket_details;
92
+		$this->template_settings = $ticket_details->getTemplateSettings();
93
+		$this->tax_settings = $tax_settings;
94
+		$this->total_tickets = $total_tickets;
95
+		$this->max_atndz = $max_atndz;
96
+		$this->row = $row;
97
+		$this->cols = $cols;
98
+		$this->date_format = $ticket_details->getDateFormat();
99
+		$this->ticket_datetime_classes = $ticket_datetime_classes;
100
+		parent::__construct($this->ticket, $max_atndz, $this->date_format, $event_status, $required_ticket_sold_out);
101
+	}
102
+
103
+
104
+
105
+	/**
106
+	 * other ticket rows will need to know if a required ticket is sold out,
107
+	 * so that they are not offered for sale
108
+	 *
109
+	 * @return boolean
110
+	 */
111
+	public function getRequiredTicketSoldOut()
112
+	{
113
+		return $this->required_ticket_sold_out;
114
+	}
115
+
116
+
117
+
118
+	/**
119
+	 * @return int
120
+	 */
121
+	public function getCols()
122
+	{
123
+		return $this->cols;
124
+	}
125
+
126
+
127
+
128
+	/**
129
+	 * getHtml
130
+	 *
131
+	 * @return string
132
+	 * @throws EE_Error
133
+	 */
134
+	public function getHtml()
135
+	{
136
+		$min = 0;
137
+		$max = $this->ticket->max();
138
+		$remaining = $this->ticket->remaining();
139
+		if ($this->ticket->is_on_sale() && $this->ticket->is_remaining()) {
140
+			list($min, $max) = $this->setTicketMinAndMax($remaining);
141
+		} else {
142
+			// set flag if ticket is required (flag is set to start date so that future tickets are not blocked)
143
+			$this->required_ticket_sold_out = $this->ticket->required() && ! $remaining
144
+				? $this->ticket->start_date()
145
+				: $this->required_ticket_sold_out;
146
+		}
147
+		list($ticket_price, $ticket_bundle) = $this->getTicketPriceDetails();
148
+		list($tkt_status, $ticket_status, $status_class) = $this->getTicketStatusClasses($remaining);
149
+		/**
150
+		 * Allow plugins to hook in and abort the generation and display of this row to do
151
+		 * something else if they want.
152
+		 * For an addon to abort things, all they have to do is register a filter with this hook, and
153
+		 * return a value that is NOT false.  Whatever is returned gets echoed instead of the
154
+		 * current row.
155
+		 *
156
+		 * @var string|bool
157
+		 */
158
+		$ticket_selector_row_html = apply_filters(
159
+			'FHEE__ticket_selector_chart_template__do_ticket_entire_row',
160
+			false,
161
+			$this->ticket,
162
+			$max,
163
+			$min,
164
+			$this->required_ticket_sold_out,
165
+			$ticket_price,
166
+			$ticket_bundle,
167
+			$ticket_status,
168
+			$status_class
169
+		);
170
+		if ($ticket_selector_row_html !== false) {
171
+			return $ticket_selector_row_html;
172
+		}
173
+		$ticket_selector_row_html = \EEH_HTML::tr(
174
+			'', '',
175
+			"tckt-slctr-tbl-tr {$status_class}{$this->ticket_datetime_classes} " . espresso_get_object_css_class($this->ticket)
176
+		);
177
+		/**
178
+		 * Allow plugins to hook in and abort the generation and display of the contents of this
179
+		 * row to do something else if they want.
180
+		 * For an addon to abort things, all they have to do is register a filter with this hook, and
181
+		 * return a value that is NOT false.  Whatever is returned gets echoed instead of the
182
+		 * current row.
183
+		 *
184
+		 * @var string|bool
185
+		 */
186
+		$new_row_cells_content = apply_filters(
187
+			'FHEE__ticket_selector_chart_template__do_ticket_inside_row',
188
+			false,
189
+			$this->ticket,
190
+			$max,
191
+			$min,
192
+			$this->required_ticket_sold_out,
193
+			$ticket_price,
194
+			$ticket_bundle,
195
+			$ticket_status,
196
+			$status_class
197
+		);
198
+		if ($new_row_cells_content !== false && $this->max_atndz === 1) {
199
+			return $ticket_selector_row_html
200
+				   . $new_row_cells_content
201
+				   . $this->ticketQtyAndIdHiddenInputs()
202
+				   . \EEH_HTML::trx();
203
+		}
204
+		if ($new_row_cells_content !== false) {
205
+			return $ticket_selector_row_html
206
+				   . $new_row_cells_content
207
+				   . \EEH_HTML::trx();
208
+		}
209
+		$this->hidden_input_qty = $this->max_atndz > 1 ? true : false;
210
+
211
+		$ticket_selector_row_html .= $this->ticketNameTableCell();
212
+		$ticket_selector_row_html .= $this->ticketPriceTableCell($ticket_price, $ticket_bundle);
213
+		$ticket_selector_row_html .= \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-qty cntr');
214
+		$this->setTicketStatusDisplay($tkt_status, $ticket_status, $remaining);
215
+		if (empty($this->ticket_status_display)) {
216
+			if ($this->max_atndz === 1) {
217
+				// only ONE attendee is allowed to register at a time
218
+				$ticket_selector_row_html .= $this->onlyOneAttendeeCanRegister();
219
+			} else if ($max > 0) {
220
+				$ticket_selector_row_html .= $this->ticketQuantitySelector($min, $max);
221
+			}
222
+		}
223
+		$ticket_selector_row_html .= $this->ticket_status_display;
224
+		$ticket_selector_row_html .= $this->ticketQtyAndIdHiddenInputs();
225
+		$ticket_selector_row_html .= $this->ticket_details->display($ticket_price, $remaining, $this->cols);
226
+		$ticket_selector_row_html .= \EEH_HTML::tdx();
227
+		$ticket_selector_row_html .= \EEH_HTML::trx();
228
+
229
+
230
+		$this->row++;
231
+		return $ticket_selector_row_html;
232
+	}
233
+
234
+
235
+
236
+	/**
237
+	 * setTicketMinAndMax
238
+	 *
239
+	 * @param int $remaining
240
+	 * @return array
241
+	 * @throws EE_Error
242
+	 */
243
+	protected function setTicketMinAndMax($remaining)
244
+	{
245
+		// offer the number of $tickets_remaining or $this->max_atndz, whichever is smaller
246
+		$max = min($remaining, $this->max_atndz);
247
+		// but... we also want to restrict the number of tickets by the ticket max setting,
248
+		// however, the max still can't be higher than what was just set above
249
+		$max = $this->ticket->max() > 0 ? min($this->ticket->max(), $max) : $max;
250
+		// and we also want to restrict the minimum number of tickets by the ticket min setting
251
+		$min = $this->ticket->min() > 0 ? $this->ticket->min() : 0;
252
+		// and if the ticket is required, then make sure that min qty is at least 1
253
+		$min = $this->ticket->required() ? max($min, 1) : $min;
254
+		return array($min, $max);
255
+	}
256
+
257
+
258
+
259
+	/**
260
+	 * getTicketPriceDetails
261
+	 *
262
+	 * @return array
263
+	 * @throws EE_Error
264
+	 */
265
+	protected function getTicketPriceDetails()
266
+	{
267
+		$ticket_price = $this->tax_settings->prices_displayed_including_taxes
268
+			? $this->ticket->get_ticket_total_with_taxes()
269
+			: $this->ticket->get_ticket_subtotal();
270
+		$ticket_bundle = false;
271
+		$ticket_min = $this->ticket->min();
272
+		// for ticket bundles, set min and max qty the same
273
+		if ($ticket_min !== 0 && $ticket_min === $this->ticket->max()) {
274
+			$ticket_price *= $ticket_min;
275
+			$ticket_bundle = true;
276
+		}
277
+		$ticket_price = apply_filters(
278
+			'FHEE__ticket_selector_chart_template__ticket_price',
279
+			$ticket_price,
280
+			$this->ticket
281
+		);
282
+		return array($ticket_price, $ticket_bundle);
283
+	}
284
+
285
+
286
+
287
+
288
+	/**
289
+	 * ticketNameTableCell
290
+	 *
291
+	 * @return string
292
+	 * @throws EE_Error
293
+	 */
294
+	protected function ticketNameTableCell()
295
+	{
296
+		$html = \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-name');
297
+		$html .= \EEH_HTML::strong($this->ticket->get_pretty('TKT_name'));
298
+		$html .= $this->ticket_details->getShowHideLinks();
299
+		if ($this->ticket->required()) {
300
+			$html .= \EEH_HTML::p(
301
+					apply_filters(
302
+							'FHEE__ticket_selector_chart_template__ticket_required_message',
303
+							esc_html__('This ticket is required and must be purchased.', 'event_espresso')
304
+					),
305
+					'', 'ticket-required-pg'
306
+			);
307
+		}
308
+		$html .= \EEH_HTML::tdx();
309
+		return $html;
310
+	}
311
+
312
+
313
+
314
+	/**
315
+	 * ticketPriceTableCell
316
+	 *
317
+	 * @param float $ticket_price
318
+	 * @param bool  $ticket_bundle
319
+	 * @return string
320
+	 * @throws EE_Error
321
+	 */
322
+	protected function ticketPriceTableCell($ticket_price, $ticket_bundle)
323
+	{
324
+		$html = '';
325
+		if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) {
326
+			$html .= \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-price jst-rght');
327
+			$html .= \EEH_Template::format_currency($ticket_price);
328
+			$html .= $this->ticket->taxable()
329
+				? \EEH_HTML::span( '*', '', 'taxable-tickets-asterisk grey-text' )
330
+				: '';
331
+			$html .= '&nbsp;';
332
+			$html .= \EEH_HTML::span(
333
+				$ticket_bundle
334
+					? apply_filters(
335
+						'FHEE__ticket_selector_chart_template__per_ticket_bundle_text',
336
+						__(' / bundle', 'event_espresso')
337
+					)
338
+					: apply_filters(
339
+						'FHEE__ticket_selector_chart_template__per_ticket_text',
340
+						__('', 'event_espresso')
341
+					),
342
+				'', 'smaller-text no-bold'
343
+			);
344
+			$html .= '&nbsp;';
345
+			$html .= \EEH_HTML::tdx();
346
+			$this->cols++;
347
+		}
348
+		return $html;
349
+	}
350
+
351
+
352
+
353
+	/**
354
+	 * onlyOneAttendeeCanRegister
355
+	 *
356
+	 * @return string
357
+	 */
358
+	protected function onlyOneAttendeeCanRegister()
359
+	{
360
+		// display submit button since we have tickets available
361
+		add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
362
+		$this->hidden_input_qty = false;
363
+		$html = '<input type="radio" name="tkt-slctr-qty-' . $this->EVT_ID . '"';
364
+		$html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"';
365
+		$html .= ' class="ticket-selector-tbl-qty-slct" value="' . $this->row . '-1"';
366
+		$html .= $this->total_tickets === 1 ? ' checked="checked"' : '';
367
+		$html .= ' title=""/>';
368
+		return $html;
369
+	}
370
+
371
+
372
+
373
+	/**
374
+	 * ticketQuantitySelector
375
+	 *
376
+	 * @param int $min
377
+	 * @param int $max
378
+	 * @return string
379
+	 * @throws EE_Error
380
+	 */
381
+	protected function ticketQuantitySelector($min = 0, $max = 0)
382
+	{
383
+		// display submit button since we have tickets available
384
+		add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
385
+		$this->hidden_input_qty = false;
386
+		$html = '<select name="tkt-slctr-qty-' . $this->EVT_ID . '[]"';
387
+		$html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"';
388
+		$html .= ' class="ticket-selector-tbl-qty-slct">';
389
+		// this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased
390
+		if ($min !== 0 && ! $this->ticket->required()) {
391
+			$html .= '<option value="0">&nbsp;0&nbsp;</option>';
392
+		}
393
+		// offer ticket quantities from the min to the max
394
+		for ($i = $min; $i <= $max; $i++) {
395
+			$html .= '<option value="' . $i . '">&nbsp;' . $i . '&nbsp;</option>';
396
+		}
397
+		$html .= '</select>';
398
+		return $html;
399
+	}
400
+
401
+
402
+
403
+	/**
404
+	 * getHiddenInputs
405
+	 *
406
+	 * @return string
407
+	 * @throws EE_Error
408
+	 */
409
+	protected function ticketQtyAndIdHiddenInputs()
410
+	{
411
+		$html = '';
412
+		// depending on group reg we need to change the format for qty
413
+		if ($this->hidden_input_qty) {
414
+			$html .= '<input type="hidden" name="tkt-slctr-qty-' . $this->EVT_ID . '[]" value="0"/>';
415
+		}
416
+		$html .= '<input type="hidden" name="tkt-slctr-ticket-id-' . $this->EVT_ID . '[]"';
417
+		$html .= ' value="' . $this->ticket->ID() . '"/>';
418
+		return $html;
419
+	}
420 420
 
421 421
 }
422 422
 // End of file TicketSelectorRowStandard.php
Please login to merge, or discard this patch.
modules/ticket_selector/TicketSelectorSimple.php 2 patches
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -18,54 +18,54 @@
 block discarded – undo
18 18
 class TicketSelectorSimple extends TicketSelector
19 19
 {
20 20
 
21
-    /**
22
-     * @var \EE_Ticket $ticket
23
-     */
24
-    protected $ticket;
21
+	/**
22
+	 * @var \EE_Ticket $ticket
23
+	 */
24
+	protected $ticket;
25 25
 
26 26
 
27 27
 
28
-    /**
29
-     * TicketSelectorSimple constructor.
30
-     *
31
-     * @param \EE_Event  $event
32
-     * @param \EE_Ticket $ticket
33
-     * @param int        $max_attendees
34
-     * @param array      $template_args
35
-     */
36
-    public function __construct(\EE_Event $event, \EE_Ticket $ticket, $max_attendees, array $template_args)
37
-    {
38
-        $this->ticket = $ticket;
39
-        parent::__construct($event, array($this->ticket), $max_attendees, $template_args);
40
-    }
28
+	/**
29
+	 * TicketSelectorSimple constructor.
30
+	 *
31
+	 * @param \EE_Event  $event
32
+	 * @param \EE_Ticket $ticket
33
+	 * @param int        $max_attendees
34
+	 * @param array      $template_args
35
+	 */
36
+	public function __construct(\EE_Event $event, \EE_Ticket $ticket, $max_attendees, array $template_args)
37
+	{
38
+		$this->ticket = $ticket;
39
+		parent::__construct($event, array($this->ticket), $max_attendees, $template_args);
40
+	}
41 41
 
42 42
 
43 43
 
44
-    /**
45
-     * sets any and all template args that are required for this Ticket Selector
46
-     *
47
-     * @return void
48
-     * @throws \EventEspresso\core\exceptions\UnexpectedEntityException
49
-     * @throws \EE_Error
50
-     */
51
-    protected function addTemplateArgs()
52
-    {
53
-        unset($this->template_args['tickets']);
54
-        $this->template_args['ticket'] = $this->ticket;
55
-        $ticket_selector_row = new TicketSelectorRowSimple(
56
-            $this->ticket,
57
-            $this->max_attendees,
58
-            $this->template_args['date_format'],
59
-            $this->template_args['event_status']
60
-        );
61
-        $this->template_args['TKT_ID'] = $this->ticket->ID();
62
-        $ticket_selector_row->setupTicketStatusDisplay();
63
-        $this->template_args['ticket_status_display'] = $ticket_selector_row->getTicketStatusDisplay();
64
-        if (empty($this->template_args['ticket_status_display'])) {
65
-            add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
66
-        }
67
-        $this->template_args['template_path'] = TICKET_SELECTOR_TEMPLATES_PATH . 'simple_ticket_selector.template.php';
68
-    }
44
+	/**
45
+	 * sets any and all template args that are required for this Ticket Selector
46
+	 *
47
+	 * @return void
48
+	 * @throws \EventEspresso\core\exceptions\UnexpectedEntityException
49
+	 * @throws \EE_Error
50
+	 */
51
+	protected function addTemplateArgs()
52
+	{
53
+		unset($this->template_args['tickets']);
54
+		$this->template_args['ticket'] = $this->ticket;
55
+		$ticket_selector_row = new TicketSelectorRowSimple(
56
+			$this->ticket,
57
+			$this->max_attendees,
58
+			$this->template_args['date_format'],
59
+			$this->template_args['event_status']
60
+		);
61
+		$this->template_args['TKT_ID'] = $this->ticket->ID();
62
+		$ticket_selector_row->setupTicketStatusDisplay();
63
+		$this->template_args['ticket_status_display'] = $ticket_selector_row->getTicketStatusDisplay();
64
+		if (empty($this->template_args['ticket_status_display'])) {
65
+			add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
66
+		}
67
+		$this->template_args['template_path'] = TICKET_SELECTOR_TEMPLATES_PATH . 'simple_ticket_selector.template.php';
68
+	}
69 69
 
70 70
 
71 71
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@
 block discarded – undo
64 64
         if (empty($this->template_args['ticket_status_display'])) {
65 65
             add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
66 66
         }
67
-        $this->template_args['template_path'] = TICKET_SELECTOR_TEMPLATES_PATH . 'simple_ticket_selector.template.php';
67
+        $this->template_args['template_path'] = TICKET_SELECTOR_TEMPLATES_PATH.'simple_ticket_selector.template.php';
68 68
     }
69 69
 
70 70
 
Please login to merge, or discard this patch.