PluginProbe
WP Directory Kit / 1.2.3
WP Directory Kit v1.2.3
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-listings.php

dash-widgets-statistics-listings.php in WP Directory Kit 1.2.3, at dash-widgets/dash-widgets-statistics-listings.php

128 lines 6.0 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_Listings extends WDK_DashWidgets {
8
9 /**
10 * The id of this widget.
11 */
12 static $widget_id = 'wdk_dashboard_widget_stats_listings';
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 Listings Stats', 'wpdirectorykit' ),//Visible name for the widget
36 array('Wdk\DashWidgets\Widgets\WDK_Dashboard_Widget_Stats_Listings','widget'), //Callback for the main widget content
37 array('Wdk\DashWidgets\Widgets\WDK_Dashboard_Widget_Stats_Listings','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-listings');
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 $post_table = $WMVC->db->prefix.'posts';
66 $fields_table = $WMVC->db->prefix.'wdk_listings_fields';
67
68 $WMVC->db->select('COUNT(*) AS total,
69 sum( IF((is_activated = 1 AND is_approved = 1), 1, 0)) AS activated_count,
70 sum(case when is_featured = 1 then 1 else 0 end) AS featured_count,
71 sum(case when is_activated IS NULL then 1 when is_approved IS NULL then 1 else 0 end) AS inactivated_count
72 ');
73 $WMVC->db->from($WMVC->listing_m->_table_name);
74 $WMVC->db->join($post_table.' ON '.$WMVC->listing_m->_table_name.'.post_id = '.$post_table.'.ID');
75 $WMVC->db->join($fields_table.' ON '.$WMVC->listing_m->_table_name.'.post_id = '.$fields_table.'.post_id');
76
77 $query = $WMVC->db->get();
78 $count_listings = $WMVC->db->row();
79
80
81 /* Total Listings*/
82 $data['stats']['total_listings'] = array('title' => __( 'Total Listings', 'wpdirectorykit' ));
83 $data['stats']['total_listings']['value'] = isset($count_listings->total) ? $count_listings->total : 0;
84 $data['stats']['total_listings']['link'] = admin_url('/admin.php?page=wdk');
85 $data['stats']['total_listings'] = array_merge($stat_default, $data['stats']['total_listings']);
86
87 /* number of active listings */
88 $data['stats']['total_active_listings'] = array('title' => __( 'Active Listings', 'wpdirectorykit' ), 'class'=>'red', 'icon'=>'dashicons dashicons-visibility');
89 $data['stats']['total_active_listings']['value'] = isset($count_listings->activated_count) ? $count_listings->activated_count : 0;
90 $data['stats']['total_active_listings']['link'] = admin_url('/admin.php?page=wdk&is_activated=on&is_approved=on');
91 if(isset($_GET['is_activated']) && $_GET['is_activated'] == 'on') {
92 $data['stats']['total_active_listings']['class'] .= ' active';
93 }
94 $data['stats']['total_active_listings'] = array_merge($stat_default, $data['stats']['total_active_listings']);
95
96 /* number of inactive listings */
97 $data['stats']['total_inactive_listings'] = array('title' => __( 'Inactive/Unapproved Listings', 'wpdirectorykit' ), 'class'=>'orange', 'icon'=>'dashicons dashicons-hidden');
98 $data['stats']['total_inactive_listings']['value'] = isset($count_listings->inactivated_count) ? $count_listings->inactivated_count : 0;
99 $data['stats']['total_inactive_listings']['link'] = admin_url('/admin.php?page=wdk&inactive=on');
100 if(isset($_GET['is_activated']) && $_GET['is_activated'] == 'off') {
101 $data['stats']['total_inactive_listings']['class'] .= ' active';
102 }
103 $data['stats']['total_inactive_listings'] = array_merge($stat_default, $data['stats']['total_inactive_listings']);
104
105 /* number of featured listings */
106 $data['stats']['total_featured_listings'] = array('title' => __( 'Featured Listings', 'wpdirectorykit'), 'class'=>'blue', 'icon'=>'dashicons dashicons-superhero-alt');
107 $data['stats']['total_featured_listings']['value'] = isset($count_listings->featured_count) ? $count_listings->featured_count : 0;
108 $data['stats']['total_featured_listings']['link'] = admin_url('/admin.php?page=wdk&is_featured=on');
109 if(isset($_GET['is_featured']) && $_GET['is_featured'] == 'on') {
110 $data['stats']['total_featured_listings']['class'] .= ' active';
111 }
112
113 $data['stats']['total_featured_listings'] = array_merge($stat_default, $data['stats']['total_featured_listings']);
114
115 self::view('dash-widgets-statistics-listings', $data, true);
116 }
117
118 /**
119 * Load widget config code.
120 *
121 * This is what will display when an admin clicks
122 */
123 public static function config() {
124 wp_redirect(admin_url("admin.php?page=listing_settings")); exit;
125 }
126
127
128 }