Skip to content

Commit 4919f52

Browse files
author
Chris Gårdenberg
committed
feat: Added possibility to use attribute allcourses to show both on demand and regular course templates at the same time.
ref #478
1 parent de2f7d0 commit 4919f52

12 files changed

Lines changed: 492 additions & 503 deletions

File tree

PLUGIN-CHECKSUM

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8cb9d57b0c0acede024cd8c7cc7e3776
1+
a39447ffe765166511c2ef20fb003a4d

content/scripts/eduapi/edu.apiclient.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
"use strict";
2-
wp_edu = wp_edu ? wp_edu : { AjaxUrl: "", CourseFolder: "", BaseUrl: "", BaseUrlScripts: "", Currency: "SEK", ShouldValidateCivRegNo: "false", SingleParticipant: "false", RecaptchaEnabled: "false" };
2+
wp_edu = wp_edu ? wp_edu : {
3+
AjaxUrl: "",
4+
CourseFolder: "",
5+
BaseUrl: "",
6+
BaseUrlScripts: "",
7+
Currency: "SEK",
8+
ShouldValidateCivRegNo: "false",
9+
SingleParticipant: "false",
10+
RecaptchaEnabled: "false"
11+
};
312
var edu = window["edu"] ? window["edu"] : {};
413
edu.apiclient = {
514
baseUrl: null,
@@ -115,7 +124,8 @@ edu.apiclient = {
115124
showimages: jQuery(target).data("showimages"),
116125
hideimages: jQuery(target).data("hideimages"),
117126
filtercity: jQuery(target).data("filtercity"),
118-
ondemand: jQuery(target).data('ondemand')
127+
ondemand: jQuery(target).data('ondemand'),
128+
allcourses: jQuery(target).data('allcourses'),
119129
},
120130
success: function (d) {
121131
jQuery(target).html(d);
@@ -141,7 +151,8 @@ edu.apiclient = {
141151
showvenue: jQuery(target).data("showvenue"),
142152
eventinquiry: jQuery(target).data("eventinquiry"),
143153
"edu-region": jQuery(target).data("region"),
144-
ondemand: jQuery(target).data('ondemand')
154+
ondemand: jQuery(target).data('ondemand'),
155+
allcourses: jQuery(target).data('allcourses'),
145156
},
146157
success: function (d) {
147158
jQuery(target).replaceWith(d);
@@ -227,7 +238,8 @@ edu.apiclient = {
227238
}
228239
return decodeURIComponent(cookie.substring(valueStart, valueEnd));
229240
}
230-
catch (e) { }
241+
catch (e) {
242+
}
231243
return null;
232244
},
233245
SetCookie: function (name, value, expire) {

content/template/listTemplate/list-courses.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,19 @@
3939
$course_level = intval( sanitize_text_field( $_REQUEST['eduadmin-level'] ) );
4040
}
4141

42-
if ( ! $show_ondemand ) {
43-
$edo = EDUAPIHelper()->GetCourseList( $attributes, $category_id, $city, $subject_id, $course_level, $custom_order_by, $custom_order_by_order );
42+
if ( $all_courses ) {
43+
$_courses = EDUAPIHelper()->GetCourseList( $attributes, $category_id, $city, $subject_id, $course_level, $custom_order_by, $custom_order_by_order );
44+
$_ondemandcourses = EDUAPIHelper()->GetOnDemandCourseList( $attributes, $category_id, $city, $subject_id, $course_level, $custom_order_by, $custom_order_by_order );
45+
46+
$edo = [
47+
'value' => array_merge( $_courses['value'], $_ondemandcourses['value'] ),
48+
];
4449
} else {
45-
$edo = EDUAPIHelper()->GetOnDemandCourseList( $attributes, $category_id, $city, $subject_id, $course_level, $custom_order_by, $custom_order_by_order );
50+
if ( ! $show_ondemand ) {
51+
$edo = EDUAPIHelper()->GetCourseList( $attributes, $category_id, $city, $subject_id, $course_level, $custom_order_by, $custom_order_by_order );
52+
} else {
53+
$edo = EDUAPIHelper()->GetOnDemandCourseList( $attributes, $category_id, $city, $subject_id, $course_level, $custom_order_by, $custom_order_by_order );
54+
}
4655
}
4756

4857
$courses = $edo['value'];

content/template/listTemplate/list-events.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,24 @@
5656
if ( $order_option === "SortIndex" ) {
5757
$order_option = "StartDate";
5858
}
59+
5960
array_push( $order_by, $order_option );
6061
array_push( $order, 1 );
6162
}
6263

63-
if ( ! $show_ondemand ) {
64-
$edo = EDUAPIHelper()->GetEventList( $attributes, $category_id, $city, $subject_id, $course_level, $custom_order_by, $custom_order_by_order );
64+
if ( $all_courses ) {
65+
$_courses = EDUAPIHelper()->GetEventList( $attributes, $category_id, $city, $subject_id, $course_level, $custom_order_by, $custom_order_by_order );
66+
$_ondemandcourses = EDUAPIHelper()->GetOnDemandEventList( $attributes, $category_id, $city, $subject_id, $course_level, $custom_order_by, $custom_order_by_order );
67+
68+
$edo = [
69+
'value' => array_merge( $_ondemandcourses['value'], $_courses['value'] ),
70+
];
6571
} else {
66-
$edo = EDUAPIHelper()->GetOnDemandEventList( $attributes, $category_id, $city, $subject_id, $course_level, $custom_order_by, $custom_order_by_order );
72+
if ( ! $show_ondemand ) {
73+
$edo = EDUAPIHelper()->GetEventList( $attributes, $category_id, $city, $subject_id, $course_level, $custom_order_by, $custom_order_by_order );
74+
} else {
75+
$edo = EDUAPIHelper()->GetOnDemandEventList( $attributes, $category_id, $city, $subject_id, $course_level, $custom_order_by, $custom_order_by_order );
76+
}
6777
}
6878

6979
$courses = $edo['value'];
@@ -180,4 +190,5 @@
180190
data-hideimages="<?php echo esc_attr( $attributes['hideimages'] ); ?>"
181191
data-filtercity="<?php echo esc_attr( $attributes['filtercity'] ); ?>"
182192
data-useeduform="<?php echo esc_attr( $use_eduadmin_form ); ?>"
183-
data-ondemand="<?php echo esc_attr( $attributes['ondemand'] ); ?>">
193+
data-ondemand="<?php echo esc_attr( $attributes['ondemand'] ); ?>"
194+
data-allcourses="<?php echo esc_attr( $attributes['allcourses'] ); ?>">

content/template/listTemplate/template-loader.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@
4444
$show_ondemand = $attributes['ondemand'];
4545
}
4646

47+
$all_courses = false;
48+
if(!empty($attributes['allcourses'])) {
49+
$all_courses = $attributes['allcourses'];
50+
}
51+
4752
if ( null !== $custom_mode ) {
4853
if ( 'event' === $custom_mode ) {
4954
$str = include $attributes['template'] . '_listEvents.php';

content/template/listTemplate/template_A_listEvents.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
break;
1010
}
1111

12-
if ( $show_ondemand && ! $event['OnDemand'] ) {
13-
continue;
12+
if ( ! $all_courses ) {
13+
if ( $show_ondemand && ! $event['OnDemand'] ) {
14+
continue;
15+
}
1416
}
1517

1618
$name = $event['EventName'];

content/template/listTemplate/template_B_listEvents.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
break;
1010
}
1111

12-
if ( $show_ondemand && ! $event['OnDemand'] ) {
13-
continue;
12+
if ( ! $all_courses ) {
13+
if ( $show_ondemand && ! $event['OnDemand'] ) {
14+
continue;
15+
}
1416
}
1517

1618
$name = $event['EventName'];

includes/edu-ajax-functions.php

Lines changed: 27 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ function edu_listview_courselist() {
4848
}
4949

5050
if ( ! empty( $_POST['city'] ) && is_numeric( $_POST['city'] ) ) {
51-
$filters[] = 'Events/any(e:e/LocationId eq ' . intval( $_POST['city'] ) . ')';
52-
$event_filters[] = 'LocationId eq ' . intval( $_POST['city'] );
51+
$filters[] = 'Events/any(e:e/LocationId eq ' . intval( $_POST['city'] ) . ')';
5352
}
5453

5554
if ( ! empty( $_POST['subject'] ) ) {
@@ -109,111 +108,33 @@ function edu_api_listview_eventlist() {
109108
$fetch_months = 6;
110109
}
111110

112-
$ondemand = $_POST['ondemand'];
113-
114-
$filters = array();
115-
$selects = array();
116-
$event_filters = array();
117-
$expands = array();
118-
119-
$selects[] = 'CourseTemplateId';
120-
$selects[] = 'CourseName';
121-
$selects[] = 'InternalCourseName';
122-
$selects[] = 'ImageUrl';
123-
$selects[] = 'CourseDescription';
124-
$selects[] = 'CourseDescriptionShort';
125-
$selects[] = 'CourseGoal';
126-
$selects[] = 'TargetGroup';
127-
$selects[] = 'Prerequisites';
128-
$selects[] = 'CourseAfter';
129-
$selects[] = 'Quote';
130-
$selects[] = 'Days';
131-
$selects[] = 'StartTime';
132-
$selects[] = 'EndTime';
133-
$selects[] = 'RequireCivicRegistrationNumber';
134-
$selects[] = 'ParticipantVat';
135-
$selects[] = 'OnDemand';
136-
$selects[] = 'OnDemandAccessDays';
137-
138-
$event_filters[] = 'HasPublicPriceName';
139-
$event_filters[] = 'StatusId eq 1';
140-
$event_filters[] = 'CustomerId eq null';
141-
$event_filters[] = 'CompanySpecific eq false';
142-
143-
if ( ! $ondemand ) {
144-
$event_filters[] = 'LastApplicationDate ge ' . date_i18n( 'c' );
145-
$event_filters[] = 'StartDate le ' . edu_get_timezoned_date( 'c', 'now 23:59:59 +' . $fetch_months . ' months' );
146-
$event_filters[] = 'EndDate ge ' . edu_get_timezoned_date( 'c', 'now' );
147-
} else {
148-
$event_filters[] = 'OnDemand';
149-
$event_filters[] = 'OnDemandPublished';
111+
$city = null;
112+
$subject_id = null;
113+
$course_level = null;
150114

151-
$filters[] = 'OnDemand';
152-
}
153-
154-
$filters[] = 'ShowOnWeb';
115+
$ondemand = $_POST['ondemand'];
116+
$all_courses = $_POST['allcourses'];
155117

156118
$category_id = wp_unslash( sanitize_text_field( $_POST['category'] ) );
157119

158120
if ( ! empty( $_POST['categorydeep'] ) ) {
159121
$category_id = 'deep-' . sanitize_text_field( $_POST['categorydeep'] );
160122
}
161123

162-
if ( ! empty( $category_id ) && ! edu_starts_with( $category_id, 'deep-' ) ) {
163-
$filters[] = 'CategoryId eq ' . $category_id;
164-
} elseif ( ! empty( $category_id ) && edu_starts_with( $category_id, 'deep-' ) ) {
165-
$filters[] = 'Categories/any(c:c/CategoryId eq ' . str_replace( 'deep-', '', $category_id ) . ')';
166-
}
167-
168124
if ( ! empty( $_POST['city'] ) && is_numeric( $_POST['city'] ) ) {
169-
$filters[] = 'Events/any(e:e/LocationId eq ' . intval( $_POST['city'] ) . ')';
170-
$event_filters[] = 'LocationId eq ' . intval( $_POST['city'] );
125+
$city = intval( $_POST['city'] );
171126
}
172127

173128
if ( ! empty( $_POST['subject'] ) ) {
174-
$filters[] = 'Subjects/any(s:s/SubjectName eq \'' . sanitize_text_field( $_POST['subject'] ) . '\')';
129+
$subject_id = intval( $_POST['subject'] );
175130
}
176131

177132
if ( ! empty( $_POST['subjectid'] ) ) {
178-
$filters[] = 'Subjects/any(s:s/SubjectId eq ' . intval( $_POST['subjectid'] ) . ')';
133+
$subject_id = intval( $_POST['subjectid'] );
179134
}
180135

181136
if ( ! empty( $_POST['courselevel'] ) ) {
182-
$filters[] = 'CourseLevelId eq ' . intval( sanitize_text_field( $_POST['courselevel'] ) );
183-
}
184-
185-
$expands['Subjects'] = '$select=SubjectName;';
186-
$expands['Categories'] = '$select=CategoryName;';
187-
$expands['PriceNames'] = '$filter=PublicPriceName';
188-
$expands['Events'] =
189-
'$filter=' .
190-
join( ' and ', $event_filters ) .
191-
';' .
192-
'$expand=PriceNames($filter=PublicPriceName;$select=PriceNameId,PriceNameDescription,Price,MaxParticipantNumber,NumberOfParticipants,DiscountPercent;),EventDates($orderby=StartDate;$select=StartDate,EndDate;)' .
193-
';' .
194-
'$orderby=StartDate asc' .
195-
';' .
196-
'$select=EventId,City,ParticipantNumberLeft,MaxParticipantNumber,StartDate,EndDate,AddressName,EventName,ParticipantVat,BookingFormUrl,OnDemand,OnDemandPublished,OnDemandAccessDays,ApplicationOpenDate';
197-
198-
$expands['CustomFields'] = '$filter=ShowOnWeb;$select=CustomFieldId,CustomFieldName,CustomFieldType,CustomFieldValue,CustomFieldChecked,CustomFieldDate,CustomFieldAlternativeId,CustomFieldAlternativeValue;';
199-
200-
if ( ! $ondemand ) {
201-
$filters[] = 'Events/any(b:b/HasPublicPriceName' .
202-
' and b/StatusId eq 1' .
203-
' and b/CustomerId eq null' .
204-
' and b/CompanySpecific eq false' .
205-
' and b/LastApplicationDate ge ' . date_i18n( 'c' ) .
206-
' and b/StartDate le ' . edu_get_timezoned_date( 'c', 'now 23:59:59 +' . $fetch_months . ' months' ) .
207-
' and b/EndDate ge ' . edu_get_timezoned_date( 'c', 'now' ) .
208-
')';
209-
} else {
210-
$filters[] = 'Events/any(b:b/HasPublicPriceName' .
211-
' and b/StatusId eq 1' .
212-
' and b/CustomerId eq null' .
213-
' and b/CompanySpecific eq false' .
214-
' and b/OnDemand' .
215-
' and b/OnDemandPublished' .
216-
')';
137+
$course_level = intval( sanitize_text_field( $_POST['courselevel'] ) );
217138
}
218139

219140
$order_by = array();
@@ -247,20 +168,23 @@ function edu_api_listview_eventlist() {
247168
array_push( $order, 1 );
248169
}
249170

250-
$expand_arr = array();
251-
foreach ( $expands as $key => $value ) {
252-
if ( empty( $value ) ) {
253-
$expand_arr[] = $key;
171+
$attributes = $_POST;
172+
173+
if ( $all_courses ) {
174+
$_courses = EDUAPIHelper()->GetEventList( $attributes, $category_id, $city, $subject_id, $course_level, $custom_order_by, $custom_order_by_order );
175+
$_ondemandcourses = EDUAPIHelper()->GetOnDemandEventList( $attributes, $category_id, $city, $subject_id, $course_level, $custom_order_by, $custom_order_by_order );
176+
177+
$edo = [
178+
'value' => array_merge( $_ondemandcourses['value'], $_courses['value'] ),
179+
];
180+
} else {
181+
if ( ! $ondemand ) {
182+
$edo = EDUAPIHelper()->GetEventList( $attributes, $category_id, $city, $subject_id, $course_level, $custom_order_by, $custom_order_by_order );
254183
} else {
255-
$expand_arr[] = $key . '(' . $value . ')';
184+
$edo = EDUAPIHelper()->GetOnDemandEventList( $attributes, $category_id, $city, $subject_id, $course_level, $custom_order_by, $custom_order_by_order );
256185
}
257186
}
258187

259-
$edo = EDUAPI()->OData->CourseTemplates->Search(
260-
join( ',', $selects ),
261-
join( ' and ', $filters ),
262-
join( ',', $expand_arr )
263-
);
264188
$courses = $edo['value'];
265189

266190
if ( ! empty( $_POST['search'] ) ) {
@@ -405,6 +329,8 @@ function edu_api_listview_eventlist_template_A( $data, $request ) {
405329
'showvenue',
406330
'order',
407331
'orderby',
332+
'ondemand',
333+
'allcourses',
408334
);
409335

410336
$current_events = 0;
@@ -481,6 +407,8 @@ function edu_api_listview_eventlist_template_B( $data, $request ) {
481407
'showvenue',
482408
'order',
483409
'orderby',
410+
'ondemand',
411+
'allcourses',
484412
);
485413

486414
$current_events = 0;

includes/edu-shortcodes.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ function eduadmin_get_list_view( $attributes ) {
5555
'showimages' => null,
5656
'categorydeep' => null,
5757
'ondemand' => false,
58+
'allcourses' => false,
5859
),
5960
normalize_empty_atts( $attributes ),
6061
'eduadmin-listview'
@@ -240,7 +241,7 @@ function eduadmin_get_detailinfo( $attributes ) {
240241
'order' => null,
241242
'orderby' => null,
242243
'ondemand' => false,
243-
//'coursesubject' => null
244+
'allcourses' => false,
244245
),
245246
normalize_empty_atts( $attributes ),
246247
'eduadmin-detailinfo'
@@ -551,6 +552,7 @@ function eduadmin_get_detailinfo( $attributes ) {
551552
$ret_str .= ' data-showvenue="' . esc_attr( EDU()->is_checked( 'eduadmin-showEventVenueName', false ) ) . '"';
552553
$ret_str .= ' data-eventinquiry="' . esc_attr( EDU()->is_checked( 'eduadmin-allowInterestRegEvent', false ) ) . '"';
553554
$ret_str .= ' data-ondemand="' . esc_attr( $attributes['ondemand'] ) . '"';
555+
$ret_str .= ' data-allcourses="' . esc_attr( $attributes['allcourses'] ) . '"';
554556
$ret_str .= '>';
555557

556558
$i = 0;

includes/edu-sort-functions.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
*/
99
function sortEvents( $events, $order_by, $order ) {
1010
$t = EDU()->start_timer( 'sortEvents' );
11+
1112
usort( $events, function( $evA, $evB ) use ( $order_by, $order ) {
12-
return multiSort( $evA, $evB, $order_by, $order, 0 );
13+
return multiSort( $evA, $evB, ['OnDemand', ...$order_by], [-1, ...$order], 0 );
1314
} );
15+
1416
EDU()->stop_timer( $t );
1517

1618
return $events;

0 commit comments

Comments
 (0)