iPédiatre
 Tout Classes Fichiers Fonctions Variables
stats-ages.php
Aller à la documentation de ce fichier.
1 <?php
14 // On récupère le noeud principal de l'utilisateur
15 $userNode = eZUser::currentUser()->contentObject()->mainNode();
16 
17 // On récupère les données de connection à la base de données
18 $ini = eZINI::instance();
19 $user = $ini->variable('DatabaseSettings', 'User');
20 $passwd = $ini->variable('DatabaseSettings', 'Password');
21 $host = $ini->variable('DatabaseSettings', 'Server');
22 $dbname = $ini->variable('DatabaseSettings', 'Database');
23 
24 // On récupère les node ids de tous les articles publiés sur la page du pédiatre
25 // $nodes_id_array = array_map(function($node){return $node->attribute('node_id');}, $userNode->children());
26 
27 // On crée une connection à la base de données
28 $db = ezcDbFactory::create( "mysql://{$user}:{$passwd}@{$host}/{$dbname}" );
29 
30 // On crée un tableau contenant tous les nodes ids classés par catégorie
31 foreach ($userNode->children() as $child)
32 {
33  $datamap = $child->object()->dataMap();
34  $ages = array_filter(explode(';',$datamap['age_slot2']->content()));
35 
36  foreach ($ages as $age) {
37  $nodes[$age][] = $child->attribute('node_id');
38  }
39 }
40 
41 $hash_i18n = array(0 => ezpI18n::tr('ipediatre/ages', '0-3 months'),
42  1 => ezpI18n::tr('ipediatre/ages', '4-6 months'),
43  2 => ezpI18n::tr('ipediatre/ages', '7-9 months'),
44  3 => ezpI18n::tr('ipediatre/ages', '10-12 months'),
45  4 => ezpI18n::tr('ipediatre/ages', '1 year'),
46  5 => ezpI18n::tr('ipediatre/ages', '2-3 years'));
47 
48 foreach ($hash_i18n as $h) {
49  $data[" ".$h] = 0;
50 }
51 
52 foreach( $nodes as $k=>$n) {
53  $q = $db->createSelectQuery();
54 
55  $stmt = $q->select($q->expr->count('*'))
56  ->from('ipediatre_visits')
57  ->where($q->expr->in('node_id', $n))
58  ->prepare();
59 
60  $stmt->execute();
61  $rows = $stmt->fetch();
62  $data[" ".$hash_i18n[$k-1]] = $rows[0];
63 }
64 
65 try {
66 $graph = new ezcGraphPieChart();
67 $graph->legend->position = ezcGraph::RIGHT;
68 $graph->options->label = '';
69 $graph->legend->portraitSize = 0.25;
70 
71 if($Params['type'] != "svg")
72 {
73  $graph->driver = new ezcGraphGdDriver();
74  $graph->options->font = 'design/standard/fonts/arial.ttf';
75 }
77 {
78  protected $dataSetColor = array(
79  '#ffaba7',
80  '#8ad2ef',
81  '#fdab00',
82  '#6db900',
83  '#fd7dab',
84  '#cc429c',
85  );
86 
87  protected $dataSetSymbol = array(ezcGraph::SQUARE);
88  protected $fontName = 'sans-serif';
89  protected $fontColor = '#3485cd';
90 }
91 
92 $graph->palette = new CustomPaletteB;
93 $graph->data['Access statistics'] = new ezcGraphArrayDataSet($data);
94 
95 $graph->renderToOutput(450,200);
96 
97 
98 } catch(Exception $e) {
99 
100  header("Content-Type: image/png");
101  $im = @imagecreate(1, 1);
102  $background_color = imagecolorallocate($im, 0, 0, 0);
103  imagepng($im);
104  imagedestroy($im);
105 }
106 
107 
108 eZExecution::cleanExit();