PluginProbe
WP Directory Kit / 1.2.7
WP Directory Kit v1.2.7
1.5.6 1.5.5 1.5.4 1.5.3 trunk 1.1.0 1.1.6 1.1.8 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.8 1.4.0 1.4.1 All 35 releases
wpdirectorykit / dash-widgets / dash-widgets-statistics-usage.php

dash-widgets-statistics-usage.php in WP Directory Kit 1.2.7, at dash-widgets/dash-widgets-statistics-usage.php

110 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Wdk\DashWidgets\Widgets;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit; // Exit if accessed directly.
6 }
7 class WDK_Dashboard_Widget_Stats_Usage extends WDK_DashWidgets {
8
9 /**
10 * The id of this widget.
11 */
12 static $widget_id = 'wdk_dashboard_widget_stats_usage';
13
14 /**
15 * Hook to wp_dashboard_setup to add the widget.
16 */
17 public static function init() {
18
19 if(!wmvc_user_in_role('administrator') && !is_super_admin()) {
20 return false;
21 }
22
23 //Register widget settings...
24 self::update_dashboard_widget_options(
25 self::$widget_id, //The widget id
26 array( //Associative array of options & default values
27 'example_number' => 42,
28 ),
29 true //Add only (will not update existing options)
30 );
31
32 //Register the widget...
33 wp_add_dashboard_widget(
34 self::$widget_id, //A unique slug/ID
35 __( 'Wdk Usage Stats', 'wpdirectorykit' ),//Visible name for the widget
36 array('Wdk\DashWidgets\Widgets\WDK_Dashboard_Widget_Stats_Usage','widget'), //Callback for the main widget content
37 array('Wdk\DashWidgets\Widgets\WDK_Dashboard_Widget_Stats_Usage','config') //Optional callback for widget configuration content
38 );
39 }
40
41 /**
42 * Load the widget code
43 */
44 public static function widget() {
45
46 $WMVC = &wdk_get_instance();
47 $WMVC->model('listing_m');
48 $WMVC->load_helper('listing');
49
50 $data = array();
51
52 $data['settings'] = array(
53 'conf_limit' => 50,
54 );
55
56 wp_enqueue_style('dash-widgets-statistics-usage');
57
58 /* default from settings */
59 $data['id_element'] = self::$widget_id;
60
61 /* widgets data */
62 $stat_default = array('color' => '', 'class' => '', 'title' => '', 'value' => '', 'icon' => '', 'link' =>'');
63
64 /* count users */
65 $result_count_users = count_users();
66
67 /* Will show number of users */
68 $data['stats']['total_users'] = array('title' => __( 'Users On Portal', 'wpdirectorykit'), 'icon'=>'dashicons dashicons-groups', 'class'=>'nohover');
69 $data['stats']['total_users']['value'] = $result_count_users['total_users'];
70 $data['stats']['total_users'] = array_merge($stat_default, $data['stats']['total_users']);
71
72 /* number of agents */
73 $data['stats']['total_users_agents'] = array('title' => __( 'Agents on Portal', 'wpdirectorykit'), 'class'=>'blue nohover', 'icon'=>'dashicons dashicons-businessperson');
74 $data['stats']['total_users_agents']['value'] = isset($result_count_users['avail_roles']['wdk_agent']) ? $result_count_users['avail_roles']['wdk_agent'] : 0;
75 $data['stats']['total_users_agents'] = array_merge($stat_default, $data['stats']['total_users_agents']);
76
77
78 $WMVC->db->select('COUNT(*) AS total,
79 sum(case when is_activated = 1 then 1 else 0 end) AS activated_count,
80 sum(case when is_activated = 1 then 0 else 1 end) AS inactivated_count');
81 $WMVC->db->from($WMVC->listing_m->_table_name);
82
83 $query = $WMVC->db->get();
84 $count_listings = $WMVC->db->row();
85
86 /* number of active listings */
87 $data['stats']['total_active_listings'] = array('title' => __( 'Active Listings', 'wpdirectorykit' ), 'class'=>'red nohover', 'icon'=>'dashicons dashicons-visibility');
88 $data['stats']['total_active_listings']['value'] = isset($count_listings->activated_count) ? $count_listings->activated_count : 0;
89 $data['stats']['total_active_listings'] = array_merge($stat_default, $data['stats']['total_active_listings']);
90
91
92 /* number of inactive listings */
93 $data['stats']['total_inactive_listings'] = array('title' => __( 'Inactive Listings', 'wpdirectorykit' ), 'class'=>'orange nohover', 'icon'=>'dashicons dashicons-hidden');
94 $data['stats']['total_inactive_listings']['value'] = isset($count_listings->inactivated_count) ? $count_listings->inactivated_count : 0;
95 $data['stats']['total_inactive_listings'] = array_merge($stat_default, $data['stats']['total_inactive_listings']);
96
97 self::view('dash-widgets-statistics-usage', $data, true);
98 }
99
100 /**
101 * Load widget config code.
102 *
103 * This is what will display when an admin clicks
104 */
105 public static function config() {
106 wp_redirect(admin_url("admin.php?page=listing_settings")); exit;
107 }
108
109
110 }