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 |
|
1941 |
aurelien |
16 |
protected $tables_referentiel = array(
|
1940 |
aurelien |
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'
|
1939 |
aurelien |
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 |
|
1941 |
aurelien |
30 |
$noms_ordonnes = array();
|
|
|
31 |
$nb_propositions_traitees = 0;
|
1939 |
aurelien |
32 |
$nb_prop_orphelines = count($propositions);
|
|
|
33 |
$nb_prop_augmentees = 0;
|
|
|
34 |
$nb_noms_trouves = 0;
|
|
|
35 |
$nb_prop_inchangees = 0;
|
|
|
36 |
|
|
|
37 |
echo $nb_prop_orphelines.' propositions sont potentiellement améliorables'."\n";
|
|
|
38 |
|
|
|
39 |
foreach($propositions as $prop) {
|
|
|
40 |
|
|
|
41 |
$referentiel = in_array($prop['referentiel_proposition'], array_keys($this->tables_referentiel)) ?
|
|
|
42 |
$prop['referentiel_proposition'] : $prop['referentiel_observation'];
|
|
|
43 |
$referentiel = in_array($referentiel, array_keys($this->tables_referentiel)) ?
|
|
|
44 |
$referentiel : 'tous';
|
|
|
45 |
$referentiel = substr($referentiel, 0, 5);
|
|
|
46 |
|
|
|
47 |
if($referentiel == 'tous') {
|
|
|
48 |
$noms_trouves = 0;
|
|
|
49 |
foreach(array_keys($this->tables_referentiel) as $ref) {
|
|
|
50 |
$noms_possibles[$referentiel] = $this->rechercherNomsPossibles($ref, $prop['nom_sel']);
|
|
|
51 |
$nb_noms_trouves += count($noms_possibles[$referentiel]);
|
|
|
52 |
$noms_trouves += empty($noms_possibles[$referentiel]) ? 1 : 0;
|
|
|
53 |
}
|
|
|
54 |
$nb_prop_inchangees += $noms_trouves != 0 ? 1 : 0;
|
|
|
55 |
$nb_prop_augmentees += $noms_trouves != 0 ? 0 : 1;
|
|
|
56 |
} else {
|
|
|
57 |
$noms_possibles[$referentiel] = $this->rechercherNomsPossibles($referentiel, $prop['nom_sel']);
|
|
|
58 |
$noms_ordonnes[$prop['id_commentaire']]['nom_trouves'] = $noms_possibles;
|
|
|
59 |
$nb_noms_trouves += count($noms_possibles[$referentiel]);
|
|
|
60 |
$nb_prop_inchangees += empty($noms_possibles[$referentiel]) ? 1 : 0;
|
|
|
61 |
$nb_prop_augmentees += empty($noms_possibles[$referentiel]) ? 0 : 1;
|
|
|
62 |
}
|
1941 |
aurelien |
63 |
|
|
|
64 |
$this->afficherAvancement('propositions traitées ');
|
1939 |
aurelien |
65 |
}
|
|
|
66 |
|
|
|
67 |
$noms_ordonnes[$prop['id_commentaire']]['proposition'] = $prop;
|
|
|
68 |
|
|
|
69 |
//TODO: faire la mise à jour
|
1941 |
aurelien |
70 |
echo "\n";
|
1939 |
aurelien |
71 |
echo $nb_noms_trouves.' noms ont été trouvés'."\n";
|
|
|
72 |
echo $nb_prop_augmentees.' propositions ont été améliorées'."\n";
|
|
|
73 |
echo $nb_prop_inchangees.' propositions n\'ont pas pu être améliorées'."\n";
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
private function obtenirPropositionsPotentiellementViables() {
|
|
|
77 |
$requete = 'SELECT dc.id_commentaire, dc.nom_sel, dc.nom_referentiel as referentiel_proposition, '.
|
|
|
78 |
'do.nom_referentiel as referentiel_observation '.
|
|
|
79 |
'FROM del_commentaire dc '.
|
|
|
80 |
'INNER JOIN del_observation do '.
|
|
|
81 |
' ON do.id_observation = dc.ce_observation '.
|
|
|
82 |
'WHERE dc.nom_sel != "" AND (dc.nom_sel_nn = 0 OR dc.nom_sel_nn IS NULL)';
|
|
|
83 |
|
|
|
84 |
$propositions = $this->conteneur->getBdd()->recupererTous($requete);
|
|
|
85 |
|
|
|
86 |
return $propositions;
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
private function rechercherNomsPossibles($referentiel, $nom) {
|
|
|
90 |
$nom = trim($nom);
|
|
|
91 |
$requete = "SELECT num_nom, num_nom_retenu, nom_sci, CONCAT(nom_sci, ' ', auteur) as nom_sci_etendu FROM ".$this->tables_referentiel[$referentiel]." ".
|
|
|
92 |
"WHERE CONCAT(nom_sci, ' ', auteur) = ".$this->conteneur->getBdd()->proteger($nom)." ".
|
|
|
93 |
" OR nom_sci = ".$this->conteneur->getBdd()->proteger($nom)." ".
|
|
|
94 |
"ORDER BY CONCAT(nom_sci, ' ', auteur) ASC";
|
|
|
95 |
|
|
|
96 |
$noms = $this->conteneur->getBdd()->recupererTous($requete);
|
|
|
97 |
return $noms;
|
|
|
98 |
}
|
|
|
99 |
}
|