Ver Mensaje Individual
  #1 (permalink)  
Antiguo 04/06/2011, 05:33
marcwolf
 
Fecha de Ingreso: junio-2010
Mensajes: 353
Antigüedad: 14 años, 5 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