Project

General

Profile

1
<?php
2
/**
3
* includestatsnumber plugin
4
* This plugin allows you to insert a statistics number to any joomla article
5
* Author: dimitra
6
* License: GNU/GPL http://www.gnu.org/copyleft/gpl.html
7
*/
8

    
9
defined( '_JEXEC' ) or die( 'Direct Access to this location is not allowed.' );
10

    
11
//jimport( 'joomla.event.plugin' );
12
//jimport( 'joomla.language.helper');
13
jimport( 'joomla.plugin.plugin' );
14
jimport( 'joomla.log.log' );
15

    
16
$GLOBALS['PREDIS_ROOT'] = dirname(__FILE__) . DS . 'predis';
17

    
18

    
19
class plgContentIncludestatsnumbers extends JPlugin {
20
	const CACHE_GROUP = "openaire.stats.plugin";
21
	private $cache;
22
	private $codes = array();
23
	private $db;
24

    
25
	public function __construct(&$subject, $config) {
26
		parent::__construct($subject, $config);
27
		JLog :: addLogger(array('text_file' => 'openaire.log'), JLog :: ALL, array('openaire'));
28
		
29
		if (!class_exists("Predis\Client"))
30
			require $GLOBALS['PREDIS_ROOT'] . DS ."autoload.php";
31
		
32
		try {
33
			$this->cache = new Predis\Client(array( 
34
				"scheme" => $this->params->get('cachescheme'),
35
       				"host" => $this->params->get('cacheserver'),
36
       				"port" => $this->params->get('cacheport')
37
				"persistent" => 1));
38
        			
39
				$this->cache->connect();
40
		
41
		} catch(Exception $e) {
42
			JLog :: add("Stats Plugin : Error connecting to Redis server: ".$e->getMessage(), JLog :: ERROR, 'openaire');
43
			$this->cache = null;
44
		}
45

    
46
		/*OVERALL*/
47
		/*1*/ $this->codes[] = "{include_number PUBS}";
48
		/*2*/ $this->codes[] = "{include_number OAPUBS}";
49
		/*3*/ $this->codes[] = "{include_number NOAPUBS}";
50
		/*4*/ $this->codes[] = "{include_number FPUBS}";
51
		/*5*/ $this->codes[] = "{include_number PROJ}";
52
		/*6*/ $this->codes[] = "{include_number DATASRC}";
53
		/*7*/ $this->codes[] = "{include_number DATASRC-PUBS}";
54
		/*8*/ $this->codes[] = "{include_number DATASRC-PUBREPS}";
55
		/*9*/ $this->codes[] = "{include_number DATASRC-PUBOAJ}";
56
		/*10*/$this->codes[] = "{include_number DATASRC-PUBAGGR}";
57
		/*11*/$this->codes[] = "{include_number FUNDERS}";
58

    
59
		/*FOR FP7*/
60
		/*12*/$this->codes[] = "{include_number FP7PUBSTOTAL}";
61
		/*13*/$this->codes[] = "{include_number FP7PROJPUBS}";
62
		/*14*/$this->codes[] = "{include_number FP7PROJTOTAL}";
63
		/*15*/$this->codes[] = "{include_number FP7OAPUBS}";
64
		/*16*/$this->codes[] = "{include_number FP7RESPUBS}";
65
		/*17*/$this->codes[] = "{include_number FP7EMBPUBS}";
66

    
67
		/*18*/$this->codes[] = "{include_number SC39FP7PUBSTOTAL}";
68
		/*19*/$this->codes[] = "{include_number SC39FP7PROJPUBS}";
69
		/*20*/$this->codes[] = "{include number SC39FP7PROJTOTAL}";
70
		/*21*/$this->codes[] = "{include_number SC39FP7OAPUBS}";
71

    
72
		/*ERC*/
73
		/*22*/$this->codes[] = "{include_number ERCPUBSTOTAL}";
74
		/*23*/$this->codes[] = "{include_number ERCPROJPUBS}";
75
		/*24*/$this->codes[] = "{include_number ERCPROJTOTAL}";
76
		/*25*/$this->codes[] = "{include_number ERCOAPUBS}";
77
		/*26*/$this->codes[] = "{include_number ERCRESPUBS}";
78
		/*27*/$this->codes[] = "{include_number ERCEMBPUBS}";
79

    
80
		/*WT*/
81
		/*28*/$this->codes[] = "{include_number WTPUBSTOTAL}";
82
		/*29*/$this->codes[] = "{include_number WTPROJPUBS}";
83
		/*30*/$this->codes[] = "{include_number WTPROJTOTAL}";
84
		/*31*/$this->codes[] = "{include_number WTOAPUBS}";
85
		/*32*/$this->codes[] = "{include_number WTRESPUBS}";
86
		/*33*/$this->codes[] = "{include_number WTEMBPUBS}";
87

    
88
		// Latest Natalias requests
89
		/*34*/$this->codes[] = "{include_number DATASRC-WITHPUBS}";
90
		/*35*/$this->codes[] = "{include_number ORG-WITHPUBS}";
91
		/*36*/$this->codes[] = "{include_number DATA-TOTAL}";
92
		
93
		// FET nums
94
		/*37*/$this->codes[] = "{include_number FETPUBS}";
95
		/*38*/$this->codes[] = "{include_number FETOAPUBS}";
96
		/*39*/$this->codes[] = "{include_number FETRESPUBS}";
97
		/*40*/$this->codes[] = "{include_number FETEMBPUBS}";
98
		
99
		
100
		// DATASETS  
101
		/*41*/$this->codes[] = "{include_number DATASETPUBS}";
102
		/*42*/$this->codes[] = "{include_number DATASETPROJ}";
103
		/*43*/$this->codes[] = "{include_number PUBSDATASETS}";
104
		 
105
		 
106
		 
107
		 	
108
		// EGI NUMS
109
		/*44*/$this->codes[] = "{include_number EGIPUBS}";
110
		/*45*/$this->codes[] = "{include_number EGIVO}";
111
		/*46*/$this->codes[] = "{include_number EGIPROJ}";
112
		 
113
		  	
114
		// EGI NUMS
115
		/*47*/$this->codes[] = "{include_number EGIOA}";
116
		/*48*/$this->codes[] = "{include_number EGIEMB}";
117
		/*49*/$this->codes[] = "{include_number EGIRES}";
118
		   	
119
		// FCT NUMS
120
		
121
		/*ERC*/
122
		/*50*/$this->codes[] = "{include_number FCTPUBSTOTAL}";
123
		/*51*/$this->codes[] = "{include_number FCTPROJPUBS}";
124
		/*52*/$this->codes[] = "{include_number FCTPROJTOTAL}";
125
		/*53*/$this->codes[] = "{include_number FCTOAPUBS}";
126
		/*54*/$this->codes[] = "{include_number FCTRESPUBS}";
127
		/*55*/$this->codes[] = "{include_number FCTEMBPUBS}";
128

    
129
		 
130
		 
131
		JLog :: add('Stats Plugin', JLog :: DEBUG, 'openaire');
132
	}
133

    
134
	public function onContentPrepare( $context, &$article, &$params, $page = 0 ) {
135
		$regex_base = '\{(include_number)\s+(PUBS|OAPUBS|NOAPUBS|FPUBS|PROJ|DATASRC|DATASRC-PUBS|DATASRC-PUBREPS|DATASRC-PUBOAJ|DATASRC-PUBAGGR|FUNDERS|FP7PUBSTOTAL|FP7PROJPUBS|FP7PROJTOTAL|FP7OAPUBS|FP7RESPUBS|FP7EMBPUBS|SC39FP7PUBSTOTAL|SC39FP7PROJPUBS|SC39FP7PROJTOTAL|SC39FP7OAPUBS|ERCPUBSTOTAL|ERCPROJTOTAL|ERCPROJPUBS|ERCOAPUBS|ERCRESPUBS|ERCEMBPUBS|WTPUBSTOTAL|WTPROJPUBS|WTPROJTOTAL|WTOAPUBS|WTRESPUBS|WTEMBPUBS|DATASRC-WITHPUBS|ORG-WITHPUBS|DATA-TOTAL|FETPUBS|FETOAPUBS|FETRESPUBS|FETEMBPUBS|DATASETPUBS|DATASETPROJ|PUBSDATASETS|EGIPUBS|EGIVO|EGIPROJ|EGIOA|EGIEMB|EGIRESERCPUBSTOTAL|FCTPROJTOTAL|FCTPROJPUBS|FCTOAPUBS|FCTRESPUBS|FCTEMBPUBS)\}';
136
		$regex = "/$regex_base/";
137

    
138
		$contents = $article->text;
139
		$found = preg_match_all($regex, $contents, $matches);
140
		
141
		
142
		//JLog :: add( "Stats Plugin  found : matches found: ".$found , JLog :: DEBUG, 'openaire')
143
		if (!$found){ return true;}
144

    
145
		try {
146
			$str = 'pgsql:host='.$this->params->get('dbhost').';port='.$this->params->get('dbport').';dbname='.$this->params->get('dbname').';user='.$this->params->get('dbuser').';password='.$this->params->get('dbpass');
147
			$this->db = new PDO($str);
148
		} catch(Exception $e){
149
			JLog :: add('Stats Plugin : Could not connect to database: ' . $e->getMessage(), JLog :: ERROR, 'openaire');
150
			return false;
151
		}
152
		$cnt = count($matches);
153
		//JLog :: add( "Stats Plugin :   matches count  found: ".$cnt." for matches ".print_r($matches), JLog :: DEBUG, 'openaire');
154

    
155
		$result = NULL;
156
		if ($this -> cache != null) {
157
		
158
			if($this->cache->exists("STATS_NUMBERS")) {
159
				$result = $this -> cache -> hgetall("STATS_NUMBERS");
160
				JLog :: add("Stats Plugin : Found in cache!", JLog :: DEBUG, 'openaire');
161
			} else {
162
				$this->cache->quit();
163
				JLog :: add("Stats Plugin : Not found in cache!", JLog :: DEBUG, 'openaire');
164
				$result = $this->makequeries(true);
165
			}
166
					
167
		} else {//make the queries but don't cache the result
168
			$result = $this->makequeries(false);
169
			
170
			
171
		}
172

    
173
		$article->text = str_replace($this->codes, $result, $article->text);
174
		
175
		
176
		
177
//JLog :: add( "Stats Plugin :   $this->codes    ".print_r($this->codes), JLog :: DEBUG, 'openaire');
178

    
179
//JLog :: add( "Stats Plugin : result : ".print_r($result), JLog :: DEBUG, 'openaire');
180

    
181
		return true;
182
	}
183

    
184
	private function makequeries($addflag){
185
		JLog :: add("Not found in cache!", JLog :: DEBUG, 'openaire');
186
		$temp = array();
187
		/*OVERALL*/
188

    
189
		/*1*/ $qpubs = "SELECT count(*) FROM result where type='publication'";
190
		/*2*/ $qoapubs = "SELECT count(*) FROM result WHERE access_mode='Open Access' and type='publication'";
191
		/*3*/ $qnoapubs = "SELECT count(*) FROM result WHERE access_mode='Closed Access' and type='publication'";
192
		/*4*/ $qfpubs = "SELECT count(distinct result_projects.id) FROM result, result_projects where result.result_projects = result_projects.id and type='publication'";
193
		/*5*/ $qproj = "SELECT count(*) FROM project";
194
		/*6*/ $qdatasrc = "SELECT count(*) FROM datasource";
195

    
196
		/*7*/ $qdtsrcpubs = "SELECT count(*) from datasource where compatibility!='non compatible' and compatibility!='unknown'";
197
		/*8*/ $qdtsrcpubreps = "SELECT count(*) FROM datasource WHERE type='Repository'";
198
		/*9*/ $qdtsrcoaj = "SELECT count(*) FROM datasource WHERE type='Aggregated Journal'";
199
		/*10*/$qdtsrcpubaggr = "SELECT count(*) FROM datasource WHERE type='Aggregated Repository'";
200
		/*11*/$qfunders = "SELECT count(distinct funding_lvl0) FROM project WHERE funding_lvl0 !=''";
201
 
202

    
203
		/*FP7*/
204
		/*12: total number of fp7 pubs */
205
		$qfp7pubstotal = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects = result_projects.id and type='publication' and result_projects.project = project.id and funding_lvl0 = 'FP7'";
206
                /*13: number of fp7 projects with publications*/
207
		$qfp7projpubs = "SELECT count(distinct project.id) FROM result, result_projects, project WHERE result.result_projects = result_projects.id and type='publication' and result_projects.project = project.id and funding_lvl0='FP7'";
208
		/*14: total number of fp7 projects*/
209
		$qfp7projtotal = "SELECT count(id) FROM project WHERE funding_lvl0 = 'FP7'";
210
		/*15: fp7 open access pubs*/
211
		$qfp7oapubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result_projects = result_projects.id AND result_projects.project = project.id and type='publication' and funding_lvl0 = 'FP7' and access_mode='Open Access'";
212
                /*16: fp7 restricted pubs*/
213
		$qfp7respubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects=result_projects.id AND result_projects.project = project.id and funding_lvl0 = 'FP7' and access_mode='Restricted' and type='publication'";
214
                /*17: fp7 pubs in embargo*/
215
		$qfp7embpubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects = result_projects.id AND result_projects.project = project.id and funding_lvl0 = 'FP7' and access_mode='Embargo' and type='publication'";
216
                /*18: total number of fp7 pubs with sc39*/
217
		$qsc39fp7pubstotal = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result_projects.project = project.id and funding_lvl0 = 'FP7' and sc39='yes' and result.result_projects = result_projects.id and type='publication'";
218
		/*19: fp7 projs with sc39 and pubs*/
219
		$qsc39fp7projpubs = "SELECT count(distinct project.id) FROM result, result_projects, project WHERE result_projects.project=project.id and funding_lvl0 = 'FP7' and sc39='yes' and result.result_projects = result_projects.id and type='publication'";
220
		/*20: total number of fp7 proj with sc39*/
221
		$qsc39fp7projtotal = "SELECT count(number) from project where funding_lvl0='FP7' and sc39='yes'";
222
		/*21: open access fp7 pubs with sc39*/
223
		$qsc39fp7oapubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects = result_projects.id AND result_projects.project = project.id and funding_lvl0 = 'FP7' and access_mode='Open Access' and sc39='yes' and type='publication'";
224

    
225
		/*ERC*/
226
		/*22: total number of erc pubs*/
227
		$qercpubstotal = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result_projects.project = project.id and funding_lvl2 = 'ERC' and result.result_projects = result_projects.id and type='publication'";
228
                /*23: erc projects with pubs*/
229
		$qercprojpubs = "SELECT count(distinct project.id) FROM result, project, result_projects where result_projects.project = project.id and project.funding_lvl2='ERC' and result.result_projects = result_projects.id and type='publication'";
230
	        /*24: total erc projects*/
231
		$qercprojtotal = "SELECT count(id) FROM project WHERE funding_lvl2 = 'ERC'";
232
		/*25: erc open access pubs*/
233
		$qercoapubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects= result_projects.id AND result_projects.project = project.id and funding_lvl2 = 'ERC' and access_mode='Open Access' and type='publication'";
234
                /*26: erc restricted pubs*/
235
		$qercrespubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects = result_projects.id AND result_projects.project = project.id and funding_lvl2 = 'ERC' and access_mode='Restricted' and type='publication'";
236
                /*27: erc embargo pubs*/
237
		$qercembpubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects=result_projects.id AND result_projects.project = project.id and funding_lvl2 = 'ERC' and access_mode='Embargo' and type='publication'";
238

    
239
		/*WT*/
240
		/*28: total number of wt pubs*/
241
		$qwtpubstotal = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result_projects.project = project.id and funding_lvl0 = 'WT' and result.result_projects = result_projects.id and type='publication'";
242
                /*29: wt projects with pubs*/
243
		$qwtprojpubs = "SELECT count(distinct project.id) FROM result, project, result_projects where result_projects.project = project.id and project.funding_lvl0='WT' and result.result_projects = result_projects.id and type='publication'";
244
	        /*30: total wt projects*/
245
		$qwtprojtotal = "SELECT count(id) FROM project WHERE funding_lvl0 = 'WT'";
246
		/*31: wt open access pubs*/
247
		$qwtoapubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects= result_projects.id AND result_projects.project = project.id and funding_lvl0 = 'WT' and access_mode='Open Access' and type='publication'";
248
                /*32: wt restricted pubs*/
249
		$qwtrespubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects = result_projects.id AND result_projects.project = project.id and funding_lvl0 = 'WT' and access_mode='Restricted' and type='publication'";
250
                /*33: wt embargo pubs*/
251
		$qwtembpubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects=result_projects.id AND result_projects.project = project.id and funding_lvl0 = 'WT' and access_mode='Embargo' and type='publication'";
252

    
253
		/*Natalia's extra stuff */
254
		/*34: datasources with publication results */
255
		$datasrc_withpubs = "SELECT count(distinct rd.datasource) from result_datasources rd join result r on r.id=rd.id where r.type='publication'";
256
		/*35: organisations with publication results */
257
		$org_withpubs = "select count(*) from (select dor.organization as organization from datasource_organizations dor join result_datasources rd on rd.datasource=dor.id join result r on r.id=rd.id where r.type='publication' union select por.organization as organization from project_organizations por join result_projects rp on rp.project=por.id join result r on r.id=rp.id where r.type='publication') as foo";
258
		/*36: number of datasets */
259
		$data_total = "select count(distinct id) from result where type='dataset';";
260

    
261
/*FET */
262

    
263

    
264
 $fetpubs  ="select count(distinct rc.id) as field0 from result_concepts rc join concept c on c.id=rc.concept join category cat on cat.id=c.category where cat.context ='fet'";
265

    
266
 $fetoapubs ="select count(distinct rc.id) as field0 from result_concepts rc join result r on r.id=rc.id join concept c on c.id=rc.concept join category cat on cat.id=c.category where cat.context ='fet' and r. bestlicense='Open Access'";
267

    
268

    
269
$fetrespubs ="select count(distinct rc.id) as field0 from result_concepts rc join result r on r.id=rc.id join concept c on c.id=rc.concept join category cat on cat.id=c.category where cat.context ='fet' and r. bestlicense='Restricted'";
270
 
271
$fetembpubs ="select count(distinct rc.id) as field0 from result_concepts rc join result r on r.id=rc.id join concept c on c.id=rc.concept join category cat on cat.id=c.category where cat.context ='fet' and r. bestlicense='Embargo'";
272

    
273

    
274
/*DATASETS */
275

    
276
 $datasetpubs= "select count(distinct r.id) from result r join result_results rr on rr.id=r.id join result rp on rp.id=rr.result  where r.type='dataset' and rp.type='publication'" ;
277

    
278
//# of datasets linked to projects
279

    
280
$datasetproj="select count(distinct r.id) from result r  join result_projects rp on rp.id=r.id join project  p on p.id=rp.project  where r.type='dataset' ";
281

    
282
//# of publications linked to datasets
283

    
284
$pubsdatasets ="select count(distinct r.id) from result r join result_results rr on rr.id=r.id join result rp on rp.id=rr.result  where r.type='publication' and rp.type='dataset'";
285

    
286
/*EGI PAGE NUMS*/
287

    
288

    
289
$egivo="select count(distinct c.name) as field0 from result_concepts rc join concept c on c.id=rc.concept join category cat on cat.id=c.category where cat.id='egi::virtual'";
290

    
291
$egiproj="select count(distinct c.name) as field0 from result_concepts rc join concept c on c.id=rc.concept join category cat on cat.id=c.category where cat.id='egi::projects' ";
292

    
293
$egipubs= " select count( distinct rc.id) as field0 from result r,result_concepts rc, concept con, category cat where rc.id=r.id  and  con.id=rc.concept and con.category= cat.id  and cat.context ='egi'";
294

    
295
$egioa="select  count(distinct r.id) as field0 from result r join result_concepts rc on r.id=rc.id join concept c on c.id=rc.concept where bestlicense='Open Access'";
296
$egiemb="select  count(distinct r.id) as field0 from result r join result_concepts rc on r.id=rc.id join concept c on c.id=rc.concept where bestlicense='Embargo'";
297
$egires="select  count(distinct r.id) as field0 from result r join result_concepts rc on r.id=rc.id join concept c on c.id=rc.concept where bestlicense='Restricted'";
298

    
299
/* FCT*/
300
/*FCT*/
301

    
302
                /*22: total number of FCTpubs*/
303
                $qfctpubstotal = "SELECT count( distinct result.id) FROM result, project, result_projects where result_projects.project = project.id and project.funding_lvl0='FCT' and result.result_projects = result_projects.id and result.type='publication'";
304

    
305
        /*23: FCTprojects with pubs*/
306
                $qfctprojpubs = "SELECT count(distinct project.id) FROM result, project, result_projects where result_projects.project = project.id and project.funding_lvl0='FCT' and result.result_projects = result_projects.id and type='publication'";
307
            /*24: total FCTprojects*/
308
                $qfctprojtotal = "SELECT count(id) FROM project WHERE funding_lvl0 = 'FCT'";
309

    
310
                /*25: FCTopen access pubs*/
311
                $qfctoapubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects= result_projects.id AND result_projects.project = project.id and funding_lvl0 = 'FCT' and bestlicense='Open Access' and type='publication'";
312
        /*26: FCTrestricted pubs*/
313
                $qfctrespubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects = result_projects.id AND result_projects.project = project.id and funding_lvl0 = 'FCT' and bestlicense='Restricted' and type='publication'";
314

    
315
        /*27: FCTembargo pubs*/
316
                $qfctembpubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects=result_projects.id AND result_projects.project = project.id and funding_lvl0 = 'FCT' and bestlicense='Embargo' and type='publication'";
317

    
318

    
319
		
320
		
321
		/*1*/ $temp['pubs'] = $this->doQuery($qpubs);
322
               	/*2*/ $temp['oapubs'] = $this->doQuery($qoapubs);
323
               	/*3*/ $temp['noapubs'] = $this->doQuery($qnoapubs);
324
              	/*4*/ $temp['fpubs'] = $this->doQuery($qfpubs);
325
                /*5*/ $temp['proj'] = $this->doQuery($qproj);
326
                /*6*/ $temp['datasrc'] = $this->doQuery($qdatasrc);
327
                /*7*/ $temp['dtsrcpubs'] = $this->doQuery($qdtsrcpubs);
328
                /*8*/ $temp['dtsrcpubreps'] = $this->doQuery($qdtsrcpubreps);
329
                /*9*/ $temp['dtsrcoaj'] = $this->doQuery($qdtsrcoaj);
330
                /*10*/$temp['dtsrcpubaggr'] = $this->doQuery($qdtsrcpubaggr);
331
                /*11*/$temp['funders'] = $this->doQuery($qfunders);
332

    
333
		/*FP7*/
334
                /*12*/$temp['fp7pubstotal'] = $this->doQuery($qfp7pubstotal);
335
                /*13*/$temp['fp7projpubs'] = $this->doQuery($qfp7projpubs);
336
                /*14*/$temp['fp7projtotal'] = $this->doQuery($qfp7projtotal);
337
                /*15*/$temp['fp7oapubs'] = $this->doQuery($qfp7oapubs);
338
                /*16*/$temp['fp7respubs'] = $this->doQuery($qfp7respubs);
339
                /*17*/$temp['fp7embpubs'] = $this->doQuery($qfp7embpubs);
340
                
341
		/*18*/$temp['sc39fp7pubstotal'] = $this->doQuery($qsc39fp7pubstotal);
342
                /*19*/$temp['sc39fp7projpubs'] = $this->doQuery($qsc39fp7projpubs);
343
		/*20*/$temp['sc39fp7projtotal'] = $this->doQuery($qsc39fp7projtotal);
344
                /*21*/$temp['sc39fp7oapubs'] = $this->doQuery($qsc39fp7oapubs);
345

    
346
		/*ERC*/
347
		/*22*/$temp['ercpubstotal'] = $this->doQuery($qercpubstotal);
348
                /*23*/$temp['ercprojpubs'] = $this->doQuery($qercprojpubs);
349
		/*24*/$temp['ercprojtotal'] = $this->doQuery($qercprojtotal);
350
                /*25*/$temp['ercoapubs'] = $this->doQuery($qercoapubs);
351
                /*26*/$temp['ercrespubs'] = $this->doQuery($qercrespubs);
352
                /*27*/$temp['ercembpubs'] = $this->doQuery($qercembpubs);
353
		
354
		/*WT*/
355
		/*28*/$temp['wtpubstotal'] = $this->doQuery($qwtpubstotal);
356
                /*29*/$temp['wtprojpubs'] = $this->doQuery($qwtprojpubs);
357
		/*30*/$temp['wtprojtotal'] = $this->doQuery($qwtprojtotal);
358
                /*31*/$temp['wtoapubs'] = $this->doQuery($qwtoapubs);
359
                /*32*/$temp['wtrespubs'] = $this->doQuery($qwtrespubs);
360
                /*33*/$temp['wtembpubs'] = $this->doQuery($qwtembpubs);
361

    
362
		/*34*/$temp['datasrc_withpubs'] = $this->doQuery($datasrc_withpubs);
363
		/*35*/$temp['org_withpubs'] = $this->doQuery($org_withpubs);
364
		/*36*/$temp['data_total'] = $this->doQuery($data_total);
365
//FET NUMS
366
		/*37*/$temp['fetpubs'] = $this->doQuery($fetpubs);
367
		/*38*/$temp['fetoapubs'] = $this->doQuery($fetoapubs);
368
		/*39*/$temp['fetrespubs'] = $this->doQuery($fetrespubs);
369
		/*40*/$temp['fetembpubs'] = $this->doQuery($fetembpubs);
370

    
371
     /*41*/$temp['datasetpubs'] = $this->doQuery($datasetpubs);
372
		/*42*/$temp['datasetproj'] = $this->doQuery($datasetproj);
373
		/*43*/$temp['pubsdatasets'] = $this->doQuery($pubsdatasets);
374
		 
375

    
376
     /*44*/$temp['egivo'] = $this->doQuery($egivo);
377
		/*45*/$temp['egiproj'] = $this->doQuery($egiproj);
378
		/*46*/$temp['egipubs'] = $this->doQuery($egipubs);
379
		 
380

    
381
     /*44*/$temp['egioa'] = $this->doQuery($egioa);
382
		/*45*/$temp['egiemb'] = $this->doQuery($egiemb);
383
		/*46*/$temp['egires'] = $this->doQuery($egires);
384
		 
385
     
386
     /*FCT*/
387
		/*22*/$temp['fctpubstotal'] = $this->doQuery($qfctpubstotal);
388
                /*23*/$temp['fctprojpubs'] = $this->doQuery($qfctprojpubs);
389
		/*24*/$temp['fctprojtotal'] = $this->doQuery($qfctprojtotal);
390
                /*25*/$temp['fctoapubs'] = $this->doQuery($qfctoapubs);
391
                /*26*/$temp['fctrespubs'] = $this->doQuery($qfctrespubs);
392
                /*27*/$temp['fctembpubs'] = $this->doQuery($qfctembpubs);
393
     
394
     
395
     
396
		if($addflag){		
397
			JLog:: add("Stats Plugin : params to store: ".print_r($temp, TRUE), JLog :: ERROR, 'openaire');
398

    
399
			$this->cache = new Predis\Client(array( 
400
				"scheme" => $this->params->get('cachescheme'),
401
				"host" => $this->params->get('cacheserver'),
402
				"port" => $this->params->get('cacheport')));
403
        			
404
			$this->cache->connect();
405
			$this->cache->hmset("STATS_NUMBERS", $temp);
406
			$this->cache->save();
407
			$this->cache->quit();
408
		}		
409
		return $temp;
410
	}
411

    
412
	private function doQuery($query){
413
		$stmt = $this->db->query($query); 
414
                if(!$stmt){
415
                        $arr = $this->db->errorInfo();
416
                        JLog :: add("Stats Plugin : Error executing query: ".$query." ".$arr[2], JLog :: ERROR, 'openaire');
417
                        return "-";
418
                }
419
                $t = $stmt->fetch();
420
                return number_format($t[0]);
421
	}
422
}
423

    
424
?>
(1-1/4)