Retroceder   Foros del Web > Programación para sitios web > PHP > PHP orientado a objetos

Respuesta
 
Herramientas Desplegado
Antiguo 28-mar-2008, 10:26   #1 (permalink)
eulloa ha deshabilitado el karma
 
Fecha de Ingreso: octubre-2007
Mensajes: 79
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-mar-2008 a las 17:03.
eulloa está desconectado   Responder Citando
Antiguo 28-mar-2008, 10:40   #2 (permalink)
Moderador
GatorV llegará a ser famoso muy prontoGatorV llegará a ser famoso muy prontoGatorV llegará a ser famoso muy prontoGatorV llegará a ser famoso muy prontoGatorV llegará a ser famoso muy pronto
 
Avatar de GatorV
 
Fecha de Ingreso: mayo-2006
Ubicación: Queretaro, Mexico
Mensajes: 11.280
Re: rectifiquenme esta clase POO

Tema trasladado a PHP Orientado a Objetos.
__________________
Blog Web
GatorV está desconectado   Responder Citando
Antiguo 28-mar-2008, 16:23   #3 (permalink)
destor77 está en el buen camino
 
Avatar de destor77
 
Fecha de Ingreso: noviembre-2004
Ubicación: Gálvez, Santa Fe, Argentina
Mensajes: 1.059
Enviar un mensaje por MSN a destor77 Enviar un mensaje por Yahoo  a destor77
Re: rectifiquenme esta clase POO

algun mod puede arreglar este post que se ve mal

gracias
destor77 está desconectado   Responder Citando
Respuesta
No hay votos aún.


Herramientas
Desplegado

Normas de Publicación
No puedes crear nuevos temas
No puedes responder temas
No puedes subir archivos adjuntos
No puedes editar tus mensajes

BB code is Activado
Caritas están Activado
[IMG] está Activado
Código HTML está Desactivado


La Zona horaria es GMT -6. Ahora son las 22:29.


Message Board Statistics

LinkBacks Enabled by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93