Foros del Web » Programando para Internet » PHP » Frameworks y PHP orientado a objetos »

rectifiquenme esta clase POO

Estas en el tema de rectifiquenme esta clase POO en el foro de Frameworks y PHP orientado a objetos en Foros del Web. Hola foreros, recién he estado tratando de introducirme en el grandioso mundo de la POO. Solo estoy empezando ¿ok? Bueno, con lo poco que he ...
  #1 (permalink)  
Antiguo 28/03/2008, 10:26
Avatar de eulloa  
Fecha de Ingreso: octubre-2007
Ubicación: Donde caiga la noche, si mi hijo me deja
Mensajes: 691
Antigüedad: 16 años, 6 meses
Puntos: 5
rectifiquenme esta clase POO

Hola foreros, recién he estado tratando de introducirme en el grandioso mundo de la POO. Solo estoy empezando ¿ok?
Bueno, con lo poco que he aprendido pongo este código inicial, que sería para hacer un calendario, para que me digan como puedo mejorarlo y darme ideas, a ustedes que son más experimentados que yo. Inicialmente no he previsto imprimir los días correspondientes, recuerden que solo lo estoy haciendo por jugar un poco con php5 jeje
Acá va:
Código PHP:
class calendar{

private 
$year;
private 
$day;
private 
$month;
private 
$day_week;
private 
$cant_day;


//CONSTRUCTOR DE LA CLASE
function __construct(){

$this->year=$year;
$this->day=$day;
$this->month=$month;
$this->day_week=$day_week;
$this->cant_day=$cant_day;
}

//FUNCIÓN PARA OBTENER EL AÑO CORRIENTE
function default_year(){

$this->year=date(Y);

}


//FUNCIÓN PARA OBTENER EL MES CORRIENTE
function default_month(){

$this->month=date(n);

}


//FUNCIÓN PARA OBTENER EL DÍA CORRIENTE
function default_day(){

$this->day=date(j);

}

//FUNCION PARA OBTENER EL DÍA DE LA SEMANA
function default_week(){

$this->day_week=date(N); //LUNEA A DOMINGO DE 1 A 7

}



//OBTENGO EL AÑO
function get_year(){

$this->default_year();
return 
$this->year;
}

//OBTENGO EL MES, LO DEVUELVO EN FORMATO LEGIBLE EN ESPAÑOL
function get_month(){

$this->default_month();
    
    
$month_real=array(1=>'Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre');
    
    
$this->month_num=$this->month;
    
    
$this->month=$month_real[$this->month];
    
    return 
$this->month;

}

//OBTENGO EL DÍA
function get_day(){

$this->default_day();
return 
$this->day; return $this->day_week;

}

//OBTENGO EL DÍA DE LA SEMANA
function get_week(){

$this->default_week();

    
$day_of_week=array(1=>'Lunes','Martes','Miércoles','Jueves','Viernes','Sábado'.'Domingo');

    return 
$this->day_week=$day_of_week[$this->day_week];
}


//OBTENGO CUANTOS DÍAS TIENE EL MES
function cant_day(){

$cant_day=array(1=>31,28,31,30,31,30,31,31,30,31,30,31);

return 
$this->cant_day=$cant_day[$this->month_num];
}


//ESTA FUNCION ES PARA DIBUJAR EL CALENDARIO
function dibuja_cal($cant_day,$current_day){

echo 
'<table>';
echo 
'<tr>';
for(
$i=1;$i<=$cant_day;++$i){

    if(
$i==$current_day){
        
$etiqueta='<td><b><font color=red>';
        
$etiqueta_f='</b></font></td>';
        }
    else{
        
$etiqueta='<td>';
        
$etiqueta_f='</td>';
        }
        
    echo 
$etiqueta;
    echo 
$i;
    echo 
$etiqueta_f;
    
        if(
$i==|| $i==14 || $i==21 || $i==28)
            echo 
'</tr><tr>';

}
}

}


$cal=new calendar();

ECHO 
'Hoy es:';
echo 
$cal->get_week().',';
echo 
$c_day=$cal->get_day().' de ';
echo 
$cal->get_month().' del ';
echo 
$cal->get_year().'   Este mes trae : ';
echo 
$days=$cal->cant_day().' días';

$cal->dibuja_cal($days,$c_day); 
Bueno ahora díganme cómo puedo mejorar este código, ejemplo, quisiera que los días, años,meses que me lo pudiera devolver una sola función ¿se puede eso?
Bueno hasta ahorita
saludos

Última edición por GatorV; 28/03/2008 a las 17:03
  #2 (permalink)  
Antiguo 28/03/2008, 10:40
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 18 años
Puntos: 2135
Re: rectifiquenme esta clase POO

Tema trasladado a PHP Orientado a Objetos.
  #3 (permalink)  
Antiguo 28/03/2008, 16:23
Avatar de destor77  
Fecha de Ingreso: noviembre-2004
Ubicación: Gálvez, Santa Fe, Argentina
Mensajes: 2.654
Antigüedad: 19 años, 6 meses
Puntos: 43
Re: rectifiquenme esta clase POO

algun mod puede arreglar este post que se ve mal

gracias
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 14:22.