devrtips / listr
This package is abandoned and no longer maintained.
The author suggests using the listem/listem-php package instead.
Listem is an easy to use (but highly customizable) data sorting and filtering module for PHP, that can be used for data lists/tables/grids, reports or APIs.
dev-master
2018-04-11 04:06 UTC
Requires
- php: >=5.4.0
Requires (Dev)
- phpunit/phpunit: ~4.8.36
This package is not auto-updated.
Last update: 2022-02-01 12:52:09 UTC
README
Listem is an easy to use (but highly customizable) data sorting and filtering module for PHP >= 5.4, which can be used for data lists/tables/grids, reports or APIs.
Installation
Make sure you have Composer installed and run the below command from your project directory.
composer require listem/listem-php
General Usage
Set configurations and initialize.
$config = [ 'filters' => [ 'name' => ['label' => 'Title'], 'content' => ['label' => 'Content', 'column' => ['content', 'summary']], 'state' => [ 'label' => 'State', 'type' => Listem\Filter::ENUM_INPUT, 'enums' => [ 1 => 'Active', 0 => 'Draft' ] ], 'created_at' => ['label' => 'Created On', 'type' => Listem\Filter::DATE], 'category' => ['label' => 'Category', 'type' => Listem\Filter::ENUM_SELECT] ], 'sorters' => [ 'name' => ['label' => 'Full Name', 'column' => 'users.name'], 'active' => ['label' => 'Active', 'column' => 'users.active'] ] ]; $list = new Listem\ListEntity($config, new Listem\Conditions\MySQL, new Listem\Params\Get); $filters = $list->getFilters(); $sorters = $list>getSorters(); $filterConditions = $filters->getConditions(); $sorterConditions = $sorters->getConditions(); $data = BlogPost::whereRaw($condition); ->orderBy($sorterConditions['column'], $sorterConditions['side']) ->get() ->toArray();
Pass $filters
and $sorters
to your view and render them easily.
<form method="GET" class="form-horizontal"> <!-- Should be submitted to the current page --> <?php foreach($filters as $filter): $filter = new Listem\Html\Decorators\Bootstrap3($filter); ?> <div class="form-group"> <?php echo $filter->renderLabel() ?> <?php echo $filter->renderFormElem() ?> </div> <?php endforeach; ?> <button type="reset">Reset</button> <button type="submit">Filter</button> </form> <table> <thead> <tr> <th><?php $sorters->render('title') ?></th> <th>Slug</th> <th><?php $sorters->render('content') ?></th> <!-- Or you can render parts of it, so you have more control --> <th> <a href="<?php $sorters->getLink('created_at') ?>"> <?php $sorters->getLabel('created_at') ?> <span class="<?php $sorters->sorted('created_at') ? 'up' : 'down' ?>"></span> </a> </th> </tr> </thead> ...
Documentation
Contributing
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
License
The MIT License (MIT). Please see License File for more information.