1: <?php
2:
3: 4: 5:
6: class Quform_Dashboard_Widget
7: {
8: 9: 10:
11: protected $repository;
12:
13: 14: 15:
16: protected $viewFactory;
17:
18: 19: 20:
21: protected $template;
22:
23: 24: 25:
26: protected $options;
27:
28: 29: 30: 31: 32:
33: public function __construct(Quform_Repository $repository, Quform_ViewFactory $viewFactory, Quform_Options $options)
34: {
35: $this->repository = $repository;
36: $this->viewFactory = $viewFactory;
37: $this->options = $options;
38: $this->template = QUFORM_TEMPLATE_PATH . '/admin/dashboard-widget.php';
39: }
40:
41: public function setup()
42: {
43: if (
44: ! $this->options->get('dashboardWidget') ||
45: ! current_user_can('quform_view_entries') ||
46: ! $this->repository->getAllUnreadEntriesCount() > 0
47: ) {
48:
49: return;
50: }
51:
52: wp_enqueue_style('qfb-dashboard', Quform::adminUrl('css/dashboard.min.css'), array(), QUFORM_VERSION);
53: wp_add_dashboard_widget('qfb-dashboard-widget', Quform::getPluginName(), array($this, 'display'));
54: }
55:
56: public function display()
57: {
58: $data = array(
59: 'forms' => $this->repository->getAllFormsWithUnreadEntries()
60: );
61:
62: echo $this->viewFactory->create($this->template, $data)->render();
63: }
64: }
65: