Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
PKPUsageStatsReportPlugin.inc.php
1 <?php
2 
17 import('lib.pkp.classes.plugins.ReportPlugin');
18 
19 abstract class PKPUsageStatsReportPlugin extends ReportPlugin {
20 
24  function register($category, $path) {
25  $success = parent::register($category, $path);
26  $this->addLocaleData();
27  return $success;
28  }
29 
33  function getName() {
34  return 'usageStatsReportPlugin';
35  }
36 
40  function getDisplayName() {
41  return __('plugins.reports.usageStats.report.displayName');
42  }
43 
47  function getDescription() {
48  return __('plugins.reports.usageStats.report.description');
49  }
50 
54  function display($args, $request) {
55  parent::display($args);
56  $router = $request->getRouter();
57  $context = $router->getContext($request);
58 
59  $metricType = $this->getMetricTypes();
60 
61  import('classes.statistics.StatisticsHelper');
62  $statsHelper = new StatisticsHelper();
63  $columns = array_keys($statsHelper->getColumnNames());
64 
65  $reportArgs = array(
66  'metricType' => $metricType,
67  'columns' => $columns,
68  'filters' => serialize(array(STATISTICS_DIMENSION_CONTEXT_ID => $context->getId())),
69  'orderBy' => serialize(array(STATISTICS_DIMENSION_MONTH => STATISTICS_ORDER_ASC))
70  );
71 
72  Request::redirect(null, null, 'tools', 'generateReport', $reportArgs);
73  }
74 
78  function getMetrics($metricType = null, $columns = null, $filters = null, $orderBy = null, $range = null) {
79  // This plug-in uses the MetricsDAO to store metrics. So we simply
80  // delegate there.
81  $metricsDao = DAORegistry::getDAO('MetricsDAO'); /* @var $metricsDao MetricsDAO */
82  return $metricsDao->getMetrics($metricType, $columns, $filters, $orderBy, $range);
83  }
84 
88  function getMetricDisplayType($metricType) {
89  return __('plugins.reports.usageStats.metricType');
90  }
91 
95  function getMetricFullName($metricType) {
96  return __('plugins.reports.usageStats.metricType.full');
97  }
98 
102  function getDefaultReportTemplates($metricTypes = null) {
103  $reports = array();
104  $pluginMetricTypes = $this->getMetricTypes();
105 
106  if (is_null($metricTypes)) $metricTypes = $pluginMetricTypes;
107  if (!is_array($metricTypes)) $metricTypes = array($metricTypes);
108 
109  // Check if the plugin supports the passed metric types.
110  $intersection = array_intersect($metricTypes, $pluginMetricTypes);
111  if (empty($intersection)) return $reports;
112 
113  // Context index page views.
114  $columns = array(STATISTICS_DIMENSION_ASSOC_TYPE,
115  STATISTICS_DIMENSION_CONTEXT_ID,
116  STATISTICS_DIMENSION_MONTH,
117  STATISTICS_DIMENSION_COUNTRY);
118 
119  $filter = array(STATISTICS_DIMENSION_ASSOC_TYPE => Application::getContextAssocType());
120 
121  // We allow the subclasses to define the name locale key.
122  $reports[] = array('nameLocaleKey' => '',
123  'metricType' => $metricTypes, 'columns' => $columns, 'filter' => $filter,
124  'aggregationColumns' => $this->getAggregationColumns());
125 
126  return $reports;
127  }
128 
129 
130  //
131  // Protected methods.
132  //
139  protected function getAggregationColumns() {
140  return array(STATISTICS_DIMENSION_COUNTRY,
141  STATISTICS_DIMENSION_REGION,
142  STATISTICS_DIMENSION_CITY,
143  STATISTICS_DIMENSION_MONTH,
144  STATISTICS_DIMENSION_DAY);
145  }
146 }
147 
148 ?>
static & getDAO($name, $dbconn=null)
redirect($context=null, $page=null, $op=null, $path=null, $params=null, $anchor=null)
Abstract class for report plugins.
getMetrics($metricType=null, $columns=null, $filters=null, $orderBy=null, $range=null)
static getContextAssocType()
addLocaleData($locale=null)
Definition: Plugin.inc.php:347
Statistics helper class.
OJS default statistics report plugin (and metrics provider)