Ver Mensaje Individual
  #1 (permalink)  
Antiguo 07/07/2016, 10:13
Avatar de katanaweb
katanaweb
 
Fecha de Ingreso: marzo-2014
Ubicación: Argentina
Mensajes: 18
Antigüedad: 10 años, 1 mes
Puntos: 0
Pregunta Simplificar el código generado

Hola amigos,

Les cuento que estoy implementando el plugin JS Ticket Support para Wordpress y este cuando se crea un ticket genera un TicketID que se usa como un número de reclamo, el problema es que es muy complejo, creo que encontré la función que lo genera:

Código PHP:
function getRandomTicketId() {
        
$query "SELECT ticketid FROM `" jssupportticket::$_db->prefix "js_ticket_tickets`";
        
$match '';
        do {
            
$ticketid "";
            
$length 9;
            
$possible "2346789bcdfghjkmnpqrtvwxyzBCDFGHJKLMNPQRTVWXYZ";
            
// we refer to the length of $possible a few times, so let's grab it now
            
$maxlength strlen($possible);
            if (
$length $maxlength) { // check for length overflow and truncate if necessary
                
$length $maxlength;
            }
            
// set up a counter for how many characters are in the ticketid so far
            
$i 0;
            
// add random characters to $password until $length is reached
            
while ($i $length) {
                
// pick a random character from the possible ones
                
$char substr($possiblemt_rand(0$maxlength 1), 1);
                if (!
strstr($ticketid$char)) {
                    if (
$i == 0) {
                        if (
ctype_alpha($char)) {
                            
$ticketid .= $char;
                            
$i++;
                        }
                    } else {
                        
$ticketid .= $char;
                        
$i++;
                    }
                }
            }
            
$rows jssupportticket::$_db->get_results($query);
            foreach (
$rows as $row) {
                if (
$ticketid == $row->ticketid)
                    
$match 'Y';
                else
                    
$match 'N';
            }
        }while (
$match == 'Y');
        return 
$ticketid;
    } 
Yo quiero simplificarlo, hoy está generando algo así: TcQ6jrF74, me gustaría que sean solo números, alguien me podría dar una mano?