PluginProbe ʕ •ᴥ•ʔ
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 4.6.0
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v4.6.0
4.6.3 4.6.2 4.6.1 4.6.0 4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.11.0 1.11.1 1.11.2 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.9.0 1.9.1 1.9.2 1.9.3 1.9.4 1.9.5 2.0.0 2.0.1 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.10.0 2.10.1 2.11.0 2.11.1 2.11.2 2.11.3 2.11.4 2.12.0 2.13.0 2.14.0 2.14.1 2.15.0 2.15.1 2.16.0 2.16.1 2.16.2 2.16.3 2.17.0 2.17.1 2.17.2 2.18.0 2.19.0 2.19.2 2.19.3 2.19.4 2.2.0 2.2.1 2.20.0 2.20.1 2.20.2 2.20.3 2.20.4 2.20.5 2.20.6 2.21.0 2.22.0 2.22.1 2.23.0 2.24.0 2.25.0 2.25.1 2.25.2 2.26.0 2.27.0 2.27.1 2.28.0 2.29.0 2.29.1 2.29.2 2.29.3 2.29.4 2.3.0 2.3.1 2.30.0 2.31.0 2.31.1 2.31.2 2.31.3 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.40.0 2.40.1 2.5.0 2.5.1 2.5.2 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.9.0 3.0.0 3.0.0-RC1 3.0.0-RC2 3.0.0-beta1 3.0.0-beta2 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.10.0 3.10.1 3.11.0 3.12.0 3.13.0 3.13.1 3.13.2 3.13.3 3.13.4 3.14.0 3.15.0 3.15.1 3.15.2 3.15.3 3.15.4 3.15.5 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.16.6 3.16.7 3.16.8 3.17.0 3.17.1 3.17.2 3.17.3 3.17.4 3.17.5 3.17.6 3.18.0 3.19.0 3.19.1 3.19.2 3.2.0 3.2.1 3.2.2 3.20.0 3.20.1 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 4.0.0 4.0.1 4.0.2 4.0.3 trunk 4.1.0 0.2.19.1 4.1.1 1.0.0 4.2.0 1.0.1 1.0.2
surecart / app / src / Controllers / Admin / CancellationInsights / CancellationInsightsListTable.php
surecart / app / src / Controllers / Admin / CancellationInsights Last commit date
CancellationInsightsController.php 1 year ago CancellationInsightsListTable.php 3 months ago
CancellationInsightsListTable.php
285 lines
1 <?php
2
3 namespace SureCart\Controllers\Admin\CancellationInsights;
4
5 use SureCart\Controllers\Admin\Tables\ListTable;
6 use SureCart\Models\CancellationAct;
7 use SureCart\Controllers\Admin\Tables\HasModeFilter;
8
9 /**
10 * Create a new table class that will extend the WP_List_Table
11 */
12 class CancellationInsightsListTable extends ListTable {
13 use HasModeFilter;
14
15 /**
16 * Prepare the items for the table to process
17 *
18 * @return Void
19 */
20 public function prepare_items() {
21 $columns = $this->get_columns();
22 $hidden = $this->get_hidden_columns();
23 $sortable = $this->get_sortable_columns();
24
25 $this->_column_headers = array( $columns, $hidden, $sortable );
26
27 $query = $this->table_data();
28 if ( is_wp_error( $query ) ) {
29 $this->items = [];
30 return;
31 }
32
33 $this->set_pagination_args(
34 [
35 'total_items' => $query->pagination->count,
36 'per_page' => $this->get_items_per_page( 'orders' ),
37 ]
38 );
39
40 $this->items = $query->data;
41 }
42
43
44 /**
45 * Override the parent columns method. Defines the columns to use in your listing table
46 *
47 * @return Array
48 */
49 public function get_columns() {
50 return array_merge(
51 [
52 'customer' => __( 'Customer', 'surecart' ),
53 'plan' => __( 'Plan', 'surecart' ),
54 'cancellation_reason' => __( 'Cancellation Reason', 'surecart' ),
55 'comment' => __( 'Comment', 'surecart' ),
56 'status' => __( 'Plan Status', 'surecart' ),
57 'date' => __( 'Date', 'surecart' ),
58 'mode' => '',
59 ],
60 parent::get_columns()
61 );
62 }
63
64 /**
65 * The subscription product.
66 *
67 * @param \SureCart\Models\CancellationAct $act Cancellation reason model.
68 *
69 * @return string
70 */
71 public function column_plan( $act ) {
72 if ( empty( $act->subscription->price->product ) ) {
73 return __( 'No product', 'surecart' );
74 }
75 return '<a href="' . esc_url( \SureCart::getUrl()->show( 'subscription', $act->subscription->id ) ) . '">' . esc_html( $act->subscription->price->product->name ) . '</a>';
76 }
77
78 /**
79 * The subscription product.
80 *
81 * @param \SureCart\Models\CancellationAct $act Cancellation reason model.
82 *
83 * @return string
84 */
85 public function column_date( $act ) {
86 return $act->performed_at_date_time;
87 }
88
89 /**
90 * We only have one default view.
91 */
92 protected function get_views() {
93 return [ 'all' => __( 'All Cancellation Attempts', 'surecart' ) ];
94 }
95
96 /**
97 * Get the table data
98 *
99 * @return Object
100 */
101 protected function table_data() {
102 $mode = sanitize_text_field( wp_unslash( $_GET['mode'] ?? '' ) );
103 $conditions = array();
104
105 if ( ! empty( $mode ) ) {
106 $conditions['live_mode'] = 'live' === $mode;
107 }
108
109 return CancellationAct::where( $conditions )
110 ->with(
111 [
112 'subscription',
113 'subscription.customer',
114 'cancellation_reason',
115 'subscription.price',
116 'price.product',
117 ]
118 )
119 ->paginate(
120 [
121 'per_page' => $this->get_items_per_page( 'cancellation_acts' ),
122 'page' => $this->get_pagenum(),
123 ]
124 );
125 }
126
127 /**
128 * Nothing found.
129 *
130 * @return void
131 */
132 public function no_items() {
133 echo esc_html_e( 'No cancellation acts.', 'surecart' );
134 }
135
136 /**
137 * The cancellation reason.
138 *
139 * @param \SureCart\Models\CancellationAct $act Cancellation act.
140 *
141 * @return string
142 */
143 public function column_cancellation_reason( $act ) {
144 return esc_html( $act->cancellation_reason->label ?? '-' );
145 }
146
147 /**
148 * The customer.
149 *
150 * @param \SureCart\Models\CancellationAct $act Cancellation act model.
151 *
152 * @return string
153 */
154 public function column_customer( $act ) {
155 ob_start();
156 ?>
157 <a class="row-title" aria-label="<?php esc_attr_e( 'Edit Customer', 'surecart' ); ?>" href="<?php echo esc_url( \SureCart::getUrl()->edit( 'customers', $act->subscription->customer->id ) ); ?>">
158 <?php echo esc_html( $act->subscription->customer->name ?? $act->subscription->customer->email ?? __( 'No name provided', 'surecart' ) ); ?>
159 </a>
160
161 <?php
162 echo $this->row_actions(
163 [
164 'edit' => '<a href="' . esc_url( \SureCart::getUrl()->edit( 'customers', $act->subscription->customer->id ) ) . '" aria-label="' . esc_attr__( 'View Customer', 'surecart' ) . '">' . esc_html__( 'View Customer', 'surecart' ) . '</a>',
165 ],
166 );
167 ?>
168
169 <?php
170 return ob_get_clean();
171 }
172
173 /**
174 * Cancellation comment.
175 *
176 * @param \SureCart\Models\CancellationAct $act Cancellation act model.
177 *
178 * @return string
179 */
180 public function column_comment( $act ) {
181 return esc_html( $act->comment ?? '-' );
182 }
183
184 /**
185 * The mode for the model.
186 *
187 * @param SureCart\Model $model Model.
188 *
189 * @return string
190 */
191 public function column_mode( $act ) {
192 return empty( $act->subscription->live_mode ) ? '<sc-tag type="warning">' . __( 'Test', 'surecart' ) . '</sc-tag>' : '';
193 }
194
195 /**
196 * The status
197 *
198 * @param \SureCart\Models\CancellationAct $act Cancellation act model.
199 *
200 * @return string
201 */
202 public function column_status( $act ) {
203 if ( $act->preserved ) {
204 ob_start();
205 ?>
206 <sc-tag type="success">
207 <?php
208 // translators: Subscription saver feature. This is displayed if the subscription has been "Saved" from cancellation.
209 echo esc_html__( 'Saved', 'surecart' );
210 ?>
211 </sc-tag>
212 <?php if ( $act->coupon_applied ) { ?>
213 <sc-tag type="info"><?php echo esc_html__( 'Coupon Applied', 'surecart' ); ?></sc-tag>
214 <?php } ?>
215 <?php
216 return ob_get_clean();
217 }
218
219 $badge = '<sc-subscription-status-badge id="act-' . esc_attr( $act->id ) . '"></sc-subscription-status-badge>';
220
221 \SureCart::assets()->addComponentData(
222 'sc-subscription-status-badge',
223 '#act-' . esc_attr( $act->id ),
224 [
225 'subscription' => $act->subscription,
226 ]
227 );
228
229 return $badge;
230 }
231
232 /**
233 * Displays extra table navigation.
234 *
235 * @param string $which Top or bottom placement.
236 */
237 protected function extra_tablenav( $which ) {
238 ?>
239 <input type="hidden" name="page" value="sc-cancellation-insights" />
240
241 <div class="alignleft actions">
242 <?php
243 if ( 'top' === $which ) {
244 ob_start();
245 $this->mode_dropdown();
246
247 /**
248 * Fires before the Filter button on the Posts and Pages list tables.
249 *
250 * The Filter button allows sorting by date and/or category on the
251 * Posts list table, and sorting by date on the Pages list table.
252 *
253 * @since 2.1.0
254 * @since 4.4.0 The `$post_type` parameter was added.
255 * @since 4.6.0 The `$which` parameter was added.
256 *
257 * @param string $post_type The post type slug.
258 * @param string $which The location of the extra table nav markup:
259 * 'top' or 'bottom' for WP_Posts_List_Table,
260 * 'bar' for WP_Media_List_Table.
261 */
262 do_action( 'restrict_manage_cancellation_insights', $this->screen->post_type, $which );
263
264 $output = ob_get_clean();
265
266 if ( ! empty( $output ) ) {
267 echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
268 submit_button( __( 'Filter', 'surecart' ), '', 'filter_action', false, array( 'id' => 'filter-by-mode-submit' ) );
269 }
270 }
271
272 ?>
273 </div>
274
275 <?php
276 /**
277 * Fires immediately following the closing "actions" div in the tablenav
278 * for the affiliate referrals list table.
279 *
280 * @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
281 */
282 do_action( 'manage_cancellation_insights_extra_tablenav', $which );
283 }
284 }
285