public function createProduit($produit) {\r
\r
$query = $this -> pdo -> prepare(\r
- 'INSERT INTO produits (nom, exploitant, reference, version) VALUES (:nom, :exploitant, :reference, :version)'\r
+ 'INSERT INTO produits (\r
+ nom, \r
+ exploitant, \r
+ reference, \r
+ version, \r
+ historique\r
+ ) VALUES (\r
+ :nom, \r
+ :exploitant, \r
+ :reference, \r
+ :version, \r
+ :historique\r
+ )'\r
);\r
$query -> bindValue(':nom', $produit -> getNom());\r
$query -> bindValue(':exploitant', $produit -> getExploitant());\r
public function updateProduit($produit) {\r
\r
$query = $this -> pdo -> prepare(\r
- 'UPDATE produits SET nom = :nom, exploitant = :exploitant, reference = :reference, version = :version WHERE id = :id'\r
+ 'UPDATE produits \r
+ SET nom = :nom, \r
+ exploitant = :exploitant, \r
+ reference = :reference, \r
+ version = :version, \r
+ historique = :historique\r
+ WHERE id = :id'\r
);\r
$query -> bindValue(':id', $produit -> getId());\r
$query -> bindValue(':nom', $produit -> getNom());\r
$query -> bindValue(':exploitant', $produit -> getExploitant());\r
$query -> bindValue(':reference', $produit -> getReference());\r
$query -> bindValue(':version', $produit -> getVersion());\r
+ $query -> bindValue(':historique', $produit -> getHistorique());\r
$query -> execute();\r
\r
}\r
\r
- public function updateProduitInfos($array) {\r
-\r
+ public function updateProduitInfos($array) {\r
$produit = $this -> getProduitByReference($array['reference']);\r
-\r
- if ($array['produit'] == $produit -> getNom()) {\r
- $query = $this -> pdo -> prepare(\r
- 'UPDATE produits SET version = :version WHERE reference = :reference'\r
- );\r
- $query -> bindValue(':reference', $array['reference']);\r
- $query -> bindValue(':version', $array['version']);\r
- $query -> execute();\r
- \r
- // CAS EXPLOITANT\r
- if($array['usager_type'] == "exploitant") {\r
- // RECUPERATION DE L'EXPLOITANT DU PRODUIT\r
- $exploitantManager = new PdoExploitantManager();\r
- $exploitant = $exploitantManager -> getExploitant($produit -> getExploitant());\r
-\r
- // MISE À JOUR DE TOUS LES PRODUITS EN CHARGE DE L'EXPLOITANT\r
- $produits_refs = $exploitant -> getProduits();\r
- $array['usager_type'] = 'client';\r
- foreach ($produits_refs as $produit_ref) {\r
- $array['reference'] = $produit_ref;\r
- $produitManager -> updateProduitInfos($array);\r
- }\r
+ // TO-DO :\r
+ // AJOUT EVENEMENT À L'HISTORIQUE\r
+ // DEMANDE DE VALIDATION\r
+ // CAS EXPLOITANT\r
+ if($array['usager_type'] === "exploitant") {\r
+ // RECUPERATION DE L'EXPLOITANT DU PRODUIT\r
+ $exploitantManager = new PdoExploitantManager();\r
+ $exploitant = $exploitantManager -> getExploitantByReference($produit -> getExploitant());\r
+\r
+ // MISE À JOUR DE TOUS LES PRODUITS EN CHARGE DE L'EXPLOITANT\r
+ $array['usager_type'] = "client";\r
+ $produits_id = $exploitant -> getProduits();\r
+ foreach ($produits_id as $produit_id) {\r
+ $array['reference'] = $this -> getProduit($produit_id) -> getReference();\r
+ $this -> updateProduitInfos($array);\r
+ }\r
+ // CAS CLIENT\r
+ } else if($array['usager_type'] === "client") {\r
+ if ($array['produit'] === $produit -> getNom()) {\r
+ $query = $this -> pdo -> prepare(\r
+ 'UPDATE produits SET version = :version WHERE reference = :reference'\r
+ );\r
+ $query -> bindValue(':reference', $array['reference']);\r
+ $query -> bindValue(':version', $array['version']);\r
+ $query -> execute();\r
+ } else {\r
+ echo "Erreur de nom du produit";\r
}\r
-\r
- }\r
- else {\r
- echo "Erreur : le nom du produit a changé";\r
}\r
-\r
}\r
\r
public function getProduit($id) {\r
$query -> execute();\r
\r
$result = $query -> fetch(PDO::FETCH_ASSOC);\r
- $produit = new Produit($result['id'], $result['nom'], $result['exploitant'], $result['reference'], $result['version']);\r
+ $produit = new Produit(\r
+ $result['id'], \r
+ $result['nom'], \r
+ $result['exploitant'], \r
+ $result['reference'], \r
+ $result['version'],\r
+ $result['historique']\r
+ );\r
\r
$query->closeCursor();\r
\r
$query -> execute();\r
\r
$result = $query -> fetch(PDO::FETCH_ASSOC);\r
- $produit = new Produit($result['id'], $result['nom'], $result['exploitant'], $result['reference'], $result['version']);\r
+ $produit = new Produit(\r
+ $result['id'], \r
+ $result['nom'], \r
+ $result['exploitant'], \r
+ $result['reference'], \r
+ $result['version'],\r
+ $result['historique']\r
+ );\r
\r
$query->closeCursor();\r
\r
$query -> execute();\r
\r
$results = $query -> fetchAll(PDO::FETCH_ASSOC);\r
- $version = array();\r
+ $produits = array();\r
foreach ($results as $result) {\r
- $version[] = new Produit($result['id'], $result['nom'], $result['exploitant'], $result['reference'], $result['version']);\r
+ $produits[] = new Produit(\r
+ $result['id'], \r
+ $result['nom'], \r
+ $result['exploitant'], \r
+ $result['reference'], \r
+ $result['version'],\r
+ $result['historique']\r
+ );\r
}\r
\r
$query->closeCursor();\r
\r
- return $version;\r
+ return $produits;\r
}\r
\r
public function removeProduit($produit) {\r