Subversion Repositories eFlore/Projets.eflore-projets

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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