15 import(
'plugins.reports.counter.classes.CounterReport');
23 return __(
'plugins.reports.counter.ar1.title');
35 function getReportItems($columns = array(), $filters = array(), $orderBy = array(), $range =
null) {
39 $defaultColumns = array(STATISTICS_DIMENSION_MONTH, STATISTICS_DIMENSION_SUBMISSION_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 foreach ($filters as $key => $filter) {
67 case STATISTICS_DIMENSION_CONTEXT_ID:
68 case STATISTICS_DIMENSION_ISSUE_ID:
69 case STATISTICS_DIMENSION_SUBMISSION_ID:
70 $validFilters[$key] = $filter;
71 unset($filters[$key]);
75 if (array_keys($filters)) {
76 $this->
setError(
new Exception(__(
'plugins.reports.counter.exception.filter'), COUNTER_EXCEPTION_WARNING | COUNTER_EXCEPTION_BAD_FILTERS));
79 $metricType = METRIC_TYPE_COUNTER;
81 $validOrder = array(STATISTICS_DIMENSION_SUBMISSION_ID => STATISTICS_ORDER_DESC, STATISTICS_DIMENSION_MONTH => STATISTICS_ORDER_ASC);
83 $results = $metricsDao->getMetrics($metricType, $defaultColumns, $validFilters, $validOrder);
84 $reportItems = array();
89 foreach ($results as $rs) {
91 if ($lastArticle != $rs[STATISTICS_DIMENSION_SUBMISSION_ID]) {
92 if ($lastArticle != 0 && $metrics) {
93 $item = $this->_createReportItem($lastArticle, $metrics);
95 $reportItems[] = $item;
97 $this->
setError(
new Exception(__(
'plugins.reports.counter.exception.partialData'), COUNTER_EXCEPTION_WARNING | COUNTER_EXCEPTION_PARTIAL_DATA));
102 $metrics[] = $this->
createMetricByMonth($rs[STATISTICS_DIMENSION_MONTH], array(
new COUNTER\PerformanceCounter(
'ft_total', $rs[STATISTICS_METRIC])));
103 $lastArticle = $rs[STATISTICS_DIMENSION_SUBMISSION_ID];
107 $item = $this->_createReportItem($lastArticle, $metrics);
109 $reportItems[] = $item;
111 $this->
setError(
new Exception(__(
'plugins.reports.counter.exception.partialData'), COUNTER_EXCEPTION_WARNING | COUNTER_EXCEPTION_PARTIAL_DATA));
115 $this->
setError(
new Exception(__(
'plugins.reports.counter.exception.noData'), COUNTER_EXCEPTION_ERROR | COUNTER_EXCEPTION_NO_DATA));
126 private function _createReportItem($submissionId, $metrics) {
128 $article = $submissionDao->getById($submissionId);
132 $title = $article->getLocalizedTitle();
133 $journalId = $article->getContextId();
135 $journal = $journalDao->getById($journalId);
139 $journalName = $journal->getLocalizedName();
140 $journalPubIds = array();
141 foreach (array(
'print',
'online') as $issnType) {
142 if ($journal->getData($issnType.
'Issn')) {
144 $journalPubIds[] =
new COUNTER\Identifier(ucfirst($issnType).
'_ISSN', $journal->getData($issnType.
'Issn'));
145 }
catch (Exception $ex) {
150 $journalPubIds[] =
new COUNTER\Identifier(COUNTER_LITERAL_PROPRIETARY, $journal->getPath());
152 $articlePubIds = array();
153 $articlePubIds[] =
new COUNTER\Identifier(COUNTER_LITERAL_PROPRIETARY, $submissionId);
154 foreach ($pubIdPlugins as $pubIdPlugin) {
155 $pubId = $article->getStoredPubId($pubIdPlugin->getPubIdType(),
true);
157 switch ($pubIdPlugin->getPubIdType()) {
160 $articlePubIds[] =
new COUNTER\Identifier(strtoupper($pubIdPlugin->getPubIdType()), $pubId);
161 }
catch (Exception $ex) {
169 $reportItem = array();
172 __(
'common.software'),
174 COUNTER_LITERAL_ARTICLE,
176 new COUNTER\ParentItem($journalName, COUNTER_LITERAL_JOURNAL, $journalPubIds),
179 }
catch (Exception $e) {
180 $this->
setError($e, COUNTER_EXCEPTION_ERROR | COUNTER_EXCEPTION_INTERNAL);