Subversion Repositories Applications.referentiel

Rev

Rev 20 | Rev 24 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 20 Rev 23
1
<?php
1
<?php
2
// declare(encoding='UTF-8');
2
// declare(encoding='UTF-8');
3
/**
3
/**
4
* Classe modèle spécifique à l'application, donc d'accés au données, elle ne devrait pas être appelée de l'extérieur.
4
* Classe modèle spécifique à l'application, donc d'accés au données, elle ne devrait pas être appelée de l'extérieur.
5
* Elle est abstraite donc doit obligatoirement être étendue.
5
* Elle est abstraite donc doit obligatoirement être étendue.
6
*
6
*
7
* @category		Php5
7
* @category		Php5
8
* @package 		Referentiel
8
* @package 		Referentiel
9
* @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
9
* @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
10
* @copyright	2010 Tela-Botanica
10
* @copyright	2010 Tela-Botanica
11
* @license		http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
11
* @license		http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
12
* @license		http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
12
* @license		http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
13
* @version		SVN: $Id$
13
* @version		SVN: $Id$
14
*/
14
*/
15
abstract class Dao {
15
abstract class Dao {
16
	protected $distinction = '0';
16
	protected $distinction = '0';
17
	protected $limite_debut = null;
17
	protected $limite_debut = null;
18
	protected $limite_nbre = null;
18
	protected $limite_nbre = null;
19
	protected $url_jrest = null;
19
	protected $url_jrest = null;
20
	
20
	
21
	public function __construct() {
21
	public function __construct() {
22
		$this->url_jrest = config::get('url_jrest');
22
		$this->url_jrest = config::get('url_jrest');
23
	}
23
	}
-
 
24
	
-
 
25
	//+----------------------------------------------------------------------------------------------------------------+
-
 
26
	// ACCESSEURS
24
	
27
	
25
	public function avoirLimitation() {
28
	public function avoirLimitation() {
26
		$limitation = false;
29
		$limitation = false;
27
		if (!is_null($this->limite_debut) && !is_null($this->limite_nbre)) {
30
		if (!is_null($this->limite_debut) && !is_null($this->limite_nbre)) {
28
			$limitation = true;
31
			$limitation = true;
29
		}
32
		}
30
		return $limitation;
33
		return $limitation;
31
	}
34
	}
32
	
35
	
33
	public function setDistinction($distinct) {
36
	public function setDistinction($distinct) {
34
		$this->distinction = $distinct;
37
		$this->distinction = $distinct;
35
	}
38
	}
36
	
39
	
37
	public function getDistinction() {
40
	public function getDistinction() {
38
		return $this->distinction;
41
		return $this->distinction;
39
	}
42
	}
40
	
43
	
41
	public function setLimitation($limite_debut, $limite_nbre) {
44
	public function setLimitation($limite_debut, $limite_nbre) {
42
		$this->limite_debut = $limite_debut;
45
		$this->limite_debut = $limite_debut;
43
		$this->limite_nbre = $limite_nbre;
46
		$this->limite_nbre = $limite_nbre;
44
	}
47
	}
45
	
48
	
46
	public function getLimiteDebut() {
49
	public function getLimiteDebut() {
47
		return $this->limite_debut;
50
		return $this->limite_debut;
48
	}
51
	}
49
	public function getLimiteNbre() {
52
	public function getLimiteNbre() {
50
		return $this->limite_nbre;
53
		return $this->limite_nbre;
51
	}
54
	}
-
 
55
	
-
 
56
	//+----------------------------------------------------------------------------------------------------------------+
-
 
57
	// MÉTHODES
-
 
58
	protected function envoyerRequeteAjout($url, Array $donnees) {
-
 
59
		$retour = $this->envoyerRequete($url, $donnees, 'PUT');
-
 
60
		return $retour;
-
 
61
	}
-
 
62
	
-
 
63
	protected function envoyerRequeteModif($url, $donnees) {
-
 
64
		$retour = $this->envoyerRequete($url, $donnees, 'POST');
-
 
65
		return $retour;
-
 
66
	}
-
 
67
	
-
 
68
	protected function envoyerRequeteSuppression($url) {
-
 
69
		$retour = $this->envoyerRequete($url, $donnees, 'DELETE');
-
 
70
		return $retour;
-
 
71
	}
-
 
72
	
-
 
73
	private function envoyerRequete($url, Array $donnees, $mode) {
-
 
74
		$retour = false;
-
 
75
		if ($mode != 'PUT' && $mode != 'POST' && $mode != 'DELETE') {
-
 
76
			$e = "Le mode de requête '$mode' n'est pas accepté!";
-
 
77
			trigger_error($e, E_USER_WARNING);
-
 
78
		} else {
-
 
79
			$contexte = stream_context_create(
-
 
80
				array('http' => array(
-
 
81
	      			'method' => $mode,
-
 
82
					'header' => "Content-type: application/x-www-form-urlencoded\r\n",
-
 
83
	      			'content' => http_build_query($donnees))));
-
 
84
			$retour = file_get_contents($url, false, $contexte);
-
 
85
		}
-
 
86
		return $retour;
-
 
87
	}
52
}
88
}
53
89