Subversion Repositories eFlore/Applications.del

Rev

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

Rev 1945 Rev 1946
1
<?php
1
<?php
2
// declare(encoding='UTF-8');
2
// declare(encoding='UTF-8');
3
/**
3
/**
4
 * Script gérant la maintenance de DEL.
4
 * Script gérant la maintenance de DEL.
5
 *
5
 *
6
 * @category   DEL
6
 * @category   DEL
7
 * @package    Scripts
7
 * @package    Scripts
8
 * @subpackage Maintenance
8
 * @subpackage Maintenance
9
 * @author     Aurelien PERONNET <aurelien@tela-botanica.org>
9
 * @author     Aurelien PERONNET <aurelien@tela-botanica.org>
10
 * @license    GPL v3 <http://www.gnu.org/licenses/gpl.txt>
10
 * @license    GPL v3 <http://www.gnu.org/licenses/gpl.txt>
11
 * @license    CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
11
 * @license    CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
12
 * @copyright  1999-2014 Tela Botanica <accueil@tela-botanica.org>
12
 * @copyright  1999-2014 Tela Botanica <accueil@tela-botanica.org>
13
 */
13
 */
14
class Maintenance extends DelScript {
14
class Maintenance extends DelScript {
15
 
15
 
16
	protected $tables_referentiel = array();
16
	protected $tables_referentiel = array();
17
	
17
	
18
	public function __construct($conteneur) {
18
	public function __construct($conteneur) {
19
		$this->conteneur = new Conteneur($this->parametres);
19
		$this->conteneur = new Conteneur($this->parametres);
20
		$this->construireTableauReferentiels();
20
		$this->construireTableauReferentiels();
21
	}
21
	}
22
	
22
	
23
	public function executer() {	
23
	public function executer() {	
24
		$this->affecterNnsAuxPropositionsViables();
24
		$this->affecterNnsAuxPropositionsViables();
25
		//$this->affecterPropositionsRetenues();
25
		//$this->affecterPropositionsRetenues();
26
	}
26
	}
27
	
27
	
28
	private function affecterPropositionsRetenues() {
28
	private function affecterPropositionsRetenues() {
29
		// TODO: est ce vraiment une bonne idée ?
29
		// TODO: est ce vraiment une bonne idée ?
30
		// mettre un filtre sur la date ?
30
		// mettre un filtre sur la date ?
31
		// sur le nombre de votes ?
31
		// sur le nombre de votes ?
32
		$requete = "UPDATE del_commentaire dc ".
32
		$requete = "UPDATE del_commentaire dc ".
33
					"SET proposition_retenue = 1 ".
33
					"SET proposition_retenue = 1 ".
34
					"INNER JOIN del_observation do ".
34
					"INNER JOIN del_observation do ".
35
					"	ON do.id_observation = dc.ce_observation ".
35
					"	ON do.id_observation = dc.ce_observation ".
36
					"	AND do.nom_sel_nn = dc.nom_sel_nn ".
36
					"	AND do.nom_sel_nn = dc.nom_sel_nn ".
37
					"	AND do.nom_referentiel = dc.nom_referentiel ".
37
					"	AND do.nom_referentiel = dc.nom_referentiel ".
38
					"WHERE ce_observation IN ( ".
38
					"WHERE ce_observation IN ( ".
39
						"SELECT ce_observation FROM del_commentaire WHERE proposition_retenue = 0 ".
39
						"SELECT ce_observation FROM del_commentaire WHERE proposition_retenue = 0 ".
40
					") ".
40
					") ".
41
					"AND ce_observation NOT IN ( ".
41
					"AND ce_observation NOT IN ( ".
42
						"SELECT ce_observation FROM del_commentaire WHERE proposition_retenue = 1 ".
42
						"SELECT ce_observation FROM del_commentaire WHERE proposition_retenue = 1 ".
43
					") ";
43
					") ";
44
		echo $requete;exit;
44
		echo $requete;exit;
45
		$modif = $this->executer($requete);
45
		$modif = $this->executer($requete);
46
		return $modif;
46
		return $modif;
47
	}
47
	}
48
	
48
	
49
	private function affecterNnsAuxPropositionsViables() {
49
	private function affecterNnsAuxPropositionsViables() {
50
		
50
		
51
		echo "Affectation de nn aux propositions qui le permettent \n";
51
		echo "Affectation de nn aux propositions qui le permettent \n";
52
		$propositions = $this->obtenirPropositionsPotentiellementViables();
52
		$propositions = $this->obtenirPropositionsPotentiellementViables();
53
		
53
		
54
		$noms_ordonnes = array();
54
		$noms_ordonnes = array();
55
		$nb_propositions_traitees = 0;
55
		$nb_propositions_traitees = 0;
56
		$nb_prop_orphelines = count($propositions);
56
		$nb_prop_orphelines = count($propositions);
57
		$nb_prop_augmentees = 0;
57
		$nb_prop_augmentees = 0;
58
		$nb_noms_trouves = 0;
58
		$nb_noms_trouves = 0;
59
		$nb_prop_inchangees = 0;
59
		$nb_prop_inchangees = 0;
60
		
60
		
61
		echo $nb_prop_orphelines.' propositions sont potentiellement améliorables'."\n";
61
		echo $nb_prop_orphelines.' propositions sont potentiellement améliorables'."\n";
62
		
62
		
63
		foreach($propositions as $prop) {
63
		foreach($propositions as $prop) {
64
				
64
				
65
			$referentiel = in_array($prop['referentiel_proposition'], array_keys($this->tables_referentiel)) ?
65
			$referentiel = in_array($prop['referentiel_proposition'], array_keys($this->tables_referentiel)) ?
66
			$prop['referentiel_proposition'] : $prop['referentiel_observation'];
66
			$prop['referentiel_proposition'] : $prop['referentiel_observation'];
67
			$referentiel = in_array($referentiel, array_keys($this->tables_referentiel)) ?
67
			$referentiel = in_array($referentiel, array_keys($this->tables_referentiel)) ?
68
			$referentiel : 'tous';
68
			$referentiel : 'tous';
69
			$referentiel = substr($referentiel, 0, 5);
69
			$referentiel = substr($referentiel, 0, 5);
70
				
70
				
71
			if($referentiel == 'tous') {
71
			if($referentiel == 'tous') {
72
				$noms_trouves = 0;
72
				$noms_trouves = 0;
73
				foreach(array_keys($this->tables_referentiel) as $ref) {
73
				foreach(array_keys($this->tables_referentiel) as $ref) {
74
					$noms_possibles[$referentiel] = $this->rechercherNomsPossibles($ref, $prop['nom_sel']);
74
					$noms_possibles[$referentiel] = $this->rechercherNomsPossibles($ref, $prop['nom_sel']);
75
					$nb_noms_trouves += count($noms_possibles[$referentiel]);
75
					$nb_noms_trouves += count($noms_possibles[$referentiel]);
76
					$noms_trouves += empty($noms_possibles[$referentiel]) ? 1 : 0;
76
					$noms_trouves += empty($noms_possibles[$referentiel]) ? 1 : 0;
77
				}
77
				}
78
				$nb_prop_inchangees += $noms_trouves != 0 ? 1 : 0;
78
				$nb_prop_inchangees += $noms_trouves != 0 ? 1 : 0;
79
				
-
 
80
				
-
 
81
				if($prop['nom_sel'] == "Iris germanica L.") {
-
 
82
					echo '<pre>'.print_r($noms_possibles, true).'</pre>';exit;
-
 
83
				}
79
				
84
				// Un seul référentiel correspond (c'est déjà bon signe)
80
				// Un seul référentiel correspond (c'est déjà bon signe)
85
				if(count($noms_possibles) == 1) {
81
				if(count($noms_possibles) == 1) {
86
					$nom_dans_ref = reset($noms_possibles);
82
					$nom_dans_ref = reset($noms_possibles);
87
					$nom_referentiel = key($noms_possibles);
83
					$nom_referentiel = key($noms_possibles);
88
					// Un seul nom trouvé
84
					// Un seul nom trouvé
89
					if(count($nom_dans_ref) == 1) {
85
					if(count($nom_dans_ref) == 1) {
90
						$this->mettreAjourProposition($prop['id_commentaire'], $nom_referentiel, $nom_dans_ref);
86
						$this->mettreAjourProposition($prop['id_commentaire'], $nom_referentiel, $nom_dans_ref);
91
						$nb_prop_augmentees ++;
87
						$nb_prop_augmentees ++;
92
					}
88
					}
93
				}
89
				}
94
			} else {
90
			} else {
95
				$noms_possibles = $this->rechercherNomsPossibles($referentiel, $prop['nom_sel']);
91
				$noms_possibles = $this->rechercherNomsPossibles($referentiel, $prop['nom_sel']);
96
				$noms_ordonnes[$prop['id_commentaire']]['nom_trouves'] = $noms_possibles;
92
				$noms_ordonnes[$prop['id_commentaire']]['nom_trouves'] = $noms_possibles;
97
				$nb_noms_trouves += count($noms_possibles);
93
				$nb_noms_trouves += count($noms_possibles);
98
				$nb_prop_inchangees += empty($noms_possibles) ? 1 : 0;
94
				$nb_prop_inchangees += empty($noms_possibles) ? 1 : 0;
99
				
95
				
100
				// On ne met à jour qu'en étant absolument sur (si l'on a trouvé un seul nom)
96
				// On ne met à jour qu'en étant absolument sur (si l'on a trouvé un seul nom)
101
				if(count($noms_possibles) == 1) {
97
				if(count($noms_possibles) == 1) {
102
					$nom_dans_ref = array_pop($noms_possibles);
98
					$nom_dans_ref = array_pop($noms_possibles);
103
					if(isset($nom_dans_ref['num_nom'])) {
99
					if(isset($nom_dans_ref['num_nom'])) {
104
						$this->mettreAjourProposition($prop['id_commentaire'], $referentiel, array_pop($noms_possibles));
100
						$this->mettreAjourProposition($prop['id_commentaire'], $referentiel, array_pop($noms_possibles));
105
						$nb_prop_augmentees ++;	
101
						$nb_prop_augmentees ++;	
106
					}
102
					}
107
				}
103
				}
108
			}
104
			}
109
				
105
				
110
			$this->afficherAvancement('propositions traitées ', 1);
106
			$this->afficherAvancement('propositions traitées ', 1);
111
		}
107
		}
112
		
108
		
113
		$noms_ordonnes[$prop['id_commentaire']]['proposition'] = $prop;
109
		$noms_ordonnes[$prop['id_commentaire']]['proposition'] = $prop;
114
		
110
		
115
		echo "\n";
111
		echo "\n";
116
		echo $nb_noms_trouves.' noms ont été trouvés'."\n";
112
		echo $nb_noms_trouves.' noms ont été trouvés'."\n";
117
		echo $nb_prop_augmentees.' propositions ont été améliorées'."\n";
113
		echo $nb_prop_augmentees.' propositions ont été améliorées'."\n";
118
		echo $nb_prop_inchangees.' propositions n\'ont pas pu être améliorées'."\n";
114
		echo $nb_prop_inchangees.' propositions n\'ont pas pu être améliorées'."\n";
119
	}
115
	}
120
	
116
	
121
	
117
	
122
	private function obtenirPropositionsPotentiellementViables() {
118
	private function obtenirPropositionsPotentiellementViables() {
123
		$requete = 'SELECT DISTINCT dc.id_commentaire, dc.nom_sel, dc.nom_referentiel as referentiel_proposition, '.
119
		$requete = 'SELECT DISTINCT dc.id_commentaire, dc.nom_sel, dc.nom_referentiel as referentiel_proposition, '.
124
							'do.nom_referentiel as referentiel_observation '.
120
							'do.nom_referentiel as referentiel_observation '.
125
					'FROM del_commentaire dc '.
121
					'FROM del_commentaire dc '.
126
					'INNER JOIN del_observation do '.
122
					'INNER JOIN del_observation do '.
127
					'	ON do.id_observation = dc.ce_observation '.
123
					'	ON do.id_observation = dc.ce_observation '.
128
					'WHERE dc.nom_sel != "" AND (dc.nom_sel_nn = 0 OR dc.nom_sel_nn IS NULL)';
124
					'WHERE dc.nom_sel != "" AND (dc.nom_sel_nn = 0 OR dc.nom_sel_nn IS NULL)';
129
 
125
 
130
		$propositions = $this->conteneur->getBdd()->recupererTous($requete);
126
		$propositions = $this->conteneur->getBdd()->recupererTous($requete);
131
		
127
		
132
		return $propositions;
128
		return $propositions;
133
	}
129
	}
134
	
130
	
135
	private function rechercherNomsPossibles($referentiel, $nom) {
131
	private function rechercherNomsPossibles($referentiel, $nom) {
136
		$nom = trim($nom);
132
		$nom = trim($nom);
137
		$requete = "SELECT num_nom, num_nom_retenu, nom_sci, CONCAT(nom_sci, ' ', auteur) as nom_sci_etendu FROM ".$this->tables_referentiel[$referentiel]." ".
133
		$requete = "SELECT num_nom, num_nom_retenu, nom_sci, CONCAT(nom_sci, ' ', auteur) as nom_sci_etendu FROM ".$this->tables_referentiel[$referentiel]." ".
138
				"WHERE CONCAT(nom_sci, ' ', auteur) = ".$this->conteneur->getBdd()->proteger($nom)." ".
134
				"WHERE CONCAT(nom_sci, ' ', auteur) = ".$this->conteneur->getBdd()->proteger($nom)." ".
139
				"		OR nom_sci = ".$this->conteneur->getBdd()->proteger($nom)." ".
135
				"		OR nom_sci = ".$this->conteneur->getBdd()->proteger($nom)." ".
140
				"ORDER BY CONCAT(nom_sci, ' ', auteur) ASC";
136
				"ORDER BY CONCAT(nom_sci, ' ', auteur) ASC";
141
		
137
		
142
		$noms = $this->conteneur->getBdd()->recupererTous($requete);
138
		$noms = $this->conteneur->getBdd()->recupererTous($requete);
143
		return $noms;
139
		return $noms;
144
	}
140
	}
145
	
141
	
146
	private function mettreAjourProposition($id_proposition, $referentiel, $infos) {
142
	private function mettreAjourProposition($id_proposition, $referentiel, $infos) {
147
		$requete = "UPDATE del_commentaire ".
143
		$requete = "UPDATE del_commentaire ".
148
					"SET nom_sel_nn = ".$this->conteneur->getBdd()->proteger($infos['num_nom']).", ".
144
					"SET nom_sel_nn = ".$this->conteneur->getBdd()->proteger($infos['num_nom']).", ".
149
					"	 nom_referentiel = ".$this->conteneur->getBdd()->proteger($referentiel)." ".
145
					"	 nom_referentiel = ".$this->conteneur->getBdd()->proteger($referentiel)." ".
150
					"WHERE id_commentaire = ".$this->conteneur->getBdd()->proteger($id_proposition);
146
					"WHERE id_commentaire = ".$this->conteneur->getBdd()->proteger($id_proposition);
151
		return $this->conteneur->getBdd()->requeter($requete);
147
		return $this->conteneur->getBdd()->requeter($requete);
152
	}
148
	}
153
	
149
	
154
	private function construireTableauReferentiels() {
150
	private function construireTableauReferentiels() {
155
		$referentiels_dispos = explode(',', $this->conteneur->getParametre('referentiels'));
151
		$referentiels_dispos = explode(',', $this->conteneur->getParametre('referentiels'));
156
		foreach($referentiels_dispos as $ref) {
152
		foreach($referentiels_dispos as $ref) {
157
			$this->tables_referentiel[$ref] = $this->conteneur->getParametre('table_referentiel_'.$ref);
153
			$this->tables_referentiel[$ref] = $this->conteneur->getParametre('table_referentiel_'.$ref);
158
		}
154
		}
159
	}
155
	}
160
}
156
}