Skip to content

Commit 58b85c8

Browse files
author
Chris Gårdenberg
committed
feat(My Profile/Bookings): Ability to sort bookings either by Created (booking) or Event Start Date
fixes #427
1 parent 30b3f25 commit 58b85c8

2 files changed

Lines changed: 44 additions & 4 deletions

File tree

PLUGIN-CHECKSUM

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
b287e82c7eda502258151d2cc7846207
1+
bf465330e7e847ae75dd70c9f4f9cac0

content/template/myPagesTemplate/bookings.php

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
$contact = $user->Contact;
44
$customer = $user->Customer;
55

6+
const valid_sort = [
7+
'Created',
8+
'StartDate',
9+
];
10+
11+
const valid_sort_order = [
12+
'ASC',
13+
'DESC',
14+
];
15+
616
?>
717
<div class="eduadmin">
818
<?php
@@ -15,6 +25,14 @@
1525
<?php echo esc_html_x( 'Export to Excel (All)', 'frontend', 'eduadmin-booking' ); ?>
1626
</button>
1727
</h2>
28+
29+
<a href="./?booking-sort=StartDate">
30+
<?php echo esc_html_x('Sort by event start date', 'frontend', 'eduadmin-booking'); ?>
31+
</a>
32+
<a href="./?booking-sort=Created">
33+
<?php echo esc_html_x('Sort by booking created', 'frontend', 'eduadmin-booking'); ?>
34+
</a>
35+
<hr />
1836
<?php
1937

2038
$events = EDUAPI()->OData->Events->Search(
@@ -30,11 +48,32 @@
3048
unset( $ev['Bookings'] );
3149
$booking['Event'] = $ev;
3250

33-
$bookings[ $booking['Created'] . '-' . $booking['BookingId'] ] = $booking;
51+
$booking['StartDate'] = $booking['Event']['StartDate'];
52+
53+
$sorting_field = 'Created';
54+
55+
if ( ! empty( $_REQUEST['booking-sort'] ) && in_array( $_REQUEST['booking-sort'], valid_sort ) ) {
56+
$sorting_field = $_REQUEST['booking-sort'];
57+
}
58+
59+
$bookings[ $booking[ $sorting_field ] . '-' . $booking['BookingId'] ] = $booking;
3460
}
3561
}
3662

37-
krsort( $bookings );
63+
$sort_order = 'DESC';
64+
65+
if ( ! empty( $_REQUEST['booking-sort-order'] ) && in_array( $_REQUEST['booking-sort-order'], valid_sort_order ) ) {
66+
$sort_order = $_REQUEST['booking-sort-order'];
67+
}
68+
69+
switch ( $sort_order ) {
70+
case "ASC":
71+
ksort( $bookings );
72+
break;
73+
case "DESC":
74+
krsort( $bookings );
75+
break;
76+
}
3877

3978
$currency = EDU()->get_option( 'eduadmin-currency', 'SEK' );
4079
$selected_price_setting = EDU()->get_option( 'eduadmin-profile-priceType', 'IncVat' );
@@ -64,7 +103,8 @@
64103
$name = $book['Event']['InternalCourseName'];
65104
}
66105
?>
67-
<tr data-bookingid="<?php echo esc_attr( $book['BookingId'] ); ?>" data-course-data="<?php echo esc_attr( json_encode( $book ) ); ?>">
106+
<tr data-bookingid="<?php echo esc_attr( $book['BookingId'] ); ?>"
107+
data-course-data="<?php echo esc_attr( json_encode( $book ) ); ?>">
68108
<td class="table-booked-date">
69109
<?php echo wp_kses_post( get_display_date( $book['Created'], true ) ); ?>
70110
</td>

0 commit comments

Comments
 (0)