PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.1
6.2.2 6.2.1 6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 All 155 releases
← All changes | modules/cost-tracker/widgets/widget-cost-tracker-clients-widget.php +238 -212 5.0 → 6.2.1 View file →
@@ -1,9 +1,9 @@
1 1 <?php
2 2 /**
3 - * MainWP Logs Widget
3 + * MainWP Cost Tracker Clients Widget
4 4 *
5 - * Displays the Logs Info.
5 + * Displays the Clients's Cost Tracker Info.
6 6 *
7 7 * @package MainWP/Dashboard
8 8 * @version 4.6
9 9 */
@@ -11,238 +11,264 @@
11 11 namespace MainWP\Dashboard\Module\CostTracker;
12 12
13 13 use MainWP\Dashboard\MainWP_DB_Client;
14 14 use MainWP\Dashboard\MainWP_Utility;
15 +use MainWP\Dashboard\MainWP_UI;
15 16
17 +// Exit if accessed directly.
18 +if ( ! defined( 'ABSPATH' ) ) {
19 + exit;
20 +}
21 +
16 22 /**
17 - * Class MainWP_Time_Tracker_Tasks_Widget
23 + * Class Cost_Tracker_Clients_Widget
18 24 */
19 25 class Cost_Tracker_Clients_Widget {
20 26
21 - /**
22 - * Public static variable to hold the single instance of class.
23 - *
24 - * @var mixed Default null
25 - */
26 - public static $instance = null;
27 + /**
28 + * Public static variable to hold the single instance of class.
29 + *
30 + * @var mixed Default null
31 + */
32 + public static $instance = null;
27 33
28 - /**
29 - * Public static variable to hold the clients costs.
30 - *
31 - * @var mixed Default array().
32 - */
33 - public $clients_sites = array();
34 + /**
35 + * Public static variable to hold the clients costs.
36 + *
37 + * @var mixed Default array().
38 + */
39 + public $clients_sites = array();
34 40
35 - /**
36 - * Method instance().
37 - *
38 - * Get instance class.
39 - */
40 - public static function instance() {
41 - if ( null === self::$instance ) {
42 - self::$instance = new self();
43 - }
44 - return self::$instance;
45 - }
41 + /**
42 + * Method instance().
43 + *
44 + * Get instance class.
45 + */
46 + public static function instance() {
47 + if ( null === static::$instance ) {
48 + static::$instance = new self();
49 + }
50 + return static::$instance;
51 + }
46 52
47 - /**
48 - * Constructor class.
49 - *
50 - * @return void
51 - */
52 - public function __construct() {
53 - // todo.
54 - }
53 + /**
54 + * Constructor class.
55 + *
56 + * @return void
57 + */
58 + public function __construct() {
59 + // construct.
60 + }
55 61
56 62
57 - /**
58 - * Method callback_render_tasks_client_page_widget().
59 - *
60 - * Handle callback render tasks client page widget.
61 - */
62 - public function callback_render_costs_widget() {
63 - if ( ! isset( $_GET['page'] ) || 'ManageClients' !== $_GET['page'] || empty( $_GET['client_id'] ) ) { //phpcs:ignore -- ok.
64 - return;
65 - }
63 + /**
64 + * Method callback_render_tasks_client_page_widget().
65 + *
66 + * Handle callback render tasks client page widget.
67 + */
68 + public function callback_render_costs_widget() {
69 + if ( ! isset( $_GET['page'] ) || 'ManageClients' !== $_GET['page'] || empty( $_GET['client_id'] ) ) { //phpcs:ignore -- ok.
70 + return;
71 + }
66 72
67 - ?>
68 - <div class="ui grid mainwp-widget-header">
69 - <div class="twelve wide column">
70 - <h3 class="ui header handle-drag">
71 - <?php esc_html_e( 'Cost Tracker', 'mainwp' ); ?>
72 - <div class="sub header"><?php esc_html_e( 'Manage and monitor your expenses.', 'mainwp' ); ?></div>
73 - </h3>
74 - </div>
75 - </div>
76 - <div class="mainwp-scrolly-overflow">
77 - <?php $this->render_costs_tracker_widget_content(); ?>
78 - </div>
79 - <div class="ui two columns grid mainwp-widget-footer">
80 - <div class="left aligned column">
81 - <a href="admin.php?page=ManageCostTracker" class="ui basic green mini fluid button"><?php esc_html_e( 'Cost Tracker Dashboard', 'mainwp' ); ?></a>
82 - </div>
83 - </div>
84 - <?php
85 - }
73 + ?>
74 + <div class="ui grid mainwp-widget-header">
75 + <div class="twelve wide column">
76 + <h2 class="ui header handle-drag">
77 + <?php esc_html_e( 'Cost Tracker', 'mainwp' ); ?>
78 + <div class="sub header"><?php esc_html_e( 'Manage and monitor your expenses.', 'mainwp' ); ?></div>
79 + </h2>
80 + </div>
81 + </div>
82 + <div class="mainwp-scrolly-overflow">
83 + <?php $this->render_costs_tracker_widget_content(); ?>
84 + </div>
85 + <div class="ui two columns grid mainwp-widget-footer">
86 + <div class="left aligned column">
87 + <a href="admin.php?page=ManageCostTracker" class="ui basic mini button"><?php esc_html_e( 'Cost Tracker Dashboard', 'mainwp' ); ?></a>
88 + </div>
89 + </div>
90 + <?php
91 + }
86 92
87 93
88 - /**
89 - * Method render_tasks_client_page_widget_content().
90 - */
91 - public function render_costs_tracker_widget_content() {
92 - $client_id = intval( $_GET['client_id'] ); //phpcs:ignore -- ok.
94 + /**
95 + * Method render_tasks_client_page_widget_content().
96 + */
97 + public function render_costs_tracker_widget_content() { // phpcs:ignore -- NOSONAR - complex method.
98 + $client_id = intval( $_GET['client_id'] ); //phpcs:ignore -- ok.
93 99
94 - $this->clients_sites = array();
95 - // get all sites of the $client_id.
96 - $cls_sites = MainWP_DB_Client::instance()->get_websites_by_client_ids( array( $client_id ) );
97 - if ( is_array( $cls_sites ) ) {
98 - foreach ( $cls_sites as $cls_site ) {
99 - if ( ! empty( $cls_site->client_id ) && ! isset( $this->clients_sites[ $cls_site->client_id ] ) ) {
100 - $this->clients_sites[ $cls_site->client_id ] = array();
101 - }
102 - $this->clients_sites[ $cls_site->client_id ][] = $cls_site->id;
103 - }
104 - }
100 + $this->clients_sites = array();
101 + // get all sites of the $client_id.
102 + $cls_sites = MainWP_DB_Client::instance()->get_websites_by_client_ids( array( $client_id ) );
103 + if ( is_array( $cls_sites ) ) {
104 + foreach ( $cls_sites as $cls_site ) {
105 + if ( ! empty( $cls_site->client_id ) && ! isset( $this->clients_sites[ $cls_site->client_id ] ) ) {
106 + $this->clients_sites[ $cls_site->client_id ] = array();
107 + }
108 + $this->clients_sites[ $cls_site->client_id ][] = $cls_site->id;
109 + }
110 + }
105 111
106 - $client_costs = Cost_Tracker_DB::get_instance()->get_cost_tracker_info_of_clients( array( $client_id ), array( 'with_sites' => true ) );
112 + $client_costs = Cost_Tracker_DB::get_instance()->get_all_cost_trackers_by_clients( array( $client_id ), array( 'get_cost_sites' => true ) );
107 113
108 - if ( is_array( $client_costs ) ) {
109 - $client_costs = current( $client_costs ); // for current client.
110 - }
114 + if ( is_array( $client_costs ) ) {
115 + $client_costs = current( $client_costs ); // for current client.
116 + }
111 117
112 - if ( ! is_array( $client_costs ) ) {
113 - $client_costs = array();
114 - }
118 + if ( ! is_array( $client_costs ) ) {
119 + $client_costs = array();
120 + }
115 121
116 - ?>
117 - <table class="ui table" id="mainwp-module-cost-tracker-costs-widget-table">
118 - <thead>
119 - <tr>
120 - <th><?php esc_html_e( 'Product', 'mainwp' ); ?></th> <?php //phpcs:ignore -- to fix WordPress word. ?>
121 - <th class="collapsing center aligned"><?php esc_html_e( 'Client Sites', 'mainwp' ); ?></th>
122 - <th class="collapsing right aligned"><?php esc_html_e( 'Cost', 'mainwp' ); ?></th>
123 - <th class="no-sort collapsing"></th>
124 - </tr>
125 - </thead>
126 - <tbody>
127 - <?php
128 - if ( ! empty( $client_costs ) ) {
129 - $columns = array(
130 - 'name',
131 - 'number_sites',
132 - 'price',
133 - 'actions',
134 - );
135 - foreach ( $client_costs as $cost ) {
136 - $item = $cost;
137 - ?>
138 - <tr>
139 - <?php
140 - foreach ( $columns as $col ) {
141 - $row = $this->column_default( $item, $col, $client_id );
142 - echo $row; // phpcs:ignore -- ok.
143 - }
144 - ?>
145 - </tr>
146 - <?php
147 - }
148 - }
149 - ?>
150 - </tbody>
151 - </table>
152 - <script type="text/javascript">
153 - jQuery( document ).ready( function () {
154 - jQuery( '#mainwp-module-cost-tracker-costs-widget-table' ).DataTable( {
155 - "lengthMenu": [ [5, 10, 25, 50, 100, -1], [5, 10, 25, 50, 100, "All"] ],
156 - "stateSave" : true,
157 - "order" : [ [1, 'asc'] ],
158 - "columnDefs": [ {
159 - "targets": 'no-sort',
160 - "orderable": false
161 - } ],
162 - "drawCallback": function () {
163 - mainwp_datatable_fix_menu_overflow('#mainwp-module-cost-tracker-costs-widget-table', -60, 5);
164 - jQuery( '#mainwp-module-cost-tracker-costs-widget-table .ui.dropdown' ).dropdown();
165 - }
166 - } );
167 - // to prevent events conflict.
168 - setTimeout( function () {
169 - mainwp_datatable_fix_menu_overflow('#mainwp-module-cost-tracker-costs-widget-table', -60, 5);
170 - }, 1000 );
171 - } );
172 - </script>
173 - <?php
174 - }
122 + ?>
123 + <?php if ( empty( $client_costs ) ) : ?>
124 + <?php MainWP_UI::render_empty_element_placeholder( __( 'No Costs Added', 'mainwp' ), __( 'Add your costs to track upcoming payments.', 'mainwp' ), '<em data-emoji=":calendar_spiral:" class="medium"></em>' ); ?>
125 + <?php else : ?>
126 + <table class="ui table" id="mainwp-module-cost-tracker-costs-widget-table">
127 + <thead>
128 + <tr>
129 + <th scope="col" ><?php esc_html_e( 'Product', 'mainwp' ); ?></th> <?php //phpcs:ignore -- to fix WordPress word. ?>
130 + <th scope="col" class="collapsing center aligned"><?php esc_html_e( 'Client Sites', 'mainwp' ); ?></th>
131 + <th scope="col" class="collapsing right aligned"><?php esc_html_e( 'Cost', 'mainwp' ); ?></th>
132 + <th scope="col" class="no-sort collapsing"></th>
133 + </tr>
134 + </thead>
135 + <tbody>
136 + <?php
137 + if ( ! empty( $client_costs ) ) {
138 + $columns = array(
139 + 'name',
140 + 'number_sites',
141 + 'price',
142 + 'actions',
143 + );
144 + foreach ( $client_costs as $cost ) {
145 + $item = $cost;
146 + ?>
147 + <tr>
148 + <?php
149 + foreach ( $columns as $col ) {
150 + $row = $this->column_default( $item, $col, $client_id );
151 + echo $row; // phpcs:ignore -- ok.
152 + }
153 + ?>
154 + </tr>
155 + <?php
156 + }
157 + }
158 + ?>
159 + </tbody>
160 + </table>
161 + <script type="text/javascript">
162 + jQuery( document ).ready( function () {
163 + jQuery( '#mainwp-module-cost-tracker-costs-widget-table' ).DataTable( {
164 + "lengthMenu": [ [5, 10, 25, 50, 100, -1], [5, 10, 25, 50, 100, "All"] ],
165 + "stateSave" : true,
166 + "info": false,
167 + "layout": {
168 + "bottom": 'paging',
169 + "bottomStart": null,
170 + "bottomEnd": null
171 + },
172 + "order" : [ [1, 'asc'] ],
173 + "columnDefs": [ {
174 + "targets": 'no-sort',
175 + "orderable": false
176 + } ],
177 + "drawCallback": function () {
178 + mainwp_datatable_fix_menu_overflow('#mainwp-module-cost-tracker-costs-widget-table', -60, 5);
179 + jQuery( '#mainwp-module-cost-tracker-costs-widget-table .ui.dropdown' ).dropdown();
180 + },
181 + stateSaveParams: function (settings, data) {
182 + data._mwpv = mainwpParams.mainwpVersion || 'dev';
183 + },
184 + stateLoadParams: function (settings, data) {
185 + if ((mainwpParams.mainwpVersion || 'dev') !== data._mwpv) return false;
186 + },
187 + search: { regex: false, smart: false },
188 + orderMulti: false,
189 + searchDelay: 350
190 + } );
191 + // to prevent events conflict.
192 + setTimeout( function () {
193 + mainwp_datatable_fix_menu_overflow('#mainwp-module-cost-tracker-costs-widget-table', -60, 5);
194 + }, 1000 );
195 + } );
196 + </script>
197 + <?php endif; ?>
198 + <?php
199 + }
175 200
176 201
177 - /**
178 - * Returns the column content for the provided item and column.
179 - *
180 - * @param array $item Record data.
181 - * @param string $column_name Column name.
182 - * @param int $client_id Client id.
183 - *
184 - * @return string $out Output.
185 - */
186 - public function column_default( $item, $column_name, $client_id ) {
187 - $out = '';
202 + /**
203 + * Returns the column content for the provided item and column.
204 + *
205 + * @param array $item Record data.
206 + * @param string $column_name Column name.
207 + * @param int $client_id Client id.
208 + *
209 + * @return string $out Output.
210 + */
211 + public function column_default( $item, $column_name, $client_id ) { //phpcs:ignore -- NOSONAR - complex.
212 + $out = '';
188 213
189 - $order_val = 0;
190 - switch ( $column_name ) {
191 - case 'name':
192 - $out = esc_html( $item->name );
193 - break;
194 - case 'number_sites': // for client widget.
195 - $out = property_exists( $item, 'number_client_costs_sites' ) && is_array( $item->number_client_costs_sites ) ? count( $item->number_client_costs_sites ) : 0;
196 - break;
197 - case 'price': // for client widget.
198 - $array_costs = array(
199 - 'weekly' => 0,
200 - 'monthly' => 0,
201 - 'quarterly' => 0,
202 - 'yearly' => 0,
203 - );
214 + $order_val = 0;
215 + switch ( $column_name ) {
216 + case 'name':
217 + $out = esc_html( $item->name );
218 + break;
219 + case 'number_sites': // for client widget.
220 + $out = property_exists( $item, 'number_client_costs_sites' ) && is_array( $item->number_client_costs_sites ) ? count( $item->number_client_costs_sites ) : 0;
221 + break;
222 + case 'price': // for client widget.
223 + $array_costs = array(
224 + 'weekly' => 0,
225 + 'monthly' => 0,
226 + 'quarterly' => 0,
227 + 'yearly' => 0,
228 + 'lifetime' => 0,
229 + );
204 230
205 - if ( 'active' === $item->cost_status ) {
206 - if ( is_array( $item->cost_sites_ids ) ) {
207 - foreach ( $item->cost_sites_ids as $ct_siteid ) {
208 - // if site of cost tracker in the client's sites then calculate the site's cost/price.
209 - if ( is_array( $this->clients_sites[ $client_id ] ) && in_array( $ct_siteid, $this->clients_sites[ $client_id ] ) ) {
210 - $cost_val = 0;
211 - if ( 'single_site' === $item->license_type ) {
212 - $cost_val = $item->price;
213 - } elseif ( 'multi_site' === $item->license_type && ! empty( $item->count_sites ) ) {
214 - $cost_val = $item->price / $item->count_sites;
215 - }
216 - if ( isset( $array_costs[ $item->renewal_type ] ) ) {
217 - $array_costs[ $item->renewal_type ] += $cost_val;
218 - }
219 - $order_val += $cost_val;
220 - }
221 - }
222 - }
223 - }
224 - $out = Cost_Tracker_Utility::get_separated_costs_price( $array_costs );
225 - break;
226 - case 'actions':
227 - ob_start();
228 - ?>
229 - <div class="ui right pointing dropdown icon mini basic green button not-auto-init" style="z-index: 999;">
230 - <i class="ellipsis horizontal icon"></i>
231 - <div class="menu">
232 - <a class="item widget-row-cost-tracker-edit-cost" href="admin.php?page=CostTrackerAdd&id=<?php echo intval( $item->id ); ?>"><?php esc_html_e( 'Edit', 'mainwp' ); ?></a>
233 - </div>
234 - </div>
235 - <?php
236 - $out = ob_get_clean();
237 - break;
238 - default:
239 - }
231 + if ( 'active' === $item->cost_status && is_array( $item->cost_sites_ids ) ) {
232 + foreach ( $item->cost_sites_ids as $ct_siteid ) {
233 + // if site of cost tracker in the client's sites then calculate the site's cost/price.
234 + if ( is_array( $this->clients_sites[ $client_id ] ) && in_array( $ct_siteid, $this->clients_sites[ $client_id ] ) ) {
235 + $cost_val = 0;
236 + if ( 'single_site' === $item->license_type ) {
237 + $cost_val = $item->price;
238 + } elseif ( 'multi_site' === $item->license_type && ! empty( $item->count_sites ) ) {
239 + $cost_val = $item->price / $item->count_sites;
240 + }
241 + if ( 'lifetime' === $item->type ) {
242 + $array_costs['lifetime'] += $cost_val;
243 + } elseif ( isset( $array_costs[ $item->renewal_type ] ) ) {
244 + $array_costs[ $item->renewal_type ] += $cost_val;
245 + }
246 + $order_val += $cost_val;
247 + }
248 + }
249 + }
250 + $out = Cost_Tracker_Utility::get_separated_costs_price( $array_costs );
251 + break;
252 + case 'actions':
253 + ob_start();
254 + ?>
255 + <div class="ui right pointing dropdown not-auto-init" style="z-index: 99;">
256 + <i class="ellipsis vertical icon"></i>
257 + <div class="menu">
258 + <a class="item widget-row-cost-tracker-edit-cost" href="admin.php?page=CostTrackerAdd&id=<?php echo intval( $item->id ); ?>"><?php esc_html_e( 'Edit', 'mainwp' ); ?></a>
259 + </div>
260 + </div>
261 + <?php
262 + $out = ob_get_clean();
263 + break;
264 + default:
265 + }
240 266
241 - if ( 'price' === $column_name ) {
242 - $out = '<td data-order="' . esc_attr( $order_val ) . '">' . $out . '</td>';
243 - } else {
244 - $out = '<td>' . $out . '</td>';
245 - }
246 - return $out;
247 - }
267 + if ( 'price' === $column_name ) {
268 + $out = '<td data-order="' . esc_attr( $order_val ) . '">' . $out . '</td>';
269 + } else {
270 + $out = '<td>' . $out . '</td>';
271 + }
272 + return $out;
273 + }
248 274 }