Esempio n. 1
0
 /**
  * A method that can be inherited and used by children classes to get the
  * required date span of a statistics page.
  *
  * @param object $oCaller      The calling object. Expected to have the
  *                             the following class variables:
  *                                  $oCaller->aPlugins    - An array of statistics fields plugins
  *                                  $oCaller->oStartDate  - Will be set by method
  *                                  $oCaller->spanDays    - Will be set by method
  *                                  $oCaller->spanWeeks   - Will be set by method
  *                                  $oCaller->spanMonths  - Will be set by method
  * @param array  $aParams      An array of query parameters for
  *                             {@link Admin_DA::fromCache()}.
  */
 function getSpan(&$oCaller, $aParams)
 {
     $oStartDate = new Date(date('Y-m-d'));
     $oStartDate->setHour(0);
     $oStartDate->setMinute(0);
     $oStartDate->setSecond(0);
     // Check span using all plugins
     foreach ($oCaller->aPlugins as $oPlugin) {
         $aPluginParams = call_user_func(array($oPlugin, 'getHistorySpanParams'));
         $aSpan = Admin_DA::fromCache('getHistorySpan', $aParams + $aPluginParams);
         if (!empty($aSpan['start_date'])) {
             $oDate = new Date($aSpan['start_date']);
             $oDate->setTZbyID('UTC');
             if ($oDate->before($oStartDate)) {
                 $oDate->convertTZ($oStartDate->tz);
                 $oStartDate = new Date($oDate);
             }
         }
     }
     $oStartDate->setHour(0);
     $oStartDate->setMinute(0);
     $oStartDate->setSecond(0);
     $oNow = new Date();
     $oSpan = new Date_Span(new Date($oStartDate), new Date($oNow->format('%Y-%m-%d')));
     // Store the span data required for stats display
     $oCaller->oStartDate = $oStartDate;
     $oCaller->spanDays = (int) ceil($oSpan->toDays());
     $oCaller->spanWeeks = (int) ceil($oCaller->spanDays / 7) + ($oCaller->spanDays % 7 ? 1 : 0);
     $oCaller->spanMonths = ($oNow->getYear() - $oStartDate->getYear()) * 12 + ($oNow->getMonth() - $oStartDate->getMonth()) + 1;
     // Set the caller's aDates span in the event that it's empty
     if (empty($oCaller->aDates)) {
         $oCaller->aDates['day_begin'] = $oStartDate->format('%Y-%m-%d');
         $oCaller->aDates['day_end'] = $oNow->format('%Y-%m-%d');
     }
 }
Esempio n. 2
0
 /**
  * Fetch and aggregate stats using the specified parameters
  *
  * @param array Query parameters
  */
 function prepareData($aParams)
 {
     if (is_null($this->data)) {
         $oNow = new Date();
         $aParams['tz'] = $oNow->tz->getID();
         // Get plugin aParams
         $pluginParams = array();
         foreach ($this->aPlugins as $oPlugin) {
             $oPlugin->addQueryParams($pluginParams);
         }
         $aRows = Admin_DA::fromCache('getEntitiesStats', $aParams + $this->aDates + $pluginParams);
         // Merge plugin additional data
         foreach ($this->aPlugins as $oPlugin) {
             $oPlugin->mergeData($aRows, $this->aEmptyRow, 'getEntitiesStats', $aParams + $this->aDates);
         }
         $this->data = array('advertiser_id' => array(), 'placement_id' => array(), 'ad_id' => array(), 'publisher_id' => array(), 'zone_id' => array());
         if (!count($aRows)) {
             $this->noStatsAvailable = true;
             return;
         }
         $aggregates = array('ad_id', 'zone_id');
         if (isset($aParams['exclude'])) {
             $aggregates = array_diff($aggregates, $aParams['exclude']);
         }
         if (isset($aParams['include'])) {
             $aggregates = array_merge($aggregates, $aParams['include']);
         }
         $this->childrendata = array();
         if (array_search('ad_id', $aggregates) !== false) {
             $this->childrendata['ad_id'] = Admin_DA::fromCache('getAds', $aParams);
             // Plugins can set their own ads in the array
             foreach ($this->aPlugins as $oPlugin) {
                 $oPlugin->mergeAds($this->childrendata['ad_id']);
             }
         }
         if (array_search('placement_id', $aggregates) !== false) {
             $this->childrendata['placement_id'] = Admin_DA::fromCache('getPlacementsChildren', $aParams);
             if (isset($this->childrendata['ad_id'])) {
                 foreach ($this->childrendata['ad_id'] as $key => $item) {
                     $this->childrendata['placement_id'][$item['placement_id']]['children'][$key] =& $this->childrendata['ad_id'][$key];
                     $this->childrendata['ad_id'][$key]['advertiser_id'] = $this->childrendata['placement_id'][$item['placement_id']]['advertiser_id'];
                 }
             }
         }
         if (array_search('advertiser_id', $aggregates) !== false) {
             $this->childrendata['advertiser_id'] = Admin_DA::fromCache('getAdvertisersChildren', $aParams);
             if (isset($this->childrendata['placement_id'])) {
                 foreach ($this->childrendata['placement_id'] as $key => $item) {
                     $this->childrendata['advertiser_id'][$item['advertiser_id']]['children'][$key] =& $this->childrendata['placement_id'][$key];
                 }
             }
         }
         if (array_search('zone_id', $aggregates) !== false) {
             $this->childrendata['zone_id'] = Admin_DA::fromCache('getZones', $aParams);
             // Plugins can set their own zones in the array
             foreach ($this->aPlugins as $oPlugin) {
                 $oPlugin->mergeZones($this->childrendata['zone_id']);
             }
         }
         if (array_search('publisher_id', $aggregates) !== false) {
             $this->childrendata['publisher_id'] = Admin_DA::fromCache('getPublishersChildren', $aParams);
             if (isset($this->childrendata['zone_id'])) {
                 foreach ($this->childrendata['zone_id'] as $key => $item) {
                     $this->childrendata['publisher_id'][$item['publisher_id']]['children'][$key] =& $this->childrendata['zone_id'][$key];
                 }
             }
         }
         foreach ($aRows as $row) {
             foreach ($aggregates as $agg) {
                 $this->_prepareDataAdd($this->data[$agg], $row, $agg);
             }
         }
     }
 }
 function testFromCacheGetAdsStats()
 {
     $this->_generateStats();
     $res = Admin_DA::fromCache('getAdsStats', array('placement_id' => $this->campaignId));
     $this->assertTrue(is_array($res));
     $this->assertTrue(count($res));
 }
$aConversions = Admin_DA::getConversions($aParams + $aDates);
if (!empty($aConversions)) {
    $conf = $GLOBALS['_MAX']['CONF'];
    $modified = false;
    // Modify conversions
    foreach ($statusIds as $conversionId => $statusId) {
        if (isset($aConversions[$conversionId]) && $aConversions[$conversionId]['connection_status'] != $statusId) {
            $modified = true;
            // Edit conversion
            $doData_intermediate_ad_connection = OA_Dal::factoryDO('data_intermediate_ad_connection');
            $doData_intermediate_ad_connection->get($conversionId);
            $doData_intermediate_ad_connection->connection_status = $statusId;
            $doData_intermediate_ad_connection->update();
            if ($aConversions[$conversionId]['connection_status'] == MAX_CONNECTION_STATUS_APPROVED || $statusId == MAX_CONNECTION_STATUS_APPROVED) {
                // Connection was changed to conversion (or conversion was changed to connection)
                $aConVariables = Admin_DA::fromCache('getConnectionVariables', $conversionId);
                // Sum up basket values
                $basketValue = 0;
                $numItems = 0;
                foreach ($aConVariables as $conVariable) {
                    if ($conVariable['purpose'] == 'basket_value') {
                        $basketValue += $conVariable['value'];
                    } elseif ($conVariable['purpose'] == 'num_items') {
                        $numItems += $conVariable['value'];
                    }
                }
                // Get day, $hour and operation interval
                $dateTime = $aConversions[$conversionId]['date_time'];
                $oConnectionDate = new Date($dateTime);
                $oConnectionDate->toUTC();
                $optIntID = OX_OperationInterval::convertDateToOperationIntervalID($oConnectionDate);
 function getZoneBanners($zoneId)
 {
     $aParams = array('zone_id' => $zoneId, 'exclude' => array('zone_id'), 'custom_columns' => array());
     // Get stats banner list
     $aStatsAds = array();
     foreach ($this->aPlugins as $oPlugin) {
         $pluginParams = $oPlugin->getHistorySpanParams();
         $aStatsAds += Admin_DA::fromCache('getEntitiesStats', $aParams + $pluginParams + $this->aDates);
     }
     // Get all banners
     $aAds = Admin_DA::fromCache('getAds', array());
     // Get anonymous campaigns
     $aAnonPlacements = Admin_DA::fromCache('getPlacements', array('placement_anonymous' => 't'));
     // Intersect
     foreach ($aAds as $k => $v) {
         if (!isset($aStatsAds[$k])) {
             unset($aAds[$k]);
         } else {
             $aAds[$k]['anonymous'] = isset($aAnonPlacements[$v['placement_id']]);
         }
     }
     // Cache results
     $this->crossEntitiesCache = $aAds;
     return $aAds;
 }
 /**
  * Add "blanks" stats to an entity array
  *
  * @param array Query parameters
  * @param array Entities array
  */
 function addBlanks($aParams, &$aEntitiesData)
 {
     $aParams['exclude'] = array('zone_id');
     $aParams['ad_id'] = 0;
     // Get plugin aParams
     $pluginParams = array();
     foreach ($this->aPlugins as $oPlugin) {
         $oPlugin->addQueryParams($pluginParams);
     }
     $aBlanks = Admin_DA::fromCache('getEntitiesStats', $aParams + $this->aDates, 1);
     // Merge plugin additional data
     foreach ($this->aPlugins as $oPlugin) {
         $oPlugin->mergeData($aBlanks, 'getEntitiesStats', $aParams + $this->aDates, $this->aEmptyRow);
     }
     if (count($aBlanks)) {
         $zone = current($aBlanks) + $this->aEmptyRow;
         $zone['active'] = $this->_hasActiveStats($zone);
         if ($zone['active']) {
             $this->_summarizeStats($zone);
             $zone['name'] = 'Blank impressions';
             $zone['prefix'] = 'x';
             $zone['id'] = '-';
             $zone['icon'] = OX::assetPath() . '/images/icon-banner-disabled.png';
             $zone['htmlclass'] = 'last';
             if ($this->listOrderField != 'name' && $this->listOrderField != 'id') {
                 $aEntitiesData[] = $zone;
                 MAX_sortArray($aEntitiesData, $this->listOrderField, $this->listOrderDirection == 'up');
             } elseif ($this->listOrderDirection == 'up') {
                 array_push($aEntitiesData, $zone);
             } else {
                 array_unshift($aEntitiesData, $zone);
             }
         }
     }
 }
 /**
  * Fetch the history stats using the specified parameters
  *
  * @param array  $aParams Query parameters
  * @param string $link    Optional link for the leftmost column content
  */
 function getHistory($aParams, $link = '')
 {
     $oNow = new Date();
     $aParams['tz'] = $oNow->tz->getID();
     $method = $this->oHistory->setBreakdownInfo($this);
     // Add plugin aParams
     $pluginParams = array();
     foreach ($this->aPlugins as $oPlugin) {
         $oPlugin->addQueryParams($pluginParams);
     }
     $aStats = Admin_DA::fromCache($method, $aParams + $this->aDates + $pluginParams);
     // Merge plugin additional $oPlugin
     foreach ($this->aPlugins as $oPlugin) {
         $oPlugin->mergeData($aStats, $method, $aParams + $this->aDates, $this->aEmptyRow);
     }
     if (count($aStats) == 0) {
         $this->noStatsAvailable = true;
         return $aStats;
     }
     // Fill unused plugins columns
     foreach (array_keys($aStats) as $k) {
         $aStats[$k] += $this->aEmptyRow;
     }
     // Set some of the variables that used to be set by getSpan
     if (!empty($aStats)) {
         $dates = array_keys($aStats);
         // assumes first row has earliest date
         $firstDate = new Date($dates[0]);
         // Convert to current TZ
         $firstDate->setTZbyID('UTC');
         $firstDate->convertTZ($oNow->tz);
         $firstDate->setHour(0);
         $firstDate->setMinute(0);
         $firstDate->setSecond(0);
         if (empty($this->aDates)) {
             $this->aDates['day_begin'] = $firstDate->format('%Y-%m-%d');
             $this->aDates['day_end'] = $oNow->format('%Y-%m-%d');
         }
         $this->oStartDate = new Date($firstDate);
     }
     $aDates = $this->oHistory->getDatesArray($this->aDates, $this->statsBreakdown, $this->oStartDate);
     $this->oHistory->fillGapsAndLink($aStats, $aDates, $this, $link);
     if (!in_array($this->listOrderField, array_merge(array($this->statsBreakdown), array_keys($this->aColumns)))) {
         $this->listOrderField = $this->statsBreakdown;
         $this->listOrderDirection = $this->statsBreakdown == 'hour' || $this->statsBreakdown == 'dow' ? 'up' : 'down';
     }
     // If required, re-format the data in the weekly breakdown format
     if ($this->statsBreakdown == 'week') {
         $this->oHistory->prepareWeekBreakdown($aStats, $this);
     }
     MAX_sortArray($aStats, $this->listOrderField, $this->listOrderDirection == 'up');
     // Summarise the values into a the totals array, & format
     $this->_summariseTotalsAndFormat($aStats, true);
     return $aStats;
 }
Esempio n. 8
0
function MAX_displayZoneStats($aParams, $pageName, $anonymous, $aNodes, $expand, $listorder, $orderdirection, $hideinactive, $showPublisher, $entityIds)
{
    global $phpAds_TextAlignLeft, $phpAds_TextAlignRight, $phpAds_TextDirection;
    // Get the icons for all levels (publisher/zone)
    $entity = _getEntityString($entityIds);
    $publishersHidden = 0;
    $aZones = Admin_DA::fromCache('getZonesStats', $aParams);
    if (!empty($aZones)) {
        echo "\n        <br /><br />\n        <table border='0' width='100%' cellpadding='0' cellspacing='0'>";
        MAX_displayStatsHeader($pageName, $listorder, $orderdirection, $entityIds, $anonymous);
        // Variable to determine if the row should be grey or white...
        $i = 0;
        $totalRequests = 0;
        $totalViews = 0;
        $totalClicks = 0;
        $totalConversions = 0;
        // Loop through publishers
        MAX_sortArray($aZones, $listorder == 'id' ? 'zone_id' : $listorder, $orderdirection == 'up');
        foreach ($aZones as $zoneId => $zone) {
            $zoneRequests = phpAds_formatNumber($zone['sum_requests']);
            $zoneViews = phpAds_formatNumber($zone['sum_views']);
            $zoneClicks = phpAds_formatNumber($zone['sum_clicks']);
            $zoneConversions = phpAds_formatNumber($zone['sum_conversions']);
            $zoneCtr = phpAds_buildRatioPercentage($zone['sum_clicks'], $zone['sum_views']);
            $zoneSr = phpAds_buildRatioPercentage($zone['sum_conversions'], $zone['sum_clicks']);
            $zoneActive = true;
            $zoneIcon = MAX_getEntityIcon('zone', $zoneActive, $zone['type']);
            if (!$hideinactive || $zoneActive) {
                $bgcolor = $i++ % 2 == 0 ? " bgcolor='#F6F6F6'" : '';
                echo "\n        <tr height='25'{$bgcolor}>\n            <td>&nbsp;<img src='" . OX::assetPath() . "/images/spacer.gif' height='16' width='16'>&nbsp;\n                <img src='{$zoneIcon}' align='absmiddle'>&nbsp;";
                if ($anonymous) {
                    echo "\n                Hidden zone {$zone['id']}";
                } else {
                    echo "\n                <a href='stats.php?entity=zone&breakdown=history&affiliateid={$zone['publisher_id']}'>{$zone['name']}</a>";
                }
                echo "\n            </td>";
                if ($anonymous) {
                    echo "\n            <td align='{$phpAds_TextAlignRight}'>&nbsp;</td>";
                } else {
                    echo "\n            <td align='{$phpAds_TextAlignRight}'>{$zoneId}</td>";
                }
                echo "\n            <td align='{$phpAds_TextAlignRight}'>{$zoneRequests}</td>\n            <td align='{$phpAds_TextAlignRight}'>{$zoneViews}</td>\n            <td align='{$phpAds_TextAlignRight}'>{$zoneClicks}</td>\n            <td align='{$phpAds_TextAlignRight}'>{$zoneCtr}</td>\n            <td align='{$phpAds_TextAlignRight}'>{$zoneConversions}</td>\n            <td align='{$phpAds_TextAlignRight}'>{$zoneSr}</td>\n        </tr>\n        <tr height='1'><td colspan='8' bgcolor='#888888'><img src='" . OX::assetPath() . "/images/break.gif' height='1' width='100%'></td></tr>";
            } else {
                $publishersHidden++;
            }
            $totalRequests += $zone['sum_requests'];
            $totalViews += $zone['sum_views'];
            $totalClicks += $zone['sum_clicks'];
            $totalConversions += $zone['sum_conversions'];
        }
        // Total
        echo "\n        <tr height='25'{$bgcolor}>\n            <td>&nbsp;&nbsp;<b>{$GLOBALS['strTotal']}</b></td>\n            <td>&nbsp;</td>\n            <td align='{$phpAds_TextAlignRight}'>" . phpAds_formatNumber($totalRequests) . "</td>\n            <td align='{$phpAds_TextAlignRight}'>" . phpAds_formatNumber($totalViews) . "</td>\n            <td align='{$phpAds_TextAlignRight}'>" . phpAds_formatNumber($totalClicks) . "</td>\n            <td align='{$phpAds_TextAlignRight}'>" . phpAds_buildCTR($totalViews, $totalClicks) . "</td>\n            <td align='{$phpAds_TextAlignRight}'>" . phpAds_formatNumber($totalConversions) . "</td>\n            <td align='{$phpAds_TextAlignRight}'>" . phpAds_buildCTR($totalClicks, $totalConversions) . "</td>\n        </tr>\n        <tr height='1'>\n            <td colspan='8' bgcolor='#888888'><img src='" . OX::assetPath() . "/images/break.gif' height='1' width='100%'></td>\n        </tr>";
        if (!$anonymous) {
            echo "\n        <tr>\n            <td colspan='4' align='{$phpAds_TextAlignLeft}' nowrap>";
            if ($hideinactive == true) {
                echo "&nbsp;&nbsp;<img src='" . OX::assetPath() . "/images/icon-activate.gif' align='absmiddle' border='0'>&nbsp;<a href='{$pageName}?{$entity}hideinactive=0'>{$GLOBALS['strShowAll']}</a>&nbsp;&nbsp;|&nbsp;&nbsp;{$publishersHidden} {$GLOBALS['strInactivePublishersHidden']}";
            } else {
                echo "&nbsp;&nbsp;<img src='" . OX::assetPath() . "/images/icon-hideinactivate.gif' align='absmiddle' border='0'>&nbsp;<a href='{$pageName}?{$entity}hideinactive=1'>{$GLOBALS['strHideInactivePublishers']}</a>";
            }
            echo "\n            </td>\n            <td colspan='4' align='{$phpAds_TextAlignRight}' nowrap><img src='" . OX::assetPath() . "/images/triangle-d.gif' align='absmiddle' border='0'>&nbsp;<a href='{$pageName}?{$entity}expand=all'>{$GLOBALS['strExpandAll']}</a>&nbsp;&nbsp;|&nbsp;&nbsp;<img src='" . OX::assetPath() . "/images/{$phpAds_TextDirection}/triangle-l.gif' align='absmiddle' border='0'>&nbsp;<a href='{$pageName}?{$entity}expand=none'>{$GLOBALS['strCollapseAll']}</a>&nbsp;&nbsp;</td>\n        </tr>\n        <tr height='25'>";
            if ($showPublisher == 't') {
                echo "\n            <td colspan='7' align='{$phpAds_TextAlignLeft}' nowrap>&nbsp;&nbsp;<img src='" . OX::assetPath() . "/images/icon-affiliate.gif' align='absmiddle'><a href='{$pageName}?{$entity}showpublisher=f'> Hide parent publisher</a></td>";
            } else {
                echo "\n            <td colspan='7' align='{$phpAds_TextAlignLeft}' nowrap>&nbsp;&nbsp;<img src='" . OX::assetPath() . "/images/icon-affiliate.gif' align='absmiddle'><a href='{$pageName}?{$entity}showpublisher=t'> Show parent publisher</a></td>";
            }
            echo "\n        </tr>";
        }
        echo "\n        </table>\n        <br /><br />";
    } else {
        MAX_displayNoStatsMessage();
    }
}
Esempio n. 9
0
 function _getHistoryTz($entity, $aParams, $name, $method, $args = array(), $formatted = null)
 {
     if (empty($aParams['tz'])) {
         return Admin_DA::_getEntities($entity, $aParams, false, $name);
     }
     $aStats = Admin_DA::fromCache('getDayHourHistory', $aParams);
     return Admin_DA::_convertStatsArrayToTz($aStats, $aParams, $name, $method, $args, $formatted);
 }
Esempio n. 10
0
 /**
  * Add direct selection stats to an entity array
  *
  * @param array Query parameters
  * @param array Entities array
  */
 function addDirectSelection($aParams, &$aEntitiesData)
 {
     $aParams['exclude'] = array('ad_id');
     $aParams['zone_id'] = 0;
     // Get plugin aParams
     $pluginParams = array();
     foreach ($this->aPlugins as $oPlugin) {
         $oPlugin->addQueryParams($pluginParams);
     }
     $aDirectSelection = Admin_DA::fromCache('getEntitiesStats', $aParams + $this->aDates);
     // Merge plugin additional data
     foreach ($this->aPlugins as $oPlugin) {
         $oPlugin->mergeData($aDirectSelection, $this->aEmptyRow, 'getEntitiesStats', $aParams + $this->aDates);
     }
     if (count($aDirectSelection)) {
         $zone = current($aDirectSelection) + $this->aEmptyRow;
         $zone['active'] = $this->_hasActiveStats($zone);
         if ($zone['active']) {
             $this->_summarizeStats($zone);
             $zone['name'] = $GLOBALS['strGenerateBannercode'];
             $zone['prefix'] = 'x';
             $zone['id'] = '-';
             $zone['icon'] = OX::assetPath() . '/images/icon-generatecode.gif';
             $zone['htmlclass'] = 'last';
             if ($this->listOrderField != 'name' && $this->listOrderField != 'id') {
                 $aEntitiesData[] = $zone;
                 MAX_sortArray($aEntitiesData, $this->listOrderField, $this->listOrderDirection == 'up');
             } elseif ($this->listOrderDirection == 'up') {
                 array_push($aEntitiesData, $zone);
             } else {
                 array_unshift($aEntitiesData, $zone);
             }
         }
     }
 }
Esempio n. 11
0
 /**
  * A private method that can be inherited and used by children classes to
  * output the context in the left navigation bar.
  *
  * {@uses phpAds_PageContext()}
  */
 function _showContext($type, $current_id = 0)
 {
     if ($this->useDailyClass && $type == 'days') {
         // Use the helper class contect method instead
         $aArray = array('period_start' => MAX_getStoredValue('period_start', date('Y-m-d')), 'period_end' => MAX_getStoredValue('period_end', date('Y-m-d')));
         $aDates = array_reverse($this->oHistory->getDatesArray($aArray, 'day', $this->oStartDate));
         $this->oDaily->showContext($aDates, $current_id, $this);
     } else {
         $aParams = array();
         switch ($type) {
             case 'advertisers':
                 if (OA_Permission::isAccount(OA_ACCOUNT_ADMIN) || OA_Permission::isAccount(OA_ACCOUNT_MANAGER)) {
                     if (OA_Permission::isAccount(OA_ACCOUNT_MANAGER)) {
                         $aParams['agency_id'] = OA_Permission::getEntityId();
                     }
                     $params = $this->aPageParams;
                     $advertisers = Admin_DA::getAdvertisers($aParams, false);
                     foreach ($advertisers as $advertiser) {
                         $params['clientid'] = $advertiser['advertiser_id'];
                         phpAds_PageContext(MAX_buildName($advertiser['advertiser_id'], $advertiser['name']), $this->_addPageParamsToURI($this->pageName, $params, true), $current_id == $advertiser['advertiser_id']);
                     }
                 }
                 break;
             case 'campaigns':
                 $aParams['advertiser_id'] = $this->aPageParams['clientid'];
                 $params = $this->aPageParams;
                 $campaigns = Admin_DA::getPlacements($aParams, false);
                 foreach ($campaigns as $campaign) {
                     $params['campaignid'] = $campaign['placement_id'];
                     // mask campaign name if anonymous campaign
                     $campaign['name'] = MAX_getPlacementName($campaign);
                     phpAds_PageContext(MAX_buildName($campaign['placement_id'], $campaign['name']), $this->_addPageParamsToURI($this->pageName, $params, true), $current_id == $campaign['placement_id']);
                 }
                 break;
             case 'banners':
                 $aParams['placement_id'] = $this->aPageParams['campaignid'];
                 $params = $this->aPageParams;
                 $banners = Admin_DA::getAds($aParams, false);
                 foreach ($banners as $banner) {
                     $params['bannerid'] = $banner['ad_id'];
                     // mask banner name if anonymous campaign
                     $campaign = Admin_DA::getPlacement($banner['placement_id']);
                     $campaignAnonymous = $campaign['anonymous'] == 't' ? true : false;
                     $banner['name'] = MAX_getAdName($banner['name'], null, null, $campaignAnonymous, $banner['ad_id']);
                     phpAds_PageContext(MAX_buildName($banner['ad_id'], $banner['name']), $this->_addPageParamsToURI($this->pageName, $params, true), $current_id == $banner['ad_id']);
                 }
                 break;
             case 'publishers':
                 if (OA_Permission::isAccount(OA_ACCOUNT_ADMIN) || OA_Permission::isAccount(OA_ACCOUNT_MANAGER)) {
                     if (OA_Permission::isAccount(OA_ACCOUNT_MANAGER)) {
                         $aParams['agency_id'] = OA_Permission::getEntityId();
                     }
                     $params = $this->aPageParams;
                     $campaigns = Admin_DA::getPublishers($aParams, false);
                     foreach ($campaigns as $publisher) {
                         $params['affiliateid'] = $publisher['publisher_id'];
                         phpAds_PageContext(MAX_buildName($publisher['publisher_id'], $publisher['name']), $this->_addPageParamsToURI($this->pageName, $params, true), $current_id == $publisher['publisher_id']);
                     }
                 }
                 break;
             case 'publisher-campaigns':
                 if (OA_Permission::isAccount(OA_ACCOUNT_ADMIN) || OA_Permission::isAccount(OA_ACCOUNT_MANAGER)) {
                     $aParams = array('publisher_id' => $publisherId, 'placement_id' => $placementId, 'include' => array('placement_id'), 'exclude' => array('zone_id'));
                     $aPlacements = array();
                     foreach (Admin_DA::fromCache('getEntitiesStats', $aParams + $this->aDates) as $v) {
                         $aPlacements[$v['placement_id']] = true;
                     }
                     $params = $this->aPageParams;
                     $campaigns = Admin_DA::getPlacements(array(), false);
                     foreach ($campaigns as $campaign) {
                         if (isset($aPlacements[$campaign['placement_id']])) {
                             $params['campaignid'] = $campaign['placement_id'];
                             phpAds_PageContext(MAX_buildName($campaign['placement_id'], $campaign['name']), $this->_addPageParamsToURI($this->pageName, $params, true), $current_id == $campaign['placement_id']);
                         }
                     }
                 }
                 break;
             case 'zones':
                 $aParams['publisher_id'] = $this->aPageParams['affiliateid'];
                 $params = $this->aPageParams;
                 $zones = Admin_DA::getZones($aParams, false);
                 foreach ($zones as $zone) {
                     $params['zoneid'] = $zone['zone_id'];
                     phpAds_PageContext(MAX_buildName($zone['zone_id'], $zone['name']), $this->_addPageParamsToURI($this->pageName, $params, true), $current_id == $zone['zone_id']);
                 }
                 break;
         }
     }
 }
Esempio n. 12
0
 /**
  * Fetch the history stats using the specified parameters
  *
  * @param array  $aParams Query parameters
  * @param string $link    Optional link for the leftmost column content
  */
 function getHistory($aParams, $link = '')
 {
     $oNow = new Date();
     $aParams['tz'] = $oNow->tz->getID();
     $method = $this->oHistory->setBreakdownInfo($this);
     // Add plugin aParams
     $pluginParams = array();
     foreach ($this->aPlugins as $oPlugin) {
         $oPlugin->addQueryParams($pluginParams);
     }
     $aStats = Admin_DA::fromCache($method, $aParams + $this->aDates + $pluginParams);
     // Merge plugin additional $oPlugin
     foreach ($this->aPlugins as $oPlugin) {
         $oPlugin->mergeData($aStats, $this->aEmptyRow, $method, $aParams + $this->aDates);
     }
     if (count($aStats) == 0) {
         $this->noStatsAvailable = true;
         return $aStats;
     }
     // Fill unused plugins columns
     foreach (array_keys($aStats) as $k) {
         $aStats[$k] += $this->aEmptyRow;
     }
     $aDates = $this->oHistory->getDatesArray($this->aDates, $this->statsBreakdown, $this->oStartDate);
     $this->oHistory->fillGapsAndLink($aStats, $aDates, $this, $link);
     if (!in_array($this->listOrderField, array_merge(array($this->statsBreakdown), array_keys($this->aColumns)))) {
         $this->listOrderField = $this->statsBreakdown;
         $this->listOrderDirection = $this->statsBreakdown == 'hour' || $this->statsBreakdown == 'dow' ? 'up' : 'down';
     }
     // If required, re-format the data in the weekly breakdown format
     if ($this->statsBreakdown == 'week') {
         $this->oHistory->prepareWeekBreakdown($aStats, $this);
     }
     MAX_sortArray($aStats, $this->listOrderField, $this->listOrderDirection == 'up');
     // Summarise the values into a the totals array, & format
     $this->_summariseTotalsAndFormat($aStats, true);
     return $aStats;
 }