Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 3166 Rev 3193
Line 23... Line 23...
23
 */
23
 */
Line 24... Line 24...
24
 
24
 
Line 25... Line 25...
25
 
25
 
26
class CelWidgetManager extends Cel {
-
 
27
 
26
class CelWidgetManager extends Cel {
28
	// certains paramètres apparaissent plusieurs fois car ils ont des alias
27
 
29
	// dans certains widgets
28
	// correspondance entre les champs de l'interface et les champs de la BD (format 2018 / 2019)
30
	private $parametres_autorises = array(
29
	private $parametres_autorises = array(
31
		'projet' => 'projet',
30
			'projet' => 'project',
32
		'type' => 'type',
31
			'type' => 'type',
-
 
32
			'esttype' => 'istype',
-
 
33
			'langue' => 'language',
-
 
34
			'order' => 'order'
-
 
35
	);
-
 
36
	
-
 
37
	private $correspondance_config_widget= array(
-
 
38
			'projet' =>  'project',
-
 
39
			'langue' =>  'language',
-
 
40
			'titre' =>  'title',
-
 
41
			'logo' =>  'logo',
-
 
42
			'description' =>  'description',
-
 
43
			'type' =>  'type',
-
 
44
			'est_type' =>  'is_type',
-
 
45
			'style_css' =>  'css_style',
-
 
46
			'image_fond' =>  'image_font',
-
 
47
			'date_creation' =>  'date_created',
-
 
48
			'type_especes' =>  'taxo_restriction_type',
-
 
49
			'referentiel' =>  'taxo_restriction_value',
-
 
50
			'type_localisation' =>  'location_type',
-
 
51
			'localisation' =>  'location',
-
 
52
			'milieux' =>  'environments',
-
 
53
			'motscles' =>  'project_tag_name'
-
 
54
	);
-
 
55
	
-
 
56
	private $correspondance_champs_etendus = array(
-
 
57
			"key" => "field_id",
-
 
58
			"element" => "data_type",
-
 
59
			"mandatory" => "is_mandatory",
-
 
60
			"unit" => "unit"
-
 
61
	);
-
 
62
	
-
 
63
	private $correspondance_champs_etendus_trad = array(
-
 
64
			"key" => "extended_field_id",
33
		'esttype' => 'est_type',
65
			"name" => "label",
Line 34... Line 66...
34
		'langue' => 'langue',
66
			"description" => "description",
35
		'order' => 'order'
67
			"fieldValues" => "default_value"
36
	);
68
	);
Line 37... Line 69...
37
 
69
 
38
	public function getRessource() {
70
	public function getRessource() {
39
		return $this->getElement(array());
71
		return $this->getElement(array());
40
	}
72
	}
41
 
73
 
42
	/**
74
	/**
43
	 * Méthode appelée avec une requête de type GET.
75
	 * Méthode appelée avec une requête de type GET.
44
	 */
76
	 */
45
	public function getElement($params = array()) {
-
 
-
 
77
	public function getElement($params = array()) { 
-
 
78
		switch(@strtolower($params[0])) { 
46
		switch(@strtolower($params[0])) {
79
		case 'widget':
47
		case 'widget':
80
			$this->getWidget();
48
			$this->getWidget();
81
			break;
49
			break;
82
		case 'champsetendus';
50
 
83
			$this->getChampsEtendus();
51
 
84
			break;
52
		default:
85
		default:
53
			$this->getWidget();
86
			$this->getWidget();
54
		}
87
		}
-
 
88
	}
-
 
89
	
-
 
90
	
-
 
91
	public function createElement($requeteDonnees) {
-
 
92
		unset($requeteDonnees['signup_submit']);
-
 
93
		if (isset($requeteDonnees['champs-supp'])) {
55
	}
94
			$gestionchamps = new GestionChampsEtendus2($this->config);
56
 
95
			$champs = $this->traiterCorrespondanceChampsEtendusInterfaceBD($requeteDonnees); //var_dump($champs);exit;
-
 
96
			$liste = $gestionchamps->ajouterParProjet($champs); 
57
 
97
			unset($requeteDonnees['champs-supp']);
-
 
98
		}
58
	public function createElement($requeteDonnees) {
99
		$requeteDonnees['est_type'] = (isset($requeteDonnees['est_type']) && $requeteDonnees['est_type']== "on") ? '1' : '0';
Line 59... Line 100...
59
		unset($requeteDonnees['signup_submit']);
100
		$manager = new GestionWidget($this->config);
60
		$requeteDonnees['est_type'] = (isset($requeteDonnees['est_type']) && $requeteDonnees['est_type']== "on") ? '1' : '0';
101
		$requeteDonnees = $this->traiterCorresponceConfigWidgetInterfaceBD($requeteDonnees);
61
		$manager = new GestionWidget($this->config);
102
		$retour = $manager->ajouterWidget($requeteDonnees);
62
		$retour = $manager->ajouterWidget($requeteDonnees);
103
 
63
		$this->envoyerJson($retour);
104
		$this->envoyerJson($retour);
64
 
105
 
65
	}
106
	}
-
 
107
	
66
 
108
	public function updateElement($uid,$params) {
67
	public function updateElement($uid,$params) {
109
		$retour = "";
68
		$retour = "";
110
		if (isset($params['projet']) && isset($params['langue'])) {
69
		if (isset($params['projet']) && isset($params['langue'])) {
111
			$manager = new GestionWidget($this->config);
70
			$manager = new GestionWidget($this->config);
112
			$params['est_type'] = (isset($params['est_type']) && $params['est_type']== "on") ? '1' : '0';
71
			$params['est_type'] = (isset($params['est_type']) && $params['est_type']== "on") ? '1' : '0';
113
			$requeteDonnees = $this->traiterCorresponceConfigWidgetInterfaceBD($params);
72
			$retour = $manager->modifierWidget($params['projet'], $params['langue'], $params);
114
			$retour = $manager->modifierWidget($params['projet'], $params['langue'], $requeteDonnees);
Line 73... Line 115...
73
 
115
			
74
		}
116
		}
75
		$this->envoyerJson($retour);
117
		$this->envoyerJson($retour);
76
		return "ff";
118
		return "ff";
-
 
119
		
Line -... Line 120...
-
 
120
	}
-
 
121
 
77
 
122
	private function getWidget() {
-
 
123
		$criteres = $this->traiterParametresAutorises($_GET); 
-
 
124
		$manager = new GestionWidget($this->config);
-
 
125
		$liste = $manager->obtenirWidget($criteres);
-
 
126
		$liste = $this->traiterCorresponceConfigWidgetBDInterface($liste);
-
 
127
 
-
 
128
		$this->envoyerJson($liste);
-
 
129
	}
78
	}
130
	
79
 
131
	private function getChampsEtendus() {
Line 80... Line 132...
80
	private function getWidget() {
132
		$champs = new GestionChampsEtendus2($this->config);
81
		$criteres = $this->traiterParametresAutorises($_GET);
133
		$projet = (isset($_GET['projet'])) ? $_GET['projet'] : "";
82
		$manager = new GestionWidget($this->config);
134
		$langue = (isset($_GET['langue'])) ? $_GET['langue'] : "fr";
83
		$liste = $manager->obtenirWidget($criteres);
135
		$liste = $champs->consulterProjetChampsEtendus($projet, $langue);
84
 
136
		$liste = $this->traiterCorrespondanceChampsEtendusBDInterface($liste);
85
 
137
		
86
		$this->envoyerJson($liste);
138
		$this->envoyerJson($liste);
87
	}
139
	}
88
 
140
 
89
 
141
 
90
	protected function traiterParametresAutorises(Array $parametres) {
142
	protected function traiterParametresAutorises(Array $parametres) {
-
 
143
		$parametres_traites = array();
-
 
144
		
-
 
145
		foreach($parametres as $cle => $valeur) {
-
 
146
			if(is_string($valeur) && !trim($valeur)) continue;
-
 
147
			if(isset($this->parametres_autorises[$cle])) {
-
 
148
				$parametres_traites[$this->parametres_autorises[$cle]] = $valeur;
-
 
149
			}
-
 
150
		}
-
 
151
		return $parametres_traites;
-
 
152
	}
-
 
153
	
-
 
154
	protected function traiterCorresponceConfigWidgetBDInterface(Array $widgets) {
-
 
155
		$parametres_traites = array();
-
 
156
		$corresp = array_flip($this->correspondance_config_widget);
-
 
157
		foreach($widgets as $id => $widget) {
-
 
158
			foreach($widget as $cle => $valeur) {
-
 
159
				if(is_string($valeur) && !trim($valeur)) continue;
-
 
160
				if(isset($corresp[$cle])) {
-
 
161
					$parametres_traites[$id][$corresp[$cle]] = $valeur;
-
 
162
				}
-
 
163
			}
-
 
164
		}
-
 
165
		return $parametres_traites;
-
 
166
	}
-
 
167
	
-
 
168
	protected function traiterCorresponceConfigWidgetInterfaceBD(Array $parametres) {
-
 
169
		$parametres_traites = array();
-
 
170
		$corresp = $this->correspondance_config_widget;
-
 
171
		foreach($parametres as $cle => $valeur) {
-
 
172
				if(is_string($valeur) && !trim($valeur)) continue;
-
 
173
				if(isset($corresp[$cle])) {
-
 
174
					$parametres_traites[$corresp[$cle]] = $valeur;
-
 
175
				}
-
 
176
			}
-
 
177
		return $parametres_traites;
-
 
178
	}
-
 
179
	
-
 
180
	protected function traiterCorrespondanceChampsEtendusInterfaceBD(Array $champsinterface) {
-
 
181
		$champsrequete = array(); $i = 0;
-
 
182
		$champssupp = json_decode($champsinterface['champs-supp'], true); 
-
 
183
		// pour chaque champs-supp, mettre correspondance extended field et extended field trad
-
 
184
		foreach ($champssupp as $champ) {
-
 
185
			$champsrequete['ce'][$i]['project'] = $champsrequete['cet'][$i]['project'] = $champsinterface['projet'];
-
 
186
			$champsrequete['cet'][$i]['language_iso_code'] = $champsinterface['langue']; 
-
 
187
			// pour la table extended fiels champs interface => champs bd
-
 
188
			foreach ($this->correspondance_champs_etendus as $ci => $ce) {
-
 
189
				if (isset($champ[$ci]) && $champ[$ci] != "") {
-
 
190
					$champsrequete['ce'][$i][$ce] = $champ[$ci];
-
 
191
				} else {
-
 
192
					if ($ci == "mandatory") {
-
 
193
						$champsrequete['ce'][$i][$ce] = "0";
-
 
194
					} else {
-
 
195
						$champsrequete['ce'][$i][$ce] = "";
-
 
196
					}
-
 
197
				}
-
 
198
			}
-
 
199
			// pour la table extended fiels trad champs interface => champs bd
-
 
200
			foreach ($this->correspondance_champs_etendus_trad as $cit => $cr) {
-
 
201
				if (isset($champ[$cit]) && is_array($champ[$cit])) {
-
 
202
					$champsrequete['cet'][$i][$cr] = json_encode($champ[$cit]);
-
 
203
				} elseif (isset($champ[$cit]) && $champ[$cit] != "") {
-
 
204
					$champsrequete['cet'][$i][$cr] = $champ[$cit];
-
 
205
				} else {
-
 
206
					$champsrequete['cet'][$i][$cr] = "";
-
 
207
				}
-
 
208
			}
-
 
209
			$i++;
-
 
210
		} 
-
 
211
		return $champsrequete;
-
 
212
	}
-
 
213
	protected function traiterCorrespondanceChampsEtendusBDInterface(Array $champsrequete) {
-
 
214
		$champssupp = array(); $i = 0;
-
 
215
		foreach ($champsrequete as $champ) {
-
 
216
			$champssupp[$champ['project']]['projet'] = $champ['project'];
-
 
217
			$champssupp[$champ['project']]['langue'] = $champ['language_iso_code'];
-
 
218
			// pour la table extended fiels champs interface => champs bd
-
 
219
			foreach ($this->correspondance_champs_etendus as $ci => $ce) {
-
 
220
				if (isset($champ[$ce]) && $champ[$ce] != "") {
-
 
221
					$champssupp[$champ['project']]['champs-supp'][$i][$ci] = $champ[$ce];
-
 
222
				} else {
-
 
223
					$champssupp[$champ['project']]['champs-supp'][$i][$ci]= "";
-
 
224
				}
-
 
225
			}
-
 
226
			// pour la table extended fiels trad champs interface => champs bd
Line 91... Line 227...
91
		$parametres_traites = array();
227
			foreach ($this->correspondance_champs_etendus_trad as $cet => $cr) {
92
 
228
				if (isset($champ[$cr]) && $champ[$cr] != "") {
93
		foreach($parametres as $cle => $valeur) {
229
					$champssupp[$champ['project']]['champs-supp'][$i][$cet]= $champ[$cr];