1 |
35459
|
argiro.kok
|
<?php
|
2 |
|
|
|
3 |
|
|
defined('_JEXEC') or die('Access denied');
|
4 |
|
|
|
5 |
|
|
jimport('joomla.application.component.helper');
|
6 |
|
|
jimport('joomla.application.component.model');
|
7 |
|
|
jimport('joomla.base.object');
|
8 |
|
|
jimport('joomla.cache.cache');
|
9 |
|
|
jimport('joomla.log.log');
|
10 |
|
|
|
11 |
|
|
$GLOBALS['THRIFT_ROOT'] = dirname(__FILE__) . DS . 'thrift';
|
12 |
|
|
require_once($GLOBALS['THRIFT_ROOT'] . DS . 'Thrift.php');
|
13 |
|
|
require_once($GLOBALS['THRIFT_ROOT'] . DS . 'protocol' . DS . 'TBinaryProtocol.php');
|
14 |
|
|
require_once($GLOBALS['THRIFT_ROOT'] . DS . 'transport' . DS . 'TSocket.php');
|
15 |
|
|
require_once($GLOBALS['THRIFT_ROOT'] . DS . 'transport' . DS . 'TBufferedTransport.php');
|
16 |
|
|
require_once($GLOBALS['THRIFT_ROOT'] . DS . 'packages' . DS . 'OpenAIREConnector' . DS . 'OpenAIREConnector.php');
|
17 |
|
|
|
18 |
|
|
// This model manages statistics.
|
19 |
|
|
class OpenAireModelStatistics extends JModelItem {
|
20 |
|
|
const STATISTICS_CACHE_ID = 'statistics';
|
21 |
|
|
const PUBLICATIONS_BY_PROGRAMME_CACHE_ID = 'publications.programme';
|
22 |
|
|
const PUBLICATIONS_BY_SCIENTIFIC_AREA_CACHE_ID = 'publications.scientific.area';
|
23 |
|
|
const PUBLICATIONS_BY_COUNTRY_CACHE_ID = 'publications.country';
|
24 |
|
|
const PUBLICATIONS_BY_INSTITUTION_CACHE_ID = 'publications.institution';
|
25 |
|
|
const CACHE_GROUP = 'openaire.statistics';
|
26 |
|
|
const LOG = 'openaire';
|
27 |
|
|
|
28 |
|
|
private $transport;
|
29 |
|
|
private $client;
|
30 |
|
|
private $cache;
|
31 |
|
|
|
32 |
|
|
// Construct a new OpenAireModelStatistics.
|
33 |
|
|
// $configuration the configuration to use
|
34 |
|
|
public function __construct($configuration) {
|
35 |
|
|
parent :: __construct($configuration);
|
36 |
|
|
$parameters = JComponentHelper :: getParams('com_openaire');
|
37 |
|
|
$socket = new TSocket($parameters -> get('thriftHost'), intval($parameters -> get('thriftPort')));
|
38 |
|
|
$socket -> setRecvTimeout(intval($parameters -> get('thriftTimeout')));
|
39 |
|
|
$this -> transport = new TBufferedTransport($socket);
|
40 |
|
|
$this -> client = new OpenAIREConnectorClient(new TBinaryProtocol($this -> transport));
|
41 |
|
|
$this -> cache = JCache :: getInstance();
|
42 |
|
|
$this -> transport -> open();
|
43 |
|
|
}
|
44 |
|
|
|
45 |
|
|
// Close Thrift transport.
|
46 |
|
|
public function __destruct() {
|
47 |
|
|
$this -> transport -> close();
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
// Retrieve statistics using cache if enabled.
|
51 |
|
|
// return statistics (object)
|
52 |
|
|
public function getStatistics() {
|
53 |
|
|
/*
|
54 |
|
|
if ($this -> cache -> getCaching()) {
|
55 |
|
|
$statistics = $this -> cache -> get(self :: STATISTICS_CACHE_ID, self :: CACHE_GROUP);
|
56 |
|
|
if ($statistics === NULL) {
|
57 |
|
|
$statistics = $this -> _getStatistics();
|
58 |
|
|
$this -> cache -> store($statistics, self :: STATISTICS_CACHE_ID, self :: CACHE_GROUP);
|
59 |
|
|
}
|
60 |
|
|
} else
|
61 |
|
|
*/
|
62 |
|
|
$statistics = $this -> _getStatistics();
|
63 |
|
|
return $statistics;
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
// Retrieve publications by access mode using cache if enabled.
|
67 |
|
|
// return publications by access mode (array)
|
68 |
|
|
public function getPublicationsByAccessMode() {
|
69 |
|
|
/*
|
70 |
|
|
if ($this -> cache -> getCaching()) {
|
71 |
|
|
$publicationsByAccessMode = $this -> cache -> get(self :: PUBLICATIONS_BY_ACCESS_MODE_CACHE_ID, self :: CACHE_GROUP);
|
72 |
|
|
if ($publications === NULL) {
|
73 |
|
|
$publicationsByAccessMode = $this -> _getPublicationsByAccessMode();
|
74 |
|
|
$this -> cache -> store($publicationsByAccessMode, self :: PUBLICATIONS_BY_ACCESS_MODE_CACHE_ID, self :: CACHE_GROUP);
|
75 |
|
|
}
|
76 |
|
|
} else
|
77 |
|
|
*/
|
78 |
|
|
$publicationsByAccessMode = $this -> _getPublicationsByAccessMode();
|
79 |
|
|
return $publicationsByAccessMode;
|
80 |
|
|
}
|
81 |
|
|
|
82 |
|
|
// Retrieve publications by programme using cache if enabled.
|
83 |
|
|
// limit the maximum number of programmes to retrieve
|
84 |
|
|
// return publications by programme (array)
|
85 |
|
|
public function getPublicationsByProgramme($limit) {
|
86 |
|
|
/*
|
87 |
|
|
if ($this -> cache -> getCaching()) {
|
88 |
|
|
$id = self :: PUBLICATIONS_BY_PROGRAMME_CACHE_ID . '.' . $limit;
|
89 |
|
|
$publicationsByProgramme = $this -> cache -> get($id, self :: CACHE_GROUP);
|
90 |
|
|
if ($publicationsByProgramme === NULL) {
|
91 |
|
|
$publicationsByProgramme = $this -> _getPublicationsByProgramme($limit);
|
92 |
|
|
$this -> cache -> store($publicationsByProgramme, $id, self :: CACHE_GROUP);
|
93 |
|
|
}
|
94 |
|
|
} else
|
95 |
|
|
*/
|
96 |
|
|
$publicationsByProgramme = $this -> _getPublicationsByProgramme($limit);
|
97 |
|
|
return $publicationsByProgramme;
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
// Retrieve publications by scientific area using cache if enabled.
|
101 |
|
|
// limit the maximum number of scientific areas to retrieve
|
102 |
|
|
// return publications by scientific area (array)
|
103 |
|
|
public function getPublicationsByScientificArea($limit) {
|
104 |
|
|
/*
|
105 |
|
|
if ($this -> cache -> getCaching()) {
|
106 |
|
|
$id = self :: PUBLICATIONS_BY_SCIENTIFIC_AREA_CACHE_ID . '.' . $limit;
|
107 |
|
|
$publicationsByScientificArea = $this -> cache -> get($id, self :: CACHE_GROUP);
|
108 |
|
|
if ($publicationsByScientificArea === NULL) {
|
109 |
|
|
$publicationsByScientificArea = $this -> _getPublicationsByScientificArea($limit);
|
110 |
|
|
$this -> cache -> store($publicationsByScientificArea, $limit, self :: CACHE_GROUP);
|
111 |
|
|
}
|
112 |
|
|
} else
|
113 |
|
|
*/
|
114 |
|
|
$publicationsByScientificArea = $this -> _getPublicationsByScientificArea($limit);
|
115 |
|
|
return $publicationsByScientificArea;
|
116 |
|
|
}
|
117 |
|
|
|
118 |
|
|
// Retrieve publications by country using cache if enabled.
|
119 |
|
|
// limit the maximum number of countries to retrieve
|
120 |
|
|
// return publications by country (array)
|
121 |
|
|
public function getPublicationsByCountry($limit) {
|
122 |
|
|
/*
|
123 |
|
|
if ($this -> cache -> getCaching()) {
|
124 |
|
|
$id = self :: PUBLICATIONS_BY_COUNTRY_CACHE_ID . '.' . $limit;
|
125 |
|
|
$publicationsByCountry = $this -> cache -> get($id, self :: CACHE_GROUP);
|
126 |
|
|
if ($publicationsByCountry === NULL) {
|
127 |
|
|
$publicationsByCountry = $this -> _getPublicationsByCountry($limit);
|
128 |
|
|
$this -> cache -> store($publicationsByCountry, $id, self :: CACHE_GROUP);
|
129 |
|
|
}
|
130 |
|
|
} else
|
131 |
|
|
*/
|
132 |
|
|
$publicationsByCountry = $this -> _getPublicationsByCountry($limit);
|
133 |
|
|
return $publicationsByCountry;
|
134 |
|
|
}
|
135 |
|
|
|
136 |
|
|
// Retrieve publications by institution using cache if enabled.
|
137 |
|
|
// limit the maximum number of institutions to retrieve
|
138 |
|
|
// return publications by institution (array)
|
139 |
|
|
public function getPublicationsByInstitution($limit) {
|
140 |
|
|
/*
|
141 |
|
|
if ($this -> cache -> getCaching()) {
|
142 |
|
|
$id = self :: PUBLICATIONS_BY_INSTITUTION_CACHE_ID . '.' . $limit;
|
143 |
|
|
$publicationsByInstitution = $this -> cache -> get($id, self :: CACHE_GROUP);
|
144 |
|
|
if ($publicationsByInstitution === NULL) {
|
145 |
|
|
$publicationsByInstitution = $this -> _getPublicationsByInstitution($limit);
|
146 |
|
|
$this -> cache -> store($publicationsByInstitution, $id, self :: CACHE_GROUP);
|
147 |
|
|
}
|
148 |
|
|
} else
|
149 |
|
|
*/
|
150 |
|
|
$publicationsByInstitution = $this -> _getPublicationsByInstitution($limit);
|
151 |
|
|
return $publicationsByInstitution;
|
152 |
|
|
}
|
153 |
|
|
|
154 |
|
|
// Retrieve statistics.
|
155 |
|
|
// return the statistics (object) or NULL if any errors occur
|
156 |
|
|
private function _getStatistics() {
|
157 |
|
|
try {
|
158 |
|
|
$time = microtime(TRUE);
|
159 |
|
|
$statistics = $this -> client -> getStatistics();
|
160 |
|
|
JLog :: add('Retrieved statistics in ' . (microtime(TRUE) - $time) . ' s', JLog :: INFO, self :: LOG);
|
161 |
|
|
return $statistics;
|
162 |
|
|
} catch (Exception $e) {
|
163 |
|
|
JLog :: add('Error retrieving statistics: ' . $e -> getMessage(), JLog :: ERROR, self :: LOG);
|
164 |
|
|
return NULL;
|
165 |
|
|
}
|
166 |
|
|
}
|
167 |
|
|
|
168 |
|
|
// Retrieve publications by access mode.
|
169 |
|
|
// return publications by access mode (array) or NULL if any errors occur
|
170 |
|
|
private function _getPublicationsByAccessMode() {
|
171 |
|
|
try {
|
172 |
|
|
$time = microtime(TRUE);
|
173 |
|
|
$publicationsByAccessMode = $this -> client -> getPublicationsByAccessMode();
|
174 |
|
|
JLog :: add('Retrieved ' . count($publicationsByAccessMode) . ' publications by access mode entries in ' . (microtime(TRUE) - $time) . ' s', JLog :: INFO, self :: LOG);
|
175 |
|
|
return $publicationsByAccessMode;
|
176 |
|
|
} catch (Exception $e) {
|
177 |
|
|
JLog :: add('Error retrieving publications by acces mode: ' . $e -> getMessage());
|
178 |
|
|
return NULL;
|
179 |
|
|
}
|
180 |
|
|
}
|
181 |
|
|
|
182 |
|
|
// Retrieve publications by programme.
|
183 |
|
|
// limit the maximum number of programmes to retrieve
|
184 |
|
|
// return publications by programme (array) or NULL if any errors occur
|
185 |
|
|
private function _getPublicationsByProgramme($limit) {
|
186 |
|
|
try {
|
187 |
|
|
$time = microtime(TRUE);
|
188 |
|
|
$publicationsByProgramme = $this -> client -> getPublicationsByProgramme($limit);
|
189 |
|
|
JLog :: add('Retrieved ' . count($publicationsByProgramme) . ' publications by programme entries in ' . (microtime(TRUE) - $time) . ' s (limit: ' . $limit . ')', JLog :: INFO, self :: LOG);
|
190 |
|
|
return $publicationsByProgramme;
|
191 |
|
|
} catch (Exception $e) {
|
192 |
|
|
JLog :: add('Error retrieving publications by programme (limit: ' . $limit . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG);
|
193 |
|
|
return NULL;
|
194 |
|
|
}
|
195 |
|
|
}
|
196 |
|
|
|
197 |
|
|
// Retrieve publications by scientific area.
|
198 |
|
|
// limit the maximum number of scientific areas to retrieve
|
199 |
|
|
// return publications by scientific area (array) or NULL if any errors occur
|
200 |
|
|
private function _getPublicationsByScientificArea($limit) {
|
201 |
|
|
try {
|
202 |
|
|
$time = microtime(TRUE);
|
203 |
|
|
$publicationsByScientificArea = $this -> client -> getPublicationsByScientificArea($limit);
|
204 |
|
|
JLog :: add('Retrieved ' . count($publicationsByScientificArea) . ' publications by scientific area entries in ' . (microtime(TRUE) - $time) . ' s (limit: ' . $limit . ')', JLog :: INFO, self :: LOG);
|
205 |
|
|
return $publicationsByScientificArea;
|
206 |
|
|
} catch (Exception $e) {
|
207 |
|
|
JLog :: add('Error retrieving publications by scientific area (limit: ' . $limit . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG);
|
208 |
|
|
return NULL;
|
209 |
|
|
}
|
210 |
|
|
}
|
211 |
|
|
|
212 |
|
|
// Retrieve publications by country.
|
213 |
|
|
// limit the maximum number of countries to retrieve
|
214 |
|
|
// return publications by country (array) or NULL if any errors occur
|
215 |
|
|
private function _getPublicationsByCountry($limit) {
|
216 |
|
|
try {
|
217 |
|
|
$time = microtime(TRUE);
|
218 |
|
|
$publicationsByCountry = $this -> client -> getPublicationsByCountry($limit);
|
219 |
|
|
JLog :: add('Retrieved ' . count($publicationsByCountry) . ' publications by country entries in ' . (microtime(TRUE) - $time) . ' s (limit: ' . $limit . ')', JLog :: INFO, self :: LOG);
|
220 |
|
|
return $publicationsByCountry;
|
221 |
|
|
} catch (Exception $e) {
|
222 |
|
|
JLog :: add('Error retrieving publications by country (limit: ' . $limit . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG);
|
223 |
|
|
return NULL;
|
224 |
|
|
}
|
225 |
|
|
}
|
226 |
|
|
|
227 |
|
|
// Retrieve publications by institution.
|
228 |
|
|
// limit the maximum number of institutions to retrieve
|
229 |
|
|
// return publications by institution (array) or NULL if any errors occur
|
230 |
|
|
private function _getPublicationsByInstitution($limit) {
|
231 |
|
|
try {
|
232 |
|
|
$time = microtime(TRUE);
|
233 |
|
|
$publicationsByInstitution = $this -> client -> getPublicationsByInstitution($limit);
|
234 |
|
|
JLog :: add('Retrieved ' . count($publicationsByInstitution) . ' publications by institution entries in ' . (microtime(TRUE) - $time) . ' s (limit: ' . $limit . ')', JLog :: INFO, self :: LOG);
|
235 |
|
|
return $publicationsByInstitution;
|
236 |
|
|
} catch (Exception $e) {
|
237 |
|
|
JLog :: add('Error retrieving publications by institution (limit: ' . $limit . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG);
|
238 |
|
|
return NULL;
|
239 |
|
|
}
|
240 |
|
|
}
|
241 |
|
|
}
|