Repository navigation
Expand file tree
/
Copy pathsofttechit.php
More file actions
167 lines (99 loc) · 3.75 KB
/
Copy pathsofttechit.php
File metadata and controls
167 lines (99 loc) · 3.75 KB
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
<?php
/**
* Plugin Name: Soft Tech IT
* Plugin URI: https://softtech-it.com/
* Description: This is a custom chart plugin Develop by softtechit.
* Version: 1.0.0
* Author: jhfahim
* Author URI: https://jhfahim.com/
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: softtechit
* Domain Path: /languages
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
/**
* Enqueue script
*/
function chart_enqueue_script()
{
wp_enqueue_script( 'chart-js', plugin_dir_url( __FILE__ ) . 'assets/js/chart.js', array('jquery'), '1.0.0', true );
wp_enqueue_script( 'my-custom-script', plugin_dir_url( __FILE__ ) . 'assets/js/custom.js',array('jquery'), '1.0.0', true );
wp_localize_script( 'my-custom-script', 'softvar', array(
'home_url' => home_url()
));
}
add_action('admin_enqueue_scripts', 'chart_enqueue_script');
/**
* This template for shortcode
*/
require plugin_dir_path( __FILE__ ) . 'inc/shortcode/deshbord-chart.php';
//add chart in deshboard menu
global $wp_meta_boxes;
add_action('wp_dashboard_setup', 'my_custom_dashboard_widgets');
function my_custom_dashboard_widgets() {
wp_add_dashboard_widget('all_test_widget', 'All Test', 'particular_test_dashboard_display');
wp_add_dashboard_widget('score_widget', 'Test score', 'chart_score_dashboard_display');
wp_add_dashboard_widget('trend_widget', 'Trends Test', 'trends_score_dashboard_display');
wp_add_dashboard_widget('all_test_score_widget', 'Overall Statics', 'all_test_score_dashboard_display');
}
//All test taken by particular account
function particular_test_dashboard_display() {
echo do_shortcode( '[particular-test]' );
global $wpdb, $ipt_fsqm_info;
$submissions = $wpdb->get_results( "SELECT * FROM `wp_fsq_data` ORDER BY `wp_fsq_data`.`user_id` ASC", ARRAY_A );
echo "<pre>";
print_r( $submissions);
echo "</pre>";
}
//All test score by particular account
function chart_score_dashboard_display() {
echo do_shortcode( '[score-chart]' );
}
//trends of number of test taker particular account
function trends_score_dashboard_display() {
echo do_shortcode( '[trend-test-chart]' );
}
//All test taken by all account
function all_test_score_dashboard_display() {
echo do_shortcode( '[all-test-chart]' );
}
add_action('admin_init', function(){
setcookie('current_user', wp_get_current_user()->ID, time() + (86400 * 30));
});
add_action('rest_api_init', function(){
register_rest_route('softtechit/v1', '/tests/', array(
'methods' => 'GET',
'callback' => function(){
global $wpdb, $ipt_fsqm_info;
$forms = $wpdb->get_results( "SELECT id, name FROM {$ipt_fsqm_info['form_table']} ORDER BY id ASC", ARRAY_A );
return $forms;
}
));
register_rest_route('softtechit/v1', '/submissions/', array(
'methods' => 'GET',
'callback' => function(){
global $wpdb, $ipt_fsqm_info;
$submissions = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}fsq_data ORDER BY id ASC", ARRAY_A );
return $submissions;
}
));
register_rest_route('softtechit/v1', '/submissions/data/', array(
'methods' => 'GET',
'callback' => function(){
global $wpdb, $ipt_fsqm_info;
$submissions = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}fsq_data ORDER BY id ASC", ARRAY_A );
$particular_data = array();
foreach($submissions as $submission){
array_push($particular_data,array(
'label' => $submission[''],
'data' => $submission['id'],
));
}
return json_encode($particular_data);
}
));
});