Subversion Repositories eFlore/Applications.del

Rev

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

Rev 1941 Rev 1944
Line 11... Line 11...
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 {
Line 15... Line 15...
15
 
15
 
16
	protected $tables_referentiel = array(
-
 
17
				'bdtfx' => 'tb_eflore_test.bdtfx_v2_01',
-
 
18
				'bdtxa' => 'tb_eflore_test.bdtxa_v1_01',
-
 
19
				'apd'	=> 'tb_eflore_test.apd_v3_4_0'	
-
 
Line 20... Line 16...
20
		);
16
	protected $tables_referentiel = array();
21
	
17
	
-
 
18
	public function __construct($conteneur) {
22
	public function __construct($conteneur) {
19
		$this->conteneur = new Conteneur($this->parametres);
Line 23... Line 20...
23
		$this->conteneur = new Conteneur($this->parametres);
20
		$this->construireTableauReferentiels();
-
 
21
	}
-
 
22
	
-
 
23
	public function executer() {	
24
	}
24
		$this->affecterNnsAuxPropositionsViables();
25
	
25
		//$this->affecterPropositionsRetenues();
-
 
26
	}
-
 
27
	
-
 
28
	private function affecterPropositionsRetenues() {
-
 
29
		// TODO: est ce vraiment une bonne idée ?
-
 
30
		// mettre un filtre sur la date ?
-
 
31
		// sur le nombre de votes ?
-
 
32
		$requete = "UPDATE del_commentaire dc ".
-
 
33
					"SET proposition_retenue = 1 ".
-
 
34
					"INNER JOIN del_observation do ".
-
 
35
					"	ON do.id_observation = dc.ce_observation ".
-
 
36
					"	AND do.nom_sel_nn = dc.nom_sel_nn ".
-
 
37
					"	AND do.nom_referentiel = dc.nom_referentiel ".
-
 
38
					"WHERE ce_observation IN ( ".
-
 
39
						"SELECT ce_observation FROM del_commentaire WHERE proposition_retenue = 0 ".
-
 
40
					") ".
-
 
41
					"AND ce_observation NOT IN ( ".
-
 
42
						"SELECT ce_observation FROM del_commentaire WHERE proposition_retenue = 1 ".
-
 
43
					") ";
-
 
44
		echo $requete;exit;
-
 
45
		$modif = $this->executer($requete);
-
 
46
		return $modif;
Line -... Line 47...
-
 
47
	}
-
 
48
	
-
 
49
	private function affecterNnsAuxPropositionsViables() {
26
	public function executer() {
50
		
27
				
51
		echo "Affectation de nn aux propositions qui le permettent \n";
28
		$propositions = $this->obtenirPropositionsPotentiellementViables();
52
		$propositions = $this->obtenirPropositionsPotentiellementViables();
29
		
53
		
30
		$noms_ordonnes = array();
54
		$noms_ordonnes = array();
31
		$nb_propositions_traitees = 0;
55
		$nb_propositions_traitees = 0;
32
		$nb_prop_orphelines = count($propositions);
56
		$nb_prop_orphelines = count($propositions);
33
		$nb_prop_augmentees = 0;
57
		$nb_prop_augmentees = 0;
34
		$nb_noms_trouves = 0;
58
		$nb_noms_trouves = 0;
35
		$nb_prop_inchangees = 0;
59
		$nb_prop_inchangees = 0;
36
		
60
		
37
		echo $nb_prop_orphelines.' propositions sont potentiellement améliorables'."\n";
61
		echo $nb_prop_orphelines.' propositions sont potentiellement améliorables'."\n";
38
		
62
		
39
		foreach($propositions as $prop) {
63
		foreach($propositions as $prop) {
40
			
64
				
41
			$referentiel = in_array($prop['referentiel_proposition'], array_keys($this->tables_referentiel)) ?
65
			$referentiel = in_array($prop['referentiel_proposition'], array_keys($this->tables_referentiel)) ?
42
							$prop['referentiel_proposition'] : $prop['referentiel_observation'];
66
			$prop['referentiel_proposition'] : $prop['referentiel_observation'];
43
			$referentiel = in_array($referentiel, array_keys($this->tables_referentiel)) ? 
67
			$referentiel = in_array($referentiel, array_keys($this->tables_referentiel)) ?
44
							$referentiel : 'tous';
68
			$referentiel : 'tous';
45
			$referentiel = substr($referentiel, 0, 5);
69
			$referentiel = substr($referentiel, 0, 5);
46
			
70
				
47
			if($referentiel == 'tous') {
71
			if($referentiel == 'tous') {
48
				$noms_trouves = 0;
72
				$noms_trouves = 0;
-
 
73
				foreach(array_keys($this->tables_referentiel) as $ref) {
-
 
74
					$noms_possibles[$referentiel] = $this->rechercherNomsPossibles($ref, $prop['nom_sel']);
-
 
75
					$nb_noms_trouves += count($noms_possibles[$referentiel]);
-
 
76
					$noms_trouves += empty($noms_possibles[$referentiel]) ? 1 : 0;
-
 
77
				}
-
 
78
				$nb_prop_inchangees += $noms_trouves != 0 ? 1 : 0;
49
				foreach(array_keys($this->tables_referentiel) as $ref) {
79
				
-
 
80
				
-
 
81
				if($prop['nom_sel'] == "Iris germanica L.") {
50
					$noms_possibles[$referentiel] = $this->rechercherNomsPossibles($ref, $prop['nom_sel']);
82
					echo '<pre>'.print_r($noms_possibles, true).'</pre>';exit;
-
 
83
				}
-
 
84
				// Un seul référentiel correspond (c'est déjà bon signe)
-
 
85
				if(count($noms_possibles) == 1) {
-
 
86
					$nom_dans_ref = reset($noms_possibles);
51
					$nb_noms_trouves += count($noms_possibles[$referentiel]);
87
					$nom_referentiel = key($noms_possibles);
-
 
88
					// Un seul nom trouvé
-
 
89
					if(count($nom_dans_ref) == 1) {
52
					$noms_trouves += empty($noms_possibles[$referentiel]) ? 1 : 0;
90
						$this->mettreAjourProposition($prop['id_commentaire'], $nom_referentiel, $nom_dans_ref);
53
				}
91
						$nb_prop_augmentees ++;
54
				$nb_prop_inchangees += $noms_trouves != 0 ? 1 : 0;
92
					}
55
				$nb_prop_augmentees += $noms_trouves != 0 ? 0 : 1;
93
				}
56
			} else {
94
			} else {
-
 
95
				$noms_possibles = $this->rechercherNomsPossibles($referentiel, $prop['nom_sel']);
-
 
96
				$noms_ordonnes[$prop['id_commentaire']]['nom_trouves'] = $noms_possibles;
57
				$noms_possibles[$referentiel] = $this->rechercherNomsPossibles($referentiel, $prop['nom_sel']);
97
				$nb_noms_trouves += count($noms_possibles);
-
 
98
				$nb_prop_inchangees += empty($noms_possibles) ? 1 : 0;
-
 
99
				
-
 
100
				// On ne met à jour qu'en étant absolument sur (si l'on a trouvé un seul nom)
58
				$noms_ordonnes[$prop['id_commentaire']]['nom_trouves'] = $noms_possibles;
101
				if(count($noms_possibles) == 1) {
59
				$nb_noms_trouves += count($noms_possibles[$referentiel]);
102
					$this->mettreAjourProposition($prop['id_commentaire'], $referentiel, array_pop($noms_possibles));
60
				$nb_prop_inchangees += empty($noms_possibles[$referentiel]) ? 1 : 0;
103
					$nb_prop_augmentees ++;
61
				$nb_prop_augmentees += empty($noms_possibles[$referentiel]) ? 0 : 1;
104
				}
62
			}
105
			}
63
			
106
				
64
			$this->afficherAvancement('propositions traitées ');
107
			$this->afficherAvancement('propositions traitées ', 1);
65
		}
-
 
66
		
108
		}
67
		$noms_ordonnes[$prop['id_commentaire']]['proposition'] = $prop;
109
		
68
		
110
		$noms_ordonnes[$prop['id_commentaire']]['proposition'] = $prop;
69
		//TODO: faire la mise à jour
111
		
70
		echo "\n";	
112
		echo "\n";
Line -... Line 113...
-
 
113
		echo $nb_noms_trouves.' noms ont été trouvés'."\n";
71
		echo $nb_noms_trouves.' noms ont été trouvés'."\n";
114
		echo $nb_prop_augmentees.' propositions ont été améliorées'."\n";
72
		echo $nb_prop_augmentees.' propositions ont été améliorées'."\n";
115
		echo $nb_prop_inchangees.' propositions n\'ont pas pu être améliorées'."\n";
73
		echo $nb_prop_inchangees.' propositions n\'ont pas pu être améliorées'."\n";
116
	}
74
	}
117
	
75
	
118
	
76
	private function obtenirPropositionsPotentiellementViables() {
119
	private function obtenirPropositionsPotentiellementViables() {
77
		$requete = 'SELECT dc.id_commentaire, dc.nom_sel, dc.nom_referentiel as referentiel_proposition, '.
120
		$requete = 'SELECT DISTINCT dc.id_commentaire, dc.nom_sel, dc.nom_referentiel as referentiel_proposition, '.
Line 94... Line 137...
94
				"ORDER BY CONCAT(nom_sci, ' ', auteur) ASC";
137
				"ORDER BY CONCAT(nom_sci, ' ', auteur) ASC";
Line 95... Line 138...
95
		
138
		
96
		$noms = $this->conteneur->getBdd()->recupererTous($requete);
139
		$noms = $this->conteneur->getBdd()->recupererTous($requete);
97
		return $noms;
140
		return $noms;
-
 
141
	}
-
 
142
	
-
 
143
	private function mettreAjourProposition($id_proposition, $referentiel, $infos) {
-
 
144
		$requete = "UPDATE del_commentaire ".
-
 
145
					"SET nom_sel_nn = ".$this->conteneur->getBdd()->proteger($infos['num_nom']).", ".
-
 
146
					"	 nom_referentiel = ".$this->conteneur->getBdd()->proteger($referentiel)." ".
-
 
147
					"WHERE id_commentaire = ".$this->conteneur->getBdd()->proteger($id_proposition);
-
 
148
		return $this->conteneur->getBdd()->requeter($requete);
-
 
149
	}
-
 
150
	
-
 
151
	private function construireTableauReferentiels() {
-
 
152
		$referentiels_dispos = explode(',', $this->conteneur->getParametre('referentiels'));
-
 
153
		foreach($referentiels_dispos as $ref) {
-
 
154
			$this->tables_referentiel[$ref] = $this->conteneur->getParametre('table_referentiel_'.$ref);
-
 
155
		}
98
	}
156
	}
99
}
157
}