2017 © Pedro Peláez
 

library filter-manager

Filter manager package for product list,elegant generate url.

image

ajiader/filter-manager

Filter manager package for product list,elegant generate url.

  • Saturday, July 7, 2018
  • by ajiader
  • Repository
  • 1 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 12 Forks
  • 0 Open issues
  • 5 Versions
  • 17 % Grown

The README.md

Intro

A filter manager package for the product list filter, help you elegant generate filter url., (*1)

中文文档, (*2)

demo image, (*3)

Install

composer require 'ajiader/filter-manager:~1.0.4'

Usage

1. The preparatory work

require 'path/to/vendor/autoload.php';
use Toplan\FilterManager\FilterManager as FilterManager;

// params
$paramsArray = [
    'paramName' => 'value',
    ...
]

// create instance by yourself.
$fm = FilterManager::create($paramsArray)->setBlackList(['page']);

//then, render `$fm` value to your template!

Or used in laravel just like this:, (*4)

Find the providers key in config/app.php and register the FilterManger Service Provider., (*5)

    'providers' => array(
        Toplan\FilterManager\FilterManagerServiceProvider::class,
    )

Find the aliases key in config/app.php., (*6)

    'aliases' => array(
        'FilterManager' => Toplan\FilterManager\Facades\FilterManager::class,
    )

2. Just enjoy it

use value $fm in template:, (*7)

<!-- example -->
<li class="item all {{$fm->isActive('gender', FM_SELECT_ALL, 'active', '')}}">
  <a href="{{$fm->url('gender', FM_SELECT_ALL)}}">All</a>
</li>
<li class="item @if($fm->isActive('gender', 'male')) active @endif">
  <a href="{{$fm->url('gender', 'male')}}">Male</a>
</li>
<li class="item @if($fm->isActive('gender', 'female')) active @endif">
  <a href="{{$fm->url('gender', 'female')}}">Female</a>
</li>

or use laravel facade value FilterManager in template:, (*8)

<!-- example -->
<li class="item all {{FilterManager::isActive('gender', FM_SELECT_ALL, 'active', '')}}">
  <a href="{{FilterManager::url('gender', FM_SELECT_ALL)}}">All</a>
</li>
<li class="item @if(FilterManager::isActive('gender', 'male')) active @endif">
  <a href="{{FilterManager::url('gender', 'male')}}">Male</a>
</li>
<li class="item @if(FilterManager::isActive('gender','female')) active @endif">
  <a href="{{FilterManager::url('gender', 'female')}}">Female</a>
</li>

API

create(array $filters, $baseUrl, $blackList)

create a instance., (*9)

  • $filters: this is filters data, required, exp:['gender'=>'male', 'city'=>'beijing'], (*10)

  • $baseUrl: default value is empty string., (*11)

  • $blackList: this is blacklist for filters, default value is [], exp:['pageindex']., (*12)

setBlackList(array $list)

set black list for filter., (*13)

example:, (*14)

$fm->setBlackList(['page', 'pageindex']);
//or in laravel
FilterManager::setBlackList(['page', 'pageindex']);

has($filterName)

whether has the character filter, if true will return the value, if don`t return false., (*15)

example:, (*16)

$value = $fm->has('gender');

//or in laravel
$value = FilterManager::has('gender');

isActive($filterName, $filterValue, $trueReturn, $falseReturn)

example:, (*17)

//in laravel
FilterManager::isActive('gender', 'male');//this will return true or false;

FilterManager::isActive('gender', 'male', 'active', '');//this will return 'active' or '';

url($filterName, $filterValue, $multi, $linkageRemoveFilters, $blackList)

One filter has some values, and every value has a url, this method return a full url string., (*18)

  • $filterName: param name, required., (*19)

  • $filterValue: param value, default value is FM_SELECT_ALL., (*20)

  • $multi: whether to support multiple values? false or true, default value is false., (*21)

  • $linkageRemoveFilters:linkage remove the other filter, default value is []., (*22)

  • $blackList: temporary blacklist, default value is []., (*23)

example:, (*24)

//in laravel
FilterManager::url('gender', FM_SELECT_ALL);//without gender param

FilterManager::url('gender', 'male', false);//single value

FilterManager::url('cities', 'shanghai', true);
FilterManager::url('cities', 'beijing', true);//multiple values

// One province has many cities, one city has many counties ...,
// If you select 'all province' or one of provinces,
// you should linkage remove the selected cities and counties ...
//
// like this:
// select all province
FilterManager::url('province', FM_SELECT_ALL, false, ['cities', 'counties', ...]);//linkage remove selected cities
// select one province
FilterManager::url('province', 'sichuan', false, ['cities', 'counties', ...]);//linkage remove selected cities

The Versions

07/07 2018

dev-master

9999999-dev

Filter manager package for product list,elegant generate url.

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

by jiaguo

05/12 2016

1.0.4

1.0.4.0

Filter manager package for product list,elegant generate url.

  Sources   Download

The Requires

  • php >=5.4.0

 

by Avatar toplan

filter product list filter manager

08/01 2016

1.0.2

1.0.2.0

Filter manager package for product list,elegant generate url.

  Sources   Download

The Requires

  • php >=5.4.0

 

by Avatar toplan

filter product list filter manager

08/01 2016

1.0.1

1.0.1.0

Filter manager package for product list,elegant generate url.

  Sources   Download

The Requires

  • php >=5.4.0

 

by Avatar toplan

filter product list filter manager

08/01 2016

1.0.0

1.0.0.0

Filter manager package for product list,elegant generate url.

  Sources   Download

The Requires

  • php >=5.4.0

 

by Avatar toplan

filter product list filter manager