Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

Rev Author Line No. Line
442 mathilde 1
<?php
2
/**
3
 *
4
 * fonctions
5
 * @author mathilde
6
 *
7
 */
8
 
9
class EfloreCommun {
10
 
11
	private $Bdd = null;
12
	private $projetNom = null;
13
 
14
 
15
	public function initialiserProjet($projetNom) {
16
		$this->projetNom = $projetNom;
17
		$this->chargerConfigDuProjet();
18
	}
19
 
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
	//+------------------------------------------------------------------------------------------------------+
34
	// Méthodes communes aux projets d'eFlore
35
 
36
	public function chargerConfigDuProjet() {
37
	$fichierIni = $this->getScriptChemin().$this->getProjetNom().'.ini';
38
	if (file_exists($fichierIni)) {
39
	Config::charger($fichierIni);
40
	} else {
41
	$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'.";
43
	throw new Exception($m);
44
			}
45
		}
46
 
47
	//changée
48
	public function chargerStructureSql($structure_sql) {
49
	$contenuSql = $this->recupererContenu(Config::get($structure_sql));
50
	$this->executerScripSql($contenuSql);
51
	}
52
 
53
	public function executerScripSql($sql) {
54
	$requetes = Outils::extraireRequetes($sql);
55
		foreach ($requetes as $requete) {
56
		$this->getBdd()->requeter($requete);
57
	}
58
	}
59
 
60
	public function recupererContenu($chemin) {
61
	$contenu = file_get_contents($chemin);
62
	if ($contenu === false){
63
	throw new Exception("Impossible d'ouvrir le fichier SQL : $chemin");
64
	}
65
	return $contenu;
66
		}
67
}
68
?>