$id = intval($this->$id_field);
if ($orden === AI_SERVICIO_ORDEN_LONG_HIJOS) {
$query = "
- SELECT A.*, SUM(CEIL(LENGTH(B.nombre) / 22)) as RENGLONES
+ SELECT
+ A.*,
+ count(1) as COUNT,
+ SUM(CEIL(LENGTH(B.nombre) / 22)) as RENGLONES
FROM {$this->conf['base']}.{$this->conf['tabla']} AS A,
{$this->conf['base']}.{$this->conf['tabla']} AS B
WHERE A.$id_field = B.$id_padre
if ($soloHabilitados) {
$query .= " AND A.{$this->conf['habilitado']} = 1";
}
- $query .= " GROUP BY A.$id_field ORDER BY RENGLONES DESC";
+ $query .= "
+ GROUP BY A.$id_field
+ ORDER BY RENGLONES DESC, COUNT DESC, A.nombre";
} elseif ($orden === AI_SERVICIO_ORDEN_LONG_NOMBRE) {
$query = "
SELECT *