1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.stock.modules.billetterie.web;
35
36 import fr.paris.lutece.plugins.stock.modules.billetterie.business.RatingProductDTO;
37 import fr.paris.lutece.plugins.stock.modules.billetterie.service.IRatingProductService;
38 import fr.paris.lutece.plugins.stock.modules.tickets.service.IStatisticService;
39 import fr.paris.lutece.portal.business.user.AdminUser;
40 import fr.paris.lutece.portal.service.dashboard.DashboardComponent;
41 import fr.paris.lutece.portal.service.spring.SpringContextService;
42 import fr.paris.lutece.portal.service.template.AppTemplateService;
43 import fr.paris.lutece.portal.service.util.AppPathService;
44 import fr.paris.lutece.util.html.HtmlTemplate;
45 import fr.paris.lutece.util.html.Paginator;
46 import fr.paris.lutece.util.url.UrlItem;
47
48 import javax.servlet.http.HttpServletRequest;
49 import java.util.*;
50
51 import static java.util.Optional.ofNullable;
52
53
54
55
56
57
58 public class BilleterieDashboardComponent extends DashboardComponent
59 {
60 private static final String MARK_NB_PURCHASE_COUNT_OF_MONTH = "nbPurchaseCountDuMois";
61 private static final String MARK_NB_PURCHASE_COUNT_OF_DAY = "nbPurchaseCountDuJour";
62 private static final String MARK_NB_PRODUCT_A_VENIR = "nbProductAVenir";
63 private static final String MARK_NB_PRODUCT_A_L_AFFICHE = "nbProductALAffiche";
64 private static final String MARK_LIST_RATING_FOR_PRODUCT = "list_product_with_rating_note";
65 private static final String MARK_NUMBER_OF_ITEM_PER_PAGE = "nItem_per_page";
66 private static final String MARK_SIZE_LIST_RATING_PRODUCT = "size_list_rp";
67
68 private static final String BEAN_STOCK_TICKETS_SHOW_SERVICE = "stock-tickets.showService";
69 public static final String BEAN_RATING_PRODUCT_SERVICE = "stock-billetterie.RatingProductService";
70
71 private static final String PARAMETER_PAGE_INDEX = "page_index";
72 private static final String MARK_PAGINATOR = "paginator";
73
74
75 private static final String DEFAULT_PAGE_INDEX = "1";
76
77
78 private static final String TEMPLATE_ADMIN_DASHBOARD = "admin/plugins/stock/modules/billetterie/billeterie_dashboard.html";
79
80
81 private IRatingProductService _ratingProductService = SpringContextService.getBean( BEAN_RATING_PRODUCT_SERVICE );
82
83
84
85
86
87 @Override
88 public String getDashboardData( AdminUser user, HttpServletRequest request )
89 {
90 HtmlTemplate template;
91 IStatisticService statisticService = SpringContextService.getContext( ).getBean( IStatisticService.class );
92
93 Integer nProductCountALAffiche = statisticService.getCountProductALAffiche( );
94 Integer nProductCountAVenir = statisticService.getCountProductAVenir( );
95
96 Integer nbPurchaseCountOfDay = statisticService.getCountPurchaseOfDay( );
97 Integer nbPurchaseCountOfMonth = statisticService.getCountPurchaseOfMonth( );
98
99 List<RatingProductDTO> ratingProductDTOList = new ArrayList<>( );
100 ratingProductDTOList = _ratingProductService.getAllRatingProduct( );
101
102 Paginator<RatingProductDTO> paginator = null;
103 int nItemPerPage = 5;
104
105 if ( ratingProductDTOList != null )
106 {
107 ratingProductDTOList.sort( Comparator.comparing( RatingProductDTO::getRating ).reversed( ) );
108
109 UrlItem urlItem = new UrlItem( AppPathService.getAdminMenuUrl( ) );
110 String strCurrentPageIndex = Paginator.getPageIndex( request, Paginator.PARAMETER_PAGE_INDEX, DEFAULT_PAGE_INDEX );
111
112 paginator = new Paginator<RatingProductDTO>( ratingProductDTOList, nItemPerPage, urlItem.getUrl( ), PARAMETER_PAGE_INDEX, strCurrentPageIndex );
113 }
114
115
116 Map<String, Object> model = new HashMap<String, Object>( );
117
118 model.put( MARK_NB_PRODUCT_A_L_AFFICHE, nProductCountALAffiche );
119 model.put( MARK_NB_PRODUCT_A_VENIR, nProductCountAVenir );
120
121 model.put( MARK_NB_PURCHASE_COUNT_OF_DAY, nbPurchaseCountOfDay );
122 model.put( MARK_NB_PURCHASE_COUNT_OF_MONTH, nbPurchaseCountOfMonth );
123
124 model.put( MARK_PAGINATOR, paginator );
125
126 if ( paginator != null )
127 {
128 model.put( MARK_LIST_RATING_FOR_PRODUCT, paginator.getPageItems( ) );
129 }
130
131 model.put( MARK_NUMBER_OF_ITEM_PER_PAGE, nItemPerPage );
132 model.put( MARK_SIZE_LIST_RATING_PRODUCT, ofNullable( ratingProductDTOList ).map( List::size ).orElse( 0 ) );
133
134 template = AppTemplateService.getTemplate( TEMPLATE_ADMIN_DASHBOARD, user.getLocale( ), model );
135
136 return template.getHtml( );
137 }
138 }