예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function createGrid(Collection $collection, array $options = array())
 {
     $extensions = $this->getExtensions();
     $grid = new Grid();
     // options resolution
     $resolver = new OptionsResolver();
     foreach ($extensions as $extension) {
         $extension->configure($resolver);
     }
     $options = $resolver->resolve($options);
     // schema building
     $schema = null;
     $entity = $collection->getPeek();
     foreach ($extensions as $extension) {
         $schema = $extension->guessSchema($entity, $options);
         if (null !== $schema) {
             break;
         }
     }
     if (null === $schema) {
         throw ConfigurationException::schemaNotFound(array_keys($this->extensions));
     }
     $schema->bind($this, $grid);
     foreach ($extensions as $extension) {
         $extension->buildSchema($schema, $collection, $options);
     }
     // grid building
     foreach ($extensions as $extension) {
         $extension->buildGrid($grid, $schema, $collection, $options);
     }
     foreach ($extensions as $extension) {
         $extension->visit($grid, $options);
     }
     return $grid;
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function buildGrid(Grid $grid, Schema $schema, Collection $collection, array $options = array())
 {
     $index = 0;
     while ($entity = $collection->next()) {
         $schema->build($row = new Row(self::NAME), $entity, $options);
         $grid->getBody()->add($entity->getId() ?: $index++, $row);
     }
 }
예제 #3
0
 public function testIteratorAggregateCollection()
 {
     $array = $this->getArrayData();
     $iterator = new \ArrayIterator($array);
     $data = new DelegatingIterator($iterator);
     $collection = new Collection($data);
     $this->assertSame($iterator, $collection->getRaw());
     $this->assertEquals($array[0], $collection->getPeek()->getRaw());
     $this->assertEquals($array[0], $collection->next()->getRaw());
     $this->assertEquals($array[1], $collection->next()->getRaw());
     $this->assertEquals($array[2], $collection->getPeek()->getRaw());
     $collection->rewind();
     $this->assertEquals($array[0], $collection->next()->getRaw());
 }