27 $this->_plugin = $plugin;
35 $oldStats = (boolean) $request->getUserVar(
'useOldCounterStats');
36 $year = (string) $request->getUserVar(
'year');
37 $type = (string) $request->getUserVar(
'type');
40 $this->
_report($request, $year, $oldStats);
43 $this->_reportXml($request, $year, $oldStats);
54 function _report($request, $year, $useLegacyStats) {
55 $journal = $request->getContext();
58 header(
'content-type: text/comma-separated-values');
59 header(
'content-disposition: attachment; filename=counter-' . date(
'Ymd') .
'.csv');
61 $fp = fopen(
'php://output',
'wt');
62 fputcsv($fp, array(__(
'plugins.reports.counter.1a.title1')));
63 fputcsv($fp, array(__(
'plugins.reports.counter.1a.title2', array(
'year' => $year))));
64 fputcsv($fp, array());
65 fputcsv($fp, array(__(
'plugins.reports.counter.1a.dateRun')));
66 fputcsv($fp, array(strftime(
"%Y-%m-%d")));
70 __(
'plugins.reports.counter.1a.publisher'),
71 __(
'plugins.reports.counter.1a.platform'),
72 __(
'plugins.reports.counter.1a.printIssn'),
73 __(
'plugins.reports.counter.1a.onlineIssn')
75 for ($i=1; $i<=12; $i++) {
76 $time = strtotime($year .
'-' . $i .
'-01');
77 strftime(
'%b', $time);
78 $cols[] = strftime(
'%b-%Y', $time);
81 $cols[] = __(
'plugins.reports.counter.1a.ytdTotal');
82 $cols[] = __(
'plugins.reports.counter.1a.ytdHtml');
83 $cols[] = __(
'plugins.reports.counter.1a.ytdPdf');
89 __(
'plugins.reports.counter.1a.totalForAllJournals'),
101 foreach ($journalIds as $journalId) {
102 $journal = $journalDao->getById($journalId);
103 if (!$journal)
continue;
106 $journal->getLocalizedName(),
107 $journal->getData(
'publisherInstitution'),
108 __(
'common.software'),
109 $journal->getData(
'printIssn'),
110 $journal->getData(
'onlineIssn')
114 unset($journal, $entry);
131 for ($i = 1; $i <= 12; $i++) {
133 foreach ($entries as $entry) {
134 $month = (int) substr($entry[STATISTICS_DIMENSION_MONTH], 4, 2);
136 $metric = $entry[STATISTICS_METRIC];
137 $currTotal += $metric;
138 if ($entry[STATISTICS_DIMENSION_FILE_TYPE] == STATISTICS_FILE_TYPE_HTML) {
139 $htmlTotal += $metric;
140 }
else if ($entry[STATISTICS_DIMENSION_FILE_TYPE] == STATISTICS_FILE_TYPE_PDF) {
141 $pdfTotal += $metric;
146 $allMonthsTotal += $currTotal;
148 $cols[] = $allMonthsTotal;
149 $cols[] = $htmlTotal;
162 $journal = $request->getContext();
167 $site = $request->getSite();
168 $availableContexts = $journalDao->getAvailable();
169 if ($availableContexts->getCount() > 1) {
170 $vendorName = $site->getLocalizedTitle();
172 $vendorName = $journal->getData(
'publisherInstitution');
173 if (empty($vendorName)) {
174 $vendorName = $journal->getLocalizedName();
178 if ($end ==
'') $end = $begin;
182 foreach ($journalIds as $journalId) {
183 $journal = $journalDao->getById($journalId);
184 if (!$journal)
continue;
188 $journalsArray[$i][
'journalTitle'] = $journal->getLocalizedName();
189 $journalsArray[$i][
'publisherInstitution'] = $journal->getData(
'publisherInstitution');
190 $journalsArray[$i][
'printIssn'] = $journal->getData(
'printIssn');
191 $journalsArray[$i][
'onlineIssn'] = $journal->getData(
'onlineIssn');
197 $reqUser = $request->getUser();
199 $templateManager->assign(
'reqUserName', $reqUser->getUsername());
200 $templateManager->assign(
'reqUserId', $reqUser->getId());
202 $templateManager->assign(
'reqUserName', __(
'plugins.reports.counter.1a.anonymous'));
203 $templateManager->assign(
'reqUserId',
'');
206 $templateManager->assign(
'journalsArray', $journalsArray);
208 $templateManager->assign(
'vendorName', $vendorName);
209 $templateManager->assign(
'base_url', $base_url);
221 foreach ($entries as $entry) {
222 $year = substr($entry[
'month'], 0, 4);
223 $month = substr($entry[
'month'], 4, 2);
224 $start = date(
"Y-m-d", mktime(0, 0, 0, $month, 1, $year));
225 $end = date(
"Y-m-t", mktime(0, 0, 0, $month, 1, $year));
227 $rangeExists =
false;
228 foreach ($ret as $key => $record) {
229 if ($record[
'start'] == $start && $record[
'end'] == $end) {
239 $ret[$workingKey][
'start'] = $start;
240 $ret[$workingKey][
'end'] = $end;
245 if (array_key_exists(
'count_total', $ret[$workingKey])) {
246 $totalCount = $ret[$workingKey][
'count_total'];
250 $ret[$workingKey][
'count_total'] = $entry[STATISTICS_METRIC] + $totalCount;
251 if ($entry[STATISTICS_DIMENSION_FILE_TYPE] == STATISTICS_FILE_TYPE_HTML) {
252 $ret[$workingKey][
'count_html'] = $entry[STATISTICS_METRIC];
253 }
else if ($entry[STATISTICS_DIMENSION_FILE_TYPE] == STATISTICS_FILE_TYPE_PDF) {
254 $ret[$workingKey][
'count_pdf'] = $entry[STATISTICS_METRIC];
268 $begin =
"$year-01-01";
269 $end =
"$year-12-01";
271 return array($begin, $end);
281 if ($useLegacyStats) {
282 $results = $metricsDao->getMetrics(OJS_METRIC_TYPE_LEGACY_COUNTER, array(STATISTICS_DIMENSION_ASSOC_ID));
283 $fieldId = STATISTICS_DIMENSION_ASSOC_ID;
285 $filter = array(STATISTICS_DIMENSION_ASSOC_TYPE => ASSOC_TYPE_SUBMISSION_FILE);
286 $results = $metricsDao->getMetrics(METRIC_TYPE_COUNTER, array(STATISTICS_DIMENSION_CONTEXT_ID), $filter);
287 $fieldId = STATISTICS_DIMENSION_CONTEXT_ID;
289 $journalIds = array();
290 foreach($results as $record) {
291 $journalIds[] = $record[$fieldId];
305 $begin = date(
'Ym', strtotime($begin));
306 $end = date(
'Ym', strtotime($end));
309 $columns = array(STATISTICS_DIMENSION_MONTH, STATISTICS_DIMENSION_FILE_TYPE);
311 STATISTICS_DIMENSION_MONTH => array(
'from' => $begin,
'to' => $end)
314 if ($useLegacyStats) {
315 $dimension = STATISTICS_DIMENSION_ASSOC_ID;
316 $metricType = OJS_METRIC_TYPE_LEGACY_COUNTER;
318 $dimension = STATISTICS_DIMENSION_CONTEXT_ID;
319 $metricType = METRIC_TYPE_COUNTER;
320 $filter[STATISTICS_DIMENSION_ASSOC_TYPE] = ASSOC_TYPE_SUBMISSION_FILE;
324 $columns[] = $dimension;
325 $filter[$dimension] = $journalId;
328 $results = $metricsDao->getMetrics($metricType, $columns, $filter);
350 function _reportXML($request, $year, $useLegacyStats) {
355 $reportContents = $templateManager->fetch($this->_plugin->getTemplateResource(
'reportxml.tpl'));
356 header(
'Content-type: text/xml');
357 echo $reportContents;