Skip to content

Commit

Permalink
Readme 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Padam87 committed Mar 22, 2014
1 parent e9cbfcb commit 0cd48bc
Showing 1 changed file with 43 additions and 16 deletions.
59 changes: 43 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,78 @@

# Search Bundle #

Search bundle for Symfony2. Use entities, collections for search directly.
Search bundle for Symfony2. Use entities, collections for search directly. Great for handling complex search forms.

## 1. Examples ##

### 1.1 Simple ###

```php
$qb = $this->get('search')->createFilter($filter, 'alias')->createQueryBuilder('YourBundle:Entity');
$fm = $this->get('padam87_search.filter.manager');
$filter = new Filter($data, 'YourBundle:Entity', 'alias');
$qb = $fm->createQueryBuilder($filter);
```
```$data``` can be an ***array***, an ***entity***, or even a doctrine ***collection***.

You can add your own converter to handle any type of data.

### 1.2 Joins ###

```php
$qb =
$this->get('search')->createFilter($joinedfilter, 'joinalias')->applyToQueryBuilder(
$this->get('search')->createFilter($filter, 'alias')->createQueryBuilder('YourBundle:Entity'),
'relationName' // this is the name of the relation in your entity, eg 'users'
);
$fm = $this->get('padam87_search.filter.manager');
$filter1 = new Filter($data1, 'YourBundle:Entity1', 'alias1');
$filter2 = new Filter($data2, 'YourBundle:Entity2', 'alias2');
$qb = $fm->joinToQueryBuilder($filter2, $fm->createQueryBuilder($filter1), 'associationName');
```

### 1.3 Collections ###
```'associationName'``` is the name of the relation in your entity, eg 'users'

You can also create a collection filter, which will use all the entities in the collection, to search.
### 1.3 Collection valued associations ###

#### 1.3.1 OR ####
```php
$fm = $this->get('padam87_search.filter.manager');
$filter = new Filter($data, 'YourBundle:Entity', 'alias');
$qb = $fm->createQueryBuilder($filter);
```

Just like the simple example, but in this case, the filter is a doctrine collection.
When ```$data``` is an entity, it can have *ToMany associations. By default, the bundle assumes OR relationship between the elements of the collection. To change that, you can use the 2nd parameter of ```$fm->createQueryBuilder```:

```php
$qb = $this->get('search')->createFilter($filter, 'alias')->createQueryBuilder('YourBundle:Entity');
$fm = $this->get('padam87_search.filter.manager');
$filter = new Filter($data, 'YourBundle:Entity', 'alias');
$qb = $fm->createQueryBuilder($filter, array(
'relationName' => 'AND'
));
```

#### 1.3.2 AND ####
### 1.4 Operators ###

```php
$qb = $this->get('search')->createFilter($filter, 'alias')->createQueryBuilder('YourBundle:Entity', array(
'relationName' => 'AND'
$data = array(
'integerField>=' => 10
'stringFiled' => 'A*'
);
$filter = new Filter($data, 'YourBundle:Entity', 'alias');
```

The bundle will search for operators in the field names and values, and use the appropriate Expr.


For a nicer, and entity-compatible solution you can use the 4th parameter of the Filter to set default operators:


```php
$filter = new Filter($data, 'YourBundle:Entity', 'alias', array(
'integerField' => '>='
));
```


## 2. Installation ##

### 2.1. Composer ###

"padam87/search-bundle": "1.0.*",
"padam87/search-bundle": "2.0.*",

### 2.2. AppKernel ###

Expand Down

0 comments on commit 0cd48bc

Please sign in to comment.