typnotice = $typnotice;
$this->typdoc = $typdoc;
$this->fetch_sources();
$this->fetch_data();
}
//On récupère la liste des sources dispos pour enrichir
public function fetch_sources(){
global $base_path;
$connectors = connecteurs::get_instance();
$this->catalog = $connectors->catalog;
foreach ($connectors->catalog as $id=>$prop) {
$comment=$prop['COMMENT'];
//Recherche du nombre de sources
$n_sources=0;
if(isset($prop['ENRICHMENT']) && ($prop['ENRICHMENT'] == "yes")){
if (is_file($base_path."/admin/connecteurs/in/".$prop['PATH']."/".$prop['NAME'].".class.php")) {
require_once($base_path."/admin/connecteurs/in/".$prop['PATH']."/".$prop['NAME'].".class.php");
eval("\$conn=new ".$prop['NAME']."(\"".$base_path."/admin/connecteurs/in/".$prop['PATH']."\");");
$conn->get_sources();
foreach($conn->sources as $source_id=>$s) {
if(isset($s['ENRICHMENT'])) {
if($s['ENRICHMENT'] == 1){
$this->enhancer[] = array(
'id' =>$s['SOURCE_ID'],
'name' =>$s['NAME']
);
}
}
}
}
}
}
}
//Récupération des données existantes
public function fetch_data(){
$rqt = "select * from sources_enrichment";
if($this->typnotice && $this->typdoc){
$rqt.= " where (source_enrichment_typnotice like '".$this->typnotice."' and source_enrichment_typdoc like '') or (source_enrichment_typnotice like '".$this->typnotice."' and source_enrichment_typdoc like '".$this->typdoc."')";
}
$res = pmb_mysql_query($rqt);
if(pmb_mysql_num_rows($res)){
while($r= pmb_mysql_fetch_object($res)){
$this->active[$r->source_enrichment_typnotice.$r->source_enrichment_typdoc][] = $r->source_enrichment_num;
$this->params[$r->source_enrichment_typnotice.$r->source_enrichment_typdoc][$r->source_enrichment_num] = unserialize($r->source_enrichment_params);
}
}
}
//retourne les éléments à rajouter dans le head, les calculs aux besoins;
public function getHeaders(){
global $include_path;
if(!$this->enrichmentsTabHeaders) $this->generateHeaders();
//l'enrichissement se fait en ajax...
$this->enrichmentsTabHeaders[]="
";
//si les notices ne sont pas dépliables, on lance le tout à la fin du chargement de la page...
// $this->enrichmentsTabHeaders[]=" ";
return implode("\n",$this->enrichmentsTabHeaders);
}
//Méthode qui génère les éléments à insérer dans le header pour le bon fonctionnement des enrichissements
public function generateHeaders(){
global $base_path;
$this->enrichmentsTabHeaders =array();
$alreadyIncluded = array();
foreach($this->active as $type => $sources){
foreach($sources as $source_id){
if(!in_array($source_id,$alreadyIncluded)){
//on récupère les infos de la source nécessaires pour l'instancier
$name = connecteurs::get_class_name($source_id);
foreach($this->catalog as $connector){
if($connector['NAME'] == $name){
if (is_file($base_path."/admin/connecteurs/in/".$connector['PATH']."/".$name.".class.php")){
require_once($base_path."/admin/connecteurs/in/".$connector['PATH']."/".$name.".class.php");
$conn = new $name($base_path."/admin/connecteurs/in/".$connector['PATH']);
$this->enrichmentsTabHeaders = array_merge($this->enrichmentsTabHeaders,$conn->getEnrichmentHeader($source_id));
$this->enrichmentsTabHeaders = array_unique($this->enrichmentsTabHeaders);
}
}
}
$alreadyIncluded[]=$source_id;
}
}
}
}
public function getTypeOfEnrichment($notice_id){
global $base_path;
global $msg;
$infos = array();
$this->parseType();
if(isset($this->active[$this->typnotice.$this->typdoc])) $type = $this->typnotice.$this->typdoc;
else $type = $this->typnotice;
if(isset($this->active[$type])){
foreach($this->active[$type] as $source_id){
//on récupère les infos de la source nécessaires pour l'instancier
$name = connecteurs::get_class_name($source_id);
foreach($this->catalog as $connector){
if($connector['NAME'] == $name){
if (is_file($base_path."/admin/connecteurs/in/".$connector['PATH']."/".$name.".class.php")){
require_once($base_path."/admin/connecteurs/in/".$connector['PATH']."/".$name.".class.php");
$conn = new $name($base_path."/admin/connecteurs/in/".$connector['PATH']);
$info = $conn->getTypeOfEnrichment($notice_id,$source_id);
$s=$conn->get_source_params($source_id);
$types = array(
'source_id' => $source_id
);
for($i=0 ; $i $info['type'][$i],
'label' => $msg[substr($this->type[$info['type'][$i]],4)]
);
}elseif(!$info['type'][$i]['label']){
$info['type'][$i]['label'] = $msg[substr($this->type[$info['type'][$i]],4)];
}
if(in_array($info['type'][$i]['code'],$s['TYPE_ENRICHMENT_ALLOWED'])){
// Récupération des infos d'affichage par défaut et d'ordre
if (isset($this->params[$type][$source_id][$info['type'][$i]['code']]['default_display'])) $info['type'][$i]['default_display'] = $this->params[$type][$source_id][$info['type'][$i]['code']]['default_display'];
if (isset($this->params[$type][$source_id][$info['type'][$i]['code']]['order'])) $info['type'][$i]['order'] = $this->params[$type][$source_id][$info['type'][$i]['code']]['order'];
$types['type'][]= $info['type'][$i];
}
}
if(count($types['type'])>0){
$infos[] = $types;
}
}
}
}
}
}
return $infos;
}
public function getEnrichment($notice_id,$enrichmentType ="",$enrich_params=array(),$enrichPage=1){
global $base_path;
$infos = array();
if(isset($this->active[$this->typnotice.$this->typdoc])) $type = $this->typnotice.$this->typdoc;
else $type = $this->typnotice;
if(isset($this->active[$type])){
foreach($this->active[$type] as $source_id){
//on récupère les infos de la source nécessaires pour l'instancier
$name = connecteurs::get_class_name($source_id);
foreach($this->catalog as $connector){
if($connector['NAME'] == $name){
if (is_file($base_path."/admin/connecteurs/in/".$connector['PATH']."/".$name.".class.php")){
require_once($base_path."/admin/connecteurs/in/".$connector['PATH']."/".$name.".class.php");
$conn = new $name($base_path."/admin/connecteurs/in/".$connector['PATH']);
$eTypes = $conn->getTypeOfEnrichment($notice_id,$source_id);
if($enrichmentType){
$bool = false;
for($i=0 ; $igetEnrichment($notice_id,$source_id,$enrichmentType,$enrich_params,$enrichPage);
}
}
}
}
}
}
return $infos;
}
public function parseType(){
global $include_path,$lang;
$file = $include_path."/enrichment/categories.xml";
$xml = file_get_contents($file);
$types= _parser_text_no_function_($xml,"XMLLIST");
foreach($types['ENTRY'] as $type){
$this->type[$type['CODE']] = $type['value'];
}
}
}
?>