Skip to content

Commit 47eec52

Browse files
authored
Merge pull request #1105 from shreesh-webkul/gli-2120
Added: Option for modules to manipulate KPI data
2 parents 5abde78 + 54f857d commit 47eec52

11 files changed

+197
-190
lines changed

classes/controller/AdminController.php

+21
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,9 @@ class AdminControllerCore extends Controller
320320
/** @var string */
321321
protected $display;
322322

323+
/** @var array */
324+
public $kpis = array();
325+
323326
/** @var bool */
324327
protected $_includeContainer = true;
325328

@@ -2682,6 +2685,24 @@ public function getTemplateFormVars()
26822685

26832686
public function renderKpis()
26842687
{
2688+
Hook::exec('action'.$this->controller_name.'KPIListingModifier', array(
2689+
'kpis' => &$this->kpis,
2690+
));
2691+
2692+
if (count($this->kpis)) {
2693+
foreach ($this->kpis as $key => &$kpi) {
2694+
if (count($kpi->exclude_id_hotels)) {
2695+
if (empty($kpi->id_hotels)) {
2696+
$kpi->id_hotels = HotelBranchInformation::getProfileAccessedHotels($this->context->employee->id_profile, 1, 1);
2697+
}
2698+
$kpi->id_hotels = array_diff($kpi->id_hotels, $kpi->exclude_id_hotels);
2699+
}
2700+
}
2701+
2702+
$helper = new HelperKpiRow();
2703+
$helper->kpis = $this->kpis;
2704+
return $helper->generate();
2705+
}
26852706
}
26862707

26872708
/**

classes/helper/HelperKpi.php

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class HelperKpiCore extends Helper
3838
public $value;
3939
public $data;
4040
public $source;
41+
public $id_hotels = false;
42+
public $exclude_id_hotels = array();
4143
public $href;
4244
public $target;
4345
public $tooltip;
@@ -57,6 +59,8 @@ public function generate()
5759
'value' => $this->value,
5860
'data' => $this->data,
5961
'source' => $this->source,
62+
'id_hotels' => $this->id_hotels,
63+
'exclude_id_hotels' => $this->exclude_id_hotels,
6064
'href' => $this->href,
6165
'target' => $this->target,
6266
'tooltip' => $this->tooltip,

controllers/admin/AdminCartsController.php

+5-11
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public function renderKpis()
197197
$helper->data = ConfigurationKPI::get('CONVERSION_RATE_CHART');
198198
}
199199
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=conversion_rate';
200-
$kpis[] = $helper;
200+
$this->kpis[] = $helper;
201201

202202
$helper = new HelperKpi();
203203
$helper->id = 'box-carts';
@@ -209,7 +209,7 @@ public function renderKpis()
209209
$helper->subtitle = sprintf($this->l('From %s to %s', null, null, false), $date_from, $date_to);
210210
$helper->href = $this->context->link->getAdminLink('AdminCarts').'&action=filterOnlyAbandonedCarts&date_from='.$date_from.'&date_to='.$date_to;
211211
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=abandoned_cart';
212-
$kpis[] = $helper;
212+
$this->kpis[] = $helper;
213213

214214
$daysForAvgOrderVal = Configuration::get('PS_ORDER_KPI_AVG_ORDER_VALUE_NB_DAYS');
215215
$helper = new HelperKpi();
@@ -219,7 +219,7 @@ public function renderKpis()
219219
$helper->title = $this->l('Average Order Value', null, null, false);
220220
$helper->subtitle = $daysForAvgOrderVal.' '.$this->l('days', null, null, false);
221221
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=average_order_value';
222-
$kpis[] = $helper;
222+
$this->kpis[] = $helper;
223223

224224
$daysForProfitPerVisitor = Configuration::get('PS_ORDER_KPI_PER_VISITOR_PROFIT_NB_DAYS');
225225
$helper = new HelperKpi();
@@ -229,15 +229,9 @@ public function renderKpis()
229229
$helper->title = $this->l('Net Profit per Visitor', null, null, false);
230230
$helper->subtitle = $daysForProfitPerVisitor.' '.$this->l('days', null, null, false);
231231
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=netprofit_visit';
232-
$kpis[] = $helper;
232+
$this->kpis[] = $helper;
233233

234-
Hook::exec('action'.$this->controller_name.'KPIListingModifier', array(
235-
'kpis' => &$kpis,
236-
));
237-
238-
$helper = new HelperKpiRow();
239-
$helper->kpis = $kpis;
240-
return $helper->generate();
234+
return parent::renderKpis();
241235
}
242236

243237

controllers/admin/AdminCustomerThreadsController.php

+4-10
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ public function renderKpis()
524524
$helper->color = 'color1';
525525
$helper->title = $this->l('Pending Discussion Threads', null, null, false);
526526
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=pending_messages';
527-
$kpis[] = $helper;
527+
$this->kpis[] = $helper;
528528

529529
$helper = new HelperKpi();
530530
$helper->id = 'box-age';
@@ -533,7 +533,7 @@ public function renderKpis()
533533
$helper->title = $this->l('Average Response Time', null, null, false);
534534
$helper->subtitle = $this->l('30 days', null, null, false);
535535
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=avg_msg_response_time';
536-
$kpis[] = $helper;
536+
$this->kpis[] = $helper;
537537

538538
$helper = new HelperKpi();
539539
$helper->id = 'box-messages-per-thread';
@@ -542,15 +542,9 @@ public function renderKpis()
542542
$helper->title = $this->l('Messages per Thread', null, null, false);
543543
$helper->subtitle = $this->l('30 day', null, null, false);
544544
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=messages_per_thread';
545-
$kpis[] = $helper;
545+
$this->kpis[] = $helper;
546546

547-
Hook::exec('action'.$this->controller_name.'KPIListingModifier', array(
548-
'kpis' => &$kpis,
549-
));
550-
551-
$helper = new HelperKpiRow();
552-
$helper->kpis = $kpis;
553-
return $helper->generate();
547+
return parent::renderKpis();
554548
}
555549

556550
public function renderView()

controllers/admin/AdminCustomersController.php

+9-15
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ public function renderKpis()
709709
$helper->subtitle = $this->l('All Time', null, null, false);
710710
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=orders_per_customer';
711711
$helper->tooltip = $this->l('The average number of orders placed per customer in given period of time.', null, null, false);
712-
$kpis[] = $helper;
712+
$this->kpis[] = $helper;
713713

714714
$helper = new HelperKpi();
715715
$helper->id = 'box-total-frequent-customers';
@@ -720,7 +720,7 @@ public function renderKpis()
720720
$helper->href = $this->context->link->getAdminLink('AdminCustomers').'&submitFiltercustomer=1&customerFilter_total_orders%5B0%5D='.Configuration::get('PS_KPI_FREQUENT_CUSTOMER_NB_ORDERS').'&customerFilter_o%21date_add%5B0%5D='.date('Y-m-d', strtotime('-365 day')).'&customerFilter_o%21date_add%5B1%5D='.date('Y-m-d');
721721
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=total_frequent_customers';
722722
$helper->tooltip = $this->l('The total number of frequent customers in given period of time.', null, null, false);
723-
$kpis[] = $helper;
723+
$this->kpis[] = $helper;
724724

725725
$helper = new HelperKpi();
726726
$helper->id = 'box-revenue-per-available-customer';
@@ -731,7 +731,7 @@ public function renderKpis()
731731
$helper->subtitle = sprintf($this->l('%d Days', null, null, false), (int) $nbDaysRevPac);
732732
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=revenue_per_available_customer';
733733
$helper->tooltip = $this->l('Revenue per Available Customer (RevPAC) in given period of time.', null, null, false);
734-
$kpis[] = $helper;
734+
$this->kpis[] = $helper;
735735

736736
$helper = new HelperKpi();
737737
$helper->id = 'box-total-newsletter-registrations';
@@ -741,7 +741,7 @@ public function renderKpis()
741741
$helper->subtitle = $this->l('All Time', null, null, false);
742742
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=total_newsletter_registrations';
743743
$helper->tooltip = $this->l('The total number of newsletter registrations in given period of time.', null, null, false);
744-
$kpis[] = $helper;
744+
$this->kpis[] = $helper;
745745

746746
$helper = new HelperKpi();
747747
$helper->id = 'box-conversion-rate';
@@ -752,7 +752,7 @@ public function renderKpis()
752752
$helper->subtitle = sprintf($this->l('%d Days', null, null, false), (int) $nbDaysConversionRate);
753753
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=conversion_rate';
754754
$helper->tooltip = $this->l('The percentage of visitors who created a booking in given period of time.', null, null, false);
755-
$kpis[] = $helper;
755+
$this->kpis[] = $helper;
756756

757757
$helper = new HelperKpi();
758758
$helper->id = 'box-total-new-customers';
@@ -766,7 +766,7 @@ public function renderKpis()
766766
$helper->subtitle = sprintf($this->l('%d Days', null, null, false), (int) $nbDaysNewCustomers);
767767
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=total_new_customers';
768768
$helper->tooltip = $this->l('The total number of new customers who registered in given period of time.', null, null, false);
769-
$kpis[] = $helper;
769+
$this->kpis[] = $helper;
770770

771771
$helper = new HelperKpi();
772772
$helper->id = 'box-total-banned-customers';
@@ -777,7 +777,7 @@ public function renderKpis()
777777
$helper->href = $this->context->link->getAdminLink('AdminCustomers').'&customerFilter_deleted=1';
778778
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=total_banned_customers';
779779
$helper->tooltip = $this->l('The total number of banned customers.', null, null, false);
780-
$kpis[] = $helper;
780+
$this->kpis[] = $helper;
781781

782782
$helper = new HelperKpi();
783783
$helper->id = 'box-gender';
@@ -787,15 +787,9 @@ public function renderKpis()
787787
$helper->subtitle = $this->l('All Time', null, null, false);
788788
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=customer_main_gender';
789789
$helper->tooltip = $this->l('The main gender from all the customers.', null, null, false);
790-
$kpis[] = $helper;
790+
$this->kpis[] = $helper;
791791

792-
Hook::exec('action'.$this->controller_name.'KPIListingModifier', array(
793-
'kpis' => &$kpis,
794-
));
795-
796-
$helper = new HelperKpiRow();
797-
$helper->kpis = $kpis;
798-
return $helper->generate();
792+
return parent::renderKpis();
799793
}
800794

801795
public function renderView()

controllers/admin/AdminModulesController.php

+4-10
Original file line numberDiff line numberDiff line change
@@ -1333,31 +1333,25 @@ public function renderKpis()
13331333
$helper->color = 'color1';
13341334
$helper->title = $this->l('Installed Modules', null, null, false);
13351335
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=installed_modules';
1336-
$kpis[] = $helper;
1336+
$this->kpis[] = $helper;
13371337

13381338
$helper = new HelperKpi();
13391339
$helper->id = 'box-disabled-modules';
13401340
$helper->icon = 'icon-off';
13411341
$helper->color = 'color2';
13421342
$helper->title = $this->l('Disabled Modules', null, null, false);
13431343
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=disabled_modules';
1344-
$kpis[] = $helper;
1344+
$this->kpis[] = $helper;
13451345

13461346
$helper = new HelperKpi();
13471347
$helper->id = 'box-update-modules';
13481348
$helper->icon = 'icon-refresh';
13491349
$helper->color = 'color3';
13501350
$helper->title = $this->l('Modules to Update', null, null, false);
13511351
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=update_modules';
1352-
$kpis[] = $helper;
1352+
$this->kpis[] = $helper;
13531353

1354-
Hook::exec('action'.$this->controller_name.'KPIListingModifier', array(
1355-
'kpis' => &$kpis,
1356-
));
1357-
1358-
$helper = new HelperKpiRow();
1359-
$helper->kpis = $kpis;
1360-
return $helper->generate();
1354+
return parent::renderKpis();
13611355
}
13621356

13631357
public function initModal()

0 commit comments

Comments
 (0)