public function stats_temas() { $stats = array(); $te0 = new inme_tema(); $max = 9; foreach ($te0->populares() as $i => $tema) { if ($i < $max) { $sql = "SELECT DATE_FORMAT(fecha, '%Y-%m') as fecha2,SUM(popularidad) as num FROM inme_noticias_fuente" . " WHERE keywords LIKE '%[" . $tema->codtema . "]%' group by fecha2"; $data = $this->db->select($sql); if ($data) { foreach ($data as $d) { if (!isset($stats[$d['fecha2']])) { $stats[$d['fecha2']] = array('time' => strtotime($d['fecha2']), 'tema_0' => array('codtema' => '-', 'popularidad' => 0), 'tema_1' => array('codtema' => '-', 'popularidad' => 0), 'tema_2' => array('codtema' => '-', 'popularidad' => 0), 'tema_3' => array('codtema' => '-', 'popularidad' => 0), 'tema_4' => array('codtema' => '-', 'popularidad' => 0), 'tema_5' => array('codtema' => '-', 'popularidad' => 0), 'tema_6' => array('codtema' => '-', 'popularidad' => 0), 'tema_7' => array('codtema' => '-', 'popularidad' => 0)); } $stats[$d['fecha2']]['tema_' . $i]['codtema'] = $tema->codtema; $stats[$d['fecha2']]['tema_' . $i]['popularidad'] = intval($d['num']); } } } else { break; } } /// completamos datos foreach ($te0->populares() as $i => $tema) { if ($i < $max) { foreach ($stats as $j => $value) { $stats[$j]['tema_' . $i]['codtema'] = $tema->codtema; } } else { break; } } /// ordenamos uasort($stats, function ($a, $b) { if ($a['time'] == $b['time']) { return 0; } else { if ($a['time'] < $b['time']) { return -1; } else { return 1; } } }); return $stats; }
public function procesar_portada() { $this->mostrar = 'portada'; if (isset($_GET['mostrar'])) { $this->mostrar = $_GET['mostrar']; } $this->buscar = ''; if (isset($_REQUEST['buscar'])) { $this->buscar = $_REQUEST['buscar']; } $this->codfuente = ''; if (isset($_GET['codfuente'])) { $this->codfuente = $_GET['codfuente']; } $this->keyword = ''; if (isset($_GET['keyword'])) { $this->keyword = $_GET['keyword']; } $this->offset = 0; if (isset($_GET['offset'])) { $this->offset = intval($_GET['offset']); } $this->preview = new inme_noticia_preview(); $noti = new inme_noticia_fuente(); if ($this->buscar != '') { $this->noticias = $noti->search($this->buscar, $this->offset); } else { if ($this->codfuente != '') { $this->noticias = $noti->all_from_fuente($this->codfuente, $this->offset); } else { if ($this->keyword != '') { $this->noticias = $noti->all_from_keyword($this->keyword, $this->offset); } else { if ($this->mostrar == 'portada') { if ($this->offset > 0) { $this->noticias = $noti->all($this->offset, 'publicada DESC'); } else { $this->noticias = $this->cache->get('inme_portada'); if (!$this->noticias) { $this->noticias = $noti->all($this->offset, 'publicada DESC'); $this->cache->set('inme_portada', $this->noticias, 300); } } } else { if ($this->mostrar == 'populares') { $this->noticias = $noti->all($this->offset, 'popularidad DESC'); } else { $this->noticias = $noti->all($this->offset); } } } } } $tema = new inme_tema(); $this->mostrar_tema = FALSE; if (isset($_GET['keyword'])) { $this->mostrar_tema = $tema->get($_GET['keyword']); } $this->temas_populares = $this->cache->get('inme_temas_populares'); if (!$this->temas_populares) { $this->temas_populares = $tema->populares(); $this->cache->set('inme_temas_populares', $this->temas_populares, 300); } }