iPédiatre
 Tout Classes Fichiers Fonctions Variables
stats-folders.php
Aller à la documentation de ce fichier.
1 <?php
12 // On récupère le noeud principal de l'utilisateur
13 $userNode = eZUser::currentUser()->contentObject()->mainNode();
14 
15 // On récupère les données de connection à la base de données
16 $ini = eZINI::instance();
17 $user = $ini->variable('DatabaseSettings', 'User');
18 $passwd = $ini->variable('DatabaseSettings', 'Password');
19 $host = $ini->variable('DatabaseSettings', 'Server');
20 $dbname = $ini->variable('DatabaseSettings', 'Database');
21 
22 // On récupère les node ids de tous les articles publiés sur la page du pédiatre
23 // $nodes_id_array = array_map(function($node){return $node->attribute('node_id');}, $userNode->children());
24 
25 // On crée une connection à la base de données
26 $db = ezcDbFactory::create( "mysql://{$user}:{$passwd}@{$host}/{$dbname}" );
27 
28 // On crée un tableau contenant tous les nodes ids classés par catégorie
29 foreach ($userNode->children() as $child)
30 {
31  $category = iPFunctionCollection::fetchCategory($child->object()->attribute('id'));
32  $nodes[" ".$category['result']->attribute('name')][] = $child->attribute('node_id');
33 }
34 
35 // Pour chaque catégorie, on compte le nombre d'articles publiés
36 foreach( $nodes as $k=>$n) {
37 
38  $q = $db->createSelectQuery();
39 
40  $stmt = $q->select($q->expr->count('*'))
41  ->from('ipediatre_visits')
42  ->where($q->expr->in('node_id', $n))
43  ->prepare();
44 
45  $stmt->execute();
46  $rows = $stmt->fetch();
47 
48  $nodes[$k] = $rows[0];
49 }
50 try {
51 $graph = new ezcGraphPieChart();
52 
53 if ($Params['type'] != 'svg')
54 {
55  $graph->driver = new ezcGraphGdDriver();
56  $graph->options->font = 'design/standard/fonts/arial.ttf';
57 }
58 
59 $graph->legend->position = ezcGraph::RIGHT;
60 $graph->options->label = '';
61 $graph->legend->portraitSize = .25;
62 
63 
65 {
66  protected $dataSetColor = array(
67  '#b9dbf6',
68  '#95caf7',
69  '#5baaeb',
70  '#0e6ec2',
71  '#114089',
72  '#4E9A0688',
73  '#3465A4',
74  '#F57900',
75  '#ffffff'
76  );
77 
78  protected $dataSetSymbol = array(ezcGraph::SQUARE);
79  protected $fontName = 'sans-serif';
80 
81  protected $fontColor = '#3485cd';
82 }
83 
84 $graph->palette = new CustomPaletteA;
85 $graph->data['Access statistics'] = new ezcGraphArrayDataSet($nodes);
86 
87 $graph->renderToOutput(450,200);
88 
89 } catch(Exception $e) {
90 
91  header("Content-Type: image/png");
92  $im = @imagecreate(1, 1);
93  $background_color = imagecolorallocate($im, 0, 0, 0);
94  imagepng($im);
95  imagedestroy($im);
96 }
97 eZExecution::cleanExit();