207 |
jpm |
1 |
<?php
|
|
|
2 |
class Versions {
|
|
|
3 |
private $parametres = null;
|
|
|
4 |
private $bdd = null;
|
|
|
5 |
private $projetNom = null;
|
|
|
6 |
private $versionsDispo = array();
|
|
|
7 |
private $versionCourrante = array();
|
|
|
8 |
|
|
|
9 |
public function __construct(Parametres $parametres, Bdd $bdd,$projetNom) {
|
|
|
10 |
$this->parametres = $parametres;
|
|
|
11 |
$this->bdd = $bdd;
|
|
|
12 |
$this->projetNom = $projetNom;
|
|
|
13 |
$this->versionsDispo = $this->chargerVersionsDisponibles();
|
|
|
14 |
}
|
|
|
15 |
|
|
|
16 |
private function chargerVersionsDisponibles() {
|
|
|
17 |
$tableMeta = $this->projetNom.'_meta';
|
|
|
18 |
$requete = "SELECT version FROM $tableMeta";
|
|
|
19 |
$resultat = $this->bdd->recupererTous($requete);
|
|
|
20 |
if ($resultat == '') {
|
|
|
21 |
//cas ou la requete comporte des erreurs
|
|
|
22 |
$message = "La requête SQL de versionnage formée comporte une erreur : $requete";
|
|
|
23 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
|
|
24 |
throw new Exception($message, $code);
|
|
|
25 |
} elseif ($resultat === false) {
|
|
|
26 |
$message = "Versions introuvables dans la table des méta-données";
|
|
|
27 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
|
|
28 |
throw new Exception($message, $code);
|
|
|
29 |
} else {
|
|
|
30 |
foreach ($resultat as $version) {
|
|
|
31 |
$versionsDispo[] = $version['version'];
|
|
|
32 |
}
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
return $versionsDispo;
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
public function getVersions() {
|
|
|
39 |
$versions = array();
|
|
|
40 |
$versionDemandee = $this->parametres->get('version.projet');
|
|
|
41 |
if ($versionDemandee == '+') {
|
|
|
42 |
$versions[] = end($this->versionsDispo);
|
|
|
43 |
} else if (is_numeric($versionDemandee)) {
|
|
|
44 |
if (in_array($versionDemandee, $this->versionsDispo)) {
|
|
|
45 |
$versions[] = $versionDemandee;
|
|
|
46 |
}
|
|
|
47 |
} else if ($versionDemandee == '*') {
|
|
|
48 |
$versions = $this->versionsDispo;
|
|
|
49 |
}
|
|
|
50 |
$versions = $this->remplacerPointParUnderscore($versions);
|
|
|
51 |
return $versions;
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
private function remplacerPointParUnderscore($versions) {
|
|
|
55 |
foreach ($versions as $cle => $valeur) {
|
|
|
56 |
$versions[$cle] = str_replace('.', '_', $valeur);
|
|
|
57 |
}
|
|
|
58 |
return $versions;
|
|
|
59 |
}
|
|
|
60 |
}
|
|
|
61 |
?>
|