function test_instantiateController() { $file = MAX_PATH . '/lib/OA/Admin/Statistics/Delivery/Common.php'; $aParams = array(); $class = 'OA_Admin_Statistics_Delivery_Common'; $oObject =& OA_Admin_Statistics_Factory::_instantiateController($file, $class, $aParams); $this->assertIsA($oObject, $class); $this->assertEqual(count($oObject->aPlugins), 2); $this->assertTrue(isset($oObject->aPlugins['default'])); $this->assertTrue(isset($oObject->aPlugins['affiliates'])); $file = MAX_PATH . '/lib/OA/Admin/Statistics/tests/data/TestStatisticsController.php'; $aParams = array(); $class = 'OA_Admin_Statistics_Test'; $oObject =& OA_Admin_Statistics_Factory::_instantiateController($file, $class, $aParams); $this->assertIsA($oObject, $class); // Disable default error handling PEAR::pushErrorHandling(null); // Test _instantiateController for not existing controller $file = MAX_PATH . '/lib/OA/Admin/Statistics/tests/data/TestNotExists.php'; $aParams = array(); $class = 'OA_Admin_Statistics_Test'; $oObject =& OA_Admin_Statistics_Factory::_instantiateController($file, $class, $aParams); $this->assertTrue(PEAR::isError($oObject)); $this->assertEqual($oObject->getMessage(), 'OA_Admin_Statistics_Factory::_instantiateController() Unable to locate ' . basename($file)); // Test _instantiateController for not existing class $file = MAX_PATH . '/lib/OA/Admin/Statistics/tests/data/TestStatisticsController.php'; $aParams = array(); $class = 'OA_Admin_not_exists'; $oObject =& OA_Admin_Statistics_Factory::_instantiateController($file, $class, $aParams); $this->assertTrue(PEAR::isError($oObject)); $this->assertEqual($oObject->getMessage(), 'OA_Admin_Statistics_Factory::_instantiateController() Class ' . $class . ' doesn\'t exist'); // Restore default error handling PEAR::popErrorHandling(); }
/** * Create a new object of the appropriate OA_Admin_Statistics_Common subclass. * * @static * @param string $controllerType The controller type (e.g. "global-advertiser"). * @param array $aParams An array of parameters to be passed as the parameter * to the constructor of the class instantiated. * @return OA_Admin_Statistics_Common The instantiated class that inherits from * OA_Admin_Statistics_Common. */ function &getController($controllerType = '', $aParams = null) { // Instantiate & return the required statistics class $result = OA_Admin_Statistics_Factory::_getControllerClass($controllerType, $aParams, $class, $file); if (PEAR::isError($result)) { return $result; } // To allow catch errors and pass it out without calling error handler PEAR::pushErrorHandling(null); $oStatsController = OA_Admin_Statistics_Factory::_instantiateController($file, $class, $aParams); PEAR::popErrorHandling(); return $oStatsController; }
/** * A method to obtain statistics for reports from the same statistics controllers * that are used in the UI, but without formatting or paging data, and return * the section headers and data independently. * * @param string $controllerType The required OA_Admin_Statistics_Common type. * @param OA_Admin_Statistics_Common $oStatsController An optional parameter to pass in a * ready-prepared stats controller object, to be used instead of creating * and populating the stats. * @return array An array containing headers (key 0) and data (key 1) */ function getHeadersAndDataFromStatsController($controllerType, $oStatsController = null) { if (is_null($oStatsController)) { $oStatsController =& OA_Admin_Statistics_Factory::getController($controllerType, array('skipFormatting' => true, 'disablePager' => true)); if (PEAR::isError($oStatsController)) { return array('Unkcown Stats Controller ', array($oStatsController->getMessage())); } $oStatsController->start(); } $aStats = $oStatsController->exportArray(); $aHeaders = array(); foreach ($aStats['headers'] as $k => $v) { switch ($aStats['formats'][$k]) { case 'default': $aHeaders[$v] = 'numeric'; break; case 'currency': $aHeaders[$v] = 'decimal'; break; case 'percent': case 'date': case 'time': $aHeaders[$v] = $aStats['formats'][$k]; break; case 'text': default: $aHeaders[$v] = 'text'; break; } } $aData = array(); foreach ($aStats['data'] as $i => $aRow) { foreach ($aRow as $k => $v) { $aData[$i][] = $aStats['formats'][$k] == 'datetime' ? $this->_oReportWriter->convertToDate($v) : $v; } } return array($aHeaders, $aData); }
protected function getController() { if (empty($this->breakDown)) { throw new Exception("Cannot use the base class directly"); } $aBackup = array($_REQUEST, $GLOBALS['_MAX']['PREF'], $GLOBALS['date_format'], $GLOBALS['month_format']); $GLOBALS['date_format'] = '%Y-%m-%d'; $GLOBALS['month_format'] = '%Y-%m'; $_REQUEST = array('period_preset' => 'specific', 'period_start' => $this->oStart->format('%Y-%m-%d'), 'period_end' => $this->oEnd->format('%Y-%m-%d'), 'statsBreakdown' => $this->breakDown, 'listorder' => $this->breakDown, 'orderdirection' => 'up'); $_REQUEST += $this->aEntityParams; // Prepare the parameters for display or export to XLS $aParams = array('skipFormatting' => true, 'disablePager' => true); foreach ($GLOBALS['_MAX']['PREF'] as $k => &$v) { if (preg_match('/^ui_column_/', $k)) { if (!preg_match('/(_rank|_label)$/', $k)) { $v = false; } } } $GLOBALS['_MAX']['PREF']['ui_column_impressions'] = true; $GLOBALS['_MAX']['PREF']['ui_column_impressions_rank'] = 1; $GLOBALS['_MAX']['PREF']['ui_column_clicks'] = true; $GLOBALS['_MAX']['PREF']['ui_column_clicks_rank'] = 2; $GLOBALS['_MAX']['PREF']['ui_column_ctr'] = true; $GLOBALS['_MAX']['PREF']['ui_column_ctr_rank'] = 3; // Prepare the stats controller, and populate with the stats $oStatsController = OA_Admin_Statistics_Factory::getController($this->entity . '-history', $aParams); if (PEAR::isError($oStatsController)) { throw new Exception($oStatsController->getMessage()); } $oStatsController->start(); list($_REQUEST, $GLOBALS['_MAX']['PREF'], $GLOBALS['date_format'], $GLOBALS['month_format']) = $aBackup; return $oStatsController; }
} if (!isset($entity)) { $entity = 'global'; } if (!isset($breakdown)) { $breakdown = 'advertiser'; } // Add all manipulated values to globals $_REQUEST['zoneid'] = $zoneid; $_REQUEST['affiliateid'] = $affiliateid; $_REQUEST['bannerid'] = $bannerid; $_REQUEST['campaignid'] = $campaignid; $_REQUEST['clientid'] = $clientid; // Overwirte file name to load right session data, see MAX_getStoredValue $pgName = 'stats.php'; $oStats =& OA_Admin_Statistics_Factory::getController($entity . "-" . $breakdown); if (PEAR::isError($oStats)) { phpAds_Die('Error occurred', htmlspecialchars($oStats->getMessage())); } $oStats->noFormat = true; $oStats->start(); // Output html code $oStats->output(true); // Erase stats graph file if (isset($GraphFile) && $GraphFile != '') { $dirObject = dir($conf['store']['webDir'] . '/temp'); while (false !== ($entry = $dirObject->read())) { if (filemtime($conf['store']['webDir'] . '/temp/' . $entry) + 60 < time()) { unlink($conf['store']['webDir'] . '/temp/' . $entry); } }
$_REQUEST['clientid'] = $clientid; $_REQUEST['day'] = $day; $_REQUEST['listorder'] = $listorder; $_REQUEST['orderdirection'] = $orderdirection; // If displaying conversion statistics, hand over control to a different file if ($entity == 'conversions') { include_once MAX_PATH . '/www/admin/stats-conversions.php'; exit; } // Prepare the parameters for display or export to XLS $aParams = null; if (isset($plugin) && $plugin != '') { $aParams = array('skipFormatting' => true, 'disablePager' => true); } // Prepare the stats controller, and populate with the stats $oStatsController =& OA_Admin_Statistics_Factory::getController($entity . "-" . $breakdown, $aParams); if (PEAR::isError($oStatsController)) { phpAds_Die('Error occured', htmlspecialchars($oStatsController->getMessage())); } $oStatsController->start(); // Export to XLS... if (isset($plugin) && $plugin != '') { require_once MAX_PATH . '/lib/OA/Admin/Reports/Export.php'; $oModule = new OA_Admin_Reports_Export($oStatsController); $oModule->export(); } // ... otherwise, output in HTML $oStatsController->output(); // Erase stats graph file if (isset($GraphFile) && $GraphFile != '') { $dirObject = dir($conf['store']['webDir'] . '/temp');