Example #1
0
 /**
  * Presenta una tabla ordenada segun los resultados de la manga
  *@param {integer} $mode 0:L 1:M 2:S 3:MS 4:LMS 5:T 6:L+M 7:S+T 8 L+M+S+T
  *@return {array} requested data or error
  */
 function getResultados($mode)
 {
     $this->myLogger->enter();
     $idmanga = $this->IDManga;
     // FASE 0: en funcion del tipo de recorrido y modo pedido
     // ajustamos el criterio de busqueda de la tabla de resultados
     $where = "(Manga={$idmanga}) AND (Pendiente=0) ";
     $cat = "";
     switch ($mode) {
         case 0:
             /* Large */
             $cat = "AND (Categoria='L')";
             break;
         case 1:
             /* Medium */
             $cat = "AND (Categoria='M')";
             break;
         case 2:
             /* Small */
             $cat = "AND (Categoria='S')";
             break;
         case 3:
             /* Med+Small */
             $cat = "AND ( (Categoria='M') OR (Categoria='S') )";
             break;
         case 4:
             /* L+M+S */
             $cat = "AND ( (Categoria='L') OR (Categoria='M') OR (Categoria='S') )";
             break;
         case 5:
             /* Tiny */
             $cat = "AND (Categoria='T')";
             break;
         case 6:
             /* L+M */
             $cat = "AND ( (Categoria='L') OR (Categoria='M') )";
             break;
         case 7:
             /* S+T */
             $cat = "AND ( (Categoria='S') OR (Categoria='T') )";
             break;
         case 8:
             /* L+M+S+T */
             break;
             // no check categoria
         // no check categoria
         default:
             return $this->error("modo de recorrido desconocido:{$mode}");
     }
     // FASE 1: recogemos resultados ordenados por precorrido y tiempo
     $res = $this->__select("Dorsal,Perro,Nombre,Raza,Equipo,Licencia,Categoria,Grado,NombreGuia,NombreClub,Faltas,Tocados,Rehuses,Tiempo,Eliminado,NoPresentado,\n\t\t\t\t\t( 5*Faltas + 5*Rehuses + 5*Tocados + 100*Eliminado + 200*NoPresentado ) AS PRecorrido,\n\t\t\t\t\t0 AS PTiempo, 0 AS Penalizacion, '' AS Calificacion, 0 AS Velocidad", "Resultados", "{$where} {$cat}", " PRecorrido ASC, Tiempo ASC", "");
     if (!is_array($res)) {
         $this->myLogger->leave();
         return $this->error($this->conn->error);
     }
     $table = $res['rows'];
     // FASE 2: evaluamos TRS Y TRM
     $tdata = $this->evalTRS($mode, $table);
     // array( 'dist' 'obst' 'trs' 'trm', 'vel')
     $res['trs'] = $tdata;
     // store trs data into result
     $trs = $tdata['trs'];
     $trm = $tdata['trm'];
     // FASE 3: aƱadimos ptiempo, puntuacion, clasificacion y logo
     $clubes = new Clubes("Resultados::getResultados", $this->getDatosPrueba()->RSCE);
     $size = count($table);
     for ($idx = 0; $idx < $size; $idx++) {
         $table[$idx]['Puntos'] = 0;
         // to be re-evaluated later
         // importante: las asignaciones se hacen en base a $table[$idx],
         // pues si no solo se actualiza la copia
         if ($trs == 0) {
             // si TRS==0 no hay penalizacion por tiempo
             $table[$idx]['PTiempo'] = 0.0;
             $table[$idx]['Penalizacion'] = $table[$idx]['PRecorrido'];
         } else {
             // evaluamos penalizacion por tiempo y penalizacion final
             if ($table[$idx]['Tiempo'] < $trs) {
                 // Por debajo del TRS
                 $table[$idx]['PTiempo'] = 0.0;
                 $table[$idx]['Penalizacion'] = $table[$idx]['PRecorrido'];
             }
             if ($table[$idx]['Tiempo'] >= $trs) {
                 // Superado TRS
                 $table[$idx]['PTiempo'] = $table[$idx]['Tiempo'] - $trs;
                 $table[$idx]['Penalizacion'] = floatval($table[$idx]['PRecorrido']) + $table[$idx]['PTiempo'];
             }
             if ($table[$idx]['Tiempo'] > $trm) {
                 // Superado TRM: eliminado
                 $table[$idx]['Penalizacion'] = 100.0;
             }
         }
         // evaluamos velocidad
         if ($table[$idx]['Tiempo'] == 0) {
             $table[$idx]['Velocidad'] = 0;
         } else {
             $table[$idx]['Velocidad'] = $tdata['dist'] / $table[$idx]['Tiempo'];
         }
         // anyadimos nombre del equipo
         $dequipos = $this->getDatosEquipos();
         $eqinfo = $dequipos[$table[$idx]['Equipo']];
         $table[$idx]['NombreEquipo'] = $eqinfo['Nombre'];
         // anyadimos logotipo del club
         $table[$idx]['LogoClub'] = $clubes->getLogoName('NombreClub', $table[$idx]['NombreClub']);
     }
     // FASE 4: re-ordenamos los datos en base a la puntuacion y calculamos campo "Puesto"
     usort($table, function ($a, $b) {
         if ($a['Penalizacion'] == $b['Penalizacion']) {
             return $a['Tiempo'] > $b['Tiempo'] ? 1 : -1;
         }
         return $a['Penalizacion'] > $b['Penalizacion'] ? 1 : -1;
     });
     // format output data and take care con duplicated penalizacion and time
     // calculamos campo "Puesto", "Calificacion" y Puntos
     $puestocat = array('C' => 1, 'L' => 1, 'M' => 1, 'S' => 1, 'T' => 1);
     // ultimo puesto por cada categoria
     $lastcat = array('C' => 0, 'L' => 0, 'M' => 0, 'S' => 0, 'T' => 0);
     // ultima puntuacion por cada categoria
     $countcat = array('C' => 0, 'L' => 0, 'M' => 0, 'S' => 0, 'T' => 0);
     // perros contabilizados de cada categoria
     $fed = $this->getFederation();
     for ($idx = 0; $idx < $size; $idx++) {
         // vemos la categoria y actualizamos contadores de categoria
         $cat = $table[$idx]['Categoria'];
         $countcat['C']++;
         // Conjunta
         $countcat[$cat]++;
         // Por categoria
         // obtenemos la penalizacion del perro actual
         $now = 100 * $table[$idx]['Penalizacion'] + $table[$idx]['Tiempo'];
         // ajustamos puesto conjunto y guardamos resultado
         if ($lastcat['C'] != $now) {
             $lastcat['C'] = $now;
             $puestocat['C'] = $countcat['C'];
         }
         $table[$idx]['Puesto'] = $puestocat['C'];
         // ajustamos puesto por categoria y guardamos resultado
         if ($lastcat[$cat] != $now) {
             $lastcat[$cat] = $now;
             $puestocat[$cat] = $countcat[$cat];
         }
         $table[$idx]['Pcat'] = $puestocat[$cat];
         // la calificacion depende de categoria, grado y federacion
         $fed->evalPartialCalification($this->getDatosPrueba(), $this->getDatosJornada(), $this->getDatosManga(), $table[$idx], $puestocat);
     }
     // componemos datos del array a retornar
     $res['rows'] = $table;
     $res['manga'] = $this->getDatosManga();
     $res['trs'] = $tdata;
     $this->myLogger->leave();
     return $res;
 }
 function printClub($id)
 {
     $y = $this->GetY();
     // retrieve club data
     $cmgr = new Clubes('printCatalogo', $this->prueba->RSCE);
     $club = $cmgr->selectByID($id);
     $fedName = $this->federation->get('Name');
     // evaluate logo
     $icon = getIconPath($fedName, "agilitycontest.png");
     if ($club['Logo'] === "") {
         $this->myLogger->error("inscritosByPrueba::printClub() club:{$id} {$club['Nombre']} no logo declared");
         $icon = getIconPath($fedName, $this->federation->get('Logo'));
         // default is federation logo
     } else {
         $icon = $icon = getIconPath($fedName, $club['Logo']);
     }
     $this->myLogger->trace("ID:" . $id . " Club: " . $club['Nombre']);
     $this->ac_SetFillColor($this->config->getEnv('pdf_hdrbg1'));
     // azul
     $this->ac_SetTextColor($this->config->getEnv('pdf_hdrfg1'));
     // blanco
     $this->ac_SetDrawColor($this->config->getEnv('pdf_linecolor'));
     // line color
     $this->SetLineWidth(0.3);
     // ancho de linea
     // pintamos logo
     $this->SetXY(10, $y);
     $this->Cell(22, 22, '', 'LTB', 0, 'C', false);
     $this->Image($icon, 12, 2 + $y, 18, 18);
     // pintamos info del club
     $this->SetFont($this->getFontName(), 'B', 9);
     $this->SetXY(32, $y);
     $this->Cell(50, 5, $club['Direccion1'], 'LT', 0, 'L', true);
     // pintamos direccion1
     $this->SetXY(32, 5 + $y);
     $this->Cell(50, 5, $club['Direccion2'], 'L', 0, 'L', true);
     // pintamos direccion2
     $this->SetXY(32, 10 + $y);
     $prov = $club['Provincia'];
     if ($prov === "-- Sin asignar --") {
         $prov = "";
     }
     $this->Cell(50, 5, $prov, 'L', 0, 'L', true);
     // pintamos provincia
     $this->SetFont($this->getFontName(), 'IB', 24);
     $this->SetXY(82, $y);
     $this->Cell(110, 15, $club['Nombre'], 'T', 0, 'R', true);
     // pintamos Nombre
     $this->Cell(10, 15, '', 'TR', 0, 'R', true);
     // caja vacia de relleno
     // pintamos cabeceras de la tabla
     $this->ac_SetFillColor($this->config->getEnv('pdf_hdrbg2'));
     // gris
     $this->ac_SetTextColor($this->config->getEnv('pdf_hdrfg2'));
     // negro
     $this->SetFont($this->getFontName(), 'B', 9);
     $this->SetXY(32, 15 + $y);
     $this->Cell($this->width[0], 7, _('Name'), 'LTB', 0, 'C', true);
     $this->Cell($this->width[1], 7, _('Breed'), 'LTB', 0, 'C', true);
     if ($this->width[2] != 0) {
         // skip license on international contests
         $this->Cell($this->width[2], 7, _('License'), 'LTB', 0, 'C', true);
     }
     $this->Cell($this->width[3], 7, _('Cat') . '/' . _('Grade'), 'LTB', 0, 'C', true);
     $this->Cell($this->width[4], 7, _('Handler'), 'LTBR', 0, 'C', true);
     // print names of each declared journeys
     for ($i = 5; $i < count($this->width); $i++) {
         // en la cabecera texto siempre centrado
         if ($this->width[$i] == 0) {
             continue;
         }
         $this->Cell($this->width[$i], 7, $this->cellHeader[$i - 5], 1, 0, 'C', true);
     }
     $this->Ln();
 }
Example #3
0
*/
require_once __DIR__ . "/../logging.php";
require_once __DIR__ . "/../tools.php";
require_once __DIR__ . "/../auth/AuthManager.php";
require_once __DIR__ . "/../i18n/Country.php";
require_once __DIR__ . "/classes/Clubes.php";
try {
    $result = null;
    $operation = http_request("Operation", "s", null);
    $federation = http_request("Federation", "i", -1);
    // force exception if undefined
    $idclub = http_request("ID", "i", 0);
    if ($operation === null) {
        throw new Exception("Call to clubFunctions without 'Operation' requested");
    }
    $clubes = new Clubes("clubFunctions", $federation);
    $am = new AuthManager("clubFunctions");
    switch ($operation) {
        case "insert":
            $am->access(PERMS_OPERATOR);
            $result = $clubes->insert();
            break;
        case "update":
            $am->access(PERMS_OPERATOR);
            $result = $clubes->update($idclub);
            break;
        case "delete":
            $am->access(PERMS_OPERATOR);
            $result = $clubes->delete($idclub);
            break;
        case "select":
Example #4
0
 /**
  * Obtiene la lista ordenada de perros de esta jornada asociadas a la sesion, y tandas especificadas
  * @param {integer} $s session id.
  *    0: ANY sesion
  *    1: ANY BUT User defined sessions
  *   -1: User defined sessions
  *    n: Session number "n"
  *   -n: Session number "n" PLUS User defined sessions
  * @param {number} $t Tanda ID.
  *     $t=0; mira todos los perros de todas las tandas de la sesion indicada
  *     $t>0; mira SOLO los perros de la tanda
  *     $t<0; mira todos los perros A PARTIR DE la tanda (-$t)
  * @param {number} $pendientes Pendientes $p==0 -> muestra todos los perros; else muestra los $p primeros pendientes de salir
  */
 private function getListaPerros($s = 0, $t = 0, $pendientes = 0)
 {
     $count = $pendientes;
     // contador de perros pendientes de listar
     $manga = 0;
     // variable para controlar manga "activa"
     $perrosmanga = null;
     // {array} lista de perros ordenada segun ordensalida de la manga
     $do_iterate = false;
     // indica si debe analizar los perros de la tanda
     $rows = array();
     // donde iremos guardando los resultados
     $result = array();
     // resultado a devolver en formato json
     // obtenemos la lista de tandas
     $lista_tandas = $this->getTandas($s);
     $club = new Clubes("Tandas::getListaPerros", $this->prueba->RSCE);
     // iteramos la lista de tandas
     foreach ($lista_tandas['rows'] as $tanda) {
         $this->myLogger->info("Analizando tanda \n" . json_encode($tanda));
         // Comprobamos si debemos analizar la tanda
         if ($t > 0) {
             $do_iterate = $tanda['ID'] == abs($t) ? true : false;
         }
         // iterar solo la tanda
         if ($t < 0) {
             if ($tanda['ID'] == abs($t)) {
                 $do_iterate = true;
             }
         }
         // iterar a partir de la tanda
         if ($t == 0) {
             $do_iterate = true;
         }
         // iterar TODAS las tandas
         if (!$do_iterate) {
             continue;
         }
         // this tanda is not the one we are looking for
         if ($tanda['Manga'] == 0) {
             continue;
         }
         // user defined tandas, has no manga associated
         // comprobamos ahora si hay cambio de manga
         if ($manga != $tanda['Manga']) {
             // cambio de manga
             $manga = $tanda['Manga'];
             // en cada manga cogemos  los perros ordenados segun el orden de salida
             $os = new OrdenSalida("Tandas::getListaPerros()", $manga);
             $perrosmanga = $os->getData(false);
             // false: do not include extra team information rows
         }
         // OK ya tenemos la lista ordenada de los perros de cada manga
         // Ahora vamos a sacar la lista por cada tanda
         foreach ($perrosmanga['rows'] as &$perro) {
             // si el perro no pertenece a la tanda skip (comprobar categoria)
             if (strpos($tanda['Categoria'], $perro['Categoria']) === false) {
                 continue;
             }
             $perro['Tanda'] = $tanda['Nombre'];
             $perro['ID'] = $tanda['ID'];
             // replace resultadoID por tandaID TODO: revise why
             if ($pendientes == 0) {
                 // include all
                 $perro['LogoClub'] = $club->getLogoName('NombreClub', $perro['NombreClub']);
                 array_push($rows, $perro);
                 continue;
             }
             if ($perro['Pendiente'] == 0) {
                 continue;
             }
             // not pendiente: skip
             if ($count > 0) {
                 // not yet at count: insert
                 $count--;
                 $perro['LogoClub'] = $club->getLogoName('NombreClub', $perro['NombreClub']);
                 array_push($rows, $perro);
                 continue;
             }
             // arriving here means that every requested dogs are filled
             $this->myLogger->debug("Tandas::getListaPerros() Already have {$pendientes} dogs");
             // so return
             $result['rows'] = $rows;
             $result['total'] = count($rows);
             $this->myLogger->leave();
             return $result;
         }
         // no more dogs in this tanda. go to next
     }
     $result['rows'] = $rows;
     $result['total'] = count($rows);
     $this->myLogger->leave();
     return $result;
 }
Example #5
0
 /**
  * Anyade una pagina con informacion de la prueba y de las jornadas
  * @param $prueba
  * @param $jornadas
  */
 function createPruebaInfoPage($prueba, $jornadas)
 {
     // Create page
     $ppage = $this->myWriter->addNewSheetAndMakeItCurrent();
     $name = $this->normalizeSheetName($prueba['Nombre']);
     $ppage->setName($name);
     // cabecera de la tabla
     $prbHdr = array("", _utf('Name'), _utf('Club'), _utf('Federation'), _utf('Selective'), _utf('Comments'));
     $this->myWriter->addRowWithStyle($prbHdr, $this->rowHeaderStyle);
     // componemos informacion de la prueba
     $row = array();
     $row[] = _utf('Contest') . ':';
     $row[] = $prueba['Nombre'];
     // extract club info
     $clbObj = new Clubes("common_writer");
     $club = $clbObj->selectByID($prueba['Club']);
     $row[] = $club['Nombre'];
     // extract federation info
     $row[] = $this->federation->get('Name');
     // add extra parameters
     $row[] = $prueba['Selectiva'];
     $row[] = $prueba['Observaciones'];
     // and print Prueba data
     $this->myWriter->addRow($row);
     // anyadimos ahora informacion de las jornadas
     $this->myWriter->addRow(array(""));
     $jrdHdr = array("", _utf('Name'), _utf('Date'), _utf('Hour'), _utf('Closed'), "");
     $this->myWriter->addRowWithStyle($jrdHdr, $this->rowHeaderStyle);
     foreach ($jornadas as $jornada) {
         if ($jornada['Nombre'] === '-- Sin asignar --') {
             continue;
         }
         // skip empty journeys
         $row = array();
         $row[] = _utf('Journey') . ": " . $jornada['Numero'];
         $row[] = $jornada['Nombre'];
         $row[] = $jornada['Fecha'];
         $row[] = $jornada['Hora'];
         $row[] = $jornada['Cerrada'];
         if ($jornada['Observaciones'] != null && $jornada['Observaciones'] !== "(sin especificar)") {
             $row[] = $jornada['Observaciones'];
             // add name for special rounds
         }
         $this->myWriter->addRow($row);
     }
 }