Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 442 | Rev 521 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 442 Rev 478
Line 1... Line 1...
1
<?php
1
<?php
2
/**
2
/**
3
 * 
3
 *
4
 * fonctions 
4
 * fonctions
5
 * @author mathilde
5
 * @author mathilde
6
 *
6
 *
7
 */
7
 */
8
 
-
 
9
class EfloreCommun {
8
class EfloreCommun {
10
	
9
 
-
 
10
	private $Conteneur = null;
11
	private $Bdd = null;
11
	private $Bdd = null;
12
	private $projetNom = null;
12
	private $projetNom = '';
-
 
13
	private $scriptChemin = '';
13
	
14
 
-
 
15
	public function __construct($conteneur) {
-
 
16
		$this->Conteneur = $conteneur;
-
 
17
		$this->Bdd = $this->Conteneur->getBdd();
-
 
18
	}
14
	
19
 
15
	public function initialiserProjet($projetNom) {
20
	public function initialiserProjet($projetNom) {
16
		$this->projetNom = $projetNom;
21
		$this->projetNom = $projetNom;
17
		$this->chargerConfigDuProjet();
22
		$this->chargerConfigDuProjet();
18
	}
23
	}
19
	
24
 
20
	//+------------------------------------------------------------------------------------------------------+
-
 
21
	// Méthodes d'accès aux objets du Framework
-
 
22
	/**
-
 
23
	* Méthode de connection à la base de données sur demande.
-
 
24
	* Tous les scripts n'ont pas besoin de s'y connecter.
-
 
25
	*/
-
 
26
	public function getBdd() {
-
 
27
	if (! isset($this->Bdd)) {
-
 
28
	$this->Bdd = new Bdd();
-
 
29
	}
-
 
30
	return $this->Bdd;
-
 
31
	}
-
 
32
	
-
 
33
	//+------------------------------------------------------------------------------------------------------+
25
	//+------------------------------------------------------------------------------------------------------+
34
	// Méthodes communes aux projets d'eFlore
26
	// Méthodes communes aux projets d'eFlore
35
	
27
 
36
	public function chargerConfigDuProjet() {
28
	public function chargerConfigDuProjet() {
-
 
29
		$scriptChemin = $this->Conteneur->getParametre('scriptChemin');
37
	$fichierIni = $this->getScriptChemin().$this->getProjetNom().'.ini';
30
		$fichierIni = $scriptChemin.$this->projetNom.'.ini';
38
	if (file_exists($fichierIni)) {
31
		if (file_exists($fichierIni)) {
39
	Config::charger($fichierIni);
32
			Config::charger($fichierIni);
40
	} else {
33
		} else {
41
	$m = "Veuillez configurer le projet en créant le fichier '{$this->projetNom}.ini' ".
34
			$m = "Veuillez configurer le projet en créant le fichier '{$this->projetNom}.ini' ".
42
	"dans le dossier du module de script du projet à partir du fichier '{$this->projetNom}.defaut.ini'.";
35
			"dans le dossier du module de script du projet à partir du fichier '{$this->projetNom}.defaut.ini'.";
43
	throw new Exception($m);
36
			throw new Exception($m);
44
			}
-
 
45
		}
37
		}
-
 
38
	}
46
	
39
 
47
	//changée
40
	//changée
48
	public function chargerStructureSql($structure_sql) {
41
	public function chargerStructureSql() {
-
 
42
		$fichierStructureSql = $this->Conteneur->getParametre('chemins.structureSql');
49
	$contenuSql = $this->recupererContenu(Config::get($structure_sql));
43
		$contenuSql = $this->recupererContenu($fichierStructureSql);
50
	$this->executerScripSql($contenuSql);
44
		$this->executerScripSql($contenuSql);
51
	}
45
	}
52
	
46
 
53
	public function executerScripSql($sql) {
47
	public function executerScripSql($sql) {
54
	$requetes = Outils::extraireRequetes($sql);
48
		$requetes = Outils::extraireRequetes($sql);
55
		foreach ($requetes as $requete) {
49
		foreach ($requetes as $requete) {
56
		$this->getBdd()->requeter($requete);
50
			$this->Bdd->requeter($requete);
57
	}
51
		}
58
	}
52
	}
59
	
53
 
60
	public function recupererContenu($chemin) {
54
	public function recupererContenu($chemin) {
61
	$contenu = file_get_contents($chemin);
55
		$contenu = file_get_contents($chemin);
62
	if ($contenu === false){
56
		if ($contenu === false){
63
	throw new Exception("Impossible d'ouvrir le fichier SQL : $chemin");
57
			throw new Exception("Impossible d'ouvrir le fichier SQL : $chemin");
64
	}
-
 
65
	return $contenu;
-
 
66
		}
58
		}
-
 
59
		return $contenu;
-
 
60
	}
67
}
61
}
68
?>
62
?>
69
63