public function testAddFilterAndIterate() { $this->subject->add(new Filter()); $this->assertCount(1, $this->subject); $this->subject->add(new Filter()); $this->assertCount(2, $this->subject); foreach ($this->subject as $filter) { $this->assertInstanceOf('ABK\\QueryBundle\\Filter\\Filter', $filter); } $this->subject->rewind(); $this->subject->next(); $this->assertEquals(1, $this->subject->key()); }
protected function addFilter($filterId, $asQuery = false) { $filter = new Filter(); if ($filterId === null) { $filterId = uniqid(); } $filter->setName($filterId); if ($this->currentFilter === null) { $this->currentFilter = $filter; if ($asQuery) { $this->query = $filter; } else { $this->filters->add($filter); } } else { $nestedFilter = new NestedFilter($filter); if ($this->currentFilter instanceof Filter) { $this->currentFilter->addOperator($nestedFilter); } elseif ($this->currentFilter instanceof NestedFilter) { $this->currentFilter->getFilter()->addOperator($nestedFilter); } $this->currentFilter = $nestedFilter; } }