to composer

This commit is contained in:
Kavalar 2024-05-27 12:59:44 +03:00
parent 3f6e5ffcec
commit 42ab26a3db
19 changed files with 134 additions and 21 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/vendor/
.idea

18
composer.json Normal file
View File

@ -0,0 +1,18 @@
{
"name": "itguild/tables",
"type": "library",
"license": "MIT",
"autoload": {
"psr-4": {
"Itguild\\Tables\\": "src/"
}
},
"authors": [
{
"name": "Kavalar",
"email": "apuc06@mail.ru"
}
],
"minimum-stability": "dev",
"require": {}
}

15
examples/simple.json Normal file
View File

@ -0,0 +1,15 @@
{
"meta": {
"title": "forma 1",
"columns": {
"email": "Email",
"description": "Описание 1",
"description2": "Описание 2"
},
"params": {"class": "table table-bordered", "border": "1"}
},
"data": [
{"email":"fas@mail.ru","description":"fafdgdfs","description2":"ffdghdas"},
]
}

11
examples/simple.php Normal file
View File

@ -0,0 +1,11 @@
<?php
require_once "../vendor/autoload.php";
use Itguild\Tables\ListJsonTable;
$json = file_get_contents('simple.json');
$table = new ListJsonTable($json);
$table->create();
$table->render();

11
index.php Normal file
View File

@ -0,0 +1,11 @@
<?php
require_once __DIR__ . "/vendor/autoload.php";
use Itguild\Tables\ListJsonTable;
$json = file_get_contents('simple.json');
$table = new ListJsonTable($json);
$table->create();
$table->render();

14
simple.json Normal file
View File

@ -0,0 +1,14 @@
{
"meta": {
"title": "forma 1",
"columns": {
"email": "Email",
"description": "Описание 1",
"description2": "Описание 2"
},
"params": {"class": "table table-bordered", "border": "1"}
},
"data": [
{"id":1, "email":"fas@mail.ru","description":"fafdgdfs","description2":"ffdghdas"}
]
}

View File

@ -1,13 +1,11 @@
<?php
namespace itguild\forms\table;
namespace Itguild\Tables;
use itguild\forms\debug\Debug;
use itguild\forms\table\ActionColumn\DeleteActionColumn;
use itguild\forms\table\ActionColumn\EditActionColumn;
use itguild\forms\table\ActionColumn\ViewActionColumn;
use itguild\forms\traits\CreateParams;
use itguild\forms\widgets\BaseWidget;
use Itguild\Tables\ActionColumn\DeleteActionColumn;
use Itguild\Tables\ActionColumn\EditActionColumn;
use Itguild\Tables\ActionColumn\ViewActionColumn;
use Itguild\Tables\traits\CreateParams;
class ListJsonTable
{
@ -27,9 +25,10 @@ class ListJsonTable
public function __construct(string $json)
{
$this->beforePrintCell = false;
$this->beforePrint = function (){};
$this->json = $json;
$this->data = json_decode($this->json, true);
$this->baseUrl = $this->data['meta']['baseUrl'] ?? null;
$this->baseUrl = $this->data['meta']['baseUrl'] ?? '';
$this->setActions();
}

View File

@ -1,8 +1,7 @@
<?php
namespace itguild\forms\table;
namespace Itguild\Tables;
use itguild\forms\widgets\BaseWidget;
class Pagination
{

View File

@ -1,9 +1,8 @@
<?php
namespace itguild\forms\table;
namespace Itguild\Tables;
use itguild\forms\traits\CreateParams;
use itguild\forms\widgets\BaseWidget;
use Itguild\Tables\traits\CreateParams;
class ViewJsonTable
{

View File

@ -1,6 +1,6 @@
<?php
namespace itguild\forms\table\actionBtn;
namespace Itguild\Tables\actionBtn;
abstract class ActionBtn
{

View File

@ -1,6 +1,6 @@
<?php
namespace itguild\forms\table\actionBtn;
namespace Itguild\Tables\actionBtn;
class ToDeleteBtn extends ActionBtn
{

View File

@ -1,6 +1,6 @@
<?php
namespace itguild\forms\table\actionBtn;
namespace Itguild\Tables\actionBtn;
class ToEditBtn extends ActionBtn
{

View File

@ -1,6 +1,6 @@
<?php
namespace itguild\forms\table\actionBtn;
namespace Itguild\Tables\actionBtn;
class ToListBtn extends ActionBtn
{

View File

@ -1,6 +1,6 @@
<?php
namespace itguild\forms\table\ActionColumn;
namespace Itguild\Tables\ActionColumn;
abstract class ActionColumn
{

View File

@ -1,6 +1,6 @@
<?php
namespace itguild\forms\table\ActionColumn;
namespace Itguild\Tables\ActionColumn;
class DeleteActionColumn extends ActionColumn
{

View File

@ -1,6 +1,6 @@
<?php
namespace itguild\forms\table\ActionColumn;
namespace Itguild\Tables\ActionColumn;
class EditActionColumn extends ActionColumn
{

View File

@ -1,6 +1,6 @@
<?php
namespace itguild\forms\table\ActionColumn;
namespace Itguild\Tables\ActionColumn;
class ViewActionColumn extends ActionColumn
{

21
src/traits/CreateOption.php Executable file
View File

@ -0,0 +1,21 @@
<?php
namespace Itguild\Tables\traits;
trait CreateOption
{
/**
* @param array $options
* @param $value
* @return string
*/
public function createOption(array $options, $value = null): string
{
$optionsString = "";
foreach ($options as $val => $title){
$selected = (int)$value === $val ? "selected" : "";
$optionsString .= "<option $selected value='$val'>$title</option>";
}
return $optionsString;
}
}

24
src/traits/CreateParams.php Executable file
View File

@ -0,0 +1,24 @@
<?php
namespace Itguild\Tables\traits;
trait CreateParams
{
/**
* @param array $data
* @return string
*/
public function createParams(array $data = []): string
{
$paramsString = "";
foreach($data as $key => $param){
if(is_string($param)){
$paramsString .= $key . "='" . $param . "'";
}
}
return $paramsString;
}
}