]> _ Git - odl.git/commitdiff
wip #4804 @0.25
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 19 Oct 2021 18:21:12 +0000 (20:21 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 19 Oct 2021 18:21:12 +0000 (20:21 +0200)
app/Console/Commands/SearchIndex.php [new file with mode: 0644]
app/Console/Kernel.php
app/Jobs/SearchIndex.php [new file with mode: 0644]
composer.json

diff --git a/app/Console/Commands/SearchIndex.php b/app/Console/Commands/SearchIndex.php
new file mode 100644 (file)
index 0000000..b3bfb36
--- /dev/null
@@ -0,0 +1,17 @@
+<?php
+
+namespace App\Console\Commands;
+
+use Illuminate\Console\Command;
+
+class SearchIndex extends Command
+{
+    protected $signature = 'odl:searchindex';
+    protected $description = 'Make the search index';
+
+    public function handle()
+    {
+        \App\Jobs\SearchIndex::dispatchSync();
+    }
+
+}
index 938d8a1f9f3ecda74aa0317ec9d25c3536a0f9bf..1a488a904c12a3cf49efaf8b123bc5b885a5828e 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace App\Console;
 
+use App\Console\Commands\SearchIndex;
 use Illuminate\Console\Scheduling\Schedule;
 use Cubist\Backpack\Console\Kernel as CubistKernel;
 
@@ -13,7 +14,7 @@ class Kernel extends CubistKernel
      * @var array
      */
     protected $commands = [
-        //
+        SearchIndex::class
     ];
 
     /**
diff --git a/app/Jobs/SearchIndex.php b/app/Jobs/SearchIndex.php
new file mode 100644 (file)
index 0000000..8c1d342
--- /dev/null
@@ -0,0 +1,71 @@
+<?php
+
+namespace App\Jobs;
+
+use App\Models\Resource;
+use Cubist\Backpack\Magic\PageData;
+use Cubist\Minisearch\Document\PDF;
+use Cubist\Minisearch\Index;
+
+class SearchIndex extends Index
+{
+    public function __construct()
+    {
+        $this->output = storage_path('search.js');
+    }
+
+    public function handle()
+    {
+        $this->indexHome();
+        $this->indexLibrary();
+        $this->indexResources();
+        $this->indexTour();
+
+        parent::handle();
+    }
+
+    public function indexHome()
+    {
+
+    }
+
+    public function indexLibrary()
+    {
+
+    }
+
+    public function indexResources()
+    {
+        /** @var PageData $data */
+        $data = Resource::find('1')->getPageData();
+
+        $chapters = $data->get('chapters');
+        foreach ($chapters as $i => $chapter) {
+            foreach ($chapter['subchapters'] as $j => $subchapter) {
+                foreach ($subchapter['subchapter_memos'] as $k => $memo) {
+                    if (!$memo['memo_pdf']) {
+                        continue;
+                    }
+                    foreach ($data->getMediaPathsByCollection($memo['memo_pdf']) as $pdf) {
+                        $document = new PDF($pdf);
+                        $document->setId('resources_' . $i . '_' . $j . '_' . $k);
+                        $document->setUrl('resources_' . $i . '_' . $j . '_' . $k);
+                        $document->setTitle($memo['memo_title']);
+                        $document->setThumb($data->getImageURLbyCollection($memo['memo_image']));
+                        $document->setType('pdf');
+                        $this->addDocument($document);
+                        break;
+                    }
+
+                }
+            }
+        }
+
+    }
+
+    public function indexTour()
+    {
+
+    }
+
+}
index 76345cde315c7676d045091ed8b48867d90ec7b9..b572211b8971c3730ea5b398c698ce38b15e593a 100644 (file)
@@ -2,7 +2,10 @@
     "name": "odl/cube",
     "type": "project",
     "description": "ODL Framework.",
-    "keywords": ["framework", "laravel"],
+    "keywords": [
+        "framework",
+        "laravel"
+    ],
     "repositories": [
         {
             "type": "composer",
@@ -18,6 +21,7 @@
         "ext-tidy": "*",
         "ext-zip": "*",
         "cubist/cms-back": "dev-master",
+        "cubist/minisearch": "dev-master",
         "cubist/socialite": "dev-master",
         "fluidbook/tools": "dev-master",
         "fruitcake/laravel-cors": "^2.0",