Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.62 KB | None | 0 0
  1. <?php declare(strict_types = 1);
  2.  
  3. namespace App\AdminModule\Components\Category;
  4.  
  5. use App\Model\CategoryModel;
  6. use Nette\Application\UI\Control;
  7. use Ublaboo\DataGrid\DataGrid;
  8.  
  9. final class CategoryControl extends Control
  10. {
  11.  
  12.     /** @var CategoryModel */
  13.     private $categoryModel;
  14.  
  15.     public function __construct(CategoryModel $categoryModel)
  16.     {
  17.         $this->categoryModel = $categoryModel;
  18.     }
  19.  
  20.  
  21.     public function render(): void
  22.     {
  23.         $this->template->render(__DIR__ . '/templates/category.latte');
  24.     }
  25.  
  26.     public function createComponentCategoryGrid(string $name)
  27.     {
  28.         $grid = new DataGrid($this, $name);
  29.         $grid->setRememberState(false);
  30.  
  31.         $grid->setTemplateFile(__DIR__ . '/../templates/datagrid.latte');
  32.         $grid->setPrimaryKey('category_id');
  33.         $grid->setDataSource($this->categoryModel->getAll());
  34.  
  35.         $grid->setTreeView([$this, 'getChildren'], 'hasChildren');
  36.  
  37.         $grid->addColumnText('name', 'Názov');
  38.  
  39.         $grid->addColumnDateTime('created', 'Vytvorený');
  40.  
  41.         $grid->addColumnText('state', 'Stav')
  42.             ->setFitContent(false)
  43.             ->setTemplate(__DIR__ . '/../templates/state.latte');
  44.  
  45.         $grid->addAction('Categories:edit', 'Upraviť')
  46.             ->setClass('btn btn-xs btn-primary');
  47.  
  48.         $grid->addToolbarButton('Categories:add', 'Pridať kategóriu')->setClass('btn btn-xs btn-success');
  49.  
  50.         return $grid;
  51.     }
  52.  
  53.     public function getChildren($parentId) {
  54.         return $this->categoryModel->getAll()->where('parent_id',$parentId);
  55.     }
  56.  
  57.     public function hasChildren($parentId) {
  58.         return $this->categoryModel->getAll()->where('parent_id',$parentId)->count() > 0 ? true : false;
  59.     }
  60.  
  61.     public function handleOpen(): void
  62.     {
  63.     }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement