Esempio n. 1
0
 public function recordes2($param)
 {
     $this->uses('Recorde');
     $recordes = array();
     $pos = array('MORTES_CONSECUTIVAS_PRO', 'MORTES_CONSECUTIVAS_CONTRA', 'DAMAGE_APLICADO', 'DAMAGE_RECEBIDO', 'PONTOS_DAMAGE', 'PONTOS_ARMOR', 'PONTOS_HP', 'PONTOS_MP', 'PONTOS_STRENGTH', 'PONTOS_AGILITY', 'PONTOS_INTELIGENCE', 'KILL_CREPS', 'KILL_NELTRALS', 'KILL_AOE', 'GOLD');
     $neg = array('TOWER');
     $oficial = 1;
     $sql = "SELECT h1.* FROM historico AS h1 " . "JOIN duelo AS d on h1.duelo = d.id " . "WHERE h1.tipoRecorde <> 'TOWER' " . ($oficial === NULL ? "" : "AND d.oficial = {$oficial} ") . "ORDER BY tipoRecorde, valor DESC";
     $results = Historico::nativeQuery($sql);
     $sql = "SELECT h1.* FROM historico AS h1 " . "JOIN duelo AS d on h1.duelo = d.id " . "WHERE tipoRecorde = 'TOWER' " . ($oficial === NULL ? "" : "AND d.oficial = {$oficial} ") . "ORDER BY tipoRecorde, valor ";
     $results = array_merge($results, Historico::nativeQuery($sql));
     $tipo = NULL;
     $limit = 3;
     $c = 0;
     foreach ($results as $r) {
         $r = new Recorde(array("dueloId" => $r->duelo, "posicao" => 1, "tipoRecorde" => $r->tipoRecorde, "valor" => $r->valor));
         //$r = new Recorde($r->duelo, 0, $r->tipoRecorde, $r->valor);
         if ($tipo != $r->getTipoRecorde()) {
             $recordes[$r->getTipoRecorde()] = array();
             $tipo = $r->getTipoRecorde();
             $c = 0;
         }
         //$recordes[$tipo][] = $r;
         if ($c > 0) {
             if (is_array($recordes[$tipo][$c - 1])) {
                 if ($r->getValor() == $recordes[$tipo][$c - 1][0]->getValor()) {
                     $r->setPosicao($c);
                     $recordes[$tipo][$c - 1][] = $r;
                     continue;
                 }
             } else {
                 if ($r->getValor() == $recordes[$tipo][$c - 1]->getValor()) {
                     $r->setPosicao($c);
                     $recordes[$tipo][$c - 1] = array($recordes[$tipo][$c - 1], $r);
                     continue;
                 }
             }
         }
         if ($c >= $limit) {
             continue;
         }
         $r->setPosicao($c + 1);
         $recordes[$tipo][] = $r;
         $c++;
     }
     return json_encode($recordes);
 }