Teams laten zien in Pools hoe?

Status
Niet open voor verdere reacties.

kevinkuijer

Gebruiker
Lid geworden
1 feb 2012
Berichten
28
Hallo,

Ik ben bezig met een rank systeem voor een toernooi,
Het toernooi begint bij pools van 4 teams elke ronde heeft pools van 4 teams,
Totdat er 32 teams over zijn en dan wordt het 1 op 1

De berekening heb ik al en het werkt perfect alleen ik wil dat hij weergeeft welke teams er in de pool zitten,
Als ik nu een ronde maak maakt hij automatisch de pools aan voor het aantal teams dat er zijn (op dit moment 4 test teams dus hij maakt 2 pools aan 1 op 1)
Ik wil kunnen zien wie er dan 1 tegen 1 spelen
Kan iemand me hierbij helpen?
Hieronder staat de code:

PHP:
<?php

class ComCodDatabaseBehaviorPoolable extends KDatabaseBehaviorAbstract
{
    protected function _afterTableInsert(KCommandContext $context)
    {
        $totalRounds = $this->getService('com://admin/cod.model.rounds')->getTotal();
        if($totalRounds >= 1)
        {
            $totalRounds - 1;
            $totalTeams = $this->getService('com://admin/cod.model.teams')->limit(0)->getTotal();
            // Per round only half of the players of the previous round will advance.
            // This is selected by the number of rounds played.
            for($i = 1; $i < $totalRounds; $i++)
            {
                $totalTeams = $totalTeams / 2;
            }

            $teams = $this->getService('com://admin/cod.model.teams')->limit($totalTeams)->sort('score')->direction('desc')->getList()->toArray();

            $this->createPools($context->data, $teams);
        }
        else
        {
            // Here we need to select all the teams and place then in random pools.
            $teams = $this->getService('com://admin/cod.model.teams')->limit(0)->getList()->toArray();
            $this->createPools($context->data, $teams);
        }
    }

    private function createPools($round, $teams = array())
    {
        $lastPool = end($this->getService('com://admin/cod.model.pools')->limit(0)->getList()->toArray());
        $poolObject = '';
        $addCount = 0;
        if(empty($lastPool))
        {
            $pool = $this->getService('com://admin/cod.database.row.pool');
            $pool->setData(array(
                'title' => '1',
                'cod_round_id' => $round->id
            ));
            $pool->save();

            $poolObject = $pool;
        }
        if(empty($poolObject))
        {
            $pool = $this->getService('com://admin/cod.database.row.pool');
            $pool->setData(array(
                'title' => $lastPool['title'] + 1,
                'cod_round_id' => $round->id
            ));
            $pool->save();

            $poolObject = $pool;
        }

        // If we have more than 32 team we need to have a new round, if we have 32 teams it will become 1-on-1.
        if(count($teams) < 32)
        {
            while(count($teams) > 0)
            {
                if($addCount == 2)
                {
                    $pool = $this->getService('com://admin/cod.database.row.pool');
                    $pool->setData(array(
                        'title' => $poolObject->title + 1,
                        'cod_round_id' => $round->id
                    ));
                    $pool->save();

                    $poolObject = $pool;

                    $addCount = 0;
                }
                $team = array_rand($teams, 1);
                $pool_team = $this->getService('com://admin/cod.database.row.pools_team');
                $pool_team->setData(array(
                    'cod_team_id' => $team,
                    'cod_pool_id' => $poolObject->id
                ));
                $pool_team->save();

                unset($teams[$team]);

                $addCount++;
            }

        }
        else
        {
            // 4teams pools
            while(count($teams) > 0)
            {
                if($addCount == 4)
                {
                    $pool = $this->getService('com://admin/cod.database.row.pool');
                    $pool->setData(array(
                        'title' => $poolObject->title + 1,
                        'cod_round_id' => $round->id
                    ));
                    $pool->save();

                    $poolObject = $pool;

                    $addCount = 0;
                }
                $team = array_rand($teams, 1);
                $pool_team = $this->getService('com://admin/cod.database.row.pools_team');
                $pool_team->setData(array(
                    'cod_team_id' => $team['id'],
                    'cod_pool_id' => $poolID
                ));
                $pool_team->save();

                unset($teams[$team]);

                $addCount++;
            }
        }
    }
}

Met vriendelijke groeten kevin
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan