PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.2
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.2
6.2.2 6.2.1 6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 All 155 releases
mainwp / modules / logs / widgets / widget-log-clients-widget.php

widget-log-clients-widget.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 6.2.2, at modules/logs/widgets/widget-log-clients-widget.php

215 lines 7.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MainWP Logs Widget
4 *
5 * Displays the Logs Info.
6 *
7 * @package MainWP/Dashboard
8 * @version 4.6
9 */
10
11 namespace MainWP\Dashboard\Module\Log;
12
13 use MainWP\Dashboard\MainWP_Utility;
14 use MainWP\Dashboard\MainWP_UI;
15
16 // Exit if accessed directly.
17 if ( ! defined( 'ABSPATH' ) ) {
18 exit;
19 }
20
21 /**
22 * Class Log_Clients_Widget
23 *
24 * Displays the Logs info.
25 */
26 class Log_Clients_Widget {
27
28 /**
29 * Protected static variable to hold the single instance of the class.
30 *
31 * @var mixed Default null
32 */
33 protected static $instance = null;
34
35 /**
36 * Return the single instance of the class.
37 *
38 * @return mixed $instance The single instance of the class.
39 */
40 public static function instance() {
41 if ( is_null( static::$instance ) ) {
42 static::$instance = new self();
43 }
44 return static::$instance;
45 }
46
47
48 /**
49 * Method get_class_name()
50 *
51 * @return string __CLASS__ Class name.
52 */
53 public static function get_class_name() {
54 return __CLASS__;
55 }
56
57 /**
58 * Method render()
59 *
60 * @param array ...$args Widget callback args.
61 * @return mixed render_site_info()
62 */
63 public function render( ...$args ) {
64 $this->render_widget( $args );
65 }
66
67
68 /**
69 * Render client overview Info.
70 *
71 * @param array $args Args data.
72 */
73 public function render_widget( $args ) {
74 $data = is_array( $args ) && ! empty( $args[1][0] ) && is_array( $args[1][0] ) ? $args[1][0] : array();
75 $stats_data = is_array( $data ) && ! empty( $data['stats_data']['client']['clients'] ) ? $data['stats_data']['client']['clients'] : array();
76 if ( ! is_array( $stats_data ) ) {
77 $stats_data = array();
78 }
79
80 $stats_prev_data = is_array( $data ) && ! empty( $data['stats_prev_data']['client']['clients'] ) ? $data['stats_prev_data']['client']['clients'] : array();
81 if ( ! is_array( $stats_prev_data ) ) {
82 $stats_prev_data = array();
83 }
84
85 ?>
86 <div class="mainwp-widget-header">
87 <h2 class="ui header handle-drag">
88 <?php esc_html_e( 'Client Management Activity Summary', 'mainwp' ); ?>
89 <div class="sub header">
90 <?php esc_html_e( 'Quantitative snapshot of client management actions and the total count of all events.', 'mainwp' ); ?>
91 </div>
92 </h2>
93 </div>
94
95 <div class="mainwp-widget-insights-card mainwp-scrolly-overflow">
96 <?php
97 /**
98 * Action: mainwp_logs_widget_top
99 *
100 * Fires at the top of the widget.
101 *
102 * @since 4.6
103 */
104 do_action( 'mainwp_logs_widget_top', 'clients' );
105 ?>
106 <div id="mainwp-message-zone" style="display:none;" class="ui message"></div>
107 <?php
108 MainWP_UI::generate_wp_nonce( 'mainwp-admin-nonce' );
109 if ( ! empty( $data ) ) {
110 $this->render_widget_content( $stats_data, $stats_prev_data );
111 } else {
112 MainWP_UI::render_empty_element_placeholder( __( 'No activity recorded', 'mainwp' ), __( 'Data will appear here once actions are tracked.', 'mainwp' ), '<em data-emoji=":bar_chart:" class="medium"></em>' );
113 }
114 ?>
115 <?php
116 /**
117 * Action: mainwp_logs_widget_bottom
118 *
119 * Fires at the bottom of the widget.
120 *
121 * @since 4.6
122 */
123 do_action( 'mainwp_logs_widget_bottom', 'clients' );
124 ?>
125 </div>
126 <div class="mainwp-widget-footer ui four columns stackable grid">
127 <div class="column">
128 </div>
129 <div class="column">
130 </div>
131 </div>
132 <?php
133 }
134
135 /**
136 * Method render_widget_content()
137 *
138 * @param array $data Stats data.
139 * @param array $prev_data Previous stats data.
140 */
141 public function render_widget_content( $data, $prev_data ) {
142 $columns = array(
143 'created' => esc_html__( 'Created', 'mainwp' ),
144 'updated' => esc_html__( 'Updated', 'mainwp' ),
145 'deleted' => esc_html__( 'Deleted', 'mainwp' ),
146 'suspend' => esc_html__( 'Suspended', 'mainwp' ),
147 'unsuspend' => esc_html__( 'Unsuspended', 'mainwp' ),
148 'lost' => esc_html__( 'Lost', 'mainwp' ),
149 'total_events' => esc_html__( 'Total', 'mainwp' ),
150 );
151 ?>
152 <div class="ui grid">
153 <div class="sixteen wide column">
154 <div class="ui equal width grid">
155 <?php
156 foreach ( $columns as $act => $title ) {
157 Log_Stats::render_stats_info( $data, $act, $title, $prev_data );
158 }
159 ?>
160 </div>
161 </div>
162 <div class="sixteen wide column">
163 <div id="mainwp-module-log-chart-clients-management-wrapper" ></div>
164 <script type="text/javascript">
165 jQuery( document ).ready( function() {
166 let options = {
167 chart: {
168 type: 'bar',
169 height: 350,
170 },
171 plotOptions: {
172 bar: {
173 columnWidth: '60%'
174 }
175 },
176 series: [ {
177 name: 'Events:',
178 data: [
179 <?php
180 foreach ( $columns as $act => $title ) {
181 Log_Stats::render_chart_series( $data, $act, $title, $prev_data );
182 }
183 ?>
184 ],
185 } ],
186 xaxis: {
187 labels: {
188 style: {
189 colors: '#999999',
190 }
191 }
192 },
193 yaxis: {
194 labels: {
195 style: {
196 colors: '#999999',
197 }
198 }
199 },
200 tooltip: {
201 theme: 'dark'
202 },
203 }
204 let clients = new ApexCharts(document.querySelector("#mainwp-module-log-chart-clients-management-wrapper"), options);
205 setTimeout(() => {
206 clients.render();
207 }, 1000);
208 } );
209 </script>
210 </div>
211 </div>
212 <?php
213 }
214 }
215