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.3 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 All 156 releases
mainwp / modules / cost-tracker / widgets / widget-cost-tracker-sites-widget.php

widget-cost-tracker-sites-widget.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 6.2.1, at modules/cost-tracker/widgets/widget-cost-tracker-sites-widget.php

220 lines 7.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MainWP Logs Widget
4 *
5 * Displays the Logs Info.
6 *
7 * @package MainWP/Dashboard
8 * @version 4.6
9 */
10
11 namespace MainWP\Dashboard\Module\CostTracker;
12
13 use MainWP\Dashboard\MainWP_Utility;
14 use MainWP\Dashboard\MainWP_UI;
15
16 // Exit if accessed directly.
17 if ( ! defined( 'ABSPATH' ) ) {
18 exit;
19 }
20
21 /**
22 * Class Cost_Tracker_Sites_Widget
23 *
24 * Displays the Logs info.
25 */
26 class Cost_Tracker_Sites_Widget {
27
28 /**
29 * Protected static variable to hold the single instance of the class.
30 *
31 * @var mixed Default null
32 */
33 protected static $instance = null;
34
35 /**
36 * Return the single instance of the class.
37 *
38 * @return mixed $instance The single instance of the class.
39 */
40 public static function instance() {
41 if ( is_null( static::$instance ) ) {
42 static::$instance = new self();
43 }
44 return static::$instance;
45 }
46
47
48 /**
49 * Method callback_render_tasks_client_page_widget().
50 *
51 * Handle callback render tasks client page widget.
52 */
53 public function callback_render_costs_widget() {
54 if ( ! isset( $_GET['page'] ) || 'managesites' !== $_GET['page'] || empty( $_GET['dashboard'] ) ) { //phpcs:ignore -- ok.
55 return;
56 }
57
58 ?>
59 <div class="ui grid mainwp-widget-header">
60 <div class="twelve wide column">
61 <h2 class="ui header handle-drag">
62 <?php esc_html_e( 'Cost Tracker', 'mainwp' ); ?>
63 <div class="sub header"><?php esc_html_e( 'Manage and monitor your expenses', 'mainwp' ); ?></div>
64 </h2>
65 </div>
66 </div>
67 <div class="mainwp-scrolly-overflow">
68 <?php $this->render_costs_tracker_widget_content(); ?>
69 </div>
70 <div class="ui two columns grid mainwp-widget-footer">
71 <div class="left aligned column">
72 <a href="admin.php?page=ManageCostTracker" class="ui mini basic button"><?php esc_html_e( 'Cost Tracker Dashboard', 'mainwp' ); ?></a>
73 </div>
74 </div>
75 <?php
76 }
77
78 /**
79 * Method render_tasks_client_page_widget_content().
80 */
81 public function render_costs_tracker_widget_content() {
82 $site_id = intval( $_GET['dashboard'] ); //phpcs:ignore -- ok.
83 $site_costs = Cost_Tracker_DB::get_instance()->get_all_cost_trackers_by_sites( array( $site_id ) );
84
85 if ( is_array( $site_costs ) ) {
86 $site_costs = current( $site_costs ); // for current site.
87 }
88
89 if ( ! is_array( $site_costs ) ) {
90 $site_costs = array();
91 }
92
93 ?>
94
95 <?php if ( empty( $site_costs ) ) : ?>
96 <?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>' ); ?>
97 <?php else : ?>
98 <table class="ui table" id="mainwp-module-cost-tracker-costs-widget-table">
99 <thead>
100 <tr>
101 <th scope="col" ><?php esc_html_e( 'Product', 'mainwp' ); ?></th> <?php //phpcs:ignore -- to fix WordPress word. ?>
102 <th scope="col" class="collapsing right aligned"><?php esc_html_e( 'Site Cost', 'mainwp' ); ?></th>
103 <th scope="col" class="no-sort collapsing"></th>
104 </tr>
105 </thead>
106 <tbody>
107 <?php
108 if ( ! empty( $site_costs ) ) {
109 $columns = array(
110 'name',
111 'price',
112 'actions',
113 );
114 foreach ( $site_costs as $cost ) {
115 $item = $cost;
116 ?>
117 <tr>
118 <?php
119 foreach ( $columns as $col ) {
120 $row = $this->column_default( $item, $col );
121 echo $row; // phpcs:ignore -- ok.
122 }
123 ?>
124 </tr>
125 <?php
126 }
127 }
128 ?>
129 </tbody>
130 </table>
131 <script type="text/javascript">
132 jQuery( document ).ready( function () {
133
134 jQuery( '#mainwp-module-cost-tracker-costs-widget-table' ).DataTable( {
135 "lengthMenu": [ [5, 10, 25, 50, 100, -1], [5, 10, 25, 50, 100, "All"] ],
136 "stateSave" : true,
137 "order" : [ [1, 'asc'] ],
138 "columnDefs": [ {
139 "targets": 'no-sort',
140 "orderable": false
141 } ],
142 "drawCallback": function () {
143 mainwp_datatable_fix_menu_overflow('#mainwp-module-cost-tracker-costs-widget-table', -60, 5);
144 jQuery( '#mainwp-module-cost-tracker-costs-widget-table .ui.dropdown' ).dropdown();
145 }
146 } );
147 // to prevent events conflict.
148 setTimeout( function () {
149 mainwp_datatable_fix_menu_overflow('#mainwp-module-cost-tracker-costs-widget-table', -60, 5);
150 }, 1000 );
151 } );
152 </script>
153 <?php endif; ?>
154 <?php
155 }
156
157
158 /**
159 * Returns the column content for the provided item and column.
160 *
161 * @param array $item Record data.
162 * @param string $column_name Column name.
163 * @return string $out Output.
164 */
165 public function column_default( $item, $column_name ) {
166 $out = '';
167 $order_val = 0;
168 switch ( $column_name ) {
169 case 'name':
170 $out = esc_html( $item->name );
171 break;
172 case 'price': // for client widget.
173 $array_costs = array(
174 'weekly' => 0,
175 'monthly' => 0,
176 'quarterly' => 0,
177 'yearly' => 0,
178 'lifetime' => 0,
179 );
180
181 if ( 'active' === $item->cost_status ) {
182 $price = 0;
183 if ( 'single_site' === $item->license_type ) {
184 $price = $item->price;
185 } elseif ( 'multi_site' === $item->license_type && ! empty( $item->count_sites ) ) {
186 $price = $item->price / $item->count_sites;
187 }
188 if ( 'lifetime' === $item->type ) {
189 $array_costs['lifetime'] += $price;
190 } elseif ( isset( $array_costs[ $item->renewal_type ] ) ) {
191 $array_costs[ $item->renewal_type ] += $price;
192 }
193 $order_val += $price;
194 }
195 $out = Cost_Tracker_Utility::get_separated_costs_price( $array_costs );
196 break;
197 case 'actions':
198 ob_start();
199 ?>
200 <div class="ui right pointing dropdown" style="z-index: 99;">
201 <i class="ellipsis vertical icon"></i>
202 <div class="menu">
203 <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>
204 </div>
205 </div>
206 <?php
207 $out = ob_get_clean();
208 break;
209 default:
210 }
211
212 if ( 'price' === $column_name ) {
213 $out = '<td data-order="' . esc_attr( $order_val ) . '">' . $out . '</td>';
214 } else {
215 $out = '<td>' . $out . '</td>';
216 }
217 return $out;
218 }
219 }
220