From 0d077fb6411b704610da93c11b048f15a186104e Mon Sep 17 00:00:00 2001 From: stas Date: Fri, 12 Jul 2024 13:46:44 +0300 Subject: [PATCH] itGuild tables --- app/controllers/UserController.php | 11 ++++++- app/foo.php | 46 ++++++++++++++++++++++++++++++ app/models/User.php | 12 +++++++- composer.json | 3 +- composer.lock | 28 +++++++++++++++++- views/user_table.html.twig | 2 +- 6 files changed, 97 insertions(+), 5 deletions(-) create mode 100644 app/foo.php diff --git a/app/controllers/UserController.php b/app/controllers/UserController.php index c610d56..47dca32 100644 --- a/app/controllers/UserController.php +++ b/app/controllers/UserController.php @@ -2,8 +2,10 @@ namespace app\controllers; +use app\foo; use app\models\Question; use app\models\User; +use Itguild\Tables\ListJsonTable; use kernel\Controller; class UserController extends Controller{ @@ -35,7 +37,14 @@ class UserController extends Controller{ { $userArr[$i++] = $user; } - echo $this->twig->render('userTable.html', ['userArr' => $userArr]); + echo $this->twig->render('user_table.html.twig', ['userArr' => $userArr]); + + $json = new foo(); + $userArr = $json->createJsonArray(User::labels(), $userArr, "form1"); + $table = new ListJsonTable($userArr); + $table->create(); + $table->render(); + } public function actionView($id): void diff --git a/app/foo.php b/app/foo.php new file mode 100644 index 0000000..82911c5 --- /dev/null +++ b/app/foo.php @@ -0,0 +1,46 @@ +informationArray = [ + "meta" => [ + "title" => $title, + "columns" => $columns, + "perPage" => 10, + "currentPage" => 1, + "params" => + [ + "class" => "table table-bordered", + "border" => "1" + ] + ], + "data" => $data + ]; + return $this->toJson($this->informationArray); + } + return null; + } + + /** + * @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; + } +} \ No newline at end of file diff --git a/app/models/User.php b/app/models/User.php index 49b7c0a..6f09d5f 100644 --- a/app/models/User.php +++ b/app/models/User.php @@ -5,5 +5,15 @@ use Illuminate\Database\Eloquent\Model; class User extends Model { protected $table = 'user'; protected $fillable = ['username', 'email', 'password_hash', 'role']; - protected $dates = ['deleted at']; + protected array $dates = ['deleted at']; + + public static function labels(): array + { + return [ + 'username' => 'Логин', + 'email' => 'Email', + 'created_at' => 'Создан', + 'updated_at' => 'Обновлен' + ]; + } } diff --git a/composer.json b/composer.json index 162bb7e..5490513 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,8 @@ "illuminate/database": "^11.14", "craft-group/phroute": "^2.1", "vlucas/phpdotenv": "^5.6", - "twig/twig": "^3.0" + "twig/twig": "^3.0", + "itguild/tables": "^0.1.0" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 5d9d1e5..8515c89 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": "ec1e05ff0752e8d6ad1df75a5cae6188", + "content-hash": "479a64315f08eb4456be2e2425d4ba60", "packages": [ { "name": "brick/math", @@ -723,6 +723,32 @@ }, "time": "2024-07-08T14:46:56+00:00" }, + { + "name": "itguild/tables", + "version": "0.1", + "source": { + "type": "git", + "url": "https://git.itguild.info/ItGuild/tables", + "reference": "42ab26a3db1cef8319985fc3a0f5d23d2dff4e3b" + }, + "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-05-27T09:59:44+00:00" + }, { "name": "nesbot/carbon", "version": "3.6.0", diff --git a/views/user_table.html.twig b/views/user_table.html.twig index e16d8f7..dc807cd 100644 --- a/views/user_table.html.twig +++ b/views/user_table.html.twig @@ -1,4 +1,4 @@ -{% extends "mainLayout.html" %} +{% extends "main_layout.html.twig" %} {% block content %}