Fin du dossier megaprocess, encore de nouvelles classesx
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
class Langage{
|
||||
|
||||
//FIXME const
|
||||
static $java = new Langage(0, "Java", "jar java javadoc");
|
||||
static $vba = new Langage(1, "VBA", "xlsm vb");
|
||||
public static $java;
|
||||
public static $vba;
|
||||
|
||||
protected static $languages = array();
|
||||
|
||||
@@ -12,7 +12,7 @@ class Langage{
|
||||
protected $avalivableFiles;//String "jar xlsx javadoc" in constructor , stored as a string array
|
||||
|
||||
|
||||
protected function __construct($ID,$name,$avalivableFiles){
|
||||
public function __construct($ID,$name,$avalivableFiles){
|
||||
$this->ID = $ID;
|
||||
$this->name = $name;
|
||||
$this->avalivableFiles = explode(" ",$avalivableFiles);
|
||||
@@ -52,4 +52,6 @@ class Langage{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Langage::$java = new Langage(0, "Java", "jar java javadoc");
|
||||
Langage::$vba = new Langage(1, "VBA", "xlsm vb");
|
||||
|
||||
+124
-21
@@ -31,8 +31,7 @@ class Membre {
|
||||
}
|
||||
|
||||
public function connect($password) {
|
||||
$this->connected = password_verify ( $this->pass, $rep ['mdp'] );
|
||||
|
||||
$this->connected = password_verify ($password, $this->hashedPassword );
|
||||
return $this->connected;
|
||||
|
||||
}
|
||||
@@ -57,7 +56,7 @@ class Membre {
|
||||
}
|
||||
|
||||
private function decodeData($data) {
|
||||
$jsonData = json_decode ( $data );
|
||||
$jsonData = json_decode ( $data ,TRUE);
|
||||
// Set the data's required_banner if it is defined , otherwise sets the DEFAULT_BANNER
|
||||
$this->requiredBanner = $jsonData ['requiredBanner'] ?? self::DEFAULT_BANNER;
|
||||
$this->personnalMessage = $jsonData ['personnalMessage'] ?? NULL;
|
||||
@@ -126,6 +125,81 @@ class Membre {
|
||||
return Membre::PASSWORD_CHANGED;
|
||||
}
|
||||
|
||||
public function setAttribute($attribute,$value,$valueType){
|
||||
$json=FALSE;
|
||||
switch ($attribute){
|
||||
case 'ID':
|
||||
if($valueType !== '0'){
|
||||
echo 'Error : the type "'.$valueType.'" is not allowed for the attribute '.$attribute;
|
||||
exit;
|
||||
}
|
||||
$value = intval($value);
|
||||
break;
|
||||
case 'pseudo':
|
||||
if($valueType !== '"'){
|
||||
echo 'Error : the type "'.$valueType.'" is not allowed for the attribute '.$attribute;
|
||||
exit;
|
||||
}
|
||||
$value = '"'.strval($value).'"';
|
||||
break;
|
||||
case 'hashedPseudo':
|
||||
if($valueType !== '"'){
|
||||
echo 'Error : the type "'.$valueType.'" is not allowed for the attribute '.$attribute;
|
||||
exit;
|
||||
}
|
||||
$value = '"'.strval($value).'"';
|
||||
break;
|
||||
case 'adminLevel':
|
||||
if($valueType !== '0'){
|
||||
echo 'Error : the type "'.$valueType.'" is not allowed for the attribute '.$attribute;
|
||||
exit;
|
||||
}
|
||||
$value = intval($value);
|
||||
break;
|
||||
case 'dateCreation':
|
||||
if($valueType !== '"'){
|
||||
echo 'Error : the type "'.$valueType.'" is not allowed for the attribute '.$attribute;
|
||||
exit;
|
||||
}
|
||||
$value = '"'.$value.'"';
|
||||
break;
|
||||
case 'requiredBanner'://FIXME jsonMysqlProblem
|
||||
$json=TRUE;
|
||||
if($valueType !== '"'){
|
||||
echo 'Error : the type "'.$valueType.'" is not allowed for the attribute '.$attribute;
|
||||
exit;
|
||||
}
|
||||
$value = '"'.strval($value).'"';
|
||||
break;
|
||||
case 'personnalMessage':
|
||||
$json=TRUE;
|
||||
if($valueType !== '"'){
|
||||
echo 'Error : the type "'.$valueType.'" is not allowed for the attribute '.$attribute;
|
||||
exit;
|
||||
}
|
||||
$value = '"'.strval($value).'"';
|
||||
break;
|
||||
default:
|
||||
echo 'Undefined attribute "'.$attribute.'" for the class Membre';
|
||||
exit;
|
||||
}
|
||||
|
||||
$restrictionValues[] = $value;
|
||||
if($json){
|
||||
//TODO Set command for json
|
||||
}else{
|
||||
$command = 'UPDATE membres SET ' . $attribute . '=' . $value . ' WHERE ID=' . $this->ID;
|
||||
}
|
||||
echo $command.'</br>';
|
||||
$req = $GLOBALS['bdd']->prepare($command);
|
||||
$req->execute(array());
|
||||
if($req->errorInfo()[0] != 0){
|
||||
echo 'Eine MYSQL Exception hat geworft. Einschuldigung';
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Objects which matchs the specified restrictions
|
||||
@@ -142,38 +216,65 @@ class Membre {
|
||||
try {
|
||||
switch ($attribute){
|
||||
case 'ID':
|
||||
$value = intval($restriction[2]);
|
||||
if($restriction[2][0] !== '0'){
|
||||
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
|
||||
exit;
|
||||
}
|
||||
$value = intval($restriction[2][1]);
|
||||
$operator = Utility::getIntegerSqlOperator($restriction[1]);
|
||||
break;
|
||||
case 'pseudo':
|
||||
$value = '"'.strval($restriction[2]).'"';//FIXME escaped chars (',",\n,\t ...)
|
||||
if($restriction[2][0] !== '"'){
|
||||
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
|
||||
exit;
|
||||
}
|
||||
$value = '"'.strval($restriction[2][1]).'"';
|
||||
$operator = Utility::getStringSqlOperator($restriction[1]);
|
||||
break;
|
||||
case 'hashedPseudo':
|
||||
$value = '"'.strval($restriction[2]).'"';
|
||||
if($restriction[2][0] !== '"'){
|
||||
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
|
||||
exit;
|
||||
}
|
||||
$value = '"'.strval($restriction[2][1]).'"';
|
||||
$operator = Utility::getStringSqlOperator($restriction[1]);
|
||||
break;
|
||||
case 'adminLevel':
|
||||
$value = intval($restriction[2]);
|
||||
if($restriction[2][0] !== '0'){
|
||||
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
|
||||
exit;
|
||||
}
|
||||
$value = intval($restriction[2][1]);
|
||||
$operator = Utility::getIntegerSqlOperator($restriction[1]);
|
||||
break;
|
||||
case 'dateCreation':
|
||||
//FIXME y ä pâs là vàlüè
|
||||
$value=""
|
||||
$operator = 'convert(datetime, "'.Utility::getDateSqlOperator($restriction[1]).'")';
|
||||
if($restriction[2][0] !== '"'){
|
||||
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
|
||||
exit;
|
||||
}
|
||||
$value = '"'.$restriction[2][1].'"';
|
||||
$operator = Utility::getDateSqlOperator($restriction[1]);
|
||||
break;
|
||||
case 'requiredBanner':
|
||||
case 'requiredBanner'://FIXME jsonMysqlProblem
|
||||
$json=TRUE;
|
||||
$value = "'".strval($restriction[2])."'";
|
||||
if($restriction[2][0] !== '"'){
|
||||
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
|
||||
exit;
|
||||
}
|
||||
$value = '"'.strval($restriction[2][1]).'"';
|
||||
$operator = Utility::getStringSqlOperator($restriction[1]);
|
||||
break;
|
||||
case 'personnalMessage':
|
||||
$json=TRUE;
|
||||
$value = "'".strval($restriction[2])."'";
|
||||
if($restriction[2][0] !== '"'){
|
||||
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
|
||||
exit;
|
||||
}
|
||||
$value = '"'.strval($restriction[2][1]).'"';
|
||||
$operator = Utility::getStringSqlOperator($restriction[1]);
|
||||
break;
|
||||
default:
|
||||
echo 'Unknown attribute "'.$attribute.'" for the class Membre';
|
||||
echo 'Undefined attribute "'.$attribute.'" for the class Membre';
|
||||
exit;
|
||||
}
|
||||
}catch(InvalidOperatorException $e){
|
||||
@@ -182,7 +283,6 @@ class Membre {
|
||||
}
|
||||
|
||||
$restrictionValues[] = $value;
|
||||
|
||||
if($json){
|
||||
$whereCommand = '((data->"$.'.$attribute.'" IS NOT NULL) AND (data->"$.'.$attribute.'" '.$operator.' ? ))';
|
||||
}else{
|
||||
@@ -190,17 +290,20 @@ class Membre {
|
||||
}
|
||||
$whereCommands[] = $whereCommand;
|
||||
}
|
||||
$wherePart = 'WHERE '.implode(' AND ',$whereCommands);
|
||||
$wherePart = "";
|
||||
if(count($whereCommands) >0)
|
||||
$wherePart = 'WHERE '.implode(' AND ',$whereCommands);
|
||||
|
||||
|
||||
$req = $GLOBALS['bdd']->prepare('SELECT * FROM membres '.$wherePart);
|
||||
$command = 'SELECT * FROM membres '.$wherePart;
|
||||
$req = $GLOBALS['bdd']->prepare($command);
|
||||
$req->execute($restrictionValues);
|
||||
if($req->errorInfo()[0] == 0)
|
||||
echo 'A SQL exception occured ...';
|
||||
echo $command.'</br>';
|
||||
if($req->errorInfo()[0] != 0)
|
||||
echo 'Erreur SQL, veuillez verifier les selecteurs';
|
||||
$out = array();
|
||||
while($rep = $req->fetch())
|
||||
$out[] = new Membre($rep['ID']);
|
||||
|
||||
|
||||
//Choose return value
|
||||
switch(count($out)){
|
||||
case 0:
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
class Projet{
|
||||
protected $ID;
|
||||
protected $name;
|
||||
protected $dateCreation;
|
||||
protected $owner;
|
||||
protected $secondaryOwners;
|
||||
|
||||
protected $valid;
|
||||
|
||||
public function __construct($ID){
|
||||
$this->ID = $ID;
|
||||
$req = $GLOBALS['bdd']->prepare('SELECT * FROM projets WHERE ID=?');
|
||||
$req->execute(array($ID));
|
||||
if($rep = $req->fetch()){
|
||||
$this->valid = TRUE;
|
||||
$this->name = $rep['name'];
|
||||
$this->owner = new Membre($rep['ownerID']);
|
||||
$this->dateCreation = $rep['dateCreation'];
|
||||
$this->secondaryOwners = array();
|
||||
foreach (explode(';',$rep['secondaryOwners']) AS $secondaryOwner)
|
||||
$this->secondaryOwners[] = new Membre($secondaryOwner);
|
||||
}else{
|
||||
$this->valid = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
public function exists(){
|
||||
return $this->valid;
|
||||
}
|
||||
|
||||
public function __toString(){
|
||||
$out = 'Projet\n';
|
||||
$out .= '\tID:' . $this->ID . '\n';
|
||||
$out .= '\tName:' . $this->name . '\n';
|
||||
$out .= '\tOwner:{' . substr(str_replace('\n\t',';',$this->owner->__toString()),0,-1) . '}\n';
|
||||
foreach($this->secondaryOwners AS $secondaryOwner)
|
||||
$out .= '\tSecondary owner:{' . substr(str_replace('\n\t',';',$secondaryOwner->__toString()),0,-1) . '}\n';
|
||||
$out .= '\tDate of creation:' . $this->dateCreation . '\n';
|
||||
return out;
|
||||
}
|
||||
|
||||
//Getters
|
||||
public function getID(){
|
||||
return $this->ID;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function getOwner(){
|
||||
return $this->owner;
|
||||
}
|
||||
|
||||
public function getSecondaryOwners(){
|
||||
return $this->secondaryOwners;
|
||||
}
|
||||
|
||||
public function getDateCreation(){
|
||||
return $this->dateCreation;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,6 +6,7 @@ try{
|
||||
die ('Erreur : ' . $e->getMessage());
|
||||
}
|
||||
|
||||
//TODO all exceptions in functions must be returns (make handle too)
|
||||
//TODO in the classes , do more test of exists in setters
|
||||
include_once 'clazz/Utility.class.php';
|
||||
include_once 'clazz/Langage.class.php';
|
||||
|
||||
Reference in New Issue
Block a user