extranet/includes/commentaires/commentaires.php

143 lines
3.5 KiB
PHP
Raw Normal View History

<?php
function commentaires_graph($id, $titre, $ratios = array() ){
$pattern = '/(Rs?)\[(.*)]#(.{1})/';
$data = array();
$data['x'] = commentaires_graph_x();
foreach($ratios as $ratio){
FB::log($ratio, 'ratio');
if( preg_match($pattern, $ratio, $matches) ){
$typeRatio = $matches[1];
$numRatio = $matches[2];
$typeElement = $matches[3];
$titreRatio = commentaires_graph_lib($numRatio);
switch($typeRatio){
case 'R' : $titreRatio.= ' - Entreprise'; break;
case 'Rs' : $titreRatio.= ' - Secteur'; break;
}
$data['y'][] = array(
'titre' => $titreRatio,
'data' => commentaires_graph_y($typeRatio, $numRatio),
'style' => $typeElement,
);
}
}
$output = commentaires_graph_xy($id, $titre, $data);
return $output;
}
function commentaires_graph_lib($numRatio){
global $ratiosInfos;
return htmlspecialchars_decode(
$ratiosInfos['r'.$numRatio]['libelle'],
ENT_QUOTES);
}
function commentaires_graph_x(){
global $bilansInfos;
$output = array();
foreach($bilansInfos as $bilan){
$output[] = $bilan['dateCloture'];
}
return $output;
}
function commentaires_graph_y($typeRatio, $numRatio){
global $ratiosEntrep, $ratiosSecteur;
FB::log($typeRatio, 'typeRatio');
switch($typeRatio){
case 'R' : $tabRatio = $ratiosEntrep; break;
case 'Rs' : $tabRatio = $ratiosSecteur; break;
}
$output = array();
foreach($tabRatio as $key => $val){
FB::log($val['r'.$numRatio], 'val');
$output[$key] = $val['r'.$numRatio];
}
return $output;
}
function commentaires_graph_xy($id, $titre, $data){
require_once 'phpchartdir/phpchartdir.php';
$path = PATH_SITE.'/cache/imgcache/';
$file = $id.'.png';
if(count($data)<=1){
$output = 0;
}else{
//Tri des données
foreach($data['y'] as $yKey => $y){
$i = 0;
foreach($y['data'] as $val){
$dataTri[$data['x'][$i]] = $val;
$i++;
}
ksort($dataTri);
$data['y'][$yKey]['data'] = array_values($dataTri);
}
sort($data['x']);
//Génération du graphique
$c = new XYChart(500, 350);
$c->addTitle($titre, 'times.ttf', 10);
$c->yAxis->setTitle('EUR');
$c->yAxis->setWidth(2);
$c->xAxis->setTitle('Années');
$c->xAxis->setWidth(2);
$legendObj = $c->addLegend2(25, 25, -2, "times.ttf", 9);
$legendObj->setBackground(Transparent, Transparent);
$c->setPlotArea(50, 90, 280, 200);
//Génération des labels
$labelsX = array();
foreach($data['x'] as $x){
$annee = substr($x, 0, 4);
$mois = substr($x, 4, 2);
$jour = substr($x, 6, 2);
$labelsX[] = $annee;
}
//Détection multi-bar
$graphStyleMH = false;
$precStyle = '';
foreach($data['y'] as $ydata){
if($ydata['style']=='H' && $precStyle == 'H'){
$graphStyleMH = true;
}
$precStyle = $ydata['style'];
}
//Affichage standard
if(!$graphStyleMH){
foreach($data['y'] as $ydata){
switch($ydata['style']){
case 'L':
$lineLayer = $c->addLineLayer(
$ydata['data'], -1, $ydata['titre']);
$lineLayer->setLineWidth(2);
break;
case 'H':
$c->addBarLayer(
$ydata['data'], -1, $ydata['titre']);
break;
}
}
//Affichage multibar
}else{
$layer = $c->addBarLayer2(Side);
$color = array(0xff8080, 0x80ff80);
$i = 0;
foreach($data['y'] as $ydata){
FB::log($ydata['data'], 'ydata');
$layer->addDataSet($ydata['data'], $color[$i], $ydata['titre']);
$i++;
}
}
$c->xAxis->setLabels($labelsX);
if( $c->makeChart($path.$file) === true ){
$output = $file;
}
else{
$output = false;
}
}
return $output;
}