PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.21
VikAppointments Services Booking Calendar v1.2.21
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / site / helpers / libraries / statistics / widgets / dashboard / appointments / table.php
vikappointments / site / helpers / libraries / statistics / widgets / dashboard / appointments Last commit date
calendar.php 6 days ago index.html 6 days ago table.php 6 days ago
table.php
165 lines
1 <?php
2 /**
3 * @package VikAppointments
4 * @subpackage core
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 /**
15 * Widget used to fetch the latest registered appointments and the next incoming ones.
16 *
17 * @since 1.7
18 */
19 class VAPStatisticsWidgetDashboardAppointmentsTable extends VAPStatisticsWidget
20 {
21 /**
22 * Checks whether the specified group is supported by the widget.
23 *
24 * @param string $group The group to check.
25 *
26 * @return boolean True if supported, false otherwise.
27 */
28 public function isSupported($group)
29 {
30 return empty($group) || $group == '*' || $group == 'dashboard';
31 }
32
33 /**
34 * Checks whether the specified user is capable to access this widget.
35 *
36 * @param JUser $user The user instance.
37 *
38 * @return boolean True if capable, false otherwise.
39 */
40 public function checkPermissions($user)
41 {
42 return $user->authorise('core.access.dashboard', 'com_vikappointments');
43 }
44
45 /**
46 * Override this method to return a configuration form of the widget.
47 *
48 * @return array
49 */
50 public function getForm()
51 {
52 return array(
53 /**
54 * The maximum number of items to load.
55 *
56 * @var select
57 */
58 'limit' => array(
59 'type' => 'select',
60 'label' => JText::translate('VAPMANAGECONFIG80'),
61 'default' => 5,
62 'options' => array(
63 5,
64 10,
65 15,
66 20,
67 ),
68 ),
69
70 /**
71 * Flag used to check whether the "latest" table
72 * should be displayed or not.
73 *
74 * @var checkbox
75 */
76 'latest' => array(
77 'type' => 'checkbox',
78 'label' => JText::translate('VAP_STATS_WIDGET_DASHBOARD_APPOINTMENTS_TABLE_LATEST_FIELD'),
79 'help' => JText::translate('VAP_STATS_WIDGET_DASHBOARD_APPOINTMENTS_TABLE_LATEST_FIELD_HELP'),
80 'default' => true,
81 ),
82
83 /**
84 * Flag used to check whether the "incoming" table
85 * should be displayed or not.
86 *
87 * @var checkbox
88 */
89 'incoming' => array(
90 'type' => 'checkbox',
91 'label' => JText::translate('VAP_STATS_WIDGET_DASHBOARD_APPOINTMENTS_TABLE_INCOMING_FIELD'),
92 'help' => JText::translate('VAP_STATS_WIDGET_DASHBOARD_APPOINTMENTS_TABLE_INCOMING_FIELD_HELP'),
93 'default' => true,
94 ),
95
96 /**
97 * Flag used to check whether the "current" table
98 * should be displayed or not.
99 *
100 * @var checkbox
101 */
102 'current' => array(
103 'type' => 'checkbox',
104 'label' => JText::translate('VAP_STATS_WIDGET_DASHBOARD_APPOINTMENTS_TABLE_CURRENT_FIELD'),
105 'help' => JText::translate('VAP_STATS_WIDGET_DASHBOARD_APPOINTMENTS_TABLE_CURRENT_FIELD_HELP'),
106 'default' => true,
107 ),
108 );
109 }
110
111 /**
112 * Loads the dataset(s) that will be recovered asynchronously
113 * for being displayed within the widget.
114 *
115 * It is possible to return an array of records to be passed
116 * to a chart or directly the HTML to replace.
117 *
118 * @return mixed
119 */
120 public function getData()
121 {
122 $data = array();
123
124 // get maximum number of items to display
125 $limit = $this->getOption('limit', 5);
126
127 // import dashboard helper
128 VAPLoader::import('libraries.statistics.helpers.dashboard');
129
130 // check whether the latest registered appointments should be displayed
131 if ($this->getOption('latest', true))
132 {
133 $data['latest'] = VAPStatisticsHelperDashboard::getLatestAppointments($limit);
134 }
135
136 // check whether the incoming appointments should be displayed
137 if ($this->getOption('incoming', true))
138 {
139 $data['incoming'] = VAPStatisticsHelperDashboard::getIncomingAppointments($limit);
140 }
141
142 // check whether the current appointments should be displayed
143 if ($this->getOption('current', true))
144 {
145 $data['current'] = VAPStatisticsHelperDashboard::getCurrentAppointments($limit);
146 }
147
148 foreach ($data as $layoutId => $rows)
149 {
150 // define args for layout file
151 $args = array(
152 'appointments' => $rows,
153 'widget' => $this,
154 'layout' => $layoutId,
155 );
156
157 // Replace appointments list with HTML layout.
158 // Use "latest" layout for both the tabs because they are almost equals.
159 $data[$layoutId] = JLayoutHelper::render('statistics.widgets.dashboard.appointments.table.latest', $args);
160 }
161
162 return $data;
163 }
164 }
165