-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from TheDMSGroup/fix-missing-chart
[ENG-652] put campaign revenue chart back
- Loading branch information
Showing
3 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?php | ||
/* | ||
* @copyright 2018 Mautic Contributors. All rights reserved | ||
* @author Digital Media Solutions, LLC | ||
* | ||
* @link http://mautic.org | ||
* | ||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html | ||
*/ | ||
|
||
namespace MauticPlugin\MauticContactLedgerBundle\EventListener; | ||
|
||
use Mautic\CoreBundle\CoreEvents; | ||
use Mautic\CoreBundle\Event\CustomAssetsEvent; | ||
use Mautic\CoreBundle\Event\CustomContentEvent; | ||
use Mautic\CoreBundle\EventListener\CommonSubscriber; | ||
use Mautic\DashboardBundle\Model\DashboardModel; | ||
use MauticPlugin\MauticContactLedgerBundle\Model\LedgerEntryModel; | ||
|
||
/** | ||
* Class CustomContentSubscriber. | ||
*/ | ||
class CustomContentSubscriber extends CommonSubscriber | ||
{ | ||
/** | ||
* @var LedgerEntryModel | ||
*/ | ||
protected $ledgerEntryModel; | ||
/** | ||
* @var DashboardModel | ||
*/ | ||
protected $dashboardModel; | ||
|
||
/** | ||
* CustomContentSubscriber constructor. | ||
* | ||
* @param LedgerEntryModel $ledgerEntryModel | ||
* @param DashboardModel $dashboardModel | ||
*/ | ||
public function __construct(LedgerEntryModel $ledgerEntryModel, DashboardModel $dashboardModel) | ||
{ | ||
$this->ledgerEntryModel = $ledgerEntryModel; | ||
$this->dashboardModel = $dashboardModel; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public static function getSubscribedEvents() | ||
{ | ||
return [ | ||
CoreEvents::VIEW_INJECT_CUSTOM_CONTENT => ['getContentInjection', 0], | ||
// CoreEvents::VIEW_INJECT_CUSTOM_ASSETS => ['getAssetInjection', 0], | ||
]; | ||
} | ||
|
||
// /** | ||
// * @param CustomAssetsEvent $event | ||
// * | ||
// * @return CustomAssetsEvent | ||
// */ | ||
// public function getAssetInjection(CustomAssetsEvent $event) | ||
// { | ||
// // $location = $this->router->getContext()->getPathInfo(); | ||
// // | ||
// // if (preg_match('#campaigns/view/\d+$#', $location)) { | ||
// // $event->addScript('plugins/MauticContactLedgerBundle/Assets/js/datatables.min.js', 'bodyClose'); | ||
// // $event->addStylesheet('plugins/MauticContactLedgerBundle/Assets/css/datatables.min.css'); | ||
// // } | ||
// // | ||
// // return $event; | ||
// } | ||
|
||
/** | ||
* @param CustomContentEvent $event | ||
* | ||
* @return CustomContentEvent | ||
* | ||
* @throws \Doctrine\DBAL\DBALException | ||
*/ | ||
public function getContentInjection(CustomContentEvent $event) | ||
{ | ||
switch ($event->getViewName()) { | ||
case 'MauticCampaignBundle:Campaign:details.html.php': | ||
if ('left.section.top' === $event->getContext()) { | ||
/** @var \DateTime[] $dateRange */ | ||
$dateRange = $this->request->request->get('daterange', []); | ||
if (empty($dateRange)) { | ||
$dateRange = $this->dashboardModel->getDefaultFilter(); | ||
$dateFrom = $dateRange['date_from'] = $dateRange['dateFrom']; | ||
$dateTo = $dateRange['date_to'] = $dateRange['dateTo']; | ||
} else { | ||
$dateFrom = $dateRange['dateFrom'] = new \DateTime($dateRange['date_from']); | ||
$dateTo = $dateRange['dateTo'] = new \DateTime($dateRange['date_to']); | ||
} | ||
/** @var array $vars */ | ||
$vars = $event->getVars(); | ||
/** @var mixed $chartData */ | ||
$chartData = null; | ||
/** @var string $chartTemplate */ | ||
$chartTemplate = ''; | ||
if (isset($vars['campaign'])) { | ||
$chartTemplate = 'MauticContactLedgerBundle:Charts:campaign_revenue_chart.html.php'; | ||
$chartData = $this->ledgerEntryModel->getCampaignRevenueChartData( | ||
$vars['campaign'], | ||
$dateFrom, | ||
$dateTo | ||
); | ||
} | ||
$event->addTemplate($chartTemplate, [ | ||
'campaignRevenueChartData' => $chartData, | ||
]); | ||
} | ||
break; | ||
//default: | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<div class="pa-md"> | ||
<div class="row"> | ||
<div class="col-sm-12"> | ||
<div class="panel"> | ||
<div class="panel-body box-layout"> | ||
<div class="col-md-3 va-m"> | ||
<h5 class="text-white dark-md fw-sb mb-xs"> | ||
<span class="fa fa-line-chart"></span> | ||
<?php echo $view['translator']->trans('mautic.contactledger.campaignrevenue'); ?> | ||
</h5> | ||
</div> | ||
<div class="col-md-9 va-m"> | ||
<?php echo $view->render( | ||
'MauticCoreBundle:Helper:graph_dateselect.html.php', | ||
['dateRangeForm' => $dateRangeForm, 'class' => 'pull-right'] | ||
); ?> | ||
</div> | ||
</div> | ||
<div class="pt-0 pl-15 pb-10 pr-15"> | ||
<?php echo $view->render( | ||
'MauticCoreBundle:Helper:chart.html.php', | ||
['chartData' => $campaignRevenueChartData, 'chartType' => 'line', 'chartHeight' => 300] | ||
); ?> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |