From bd755622a7b4a25b71ee0999b62feb63485b6a55 Mon Sep 17 00:00:00 2001 From: soufiane Date: Thu, 18 Jan 2024 17:54:43 +0100 Subject: [PATCH] wait #6564 @5:00 --- .../Elementor/Widgets/FluxPostCarousel.php | 95 +++++++++++++++++-- .../assets/scripts/flux-post-carousel.js | 4 + .../physioassist/resources/functions.php | 29 +++--- .../resources/views/partials/post.blade.php | 17 +++- .../widgets/flux-post-carousel.blade.php | 4 - 5 files changed, 117 insertions(+), 32 deletions(-) diff --git a/wp-content/mu-plugins/physioassist/src/Elementor/Widgets/FluxPostCarousel.php b/wp-content/mu-plugins/physioassist/src/Elementor/Widgets/FluxPostCarousel.php index b75eff20..7669b802 100644 --- a/wp-content/mu-plugins/physioassist/src/Elementor/Widgets/FluxPostCarousel.php +++ b/wp-content/mu-plugins/physioassist/src/Elementor/Widgets/FluxPostCarousel.php @@ -2,6 +2,7 @@ namespace PhysioAssist\Elementor\Widgets; +use Elementor\Repeater; use Elementor\Widget_Base; use Elementor\Controls_Manager; use Elementor\Scheme_Color; @@ -82,6 +83,76 @@ class FluxPostCarousel extends Widget_Base { ] ); + $repeater = new Repeater(); + + $repeater->add_control( + 'category', + [ + 'label' => __( 'Category', 'cube' ), + 'type' => Controls_Manager::SELECT, + 'options' => array_combine(array_column($this->getCats(), 'term_id'),array_column($this->getCats(), 'name')) + ] + ); + + $repeater->add_control( + 'post_date', + [ + 'label' => esc_html__( 'Date', 'textdomain' ), + 'type' => Controls_Manager::DATE_TIME, + ] + ); + + $repeater->add_control( + 'post_title', + [ + 'label' => __( 'Title', 'elementor' ), + 'type' => Controls_Manager::TEXT, + 'placeholder' => __( 'Enter your title', 'elementor' ), + 'default' => '', + ] + ); + + $repeater->add_control( + 'subtitle', + [ + 'label' => __( 'Subtitle', 'cube' ), + 'type' => Controls_Manager::TEXTAREA, + 'label_block' => true, + ] + ); + + $repeater->add_control( + 'cta_text', + [ + 'label' => __('Call to Action text', 'cube'), + 'type' => Controls_Manager::TEXT, + 'default' => '' + ] + ); + + $repeater->add_control( + 'cta_link', + [ + 'label' => __('Call to Action link', 'cube'), + 'type' => Controls_Manager::URL, + 'default' => [ + 'url' => '', + 'is_external' => false, + ], + 'show_external' => true + ] + ); + + $this->add_control( + 'items', + [ + 'label' => __( 'Items', 'cube' ), + 'type' => Controls_Manager::REPEATER, + 'fields' => $repeater->get_controls(), + 'title_field' => '{{{ post_title }}}', + ] + ); + $this->add_control( 'cta_text', [ @@ -109,17 +180,10 @@ class FluxPostCarousel extends Widget_Base { * @access protected */ protected function render() { - $newsCat = get_category_by_slug('news'); - $categories = get_terms([ - 'taxonomy' => 'category', - 'hide_empty' => false, - 'exclude' => [$newsCat->term_id] - ]); - $categoriesId = array_map(function($n){ return $n->term_id; },$categories); - $args = ['category__in'=>$categoriesId,'posts_per_page'=> -1]; - $items = get_posts($args); + $categories = $this->getCats(); $title = $this->get_settings('title'); + $items = $this->get_settings('items'); $cta = [ 'cta_text' => $this->get_settings('cta_text'), @@ -129,4 +193,17 @@ class FluxPostCarousel extends Widget_Base { echo template('widgets/flux-post-carousel', compact('items','categories', 'title', 'cta')); } + public function getCats() { + $newsCat = get_category_by_slug('news'); + return get_terms([ + 'taxonomy' => 'category', + 'hide_empty' => false, + 'exclude' => [$newsCat->term_id] + ]); + } + + public function getItems() { + return $this->get_settings('items'); + } + } \ No newline at end of file diff --git a/wp-content/themes/physioassist/resources/assets/scripts/flux-post-carousel.js b/wp-content/themes/physioassist/resources/assets/scripts/flux-post-carousel.js index 80f8a460..50cdc82b 100644 --- a/wp-content/themes/physioassist/resources/assets/scripts/flux-post-carousel.js +++ b/wp-content/themes/physioassist/resources/assets/scripts/flux-post-carousel.js @@ -11,6 +11,8 @@ } $(document).on("click", ".flux-post-carousel-filter-item", function() { + let widget_id = $scope.find(".flux-post-carousel").parents(".elementor-widget").data('id') + let section_id = $scope.find(".flux-post-carousel").parents(".elementor-section").data('id') let cat = $(this).data("cat") $(".flux-post-carousel-filter-item").addClass("inactive") $(this).removeClass("inactive") @@ -21,6 +23,8 @@ data: { action: 'flux_posts', cat: cat, + widget_id: widget_id, + section_id: section_id, }, success: function (res) { $scope.find('.flux-post-carousel').html(res).removeClass('slick-initialized'); diff --git a/wp-content/themes/physioassist/resources/functions.php b/wp-content/themes/physioassist/resources/functions.php index 1dae87d7..3f5f0d9a 100644 --- a/wp-content/themes/physioassist/resources/functions.php +++ b/wp-content/themes/physioassist/resources/functions.php @@ -4,9 +4,11 @@ * Do not edit anything in this file unless you know what you're doing */ +use Elementor\Plugin; use Roots\Sage\Config; use Roots\Sage\Container; use function App\template; +use PhysioAssist\Elementor\Widgets\FluxPostCarousel; /** * Helper function for prettying up errors @@ -102,26 +104,23 @@ add_filter('theme_file_path', function($path, $file) { function flux_posts() { $catId = $_POST['cat']; + $widgetId = $_POST['widget_id']; + $sectionId = $_POST['section_id']; - $newsCat = get_category_by_slug('news'); - $categories = get_terms([ - 'taxonomy' => 'category', - 'hide_empty' => false, - 'exclude' => [$newsCat->term_id] - ]); + $widget_settings = get_post_meta(1406, '_elementor_data', true); + $widget_settings = json_decode($widget_settings,true); - $categoriesId = array_map(function($n){ return $n->term_id; },$categories); + $items = array_filter($widget_settings, function($n) use($sectionId) { return $n['id'] === $sectionId; }); + $items = array_values($items); + $items = $items[0]['elements'][0]['elements'][0]['settings']['items']; + + if($catId) { + $items = array_filter($items, function($n) use($catId) { return $n['category'] === $catId; }); + } - $posts = get_posts([ - 'posts_per_page' => -1, - 'category__in' => !empty($catId) ? [$catId] : $categoriesId, - 'order' => 'desc' - ]); $current_language = apply_filters( 'wpml_current_language', NULL ); - foreach ($posts as $item) { - $translated_id = apply_filters('wpml_object_id', $item->ID, 'post'); - $item = get_post($translated_id); + foreach ($items as $item) { echo template('partials/post', compact('item')); } diff --git a/wp-content/themes/physioassist/resources/views/partials/post.blade.php b/wp-content/themes/physioassist/resources/views/partials/post.blade.php index a005a061..48969146 100644 --- a/wp-content/themes/physioassist/resources/views/partials/post.blade.php +++ b/wp-content/themes/physioassist/resources/views/partials/post.blade.php @@ -4,9 +4,18 @@ $format = $current_language === "en" ? "Y/m" : "m/Y";
-

{!! date($format, strtotime($item->post_date)) !!}

-

{{ $item->post_title }}

-

{{ $item->subtitle }}

- @svg('arrow') {{ __('Read more', 'sage') }} + @if (!empty($item['post_date'])) +

{!! date($format, strtotime($item['post_date'])) !!}

+ @endif +

{{ $item['post_title'] }}

+

{{ $item['subtitle'] }}

+ @if (!empty($item['cta_text'])) + + @svg('arrow') {{ $item['cta_text'] }} + + @endif
{{-- .flux-post-carousel-item-content --}}
{{-- .flux-post-carousel-item --}} diff --git a/wp-content/themes/physioassist/resources/views/widgets/flux-post-carousel.blade.php b/wp-content/themes/physioassist/resources/views/widgets/flux-post-carousel.blade.php index df9c6683..40821aae 100644 --- a/wp-content/themes/physioassist/resources/views/widgets/flux-post-carousel.blade.php +++ b/wp-content/themes/physioassist/resources/views/widgets/flux-post-carousel.blade.php @@ -57,10 +57,6 @@
@foreach ($items as $item) - @php - $translated_id = apply_filters('wpml_object_id', $item->ID, 'post'); - $item = get_post($translated_id); - @endphp @include('partials.post') @endforeach -- 2.39.5