to composer
This commit is contained in:
		
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,2 @@ | ||||
| /vendor/ | ||||
| .idea | ||||
							
								
								
									
										18
									
								
								composer.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								composer.json
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										15
									
								
								examples/simple.json
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										11
									
								
								examples/simple.php
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										11
									
								
								index.php
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										14
									
								
								simple.json
									
									
									
									
									
										Normal 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"} | ||||
|   ] | ||||
| } | ||||
| @@ -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(); | ||||
|     } | ||||
| 
 | ||||
| @@ -1,8 +1,7 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace itguild\forms\table; | ||||
| namespace Itguild\Tables; | ||||
| 
 | ||||
| use itguild\forms\widgets\BaseWidget; | ||||
| 
 | ||||
| class Pagination | ||||
| { | ||||
| @@ -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 | ||||
| { | ||||
| @@ -1,6 +1,6 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace itguild\forms\table\actionBtn; | ||||
| namespace Itguild\Tables\actionBtn; | ||||
| 
 | ||||
| abstract class ActionBtn | ||||
| { | ||||
| @@ -1,6 +1,6 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace itguild\forms\table\actionBtn; | ||||
| namespace Itguild\Tables\actionBtn; | ||||
| 
 | ||||
| class ToDeleteBtn extends ActionBtn | ||||
| { | ||||
| @@ -1,6 +1,6 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace itguild\forms\table\actionBtn; | ||||
| namespace Itguild\Tables\actionBtn; | ||||
| 
 | ||||
| class ToEditBtn extends ActionBtn | ||||
| { | ||||
| @@ -1,6 +1,6 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace itguild\forms\table\actionBtn; | ||||
| namespace Itguild\Tables\actionBtn; | ||||
| 
 | ||||
| class ToListBtn extends ActionBtn | ||||
| { | ||||
| @@ -1,6 +1,6 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace itguild\forms\table\ActionColumn; | ||||
| namespace Itguild\Tables\ActionColumn; | ||||
| 
 | ||||
| abstract class ActionColumn | ||||
| { | ||||
| @@ -1,6 +1,6 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace itguild\forms\table\ActionColumn; | ||||
| namespace Itguild\Tables\ActionColumn; | ||||
| 
 | ||||
| class DeleteActionColumn extends ActionColumn | ||||
| { | ||||
| @@ -1,6 +1,6 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace itguild\forms\table\ActionColumn; | ||||
| namespace Itguild\Tables\ActionColumn; | ||||
| 
 | ||||
| class EditActionColumn extends ActionColumn | ||||
| { | ||||
| @@ -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
									
								
							
							
						
						
									
										21
									
								
								src/traits/CreateOption.php
									
									
									
									
									
										Executable 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
									
								
							
							
						
						
									
										24
									
								
								src/traits/CreateParams.php
									
									
									
									
									
										Executable 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; | ||||
|     } | ||||
|  | ||||
| } | ||||
		Reference in New Issue
	
	Block a user