1 |
12772
|
antonis.le
|
<?php
|
2 |
|
|
|
3 |
12832
|
antonis.le
|
if (!class_exists('TBase')) {
|
4 |
|
|
$GLOBALS['THRIFT_ROOT'] = dirname(__FILE__) . DS . 'models' . DS . 'thrift';
|
5 |
12772
|
antonis.le
|
|
6 |
12832
|
antonis.le
|
require_once($GLOBALS['THRIFT_ROOT'] . DS . 'Thrift.php');
|
7 |
|
|
require_once($GLOBALS['THRIFT_ROOT'] . DS . 'protocol' . DS . 'TBinaryProtocol.php');
|
8 |
|
|
require_once($GLOBALS['THRIFT_ROOT'] . DS . 'transport' . DS . 'TSocket.php');
|
9 |
|
|
require_once($GLOBALS['THRIFT_ROOT'] . DS . 'transport' . DS . 'TBufferedTransport.php');
|
10 |
|
|
require_once($GLOBALS['THRIFT_ROOT'] . DS . 'packages' . DS . 'openaire' . DS . 'OpenAireConnector.php');
|
11 |
|
|
}
|
12 |
|
|
|
13 |
12772
|
antonis.le
|
class modOpenAireStatsHelper {
|
14 |
12832
|
antonis.le
|
private static function setupThrift(&$params) {
|
15 |
12772
|
antonis.le
|
$host = $params->get('thriftHost');
|
16 |
|
|
$port = $params->get('thriftPort');
|
17 |
|
|
|
18 |
|
|
$socket = new TSocket($host, $port);
|
19 |
|
|
|
20 |
|
|
$socket->setRecvTimeout(10000);
|
21 |
|
|
|
22 |
12832
|
antonis.le
|
$_transport = new TBufferedTransport($socket);
|
23 |
|
|
$protocol = new TBinaryProtocol($_transport);
|
24 |
12772
|
antonis.le
|
|
25 |
12832
|
antonis.le
|
$_client = new OpenAireConnectorClient($protocol);
|
26 |
|
|
|
27 |
|
|
return array("client" => $_client, "transport" => $_transport);
|
28 |
12772
|
antonis.le
|
}
|
29 |
|
|
|
30 |
12956
|
antonis.le
|
public static function getStats($params) {
|
31 |
12832
|
antonis.le
|
$thrift = modOpenAireStatsHelper::setupThrift($params);
|
32 |
|
|
|
33 |
|
|
// Open up the connection
|
34 |
|
|
$thrift["transport"]->open();
|
35 |
|
|
|
36 |
13643
|
antonis.le
|
// $list = $thrift["client"]->getPublicationStatistics();
|
37 |
|
|
|
38 |
|
|
$cache = & JFactory::getCache('mod_openairestats', 'callback');
|
39 |
|
|
$conf =& JFactory::getConfig();
|
40 |
|
|
$cacheactive = $conf->getValue('config.caching');
|
41 |
|
|
$cache->setCaching(1); //enable caching
|
42 |
|
|
|
43 |
|
|
$list = $cache->call(array($thrift['client'], 'getPublicationStatistics'));
|
44 |
|
|
|
45 |
|
|
$cache->setCaching($cacheactive);
|
46 |
|
|
|
47 |
12832
|
antonis.le
|
$thrift["transport"]->close();
|
48 |
|
|
|
49 |
|
|
return $list;
|
50 |
12772
|
antonis.le
|
}
|
51 |
13643
|
antonis.le
|
|
52 |
12772
|
antonis.le
|
}
|
53 |
12956
|
antonis.le
|
|
54 |
|
|
function compareStatLines($line1, $line2) {
|
55 |
|
|
$v1 = $line1->values[0]->value;
|
56 |
|
|
$v2 = $line2->values[0]->value;
|
57 |
|
|
|
58 |
|
|
if ($v1 == $v2)
|
59 |
|
|
return 0;
|
60 |
|
|
else
|
61 |
|
|
return ($v1 < $v2 ?-1:1);
|
62 |
|
|
}
|
63 |
12772
|
antonis.le
|
?>
|