Stuck on the maze - could a Helper help?

Hello all,

I have to list several elements that are coming from a database source A and they are:
team_id, team_name and team_score (translated for explanation sake).

I need to loop over them, and display that information.

So, I have, on the DAO side:

public function listaEquipasInscritas()
{
  $select = $this->select()
    ->from(array('e'=>'equipas'), array('cod_equipa','nome','pontos'));
  return $this->fetchAll($select);

}

On my controller:

public function listaAction()
{
  $equipasDao = new EquipasDao();
  $this->view->infoEquipa = $equipasDao->listaEquipasInscritas();                    
}

And at the view:

<?php for($i = 0; $i < 30; $i++): ?>

  <?php if(isset($this->infoEquipa[$i])): ?>

Now, the thing is, on each of those listed items, I need to add more information.

That information doesn’t come directly from a database, but it’s a result of some calculations.

Take for example the percentage of games done. (translated);

$totalGamesNumber > 0 ? ($gamesDone*100)/$totalGamesNumber : 0);

So, I need to grab the total games number from the database, then, for each team, I need to have the number of games done, so that I can have the percentage to be displayed for each of them.

The $gamesDone are obtained by:

$desafioEquipaDao->contaDesafiosPorEstadoPorEquipa($desafioVo, $equipaVo);

I’m stuck here, because I cannot see where/how should I call and make the method for calculating the percentage, in order to allow the percentage of games completed to be presented along with the other data.

Can I have some help out of this mud ?

Thanks in advance,
Márcio

Let’s forget about the all post.

I have the following:

$completedGames = gamesTeamDao->countGamesPerTeam($gameVo, $teamVo);

countGamesPerTeam() Looks like this:


$select = $this->getAdapter()->select();
$select->from(array("t"=>"team"),array('COUNT(*) AS gamesNumber'));
            $select->join(array("gt"=>"gamesperteam"),"t.cod_team = gt.cod_teamFk",array());
            $select->join(array("g"=>"games"),"d.cod_games = gt.cod_gamesFk");
            $select->where("gt.status = ".$gameVo->getStatus());
            $select->where("t.cod_team = ".$teamVo->getCodTeam());

            $row = $this->getAdapter()->fetchRow($select);

            return $row['gamesNumber'];

After this I do,

$totalGames = $gameDao->totalGames();

$gameVo->setStatus(1);

$gamesFinished = $gameTeamDao->countGamesPerTeam($gameVo, $teamVo);
                
$this->view->percentageFinishedGames = ($totalGames > 0 ? ($gamesFinished*100)/$totalGames : 0);

Then, I can use "percentageFinishedGames on the view.

This works when we want to list ONE team game percentage information.

How should I change it, in order to allow the display for the percentage for All teams?

Thanks again,
MEM

Try number three., maybe like this makes more sense:

Hello all, :smiley:

I have to list several elements that are coming from a database source A and they are:
team_id, team_name and team_score (translated for explanation sake).

I need to loop over them, and display that information.

So, I have, on the DAO side:

    public function listOfTeams()
    {
      $select = $this->select()
        ->from(array('t'=>'teams'), array('cod_team','name','score'));
      return $this->fetchAll($select);
    
    }

On my team controller:


    public function listAction()
    {
      $teamsDao = new TeamsDao();
      $this->view->infoTeam = $teamsDao->listOfTeams();                    
    }

And at the view:

    <?php for($i = 0; $i < 30; $i++): ?>
    
      <?php if(isset($this->infoTeam[$i])): ?>

Now, the thing is, on each of those listed items, I need to add more information.

That information doesn’t come directly from a database, but it’s a result of some calculations.

Take for example the percentage of games done. (translated);

    $totalGamesNumber > 0 ? ($gamesDone*100)/$totalGamesNumber : 0);

So, I need to grab the total games number from the database, then, for each team, I need to have the number of games done, so that I can have the percentage to be displayed.

The $gamesDone are obtained by:

  $gameTeamDao->countGamesPerTeam($gameVo, $teamVo);

I’m stuck here, because I cannot see where/how should I call and make the method for calculating the percentage, in order to allow the percentage of games completed to be presented along with the other data.

If you had to write a helper for this, more or less, how will it looked like?

Márcio

PS - If you need more detailed information. I can provide. I could be forgeting something that for me is taken, but that, for those who want to help it isn’t. So, just let me know. Thanks a lot again.