Ajout de quelques fonctions pour les projets
This commit is contained in:
parent
b3975e3cd1
commit
6c9434e092
@ -56,9 +56,122 @@ class Projet{
|
|||||||
public function getSecondaryOwners(){
|
public function getSecondaryOwners(){
|
||||||
return $this->secondaryOwners;
|
return $this->secondaryOwners;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDateCreation(){
|
public function getDateCreation(){
|
||||||
return $this->dateCreation;
|
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 dateCreation<?');
|
||||||
|
$req->execute(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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user