-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathfossee_stats.module
executable file
·7723 lines (6999 loc) · 307 KB
/
fossee_stats.module
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
function fossee_stats_permission() {
return array(
"access fossee_stats" => array(
"title" => t("Access fossee_stats"),
"description" => t("Allows users to view fossee stats.")
),
"view dashboard" => array(
"title" => t("View Dashboard"),
"description" => t("Allows users to view FOSSEE Dashboard.")
),
"view workshop" => array(
"title" => t("View Workshop"),
"description" => t("Allows users to view workshop.")
),
"manage workshop" => array(
"title" => t("Manage Workshop"),
"description" => t("Allows users to manage workshop.")
),
"view postalcampaign" => array(
"title" => t("View postalcampaign"),
"description" => t("Allows users to view postalcampaign.")
),
"manage postalcampaign" => array(
"title" => t("Manage Postalcampaign"),
"description" => t("Allows users to manage postalcampaign.")
),
"view tutorial" => array(
"title" => t("View Spoken Tutorial"),
"description" => t("Allows users to view spoken tutorial.")
),
"manage tutorial" => array(
"title" => t("Manage Spoken Tutorial"),
"description" => t("Allows users to manage spoken tutorial.")
),
"view events" => array(
"title" => t("View Events"),
"description" => t("Allows users to view events.")
),
"manage events" => array(
"title" => t("Manage Events"),
"description" => t("Allows users to manage events.")
),
"administer events" => array(
"title" => t("Events upload setting"),
"description" => t("Allows users to manage postalcampaign.")
)
);
}
function fossee_stats_menu() {
$items = array();
//Load main page
$items['api/fossee-stats/all-time'] = array(
'access callback' => true,
'page callback' => 'all_time_fossee_stats_json',
'delivery callback' => 'drupal_json_output',
'file' => 'fossee_stats_json.inc',
"type" => MENU_CALLBACK
);
$items['api/fossee-stats'] = array(
'access callback' => true,
'page callback' => 'fossee_stats_json',
'delivery callback' => 'drupal_json_output',
'file' => 'fossee_stats_json.inc',
"type" => MENU_CALLBACK
);
$items["fossee-stats"] = array(
"title" => "FOSSEE STATS",
"page callback" => "drupal_get_form",
"page arguments" => array(
"fossee_stats_form"
),
"access arguments" => array(
"access fossee_stats"
),
"type" => MENU_NORMAL_ITEM
);
$items["fossee-dashboard"] = array(
"title" => "FOSSEE Dashboard",
"page callback" => "drupal_get_form",
"page arguments" => array(
"fossee_dashboard_form"
),
"access arguments" => array(
"view dashboard"
),
'file' => 'fossee-dashboard.inc',
"type" => MENU_NORMAL_ITEM
);
//Fetch the list of TBC and LM which comes after filter is applied.
$items["get-list"] = array(
"title" => "",
"page callback" => "list_tbc_and_lm_detail",
'page arguments' => array(
8
),
"access arguments" => array(
"access fossee_stats"
),
"type" => MENU_CALLBACK
);
//Fetch the list of self workshop with all detail after filter is applied and count is received
$items['completed-workshops-list'] = array(
'title' => '',
'page callback' => 'completed_workshops_list',
'page arguments' => array(
5
),
"access arguments" => array(
"access fossee_stats"
),
//'access callback' => TRUE,
"type" => MENU_CALLBACK
);
//Fetch the Details of self workshop
$items['view-completed-workshop'] = array(
'title' => 'Workshop Details',
'page callback' => 'view_completed_workshop',
'access callback' => TRUE,
);
//Following are menu of Events (Workshop, Conference along with testimonial and images and speakers)
$items["events/add"] = array(
"title" => "Add Events",
"page callback" => "workshop_display_all",
"access arguments" => array(
"manage workshop"
),
"type" => MENU_CALLBACK
);
//To edit existing events detail
$items["events/edit"] = array(
"title" => "Edit Events",
"page callback" => "workshop_edit_all",
"access arguments" => array(
"manage workshop"
),
"type" => MENU_CALLBACK
);
//To delete existing events
/*$items["events/delete"] = array(
"title" => "Delete Events",
"page callback" => "workshop_delete_all",
"access arguments" => array(
"manage workshop"
),
"type" => MENU_CALLBACK
);*/
//List of all events
$items["events/view_details"] = array(
"title" => "Details of Selected Event",
"page callback" => "workshop_view_details_all",
"access arguments" => array(
"view workshop"
),
"type" => MENU_CALLBACK
);
//Generate PDF
$items["events/pdfgenerate"] = array(
"title" => "Generate PDF of Selected Event",
"page callback" => "generate_pdf",
"access arguments" => array(
"view workshop"
),
"type" => MENU_CALLBACK
);
//List of images added to particular event
$items["events/images"] = array(
"title" => "Event's Images",
"page callback" => "workshop_view_image_all",
"access arguments" => array(
"view workshop"
),
"type" => MENU_CALLBACK
);
//For changing image
$items["events/images/change"] = array(
"title" => "Event's Images",
"page callback" => "workshop_view_image_change",
"access arguments" => array(
"view workshop"
),
"type" => MENU_CALLBACK
);
//Display all testimonial added for event in list
$items["events/testimonials"] = array(
//"title" => "Testimonials",
"page callback" => "workshop_view_all_testimonials",
"access arguments" => array(
"view workshop"
),
"type" => MENU_CALLBACK
);
//Display details of selected testimonial
$items["events/testimonials/view"] = array(
"title" => "Testimonial",
"page callback" => "workshop_view_selected_testimonial",
"access arguments" => array(
"view workshop"
),
"type" => MENU_CALLBACK
);
$items["events"] = array(
"title" => "Events",
"page callback" => "event_seminar_view_all",
"access arguments" => array(
"view events"
),
"type" => MENU_CALLBACK
);
$items["testconf"] = array(
"title" => "Activities",
"page callback" => "event_activities_all",
"access arguments" => array(
"view events"
),
"type" => MENU_CALLBACK
);
// List of all Postal Campaign
$items["postalcampaign"] = array(
"title" => "Postal Campaign",
"page callback" => "postalcampaign_view_withoutfilter",
"access arguments" => array(
"view postalcampaign"
),
"type" => MENU_CALLBACK
);
// Add Postal Campaign
$items["postalcampaign/add"] = array(
"title" => "Add Postal Campaign",
"page callback" => "postalcampaign_display_all",
"access arguments" => array(
"manage postalcampaign"
),
"type" => MENU_CALLBACK
);
// Edit Postal Campaign
$items["postalcampaign/edit"] = array(
"title" => "Edit Postal Campaign",
"page callback" => "postalcampaign_edit_all",
"access arguments" => array(
"manage postalcampaign"
),
"type" => MENU_CALLBACK
);
// Delete Postal Campaign
$items["postalcampaign/delete"] = array(
"title" => "Delete Postal Campaign",
"page callback" => "postalcampaign_delete_all",
"access arguments" => array(
"manage postalcampaign"
),
"type" => MENU_CALLBACK
);
// View detail of selected Postal Campaign
$items["postalcampaign/view_details"] = array(
"title" => "Postal Campaign Detail",
"page callback" => "postalcampaign_view_details_all",
"access arguments" => array(
"view postalcampaign"
),
"type" => MENU_CALLBACK
);
//To download postal campaign poster in zip format
$items["postalcampaign/download"] = array(
"title" => "Download Postal Campaign",
"page callback" => "createZipOfPosterMaterial",
"access arguments" => array(
"view postalcampaign"
),
"type" => MENU_CALLBACK
);
/*Spoken Tutorial*/
//Add Spoken Tutorial
$items["spokentutorial/add"] = array(
"title" => "Add Spoken Tutorial",
"page callback" => "spokentutorial_display_all",
"access arguments" => array(
"view tutorial"
),
"type" => MENU_CALLBACK
);
/* ADMIN SETTINGS */
//For mentioning extension allowed for image and pdf
$items['admin/settings/events'] = array(
'title' => 'Events Settings',
'description' => 'Events Settings',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'events_settings_form'
),
'access arguments' => array(
'administer events'
),
'type' => MENU_NORMAL_ITEM,
'file' => 'settings.inc'
);
return $items;
}
//Folder path to save all uploaded images of events
function events_images_path() {
return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'events_images/';
}
//Folder path to save all uploaded images/PDF of postal campaign
function posters_path() {
return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'campaign_posters/';
}
//Main Page Form
function fossee_stats_form($form, &$form_state) {
/* First Dropdown for Foss type */
$options_first = _ajax_example_get_first_dropdown_options();
if (isset($form_state['values']['foss_sub_project']) && isset($form_state['values']['foss_type']) && isset($form_state['values']['foss_sub_project_status'])) {
$foss_project = isset($form_state['values']['foss_type']) ? $form_state['values']['foss_type'] : key($options_first);
}
else {
$foss_project = '';
}
$form['foss_type'] = array(
'#type' => 'select',
'#prefix' => '<div class="content"><div><table ><tr><td>',
'#suffix' => '</td>',
'#title' => t('FOSS Type'),
'#multiple' => FALSE,
'#options' => $options_first,
//'#default_value' => $foss_project,
'#validated' => TRUE,
'#ajax' => array(
'callback' => 'ajax_foss_type_dependent_dropdown_callback',
'wrapper' => 'dropdown-second-replace',
'progress' => array(
'message' => ''
)
)
);
/* Second Dropdown for Activities like TBC, LM and other */
if (isset($form_state['values']['foss_sub_project']) && isset($form_state['values']['foss_type']) && isset($form_state['values']['foss_sub_project_status'])) {
$foss_sub_project = isset($form_state['values']['foss_sub_project']) ? $form_state['values']['foss_sub_project'] : key(get_activities_list($foss_project));
}
else {
$foss_sub_project = '';
}
$form['foss_sub_project'] = array(
'#type' => 'select',
'#title' => t('Activities'),
'#options' => get_activities_list($foss_project),
'#prefix' => '<td><div id="dropdown-second-replace" style="width:250px;padding-left:25px" >',
'#suffix' => '</div>',
'#default_value' => "--------------",
'#validated' => TRUE,
'#ajax' => array(
'callback' => 'ajax_foss_sub_project_dependent_dropdown_callback',
'wrapper' => 'dropdown-third-replace',
'progress' => array(
'message' => ''
)
),
'#states' => array(
'invisible' => array(
':input[name="foss_type"]' => array(
'value' => ""
)
)
)
);
/* third Dropdown for Status like Completed and In Progress */
if (isset($form_state['values']['foss_sub_project']) && isset($form_state['values']['foss_type']) && isset($form_state['values']['foss_sub_project_status'])) {
$foss_sub_project_status = isset($form_state['values']['$foss_sub_project_status']) ? $form_state['values']['$foss_sub_project_status'] : '';
}
else {
$foss_sub_project_status = '';
}
$form['foss_sub_project_status'] = array(
'#type' => 'select',
'#title' => t('Status'),
'#options' => _ajax_example_get_third_dropdown_options($foss_sub_project),
'#prefix' => '<td><div id="dropdown-third-replace" style="width:250px">',
'#suffix' => '</div></td></tr>',
'#default_value' => $foss_sub_project_status,
'#validated' => TRUE,
'#states' => array(
'invisible' => array(
array(
array(
':input[name="foss_sub_project"]' => array(
'value' => 0
)
),
'or',
array(
':input[name="foss_type"]' => array(
'value' => ""
)
)
)
)
)
);
/* Start Date for Filter */
$form['start_date'] = array(
'#type' => 'date_popup',
'#title' => t('From Date:'),
'#date_label_position' => '',
'#description' => '',
'#default_value' => '',
'#date_format' => 'Y-m-d',
'#date_increment' => 0,
'#date_year_range' => '2011:+0',
'#prefix' => '<tr><td><div id="startdate">',
'#suffix' => '</div></td>',
'#datepicker_options' => array(
'maxDate' => 0
),
'#states' => array(
'invisible' => array(
':input[name="foss_type"]' => array(
'value' => ""
)
)
)
);
/* End Date for Filter */
$form['end_date'] = array(
'#type' => 'date_popup',
'#title' => t('To Date:'),
'#date_label_position' => '',
'#description' => '',
'#default_value' => '',
'#date_format' => 'Y-m-d',
'#date_increment' => 0,
'#date_year_range' => '2011:+0',
'#prefix' => '<td><div id="enddate" style="padding-left:15px;">',
'#suffix' => '</div></td>',
'#datepicker_options' => array(
'maxDate' => 0
),
'#states' => array(
'invisible' => array(
':input[name="foss_type"]' => array(
'value' => ""
)
)
)
);
/* Country list for Filter */
if (isset($form_state['values']['countryname']) && isset($form_state['values']['statename']) && isset($form_state['values']['cityname'])) {
$countryname = isset($form_state['values']['countryname']) ? $form_state['values']['countryname'] : key(get_country_list($foss_project, $foss_sub_project));
}
else {
$countryname = '';
}
$form['countryname'] = array(
"#type" => "select",
"#title" => t("Select Country"),
'#prefix' => '<td><div style="width:200px;" id= "load_country">',
'#suffix' => '</div></td></tr>',
'#options' => get_country_list($foss_project, $foss_sub_project),
'#states' => array(
'invisible' => array(
array(
array(
':input[name="foss_sub_project"]' => array(
'value' => 0
)
),
'or',
array(
':input[name="foss_type"]' => array(
'value' => ""
),
':input[name="foss_type"]' => array(
'value' => 3
)
)
)
)
),
'#ajax' => array(
'callback' => 'ajax_state_list_dependent_dropdown_callback',
'wrapper' => 'load_state',
'progress' => array(
'message' => ''
)
)
);
/* State list for Filter */
if (isset($form_state['values']['countryname']) && isset($form_state['values']['statename']) && isset($form_state['values']['cityname'])) {
$statename = isset($form_state['values']['statename']) ? $form_state['values']['statename'] : key(get_state_list($foss_project, $foss_sub_project, $countryname));
}
else {
$statename = '';
}
$form['statename'] = array(
"#type" => "select",
"#title" => t("State Name"),
'#validated' => TRUE,
'#options' => get_state_list($foss_project, $foss_sub_project, $countryname),
'#prefix' => '<tr><td><div style="width:150px;" id= "load_state">',
'#suffix' => '</div></td>',
'#states' => array(
'invisible' => array(
array(
array(
':input[name="foss_sub_project"]' => array(
'value' => 0
)
),
'or',
array(
':input[name="foss_type"]' => array(
'value' => ""
),
':input[name="foss_type"]' => array(
'value' => 3
)
)
)
)
),
'#ajax' => array(
'callback' => 'ajax_city_list_dependent_dropdown_callback',
'wrapper' => 'load_state',
'progress' => array(
'message' => ''
)
)
);
/* City list for Filter */
if (isset($form_state['values']['countryname']) && isset($form_state['values']['statename']) && isset($form_state['values']['cityname'])) {
$cityname = isset($form_state['values']['cityname']) ? $form_state['values']['cityname'] : key(get_city_list($foss_project, $foss_sub_project, $countryname, $statename));
}
else {
$cityname = '';
}
$form['cityname'] = array(
"#type" => "select",
"#title" => t("City Name"),
'#validated' => TRUE,
'#options' => get_city_list($foss_project, $foss_sub_project, $countryname, $statename),
'#prefix' => '<td><div style="width:200px ;padding-left:30px;" id= "load_city">',
'#suffix' => '</div></td></tr>',
'#states' => array(
'invisible' => array(
array(
array(
':input[name="foss_sub_project"]' => array(
'value' => 0
)
),
'or',
array(
':input[name="foss_type"]' => array(
'value' => ""
),
':input[name="foss_type"]' => array(
'value' => 3
)
)
)
)
)
);
$form['submit'] = array(
'#type' => 'submit',
'#ajax' => array(
'callback' => 'ajax_example_submit_driven_callback',
'progress' => array(
'message' => ''
)
),
'#value' => t('Filter'),
'#prefix' => '<tr><td align="center">',
'#suffix' => ''
);
$form['reset'] = array(
'#type' => 'submit',
'#value' => t('Reset'),
'#prefix' => '',
'#suffix' => '</td></tr></table></div>'
);
//This is used for displaying text (tab sta)
$form['displaytext'] = array(
'#type' => 'markup',
'#prefix' => '<div><div id="displaytext" style="font-weight:bold;padding-top:10px">',
'#suffix' => '</div></div>',
'#markup' => ''
);
//For displaying count of TBC of all foss
$form['tbctable'] = array(
'#type' => 'item',
'#prefix' => '<div id="default_load" >',
'#markup' => '<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#tbctabledata">Textbook Companions</a></li>
<li><a data-toggle="tab" href="#lmtabledata">Lab Migrations</a></li>
<li><a data-toggle="tab" href="#workshopdata">Workshops</a></li>
<li><a data-toggle="tab" href="#selfworkshopdata">Self Workshops</a></li>
<li><a data-toggle="tab" href="#conferencedata">Conferences </a></li>
<li><a data-toggle="tab" href="#spokentutorialdata">Spoken Tutorials</a></li>
</ul>'
);
$TBC_getchart = getchart("TBC");
$LM_getchart = getchart("LM");
$form['tab_content'] = array(
'#type' => 'item',
'#markup' => '<div class="tab-content">
<div id="tbctabledata"class="tab-pane fade in active">' . get_tabledata_TBC_or_LM("TBC", "1960/01/01", "") . '
<div id="tbcchartdata" style="float:left;width:300px;height:300px;">' . drupal_render($TBC_getchart) . '</div>
</div>
<div id="lmtabledata" class="tab-pane fade ">' . get_tabledata_TBC_or_LM("LM", "1960/01/01", "") . '
<div id="lmchartdata" style="float:left;width:350px;height:300px;">' . drupal_render($LM_getchart) . '</div>
</div>
<div id="workshopdata" class="tab-pane fade ">' . workshop_view_all(0, 1960-01-01, date("Y-m-d")) . '</div>
<div id="selfworkshopdata" class="tab-pane fade">' . getselfworkshoplcount(0, 1960-01-01, date("Y-m-d"), "", "") . '</div>
<div id="conferencedata" class="tab-pane fade ">' . conference_seminar_view_all(0, "", "") . '</div>
<div id="spokentutorialdata" class="tab-pane fade ">' . spokentutorial_view_all("") . '</div>
</div>'
);
$form['lastdiv'] = array(
'#type' => 'item',
'#markup' => '',
'#suffix' => '</div></div>'
);
return $form;
}
/* This function is used to create chart for TBC/LM */
function getchart($sub_type) {
$title = "";
if ($sub_type == "TBC") {
$title = "Textbook Companion Statistics";
}
else {
$title = "Lab Migration Statistics";
}
$chart = array(
'#type' => 'chart',
'#title' => t($title),
'#chart_type' => 'pie',
'#chart_library' => 'google',
'#legend_position' => 'right',
'#data_labels' => TRUE,
'#tooltips' => TRUE,
'#width' => 700,
'#height' => 300
);
$chart['pie_data'] = array(
'#type' => 'chart_data',
'#title' => t($title),
'#data' => get_data_for_chart_allproject($sub_type)
);
$example['chart'] = $chart;
return $example;
}
//This is used to create a bar chart for particular LM or TBC and along with filters
function getchartforselectedProject($foss_type, $sub_type, $startdate, $enddate, $countryname, $statename, $cityname) {
$title = "";
if ($sub_type == "TBC") {
$title = $foss_type . "" . "'s Completed Textbook Companion Statistics";
}
else {
$title = $foss_type . "" . "'s Completed Lab Migration Statistics";
}
$chart = array(
'#type' => 'chart',
'#title' => t($title),
'#chart_type' => 'column',
'#chart_library' => 'google',
'#legend_position' => 'bottom',
'#data_labels' => TRUE,
'#tooltips' => TRUE,
'#width' => 800,
'#height' => 300
);
$chart['pie_data'] = array(
'#type' => 'chart_data',
'#title' => t($title),
'#data' => get_data_for_chart_selectedproject($foss_type, $sub_type, $startdate, $enddate, $countryname, $statename, $cityname)
);
$example['chart'] = $chart;
return $example;
}
//This is used to create a pie chart for particular LM or TBC and along with filters
function getpiechartforselectedProject($foss_type, $sub_type, $startdate, $enddate, $countryname, $statename, $cityname) {
$title = "";
if ($sub_type == "TBC") {
$title = $foss_type . "" . "'s Textbook Companion Statistics";
}
else {
$title = $foss_type . "" . "'s Lab Migration Statistics";
}
$chart = array(
'#type' => 'chart',
'#title' => t($title),
'#chart_type' => 'pie',
'#chart_library' => 'google',
'#legend_position' => 'right',
'#data_labels' => TRUE,
'#tooltips' => TRUE,
'#width' => 700,
'#height' => 300
);
$chart['pie_data'] = array(
'#type' => 'chart_data',
'#title' => t($title),
'#data' => get_data_for_chart_selectedproject($foss_type, $sub_type, $startdate, $enddate, $countryname, $statename, $cityname)
);
$example['chart'] = $chart;
return $example;
}
//Function is used to get the count of LM or TBC for all foss type and pass this count to create charts
function get_data_for_chart_allproject($sub_type) {
$rows = array();
if ($sub_type == "TBC") {
$query = db_select('foss_type');
$query->fields('foss_type', array(
'id'
));
$query->fields('foss_type', array(
'foss_name'
));
$query->fields('foss_type', array(
'tbc'
));
$query->condition('tbc', 1);
$result = $query->execute();
while ($foss_detail = $result->fetchObject()) {
if ($foss_detail->foss_name != NULL) {
if ($foss_detail->foss_name != 'Python') {
db_set_active($foss_detail->foss_name); //Active other database
//For TBC
if ($foss_detail->foss_name != 'eSim' && $foss_detail->foss_name != 'OpenModelica' && $foss_detail->foss_name != 'OpenFOAM' && $foss_detail->foss_name != 'OR-Tools' && $foss_detail->foss_name != 'R') {
$query2 = db_query("SELECT COUNT( pe.book ) AS book_count FROM {textbook_companion_preference} pe LEFT JOIN {textbook_companion_proposal} po ON pe.proposal_id = po.id WHERE po.proposal_status =3 AND pe.approval_status =1 AND pe.category>0");
}
else {
$query2 = db_query("SELECT COUNT( pe.book ) AS book_count FROM {textbook_companion_preference} pe LEFT JOIN {textbook_companion_proposal} po ON pe.proposal_id = po.id WHERE po.proposal_status =3 AND pe.approval_status =1");
}
db_set_active('default'); // We need to call the main (drupal) db back
db_set_active();
$completedbookcount = $query2->fetchObject()->book_count;
$option1 = array(
$foss_detail->foss_name,
(int) $completedbookcount
);
array_push($rows, $option1);
}
else {
db_set_active($foss_detail->foss_name); //Active other database
$query2 = db_select('tbc_book');
$query2->addExpression('count(*)', 'count');
$query2->condition('approved', 1);
$result2 = $query2->execute();
db_set_active('default'); // We need to call the main (drupal) db back
db_set_active();
$completedbookcount = $result2->fetchObject()->count;
$option1 = array(
$foss_detail->foss_name,
(int) $completedbookcount
);
array_push($rows, $option1);
}
}
}
}
else {
$query = db_select('foss_type');
$query->fields('foss_type', array(
'id'
));
$query->fields('foss_type', array(
'foss_name'
));
$query->fields('foss_type', array(
'lab_migration'
));
$query->condition('lab_migration', 1);
$result = $query->execute();
while ($foss_detail = $result->fetchObject()) {
if ($foss_detail->foss_name != NULL) {
db_set_active($foss_detail->foss_name); //Active other database
//For LM
$query3 = db_select('lab_migration_proposal');
$query3->addExpression('count(*)', 'count');
$query3->condition('approval_status', 3);
$result3 = $query3->execute();
db_set_active('default'); // We need to call the main (drupal) db back
db_set_active();
$completedlabcount = $result3->fetchObject()->count;
$option1 = array(
$foss_detail->foss_name,
(int) $completedlabcount
);
array_push($rows, $option1);
}
}
}
return $rows;
}
//This function is used to get list of TBC books/LM Labs after the filter is applied
function list_tbc_and_lm_detail($String, $foss_type, $sub_type, $status, $startdate, $enddate, $countryname, $statename, $cityname) {
if ($cityname == "" || $cityname == "null") {
$cityname = "%";
}
else {
$cityname = $cityname;
}
if ($statename == "" || $statename == "null") {
$statename = "%";
}
else {
$statename = $statename;
}
if ($countryname == "" || $countryname == "null") {
$countryname = "%";
}
else {
$countryname = $countryname;
}
$flag = 1;
$page_content = "";
db_set_active($foss_type);
$query2 = "";
if ($sub_type == "TBC") {
if ($foss_type != NULL) {
if ($foss_type != 'Python') {
//For TBC
if ($foss_type != 'eSim' && $foss_type != 'OpenModelica' && $foss_type != 'OpenFOAM' && $foss_type != 'OR-Tools' && $foss_type != 'R') {
if ($foss_type != 'DWSIM') {
if ($status == "completed") {
$query2 = db_query("SELECT pe.book as book,pe.author as author,pe.publisher as publisher,pe.year as year,pe.id as id FROM {textbook_companion_preference} pe LEFT JOIN {textbook_companion_proposal} po ON pe.proposal_id = po.id WHERE po.proposal_status =3 AND pe.approval_status =1 AND pe.category>0 AND po.city LIKE :city AND po.state LIKE :state AND po.country LIKE :country AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate", array(
':city' => $cityname,
':state' => $statename,
':country' => $countryname,
':startdate' => $startdate,
':enddate' => $enddate
));
}
if ($status == "pending") {
/* For setting completion date for pending TBC and LM more */
$pending_enddate = date('Y-m-d', strtotime("+5 months", strtotime( $enddate)));
$query2 = db_query("SELECT pe.book,pe.author,pe.publisher,pe.year,pe.id FROM {textbook_companion_preference} pe LEFT JOIN {textbook_companion_proposal} po ON pe.proposal_id = po.id WHERE po.proposal_status <> 3 AND pe.approval_status =1 AND pe.category>0 AND po.city LIKE :city AND po.state LIKE :state AND po.country LIKE :country AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate", array(
':city' => $cityname,
':state' => $statename,
':country' => $countryname,
':startdate' => $startdate,
':enddate' => $pending_enddate
));
$flag = 0;
}
}
else {
if ($status == "completed") {
$query2 = db_query("SELECT pe.book,pe.author,pe.publisher,pe.year,pe.id FROM {textbook_companion_preference} pe LEFT JOIN {textbook_companion_proposal} po ON pe.proposal_id = po.id WHERE po.proposal_status =3 AND pe.approval_status =1 AND pe.category>0 AND po.city LIKE :city AND po.state LIKE :state AND po.country LIKE :country AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate ", array(
':city' => $cityname,
':state' => $statename,
':country' => $countryname,
':startdate' => $startdate,
':enddate' => $enddate
));
}
if ($status == "pending") {
/* For setting completion date for pending TBC and LM more */
$pending_enddate = date('Y-m-d', strtotime("+5 months", strtotime( $enddate)));
$query2 = db_query("SELECT pe.book,pe.author,pe.publisher,pe.year,pe.id FROM {textbook_companion_preference} pe LEFT JOIN {textbook_companion_proposal} po ON pe.proposal_id = po.id WHERE po.proposal_status <>3 AND pe.approval_status =1 AND pe.category>0 AND po.city LIKE :city AND po.state LIKE :state AND po.country LIKE :country AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate", array(
':city' => $cityname,
':state' => $statename,
':country' => $countryname,
':startdate' => $startdate,
':enddate' => $pending_enddate
));
$flag = 0;
}
}
}
else {
if ($status == "completed") {
$query2 = db_query("SELECT pe.book,pe.author,pe.publisher,pe.year,pe.id FROM {textbook_companion_preference} pe LEFT JOIN {textbook_companion_proposal} po ON pe.proposal_id = po.id WHERE po.proposal_status =3 AND pe.approval_status =1 AND po.city LIKE :city AND po.state LIKE :state AND po.country LIKE :country AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate", array(
':city' => $cityname,
':state' => $statename,
':country' => $countryname,
':startdate' => $startdate,
':enddate' => $enddate
));
}
if ($status == "pending") {
/* For setting completion date for pending TBC and LM more */
$pending_enddate = date('Y-m-d', strtotime("+5 months", strtotime( $enddate)));
$query2 = db_query("SELECT pe.book,pe.author,pe.publisher,pe.year,pe.id FROM {textbook_companion_preference} pe LEFT JOIN {textbook_companion_proposal} po ON pe.proposal_id = po.id WHERE po.proposal_status <> 3 AND pe.approval_status =1 AND po.city LIKE :city AND po.state LIKE :state AND po.country LIKE :country AND FROM_UNIXTIME(po.completion_date) >= :startdate AND FROM_UNIXTIME(po.completion_date) <= :enddate", array(
':city' => $cityname,
':state' => $statename,
':country' => $countryname,
':startdate' => $startdate,
':enddate' => $pending_enddate
));
$flag = 0;
}
}
}
else {
if ($status == "completed") {
$query2 = db_select('tbc_book', 'tbc');
$query2->fields('tbc', array(
'title',
'author',
'id'
));
$query2->condition('approved', 1);
}
if ($status == "pending") {
$query2 = db_select('tbc_book', 'tbc');
$query2->fields('tbc', array(
'title',
'author',
'id'
));
$query2->condition('approved', 1, '<>');
}
}
}
db_set_active('default'); // We need to call the main (drupal) db back
db_set_active();
if ($flag != 0) {
$page_content .= "<h3>List of Completed Books</h3><br>";
$query = db_select('foss_type');
$query->fields('foss_type', array(
'id'
));
$query->fields('foss_type', array(
'tbc_run'
));
$query->condition('tbc', 1);
$query->condition('foss_name', $foss_type);
$result = $query->execute();
$foss_detail = $result->fetchObject();
$page_content .= "<ol>";
$i = 1;
while ($preference_data = $query2->fetchObject()) {
$page_content .= "<li>";
$page_content .= "<a href=" . $foss_detail->tbc_run . "/" . $preference_data->id . " target='_blank'>" . $preference_data->book . " by " . $preference_data->author . ", " . $preference_data->publisher . ", " . $preference_data->year . "</a>";
$page_content .= "</li>";
}
$page_content .= "</ol>";
}