From e84051ae212c1c590979ff7e1e51fd9ae210a0f6 Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Wed, 7 Aug 2024 15:26:44 +0300 Subject: [PATCH 1/4] add filters --- src/EloquentDataProvider.php | 7 ++++--- src/JSONCreator.php | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/EloquentDataProvider.php b/src/EloquentDataProvider.php index 8d1639f..853da54 100644 --- a/src/EloquentDataProvider.php +++ b/src/EloquentDataProvider.php @@ -4,6 +4,7 @@ namespace Itguild\EloquentTable; use Exception; use Illuminate\Database\Eloquent\Model; +use itguild\forms\debug\Debug; class EloquentDataProvider { @@ -19,6 +20,7 @@ class EloquentDataProvider protected array $options = []; protected array $meta = []; + protected array $filters = []; protected string $jsonStr = ''; /** @@ -46,10 +48,9 @@ class EloquentDataProvider $this->meta['baseUrl'] = $options['baseUrl'] ?? $model->table; $this->meta['params'] = $options['params'] ?? []; $this->meta['actions'] = $options['actions'] ?? []; + $this->filters = $options['filters'] ?? []; $this->createQuery(); - - $this->jsonStr = (new JSONCreator($this->meta, $this->getCollection()->toArray()))->getJson(); - + $this->jsonStr = (new JSONCreator($this->meta, $this->filters, $this->getCollection()->toArray()))->getJson(); } public function createQuery(): void diff --git a/src/JSONCreator.php b/src/JSONCreator.php index f6ce444..e3ee133 100644 --- a/src/JSONCreator.php +++ b/src/JSONCreator.php @@ -7,12 +7,13 @@ class JSONCreator { protected array $informationArray = []; - public function __construct(array $meta, array $data) + public function __construct(array $meta, array $filters, array $data) { $params = empty($meta['params']) ? ["class" => "table table-bordered", "border" => "1"] : $meta['params']; if ($meta) { $this->informationArray = [ "meta" => $meta, + "filters" => $filters, "data" => $data ?? [] ]; } From b4afddc7f7089686a28e879e344a8370e24f42c0 Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Wed, 7 Aug 2024 15:28:18 +0300 Subject: [PATCH 2/4] add filters --- src/JSONCreator.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/JSONCreator.php b/src/JSONCreator.php index e3ee133..8087da9 100644 --- a/src/JSONCreator.php +++ b/src/JSONCreator.php @@ -27,6 +27,7 @@ class JSONCreator { if ($infArr) return json_encode($infArr, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); + return null; } From cba0498e7d9826b041b8bb8df1812ed0d7ac1217 Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Wed, 7 Aug 2024 15:40:01 +0300 Subject: [PATCH 3/4] some fix --- composer.lock | 67 +++++++++++++++++++++++---------------------- src/JSONCreator.php | 2 +- 2 files changed, 35 insertions(+), 34 deletions(-) diff --git a/composer.lock b/composer.lock index 7a3f0cb..16bd908 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,36 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "23ab91e73c3a10e841f8f2b12f05e49d", + "content-hash": "ee2becfe4c626d6528700c6b89b77875", "packages": [ + { + "name": "itguild/tables", + "version": "0.1.14", + "source": { + "type": "git", + "url": "https://git.itguild.info/ItGuild/tables", + "reference": "9e7c83b680301497d15223a320e665279f9c2555" + }, + "type": "library", + "autoload": { + "psr-4": { + "Itguild\\Tables\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Kavalar", + "email": "apuc06@mail.ru" + } + ], + "time": "2024-08-07T11:31:07+00:00" + } + ], + "packages-dev": [ { "name": "brick/math", "version": "0.12.1", @@ -753,32 +781,6 @@ }, "time": "2024-08-05T14:24:50+00:00" }, - { - "name": "itguild/tables", - "version": "0.1.13", - "source": { - "type": "git", - "url": "https://git.itguild.info/ItGuild/tables", - "reference": "d98ddded07131f602486783f5f016002ea7d7fb7" - }, - "type": "library", - "autoload": { - "psr-4": { - "Itguild\\Tables\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Kavalar", - "email": "apuc06@mail.ru" - } - ], - "time": "2024-08-07T09:43:14+00:00" - }, { "name": "nesbot/carbon", "version": "dev-master", @@ -1752,12 +1754,12 @@ "source": { "type": "git", "url": "https://github.com/twbs/bootstrap.git", - "reference": "4e954ea3322e0a2c6428159108c676428a05d748" + "reference": "3083596e87146c1c5a61de7238cb69e1dab5ae8b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twbs/bootstrap/zipball/4e954ea3322e0a2c6428159108c676428a05d748", - "reference": "4e954ea3322e0a2c6428159108c676428a05d748", + "url": "https://api.github.com/repos/twbs/bootstrap/zipball/3083596e87146c1c5a61de7238cb69e1dab5ae8b", + "reference": "3083596e87146c1c5a61de7238cb69e1dab5ae8b", "shasum": "" }, "replace": { @@ -1795,7 +1797,7 @@ "issues": "https://github.com/twbs/bootstrap/issues", "source": "https://github.com/twbs/bootstrap/tree/main" }, - "time": "2024-08-07T04:51:04+00:00" + "time": "2024-08-07T10:11:06+00:00" }, { "name": "vlucas/phpdotenv", @@ -1957,7 +1959,6 @@ "time": "2022-03-08T17:03:00+00:00" } ], - "packages-dev": [], "aliases": [], "minimum-stability": "dev", "stability-flags": { @@ -1970,5 +1971,5 @@ "prefer-lowest": false, "platform": [], "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/src/JSONCreator.php b/src/JSONCreator.php index 8087da9..617262c 100644 --- a/src/JSONCreator.php +++ b/src/JSONCreator.php @@ -27,7 +27,7 @@ class JSONCreator { if ($infArr) return json_encode($infArr, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); - + return null; } From 850b0b315a77a1fdf7209757ede2523a0c16d46b Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Thu, 8 Aug 2024 11:15:07 +0300 Subject: [PATCH 4/4] fix JSON creator --- src/EloquentDataProvider.php | 2 +- src/JSONCreator.php | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/EloquentDataProvider.php b/src/EloquentDataProvider.php index 853da54..1d730b8 100644 --- a/src/EloquentDataProvider.php +++ b/src/EloquentDataProvider.php @@ -50,7 +50,7 @@ class EloquentDataProvider $this->meta['actions'] = $options['actions'] ?? []; $this->filters = $options['filters'] ?? []; $this->createQuery(); - $this->jsonStr = (new JSONCreator($this->meta, $this->filters, $this->getCollection()->toArray()))->getJson(); + $this->jsonStr = (new JSONCreator($this->meta, $this->getCollection()->toArray(), $this->filters,))->getJson(); } public function createQuery(): void diff --git a/src/JSONCreator.php b/src/JSONCreator.php index 617262c..05fea2c 100644 --- a/src/JSONCreator.php +++ b/src/JSONCreator.php @@ -7,7 +7,7 @@ class JSONCreator { protected array $informationArray = []; - public function __construct(array $meta, array $filters, array $data) + public function __construct(array $meta, array $data, array $filters = []) { $params = empty($meta['params']) ? ["class" => "table table-bordered", "border" => "1"] : $meta['params']; if ($meta) { @@ -27,7 +27,6 @@ class JSONCreator { if ($infArr) return json_encode($infArr, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); - return null; }