|
| 1 | +<?php |
| 2 | +global $wp_query; |
| 3 | + |
| 4 | +if ( ! empty( $wp_query->query_vars['courseId'] ) ) { |
| 5 | + $course_id = $wp_query->query_vars['courseId']; |
| 6 | +} elseif ( ! empty( $attributes['courseid'] ) ) { |
| 7 | + $course_id = $attributes['courseid']; |
| 8 | +} else { |
| 9 | + $course_id = null; |
| 10 | +} |
| 11 | +$group_by_city = EDU()->is_checked( 'eduadmin-groupEventsByCity', false ); |
| 12 | +$group_by_city_class = ''; |
| 13 | + |
| 14 | +$fetch_months = EDU()->get_option( 'eduadmin-monthsToFetch', 6 ); |
| 15 | +if ( ! is_numeric( $fetch_months ) ) { |
| 16 | + $fetch_months = 6; |
| 17 | +} |
| 18 | + |
| 19 | +$edo = EDUAPIHelper()->GetCourseDetailInfo( $course_id, $fetch_months, $group_by_city ); |
| 20 | + |
| 21 | +$organization = EDUAPIHelper()->GetOrganization(); |
| 22 | + |
| 23 | +$selected_course = false; |
| 24 | +$name = ''; |
| 25 | +if ( $edo ) { |
| 26 | + $selected_course = json_decode( $edo, true ); |
| 27 | + $name = ( ! empty( $selected_course['CourseName'] ) ? $selected_course['CourseName'] : $selected_course['InternalCourseName'] ); |
| 28 | + |
| 29 | + $is_ondemand = $selected_course['OnDemand']; |
| 30 | + |
| 31 | + if ( $is_ondemand ) { |
| 32 | + $selected_course = json_decode( EDUAPIHelper()->GetOnDemandCourseDetailInfo( $course_id, $group_by_city ), true ); |
| 33 | + } |
| 34 | + |
| 35 | + $description = wp_strip_all_tags( ! empty( $selected_course['CourseDescriptionShort'] ) ? $selected_course['CourseDescriptionShort'] : $selected_course['CourseDescription'] ); |
| 36 | + |
| 37 | + if ( strlen( $description ) > 60 ) { |
| 38 | + $description = substr( $description, 0, 57 ) . "..."; |
| 39 | + } |
| 40 | + |
| 41 | + if ( strlen( $description ) == 0 ) { |
| 42 | + return; |
| 43 | + } |
| 44 | + |
| 45 | + $org_name = trim( ! empty( $organization['LegalName'] ) ? $organization['LegalName'] : $organization['OrganisationName'] ); |
| 46 | + |
| 47 | + $events = null; |
| 48 | + |
| 49 | + foreach ( $selected_course['Events'] as $event ) { |
| 50 | + $_event = [ |
| 51 | + '@type' => 'CourseInstance', |
| 52 | + 'identifier' => (string)$event['EventId'] |
| 53 | + ]; |
| 54 | + |
| 55 | + if ( $is_ondemand ) { |
| 56 | + $_event['courseMode'] = "online"; |
| 57 | + $_event['location'] = "Online"; |
| 58 | + $_event['description'] = 'On-demand'; |
| 59 | + } else { |
| 60 | + $_event['location'] = $event['City']; |
| 61 | + $_event['startDate'] = $event['StartDate']; |
| 62 | + $_event['endDate'] = $event['EndDate']; |
| 63 | + } |
| 64 | + |
| 65 | + if ( ! empty( $event['MaxParticipantNumber'] ) && $event['MaxParticipantNumber'] > 0 ) { |
| 66 | + $_event['maximumAttendeeCapacity'] = $event['MaxParticipantNumber']; |
| 67 | + $_event['remainingAttendeeCapacity'] = $event['ParticipantNumberLeft']; |
| 68 | + } |
| 69 | + |
| 70 | + $events[] = $_event; |
| 71 | + } |
| 72 | + |
| 73 | + $ld_object = [ |
| 74 | + '@context' => 'https://schema.org', |
| 75 | + '@type' => 'Course', |
| 76 | + 'description' => $description, |
| 77 | + 'name' => $name, |
| 78 | + 'image' => $selected_course['ImageUrl'], |
| 79 | + 'coursePrerequisites' => $selected_course['Prerequisites'], |
| 80 | + 'provider' => [ |
| 81 | + '@type' => 'Organization', |
| 82 | + 'name' => $org_name, |
| 83 | + 'legalName' => trim( $organization['LegalName'] ), |
| 84 | + 'telephone' => $organization['Phone'], |
| 85 | + 'sameAs' => $organization['Web'], |
| 86 | + 'image' => $organization['LogoUrl'], |
| 87 | + ], |
| 88 | + 'hasCourseInstance' => $events, |
| 89 | + ]; |
| 90 | + |
| 91 | + echo '<script type="application/ld+json"> |
| 92 | +' . json_encode( $ld_object, JSON_PRETTY_PRINT ) . ' |
| 93 | +</script>'; |
| 94 | +} |
0 commit comments