Foros del Web » Programando para Internet » PHP »

PHP orientado a objetos

Estas en el tema de PHP orientado a objetos en el foro de PHP en Foros del Web. hola, Estoy muy perdido mirad os comento el problema. Tengo estas dos clases. TaskClass Código: class TaskClass{ private $hasChanged;// notify if the task has been ...
  #1 (permalink)  
Antiguo 04/06/2011, 05:33
 
Fecha de Ingreso: junio-2010
Mensajes: 353
Antigüedad: 13 años, 10 meses
Puntos: 6
PHP orientado a objetos

hola,

Estoy muy perdido mirad os comento el problema.

Tengo estas dos clases.
TaskClass
Código:
class TaskClass{
    
    private $hasChanged;// notify if the task has been change
    private $deleted;// notify if the task has been removed
    private $childsDeleted; //notify if the task has been removed so has been his children
    //put your properties here, ex: childs, inidate, endate...
    //projectid 	taskid 	name 	initialdate 	enddate 	desc 	parentid
     private $taskId;
    private $name;
      private $iniDate;
      private $endDate;
      private $desc;
      private $parentId;
      private $childs = array();// Array de hijos
      function __construct($parentId,$name, $iniDate, $endDate, $desc){
          $this->parentId = $parentId;
          $this->name = $name;
           $this->iniDate = $iniDate;
            $this->endDate = $endDate;
             $this->desc = $desc;

      }
   
    public function createChild($parentId,$name, $iniDate, $endDate, $desc){
       // create a new object
        $TaskClass = new TaskClass($parentId,$name, $iniDate, $endDate, $desc);
        $this->childs[] = $TaskClass;
    }

    function addChid($task){
        //adds a subtask
    }
    
    function removeAll(){
        //remove all task includes himself
    }
    
    function getParentId(){
        //return parent task id
        return $this->parentId;
    }
    
    
    function getChild($taskId){
        //return (could be a direct or non direct child)
        foreach ($this->childs as $value) {

        }

        $this->childs[$i];
    }
    
    function addWorker($userId){
        // workers MUST be users that belongs to groupId 
    }
    
    function deleteWorker($userId){
        // delete a worker from that task
    }
    
    function save(){
        //save this object and his workers to BD throught BDController
        //and save all childs
        //if one task is mark for erased, then must be erase from BD
    }
}
ProjectClass
Código:
class ProjectClass
 {
 

    private $groupId;
    private $name;
    private $projectId;
    private $tasks = array();//array of main tasks

public function __construct($opcion,$var1,$var2){
        if($opcion =="CreariDProject"){$this->CreariDProject($var1);}
    }
    public function CreariDProject($var1){
        $this->projectId = $var1;
    }
 public function CrearProject($var1){
        $this->name = $var1;
    }
   public function Asignar($var1,$var2){
        $this->projectId = $var1;
        $this->groupId = $var2;
    }

            public function getProjectId(){
        return $this->projectId;
    }
            public function getGroupId(){
        return $this->groupId;
    }

        public function getNameProject(){
        return $this->name;
    }

    public function createMainTask($parentId,$name, $iniDate, $endDate, $desc){
       // create a new object(rojectid(atuomatico) 	taskid 	name 	initialdate 	enddate 	desc 	parentid(asignar))
        $TaskClass = new TaskClass($parentId,$name, $iniDate, $endDate, $desc);
        $this->task[] = $TaskClass;
    }
    
    public function deleteTask($taskId){
        // only mark for remove the task selected.
        // if the task has childs then, are direct sons of his grandfather.
    }
    
    public function deleteBranch($taskId){
        // mark for remove the task selected and all of his sons
    }
    
    public function addWorker($taskId, $userId){
            //add a person as a worker in that task


    }
    
    public function deleteWorker($taskId, $userId){
        // delete a worker from that task
    }
    
    public function saveChanges(){
     //saves the project. In fact, it only saves the tasks and his workers
    }
    
    private function loadTasks(){
        // load all tasks of the project
    }
 
    
}
Supongo lo siguiente(correjidme si me equivoco xD): Project class tiene array de task donde parentId sea 0 o NULL y por cada posicion de esa array tiene un array de taskclass DONDE el parentId es igual al taskId del padre. Pero también pueden haber hijas de hijas osea taskClass que tengan como hijas otras taskClass :S no sé si me explico

La questión esque no se como hacer esto.. he estado mirando paginas i tal pero sigo sin enterarme, un ejemplo o si puede ser una solución muy simple creo que me sacaría de dudas.

Gracias de antemano
  #2 (permalink)  
Antiguo 04/06/2011, 05:43
Avatar de masterpuppet
Software Craftsman
 
Fecha de Ingreso: enero-2008
Ubicación: Montevideo, Uruguay
Mensajes: 3.550
Antigüedad: 16 años, 3 meses
Puntos: 845
Respuesta: PHP orientado a objetos

Project y Task tienen como propiedad un array que contiene Task's.

Ahora, cual es tu duda o problema exactamente ?
__________________
http://es.phptherightway.com/
thats us riders :)
  #3 (permalink)  
Antiguo 04/06/2011, 07:21
 
Fecha de Ingreso: junio-2010
Mensajes: 353
Antigüedad: 13 años, 10 meses
Puntos: 6
Respuesta: PHP orientado a objetos

Obtener los valores de las array's en orden;
tasksinpadre1(escribir valores) tiene task2(escribir valores) tiene task3(escribir valores)

He pensado lo siguiente(pseudo codigo cutre);

Rutina(task)
1- cojer una task -> escribir todas var de ese objeto task
2- si task->getNumChild = 0 ->paso siguiente task
3-sino for(i=0; i <task->getNumChild;i++)
rutina(childs[i]);

Creo que de esta manera ya podré imprimirlas, no sé si hay otras manera mejores

Hara me falta saber como escribir eso en php xD si alguién me puede orientar un poco.
  #4 (permalink)  
Antiguo 04/06/2011, 08:53
Avatar de masterpuppet
Software Craftsman
 
Fecha de Ingreso: enero-2008
Ubicación: Montevideo, Uruguay
Mensajes: 3.550
Antigüedad: 16 años, 3 meses
Puntos: 845
Respuesta: PHP orientado a objetos

Lo ideal seria que implementes RecursiveIterator en tus clases.

Saludos.
__________________
http://es.phptherightway.com/
thats us riders :)

Etiquetas: objetos, orientado
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 09:44.