| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentForm\App\Modules; |
| 4 |
|
| 5 |
use FluentForm\App\Helpers\Helper; |
| 6 |
use FluentForm\App\Models\Submission; |
| 7 |
|
| 8 |
class DashboardWidgetModule |
| 9 |
{ |
| 10 |
public function showStat() |
| 11 |
{ |
| 12 |
global $wpdb; |
| 13 |
$stats = Submission::select([ |
| 14 |
'fluentform_forms.title', |
| 15 |
'fluentform_submissions.form_id', |
| 16 |
wpFluent()->raw('count(' . $wpdb->prefix . 'fluentform_submissions.id) as total'), |
| 17 |
wpFluent()->raw('max(' . $wpdb->prefix . 'fluentform_submissions.id) as max_id'), |
| 18 |
]) |
| 19 |
->orderBy('max_id', 'DESC') |
| 20 |
->groupBy('fluentform_submissions.form_id') |
| 21 |
->join('fluentform_forms', 'fluentform_forms.id', '=', 'fluentform_submissions.form_id') |
| 22 |
->limit(10) |
| 23 |
->get(); |
| 24 |
|
| 25 |
if (!$stats) { |
| 26 |
echo 'You can see your submission stats here'; |
| 27 |
return; |
| 28 |
} |
| 29 |
|
| 30 |
foreach ($stats as $stat) { |
| 31 |
$stat->unreadCount = Helper::unreadCount($stat->form_id); |
| 32 |
} |
| 33 |
|
| 34 |
$this->printStats($stats); |
| 35 |
return; |
| 36 |
} |
| 37 |
|
| 38 |
private function printStats($stats) |
| 39 |
{ |
| 40 |
?> |
| 41 |
<ul class="ff_dashboard_stats"> |
| 42 |
<?php foreach ($stats as $stat): ?> |
| 43 |
<li> |
| 44 |
<a |
| 45 |
href="<?php echo esc_url(admin_url('admin.php?page=fluent_forms&route=entries&form_id=' . $stat->form_id)); ?>"> |
| 46 |
<?php echo esc_html($stat->title); ?> |
| 47 |
<span class="ff_total"><?php echo esc_attr($stat->unreadCount); ?>/<?php echo esc_attr($stat->total); ?></span> |
| 48 |
</a> |
| 49 |
</li> |
| 50 |
<?php endforeach; ?> |
| 51 |
</ul> |
| 52 |
<?php if (!defined('FLUENTCRM') && !defined('FLUENTFORMPRO')) : ?> |
| 53 |
<div class="ff_recommended_plugin"> |
| 54 |
Recommended Plugin: <b>FluentCRM - Email Marketing Automation For WordPress</b> <br /> |
| 55 |
<a |
| 56 |
href="<?php echo esc_url($this->getInstallUrl('fluent-crm')); ?>">Install</a> |
| 57 |
| <a target="_blank" rel="noopener" href="https://wordpress.org/plugins/fluent-crm/">Learn More</a> |
| 58 |
</div> |
| 59 |
<?php endif; ?> |
| 60 |
<style> |
| 61 |
ul.ff_dashboard_stats { |
| 62 |
margin: 0; |
| 63 |
padding: 0; |
| 64 |
list-style: none; |
| 65 |
} |
| 66 |
|
| 67 |
ul.ff_dashboard_stats li { |
| 68 |
padding: 8px 12px; |
| 69 |
border-bottom: 1px solid #eeeeee; |
| 70 |
margin: 0 -12px; |
| 71 |
cursor: pointer; |
| 72 |
} |
| 73 |
|
| 74 |
ul.ff_dashboard_stats li:hover { |
| 75 |
background: #fafafa; |
| 76 |
border-bottom: 1px solid #eeeeee; |
| 77 |
} |
| 78 |
|
| 79 |
ul.ff_dashboard_stats li:hover a { |
| 80 |
color: black; |
| 81 |
} |
| 82 |
|
| 83 |
ul.ff_dashboard_stats li:nth-child(2n+2) { |
| 84 |
background: #f9f9f9; |
| 85 |
} |
| 86 |
|
| 87 |
ul.ff_dashboard_stats li span.ff_total { |
| 88 |
float: right; |
| 89 |
} |
| 90 |
|
| 91 |
ul.ff_dashboard_stats li a { |
| 92 |
display: block; |
| 93 |
color: #0073aa; |
| 94 |
font-weight: 500; |
| 95 |
font-size: 105%; |
| 96 |
} |
| 97 |
|
| 98 |
.ff_recommended_plugin { |
| 99 |
padding: 15px 0px 0px; |
| 100 |
} |
| 101 |
|
| 102 |
.ff_recommended_plugin a { |
| 103 |
font-weight: bold; |
| 104 |
font-size: 110%; |
| 105 |
} |
| 106 |
</style> |
| 107 |
<?php |
| 108 |
} |
| 109 |
|
| 110 |
private function getInstallUrl($plugin) |
| 111 |
{ |
| 112 |
return wp_nonce_url( |
| 113 |
self_admin_url('update.php?action=install-plugin&plugin=' . $plugin), |
| 114 |
'install-plugin_' . $plugin |
| 115 |
); |
| 116 |
} |
| 117 |
} |
| 118 |
|