From 52f592a42828df9c0fa482db31fd12d16f26d2c0 Mon Sep 17 00:00:00 2001 From: Szymon Kasprzyk Date: Fri, 11 Aug 2023 14:42:48 +0200 Subject: [PATCH] adds related courses plugin --- .../plugins/vf-related-courses/README.md | 1 + .../group_vf_related_courses.json | 48 ++++++ .../plugins/vf-related-courses/index.php | 112 ++++++++++++ .../plugins/vf-related-courses/template.php | 161 ++++++++++++++++++ wp-content/themes/vf-wp/functions.php | 1 + 5 files changed, 323 insertions(+) create mode 100644 wp-content/plugins/vf-related-courses/README.md create mode 100644 wp-content/plugins/vf-related-courses/group_vf_related_courses.json create mode 100644 wp-content/plugins/vf-related-courses/index.php create mode 100644 wp-content/plugins/vf-related-courses/template.php diff --git a/wp-content/plugins/vf-related-courses/README.md b/wp-content/plugins/vf-related-courses/README.md new file mode 100644 index 000000000..8c1acc93e --- /dev/null +++ b/wp-content/plugins/vf-related-courses/README.md @@ -0,0 +1 @@ +# Related Courses block diff --git a/wp-content/plugins/vf-related-courses/group_vf_related_courses.json b/wp-content/plugins/vf-related-courses/group_vf_related_courses.json new file mode 100644 index 000000000..d6b0b2dbd --- /dev/null +++ b/wp-content/plugins/vf-related-courses/group_vf_related_courses.json @@ -0,0 +1,48 @@ +{ + "key": "group_64d615352f1a3", + "title": "Related Courses", + "fields": [ + { + "key": "field_64d61570693c4", + "label": "Related courses", + "name": "vf_related_courses", + "type": "relationship", + "instructions": "", + "required": 0, + "conditional_logic": 0, + "wrapper": { + "width": "", + "class": "", + "id": "" + }, + "post_type": [ + "training" + ], + "taxonomy": "", + "filters": [ + "search" + ], + "elements": "", + "min": "", + "max": "", + "return_format": "object" + } + ], + "location": [ + [ + { + "param": "block", + "operator": "==", + "value": "acf\/vf-related-courses" + } + ] + ], + "menu_order": 0, + "position": "normal", + "style": "seamless", + "label_placement": "top", + "instruction_placement": "label", + "hide_on_screen": "", + "active": true, + "description": "" +} \ No newline at end of file diff --git a/wp-content/plugins/vf-related-courses/index.php b/wp-content/plugins/vf-related-courses/index.php new file mode 100644 index 000000000..3e96b8b28 --- /dev/null +++ b/wp-content/plugins/vf-related-courses/index.php @@ -0,0 +1,112 @@ + $this->get_name(), + 'title' => __('Related Courses', 'vfwp'), + 'category' => $category, + 'supports' => array( + 'align' => false, + 'customClassName' => false + ) + ); + } + + /** + * Return block render template path + */ + public function get_template() { + // Allow themes to provide a custom template + $template = locate_template( + "blocks/{$this->get_name()}.php", + false, false + ); + // Otherwise default to the plugin template + if ( ! file_exists($template)) { + $template = plugin_dir_path(__FILE__) . 'template.php'; + } + return $template; + } + + /** + * Action: `after_setup_theme` + */ + public function after_setup_theme() { + // Setup render callback using VF Gutenberg plugin or fallback + $callback = function() { + $args = func_get_args(); + $template = $this->get_template(); + if (class_exists('VF_Gutenberg')) { + VF_Gutenberg::acf_render_template($args, $template); + } else { + $block = $args[0]; + include($template); + } + }; + // Register the Gutenberg block with ACF + acf_register_block_type(array_merge( + $this->get_config(), + array( + 'render_callback' => $callback + ) + )); + } + + /** + * Filter: `acf/settings/load_json` + */ + public function acf_settings_load_json($paths) { + $paths[] = plugin_dir_path(__FILE__); + return $paths; + } + +} // VF_Related_Courses + +// Initialize one instance +$vf_related_courses = new VF_Related_Courses(); + +endif; + +?> diff --git a/wp-content/plugins/vf-related-courses/template.php b/wp-content/plugins/vf-related-courses/template.php new file mode 100644 index 000000000..d561feb84 --- /dev/null +++ b/wp-content/plugins/vf-related-courses/template.php @@ -0,0 +1,161 @@ + +
+
+

+ +

+
+
+ + + + +
+ format('Y-m-d'); + $organiser = get_the_terms( $relatedCourse->ID , 'training-organiser' ); + $location = get_the_terms( $relatedCourse->ID , 'event-location' ); + $start_date = get_field('vf-wp-training-start_date',$relatedCourse->ID); + $start_time = get_field('vf-wp-training-start_time',$relatedCourse->ID); + $start = DateTime::createFromFormat('j M Y', $start_date); + $start_time_format = DateTime::createFromFormat('H:i', $start_time); + $end_date = get_field('vf-wp-training-end_date',$relatedCourse->ID); + $end_time = get_field('vf-wp-training-end_time',$relatedCourse->ID); + $end_time_format = DateTime::createFromFormat('H:i', $end_time); + $end = DateTime::createFromFormat('j M Y', $end_date); + $end_date_format = DateTime::createFromFormat('j M Y', $end_date); + $registrationStatus = get_field('vf-wp-training-registration-status',$relatedCourse->ID); + $registrationDeadline = get_field('vf-wp-training-registration-deadline',$relatedCourse->ID); + $deadlineDate = new DateTime($registrationDeadline); + $registrationDeadlineFormatted = $deadlineDate->format('Y-m-d'); + $venue = get_field('vf-wp-training-venue',$relatedCourse->ID); + $additionalInfo = get_field('vf-wp-training-info',$relatedCourse->ID); + $relatedCoursePermalink = get_permalink( $relatedCourse->ID ); + $relatedCourseTitle = get_the_title($relatedCourse->ID ); + + + if (!empty($start_time)) { + $calendar_start_time = 'T' . $start_time_format->format('Hi') . '00'; + } + else { + $calendar_start_time = ''; + } + + if (!empty($end_time)) { + $calendar_end_time = 'T' . $end_time_format->format('Hi') . '00'; + } + elseif (empty($end_time) && !empty($start_time)) { + $calendar_end_time = 'T' . $start_time_format->format('Hi') . '00'; + } + else { + $calendar_end_time = ''; + } + + if (!empty($end_date)) { + $calendar_end_date = '/' . $end->format('Ymd'); + } + else { + $calendar_end_date = '/' . $start->format('Ymd'); + } + ?> +
+ +

+ format('M') == $end->format('M')) { + echo $start->format('j'); ?> - format('j F Y'); } + else { + echo $start->format('j M'); ?> - format('j F Y'); } + } + else { + echo $start->format('j F Y'); + } ?> +

+ + +

+ +

+
+
+ +
+

+ + + name); } + echo implode(', ', $org_list); ?> + + + Location:  + + + name; } + echo implode(', ', $loc_list); ?> + + Registration:  + Open'; + } + else if ($registrationStatus == 'Closed') { + echo 'Closed'; + } + else if ($registrationStatus == 'Waiting list only') { + echo 'Waiting list only'; + } + else { + echo '' . $registrationStatus . ''; + } + } + else { + if ($registrationDeadlineFormatted >= $current_date) { + echo 'Open'; + } + else { + echo 'Closed'; + } + } + ?> +

+
+
+ + + + +
diff --git a/wp-content/themes/vf-wp/functions.php b/wp-content/themes/vf-wp/functions.php index cea808774..422f0939b 100644 --- a/wp-content/themes/vf-wp/functions.php +++ b/wp-content/themes/vf-wp/functions.php @@ -209,6 +209,7 @@ function allowed_block_types($allowed_blocks) { 'acf/vf-members-internal', 'acf/vf-person', 'acf/vf-person-internal', + 'acf/vf-related-courses', 'acf/vf-events-list', 'acf/vf-group-header', 'acf/vf-jobs',