16 define(
'OJS_METRIC_TYPE_LEGACY_COUNTER',
'ojs::legacyCounterPlugin');
18 define(
'COUNTER_CLASS_SUFFIX',
'.inc.php');
20 import(
'lib.pkp.classes.plugins.ReportPlugin');
21 import(
'plugins.reports.counter.classes.CounterReport');
28 function register($category, $path, $mainContextId =
null) {
29 $success = parent::register($category, $path, $mainContextId);
40 $localeFilenames = parent::getLocaleFilename($locale);
42 foreach (glob($this->
getPluginPath() . DIRECTORY_SEPARATOR .
'locale' . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR .
'*.xml') as $file) {
43 if (!in_array($file, $localeFilenames)) {
44 $localeFilenames[] = $file;
47 return $localeFilenames;
54 return 'CounterReportPlugin';
61 return __(
'plugins.reports.counter');
68 return __(
'plugins.reports.counter.description');
86 $prefix = $this->
getReportPath().DIRECTORY_SEPARATOR.COUNTER_CLASS_PREFIX;
87 $suffix = COUNTER_CLASS_SUFFIX;
88 foreach (glob($prefix.
'*'.$suffix) as $file) {
89 $report_name = substr($file, strlen($prefix), -strlen($suffix));
90 $report_class_file = substr($file, strlen($prefix), -strlen(COUNTER_CLASS_SUFFIX));
91 $reports[$report_name] = $report_class_file;
104 $reportClass = COUNTER_CLASS_PREFIX.$report;
105 $reportClasspath =
'plugins.reports.counter.classes.reports.';
106 $reportPath = str_replace(
'.', DIRECTORY_SEPARATOR, $reportClasspath);
107 if (file_exists($reportPath.$reportClass.COUNTER_CLASS_SUFFIX)) {
108 import($reportPath.$reportClass);
109 $reporter =
new $reportClass($release);
120 return $this->
getPluginPath() . DIRECTORY_SEPARATOR .
'classes';
129 return $this->
getClassPath().DIRECTORY_SEPARATOR.
'reports';
137 import(
'classes.statistics.StatisticsHelper');
142 $type = (string)
$request->getUserVar(
'type');
152 import(
'plugins.reports.counter.classes.LegacyJR1');
159 $release =
$request->getUserVar(
'release');
160 $report =
$request->getUserVar(
'report');
161 $year =
$request->getUserVar(
'year');
162 if ($release && $report && $year) {
164 if ($release == $this->
getCurrentRelease() && isset($available[$report]) && in_array($year, $years)) {
169 $reportItems = $reporter->getReportItems(array(), array(STATISTICS_DIMENSION_MONTH => array(
'from' => $year.
'01',
'to' => $year.
'12')));
171 $xmlResult = $reporter->createXML($reportItems);
173 header(
'content-type: text/xml');
174 header(
'content-disposition: attachment; filename=counter-'. $release .
'-' . $report .
'-' . date(
'Ymd') .
'.xml');
178 $errormessage = __(
'plugins.reports.counter.error.noXML');
181 $errormessage = __(
'plugins.reports.counter.error.noResults');
187 if (!$errormessage) {
188 $errormessage = __(
'plugins.reports.counter.error.badParameters');
191 if (!$errormessage) {
192 $errormessage = __(
'plugins.reports.counter.error.badRequest');
195 import(
'classes.notification.NotificationManager');
197 $notificationManager->createTrivialNotification($user->getId(), NOTIFICATION_TYPE_ERROR, array(
'contents' => $errormessage));
203 $templateManager->assign(
'pluginName', $this->
getName());
204 $templateManager->assign(
'available', $available);
206 $templateManager->assign(
'years', $years);
209 if (!empty($legacyYears)) $templateManager->assign(
'legacyYears', $legacyYears);
210 $templateManager->assign(
'pageTitle', __(
'plugins.reports.counter'));
220 if ($useLegacyStats) {
221 $metricType = OJS_METRIC_TYPE_LEGACY_COUNTER;
224 $metricType = METRIC_TYPE_COUNTER;
225 $filter = array(STATISTICS_DIMENSION_ASSOC_TYPE => ASSOC_TYPE_SUBMISSION_FILE);
228 $results = $metricsDao->getMetrics($metricType, array(STATISTICS_DIMENSION_MONTH), $filter);
230 foreach($results as $record) {
231 $year = substr($record[
'month'], 0, 4);
232 if (in_array($year, $years))
continue;