diff --git a/clazz/Projet.class.php b/clazz/Projet.class.php index 0a9e3c7..898e820 100644 --- a/clazz/Projet.class.php +++ b/clazz/Projet.class.php @@ -56,9 +56,122 @@ class Projet{ public function getSecondaryOwners(){ return $this->secondaryOwners; } - + public function getDateCreation(){ return $this->dateCreation; } + + //Useful getters + public function haveRights($member){ + return $member->getID() == $owner->getID() or in_array($member,$this->secondaryOwners); + } + + //Setters + public function setSecondaryOwners($secondaryOwners){ + $this->secondaryOwners = $secondaryOwners; + $secondaryOwnersID = array(); + foreach($secondaryOwners AS $secondaryOwner)$secondaryOwnersID[] = $secondaryOwner->getID(); + $req = $GLOBALS['bdd']->prepare('UPDATE projets SET secondaryOwners=? WHERE ID=?'); + $req->execute(array(implode(';',$secondaryOwnersID),$this->ID)); + } + + public function addSecondaryOwner($secondaryOwner){ + $this->secondaryOwners[] = $secondaryOwner; + $this->setSecondaryOwners($this->secondaryOwners); + } + + public function delSecondaryOwner($secondaryOwner){ + $this->secondaryOwners = array_diff($this->secondaryOwners,array($secondaryOwner)); + $this->setSecondaryOwners($this->secondaryOwners); + } + + + //Project getters + private static function projectGetterOutput($req){ + $out = array(); + while($rep = $req->fetch()) + $out[] = new Project($rep['ID']); + switch(count($out)){ + case 0: + return NULL; + case 1: + return $out[0]; + default: + return $out; + } + } + + public static function getFromName($name){ + $req = $GLOBALS['bdd']->prepare('SELECT * FROM project WHERE name=?'); + $req->execute(array($name)); + return projectGetterOutput($req); + } + + public static function getFromOwner($owner){ + $req = $GLOBALS['bdd']->prepare('SELECT * FROM project WHERE owner=?'); + $req->execute(array($owner->getID())); + return projectGetterOutput($req); + } + + public static function getFromSecondaryOwner($secondaryOwner){ + $req = $GLOBALS['bdd']->prepare('SELECT * FROM project'); + $req->execute(); + $out = array(); + while ($rep = $req->fetch()) { + $projet = new Projet($rep['ID']); + if ($projet->haveRights($secondaryOwner)) + $out[] = $projet; + } + switch(count($out)){ + case 0: + return NULL; + case 1: + return $out[0]; + default: + return $out; + } + + return projectGetterOutput($req); + } + + public static function getFromDateCreation($date){ + $req = $GLOBALS['bdd']->prepare('SELECT * FROM project WHERE dateCreation=?'); + $req->execute(array($date)); + return projectGetterOutput($req); + } + + public static function getCreatedLaterThan($date){ + $req = $GLOBALS['bdd']->prepare('SELECT * FROM project WHERE dateCreation>?'); + $req->execute(array($date)); + return projectGetterOutput($req); + } + + public static function getCreatedEarlierThan($date){ + $req = $GLOBALS['bdd']->prepare('SELECT * FROM project WHERE dateCreationexecute(array($date)); + return projectGetterOutput($req); + } + + public static function getWhichHeCanAccess($he){ + $req = $GLOBALS['bdd']->prepare('SELECT * FROM project'); + $req->execute(array()); + $out = array(); + while ( $rep = $req->fetch()) { + $disc = new Discussion($rep['ID']); + if ($disc->canAccess($membre)) + $out[] = $disc; + } + switch(count($out)){ + case 0: + return NULL; + case 1: + return $out[0]; + default: + return $out; + } + } + + + } \ No newline at end of file