]> _ Git - pmi.git/commitdiff
fix #2926 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 23 Aug 2019 14:25:45 +0000 (16:25 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 23 Aug 2019 14:25:45 +0000 (16:25 +0200)
app/Http/Controllers/ApplicationController.php [new file with mode: 0644]
app/Models/Application.php
app/Templates/Solution.php
resources/views/pages/application.blade.php [new file with mode: 0644]
resources/views/pages/home.blade.php
resources/views/pages/solution.blade.php

diff --git a/app/Http/Controllers/ApplicationController.php b/app/Http/Controllers/ApplicationController.php
new file mode 100644 (file)
index 0000000..0c506d7
--- /dev/null
@@ -0,0 +1,23 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\Models\Application;
+use App\Models\Product;
+use Cubist\Backpack\app\Http\Controllers\CubistFrontController;
+use Cubist\Backpack\app\Magic\PageData;
+
+class ApplicationController extends CubistFrontController
+{
+    public function view($id)
+    {
+        $application = Application::find($id);
+
+        if (!$application) {
+            $this->_404();
+        }
+        $this->data['page'] = $application->getPageData();
+        $this->data['related'] = PageData::fromEntities(Product::with('media')->whereIn('id', $application->related)->get());
+        return view('pages.application', $this->data);
+    }
+}
index 9ce59a29bd5626dd7d13de9d6cf8df50663daa11..5d001166878108e68ffc4c74cf9915eda3b45c67 100644 (file)
@@ -5,15 +5,26 @@ namespace App\Models;
 
 
 use Cubist\Backpack\app\Magic\Models\CubistMagicPageModel;
+use Spatie\MediaLibrary\Models\Media;
 
 class Application extends CubistMagicPageModel
 {
+
+
     protected $table = 'applications';
 
     protected $_options = ['name' => 'application',
         'singular' => 'application',
         'plural' => 'applications'];
 
+    public function registerMediaConversions(Media $media = null) {
+
+        parent::registerMediaConversions($media);
+
+        $this->addMediaConversion('thumb')
+            ->crop('crop-center', 348, 232);
+    }
+
     public function setFields()
     {
         $this->addField(['name' => 'title',
index 07e7b8c54c1ef580cc3c3b8d3a66f555b657cef3..5b35ffba57e48b4930dacf5f2e4adb84e2d921bb 100644 (file)
@@ -3,11 +3,65 @@
 
 namespace App\Templates;
 
+use App\Models\Application;
+use Barryvdh\Debugbar\Facade as Debugbar;
+use Cubist\Backpack\app\Magic\Menu\Item;
+use Cubist\Backpack\app\Magic\PageData;
 
 class Solution extends Base
 {
+    protected static $_menuChildrenDone = false;
+
     public function getName()
     {
         return 'Solution';
     }
+
+    public function init()
+    {
+        parent::init();
+
+        $this->addField(['name' => 'applications',
+            'label' => 'Applications',
+            'type' => 'SelectFromModel',
+            'optionsmodel' => 'App\Models\Application',
+            'attribute' => 'title_solutions',
+            'order' => true,
+            'multiple' => true,
+            'tab' => 'Applications']);
+    }
+
+    public function setMenuChildren($menu)
+    {
+        if (self::$_menuChildrenDone) {
+            return;
+        }
+
+        self::$_menuChildrenDone = true;
+
+        Debugbar::startMeasure('nav_applications', 'Make applications nav items');
+        parent::setMenuChildren($menu);
+
+        $applications = Application::all();
+
+        foreach ($applications as $application) {
+            $item = new Item();
+            $item->setTitle($application->title);
+            $item->setHref($application->getSlugOrTitleAttribute());
+            $item->setId('application/' . $application->id);
+            $item->setController(['controller' => 'ApplicationController', 'action' => 'view', 'params' => ['id' => $application->id]]);
+            $menu->addChild($item);
+        }
+
+        Debugbar::stopMeasure('nav_applications');
+    }
+
+    public function setData(&$data)
+    {
+        if (null === $data['page']->applications) {
+            $data['applications'] = [];
+            return;
+        }
+        $data['applications'] = PageData::fromEntities(Application::whereIn('id', $data['page']->applications)->get());
+    }
 }
diff --git a/resources/views/pages/application.blade.php b/resources/views/pages/application.blade.php
new file mode 100644 (file)
index 0000000..168934c
--- /dev/null
@@ -0,0 +1,34 @@
+@extends('layouts/app')
+
+@section('content')
+
+    <full-width padding="pb-2v">
+        <content>
+            <text-block :title="$page->title" title-tag="h1"/>
+
+            <div class="news-post-layout">
+                {{-- Todo: use larger image + srcset here --}}
+                <img src="{{ $page->getImageURL('image','thumb') }}" alt="{{ $page->title }}" class="news-post-image">
+
+                <div class="news-post-body">
+                    @markdown($page->content)
+                </div>
+            </div>
+        </content>
+    </full-width>
+
+    <full-width class="bg-grey-100">
+        <content>
+
+            <text-block :title="__('Sélection de produits')" title-class="h2"/>
+
+            {{-- Product Grid --}}
+            <grid cols="auto" class="products-grid">
+                @foreach($related as $id=>$rel)
+                    @include('partials.product-link',['id'=>$id,'product'=>$rel])
+                @endforeach
+            </grid>
+
+        </content>
+    </full-width>
+@endsection
index 5d84449c256d08242fecb6a281d7fa9c16c26729..c500fd58d54e2ee09338e8e3054f50ee727580bb 100644 (file)
@@ -95,7 +95,7 @@
     {{-- Solutions / Applications --}}
     <full-width class="bg-navy text-white antialiased">
         <content>
-            <text-block title-class="h1 text-inherit" title="Solutions / Applications"/>
+            <text-block title-class="h1 text-inherit" :title="__('Solutions / Applications')"/>
 
             <grid cols="3" class="sm:grid-cols-2 xs:grid-cols-1">
                 @foreach ($page->get('solutions', []) as $solution)
index b26799e7ac7038ac983cbeea5be7d76166be1569..abec4c4bd9e282fe5202b63359c8cf2b8c664354 100644 (file)
@@ -4,4 +4,20 @@
 
     @intro(['padding' => 'pb-4v'])
 
+    <full-width class="bg-grey-100 antialiased">
+        <content>
+            <text-block title-class="h1" :title="__('Applications')"/>
+
+            <grid cols="4" class="sm:grid-cols-2 xs:grid-cols-1">
+                @foreach ($applications as $application)
+                    <a class="solutions-link" href="{{ $nav->getHrefByID('application/'.$application->id) }}">
+                        <span class="solutions-link-bg"
+                              style="background-image:url({{ $application->getImageURLbyCollection($application['image_solutions']) }})"></span>
+                        <span class="solutions-link-text">{{ $application->title_solutions }}</span>
+                    </a>
+                @endforeach
+            </grid>
+
+        </content>
+    </full-width>
 @endsection