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 / packages / table.php
vikappointments / site / helpers / libraries / statistics / widgets / dashboard / packages Last commit date
index.html 6 days ago table.php 6 days ago
table.php
144 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 purchased and redeemed packages.
16 *
17 * @since 1.7
18 */
19 class VAPStatisticsWidgetDashboardPackagesTable 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 ordered" table
72 * should be displayed or not.
73 *
74 * @var checkbox
75 */
76 'purchased' => array(
77 'type' => 'checkbox',
78 'label' => JText::translate('VAP_STATS_WIDGET_DASHBOARD_PACKAGES_TABLE_PURCHASED_FIELD'),
79 'help' => JText::translate('VAP_STATS_WIDGET_DASHBOARD_PACKAGES_TABLE_PURCHASED_FIELD_HELP'),
80 'default' => true,
81 ),
82
83 /**
84 * Flag used to check whether the "latest used" table
85 * should be displayed or not.
86 *
87 * @var checkbox
88 */
89 'redeemed' => array(
90 'type' => 'checkbox',
91 'label' => JText::translate('VAP_STATS_WIDGET_DASHBOARD_PACKAGES_TABLE_REDEEMED_FIELD'),
92 'help' => JText::translate('VAP_STATS_WIDGET_DASHBOARD_PACKAGES_TABLE_REDEEMED_FIELD_HELP'),
93 'default' => true,
94 ),
95 );
96 }
97
98 /**
99 * Loads the dataset(s) that will be recovered asynchronously
100 * for being displayed within the widget.
101 *
102 * It is possible to return an array of records to be passed
103 * to a chart or directly the HTML to replace.
104 *
105 * @return mixed
106 */
107 public function getData()
108 {
109 $data = array();
110
111 // get maximum number of items to display
112 $limit = $this->getOption('limit', 5);
113
114 // import dashboard helper
115 VAPLoader::import('libraries.statistics.helpers.dashboard');
116
117 // check whether the latest purchased should be displayed
118 if ($this->getOption('purchased', true))
119 {
120 $data['purchased'] = VAPStatisticsHelperDashboard::getLatestPurchasedPackages($limit);
121 }
122
123 // check whether the latest redeemed packages should be displayed
124 if ($this->getOption('redeemed', true))
125 {
126 $data['redeemed'] = VAPStatisticsHelperDashboard::getLatestUsedPackages($limit);
127 }
128
129 foreach ($data as $layoutId => $rows)
130 {
131 // define args for layout file
132 $args = array(
133 'packages' => $rows,
134 'widget' => $this,
135 );
136
137 // replace packages list with HTML layout
138 $data[$layoutId] = JLayoutHelper::render('statistics.widgets.dashboard.packages.table.' . $layoutId, $args);
139 }
140
141 return $data;
142 }
143 }
144