Ver Mensaje Individual
  #17 (permalink)  
Antiguo 11/05/2004, 21:37
Avatar de Calisco
Calisco
 
Fecha de Ingreso: marzo-2004
Ubicación: Neuquen
Mensajes: 732
Antigüedad: 20 años, 1 mes
Puntos: 4
Correcciones de los scripts.

Bueno, la verdad que todo esto me esta dando vuelta la cabeza. Me parece que es demasiado para mi. Igualmente, estuve depurando un poco el codigo e hice correcciones de sintaxis.
Aca los pongo por si alguien quiere reutilizar este codigo:

Clase Noticias
Código PHP:
<?php
class Noticias{
    
        var 
$ArrayPropiedades null;

        function 
Noticias$objDatos null){

            if( 
$objDatos !== null && is_array$objDatos ) ){

                foreach( 
$objDatos as $k => $v ){

                    
$this->ArrayPropiedades[$k] = $v;

                }

            }
            return;

        }

        function 
obtId(){

            switch( 
func_num_args()){

                case 
0:
                        return 
$this->ArrayPropiedades['id_noticia'];
                        break;
                case 
1:
                        
$this->ArrayPropiedades['id_noticia']= func_get_arg(0);
                        break;

            }

        }

        function 
obtUsuarioId(){

            switch( 
func_num_args()){

                case 
0:
                        return 
$this->ArrayPropiedades['id_usuario'];
                        break;
                case 
1:
                        
$this->ArrayPropiedades['id_usuario']= func_get_arg(0);
                        break;

            }

        }

        function 
obtTitulo(){

            switch( 
func_num_args()){

                case 
0:
                        return 
$this->ArrayPropiedades['titulo'];
                        break;
                case 
1:
                        
$this->ArrayPropiedades['titulo']= func_get_arg(0);
                        break;

            }

        }

        function 
obtDescripcion(){

            switch( 
func_num_args()){

                case 
0:
                        return 
$this->ArrayPropiedades['descripcion'];
                        break;
                case 
1:
                        
$this->ArrayPropiedades['descripcion']= func_get_arg(0);
                        break;

            }

        }

        function 
obtFecha(){

            switch( 
func_num_args()){

                case 
0:
                        return 
$this->ArrayPropiedades['fecha'];
                        break;
                case 
1:
                        
$this->ArrayPropiedades['fecha']= func_get_arg(0);
                        break;

            }

        }

        function 
obtImagen(){

            switch( 
func_num_args()){

                case 
0:
                        return 
$this->ArrayPropiedades['imagen'];
                        break;
                case 
1:
                        
$this->ArrayPropiedades['imagen']= func_get_arg(0);
                        break;

            }

        }

        function 
obtLink(){

            switch( 
func_num_args()){

                case 
0:
                        return 
$this->ArrayPropiedades['link'];
                        break;
                case 
1:
                        
$this->ArrayPropiedades['link']= func_get_arg(0);
                        break;

            }

        }
    
    }
?>

Clase Mapper
Código PHP:
<?php
class NoticiaMapper{

        var 
$_bdcon null;

        var 
$_arrayNoticias null;

        function 
NoticiaMapper(){

            
$this->_bdcon DB::connect($dsn);
            if( 
DB::isError($this->_bdcon) )
            {
                die( 
$this->_bdcon->getMessage( ) );
            }

        }

        function 
obtListaNoticias(){

            
$sql 'SELECT * FROM noticias';
            
$sqlResult $this->_bdcon->query($sql);

            if( 
$this->_bdcon->isError($sqlResult)){

                die(
$sqlResult->getMessage());

            }

            if( 
$sqlResult->numRows() > 0){

                while( 
$registro $sqlResult->fetchRow(DB_FETCHMODE_ASSOC) ){

                    
$this->_arrayNoticias[ ] = &new Noticias$registro );

                }

                return 
$this->_arrayNoticias;

            }

            return 
false;

        }

        function 
obtNoticiaPorId$id ){

            
$strSql 'SELECT * FROM noticias WHERE id_noticia = %d';
            
$sql sprintf$strSql, (int)$id );
            
$this->_bdcon->query($sql);

            if( 
$this->_bdcon->isError($sqlResult)){

                die(
$sqlResult->getMessage());

            }

            if( 
$sqlResult->numRows() > 0){

                while( 
$registro $sqlResult->fetchRow(DB_FETCHMODE_ASSOC) ){

                    
$this->_arrayNoticias[ ] = &new Noticias$registro );

                }

                return 
$this->_arrayNoticias;

            }

            return 
false;

        }

        function 
obtNoticiaPorFecha$fecha ){

            
$strSql 'SELECT * FROM noticias WHERE fecha = %s';
            
$sql sprintf$strSql$fecha );
            
$this->_bdcon->query($sql);

            if( 
$this->_bdcon->isError($sqlResult)){

                die(
$sqlResult->getMessage());

            }

            if( 
$sqlResult->numRows() > 0){

                while( 
$registro $sqlResult->fetchRow(DB_FETCHMODE_ASSOC) ){

                    
$this->_arrayNoticias[ ] = &new Noticias$registro );

                }

                return 
$this->_arrayNoticias;

            }

            return 
false;

        }

        function 
agregar( &$noticia ){

            
$strSql "INSERT INTO noticias VALUES(%d,%d,'%s')";
            
$propObjeto = array(
                                    
$noticia->obtTitulo(),
                                    
$noticia->obtDescripcion(),
                                    
$noticia->obtFecha(),
                                    
$noticia->obtImagen(),
                                    
$noticia->obtLink()
                                );
            
$sql sprintf(
                                
$sql,
                                
'',
                                
$noticia->obtUsuarioId(),
                                
implode(',',$propObjeto)
                          );

            
$this->_bdcon->query($sql);
            if( 
$this->_bdcon->isError($sqlResult)){

                die(
$sqlResult->getMessage());

            }

            if(
$this->_bdcon->affectedRows()){

                return 
true;

            }else{

                return 
false;

            }
        }

        function 
actualizar( &$noticia ){

            
$strSql "UPDATE noticias SET id_usuarios = %d,
                                            titulo = '%s',
                                            descripcion = '%s',
                                            fecha = '%s',
                                            imagen = '%s',
                                            link = '%s'"
;

            
$sql sprintf(
                                
$sql,
                                
$noticia->obtUsuarioId(),
                                
$noticia->obtTitulo(),
                                
$noticia->obtDescripcion(),
                                
$noticia->obtFecha(),
                                
$noticia->obtImagen(),
                                
$noticia->obtLink()
                          );

            
$this->_bdcon->query($sql);
            if( 
$this->_bdcon->isError($sqlResult)){

                die(
$sqlResult->getMessage());

            }

            if(
$this->_bdcon->affectedRows()){

                return 
true;

            }else{

                return 
false;

            }
        }

        function 
borrar(&$noticia ){

            
$strSql "DELETE FROM noticias WHERE id_noticia = %d";

            
$sql sprintf(
                                
$sql,
                                
$noticia->obtId()
                          );

            
$this->_bdcon->query($sql);
            if( 
$this->_bdcon->isError($sqlResult)){

                die(
$sqlResult->getMessage());

            }

            if(
$this->_bdcon->affectedRows()){

                return 
true;

            }else{

                return 
false;

            }
        }

    }
?>
Estoy en la prehistoria del conocimiento en la POO. Que es pear DB ?
Acabo de bajarme el archivo de http://pear.php.net/
Esta es la ultima version de DB: 1.6.4
http://pear.php.net/get/DB

Saludos ...
__________________
| Cabeza De Raton |

Última edición por Calisco; 11/05/2004 a las 22:07