15 import(
'plugins.reports.counter.classes.CounterReport');
23 return __(
'plugins.reports.counter.jr1.title');
35 function getReportItems($columns = array(), $filters = array(), $orderBy = array(), $range =
null) {
39 $defaultColumns = array(STATISTICS_DIMENSION_MONTH, STATISTICS_DIMENSION_FILE_TYPE, STATISTICS_DIMENSION_CONTEXT_ID);
40 if ($columns && array_diff($columns, $defaultColumns)) {
41 $this->
setError(
new Exception(__(
'plugins.reports.counter.exception.column'), COUNTER_EXCEPTION_WARNING | COUNTER_EXCEPTION_BAD_COLUMNS));
46 if (!isset($filters[STATISTICS_DIMENSION_MONTH]) && !isset($filters[STATISTICS_DIMENSION_DAY])) {
47 $validFilters[STATISTICS_DIMENSION_MONTH] = array(
48 'from' => date_format(date_create(
"first day of previous month"),
'Ymd'),
49 'to' => date_format(date_create(
"last day of previous month"),
'Ymd')
51 } elseif (isset($filters[STATISTICS_DIMENSION_MONTH])) {
52 $validFilters[STATISTICS_DIMENSION_MONTH] = $filters[STATISTICS_DIMENSION_MONTH];
53 unset($filters[STATISTICS_DIMENSION_MONTH]);
54 } elseif (isset($filters[STATISTICS_DIMENSION_DAY])) {
55 $validFilters[STATISTICS_DIMENSION_DAY] = $filters[STATISTICS_DIMENSION_DAY];
56 unset($filters[STATISTICS_DIMENSION_DAY]);
58 if (!isset($filters[STATISTICS_DIMENSION_ASSOC_TYPE])) {
59 $validFilters[STATISTICS_DIMENSION_ASSOC_TYPE] = ASSOC_TYPE_SUBMISSION_FILE;
60 unset($filters[STATISTICS_DIMENSION_ASSOC_TYPE]);
61 } elseif ($filters[STATISTICS_DIMENSION_ASSOC_TYPE] != ASSOC_TYPE_SUBMISSION_FILE) {
62 $this->
setError(
new Exception(__(
'plugins.reports.counter.exception.filter'), COUNTER_EXCEPTION_ERROR | COUNTER_EXCEPTION_BAD_FILTERS));
65 if (array_keys($filters)) {
66 $this->
setError(
new Exception(__(
'plugins.reports.counter.exception.filter'), COUNTER_EXCEPTION_WARNING | COUNTER_EXCEPTION_BAD_FILTERS));
69 $metricType = METRIC_TYPE_COUNTER;
71 $validOrder = array(STATISTICS_DIMENSION_CONTEXT_ID => STATISTICS_ORDER_DESC, STATISTICS_DIMENSION_MONTH => STATISTICS_ORDER_ASC);
73 $results = $metricsDao->getMetrics($metricType, $defaultColumns, $validFilters, $validOrder);
74 $reportItems = array();
82 foreach ($results as $rs) {
86 if ($lastPeriod != $rs[STATISTICS_DIMENSION_MONTH] || $lastJournal != $rs[STATISTICS_DIMENSION_CONTEXT_ID]) {
87 if ($lastPeriod != 0) {
92 $lastPeriod = $rs[STATISTICS_DIMENSION_MONTH];
95 if ($lastJournal != $rs[STATISTICS_DIMENSION_CONTEXT_ID]) {
96 if ($lastJournal != 0 && $metrics) {
97 $item = $this->_createReportItem($lastJournal, $metrics);
99 $reportItems[] = $item;
101 $this->
setError(
new Exception(__(
'plugins.reports.counter.exception.partialData'), COUNTER_EXCEPTION_WARNING | COUNTER_EXCEPTION_PARTIAL_DATA));
106 $lastJournal = $rs[STATISTICS_DIMENSION_CONTEXT_ID];
113 $item = $this->_createReportItem($lastJournal, $metrics);
115 $reportItems[] = $item;
117 $this->
setError(
new Exception(__(
'plugins.reports.counter.exception.partialData'), COUNTER_EXCEPTION_WARNING | COUNTER_EXCEPTION_PARTIAL_DATA));
121 $this->
setError(
new Exception(__(
'plugins.reports.counter.exception.noData'), COUNTER_EXCEPTION_ERROR | COUNTER_EXCEPTION_NO_DATA));
132 private function _createReportItem($journalId, $metrics) {
134 $journal = $journalDao->getById($journalId);
138 $journalName = $journal->getLocalizedName();
139 $journalPubIds = array();
140 foreach (array(
'print',
'online') as $issnType) {
141 if ($journal->getData($issnType.
'Issn')) {
143 $journalPubIds[] =
new COUNTER\Identifier(ucfirst($issnType).
'_ISSN', $journal->getData($issnType.
'Issn'));
144 }
catch (Exception $ex) {
149 $journalPubIds[] =
new COUNTER\Identifier(COUNTER_LITERAL_PROPRIETARY, $journal->getPath());
150 $reportItem = array();
152 $reportItem =
new COUNTER\ReportItems(__(
'common.software'), $journalName, COUNTER_LITERAL_JOURNAL, $metrics, NULL, $journalPubIds);
153 }
catch (Exception $e) {
154 $this->
setError($e, COUNTER_EXCEPTION_ERROR | COUNTER_EXCEPTION_INTERNAL);