Comments (8)
@jippi since there is such an overwhelming interest from other people here is my implementation.
Please let me know if this will work for you and I'll add it to my branch.
/**
* Gets all filters in a given collection.
*
* @param string $collection Name of the filter collection.
* @return array Array of filter instances.
*/
public function getFilters($collection = 'default')
{
return $this->_filters[$collection];
}
/**
* Sets or gets the filter collection name.
*
* @param string $name Name of the active filter collection to set.
* @return mixed Returns $this or the name of the active collection if no $name was provided.
*/
public function collection($name = null) {
if ($name === null) {
return $this->_collection;
}
if (!isset($this->_filters[$name])) {
$this->_filters[$name] = [];
}
$this->_collection = $name;
return $this;
}
/**
* Adds a new filter to the active collection.
*
* @param string $name
* @param string $filter
* @param array $options
* @return $this
*/
public function add($name, $filter, array $options = [])
{
$this->_filters[$this->_collection][$name] = $this->_loadFilter($filter, $options);
return $this;
}
/**
* Loads a search filter instance.
*
* @param string $name Name of the filter class to load.
* @param array $options Filter options.
* @return \Search\Search\Type\Base
* @throws \InvalidArgumentException When no filter was found.
*/
public function _loadFilter($name, array $options = [])
{
list($plugin, $name) = pluginSplit($name);
if (!empty($plugin)) {
$className = '\\' . $plugin . '\Search\Type\\' . $name;
if (class_exists($className)) {
return new $className($name, $options, $this);
}
}
if (isset($config['typeClasses'][$name])) {
return new $config['typeClasses'][$name]($name, $options, $this);
}
if (class_exists('\FOC\Search\Search\Type\\' . $name)) {
$className = '\FOC\Search\Search\Type\\' . $name;
return new $className($name, $options, $this);
}
if (class_exists('\App\Search\Type\\' . $name)) {
$className = '\App\Search\Type\\' . $name;
return new $className($name, $options, $this);
}
throw new \InvalidArgumentException(sprintf('Can\'t find filter class %s!', $name));
}
from search.
@jippi I've implented this proposal in my fork of the plugin, feel free to take it from there or just close this ticket.
from search.
Why a trait and not a behaviour? It makes more sense to be that if it's dealing with the table classes it should be a behaviour. Using a trait feels like a hack to me, like it's sidestepping the framework.
from search.
@davidyell where do you see a trait?
from search.
Sorry, I should have tagged Jippi,
@jippi said
in the table class I think a trait that
Oh, but it looks like it's quoting you. So my question was why use a trait to return the manager rather than a behaviour.
from search.
@jippi you can close this.
from search.
See #46
from search.
Closing as PR is open.
from search.
Related Issues (20)
- Additional search data from request to manager HOT 4
- Help on installation.
- Any way to get the matched text of a particular field?
- Query parameter value filter containing period in string name is not running HOT 4
- Bake filter collections? HOT 2
- warning with bake in cake42 HOT 4
- Conflict with Migration ? HOT 2
- 3.9 not working as usual HOT 8
- Can't search in associated Model HOT 1
- SearchComponent conflict with DisableGenericTables HOT 4
- Search resetUrl function HOT 6
- Bug/inconvenience when baking FilterCollections HOT 4
- Passing an integer value to the search query HOT 2
- German umlauts not recognized HOT 4
- Complex Searches (question / request) HOT 3
- BC issue HOT 15
- Reset doesn't work WA's solution to keep search filters HOT 2
- belongsToMany Search not Working HOT 5
- 5.x: Search exception HOT 5
- Casting needed for Finder filter
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from search.