src/Block/Group.php
public function partition($index, $total)
    {
        $index = (integer) $index;
        $total = (integer) $total;
        if (!$index || !$total || $index > $total) {
            throw new Exception("Invalid partition parameters: {$index}/{$total}");
        }

        $groups = [];
        $partitions = [];
        $partitionsTotal = [];

        for ($i = 0; $i < $total; $i++) {
            $partitions[$i] = [];
            $partitionsTotal[$i] = 0;
        }

        $children = $this->children();

        foreach ($children as $key => $child) {
            $groups[$key] = $child->stats()['normal'];
            $child->enabled(false);
        }
        asort($groups);

        foreach ($groups as $key => $value) {
            $i = array_search(min($partitionsTotal), $partitionsTotal);
            $partitions[$i][] = $key;
            $partitionsTotal[$i] += $groups[$key];
        }

        foreach ($partitions[$index - 1] as $key) {
            $children[$key]->enabled(true);
        }
    }
public function partition($index, $total)
    {
        $index = (integer) $index;
        $total = (integer) $total;
        if (!$index || !$total || $index > $total) {
            throw new Exception("Invalid partition parameters: {$index}/{$total}");
        }

        $groups = [];
        $partitions = [];
        $partitionsTotal = [];

        for ($i = 0; $i < $total; $i++) {
            $partitions[$i] = [];
            $partitionsTotal[$i] = 0;
        }

        $children = $this->children();

        foreach ($children as $key => $child) {
            $groups[$key] = $child->stats()['normal'];
            $child->enabled(false);
        }
        asort($groups);

        foreach ($groups as $key => $value) {
            $i = array_search(min($partitionsTotal), $partitionsTotal);
            $partitions[$i][] = $key;
            $partitionsTotal[$i] += $groups[$key];
        }

        foreach ($partitions[$index - 1] as $key) {
            $children[$key]->enabled(true);
        }
    }
public function partition ( $ index , $ total ) { $ index = ( integer ) $ index ; $ total = ( integer ) $ total ; if ( ! $ index || ! $ total || $ index > $ total ) { throw new Exception ( "Invalid partition parameters: {$index}/{$total}" ) ; } $ groups = [ ] ; $ partitions = [ ] ; $ partitionsTotal = [ ] ; for ( $ i = 0 ; $ i < $ total ; $ i ++ ) { $ partitions [ $ i ] = [ ] ; $ partitionsTotal [ $ i ] = 0 ; } $ children = $ this -> children ( ) ; foreach ( $ children as $ key => $ child ) { $ groups [ $ key ] = $ child -> stats ( ) [ 'normal' ] ; $ child -> enabled ( false ) ; } asort ( $ groups ) ; foreach ( $ groups as $ key => $ value ) { $ i = array_search ( min ( $ partitionsTotal ) , $ partitionsTotal ) ; $ partitions [ $ i ] [ ] = $ key ; $ partitionsTotal [ $ i ] += $ groups [ $ key ] ; } foreach ( $ partitions [ $ index - 1 ] as $ key ) { $ children [ $ key ] -> enabled ( true ) ; } }
Splits the specs in different partitions and only enable one.

@param integer $index The partition index to enable.
@param integer $total The total of partitions.
Splits the specs in different partitions and only enable one .