itGuild tables
This commit is contained in:
		@@ -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
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										46
									
								
								app/foo.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								app/foo.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,46 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
namespace app;
 | 
			
		||||
class foo
 | 
			
		||||
{
 | 
			
		||||
    public array $informationArray;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param array $columns
 | 
			
		||||
     * @param array $data
 | 
			
		||||
     * @return string|null
 | 
			
		||||
     */
 | 
			
		||||
    public function createJsonArray(array $columns, array $data, string $title): ?string
 | 
			
		||||
    {
 | 
			
		||||
        if ($columns && $data) {
 | 
			
		||||
            $this->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;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -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' => 'Обновлен'
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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": {
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										28
									
								
								composer.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										28
									
								
								composer.lock
									
									
									
										generated
									
									
									
								
							@@ -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",
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
{% extends "mainLayout.html" %}
 | 
			
		||||
{% extends "main_layout.html.twig" %}
 | 
			
		||||
 | 
			
		||||
{% block content %}
 | 
			
		||||
<table border="1" style="width: 80%;">
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user