Ahí va, hay metodos no-terminados no le hagas caso prk no lo uso demomento.
ProjectClass Código PHP:
<?php
include_once "./clases/TaskClass.php";
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Description of ProjectClass
*
* @author marc
*/
class ProjectClass extends TaskClass {
private $groupId;
private $name;
private $projectId;
private $tasks = array(); //array of main tasks
private $numChilds = 0;
private $projects = array(); // array de projects
public function __construct($opcion, $var1, $var2) {
if ($opcion == "CreariDProject") {
$this->CreariDProject($var1);
$this->loadTasks();
}
if ($opcion == "Load") {
$this->loadProjects();
}
}
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 loadProjects() {
$bd = ($_SESSION['bd']);
$PersonClass = $_SESSION['PersonClass'];
$dataset = $bd->getListProjects($PersonClass->getGroupId());
$i = 0;
while ($registro = mysql_fetch_array($dataset)) {
//projectid groupid name
$this->projects[$i] = ($registro['projectid']);
$i++;
$this->projects[$i] = ($registro['name']);
$i++;
if (!isset($this->projects[$i])) {
$this->projects[$i] = ("");
$i++; //CampoReservado:user
$this->projects[$i] = ("");
$i++; //CampoReservado:IP
}
}
return $i;
}
public function markProject($projectID, $userID, $IP) {
//selects a project for modification by a user with an ip address
// throws an error if the project had been selected before.
for ($i = 0; $i < count($this->projects); $i++) {
if ($projectID == $this->projects[$i]) {
$this->projects[$i + 2] = $userID;
$this->projects[$i + 3] = $IP;
}
}
}
public function unMarkProject($projectID) {
// unselects a project that has previously modified
// throws an error if the project hadn't been selected
}
function getArrayOfProjects() {
return $this->projects;
}
public function getArrayOfTask() {
return $this->tasks;
}
public function getArrayOfTask2($i) {
return $this->tasks[$i]->getArrayOfChilds();
}
//$taskId,$parentId, $name, $iniDate, $endDate, $desc
public function createMainTask($opcion, $taskId, $parentId, $name, $iniDate, $endDate, $desc, $nombresString) {
// create a new object(rojectid(atuomatico) taskid name initialdate enddate desc parentid(asignar))
// Tengo que contar las task para añadirle un taskId, para el controlo de estas
$bd = $_SESSION['bd'];
$TaskClass = new TaskClass($opcion, $taskId, $parentId, $name, $iniDate, $endDate, $desc, $nombresString);
$this->tasks[] = $TaskClass;
}
function addChild($opcion, $taskId, $parentId, $name, $iniDate, $endDate, $desc, $nombresString) {
//adds a subtask
// Tengo que contar las task para añadirle un taskId, para el controlo de estas
$bd = $_SESSION['bd'];
//Tareasaddchild 0,$_SESSION['taskId'], $_POST['name'], $_POST['iniDate'], $_POST['endDate'], $_POST['desc']
//addchild $taskId,$parentId, $name, $iniDate, $endDate, $desc
//
$TaskClass = new TaskClass($opcion, $taskId, $parentId, $name, $iniDate, $endDate, $desc, $nombresString);
$this->childs[] = $TaskClass;
}
private function loadTasks() {
// load all tasks of the project
$bd = $_SESSION['bd'];
$opcion = "ObjdeMysql";
$dataset = $bd->loadMainTasks($this->projectId);
while ($registro = mysql_fetch_array($dataset)) {
$nombresString = $this->nombreString($registro['taskid'], $bd);
$TaskClass = new TaskClass($opcion, $registro['taskid'], $registro['parentid'], $registro['name'], $registro['initialdate'], $registro['enddate'], $registro['desc'], $nombresString,$this->childs[]=($this-> loadChildTasks($registro['taskid'])));
$this->tasks[] = $TaskClass;
}
}
private function loadChildTasks($parentId) {
$opcion = "ObjdeMysql";
$bd = $_SESSION['bd'];
$dataset = $bd->loadTask($parentId,$this->projectId);
while ($registro = mysql_fetch_array($dataset)) {
$nombresString = $this->nombreString($registro['taskid'], $bd);
$TaskClass = new TaskClass($opcion, $registro['taskid'], $registro['parentid'], $registro['name'], $registro['initialdate'], $registro['enddate'], $registro['desc'], $nombresString,$this->childs[]=($this-> loadChildTasks()));
$this->childs[] = $TaskClass;
return $this->childs;
}
}
function nombreString($taskid, $bd) {
//Saco array de personid
$arrayPersonId = $bd->countIdOfWorkers($taskid);
// Saco array de nombres ,concateno en un String y lo envio.
$nombresString = $bd->nameWorkers($arrayPersonId);
return $nombresString;
}
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
}
}
?>
TaskClass Código PHP:
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Description of TaskClass
*
* @author marc
*/
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
private $nombresString; // Array de hijos
private $padreId;
private $opcion;
function __construct($opcion, $taskId, $parentId, $name, $iniDate, $endDate, $desc, $nombresString,$childs) {
$this->taskId = $taskId;
$this->parentId = $parentId;
$this->name = $name;
$this->iniDate = $iniDate;
$this->endDate = $endDate;
$this->desc = $desc;
$this->nombresString = $nombresString;
$this->opcion = $opcion;
$this->childs = $childs;
}
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
}
/** Getters
* $parentId,$name, $iniDate, $endDate, $desc
* */
function getArrayOfChilds() {
return $this->childs;
}
public function getOpcion() {
return $this->opcion;
}
public function getTaskId() {
return $this->taskId;
}
public function getParentId() {
return $this->parentId;
}
public function getName() {
return $this->name;
}
public function getIniDate() {
return $this->iniDate;
}
public function getEndDate() {
return $this->endDate;
}
public function getDesc() {
return $this->desc;
}
function getNameWorkers() {
return $this->nombresString;
}
function getChild($taskId) {
//return (could be a direct or non direct child)
}
function removeAll() {
//remove all task includes himself
//$this->numChilds=0;
return numChilds;
}
}
?>
BD Controller : todos los metodos que tengan k ver con consultas/Inserts/etc en bd estan aquí
Código PHP:
Es demasiado largo XD, pongo los métodos que uso,los del metodo para sacar string de workers no los he puesto
public function loadMainTasks($projectId){
// returns a list of task that belongs to the project and has no parents.
$consulta = "SELECT * FROM `task` where projectid ='".$projectId."' and parentid='0';";
$dataset = mysql_query($consulta,$this->link);
return ($dataset);
}
public function loadTask($parentId,$projectId){
// devolver una lista de tareas que pertenecen al proyecto identificado por projectId y su padre es parentID;
$consulta = "SELECT * FROM `task` where projectid ='".$projectId."'and parentid='".$parentId."';";
$dataset = mysql_query($consulta,$this->link);
return ($dataset);
}
Depués creo obj "ProjectClass" en login, y lo paso a SESSION["ProjectClass"]; y hago más cosas pero no influyen para este apartado