]> _ Git - physioassist-wordpress.git/commitdiff
wait #6564 @5:00
authorsoufiane <soufiane@cubedesigners.com>
Thu, 18 Jan 2024 16:54:43 +0000 (17:54 +0100)
committersoufiane <soufiane@cubedesigners.com>
Thu, 18 Jan 2024 16:54:43 +0000 (17:54 +0100)
wp-content/mu-plugins/physioassist/src/Elementor/Widgets/FluxPostCarousel.php
wp-content/themes/physioassist/resources/assets/scripts/flux-post-carousel.js
wp-content/themes/physioassist/resources/functions.php
wp-content/themes/physioassist/resources/views/partials/post.blade.php
wp-content/themes/physioassist/resources/views/widgets/flux-post-carousel.blade.php

index b75eff20dc33b2001367f16a10369e2c76b2f0c2..7669b802ec4697143496e7e593bb2105317f10a0 100644 (file)
@@ -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
index 80f8a46026213d52ff1d2bc2f301159242144316..50cdc82b9c6475db8ebe7f438bbe611d0619b231 100644 (file)
@@ -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');
index 1dae87d74f6ca8284df40a1bda4fc713d71f3331..3f5f0d9ac8f43393ef4e11883f94f776808084db 100644 (file)
@@ -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'));
     }
 
index a005a0617607dd28e5d9ecee94ffe1d498516e50..48969146f1cd2cb85c759a56e6df3913b69dc1f3 100644 (file)
@@ -4,9 +4,18 @@ $format = $current_language === "en" ? "Y/m" : "m/Y";
 
 <div class="text-carousel-item flux-post-carousel-item slick-slide">
   <div class="flux-post-carousel-item-content">
-    <p class="flux-post-carousel-date">{!! date($format, strtotime($item->post_date)) !!}</p>
-    <h3 class="flux-post-carousel-title">{{ $item->post_title }}</h3>
-    <p class="flux-post-carousel-subtitle">{{ $item->subtitle }}</p>
-    <a href="{{ get_the_permalink($item->ID) }}" class="arrow-link">@svg('arrow') {{ __('Read more', 'sage') }}</a>
+    @if (!empty($item['post_date']))
+    <p class="flux-post-carousel-date">{!! date($format, strtotime($item['post_date'])) !!}</p>
+    @endif
+    <h3 class="flux-post-carousel-title">{{ $item['post_title'] }}</h3>
+    <p class="flux-post-carousel-subtitle">{{ $item['subtitle'] }}</p>
+    @if (!empty($item['cta_text']))
+      <a href="{{ $item['cta_link']['url'] }}" class="arrow-link"
+         @if ($item['cta_link']['is_external']) target="_blank" @endif
+         @if ($item['cta_link']['nofollow']) rel="noopener" @endif
+      >
+        @svg('arrow') {{ $item['cta_text'] }}
+      </a>
+    @endif
   </div>  {{-- .flux-post-carousel-item-content --}}
 </div> {{-- .flux-post-carousel-item --}}
index df9c6683b550a97ac84960f9d3d9fc3907d47639..40821aae9a6c7ad131ee5c770a27a9f7da255fe1 100644 (file)
   <div class="flux-post-carousel elementor-slick-slider" data-slick="{{ $slick }}">
 
     @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