public function addWidget($name, $type, array $values = array())
 {
     // Create the widget
     $widget = new Widget();
     $widget->setId($this->id);
     $widget->setCollectionName($this->collectionName);
     $widget->setName($name);
     $widget->setType(strtolower($type));
     $widget->setPosition(count($this->collection));
     $widget->setValues($values);
     $widget->setClassName(str_replace('widget.', '', strtolower($type)));
     if ($this->parent !== null && $this->parent->getType() == 'widget.responsivecolumns') {
         $this->parent->setValues(array_merge($this->parent->getValues(), array('isEmpty' => 0)));
     }
     // Append the widget to the zone's collection
     $this->collection[count($this->collection)] = $widget;
     return $widget;
 }
 public function __construct($columns, Widget $widget)
 {
     // Construct an ID to be used by the column widget's collections
     $idPrefix = $widget->getId() . '-' . $widget->getCollectionName() . '__' . $widget->getName();
     $zones = $widget->getCollection('zones');
     // Add column collections to the widget
     for ($column = 0; $column < $columns; ++$column) {
         $name = 'column' . ($column > 0 ? $column : '');
         $id = $idPrefix . '-zones__' . $name;
         // Add a column widget
         $zone = new Widget();
         $zone->setId($idPrefix);
         $zone->setCollectionName('zones');
         $zone->setName($name);
         $zone->setType('Widget.Columns.Column');
         $zone->setPosition($column);
         $zones[$column] = $zone;
         $collection = new Collection();
         $zone->addCollection('widgets', $collection);
         $this->columns[] = new CollectionBuilder($id, 'widgets', $collection, $widget);
     }
 }
 /**
  * @test
  */
 public function partition()
 {
     $collection = new Collection();
     $component = new Widget\Widget();
     $component->setCollectionName('foo');
     $component->setPosition(0);
     $collection[0] = $component;
     $component = new Widget\Widget();
     $component->setCollectionName('bar');
     $component->setPosition(0);
     $collection[1] = $component;
     $component = new Widget\Widget();
     $component->setCollectionName('foo');
     $component->setPosition(1);
     $collection[2] = $component;
     $result = $collection->partition(function ($element) {
         return $element->getCollectionName();
     });
     $this->assertEquals(2, count($result));
     $this->assertTrue(isset($result['foo']));
     $this->assertEquals(2, count($result['foo']));
     $this->assertTrue(isset($result['bar']));
     $this->assertEquals(1, count($result['bar']));
 }