itGuild tables

This commit is contained in:
2024-07-12 13:46:44 +03:00
parent 91dc9194e0
commit 0d077fb641
6 changed files with 97 additions and 5 deletions

View File

@ -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
View 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;
}
}

View File

@ -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' => 'Обновлен'
];
}
}