diff --git a/composer.json b/composer.json index 966ecb9..76f3f84 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,8 @@ "itguild/tables": "^0.1.3", "madesimple/php-form-validator": "^2.9", "itguild/forms": "^0.1.1", - "samejack/php-argv": "dev-master" + "samejack/php-argv": "dev-master", + "itguild/eloquent-table": "^0.2.0" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index aad281a..2f008d4 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "05960b2d73dd4ee5a824e5a9416486b2", + "content-hash": "f12e70f90d120b5b660f18c367fc7c7b", "packages": [ { "name": "brick/math", @@ -337,16 +337,16 @@ }, { "name": "illuminate/collections", - "version": "v11.19.0", + "version": "v11.20.0", "source": { "type": "git", "url": "https://github.com/illuminate/collections.git", - "reference": "2be24113fe25ef18be33bbd083ad36bf1e751eb5" + "reference": "dc68a7ccad93f3c2baa0bc8f559431c06391aa75" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/collections/zipball/2be24113fe25ef18be33bbd083ad36bf1e751eb5", - "reference": "2be24113fe25ef18be33bbd083ad36bf1e751eb5", + "url": "https://api.github.com/repos/illuminate/collections/zipball/dc68a7ccad93f3c2baa0bc8f559431c06391aa75", + "reference": "dc68a7ccad93f3c2baa0bc8f559431c06391aa75", "shasum": "" }, "require": { @@ -388,11 +388,11 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-07-23T14:08:10+00:00" + "time": "2024-08-01T18:54:27+00:00" }, { "name": "illuminate/conditionable", - "version": "v11.19.0", + "version": "v11.20.0", "source": { "type": "git", "url": "https://github.com/illuminate/conditionable.git", @@ -438,16 +438,16 @@ }, { "name": "illuminate/container", - "version": "v11.19.0", + "version": "v11.20.0", "source": { "type": "git", "url": "https://github.com/illuminate/container.git", - "reference": "122c62229b209678013c0833793d7cf94d14bbbd" + "reference": "f47be671981a4438257c4fbfc3ad257f4e3e929a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/container/zipball/122c62229b209678013c0833793d7cf94d14bbbd", - "reference": "122c62229b209678013c0833793d7cf94d14bbbd", + "url": "https://api.github.com/repos/illuminate/container/zipball/f47be671981a4438257c4fbfc3ad257f4e3e929a", + "reference": "f47be671981a4438257c4fbfc3ad257f4e3e929a", "shasum": "" }, "require": { @@ -485,20 +485,20 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-07-26T06:12:27+00:00" + "time": "2024-08-05T15:04:01+00:00" }, { "name": "illuminate/contracts", - "version": "v11.19.0", + "version": "v11.20.0", "source": { "type": "git", "url": "https://github.com/illuminate/contracts.git", - "reference": "ebe2b8d69b8fb1c07111e3500d464e77dfab3202" + "reference": "34ead9385e0eab7e947807d77da66faf9bdf95ff" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/contracts/zipball/ebe2b8d69b8fb1c07111e3500d464e77dfab3202", - "reference": "ebe2b8d69b8fb1c07111e3500d464e77dfab3202", + "url": "https://api.github.com/repos/illuminate/contracts/zipball/34ead9385e0eab7e947807d77da66faf9bdf95ff", + "reference": "34ead9385e0eab7e947807d77da66faf9bdf95ff", "shasum": "" }, "require": { @@ -533,20 +533,20 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-07-29T06:48:51+00:00" + "time": "2024-08-01T19:08:33+00:00" }, { "name": "illuminate/database", - "version": "v11.19.0", + "version": "v11.20.0", "source": { "type": "git", "url": "https://github.com/illuminate/database.git", - "reference": "db151e9a3221705cb4149c39dce2c51799708637" + "reference": "dae4ab28c830a906a410a168d8ece8fb4ab7b2be" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/database/zipball/db151e9a3221705cb4149c39dce2c51799708637", - "reference": "db151e9a3221705cb4149c39dce2c51799708637", + "url": "https://api.github.com/repos/illuminate/database/zipball/dae4ab28c830a906a410a168d8ece8fb4ab7b2be", + "reference": "dae4ab28c830a906a410a168d8ece8fb4ab7b2be", "shasum": "" }, "require": { @@ -601,11 +601,11 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-07-30T07:00:12+00:00" + "time": "2024-08-06T14:16:43+00:00" }, { "name": "illuminate/filesystem", - "version": "v11.19.0", + "version": "v11.20.0", "source": { "type": "git", "url": "https://github.com/illuminate/filesystem.git", @@ -672,7 +672,7 @@ }, { "name": "illuminate/macroable", - "version": "v11.19.0", + "version": "v11.20.0", "source": { "type": "git", "url": "https://github.com/illuminate/macroable.git", @@ -718,16 +718,16 @@ }, { "name": "illuminate/support", - "version": "v11.19.0", + "version": "v11.20.0", "source": { "type": "git", "url": "https://github.com/illuminate/support.git", - "reference": "f3c19ee61d875dca1045df2d90000ae97f1645f9" + "reference": "40457b4694486e506bad1b5be6de8dc86afce46f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/support/zipball/f3c19ee61d875dca1045df2d90000ae97f1645f9", - "reference": "f3c19ee61d875dca1045df2d90000ae97f1645f9", + "url": "https://api.github.com/repos/illuminate/support/zipball/40457b4694486e506bad1b5be6de8dc86afce46f", + "reference": "40457b4694486e506bad1b5be6de8dc86afce46f", "shasum": "" }, "require": { @@ -788,7 +788,42 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-07-30T06:57:25+00:00" + "time": "2024-08-06T14:20:50+00:00" + }, + { + "name": "itguild/eloquent-table", + "version": "0.2", + "source": { + "type": "git", + "url": "https://git.itguild.info/ItGuild/eloquent_table", + "reference": "59e065458d8db8690944751b0e2e8e394e250fe9" + }, + "require": { + "itguild/tables": "^0.1.9" + }, + "require-dev": { + "illuminate/database": "^12.0@dev", + "illuminate/filesystem": "^12.0@dev", + "twbs/bootstrap": "dev-main", + "vlucas/phpdotenv": "^5.6@dev" + }, + "type": "library", + "autoload": { + "psr-4": { + "Itguild\\EloquentTable\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Kavalar", + "email": "apuc06@mail.ru" + } + ], + "time": "2024-08-07T10:27:11+00:00" }, { "name": "itguild/forms", @@ -851,11 +886,11 @@ }, { "name": "itguild/tables", - "version": "0.1.8", + "version": "0.1.13", "source": { "type": "git", "url": "https://git.itguild.info/ItGuild/tables", - "reference": "d6d703aaa6ea26005b029d1110b96b268ea30fe7" + "reference": "d98ddded07131f602486783f5f016002ea7d7fb7" }, "type": "library", "autoload": { @@ -873,7 +908,7 @@ "email": "apuc06@mail.ru" } ], - "time": "2024-07-31T09:48:26+00:00" + "time": "2024-08-07T09:43:14+00:00" }, { "name": "madesimple/php-arrays", @@ -2384,5 +2419,5 @@ "prefer-lowest": false, "platform": [], "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/kernel/IGTabel/EloquentDataProvider.php b/kernel/IGTabel/EloquentDataProvider.php index db0d53f..2efe235 100644 --- a/kernel/IGTabel/EloquentDataProvider.php +++ b/kernel/IGTabel/EloquentDataProvider.php @@ -1,78 +1,78 @@ queryBuilder = $source::query(); - $model = new $source(); - } elseif (is_object($source)) { - $this->queryBuilder = $source; - $model = $source->getModel(); - } else { - throw new Exception(message: "source is not valid"); - } - $this->options = $options; - $this->currentPage = $this->options['currentPage'] ?? 1; - $this->perPage = $this->options['perPage'] ?? 10; - $this->meta['total'] = $model->count(); - $this->meta['totalWithFilters'] = $this->queryBuilder->count(); - $this->meta['columns'] = $options['columns'] ?? $model->labels(); - $this->meta['perPage'] = $options['perPage'] ?? 10; - $this->meta['currentPage'] = $options['currentPage'] ?? 1; - $this->meta['baseUrl'] = $options['baseUrl'] ?? $model->table; - $this->meta['params'] = $options['params'] ?? []; - $this->meta['actions'] = $options['actions'] ?? []; - $this->createQuery(); - - $this->jsonStr = (new JSONCreator($this->meta, $this->getCollection()->toArray()))->getJson(); - - } - - public function createQuery(): void - { - if ($this->currentPage > 1) { - $this->queryBuilder->skip(($this->currentPage - 1) * $this->perPage)->take($this->perPage); - } else { - $this->queryBuilder->take($this->perPage); - } - } - - public function getCollection() - { - return $this->queryBuilder->get(); - } - - /** - * @return string|null - */ - public function getJson(): string|null - { - return $this->jsonStr; - } - -} \ No newline at end of file +// +//namespace kernel\IGTabel; +// +//use app\helpers\Debug; +//use Exception; +//use Illuminate\Database\Eloquent\Model; +// +//class EloquentDataProvider +//{ +// protected int $totalCount; +// +// protected int $perPage = 10; +// +// protected int $currentPage = 1; +// +// protected Model $model; +// +// protected $queryBuilder = false; +// +// protected array $options = []; +// protected array $meta = []; +// protected string $jsonStr = ''; +// +// /** +// * @throws Exception +// */ +// public function __construct($source, array $options) +// { +// if (is_string($source)) { +// $this->queryBuilder = $source::query(); +// $model = new $source(); +// } elseif (is_object($source)) { +// $this->queryBuilder = $source; +// $model = $source->getModel(); +// } else { +// throw new Exception(message: "source is not valid"); +// } +// $this->options = $options; +// $this->currentPage = $this->options['currentPage'] ?? 1; +// $this->perPage = $this->options['perPage'] ?? 10; +// $this->meta['total'] = $model->count(); +// $this->meta['totalWithFilters'] = $this->queryBuilder->count(); +// $this->meta['columns'] = $options['columns'] ?? $model->labels(); +// $this->meta['perPage'] = $options['perPage'] ?? 10; +// $this->meta['currentPage'] = $options['currentPage'] ?? 1; +// $this->meta['baseUrl'] = $options['baseUrl'] ?? $model->table; +// $this->meta['params'] = $options['params'] ?? []; +// $this->meta['actions'] = $options['actions'] ?? []; +// $this->createQuery(); +// +// $this->jsonStr = (new JSONCreator($this->meta, $this->getCollection()->toArray()))->getJson(); +// +// } +// +// public function createQuery(): void +// { +// if ($this->currentPage > 1) { +// $this->queryBuilder->skip(($this->currentPage - 1) * $this->perPage)->take($this->perPage); +// } else { +// $this->queryBuilder->take($this->perPage); +// } +// } +// +// public function getCollection() +// { +// return $this->queryBuilder->get(); +// } +// +// /** +// * @return string|null +// */ +// public function getJson(): string|null +// { +// return $this->jsonStr; +// } +// +//} \ No newline at end of file diff --git a/kernel/IGTabel/JSONCreator.php b/kernel/IGTabel/JSONCreator.php index 0f28248..8a8da5a 100644 --- a/kernel/IGTabel/JSONCreator.php +++ b/kernel/IGTabel/JSONCreator.php @@ -1,40 +1,40 @@ "table table-bordered", "border" => "1"] : $meta['params']; - if ($meta) { - $this->informationArray = [ - "meta" => $meta, - "data" => $data ?? [] - ]; - } - } - - /** - * @param array $infArr - * @return string|null - */ - protected function toJson(array $infArr): ?string - { - if ($infArr) - return json_encode($infArr, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); - return null; - } - - /** - * @return string|null - */ - public function getJson(): ?string - { - return $this->toJson($this->informationArray); - } -} \ No newline at end of file +// +//namespace kernel\IGTabel; +// +//use app\helpers\Debug; +// +//class JSONCreator +//{ +// protected array $informationArray = []; +// +// public function __construct(array $meta, array $data) +// { +// $params = empty($meta['params']) ? ["class" => "table table-bordered", "border" => "1"] : $meta['params']; +// if ($meta) { +// $this->informationArray = [ +// "meta" => $meta, +// "data" => $data ?? [] +// ]; +// } +// } +// +// /** +// * @param array $infArr +// * @return string|null +// */ +// protected function toJson(array $infArr): ?string +// { +// if ($infArr) +// return json_encode($infArr, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); +// return null; +// } +// +// /** +// * @return string|null +// */ +// public function getJson(): ?string +// { +// return $this->toJson($this->informationArray); +// } +//} \ No newline at end of file diff --git a/kernel/IGTabel/ListJsonTableEloquentCollection.php b/kernel/IGTabel/ListJsonTableEloquentCollection.php index ff2ffe0..32c86a9 100644 --- a/kernel/IGTabel/ListJsonTableEloquentCollection.php +++ b/kernel/IGTabel/ListJsonTableEloquentCollection.php @@ -1,42 +1,42 @@ meta['columns'] = $params['columns'] ?? $model->labels(); - $this->meta['perPage'] = $params['perPage'] ?? 10; - $this->meta['currentPage'] = $params['currentPage'] ?? 1; - $this->meta['baseUrl'] = $params['baseUrl'] ?? $model->table; - $this->meta['params'] = $params['params'] ?? []; - $this->meta['actions'] = $params['actions'] ?? []; - - $this->jsonStr = (new JSONCreator($this->meta, $collection->toArray()))->getJson(); - } - - /** - * @return string|null - */ - public function getJson(): string|null - { - return $this->jsonStr; - } - -} \ No newline at end of file +// +//namespace kernel\IGTabel; +// +//use app\helpers\Debug; +//use Illuminate\Database\Eloquent\Collection; +// +//class ListJsonTableEloquentCollection +//{ +// private string|null $jsonStr; +// private array $meta = []; +// +// /** +// * @param Collection $collection +// * @param array $params +// * @throws \Exception +// */ +// public function __construct(Collection $collection, array $params = []) +// { +// if (!isset($params['model'])) { +// throw new \Exception(message: "The parameter model must not be empty"); +// } +// $model = new $params['model'](); +// $this->meta['columns'] = $params['columns'] ?? $model->labels(); +// $this->meta['perPage'] = $params['perPage'] ?? 10; +// $this->meta['currentPage'] = $params['currentPage'] ?? 1; +// $this->meta['baseUrl'] = $params['baseUrl'] ?? $model->table; +// $this->meta['params'] = $params['params'] ?? []; +// $this->meta['actions'] = $params['actions'] ?? []; +// +// $this->jsonStr = (new JSONCreator($this->meta, $collection->toArray()))->getJson(); +// } +// +// /** +// * @return string|null +// */ +// public function getJson(): string|null +// { +// return $this->jsonStr; +// } +// +//} \ No newline at end of file diff --git a/kernel/IGTabel/ViewJsonTableEloquentModel.php b/kernel/IGTabel/ViewJsonTableEloquentModel.php index 6d1e3d4..8915be7 100644 --- a/kernel/IGTabel/ViewJsonTableEloquentModel.php +++ b/kernel/IGTabel/ViewJsonTableEloquentModel.php @@ -1,37 +1,37 @@ meta['rows'] = $params['rows'] ?? $model->labels(); - $this->meta['baseUrl'] = $params['baseUrl'] ?? $model->table; - $this->meta['params'] = $params['params'] ?? []; - $this->meta['actions'] = $params['actions'] ?? []; - -// $this->jsonStr = (new JSONCreator($this->meta, $model->toArray()))->getJson(); - $model = $model->toArray(); - if(isset($model['user_id'])) - { - $model['user_id'] = User::find($model['user_id'])->username; - } - - $this->jsonStr = (new JSONCreator($this->meta, $model))->getJson(); - } - - public function getJson(): ?string - { - return $this->jsonStr; - } - -} \ No newline at end of file +// +//namespace kernel\IGTabel; +// +//use app\helpers\Debug; +//use app\models\User; +//use Illuminate\Database\Eloquent\Model; +// +//class ViewJsonTableEloquentModel +//{ +// private string|null $jsonStr; +// +// private array $meta = []; +// +// public function __construct(Model $model, array $params = []) +// { +// $this->meta['rows'] = $params['rows'] ?? $model->labels(); +// $this->meta['baseUrl'] = $params['baseUrl'] ?? $model->table; +// $this->meta['params'] = $params['params'] ?? []; +// $this->meta['actions'] = $params['actions'] ?? []; +// +//// $this->jsonStr = (new JSONCreator($this->meta, $model->toArray()))->getJson(); +// $model = $model->toArray(); +// if(isset($model['user_id'])) +// { +// $model['user_id'] = User::find($model['user_id'])->username; +// } +// +// $this->jsonStr = (new JSONCreator($this->meta, $model))->getJson(); +// } +// +// public function getJson(): ?string +// { +// return $this->jsonStr; +// } +// +//} \ No newline at end of file diff --git a/rout.php b/rout.php index 08b57b7..df83f23 100644 --- a/rout.php +++ b/rout.php @@ -20,6 +20,7 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){ }); App::$collector->group(["prefix" => "post"], function (RouteCollector $router){ App::$collector->get('/', [\app\controllers\PostController::class, 'actionIndex']); + App::$collector->get('/page/{page_number}', [\app\controllers\PostController::class, 'actionIndex']); App::$collector->get('/create', [\app\controllers\PostController::class, 'actionCreate']); App::$collector->post("/", [\app\controllers\PostController::class, 'actionAdd']); App::$collector->get('/{id}', [\app\controllers\PostController::class, 'actionView']); diff --git a/views/admin/post/index.php b/views/admin/post/index.php index 60b92d0..aa59896 100644 --- a/views/admin/post/index.php +++ b/views/admin/post/index.php @@ -2,25 +2,44 @@ /** * @var \Illuminate\Database\Eloquent\Collection $contents + * @var int $page_number */ use app\models\Post; +use app\models\User; use app\tables\columns\PostDeleteActionColumn; use app\tables\columns\PostEditActionColumn; use app\tables\columns\PostViewActionColumn; -use Itguild\Tables\ListJsonTable; +use Itguild\EloquentTable\EloquentDataProvider; +use Itguild\EloquentTable\ListEloquentTable; use kernel\IGTabel\btn\PrimaryBtn; -use kernel\IGTabel\ListJsonTableEloquentCollection; -$dataProvider = new ListJsonTableEloquentCollection($contents, [ - 'model' => Post::class, - 'perPage' => 5, +$table = new ListEloquentTable(new EloquentDataProvider(Post::class, [ + 'currentPage' => $page_number, + 'perPage' => 3, 'params' => ["class" => "table table-bordered", "border" => "2"], - 'baseUrl' => "/admin/post", -]); + 'baseUrl' => "/admin/post" +])); +$table->columns([ + 'created_at' => function ($data) { + if (!$data){ + return null; + } -$table = new ListJsonTable($dataProvider->getJson()); -$table->beforePrint(function (){ + return (new DateTimeImmutable($data))->format("d-m-Y"); + }, + 'updated_at' => function ($data) { + if (!$data){ + return null; + } + + return (new DateTimeImmutable($data))->format("d-m-Y"); + }, + 'user_id' => (function ($data) { + return User::find($data)->username; + }) +]); +$table->beforePrint(function () { return PrimaryBtn::create("Создать", "/admin/post/create")->fetch(); //return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch(); }); diff --git a/views/admin/post/view.php b/views/admin/post/view.php index 110b2bd..489ad90 100644 --- a/views/admin/post/view.php +++ b/views/admin/post/view.php @@ -3,22 +3,54 @@ /** * @var \Illuminate\Database\Eloquent\Collection $content */ -use Itguild\Tables\ViewJsonTable; + +use app\models\User; +use Itguild\EloquentTable\ViewEloquentTable; +use Itguild\EloquentTable\ViewJsonTableEloquentModel; use kernel\IGTabel\btn\DangerBtn; use kernel\IGTabel\btn\PrimaryBtn; use kernel\IGTabel\btn\SuccessBtn; -use kernel\IGTabel\ViewJsonTableEloquentModel; -$dataProvider = new ViewJsonTableEloquentModel($content, [ +//$dataProvider = new ViewJsonTableEloquentModel($content, [ +// 'params' => ["class" => "table table-bordered", "border" => "2"], +// 'baseUrl' => "/admin/user", +//]); +//$table = new ViewJsonTable($dataProvider->getJson()); +//$table->beforeTable(function () use ($content) { +// $btn = PrimaryBtn::create("Список", "/admin/post")->fetch(); +// $btn .= SuccessBtn::create("Редактировать", "/admin/post/update/" . $content->id)->fetch(); +// $btn .= DangerBtn::create("Удалить", "/admin/post/delete/" . $content->id)->fetch(); +// return $btn; +//}); +//$table->create(); +//$table->render(); + +$table = new ViewEloquentTable(new ViewJsonTableEloquentModel($content, [ 'params' => ["class" => "table table-bordered", "border" => "2"], - 'baseUrl' => "/admin/user", -]); -$table = new ViewJsonTable($dataProvider->getJson()); -$table->beforeTable(function () use ($content) { + 'baseUrl' => "/admin/post", +])); +$table->beforePrint(function () use ($content) { $btn = PrimaryBtn::create("Список", "/admin/post")->fetch(); $btn .= SuccessBtn::create("Редактировать", "/admin/post/update/" . $content->id)->fetch(); $btn .= DangerBtn::create("Удалить", "/admin/post/delete/" . $content->id)->fetch(); return $btn; }); +$table->rows([ + 'created_at' => function ($data) { + if (!$data){ + return null; + } + return (new DateTimeImmutable($data))->format("d-m-Y"); + }, + 'updated_at' => function ($data) { + if (!$data){ + return null; + } + return (new DateTimeImmutable($data))->format("d-m-Y"); + }, + 'user_id' => (function ($data) { + return User::find($data)->username; + }) +]); $table->create(); $table->render(); \ No newline at end of file diff --git a/views/admin/user/index.php b/views/admin/user/index.php index 9074016..17db7b9 100644 --- a/views/admin/user/index.php +++ b/views/admin/user/index.php @@ -8,28 +8,37 @@ use app\models\User; use app\tables\columns\UserDeleteActionColumn; use app\tables\columns\UserEditActionColumn; use app\tables\columns\UserViewActionColumn; -use Illuminate\Support\Facades\DB; -use Itguild\Tables\ListJsonTable; +use Itguild\EloquentTable\EloquentDataProvider; +use Itguild\EloquentTable\ListEloquentTable; use kernel\IGTabel\btn\PrimaryBtn; -use kernel\IGTabel\ListJsonTableEloquentCollection; - -$dataProvider = new \kernel\IGTabel\EloquentDataProvider(User::where(['status' => 2]), [ +$table = new ListEloquentTable(new EloquentDataProvider(User::class, [ 'currentPage' => $page_number, 'perPage' => 3, 'params' => ["class" => "table table-bordered", "border" => "2"], 'baseUrl' => "/admin/user", + 'filters' => ['username', 'email'], +])); +$table->columns([ + 'created_at' => function ($data) { + if (!$data){ + return null; + } + + return (new DateTimeImmutable($data))->format("d-m-Y"); + }, + 'updated_at' => function ($data) { + if (!$data){ + return null; + } + + return (new DateTimeImmutable($data))->format("d-m-Y"); + } ]); -$table = new ListJsonTable($dataProvider->getJson()); $table->beforePrint(function () { return PrimaryBtn::create("Создать", "/admin/user/create")->fetch(); //return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch(); }); -$table->afterPrint(function ($meta) { - $pagination = new \Itguild\Tables\Pagination($meta['totalWithFilters'], $meta['perPage'], $meta['currentPage'], $meta['baseUrl'] . "/page"); - $pagination->create(); - return $pagination->fetch(); -}); $table->addAction(UserViewActionColumn::class); $table->addAction(UserEditActionColumn::class); $table->addAction(UserDeleteActionColumn::class); diff --git a/views/admin/user/view.php b/views/admin/user/view.php index 452caed..159a3c1 100644 --- a/views/admin/user/view.php +++ b/views/admin/user/view.php @@ -3,22 +3,53 @@ /** * @var \Illuminate\Database\Eloquent\Collection $user */ -use Itguild\Tables\ViewJsonTable; + +use app\models\User; +use Itguild\EloquentTable\ViewEloquentTable; +use Itguild\EloquentTable\ViewJsonTableEloquentModel; use kernel\IGTabel\btn\DangerBtn; use kernel\IGTabel\btn\PrimaryBtn; use kernel\IGTabel\btn\SuccessBtn; -use kernel\IGTabel\ViewJsonTableEloquentModel; -$dataProvider = new ViewJsonTableEloquentModel($user, [ +//$dataProvider = new ViewJsonTableEloquentModel($user, [ +// 'params' => ["class" => "table table-bordered", "border" => "2"], +// 'baseUrl' => "/admin/user", +//]); +//$table = new ViewJsonTable($dataProvider->getJson()); +//$table->beforeTable(function () use ($user) { +// $btn = PrimaryBtn::create("Список", "/admin/user")->fetch(); +// $btn .= SuccessBtn::create("Редактировать", "/admin/user/update/" . $user->id)->fetch(); +// $btn .= DangerBtn::create("Удалить", "/admin/user/delete/" . $user->id)->fetch(); +// return $btn; +//}); +//$table->create(); +//$table->render(); + +$table = new ViewEloquentTable(new ViewJsonTableEloquentModel($user, [ 'params' => ["class" => "table table-bordered", "border" => "2"], 'baseUrl' => "/admin/user", -]); -$table = new ViewJsonTable($dataProvider->getJson()); -$table->beforeTable(function () use ($user) { +])); +$table->beforePrint(function () use ($user) { $btn = PrimaryBtn::create("Список", "/admin/user")->fetch(); $btn .= SuccessBtn::create("Редактировать", "/admin/user/update/" . $user->id)->fetch(); $btn .= DangerBtn::create("Удалить", "/admin/user/delete/" . $user->id)->fetch(); return $btn; }); +$table->rows([ + 'created_at' => function ($data) { + if (!$data){ + return null; + } + + return (new DateTimeImmutable($data))->format("d-m-Y"); + }, + 'updated_at' => function ($data) { + if (!$data){ + return null; + } + + return (new DateTimeImmutable($data))->format("d-m-Y"); + } +]); $table->create(); $table->render(); \ No newline at end of file