Skip to content

Commit

Permalink
Fix revive-adserver#1517 Added accounts statistics for the administrator
Browse files Browse the repository at this point in the history
Hopefully also fixed some sorting weirdness when switching through
various stats screens.
  • Loading branch information
mbeccati committed Jul 30, 2024
1 parent ce77f64 commit 967da99
Show file tree
Hide file tree
Showing 17 changed files with 421 additions and 68 deletions.
4 changes: 4 additions & 0 deletions RELEASE_NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ New Features
* Added support for writing to a fail2ban compatible log file on unsuccessful
login attempts.

* Replaced advertiser and website statistics with a new account statistics
screen for administrator users.


Bug Fixes
---------

Expand Down
5 changes: 4 additions & 1 deletion lib/OA/Admin/Menu/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ function _buildNavigation($accountType)
}

// Note: The stats screens haven't been updated to use the new menuing names...
$oMenu->add(new OA_Admin_Menu_Section("2", 'Stats', "stats.php?entity=global&breakdown=history", false, "statistics"));
$oMenu->add(new OA_Admin_Menu_Section("2", 'Stats', "stats.php?entity=global&breakdown=agency", false, "statistics"));
$oMenu->addTo("2", new OA_Admin_Menu_Section("2.9", 'GlobalAgency', "stats.php?entity=global&breakdown=agency", false, "statistics/agencies"));
$oMenu->addTo("2.9", new OA_Admin_Menu_Section("2.9.1", 'AgencyHistory', "stats.php?entity=agency&breakdown=history&agencyid={agencyid}", false, "statistics/agencyHistory"));
$oMenu->addTo("2.9.1", new OA_Admin_Menu_Section("2.9.1.1", 'DailyStats', "stats.php?entity=agency&breakdown=daily&agencyid={agencyid}&day={day}", false, "statistics/agencyHistory/daily"));
$oMenu->addTo("2", new OA_Admin_Menu_Section("2.2", 'GlobalHistory', "stats.php?entity=global&breakdown=history", false, "statistics/global"));
$oMenu->addTo("2.2", new OA_Admin_Menu_Section("2.2.1", 'DailyStats', "stats.php?entity=global&breakdown=daily&day={day}", false, "statistics/global/daily"));
$oMenu->addTo("2", new OA_Admin_Menu_Section("report-index", 'AdvancedReports', "report-index.php", false, "statistics"));
Expand Down
8 changes: 7 additions & 1 deletion lib/OA/Admin/Statistics/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ public function _pluginSort($a, $b)
* @access private
* @param string $type One of "advertiser", "publisher", "placement",
* "ad", "zone".
* @param ingeger $default Optional default value.
* @param integer|null $default Optional default value.
* @return integer The appropriate ID field.
*/
public function _getId($type, $default = null)
Expand Down Expand Up @@ -628,6 +628,12 @@ public function _getId($type, $default = null)
} else {
return (int) MAX_getValue('zoneid', $default);
}
} elseif ($type == 'agency') {
if (is_null($default)) {
return (int) MAX_getValue('agencyid', '');
} else {
return (int) MAX_getValue('agencyid', $default);
}
}
}

Expand Down
127 changes: 93 additions & 34 deletions lib/OA/Admin/Statistics/Delivery/CommonEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ abstract class OA_Admin_Statistics_Delivery_CommonEntity extends OA_Admin_Statis
'b' => 'stats.php?entity=banner&breakdown=history',
'p' => 'stats.php?entity=affiliate&breakdown=history',
'z' => 'stats.php?entity=zone&breakdown=history',
'g' => 'stats.php?entity=agency&breakdown=history',
];

/**
Expand Down Expand Up @@ -240,6 +241,7 @@ public function prepareData($aParams)
}

$this->data = [
'agency_id' => [],
'advertiser_id' => [],
'placement_id' => [],
'ad_id' => [],
Expand Down Expand Up @@ -303,6 +305,9 @@ public function prepareData($aParams)
}
}
}
if (in_array('agency_id', $aggregates)) {
$this->childrendata['agency_id'] = Admin_DA::fromCache('getAgencies', $aParams);
}

foreach ($aRows as $row) {
foreach ($aggregates as $agg) {
Expand Down Expand Up @@ -354,59 +359,52 @@ public function mergeData($aParams, $key)
}

/**
* Get advertiser stats
* Get agency stats
*
* @param array Query parameters
* @param int Tree level
* @param string Expand GET parameter, used only when called from other get methods
* @return Entities array
* @return array Entities array
*/
public function getAdvertisers($aParams, $level, $expand = '')
public function getAgencies($aParams)
{
$aParams['include'] = ['advertiser_id', 'placement_id'];
$aParams['exclude'] = ['zone_id'];
$aParams['include'] = ['agency_id'];
$aParams['exclude'] = ['advertiser_id', 'zone_id', 'ad_id', 'placement_id'];
$this->prepareData($aParams);
$period_preset = MAX_getStoredValue('period_preset', 'today');
$aAdvertisers = $this->mergeData($aParams, 'advertiser_id');
$aAgencies = $this->mergeData($aParams, 'agency_id');
MAX_sortArray(
$aAdvertisers,
($this->listOrderField == 'id' ? 'advertiser_id' : $this->listOrderField),
$aAgencies,
($this->listOrderField == 'id' ? 'agency_id' : $this->listOrderField),
$this->listOrderDirection == 'up',
);

$aEntitiesData = [];
foreach ($aAdvertisers as $advertiserId => $advertiser) {
$advertiser['active'] = $this->_hasActiveStats($advertiser);
foreach ($aAgencies as $agencyId => $agency) {
$agency['active'] = $this->_hasActiveStats($agency);

$this->_summarizeStats($advertiser);
$this->_summarizeStats($agency);

if ($this->startLevel > $level || !$this->hideInactive || $advertiser['active']) {
$advertiser['prefix'] = 'a';
$advertiser['id'] = $advertiserId;
$advertiser['linkparams'] = "clientid={$advertiserId}&";
if (!$this->hideInactive || $agency['active']) {
$agency['prefix'] = 'g';
$agency['id'] = $agencyId;
$agency['linkparams'] = "agencyid={$agencyId}&";
if (is_array($aParams) && $aParams !== []) {
foreach ($aParams as $key => $value) {
if ($key != "include" && $key != "exclude") {
$advertiser['linkparams'] .= $key . "=" . $value . "&";
$agency['linkparams'] .= $key . "=" . $value . "&";
}
}
} else {
$advertiser['linkparams'] .= "&";
$agency['linkparams'] .= "&";
}
$advertiser['linkparams'] .= "period_preset={$period_preset}&period_start=" . MAX_getStoredValue('period_start', date('Y-m-d'))
. "&period_end=" . MAX_getStoredValue('period_end', date('Y-m-d'));

$advertiser['conversionslink'] = "stats.php?entity=conversions&clientid={$advertiserId}";
$advertiser['expanded'] = MAX_isExpanded($advertiserId, $expand, $this->aNodes, $advertiser['prefix']);
$advertiser['icon'] = MAX_getEntityIcon('advertiser', $advertiser['active'], $advertiser['type']);
$agency['linkparams'] .= "period_preset={$period_preset}&period_start=" . MAX_getStoredValue('period_start', date('Y-m-d'))
. "&period_end=" . MAX_getStoredValue('period_end', date('Y-m-d'));

if ($advertiser['expanded'] || $this->startLevel > $level) {
$aParams2 = $aParams + ['advertiser_id' => $advertiserId];
$advertiser['subentities'] = $this->getCampaigns($aParams2, $level + 1, $expand);
}
$agency['icon'] = MAX_getEntityIcon('agency', $agency['active']);

$aEntitiesData[] = $advertiser;
} elseif ($this->startLevel == $level) {
$aEntitiesData[] = $agency;
} else {
$this->hiddenEntities++;
}
}
Expand All @@ -420,7 +418,7 @@ public function getAdvertisers($aParams, $level, $expand = '')
* @param array Query parameters
* @param int Tree level
* @param string Expand GET parameter, used only when called from other get methods
* @return Entities array
* @return array Entities array
*/
public function getCampaigns($aParams, $level, $expand = '')
{
Expand Down Expand Up @@ -467,7 +465,7 @@ public function getCampaigns($aParams, $level, $expand = '')
$campaign['linkparams'] .= "&";
}
$campaign['linkparams'] .= "period_preset={$period_preset}&period_start=" . MAX_getStoredValue('period_start', date('Y-m-d'))
. "&period_end=" . MAX_getStoredValue('period_end', date('Y-m-d'));
. "&period_end=" . MAX_getStoredValue('period_end', date('Y-m-d'));
$campaign['expanded'] = MAX_isExpanded($campaignId, $expand, $this->aNodes, $campaign['prefix']);
$campaign['icon'] = MAX_getEntityIcon('placement', $campaign['active'], $campaign['type']);

Expand Down Expand Up @@ -495,6 +493,67 @@ public function getCampaigns($aParams, $level, $expand = '')
return $aEntitiesData;
}

/**
* Get advertiser stats
*
* @param array Query parameters
* @param int Tree level
* @param string Expand GET parameter, used only when called from other get methods
* @return array Entities array
*/
public function getAdvertisers($aParams, $level, $expand = '')
{
$aParams['include'] = ['advertiser_id', 'placement_id'];
$aParams['exclude'] = ['zone_id'];
$this->prepareData($aParams);
$period_preset = MAX_getStoredValue('period_preset', 'today');
$aAdvertisers = $this->mergeData($aParams, 'advertiser_id');
MAX_sortArray(
$aAdvertisers,
($this->listOrderField == 'id' ? 'advertiser_id' : $this->listOrderField),
$this->listOrderDirection == 'up',
);

$aEntitiesData = [];
foreach ($aAdvertisers as $advertiserId => $advertiser) {
$advertiser['active'] = $this->_hasActiveStats($advertiser);

$this->_summarizeStats($advertiser);

if ($this->startLevel > $level || !$this->hideInactive || $advertiser['active']) {
$advertiser['prefix'] = 'a';
$advertiser['id'] = $advertiserId;
$advertiser['linkparams'] = "clientid={$advertiserId}&";
if (is_array($aParams) && $aParams !== []) {
foreach ($aParams as $key => $value) {
if ($key != "include" && $key != "exclude") {
$advertiser['linkparams'] .= $key . "=" . $value . "&";
}
}
} else {
$advertiser['linkparams'] .= "&";
}
$advertiser['linkparams'] .= "period_preset={$period_preset}&period_start=" . MAX_getStoredValue('period_start', date('Y-m-d'))
. "&period_end=" . MAX_getStoredValue('period_end', date('Y-m-d'));

$advertiser['conversionslink'] = "stats.php?entity=conversions&clientid={$advertiserId}";
$advertiser['expanded'] = MAX_isExpanded($advertiserId, $expand, $this->aNodes, $advertiser['prefix']);
$advertiser['icon'] = MAX_getEntityIcon('advertiser', $advertiser['active'], $advertiser['type']);

if ($advertiser['expanded'] || $this->startLevel > $level) {
$aParams2 = $aParams + ['advertiser_id' => $advertiserId];
$advertiser['subentities'] = $this->getCampaigns($aParams2, $level + 1, $expand);
}

$aEntitiesData[] = $advertiser;
} elseif ($this->startLevel == $level) {
$this->hiddenEntities++;
}
}

return $aEntitiesData;
}

/**
* Returns the HTML used to display the help icon triggering the tooltip
* @param $id ID of the html div to show on hover
Expand All @@ -511,7 +570,7 @@ private function getHtmlHelpLink($id)
* @param array Query parameters
* @param int Tree level
* @param string Expand GET parameter, used only when called from other get methods
* @return Entities array
* @return array Entities array
*/
public function getBanners($aParams, $level, $expand = '')
{
Expand Down Expand Up @@ -574,7 +633,7 @@ public function getBanners($aParams, $level, $expand = '')
* @param array Query parameters
* @param int Tree level
* @param string Expand GET parameter, used only when called from other get methods
* @return Entities array
* @return array Entities array
*/
public function getPublishers($aParams, $level, $expand = '')
{
Expand Down Expand Up @@ -634,7 +693,7 @@ public function getPublishers($aParams, $level, $expand = '')
* @param array Query parameters
* @param int Tree level
* @param string Expand GET parameter, used only when called from other get methods
* @return Entities array
* @return array Entities array
*/
public function getZones($aParams, $level, $expand)
{
Expand Down
90 changes: 90 additions & 0 deletions lib/OA/Admin/Statistics/Delivery/Controller/AgencyDaily.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php

/*
+---------------------------------------------------------------------------+
| Revive Adserver |
| http://www.revive-adserver.com |
| |
| Copyright: See the COPYRIGHT.txt file. |
| License: GPLv2 or later, see the LICENSE.txt file. |
+---------------------------------------------------------------------------+
*/

require_once MAX_PATH . '/lib/OA/Admin/Statistics/Delivery/CommonCrossHistory.php';

/**
* The class to display the delivery statistcs for the page:
*
* Statistics -> Accounts -> Daily Statistics
*
* @package OpenXAdmin
* @subpackage StatisticsDelivery
*/
class OA_Admin_Statistics_Delivery_Controller_AgencyDaily extends OA_Admin_Statistics_Delivery_CommonCrossHistory
{
/**
* The final "child" implementation of the PHP5-style constructor.
*
* @param array $aParams An array of parameters. The array should
* be indexed by the name of object variables,
* with the values that those variables should
* be set to. For example, the parameter:
* $aParams = array('foo' => 'bar')
* would result in $this->foo = bar.
*/
public function __construct($aParams)
{
// Set this page's entity/breakdown values
$this->entity = 'agency';
$this->breakdown = 'daily';

// Use the OA_Admin_Statistics_Daily helper class
$this->useDailyClass = true;

parent::__construct($aParams);
}

/**
* The final "child" implementation of the parental abstract method.
*
* @see OA_Admin_Statistics_Common::start()
*/
public function start()
{
// Get parameters
$agencyId = $this->_getId('agency');

// Security check
OA_Permission::enforceAccount(OA_ACCOUNT_ADMIN);

// Add standard page parameters
$this->aPageParams = ['agencyid' => $agencyId];

// Load $_GET parameters
$this->_loadParams();

// Load the period preset and stats breakdown parameters
$this->_loadPeriodPresetParam();
$this->_loadStatsBreakdownParam();

// HTML Framework
$this->pageId = '2.9.1.1';
$this->aPageSections = [$this->pageId];

// Add breadcrumbs
$this->_addBreadcrumbs('agency', $agencyId);

// Add shortcuts
$this->_addShortcut(
$GLOBALS['strAgencyProperties'],
'agency-edit.php?agencyid=' . $agencyId,
'iconAgency',
);

// Prepare the data for display by output() method
$aParams = [
'agency_id' => $agencyId,
];
$this->prepare($aParams);
}
}
Loading

0 comments on commit 967da99

Please sign in to comment.