Subversion Repositories eFlore/Applications.del

Rev

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

Rev 1946 Rev 1947
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
				
79
				
80
				// 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)
81
				if(count($noms_possibles) == 1) {
81
				if(count($noms_possibles) == 1) {
82
					$nom_dans_ref = reset($noms_possibles);
82
					$nom_dans_ref = reset($noms_possibles);
83
					$nom_referentiel = key($noms_possibles);
83
					$nom_referentiel = key($noms_possibles);
84
					// Un seul nom trouvé
84
					// Un seul nom trouvé
85
					if(count($nom_dans_ref) == 1) {
85
					if(count($nom_dans_ref) == 1) {
-
 
86
						if(isset($nom_dans_ref['num_nom'])) {
86
						$this->mettreAjourProposition($prop['id_commentaire'], $nom_referentiel, $nom_dans_ref);
87
							$this->mettreAjourProposition($prop['id_commentaire'], $nom_referentiel, $nom_dans_ref);
87
						$nb_prop_augmentees ++;
88
							$nb_prop_augmentees ++;
-
 
89
						}
88
					}
90
					}
89
				}
91
				}
90
			} else {
92
			} else {
91
				$noms_possibles = $this->rechercherNomsPossibles($referentiel, $prop['nom_sel']);
93
				$noms_possibles = $this->rechercherNomsPossibles($referentiel, $prop['nom_sel']);
92
				$noms_ordonnes[$prop['id_commentaire']]['nom_trouves'] = $noms_possibles;
94
				$noms_ordonnes[$prop['id_commentaire']]['nom_trouves'] = $noms_possibles;
93
				$nb_noms_trouves += count($noms_possibles);
95
				$nb_noms_trouves += count($noms_possibles);
94
				$nb_prop_inchangees += empty($noms_possibles) ? 1 : 0;
96
				$nb_prop_inchangees += empty($noms_possibles) ? 1 : 0;
95
				
97
				
96
				// On ne met à jour qu'en étant absolument sur (si l'on a trouvé un seul nom)
98
				// On ne met à jour qu'en étant absolument sur (si l'on a trouvé un seul nom)
97
				if(count($noms_possibles) == 1) {
99
				if(count($noms_possibles) == 1) {
98
					$nom_dans_ref = array_pop($noms_possibles);
100
					$nom_dans_ref = array_pop($noms_possibles);
99
					if(isset($nom_dans_ref['num_nom'])) {
101
					if(isset($nom_dans_ref['num_nom'])) {
100
						$this->mettreAjourProposition($prop['id_commentaire'], $referentiel, array_pop($noms_possibles));
102
						$this->mettreAjourProposition($prop['id_commentaire'], $referentiel, array_pop($noms_possibles));
101
						$nb_prop_augmentees ++;	
103
						$nb_prop_augmentees ++;	
102
					}
104
					}
103
				}
105
				}
104
			}
106
			}
105
				
107
				
106
			$this->afficherAvancement('propositions traitées ', 1);
108
			$this->afficherAvancement('propositions traitées ', 1);
107
		}
109
		}
108
		
110
		
109
		$noms_ordonnes[$prop['id_commentaire']]['proposition'] = $prop;
111
		$noms_ordonnes[$prop['id_commentaire']]['proposition'] = $prop;
110
		
112
		
111
		echo "\n";
113
		echo "\n";
112
		echo $nb_noms_trouves.' noms ont été trouvés'."\n";
114
		echo $nb_noms_trouves.' noms ont été trouvés'."\n";
113
		echo $nb_prop_augmentees.' propositions ont été améliorées'."\n";
115
		echo $nb_prop_augmentees.' propositions ont été améliorées'."\n";
114
		echo $nb_prop_inchangees.' propositions n\'ont pas pu être améliorées'."\n";
116
		echo $nb_prop_inchangees.' propositions n\'ont pas pu être améliorées'."\n";
115
	}
117
	}
116
	
118
	
117
	
119
	
118
	private function obtenirPropositionsPotentiellementViables() {
120
	private function obtenirPropositionsPotentiellementViables() {
119
		$requete = 'SELECT DISTINCT dc.id_commentaire, dc.nom_sel, dc.nom_referentiel as referentiel_proposition, '.
121
		$requete = 'SELECT DISTINCT dc.id_commentaire, dc.nom_sel, dc.nom_referentiel as referentiel_proposition, '.
120
							'do.nom_referentiel as referentiel_observation '.
122
							'do.nom_referentiel as referentiel_observation '.
121
					'FROM del_commentaire dc '.
123
					'FROM del_commentaire dc '.
122
					'INNER JOIN del_observation do '.
124
					'INNER JOIN del_observation do '.
123
					'	ON do.id_observation = dc.ce_observation '.
125
					'	ON do.id_observation = dc.ce_observation '.
124
					'WHERE dc.nom_sel != "" AND (dc.nom_sel_nn = 0 OR dc.nom_sel_nn IS NULL)';
126
					'WHERE dc.nom_sel != "" AND (dc.nom_sel_nn = 0 OR dc.nom_sel_nn IS NULL)';
125
 
127
 
126
		$propositions = $this->conteneur->getBdd()->recupererTous($requete);
128
		$propositions = $this->conteneur->getBdd()->recupererTous($requete);
127
		
129
		
128
		return $propositions;
130
		return $propositions;
129
	}
131
	}
130
	
132
	
131
	private function rechercherNomsPossibles($referentiel, $nom) {
133
	private function rechercherNomsPossibles($referentiel, $nom) {
132
		$nom = trim($nom);
134
		$nom = trim($nom);
133
		$requete = "SELECT num_nom, num_nom_retenu, nom_sci, CONCAT(nom_sci, ' ', auteur) as nom_sci_etendu FROM ".$this->tables_referentiel[$referentiel]." ".
135
		$requete = "SELECT num_nom, num_nom_retenu, nom_sci, CONCAT(nom_sci, ' ', auteur) as nom_sci_etendu FROM ".$this->tables_referentiel[$referentiel]." ".
134
				"WHERE CONCAT(nom_sci, ' ', auteur) = ".$this->conteneur->getBdd()->proteger($nom)." ".
136
				"WHERE CONCAT(nom_sci, ' ', auteur) = ".$this->conteneur->getBdd()->proteger($nom)." ".
135
				"		OR nom_sci = ".$this->conteneur->getBdd()->proteger($nom)." ".
137
				"		OR nom_sci = ".$this->conteneur->getBdd()->proteger($nom)." ".
136
				"ORDER BY CONCAT(nom_sci, ' ', auteur) ASC";
138
				"ORDER BY CONCAT(nom_sci, ' ', auteur) ASC";
137
		
139
		
138
		$noms = $this->conteneur->getBdd()->recupererTous($requete);
140
		$noms = $this->conteneur->getBdd()->recupererTous($requete);
139
		return $noms;
141
		return $noms;
140
	}
142
	}
141
	
143
	
142
	private function mettreAjourProposition($id_proposition, $referentiel, $infos) {
144
	private function mettreAjourProposition($id_proposition, $referentiel, $infos) {
143
		$requete = "UPDATE del_commentaire ".
145
		$requete = "UPDATE del_commentaire ".
144
					"SET nom_sel_nn = ".$this->conteneur->getBdd()->proteger($infos['num_nom']).", ".
146
					"SET nom_sel_nn = ".$this->conteneur->getBdd()->proteger($infos['num_nom']).", ".
145
					"	 nom_referentiel = ".$this->conteneur->getBdd()->proteger($referentiel)." ".
147
					"	 nom_referentiel = ".$this->conteneur->getBdd()->proteger($referentiel)." ".
146
					"WHERE id_commentaire = ".$this->conteneur->getBdd()->proteger($id_proposition);
148
					"WHERE id_commentaire = ".$this->conteneur->getBdd()->proteger($id_proposition);
147
		return $this->conteneur->getBdd()->requeter($requete);
149
		return $this->conteneur->getBdd()->requeter($requete);
148
	}
150
	}
149
	
151
	
150
	private function construireTableauReferentiels() {
152
	private function construireTableauReferentiels() {
151
		$referentiels_dispos = explode(',', $this->conteneur->getParametre('referentiels'));
153
		$referentiels_dispos = explode(',', $this->conteneur->getParametre('referentiels'));
152
		foreach($referentiels_dispos as $ref) {
154
		foreach($referentiels_dispos as $ref) {
153
			$this->tables_referentiel[$ref] = $this->conteneur->getParametre('table_referentiel_'.$ref);
155
			$this->tables_referentiel[$ref] = $this->conteneur->getParametre('table_referentiel_'.$ref);
154
		}
156
		}
155
	}
157
	}
156
}
158
}