Viewing file: dt_nota.php (17.96 KB) -rw-rw-r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php class dt_nota extends toba_datos_tabla {
function get_listado($filtro=array(),$order='ORDER BY t_n.id_nota DESC') { $where = array();
if (isset($filtro['id_nota'])) { $where[] = "t_n.id_nota = '".$filtro['id_nota']."'"; }
if (isset($filtro['titulo'])) { $where[] = "t_n.titulo ILIKE ".quote("%{$filtro['titulo']}%"); }
if (isset($filtro['visible']) and count($filtro['visible'])>0) { foreach($filtro['visible'] as $visible_en){ switch($visible_en){ case 'principal': $where[] = "principal = 1"; break; case 'secundaria': $where[] = "secundaria = 1"; break; case 'newsletter': $where[] = "newsletter = 1"; break; case 'newsletter2': $where[] = "newsletter2 = 1"; break; } } }
if (isset($filtro['fecha_desde'])) { list($y,$m,$d)=explode("-",$filtro['fecha_desde']); //2011-03-31 $fecha_desde = $y."-".$m."-".$d; $where[] = "t_n.fecha_alta >= ".quote($fecha_desde); } if (isset($filtro['fecha_hasta'])) { list($y,$m,$d)=explode("-",$filtro['fecha_hasta']); //2011-03-31 $fecha_hasta = $y."-".$m."-".$d." 23:59:59"; $where[] = "t_n.fecha_alta <= ".quote($fecha_hasta); }
if (isset($filtro['usuario_alta'])) { $where[] = "t_n.usuario_alta ILIKE ".quote("%{$filtro['usuario_alta']}%"); } if (isset($filtro['estado'])) { $where[] = "t_n.estado = '".$filtro['estado']."'"; }
if (isset($filtro['id_seccion'])) { $where[] = "t_n.id_nota IN (select id_nota from seccion_nota where id_seccion = '".$filtro['id_seccion']."') "; }
if (isset($filtro['secciones']) and count($filtro['secciones'])>0) { $primero = true; foreach($filtro['secciones'] as $id_seccion){ if($primero){ $primero = false; $in_secciones.= $id_seccion; }else{ $in_secciones.= ','.$id_seccion; } }
if(!empty($in_secciones)){ $where[] = "t_n.id_nota IN (select id_nota from seccion_nota where id_seccion IN ($in_secciones) ) "; } }
//////////////////////// if (isset($filtro['limit'])) { $limit = 'LIMIT '.$filtro['limit']; }elseif (isset($filtro['string_limit'])) { $limit = $filtro['string_limit']; }
$sql = "SELECT t_n.id_nota, t_n.volanta, t_n.titulo, t_n.bajada, t_n.nota, t_n.foto, CASE WHEN t_n.foto IS NOT NULL THEN '<img src=\"fotos/'||t_n.foto||'\" width=\"120\" >' ELSE '' END as url_foto, t_n.epigrafe, t_n.nota, t_n.foto_2, CASE WHEN t_n.foto_2 IS NOT NULL THEN '<img src=\"fotos/'||t_n.foto_2||'\" width=\"120\" >' ELSE '' END as url_foto_2, t_n.epigrafe_2, t_n.nota_2, t_n.foto_3, CASE WHEN t_n.foto_3 IS NOT NULL THEN '<img src=\"fotos/'||t_n.foto_3||'\" width=\"120\" >' ELSE '' END as url_foto_3, t_n.epigrafe_3, t_n.nota_3, t_n.audio, t_n.video, t_n.video_mp4, t_n.principal, t_n.orden_principal, t_n.secundaria, t_n.orden_secundaria, t_n.newsletter, t_n.orden_newsletter, t_n.newsletter2, t_n.orden_newsletter2, t_n.fecha_alta, t_n.usuario_alta, t_n.estado, t_n.id_galeria, CASE WHEN t_n.estado='A' THEN 'Activa' WHEN t_n.estado='I' THEN 'Inactiva' WHEN t_n.estado='V' THEN 'Vista Previa' ELSE t_n.estado END as estado_descripcion, t_g.nombre as id_galeria_nombre, t_n.id_nota||' .'||t_n.titulo as descripcion, t_n.lecturas, t_n.autor, t_n.foto_autor, CASE WHEN t_n.foto_autor IS NOT NULL THEN '<img src=\"fotos/'||t_n.foto_autor||'\" height=\"100\" width=\"100\">' ELSE '' END as url_foto_autor, t_n.adjunto FROM nota as t_n LEFT OUTER JOIN galeria as t_g ON (t_n.id_galeria = t_g.id_galeria) $order $limit";
if (count($where)>0) { $sql = sql_concatenar_where($sql, $where); } $datos = toba::db('tdfonline')->consultar($sql);
return $datos; }
function get_total_registros($filtro=array()) { $where = array();
if (isset($filtro['id_nota'])) { $where[] = "t_n.id_nota = '".$filtro['id_nota']."'"; }
if (isset($filtro['titulo'])) { $where[] = "t_n.titulo ILIKE ".quote("%{$filtro['titulo']}%"); }
if (isset($filtro['visible']) and count($filtro['visible'])>0) { foreach($filtro['visible'] as $visible_en){ switch($visible_en){ case 'principal': $where[] = "principal = 1"; break; case 'secundaria': $where[] = "secundaria = 1"; break; case 'newsletter': $where[] = "newsletter = 1"; break; case 'newsletter2': $where[] = "newsletter2 = 1"; break; } } }
if (isset($filtro['fecha_desde'])) { list($y,$m,$d)=explode("-",$filtro['fecha_desde']); //2011-03-31 $fecha_desde = $y."-".$m."-".$d; $where[] = "t_n.fecha_alta >= ".quote($fecha_desde); } if (isset($filtro['fecha_hasta'])) { list($y,$m,$d)=explode("-",$filtro['fecha_hasta']); //2011-03-31 $fecha_hasta = $y."-".$m."-".$d." 23:59:59"; $where[] = "t_n.fecha_alta <= ".quote($fecha_hasta); }
if (isset($filtro['usuario_alta'])) { $where[] = "t_n.usuario_alta ILIKE ".quote("%{$filtro['usuario_alta']}%"); } if (isset($filtro['estado'])) { $where[] = "t_n.estado = '".$filtro['estado']."'"; }
if (isset($filtro['id_seccion'])) { $where[] = "t_n.id_nota IN (select id_nota from seccion_nota where id_seccion = '".$filtro['id_seccion']."') "; }
if (isset($filtro['secciones']) and count($filtro['secciones'])>0) { $primero = true; foreach($filtro['secciones'] as $id_seccion){ if($primero){ $primero = false; $in_secciones.= $id_seccion; }else{ $in_secciones.= ','.$id_seccion; } }
if(!empty($in_secciones)){ $where[] = "t_n.id_nota IN (select id_nota from seccion_nota where id_seccion IN ($in_secciones) ) "; } }
$sql = "SELECT count(t_n.id_nota) as cantidad FROM nota as t_n ";
if (count($where)>0) { $sql = sql_concatenar_where($sql, $where); } $datos = toba::db('tdfonline')->consultar_fila($sql);
if($datos['cantidad']>0){ return $datos['cantidad']; }else{ return 0; } }
function get_semaforo_estado($id_nota){ $sql = "SELECT estado FROM nota WHERE id_nota = '$id_nota'"; $dato = toba::db('tdfonline')->consultar_fila($sql);
/* WHEN t_n.estado='A' THEN 'Activa' WHEN t_n.estado='I' THEN 'Inactiva' WHEN t_n.estado='V' THEN 'Vista Previa' ELSE t_n.estado */ switch ($dato['estado']) { case 'A': $semaforo = '<div class="semaforo_activa">A</>'; break; case 'I': $semaforo = '<div class="semaforo_inactiva">I</>'; break;
case 'V': $semaforo = '<div class="semaforo_vistaprevia">B</>'; break; default: $semaforo = '<div class="semaforo_indefinido">'.$dato['estado'].'</>'; }
return $semaforo; }
function get_last_nota(){ $sql = "SELECT max(id_nota) as id_nota FROM nota"; $dato = toba::db('tdfonline')->consultar_fila($sql);
return $dato['id_nota'];
}
function get_foto($id_nota = '',$foto='') { #if(!empty($id_nota)){ $sql = "SELECT foto".$foto." FROM nota WHERE id_nota = '$id_nota'"; return toba::db('tdfonline')->consultar_fila($sql); #} }
function get_audio($id_nota = '') { $sql = "SELECT audio FROM nota WHERE id_nota = '$id_nota'"; return toba::db('tdfonline')->consultar_fila($sql); }
function get_video($id_nota = '') { $sql = "SELECT video_mp4 FROM nota WHERE id_nota = '$id_nota'"; return toba::db('tdfonline')->consultar_fila($sql); }
function get_foto_autor($id_nota = '') { #if(!empty($id_nota)){ $sql = "SELECT foto_autor FROM nota WHERE id_nota = '$id_nota'"; return toba::db('tdfonline')->consultar_fila($sql); #} }
function get_adjunto($id_nota) { $sql = "SELECT adjunto FROM nota WHERE id_nota = '$id_nota'"; return toba::db('tdfonline')->consultar_fila($sql); }
function activar_desactivar($id_nota){
$sql = "SELECT estado FROM nota WHERE id_nota = '$id_nota'"; $dato = toba::db('tdfonline')->consultar_fila($sql);
if($dato['estado']== 'A'){ $estado = 'I'; }elseif($dato['estado']== 'I'){ $estado = 'A'; }else{ return false; }
$sql = "UPDATE nota SET estado = '$estado' WHERE id_nota = '$id_nota'"; toba::db('tdfonline')->ejecutar($sql); return true; }
function set_portada($array_datos,$sector_visibilidad){ switch ($sector_visibilidad) { case 'principal': $sql = "UPDATE nota SET principal = 0 WHERE estado = 'A'"; toba::db('tdfonline')->ejecutar($sql);
foreach($array_datos as $dato){ if(!empty($dato['id_nota'])){ $sql = "UPDATE nota SET principal = 1, orden_principal = '".$dato['orden']."' WHERE estado = 'A' AND id_nota = '".$dato['id_nota']."'"; toba::db('tdfonline')->ejecutar($sql); } }
break;
case 'secundaria': $sql = "UPDATE nota SET secundaria = 0 WHERE estado = 'A'"; toba::db('tdfonline')->ejecutar($sql);
foreach($array_datos as $dato){ if(!empty($dato['id_nota'])){ $sql = "UPDATE nota SET secundaria = 1, orden_secundaria = '".$dato['orden']."' WHERE estado = 'A' AND id_nota = '".$dato['id_nota']."'"; toba::db('tdfonline')->ejecutar($sql); } }
break;
}
return true; }
function set_newsletter($array_datos,$sector_visibilidad){ $sql = "UPDATE nota SET $sector_visibilidad = 0 WHERE estado = 'A'"; toba::db('tdfonline')->ejecutar($sql);
foreach($array_datos as $dato){ if(!empty($dato['id_nota'])){ $sql = "UPDATE nota SET $sector_visibilidad = 1, orden_$sector_visibilidad = '".$dato['orden']."' WHERE estado = 'A' AND id_nota = '".$dato['id_nota']."'"; toba::db('tdfonline')->ejecutar($sql); } }
return true; }
function set_lecturas($id_nota){
$sql = "SELECT lecturas FROM nota WHERE id_nota = '$id_nota'"; $dato = toba::db('tdfonline')->consultar_fila($sql);
$lecturas = $dato['lecturas'] + 1;
$sql = "UPDATE nota SET lecturas = $lecturas WHERE id_nota = '$id_nota'"; if(toba::db('tdfonline')->ejecutar($sql)){ return true; }else{ return false; } }
function eliminar_nota($id_nota) { $sql = "SELECT foto, foto_autor, adjunto FROM nota WHERE id_nota = '$id_nota'"; $dato = toba::db('tdfonline')->consultar_fila($sql);
$sql = "DELETE FROM nota WHERE id_nota = '$id_nota'"; if (toba::db('tdfonline')->ejecutar($sql)){
if(!empty($dato['foto'])){ $folder_path = "../www/fotos/"; $nombre_archivo = $dato['foto']; $destino=$folder_path.$nombre_archivo; if(unlink($destino)){ //return true; }else{ //return false; } }
if(!empty($dato['foto_autor'])){ $folder_path = "../www/fotos/"; $nombre_archivo = $dato['foto_autor']; $destino=$folder_path.$nombre_archivo; if(unlink($destino)){ //return true; }else{ //return false; } }
if(!empty($dato['adjunto'])){ $folder_path = "../www/docs/"; $nombre_archivo = $dato['adjunto']; $destino=$folder_path.$nombre_archivo; if(unlink($destino)){ //return true; }else{ //return false; } }
return true; }else{ return false; } }
function get_descripciones() { $sql = "SELECT id_nota, titulo as descripcion_html FROM nota ORDER BY titulo"; return toba::db('tdfonline')->consultar($sql); }
//Las descripción del estado del EF se cargan a partir del resultado de este método. El formato de retorno es una cadena simple. static function get_nota_busca($id_nota=null) { if (! isset($id_nota)) { return array(); }
$sql = "SELECT t_n.id_nota, t_n.titulo, t_n.fecha_alta, t_n.usuario_alta, '#'||t_n.id_nota||' '||t_n.fecha_alta||' | '||t_n.titulo as descripcion FROM nota as t_n WHERE t_n.id_nota = '$id_nota' AND t_n.estado = 'A' ";
$result = toba::db('tdfonline')->consultar($sql); if (! empty($result)) { return $result[0]['descripcion']; } }
//Las opciones se cargan a partir del resultado del método. //El formato de retorno generalmente es una matriz fila por columnas, salvo los editables y el popup que requieren el retorno de un único valor. function get_notas_busca($filtro=null, $id_seccion =null, $locale=null) { if (! isset($filtro) || ($filtro == null) || trim($filtro) == '') { return array(); }
$and = ""; if ($id_seccion <> null) { $and = "AND t_n.id_nota IN (select id_nota from seccion_nota where id_seccion = '$id_seccion') "; } if(is_numeric($filtro)){ //es numero $filtro = quote("{$filtro}%"); $sql = "SELECT DISTINCT t_n.id_nota, '#'||t_n.id_nota||' '||t_n.fecha_alta||' | '||t_n.titulo as descripcion FROM nota as t_n WHERE CAST(t_n.id_nota AS TEXT) ILIKE $filtro AND t_n.estado = 'A' $and ORDER BY t_n.id_nota DESC LIMIT 20 "; }else{//es string $filtro = strtoupper($filtro); $filtro = quote("{$filtro}%"); $sql = "SELECT DISTINCT t_n.id_nota, '#'||t_n.id_nota||' '||t_n.fecha_alta||' | '||t_n.titulo as descripcion FROM nota as t_n WHERE t_n.titulo ILIKE $filtro AND t_n.estado = 'A' $and ORDER BY t_n.id_nota DESC LIMIT 20 "; } return toba::db('tdfonline')->consultar($sql); }
//----------------------------------------------------------------------------------- //---- Descripciones para portada borrador ------------------------------------------ //-----------------------------------------------------------------------------------
function get_activas($filtro=array()){
if (isset($filtro['id_seccion'])) { $where[] = "t_n.id_nota IN (select id_nota from seccion_nota where id_seccion = '".$filtro['id_seccion']."') "; }
$sql = "SELECT t_n.id_nota, t_n.titulo, t_n.fecha_alta, t_n.usuario_alta, '#'||t_n.id_nota||' '||t_n.fecha_alta||' | '||t_n.titulo as descripcion FROM nota as t_n WHERE t_n.estado = 'A' ORDER BY t_n.id_nota DESC";
if (count($where)>0) { $sql = sql_concatenar_where($sql, $where); }
return toba::db('tdfonline')->consultar($sql);
}
function get_activas_1(){ $filtro['id_seccion'] = 1; $datos = $this->get_activas($filtro); return $datos; }
function get_activas_2(){ $filtro['id_seccion'] = 2; $datos = $this->get_activas($filtro); return $datos; }
function get_activas_3(){ $filtro['id_seccion'] = 3; $datos = $this->get_activas($filtro); return $datos; }
function get_activas_4(){ $filtro['id_seccion'] = 4; $datos = $this->get_activas($filtro); return $datos; }
function get_activas_5(){ $filtro['id_seccion'] = 5; $datos = $this->get_activas($filtro); return $datos; } function get_activas_6(){ $filtro['id_seccion'] = 6; $datos = $this->get_activas($filtro); return $datos; } function get_activas_7(){ $filtro['id_seccion'] = 7; $datos = $this->get_activas($filtro); return $datos; }
function get_activas_8(){ $filtro['id_seccion'] = 8; $datos = $this->get_activas($filtro); return $datos; }
function get_activas_9(){ $filtro['id_seccion'] = 9; $datos = $this->get_activas($filtro); return $datos; }
function get_activas_10(){ $filtro['id_seccion'] = 10; // $datos = $this->get_activas($filtro); return $datos; }
function get_activas_11(){ $filtro['id_seccion'] = 11; $datos = $this->get_activas($filtro); return $datos; } function get_activas_12(){ $filtro['id_seccion'] = 12; $datos = $this->get_activas($filtro); return $datos; }
function get_activas_13(){ $filtro['id_seccion'] = 13; $datos = $this->get_activas($filtro); return $datos; }
function get_activas_14(){ $filtro['id_seccion'] = 14; $datos = $this->get_activas($filtro); return $datos; }
function get_activas_15(){ $filtro['id_seccion'] = 15; $datos = $this->get_activas($filtro); return $datos; }
function get_activas_16(){ $filtro['id_seccion'] = 16; $datos = $this->get_activas($filtro); return $datos; }
function get_activas_17(){ $filtro['id_seccion'] = 17; $datos = $this->get_activas($filtro); return $datos; } function get_activas_18(){ $filtro['id_seccion'] = 18; $datos = $this->get_activas($filtro); return $datos; } function get_activas_19(){ $filtro['id_seccion'] = 19; $datos = $this->get_activas($filtro); return $datos; }
function get_activas_20(){ $filtro['id_seccion'] = 20; $datos = $this->get_activas($filtro); return $datos; }
function get_activas_21(){ $filtro['id_seccion'] = 21; $datos = $this->get_activas($filtro); return $datos; }
} ?>
|