1: <?php
2:
3: 4: 5:
6: class Quform_Admin_Page_Dashboard extends Quform_Admin_Page
7: {
8: 9: 10:
11: protected $options;
12:
13: 14: 15: 16: 17:
18: public function __construct(Quform_ViewFactory $viewFactory, Quform_Repository $repository, Quform_Options $options)
19: {
20: parent::__construct($viewFactory, $repository);
21:
22: $this->options = $options;
23: }
24:
25: public function init()
26: {
27: $this->template = QUFORM_TEMPLATE_PATH . '/admin/dashboard.php';
28: }
29:
30: 31: 32: 33: 34: 35: 36:
37: public function getNavHtml(array $currentForm = null, array $extra = array())
38: {
39: ob_start();
40: ?>
41: <div class="qfb-nav-item qfb-nav-page-info"><i class="qfb-nav-page-icon qfb-mdi qfb-mdi-dashboard"></i><span class="qfb-nav-page-title"><?php esc_html_e('Dashboard', 'quform'); ?></span></div>
42: <?php
43:
44: return parent::getNavHtml($currentForm, array(40 => ob_get_clean()));
45: }
46:
47: 48: 49:
50: public function process()
51: {
52: if ( ! current_user_can('quform_view_dashboard')) {
53: wp_die(__( 'You do not have sufficient permissions to access this page.', 'quform'), 403);
54: }
55:
56: $recentEntries = $this->repository->getRecentEntries(10);
57:
58: $unreadCount = 0;
59:
60: foreach ($recentEntries as $recentEntry) {
61: if ($recentEntry['unread'] == '1') {
62: $unreadCount++;
63: }
64: }
65:
66: $this->view->with(array(
67: 'options' => $this->options,
68: 'forms' => $this->repository->getForms(array('limit' => 9)),
69: 'unreadCount' => $unreadCount,
70: 'recentEntries' => $recentEntries,
71: 'tools' => $this->getTools(),
72: ));
73: }
74:
75: 76: 77: 78: 79:
80: protected function getTools()
81: {
82: $tools = array(
83: 'export.entries' => array(
84: 'title' => __('Export Entries', 'quform'),
85: 'cap' => 'quform_export_entries',
86: 'url' => admin_url('admin.php?page=quform.tools&sp=export.entries'),
87: 'icon' => '<i class="qfb-icon qfb-icon-file-excel-o"></i>'
88: ),
89: 'export.form' => array(
90: 'title' => __('Export Form', 'quform'),
91: 'cap' => 'quform_export_forms',
92: 'url' => admin_url('admin.php?page=quform.tools&sp=export.form'),
93: 'icon' => '<i class="qfb-icon qfb-icon-file-code-o"></i>'
94: ),
95: 'import.form' => array(
96: 'title' => __('Import Form', 'quform'),
97: 'cap' => 'quform_import_forms',
98: 'url' => admin_url('admin.php?page=quform.tools&sp=import.form'),
99: 'icon' => '<i class="qfb-mdi qfb-mdi-playlist_add"></i>'
100: )
101: );
102:
103: foreach ($tools as $key => $tool) {
104: if ( ! current_user_can($tool['cap'])) {
105: unset($tools[$key]);
106: }
107: }
108:
109: return $tools;
110: }
111: }
112: