Subversion Repositories eFlore/Applications.del

Rev

Rev 1940 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1939 aurelien 1
<?php
2
// declare(encoding='UTF-8');
3
/**
4
 * Script gérant la maintenance de DEL.
5
 *
6
 * @category   DEL
7
 * @package    Scripts
8
 * @subpackage Maintenance
9
 * @author     Aurelien PERONNET <aurelien@tela-botanica.org>
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>
12
 * @copyright  1999-2014 Tela Botanica <accueil@tela-botanica.org>
13
 */
14
class Maintenance extends DelScript {
15
 
16
	private $tables_referentiel = array(
17
				'bdtfx' => 'tb_eflore.bdtfx_v2_01',
18
				'bdtxa' => 'tb_eflore.bdtxa_v1_01',
19
				'apd'	=> 'tb_eflore.apd_v3_4_0'
20
		);
21
 
22
	public function __construct($conteneur) {
23
		$this->conteneur = new Conteneur($this->parametres);
24
	}
25
 
26
	public function executer() {
27
 
28
		$propositions = $this->obtenirPropositionsPotentiellementViables();
29
 
30
		$noms_ordonnes = array();
31
		$nb_prop_orphelines = count($propositions);
32
		$nb_prop_augmentees = 0;
33
		$nb_noms_trouves = 0;
34
		$nb_prop_inchangees = 0;
35
 
36
		echo $nb_prop_orphelines.' propositions sont potentiellement améliorables'."\n";
37
 
38
		foreach($propositions as $prop) {
39
 
40
			$referentiel = in_array($prop['referentiel_proposition'], array_keys($this->tables_referentiel)) ?
41
							$prop['referentiel_proposition'] : $prop['referentiel_observation'];
42
			$referentiel = in_array($referentiel, array_keys($this->tables_referentiel)) ?
43
							$referentiel : 'tous';
44
			$referentiel = substr($referentiel, 0, 5);
45
 
46
			if($referentiel == 'tous') {
47
				$noms_trouves = 0;
48
				foreach(array_keys($this->tables_referentiel) as $ref) {
49
					$noms_possibles[$referentiel] = $this->rechercherNomsPossibles($ref, $prop['nom_sel']);
50
					$nb_noms_trouves += count($noms_possibles[$referentiel]);
51
					$noms_trouves += empty($noms_possibles[$referentiel]) ? 1 : 0;
52
				}
53
				$nb_prop_inchangees += $noms_trouves != 0 ? 1 : 0;
54
				$nb_prop_augmentees += $noms_trouves != 0 ? 0 : 1;
55
			} else {
56
				$noms_possibles[$referentiel] = $this->rechercherNomsPossibles($referentiel, $prop['nom_sel']);
57
				$noms_ordonnes[$prop['id_commentaire']]['nom_trouves'] = $noms_possibles;
58
				$nb_noms_trouves += count($noms_possibles[$referentiel]);
59
				$nb_prop_inchangees += empty($noms_possibles[$referentiel]) ? 1 : 0;
60
				$nb_prop_augmentees += empty($noms_possibles[$referentiel]) ? 0 : 1;
61
			}
62
		}
63
 
64
		$noms_ordonnes[$prop['id_commentaire']]['proposition'] = $prop;
65
 
66
		//TODO: faire la mise à jour
67
 
68
		echo $nb_noms_trouves.' noms ont été trouvés'."\n";
69
		echo $nb_prop_augmentees.' propositions ont été améliorées'."\n";
70
		echo $nb_prop_inchangees.' propositions n\'ont pas pu être améliorées'."\n";
71
	}
72
 
73
	private function obtenirPropositionsPotentiellementViables() {
74
		$requete = 'SELECT dc.id_commentaire, dc.nom_sel, dc.nom_referentiel as referentiel_proposition, '.
75
							'do.nom_referentiel as referentiel_observation '.
76
					'FROM del_commentaire dc '.
77
					'INNER JOIN del_observation do '.
78
					'	ON do.id_observation = dc.ce_observation '.
79
					'WHERE dc.nom_sel != "" AND (dc.nom_sel_nn = 0 OR dc.nom_sel_nn IS NULL)';
80
 
81
		$propositions = $this->conteneur->getBdd()->recupererTous($requete);
82
 
83
		return $propositions;
84
	}
85
 
86
	private function rechercherNomsPossibles($referentiel, $nom) {
87
		$nom = trim($nom);
88
		$requete = "SELECT num_nom, num_nom_retenu, nom_sci, CONCAT(nom_sci, ' ', auteur) as nom_sci_etendu FROM ".$this->tables_referentiel[$referentiel]." ".
89
				"WHERE CONCAT(nom_sci, ' ', auteur) = ".$this->conteneur->getBdd()->proteger($nom)." ".
90
				"		OR nom_sci = ".$this->conteneur->getBdd()->proteger($nom)." ".
91
				"ORDER BY CONCAT(nom_sci, ' ', auteur) ASC";
92
 
93
		$noms = $this->conteneur->getBdd()->recupererTous($requete);
94
		return $noms;
95
	}
96
}