Project

General

Profile

1
<?php
2

    
3
if (!class_exists('TBase')) {
4
	$GLOBALS['THRIFT_ROOT'] = dirname(__FILE__) . DS . 'models' . DS . 'thrift';
5

    
6
	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
class modOpenAireStatsHelper {
14
	private static function setupThrift(&$params) {
15
		$host = $params->get('thriftHost');
16
		$port = $params->get('thriftPort');
17

    
18
		$socket = new TSocket($host, $port);
19

    
20
                $socket->setRecvTimeout(10000);
21

    
22
                $_transport = new TBufferedTransport($socket);
23
                $protocol = new TBinaryProtocol($_transport);
24

    
25
                $_client = new OpenAireConnectorClient($protocol);
26

    
27
		return array("client" => $_client, "transport" => $_transport);
28
	}
29

    
30
	public static function getStats($params) {
31
		$thrift = modOpenAireStatsHelper::setupThrift($params);
32

    
33
		// Open up the connection
34
		$thrift["transport"]->open();
35

    
36
//		$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
		$thrift["transport"]->close();
48

    
49
                return $list;
50
	}
51

    
52
}
53

    
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
?>
(1-1/4)