Skip to content
This repository was archived by the owner on Dec 15, 2019. It is now read-only.

Commit 851ff8b

Browse files
committed
stats using flot api
1 parent 53cd1e3 commit 851ff8b

31 files changed

+3370
-654
lines changed

app/Resources/test/mytest.sql

+31-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
use benassociation;
2-
show tables;
2+
-- show tables;
33

4-
-- select * from cotisation;
5-
-- update profile set method = 'Virement' where 1=1;
6-
-- select method from profile;
4+
-- select DATE(created) as x ,sum(price) as y from cotisation group by x order by x;
75

6+
-- select cin, cause, archived from profile;
87

8+
SELECT ROUND(DATEDIFF(Cast(NOW() as Date), Cast(birthday as Date)) / 365, 0) as age from profile;
99

10+
select count(*) from profile where DATEDIFF(Cast(NOW() as Date), Cast(birthday as Date)) / 365 between 19 and 20 ;
1011

1112

1213

@@ -20,6 +21,14 @@ show tables;
2021

2122

2223

24+
25+
26+
27+
-- select gender , count(*) as data from profile group by gender;
28+
29+
-- select created from user;
30+
31+
2332
-- insert into config(the_key, the_value) values('app_theme', 'theme1');
2433

2534
-- describe profile;
@@ -68,4 +77,21 @@ show tables;
6877
-- HAVING DATEDIFF(max(c.date_to), CURRENT_DATE()) < 0
6978
-- ;
7079
-- select id from (select user_id as id, DATEDIFF(max(date_to), CURRENT_DATE()) days from cotisation group by user_id having days < 0 )A ;
71-
-- select u.id from user u LEFT JOIN cotisation c on c.user_id = u.id group by user_id having DATEDIFF(max(c.date_to), CURRENT_DATE()) >= 0 ;
80+
-- select u.id from user u LEFT JOIN cotisation c on c.user_id = u.id group by user_id having DATEDIFF(max(c.date_to), CURRENT_DATE()) >= 0 ;
81+
82+
83+
-- select user_id as id, DATEDIFF(max(date_to), CURRENT_DATE()) days from cotisation group by user_id having days < 0 ;
84+
-- select count(*) as id from cotisation c having DATEDIFF(max(c.date_to), CURRENT_DATE()) >= 0 ;
85+
-- select count(*) as ids from cotisation c having DATEDIFF(max(c.date_to), CURRENT_DATE()) < 0 ;
86+
-- select count(*) from user;
87+
-- select count(*) from cotisation group by user_id;
88+
89+
-- select count(*) from user;
90+
-- select u.id from user u LEFT JOIN cotisation c on c.user_id = u.id
91+
-- where u.id in (select id from (select user_id id, DATEDIFF(max(date_to), CURRENT_DATE()) days from cotisation group by user_id)A where A.days < 0)
92+
93+
-- select * from
94+
-- (select count(*) as yes from (select u.id from user u LEFT JOIN cotisation c on c.user_id = u.id group by user_id having DATEDIFF(max(c.date_to), CURRENT_DATE()) >= 0) A) A,
95+
-- (select count(*) as no from (select u.id from user u LEFT JOIN cotisation c on c.user_id = u.id group by user_id having DATEDIFF(max(c.date_to), CURRENT_DATE()) < 0) A) B,
96+
-- (select count(*) as never from user u left join cotisation c on c.user_id = u.id where c.id is NULL) C;
97+

app/config/config.yml

+4
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ doctrine:
5353
orm:
5454
auto_generate_proxy_classes: %kernel.debug%
5555
auto_mapping: true
56+
dql:
57+
datetime_functions:
58+
DATEDIFF: Ben\UserBundle\DQL\DateDiff
59+
Cast: Ben\UserBundle\DQL\Cast
5660

5761
# Swiftmailer Configuration
5862
swiftmailer:

benbundle.sublime-workspace

+1,351-515
Large diffs are not rendered by default.

composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@
1010
"doctrine/orm": ">=2.2.3,<2.4-dev",
1111
"doctrine/doctrine-bundle": "1.0.*",
1212
"twig/extensions": "1.0.*@dev",
13-
"symfony/assetic-bundle": "2.3.*@dev",
13+
"symfony/assetic-bundle": "2.1.x-dev",
1414
"symfony/swiftmailer-bundle": "2.1.*",
1515
"symfony/monolog-bundle": "2.1.*",
1616
"sensio/distribution-bundle": "2.1.*",
1717
"sensio/framework-extra-bundle": "2.1.*",
1818
"sensio/generator-bundle": "2.1.*",
19+
"kriswallsmith/assetic": "1.1.x-dev",
1920
"jms/security-extra-bundle": "1.2.*",
2021
"jms/di-extra-bundle": "1.1.*",
2122
"doctrine/data-fixtures": "dev-master",
2223
"friendsofsymfony/user-bundle": "*",
2324
"friendsofsymfony/message-bundle": "dev-master",
2425
"stof/doctrine-extensions-bundle": "dev-master",
2526
"liuggio/excelbundle": "~2.0",
26-
"kriswallsmith/assetic": "1.1.*@dev",
27-
"knplabs/knp-snappy-bundle": "dev-master",
27+
"knplabs/knp-snappy-bundle": "dev-master"
2828
},
2929
"scripts": {
3030
"post-install-cmd": [

src/Ben/AssociationBundle/Controller/CotisationController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public function deleteAction(Request $request, $id)
213213
}
214214

215215
$this->get('session')->getFlashBag()->add('success', "ben.flash.success.contribution.deleted");
216-
return $this->redirect($this->generateUrl('cotisation'));
216+
return $this->redirect($this->generateUrl('cotisation_new', array('id' => $entity->getUser()->getId())));
217217
}
218218

219219
private function createDeleteForm($id)

src/Ben/AssociationBundle/Controller/DefaultController.php

+59-15
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,9 @@ public function indexAction()
2424
$counter['cotisation'] = $em->getRepository('BenAssociationBundle:Cotisation')->counter();
2525
$counter['status'] = $em->getRepository('BenAssociationBundle:Status')->counter();
2626

27-
$stats['status'] = $em->getRepository('BenUserBundle:User')->statsByStatus();
28-
$stats['city'] = $em->getRepository('BenUserBundle:User')->statsByCity();
29-
$total = 0;
30-
foreach ($stats['city'] as $obj) {
31-
$total += $obj['data'];
32-
}
33-
34-
$stats['city'] = array_map(function($obj) use ($total){
35-
$obj['percentage'] = $obj['data'] * 100 / $total;
36-
return $obj;
37-
}, $stats['city']);
38-
3927
$groups = $em->getRepository('BenUserBundle:Group')->findByType(Group::$COMMISSION);
4028
return $this->render('BenAssociationBundle:Default:index.html.twig', array(
4129
'groups' => $groups,
42-
'stats' => $stats,
4330
'counter' => $counter));
4431
}
4532

@@ -50,8 +37,8 @@ public function indexAction()
5037
public function inmportFromCsvAction(Request $request)
5138
{
5239
$form = $this->createFormBuilder()
53-
->add('submitFile', 'file')
54-
->getForm();
40+
->add('submitFile', 'file')
41+
->getForm();
5542

5643
if ($request->getMethod('post') == 'POST') {
5744
$form->bindRequest($request);
@@ -89,4 +76,61 @@ public function inmportFromCsvAction(Request $request)
8976
array('form' => $form->createView(),)
9077
);
9178
}
79+
80+
/**
81+
* @Secure(roles="ROLE_MANAGER")
82+
*/
83+
public function statsAction()
84+
{
85+
$statsHandler = $this->get('ben.stats_handler');
86+
87+
$stats['city'] = $statsHandler->setDataColumn('city')->processData();
88+
$stats['gender'] = $statsHandler->setDataColumn('gender')->processData();
89+
$stats['status'] = $statsHandler->setDataColumn('status')->processData();
90+
$stats['created'] = $statsHandler->setDataColumn('created')->processData();
91+
$stats['created'] = array_map(function($item){
92+
return array((new \DateTime($item['x']))->getTimestamp()*1000, 0+$item['y']);
93+
}, $stats['created']);
94+
95+
$stats['revenu'] = $statsHandler->setDataColumn('revenu')->processData();
96+
$stats['revenu'] = array_map(function($item){
97+
return array((new \DateTime($item['x']))->getTimestamp()*1000, 0+$item['y']);
98+
}, $stats['revenu']);
99+
100+
$cot = $statsHandler->setDataColumn('cotisation')->processData();
101+
$stats['cotisation'] = array(
102+
array('label' => 'A jour', 'data' => $cot['yes'], 'color' => '#93b40f'),
103+
array('label' => 'En retard', 'data' => $cot['no'], 'color' => '#e1ab0b'),
104+
array('label' => 'N\'a jamais cotisé', 'data' => $cot['never'], 'color' => '#b94a48')
105+
);
106+
// var_dump($stats);die;
107+
108+
109+
$em = $this->getDoctrine()->getManager();
110+
$status = $em->getRepository('BenAssociationBundle:Status')->findAll();
111+
$groups = $em->getRepository('BenUserBundle:Group')->findAll();
112+
return $this->render('BenAssociationBundle:Default:stats.html.twig', array(
113+
'status' => $status,
114+
'groups' => $groups,
115+
'stats' => $stats));
116+
}
117+
118+
/**
119+
* @Secure(roles="ROLE_MANAGER")
120+
*/
121+
public function jsonStatsAction(Request $request)
122+
{
123+
$em = $this->getDoctrine()->getManager();
124+
$searchParam = $request->get('searchParam');
125+
$all = $em->getRepository('BenUserBundle:User')->counter();
126+
$result = $em->getRepository('BenUserBundle:User')->counter(0, $searchParam);
127+
$response = new Response(json_encode(array(
128+
array('label' => $searchParam['label'], 'data' => $result, 'color' => '#058dc7'),
129+
array('label' => 'Autres', 'data' => ($all-$result), 'color' => '#E9E9E9')
130+
)));
131+
$response->headers->set('Content-Type', 'application/json');
132+
133+
return $response;
134+
}
135+
92136
}

src/Ben/AssociationBundle/Resources/config/routing/default.yml

+10-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,13 @@ Ben_association_homepage:
44

55
ben_import_csv:
66
pattern: /import/csv
7-
defaults: { _controller: BenAssociationBundle:Default:inmportFromCsv }
7+
defaults: { _controller: BenAssociationBundle:Default:inmportFromCsv }
8+
9+
ben_stats:
10+
pattern: /stats
11+
defaults: { _controller: BenAssociationBundle:Default:stats }
12+
13+
ben_stats_json:
14+
pattern: /stats/json
15+
defaults: { _controller: BenAssociationBundle:Default:jsonStats }
16+
requirements: { _method: post }

src/Ben/AssociationBundle/Resources/config/services.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ services:
1111
class: Ben\AssociationBundle\Twig\ConfigExtension
1212
arguments: ["@doctrine.orm.entity_manager"]
1313
tags:
14-
- { name: twig.extension }
14+
- { name: twig.extension }
15+
ben.stats_handler:
16+
class: Ben\AssociationBundle\Stats\StatsHandler
17+
arguments: ["@doctrine.orm.entity_manager"]

src/Ben/AssociationBundle/Resources/translations/messages.fr.yml

+2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ user:
5757
main: Gestion des membres
5858
profile: Profile
5959
user: utilisateur
60+
archive: Archive
6061
meta:
6162
identity: Identité
6263
name: Adhérent
@@ -202,6 +203,7 @@ ben:
202203
show: afficher
203204
edit: Mettre à jour
204205
delete: Supprimer
206+
restore: rétaurer
205207
empty:
206208
history: Supprimer l'historique
207209
valide: Valider

src/Ben/AssociationBundle/Resources/views/Cotisation/new.html.twig

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<h2>{{ 'cotisation.action.new'|trans }}</h2>
77

88
<div class="row">
9-
<div class="col-md-6">
9+
<div class="col-md-6 hidden-print">
1010
<div id="myCalendar" class="datetimepicker"></div>
1111
</div>
1212
<div class="col-md-6">

src/Ben/AssociationBundle/Resources/views/Default/flashes.html.twig

+19-12
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,24 @@
99
{% endfor %}
1010

1111
{% if daysleft is defined %}
12-
{% if daysleft.days < 0 %}
13-
<div class="alert alert-error fade in">
14-
<button type="button" class="close fui-cross" data-dismiss="alert"></button>
15-
<p>Cet adhérent est en retard de {{ daysleft.days|abs }} jours depuis le {{ daysleft.date }}, envoyer lui une alerte par <a href="{{ path('ben_mail_alert', { 'id': daysleft.user }) }}">mail</a>, ou imprimer la <a href="{{ path('ben_print_alert', { 'id': daysleft.user }) }}">lettre</a> pour envoie postal
16-
</p>
17-
</div>
18-
{% else %}
19-
<div class="alert alert-info fade in">
20-
<button type="button" class="close fui-cross" data-dismiss="alert"></button>
21-
Adhérent à jour, {{ daysleft.days }} jours restants (depuis le {{ daysleft.date }})
22-
</div>
23-
{% endif %}
12+
{% if daysleft.days %}
13+
{% if daysleft.days < 0 %}
14+
<div class="alert alert-error fade in">
15+
<button type="button" class="close fui-cross" data-dismiss="alert"></button>
16+
<p>Cet adhérent est en retard de {{ daysleft.days|abs }} jours depuis le {{ daysleft.date }}, envoyer lui une alerte par <a href="{{ path('ben_mail_alert', { 'id': daysleft.user }) }}">mail</a>, ou imprimer la <a href="{{ path('ben_print_alert', { 'id': daysleft.user }) }}">lettre</a> pour envoie postal
17+
</p>
18+
</div>
19+
{% else %}
20+
<div class="alert alert-info fade in">
21+
<button type="button" class="close fui-cross" data-dismiss="alert"></button>
22+
Adhérent à jour, {{ daysleft.days }} jours restants (depuis le {{ daysleft.date }})
23+
</div>
24+
{% endif %}
25+
{% else %}
26+
<div class="alert alert-error fade in">
27+
<button type="button" class="close fui-cross" data-dismiss="alert"></button>
28+
<p>Cet adhérent n'est pas à jour</p>
29+
</div>
30+
{% endif %}
2431
{% endif %}
2532
</section>

src/Ben/AssociationBundle/Resources/views/Default/index.html.twig

+4-63
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,22 @@
2727
{% endfor %}
2828
</ul>
2929
</div>
30-
<div class="box widget-body">
30+
{# <div class="box widget-body">
3131
<header>
3232
<h3><span class="glyphicon glyphicon-stats"></span> Statistiques par ville
3333
<i class="js-toggle pull-right glyphicon glyphicon-chevron-up"></i></h3>
3434
</header>
3535
<ul class="list-group">
3636
{% for item in stats.city %}
3737
<li class="list-group-item">
38-
<span class="mylabel">{{ item.city }}</span> <span class="badge">{{ item.data }}</span>
38+
<span class="mylabel">{{ item.label }}</span> <span class="badge">{{ item.data }}</span>
3939
<div class="progress">
4040
<div class="progress-bar" style="width: {{ item.percentage }}%;"></div>
4141
</div>
4242
</li>
4343
{% endfor %}
4444
</ul>
45-
</div>
45+
</div> #}
4646
</div>
4747
<div class="col-md-8">
4848
<div class="row">
@@ -96,16 +96,6 @@
9696
</div>
9797
</div>
9898
</div>
99-
<div class="box widget-body">
100-
<header>
101-
<h3><span class="glyphicon glyphicon-stats"></span> Statistiques par status
102-
<i class="js-toggle pull-right glyphicon glyphicon-chevron-up"></i></h3>
103-
</header>
104-
<div class="stats-warper">
105-
<div id="statsbystatus" class="graph"></div>
106-
<div class="clearfix"></div>
107-
</div>
108-
</div>
10999
</div>
110100
<div class="col-md-12">
111101
<div class="box widget-body">
@@ -143,43 +133,7 @@
143133

144134
<script>
145135
(function($) {
146-
// var graphData = [{
147-
// // Visits
148-
// data: [ [6, 1300], [7, 1600], [8, 1900], [9, 2100], [10, 2500], [11, 2200], [12, 2000], [13, 1950], [14, 1900], [15, 2000] ],
149-
// color: '#71c73e'
150-
// }, {
151-
// // Returning Visits
152-
// data: [ [6, 500], [7, 600], [8, 550], [9, 600], [10, 800], [11, 900], [12, 800], [13, 850], [14, 830], [15, 1000] ],
153-
// color: '#77b7c5',
154-
// points: { radius: 4, fillColor: '#77b7c5' }
155-
// }
156-
// ];
157-
// // Lines
158-
// $.plot($('#graph-lines'), graphData, {
159-
// series: {
160-
// points: {
161-
// show: true,
162-
// radius: 5
163-
// },
164-
// lines: {
165-
// show: true
166-
// },
167-
// shadowSize: 0
168-
// },
169-
// grid: {
170-
// color: '#646464',
171-
// borderColor: 'transparent',
172-
// borderWidth: 20,
173-
// hoverable: true
174-
// },
175-
// xaxis: {
176-
// tickColor: 'transparent',
177-
// tickDecimals: 2
178-
// },
179-
// yaxis: {
180-
// tickSize: 1000
181-
// }
182-
// });
136+
183137
184138
// // Bars
185139
// $.plot($('#graph-bars'), graphData, {
@@ -247,19 +201,6 @@
247201
// previousPoint = null;
248202
// }
249203
// });
250-
251-
var data = {{ stats.status|json_encode|raw }};
252-
253-
$.plot('#statsbystatus', data, {
254-
series: {
255-
pie: {
256-
show: true
257-
}
258-
},
259-
legend: {
260-
show: false
261-
}
262-
});
263204
264205
var styles = [
265206
// {

0 commit comments

Comments
 (0)