class.tx_nG6_db.php 80.1 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
/***************************************************************
*  Copyright notice
*
*  (c) 2009 PF bioinformatique de Toulouse <>
*  All rights reserved
*
*  This script is part of the TYPO3 project. The TYPO3 project is
*  free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  The GNU General Public License can be found at
*  http://www.gnu.org/copyleft/gpl.html.
*
*  This script is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

require_once(t3lib_extMgm::extPath('nG6').'/lib/class.tx_nG6_utils.php');

/**
 * Class_nG6_db' for the 'nG6' extension.
 * This class is in charge of all communication with the database
 *
 * @author	PF bioinformatique de Toulouse <>
 */
class tx_nG6_db {
Penom Nom's avatar
Penom Nom committed
34
35
36
37
38
39
40
41
	
	/*
	 * Global functions
	*------------------------------------------------------------*/
	
	/**
	* Update the specified field of the table
	 *
42
	* @param	string  $table the entity to change
Penom Nom's avatar
Penom Nom committed
43
44
45
46
	* @param	string  $id     the element id to update
	* @param	string  $field  the field to change
	* @param	string  $value  the new value
	*/
47
	function update_field($table, $id, $field, $value) {
48
49
50
		if( $field == 'uid' ) {
			throw new Exception ("The function 'update_field' cannot change an id.") ;
		}	
51
		$GLOBALS['TYPO3_DB']-> exec_UPDATEquery ($table, 'uid='.$id, array($field => $value));
52
	}
Jerome Mariette's avatar
Jerome Mariette committed
53
		
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
    /**
     * Select all project for the current user
     *
     * @param	string	$by	by can group, organism, location
     * @param	string	$role	role can be create_user, manager
     * @return	table with all projects
     */
    function select_projects_repartition($role, $by='title') {
    	
    	if ($role == "create_user") {
    		$queryParts = array(
    				'SELECT' 	=> 'tx_nG6_project.uid as pid, fe_groups.title as title, fe_groups.tx_nG6_organism as organism, fe_groups.tx_nG6_location as location',
    				'FROM' 		=> 'tx_nG6_project '
    				.' INNER JOIN fe_users ON tx_nG6_project.cruser_id=fe_users.uid '
    				.' INNER JOIN fe_groups ON fe_groups.uid=fe_users.usergroup ',
    				'WHERE' 	=> "",
    				'GROUPBY' 	=> '',
    				'ORDERBY' 	=> '',
    				'LIMIT' 	=> ''
    		);
    		//$where = "tx_nG6_project.cruser_id="
    	} else if ($role == "manager") {
	    	$queryParts = array(
    				'SELECT' 	=> 'tx_nG6_project.uid as pid, fe_groups.title as title, fe_groups.tx_nG6_organism as organism, fe_groups.tx_nG6_location as location',
	    			'FROM' 		=> 'tx_nG6_project '
	    			.' INNER JOIN fe_rights ON tx_nG6_project.uid=fe_rights.project_id '
	    			.' INNER JOIN fe_users ON fe_rights.fe_user_id=fe_users.uid '
	    			.' INNER JOIN fe_groups ON fe_groups.uid=fe_users.usergroup ',
	    			'WHERE' 	=> "fe_rights.right_id=1",
	    			'GROUPBY' 	=> '',
	    			'ORDERBY' 	=> '',
	    			'LIMIT' 	=> ''
	    	);
    	}
    	$by_title = array() ;
    	$by_organism = array();
    	$by_location = array();
    	$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
    	while($res_row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
    		if (!isset ($by_title[$res_row['title']])) {
    			$by_title[$res_row['title']] = array(
    					'count'			=> 1,
Jerome Mariette's avatar
Jerome Mariette committed
96
97
    					'organism'		=> $res_row['organism'],
    					'location'		=> $res_row['location']);
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
    		} else {
    			$by_title[$res_row['title']]['count'] += 1;
    		}
    		
    		if (!isset ($by_organism[$res_row['organism']])) {
    			$by_organism[$res_row['organism']] = array(
    					'count'			=> 1);
    		} else {
    			$by_organism[$res_row['organism']]['count'] += 1;
    		}
    		
    		if (!isset ($by_location[$res_row['location']])) {
    			$by_location[$res_row['location']] = array(
    					'count'			=> 1);
    		} else {
    			$by_location[$res_row['location']]['count'] += 1;
    		}
    	}
    	if ($by=='title') {
    		return ($by_title);
    	} else if ($by=='organism') {
    		return ($by_organism);
    	} else if ($by=='location') {
    		return ($by_location);
    	}
    }
Jerome Mariette's avatar
Jerome Mariette committed
124

125
    function select_projects_evolution($values, $by, $role, $cumulate) {
Penom Nom's avatar
Penom Nom committed
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
		if ($by == "organism" || $by == "location") {
			$by = "tx_nG6_".$by;
		}
	
		$from = "" ;
		$where = "fe_groups.".$by." IN ('".implode("', '", $values)."')" ;
    	if ($role == "create_user") {
    		$from = 'tx_nG6_project '
	    			.' INNER JOIN fe_users ON tx_nG6_project.cruser_id=fe_users.uid '
	    			.' INNER JOIN fe_groups ON fe_groups.uid=fe_users.usergroup ' ;
    	} else if ($role == "manager") {
    		$from = 'tx_nG6_project '
    				.' INNER JOIN fe_rights ON tx_nG6_project.uid=fe_rights.project_id '
    				.' INNER JOIN fe_users ON fe_rights.fe_user_id=fe_users.uid '
    				.' INNER JOIN fe_groups ON fe_groups.uid=fe_users.usergroup ';
Jerome Mariette's avatar
Jerome Mariette committed
141
    		$where .= " AND fe_rights.right_id=1" ;
Penom Nom's avatar
Penom Nom committed
142
143
    	}
    	$queryParts = array(
Jerome Mariette's avatar
Jerome Mariette committed
144
    			'SELECT' 	=> 'tx_nG6_project.crdate, count(tx_nG6_project.crdate) nb',
Penom Nom's avatar
Penom Nom committed
145
146
    			'FROM' 		=> $from,
    			'WHERE' 	=> $where,
Jerome Mariette's avatar
Jerome Mariette committed
147
148
    			'GROUPBY' 	=> 'tx_nG6_project.crdate',
    			'ORDERBY' 	=> 'tx_nG6_project.crdate',
Penom Nom's avatar
Penom Nom committed
149
150
151
152
153
    			'LIMIT' 	=> ''
    	);
    	$results = array();
    	$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
    	while($res_row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
154
155
156
157
158
    		if ($cumulate && count($results) > 0) {
    			$results[] = array($res_row["crdate"], $res_row["nb"] + $results[count($results)-1][1]);
    		} else {
    			$results[] = array($res_row["crdate"], $res_row["nb"]);
    		}
Penom Nom's avatar
Penom Nom committed
159
160
161
162
163
    	}

    	return $results;
    }

164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
    function select_projects_distribution($values, $by, $role) {
		$from = "" ;
		$where = "" ;
		if ($by == "organism" || $by == "location") {
			$by = "tx_nG6_".$by;
		}
    	if ($role == "create_user") {
    		$from = 'tx_nG6_project '
	    			.' INNER JOIN fe_users ON tx_nG6_project.cruser_id=fe_users.uid '
	    			.' INNER JOIN fe_groups ON fe_groups.uid=fe_users.usergroup ' ;
    	} else if ($role == "manager") {
    		$from = 'tx_nG6_project '
    				.' INNER JOIN fe_rights ON tx_nG6_project.uid=fe_rights.project_id '
    				.' INNER JOIN fe_users ON fe_rights.fe_user_id=fe_users.uid '
    				.' INNER JOIN fe_groups ON fe_groups.uid=fe_users.usergroup ';
    		$where = "fe_rights.right_id=1" ;
    	}
    	$queryParts = array(
    			'SELECT' 	=> 'fe_groups.'.$by.', count(fe_groups.'.$by.') nb',
    			'FROM' 		=> $from,
    			'WHERE' 	=> $where,
    			'GROUPBY' 	=> 'fe_groups.'.$by,
    			'ORDERBY' 	=> '',
    			'LIMIT' 	=> ''
    	);
    	$results = array();
    	$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
    	$others = 0 ;
    	while($res_row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
    		if( in_array($res_row[$by], $values) ) {
    			$results[] = array($res_row[$by], $res_row["nb"]);
    		} else {
    			$others += $res_row["nb"] ;
    		}
    	}
    	if ($others != 0) { 
    		$results[] = array("OTHERS", $others);
    	}
    	return $results;
    }
    
Jerome Mariette's avatar
Jerome Mariette committed
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
    function select_storage_distribution($values, $by, $role, $get_analyzes, $octet) {
    	if ($by == "organism" || $by == "location") {
    		$by = "tx_nG6_".$by;
    	}
    	$storage_unit = "full_seq_size";
    	if ($octet) {
    		$storage_unit = "storage_size";
    	}
    	$from = "" ;
    	$where = "" ;
    	if ($role == "create_user") {
    		$from = 'tx_nG6_project '
    		.' INNER JOIN tx_nG6_project_run ON tx_nG6_project_run.project_id= tx_nG6_project.uid'
    		.' INNER JOIN tx_nG6_run ON tx_nG6_project_run.run_id= tx_nG6_run.uid'
    		.' INNER JOIN fe_users ON tx_nG6_project.cruser_id=fe_users.uid '
    		.' INNER JOIN fe_groups ON fe_groups.uid=fe_users.usergroup ' ;
    	} else if ($role == "manager") {
    		$from = 'tx_nG6_project '
    		.' INNER JOIN tx_nG6_project_run ON tx_nG6_project_run.project_id= tx_nG6_project.uid'
    		.' INNER JOIN tx_nG6_run ON tx_nG6_project_run.run_id= tx_nG6_run.uid'
    		.' INNER JOIN fe_rights ON tx_nG6_project.uid=fe_rights.project_id '
    		.' INNER JOIN fe_users ON fe_rights.fe_user_id=fe_users.uid '
    		.' INNER JOIN fe_groups ON fe_groups.uid=fe_users.usergroup ';
    		$where = "fe_rights.right_id=1" ;
    	}
    	$queryParts = array(
    			'SELECT' 	=> 'tx_nG6_run.uid, tx_nG6_run.'.$storage_unit.', fe_groups.'.$by,
    			'FROM' 		=> $from,
    			'WHERE' 	=> $where,
    			'GROUPBY' 	=> '',
    			'ORDERBY' 	=> '',
    			'LIMIT' 	=> ''
    	);
    	
    	$results = array();
    	$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
    	$others = 0 ;
    	while($res_row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
			
    		$analyses_size = 0;
    		if ($get_analyzes && $octet) {
    			$run_analysis = tx_nG6_db::get_run_analysis($res_row["uid"]);
    			foreach($run_analysis as $analyse_id => $analyze_values) {
    				$analyses_size += intval($analyze_values["storage_size"]);
    			}
    		}
    		if( in_array($res_row[$by], $values) ) {
    			
    			if( array_key_exists( $res_row[$by], $results) ) {
    				$results[$res_row[$by]] += $res_row[$storage_unit] + $analyses_size;
    			} else {
    				$results[$res_row[$by]] = $res_row[$storage_unit] + $analyses_size;
    			}
    		} else {
    			$others += $res_row[$storage_unit] + $analyses_size;
    		}
    	}
    	if ($others != 0) {
    		$results["OTHERS"] = $others;
    	}
    	$final_results = array();
    	foreach($results as $group_key => $group_values) {
    		$final_results[] = array( $group_key, $group_values );
    	}
    	return $final_results;
270
271
272
    }
    
    function select_storage_evolution($values, $by, $role, $get_analyzes, $octet, $cumulate) {
Jerome Mariette's avatar
Jerome Mariette committed
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
    	if ($by == "organism" || $by == "location") {
    		$by = "tx_nG6_".$by;
    	}
    	$storage_unit = "full_seq_size";
    	if ($octet) {
    		$storage_unit = "storage_size";
    	}
    	$from = "" ;
    	$where = "fe_groups.".$by." IN ('".implode("', '", $values)."')" ;
    	if ($role == "create_user") {
    		$from = 'tx_nG6_project '
    		.' INNER JOIN tx_nG6_project_run ON tx_nG6_project_run.project_id= tx_nG6_project.uid'
    		.' INNER JOIN tx_nG6_run ON tx_nG6_project_run.run_id= tx_nG6_run.uid'
    		.' INNER JOIN fe_users ON tx_nG6_project.cruser_id=fe_users.uid '
    		.' INNER JOIN fe_groups ON fe_groups.uid=fe_users.usergroup ' ;
    	} else if ($role == "manager") {
    		$from = 'tx_nG6_project '
    		.' INNER JOIN tx_nG6_project_run ON tx_nG6_project_run.project_id= tx_nG6_project.uid'
    		.' INNER JOIN tx_nG6_run ON tx_nG6_project_run.run_id= tx_nG6_run.uid'
    		.' INNER JOIN fe_rights ON tx_nG6_project.uid=fe_rights.project_id '
    		.' INNER JOIN fe_users ON fe_rights.fe_user_id=fe_users.uid '
    		.' INNER JOIN fe_groups ON fe_groups.uid=fe_users.usergroup ';
    		$where .= " AND fe_rights.right_id=1" ;
    	}
    	$queryParts = array(
    			'SELECT' 	=> 'tx_nG6_run.uid, tx_nG6_run.crdate, tx_nG6_run.'.$storage_unit.', fe_groups.'.$by,
    			'FROM' 		=> $from,
    			'WHERE' 	=> $where,
    			'GROUPBY' 	=> '',
    			'ORDERBY' 	=> 'tx_nG6_run.crdate',
    			'LIMIT' 	=> ''
    	);
    	
    	$results = array();
    	$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
    	while($res_row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
			
    		$analyses_size = 0;
    		if ($get_analyzes && $octet) {
    			$run_analysis = tx_nG6_db::get_run_analysis($res_row["uid"]);
    			foreach($run_analysis as $analyse_id => $analyze_values) {
    				$analyses_size += intval($analyze_values["storage_size"]);
    			}
    		}
    		
    		if( array_key_exists( $res_row["crdate"], $results) ) {
    			$results[$res_row["crdate"]] += $res_row[$storage_unit] + $analyses_size;
    		} else {
    			$results[$res_row["crdate"]] = $res_row[$storage_unit] + $analyses_size;
    		}
    	}
    	
    	$final_results = array();
    	foreach($results as $group_key => $group_values) {
    		
    		if ($cumulate && count($final_results) > 0) {
    			$final_results[] = array( $group_key, $group_values + $final_results[count($final_results)-1][1]);
    		} else {
    			$final_results[] = array( $group_key, $group_values );
    		}

    	}
    	return $final_results;
Jerome Mariette's avatar
Jerome Mariette committed
336
    }
337
    
338
339
340
341
342
343
	/*
	 * Project functions
	 *------------------------------------------------------------*/

	/**
	 * Select all project for the current user
344
	 * 
345
	 * @param	string	$user_id	the user id
346
347
	 * @return	table with all projects
	 */
348
	function select_all_user_projects($user_id, $orderby='', $limit='') {		
349
		$projects = array();
Jerome Mariette's avatar
Jerome Mariette committed
350
		
351
		// If the user is not logged on display demonstration project
Jerome Mariette's avatar
Jerome Mariette committed
352
353
354
		if ($user_id == null) { $where = 'tx_nG6_project.public=0'; } 
		else { $where = 'fe_rights.fe_user_id='.$user_id; }
		
355
		//First, get the analyzis project-scale
356
		$queryParts = array(
357
358
359
			'SELECT' => 'tx_nG6_project.uid AS project_id, '.
						'tx_nG6_project.name AS project_name, '.
						'tx_nG6_project.description AS project_description, '.
360
						'tx_nG6_project.public AS project_public, '.
Jerome Mariette's avatar
Jerome Mariette committed
361
						'tx_nG6_project.crdate AS project_crdate, '.
362
363
						'tx_nG6_project.hidden AS project_hidden ',
			'FROM' => 'tx_nG6_project INNER JOIN fe_rights ON fe_rights.project_id=tx_nG6_project.uid',
364
365
			'WHERE' => $where,
			'GROUPBY' => '',
Jerome Mariette's avatar
Jerome Mariette committed
366
367
			'ORDERBY' => $orderby,
			'LIMIT' => $limit
368
		);
369
		$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);		
370
371
		while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
			$project_id = $row['project_id'];
Jerome Mariette's avatar
Jerome Mariette committed
372
			if (!isset ($projects['project_'.$project_id])) {		
373
				$projects['project_'.$project_id] = array(
374
					'id'			=> $project_id,				
375
					'name'			=> $row['project_name'],
Jerome Mariette's avatar
Jerome Mariette committed
376
					'hidden'		=> $row['project_hidden'],
Jerome Mariette's avatar
Jerome Mariette committed
377
					'date'			=> $row['project_crdate'],
378
					'public'		=> $row['project_public'],
379
380
					'description'	=> $row['project_description']);
			}
381
						
382
		}		
383
384
385
		return $projects;
	}

Penom Nom's avatar
Penom Nom committed
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
	/**
	* Select all project for the current user
	*
	* @param	string	$user_id	the user id
	* @return	table with all projects
	*/
	function get_user_projects($user_id, $orderby='', $limit='') {
		$projects = array();
	
		// If the user is not logged on display demonstration project
		if ($user_id == null) {
			$where = 'tx_nG6_project.public=0';
		}
		else { 
				$where = 'fe_rights.fe_user_id='.$user_id.' AND ((fe_rights.right_id<>2 AND tx_nG6_project.hidden=0) '
				.'OR fe_rights.right_id=2)' ;
		}
	
		//First, get the analyzis project-scale
		$queryParts = array(
				'SELECT' => 'tx_nG6_project.uid AS project_id, '.
							'tx_nG6_project.name AS project_name, '.
							'tx_nG6_project.description AS project_description, '.
							'tx_nG6_project.public AS project_public, '.
							'tx_nG6_project.crdate AS project_crdate, '.
							'tx_nG6_project.hidden AS project_hidden ',
				'FROM' => 'tx_nG6_project INNER JOIN fe_rights ON fe_rights.project_id=tx_nG6_project.uid',
				'WHERE' => $where,
				'GROUPBY' => '',
				'ORDERBY' => $orderby,
				'LIMIT' => $limit
		);
		$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
		while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
			$project_id = $row['project_id'];
			if (!isset ($projects['project_'.$project_id])) {
				$projects['project_'.$project_id] = array(
						'id'			=> $project_id,				
						'name'			=> $row['project_name'],
						'hidden'		=> $row['project_hidden'],
						'date'			=> $row['project_crdate'],
						'public'		=> $row['project_public'],
						'description'	=> $row['project_description']);
			}
	
		}
		return $projects;
	}

435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
	/**
	 * Select a run from the database
	 *
	 * @param	string	$project_id	the project id to return
	 * @return	hash table with all project information
	 */
	function select_project($project_id) {
		$queryParts = array(
			'SELECT' => '*',
			'FROM' => 'tx_nG6_project',
			'WHERE' => 'tx_nG6_project.uid = '.$project_id,
			'GROUPBY' => '',
			'ORDERBY' => '',
			'LIMIT' => ''
		);
		$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
Jerome Mariette's avatar
Jerome Mariette committed
451
452
453
454
		$vals = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
		return array('id'			=> $vals['uid'],				
					 'name'			=> $vals['name'],
					 'hidden'		=> $vals['hidden'],
Jerome Mariette's avatar
Jerome Mariette committed
455
					 'date'			=> $vals['crdate'],
Jerome Mariette's avatar
Jerome Mariette committed
456
457
					 'public'		=> $vals['public'],
					 'description'	=> $vals['description']);
458
459
460
461
462
463
464
465
	}

	/**
	 * Select all runs linked to the specified project
	 *
	 * @param	string	$project_id	the project id
	 * @return	hash table with all runs information
	 */
Jerome Mariette's avatar
Jerome Mariette committed
466
    function get_project_runs($project_id, $orderby='', $limit='') {
467
    	
468
		// First select all runs from the database
469
		$queryParts = Array( 
470
471
472
473
			'SELECT' => 'tx_nG6_run.uid AS run_id,'.
					 	'tx_nG6_run.directory AS run_directory,'.
					 	'tx_nG6_run.species AS run_species,'.
						'tx_nG6_run.description AS run_description, '.
Jerome Mariette's avatar
Jerome Mariette committed
474
475
476
						'tx_nG6_run.data_nature AS run_data_nature, '.
						'tx_nG6_run.sequencer AS run_sequencer, '.
						'tx_nG6_run.type AS run_type, '.
477
						'tx_nG6_run.name AS run_name, '.
Jerome Mariette's avatar
Jerome Mariette committed
478
479
						'tx_nG6_run.nb_sequences AS run_nb_sequences, '.
						'tx_nG6_run.full_seq_size AS run_full_seq_size, '.
480
481
						'tx_nG6_run.date AS run_date, '.
						'tx_nG6_run.hidden AS run_hidden, '.
482
483
						'tx_nG6_project.uid AS project_id, '.
						'tx_nG6_project.name AS project_name ',
Jerome Mariette's avatar
Jerome Mariette committed
484
			'FROM' => 'tx_nG6_project '.
485
486
  						'INNER JOIN tx_nG6_project_run ON  tx_nG6_project.uid=tx_nG6_project_run.project_id '.
  						'INNER JOIN tx_nG6_run ON tx_nG6_project_run.run_id=tx_nG6_run.uid ',
Jerome Mariette's avatar
Jerome Mariette committed
487
			'WHERE' => 'tx_nG6_project.uid='.$project_id,
488
			'GROUPBY' => '',
Jerome Mariette's avatar
Jerome Mariette committed
489
490
			'ORDERBY' => $orderby,
			'LIMIT' 	=> $limit
Penom Nom's avatar
Penom Nom committed
491
492
493
		);

	
494
495
496
497
		// Then create the result hash table
		$results = array();
		$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
		while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
Jerome Mariette's avatar
Jerome Mariette committed
498
499
			$run_id = $row['run_id'];				
			if (!isset($results['run_'.$run_id])) {				
500
				$results['run_'.$run_id] = array( 
Jerome Mariette's avatar
Jerome Mariette committed
501
					'id'			=> $run_id,
502
					'directory'		=> $row['run_directory'], 
503
					'name' 			=> $row['run_name'],
Jerome Mariette's avatar
Jerome Mariette committed
504
505
					'project_name' 	=> $row['project_name'],
					'hidden'		=> $row['run_hidden'],
506
					'species' 		=> $row['run_species'],
Jerome Mariette's avatar
Jerome Mariette committed
507
508
509
					'nb_sequences' 	=> $row['run_nb_sequences'],
					'full_seq_size' => $row['run_full_seq_size'],
					'project_id' 	=> $row['project_id'],
510
					'date'			=> $row['run_date'],
Jerome Mariette's avatar
Jerome Mariette committed
511
512
513
					'data_nature'	=> $row['run_data_nature'],
					'sequencer'		=> $row['run_sequencer'],
					'type'			=> $row['run_type'],
Jerome Mariette's avatar
Jerome Mariette committed
514
					'description' 	=> $row['run_description']
515
				);
516
			}						
517
518
519
520
		}
		return $results;
    }

Penom Nom's avatar
Penom Nom committed
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
    /**
     * Select all runs linked to the specified project for the user
     *
     * @param	string	$user_id	the user id
     * @param	string	$project_id	the project id
     * @return	hash table with all runs information
     */
     function get_user_project_runs($user_id, $project_id, $orderby='', $limit='') {
    	// If the user is not logged on display demonstration project
	    if ($user_id == null) {
	    	$where = 'tx_nG6_project.uid='.$project_id.' AND tx_nG6_project.public=0 AND tx_nG6_run.hidden=0';
	    }
	    else {
	    	$where = 'fe_users.uid='.$user_id.' AND '.'tx_nG6_project.uid='.$project_id.
	    		' AND ((fe_rights.right_id<>2 AND tx_nG6_run.hidden=0) OR fe_rights.right_id=2)' ;
	    }
    	
	    // First select all runs from the database
	    $queryParts = Array(
		    'SELECT' => 'tx_nG6_run.uid AS run_id,'.
			    'tx_nG6_run.directory AS run_directory,'.
			    'tx_nG6_run.species AS run_species,'.
			    'tx_nG6_run.description AS run_description, '.
			    'tx_nG6_run.data_nature AS run_data_nature, '.
			    'tx_nG6_run.sequencer AS run_sequencer, '.
			    'tx_nG6_run.type AS run_type, '.
			    'tx_nG6_run.name AS run_name, '.
			    'tx_nG6_run.nb_sequences AS run_nb_sequences, '.
			    'tx_nG6_run.full_seq_size AS run_full_seq_size, '.
			    'tx_nG6_run.date AS run_date, '.
			    'tx_nG6_run.hidden AS run_hidden, '.
			    'tx_nG6_project.uid AS project_id, '.
			    'tx_nG6_project.name AS project_name ',
		    'FROM' => 'tx_nG6_run '.
			    'INNER JOIN tx_nG6_project_run ON tx_nG6_run.uid=tx_nG6_project_run.run_id '.
			    'INNER JOIN tx_nG6_project ON tx_nG6_project_run.project_id=tx_nG6_project.uid '.
			    'INNER JOIN fe_rights ON tx_nG6_project.uid=fe_rights.project_id '.
			    'INNER JOIN fe_users ON fe_rights.fe_user_id=fe_users.uid ',
		    'WHERE' => $where,
		    'GROUPBY' => '',
		    'ORDERBY' => $orderby,
		    'LIMIT' 	=> $limit
	    );
    
	    // Then create the result hash table
	    $results = array();
	    $res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
	    while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
	    	$run_id = $row['run_id'];
	    	if (!isset($results['run_'.$run_id])) {
			    $results['run_'.$run_id] = array(
			    'id'			=> $run_id,
			    'directory'		=> $row['run_directory'],
			    'name' 			=> $row['run_name'],
			    							'project_name' 	=> $row['project_name'],
			    'hidden'		=> $row['run_hidden'],
			    							'species' 		=> $row['run_species'],
			    'nb_sequences' 	=> $row['run_nb_sequences'],
			    							'full_seq_size' => $row['run_full_seq_size'],
			    							'project_id' 	=> $row['project_id'],
			    							'date'			=> $row['run_date'],
			    							'data_nature'	=> $row['run_data_nature'],
			    							'sequencer'		=> $row['run_sequencer'],
			    							'type'			=> $row['run_type'],
			    'description' 	=> $row['run_description']
			    				);
		    }
	    }
	    return $results;
    }

592
593
594
595
596
597
	/**
	 * Select all analysis linked to the specified project
	 *
	 * @param	string	$project_id	the project id
	 * @return	hash table with all analysis information
	 */
Jerome Mariette's avatar
Jerome Mariette committed
598
    function get_project_analysis($project_id, $orderby='', $limit='') {
599
600
    	
    	// First select all analysis from the database    	
601
    	$queryParts = array( 
602
603
			'SELECT' => 'tx_nG6_analyze.uid AS analyze_id,'. 
						'tx_nG6_analyze.directory AS analyze_directory,'. 
604
						'tx_nG6_analyze.name AS analyze_name, '.
605
						'tx_nG6_analyze.class AS analyze_class, '.
606
						'tx_nG6_analyze.date AS analyze_date, '.
Jerome Mariette's avatar
Jerome Mariette committed
607
608
						'tx_nG6_analyze.software AS analyze_software, '.
						'tx_nG6_analyze.version AS analyze_version, '.
609
						'tx_nG6_analyze.params AS analyze_params, '.
610
						'tx_nG6_analyze.description AS analyze_description, '.
611
    					'tx_nG6_analyze.is_editable AS analyze_is_editable, '.
Jerome Mariette's avatar
Jerome Mariette committed
612
						'tx_nG6_analyze.parent_uid AS analyze_parent_uid, '.
613
						'tx_nG6_analyze.hidden AS analyze_hidden ',
Jerome Mariette's avatar
Jerome Mariette committed
614
			'FROM' => 'tx_nG6_project '.
615
616
						'INNER JOIN tx_nG6_project_analyze ON tx_nG6_project.uid = tx_nG6_project_analyze.project_id '.
						'INNER JOIN tx_nG6_analyze ON tx_nG6_analyze.uid=tx_nG6_project_analyze.analyze_id ',
Jerome Mariette's avatar
Jerome Mariette committed
617
			'WHERE' => 'tx_nG6_project.uid='.$project_id,
618
			'GROUPBY' => '',
Jerome Mariette's avatar
Jerome Mariette committed
619
620
			'ORDERBY' => $orderby,
			'LIMIT' => $limit
621
622
623
624
625
626
		);
		// Then create the result hash table
		$results = array();
		$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
		while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
			$analyze_id = $row['analyze_id'];
Jerome Mariette's avatar
Jerome Mariette committed
627
			if (!isset ($results['analyse_'.$analyze_id])) {				
628
629
				$results['analyse_'.$analyze_id] = array( 
					'directory'		=> $row['analyze_directory'], 
630
					'name' 			=> $row['analyze_name'],
631
					'class'			=> $row['analyze_class'],
Jerome Mariette's avatar
Jerome Mariette committed
632
633
					'id' 			=> $row['analyze_id'],
					'hidden' 		=> $row['analyze_hidden'],
634
					'params' 		=> $row['analyze_params'],
Jerome Mariette's avatar
Jerome Mariette committed
635
636
					'software' 		=> $row['analyze_software'],
					'version' 		=> $row['analyze_version'],
637
					'date'			=> $row['analyze_date'],
Jerome Mariette's avatar
Jerome Mariette committed
638
					'description' 	=> $row['analyze_description'],
639
					'is_editable' 	=> $row['analyze_is_editable'],
Jerome Mariette's avatar
Jerome Mariette committed
640
					'parent_id'		=> $row['analyze_parent_uid']	
641
				);
642
			}						
643
644
645
646
		}
		return $results;
    }

Penom Nom's avatar
Penom Nom committed
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
    /**
    * Select all analysis linked to the specified project for the user
    *
    * @param	string	$user_id	the user id
    * @param	string	$project_id	the project id
    * @return	hash table with all analysis information
    */
    function get_user_project_analysis($user_id, $project_id, $orderby='', $limit='') {
    	// If the user is not logged on display demonstration project
    	if ($user_id == null) {
    		$where = 'tx_nG6_project.uid='.$project_id.' AND tx_nG6_project.public=0 AND tx_nG6_run.hidden=0';
    	}
    	else {
    		$where = 'fe_users.uid='.$user_id.' AND tx_nG6_project.uid='.$project_id.
    					' AND ((fe_rights.right_id<>2 AND tx_nG6_analyze.hidden=0) OR fe_rights.right_id=2)' ;
    	}
    	
    	// First select all analysis from the database
    	$queryParts = array(
    			'SELECT' => 'tx_nG6_analyze.uid AS analyze_id,'. 
    						'tx_nG6_analyze.directory AS analyze_directory,'. 
    						'tx_nG6_analyze.name AS analyze_name, '.
    						'tx_nG6_analyze.class AS analyze_class, '.
    						'tx_nG6_analyze.date AS analyze_date, '.
    						'tx_nG6_analyze.software AS analyze_software, '.
    						'tx_nG6_analyze.version AS analyze_version, '.
    						'tx_nG6_analyze.params AS analyze_params, '.
    						'tx_nG6_analyze.description AS analyze_description, '.
675
    						'tx_nG6_analyze.is_editable AS analyze_is_editable, '.
Penom Nom's avatar
Penom Nom committed
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
    						'tx_nG6_analyze.parent_uid AS analyze_parent_uid, '.
    						'tx_nG6_analyze.hidden AS analyze_hidden ',
    			'FROM' => 'tx_nG6_analyze '.
    						'INNER JOIN tx_nG6_project_analyze ON tx_nG6_analyze.uid = tx_nG6_project_analyze.analyze_id '.
    						'INNER JOIN tx_nG6_project ON tx_nG6_project_analyze.project_id=tx_nG6_project.uid '.
							'INNER JOIN fe_rights ON tx_nG6_project.uid=fe_rights.project_id '.
					  		'INNER JOIN fe_users ON fe_rights.fe_user_id=fe_users.uid ',
    			'WHERE' => $where,
    			'GROUPBY' => '',
    			'ORDERBY' => $orderby,
    			'LIMIT' => $limit
    	);
    	// Then create the result hash table
    	$results = array();
    	$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
    	while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
    		$analyze_id = $row['analyze_id'];
    		if (!isset ($results['analyse_'.$analyze_id])) {
    			$results['analyse_'.$analyze_id] = array(
    					'directory'		=> $row['analyze_directory'], 
    					'name' 			=> $row['analyze_name'],
    					'class'			=> $row['analyze_class'],
    					'id' 			=> $row['analyze_id'],
    					'hidden' 		=> $row['analyze_hidden'],
    					'params' 		=> $row['analyze_params'],
    					'software' 		=> $row['analyze_software'],
    					'version' 		=> $row['analyze_version'],
    					'date'			=> $row['analyze_date'],
    					'description' 	=> $row['analyze_description'],
705
    					'is_editable' 	=> $row['analyze_is_editable'],
Penom Nom's avatar
Penom Nom committed
706
707
708
709
710
711
712
    					'parent_id'		=> $row['analyze_parent_uid']	
    			);
    		}
    	}
    	return $results;
    }

713
714
715
716
717
    /**
     * Hide a project and sublevels (runs & analyzes) datas from database project
     * 
     * @param	string	$p_id	the project id to hide
     */
Jerome Mariette's avatar
Jerome Mariette committed
718
	function hide_project($p_id) {
719
720
		
		// First change all project runs
Jerome Mariette's avatar
Jerome Mariette committed
721
		$project_runs = tx_nG6_db::get_project_runs($p_id);
722
		foreach($project_runs as $run_id => $run_values) {
Jerome Mariette's avatar
Jerome Mariette committed
723
			tx_nG6_db::hide_run($run_values['id']);
724
725
726
		}

		// Then all project analysis
Jerome Mariette's avatar
Jerome Mariette committed
727
    	$project_analysis = tx_nG6_db::get_project_analysis($p_id);
728
729
730
		foreach($project_analysis as $analysis_id => $analysis_values) {  
			tx_nG6_db::hide_analysis($analysis_values['id']);
		}
731
		tx_nG6_db::unpublish_project($p_id);
732
733
734
735
736
737
738
739
740
		// Finaly change the project itself
		$GLOBALS['TYPO3_DB']-> exec_UPDATEquery ('tx_nG6_project', 'uid='.$p_id, array('hidden' => '1'));
	}

    /**
     * Unhide a project and sublevels (runs & analyzes) datas
     * 
     * @param	string	$p_id	the project id to hide
     */
Jerome Mariette's avatar
Jerome Mariette committed
741
	function unhide_project($p_id) {
742
743
		
		// First change all project runs
Jerome Mariette's avatar
Jerome Mariette committed
744
		$project_runs = tx_nG6_db::get_project_runs($p_id);
745
		foreach($project_runs as $run_id => $run_values) {
Jerome Mariette's avatar
Jerome Mariette committed
746
			tx_nG6_db::unhide_run($run_values['id']);
747
748
749
		}

		// Then all project analysis
Jerome Mariette's avatar
Jerome Mariette committed
750
    	$project_analysis = tx_nG6_db::get_project_analysis($p_id);
751
752
753
754
755
756
757
758
759
760
761
762
763
		foreach($project_analysis as $analysis_id => $analysis_values) {  
			tx_nG6_db::unhide_analysis($analysis_values['id']);
		}
		
		// Finaly change the project itself
		$GLOBALS['TYPO3_DB']-> exec_UPDATEquery ('tx_nG6_project', 'uid='.$p_id, array('hidden' => '0'));
	}

    /**
     * Publish the project
     * 
     * @param	string	$p_id	the project id to publish
     */
Jerome Mariette's avatar
Jerome Mariette committed
764
	function publish_project($p_id) {
765
		// First unhide the project
Jerome Mariette's avatar
Jerome Mariette committed
766
		tx_nG6_db::unhide_project($p_id);
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
		// The set the project as visible
		$GLOBALS['TYPO3_DB']-> exec_UPDATEquery ('tx_nG6_project', 'uid='.$p_id, array('public' => '0'));
	}

    /**
     * Unpublish the project
     * 
     * @param	string	$p_id	the project id to publish
     */
	function unpublish_project($p_id) {
		$GLOBALS['TYPO3_DB']-> exec_UPDATEquery ('tx_nG6_project', 'uid='.$p_id, array('public' => '1'));
	}

    /**
     * Delete a project and sublevels (runs & analyzes) datas from database project
     * 
     * @param string $p_id			the project id
     * @param string $user_login	the user login
     * @param string $user_pwd		the user password
     * @param string $data_folder	the data folder
     */
Jerome Mariette's avatar
Jerome Mariette committed
788
	function delete_project($p_id, $user_login, $user_pwd, $data_folder) {
789
790
791
		
		$res = 0;
		// All runs
Jerome Mariette's avatar
Jerome Mariette committed
792
		$project_runs = tx_nG6_db::get_project_runs($p_id);
793
794
795
		foreach($project_runs as $run_id => $run_values) {
			if ($run_values['id'] != 'undefined' && $run_values['id'] != '') {
				//delete the run sublevels
Jerome Mariette's avatar
Jerome Mariette committed
796
				$res = tx_nG6_db::delete_run($run_values['id'], $user_login, $user_pwd, $data_folder);
797
798
799
800
801
802
				if ($res != 0) { break; }				
			}
		}
		
		// All project_analysis
		if ($res == 0) {
Jerome Mariette's avatar
Jerome Mariette committed
803
			$project_analysis = tx_nG6_db::get_project_analysis($p_id);
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
			foreach($project_analysis as $analyse_id => $analyze_values) {  
				if ($analyze_values['id'] != 'undefined' && $analyze_values['id'] != '') {
					// delete table 'analyze' entries
					$res = tx_nG6_db::delete_analysis($analyze_values['id'], $user_login, $user_pwd, $data_folder);
					if ($res != 0) { break; }
				}
			}
		}
		
		// Delete DB project entry
		if ($res == 0) {
			$table='tx_nG6_project';
			$where='tx_nG6_project.uid='.$p_id;
			$res1 = $GLOBALS['TYPO3_DB']-> exec_DELETEquery ($table, $where);
			if ($res1 != 1) {$res = 1;}
		}
		
Jerome Mariette's avatar
Jerome Mariette committed
821
822
823
824
825
826
827
828
		// Delete right associated to the project
		if ($res == 0) {
			$table='fe_rights';
			$where='fe_rights.project_id='.$p_id;
			$res1 = $GLOBALS['TYPO3_DB']-> exec_DELETEquery ($table, $where);
			if ($res1 != 1) {$res = 1;}
		}
		
829
830
831
		return $res;
	}

832
833
834
835
836
    /**
     * Return the size of the project
     * 
     * @param	string	$p_id	the project id to return the size
	 * @param	string	$data_folder	the data folder
Jerome Mariette's avatar
Jerome Mariette committed
837
	 * @param	boolean $get_analyzes	get analyzes size ? 
838
     */
839
	function get_project_size($p_id, $get_analyzes=false) {
840
841
842
		
		$full_size = 0;
		// All runs
Jerome Mariette's avatar
Jerome Mariette committed
843
		$project_runs = tx_nG6_db::get_project_runs($p_id);
844
		foreach($project_runs as $run_id => $run_values) {
845
			$full_size += tx_nG6_db::get_run_size($run_values['id'], $get_analyzes);
846
		}
Jerome Mariette's avatar
Jerome Mariette committed
847
848
849
850
		if ($get_analyzes) {
			// All analysis
			$project_analysis = tx_nG6_db::get_project_analysis($p_id);
			foreach($project_analysis as $analyse_id => $analyze_values) {  
851
				$full_size += tx_nG6_db::get_analysis_size($analyze_values['id']);
Jerome Mariette's avatar
Jerome Mariette committed
852
			}
853
854
855
856
		}
		return $full_size;
	}

857
858
859
860

	/*
	 * Run functions
	 *------------------------------------------------------------*/
861
862
	
	
Jerome Mariette's avatar
Jerome Mariette committed
863
864
	/**
	 * Select all run for the specified user
865
	 * 
866
	 * @param	string	$user_id	the user id
Jerome Mariette's avatar
Jerome Mariette committed
867
868
	 * @return	table with all projects
	 */
869
	function select_all_user_runs($user_id, $orderby='', $limit='') {
870

Jerome Mariette's avatar
Jerome Mariette committed
871
		// If the user is not logged on display demonstration project
Jerome Mariette's avatar
Jerome Mariette committed
872
873
874
		if ($user_id == null) { $where = 'tx_nG6_project.public=0'; } 
		else { $where = 'fe_rights.fe_user_id='.$user_id; }
		
Jerome Mariette's avatar
Jerome Mariette committed
875
     	// Execute the request
876
		$queryParts = Array( 
Jerome Mariette's avatar
Jerome Mariette committed
877
878
879
880
			'SELECT' => 'tx_nG6_run.uid AS run_id,'.
					 	'tx_nG6_run.directory AS run_directory,'.
					 	'tx_nG6_run.species AS run_species,'.
						'tx_nG6_run.description AS run_description, '.
881
						'tx_nG6_run.data_nature AS run_data_nature, '. 
Jerome Mariette's avatar
Jerome Mariette committed
882
883
884
885
886
887
888
889
						'tx_nG6_run.sequencer AS run_sequencer, '.
						'tx_nG6_run.type AS run_type, '.
						'tx_nG6_run.name AS run_name, '.
						'tx_nG6_run.nb_sequences AS run_nb_sequences, '.
						'tx_nG6_run.full_seq_size AS run_full_seq_size, '.
						'tx_nG6_run.date AS run_date, '.
						'tx_nG6_run.hidden AS run_hidden, '.
						'tx_nG6_project.uid AS project_id, '.
890
891
892
893
894
						'tx_nG6_project.name AS project_name ',
			'FROM' => 'fe_rights '.
						'INNER JOIN tx_nG6_project ON tx_nG6_project.uid=fe_rights.project_id '.
						'INNER JOIN tx_nG6_project_run ON tx_nG6_project.uid=tx_nG6_project_run.project_id '.
						'INNER JOIN tx_nG6_run ON tx_nG6_project_run.run_id=tx_nG6_run.uid ',
Jerome Mariette's avatar
Jerome Mariette committed
895
896
897
898
			'WHERE' => $where,
			'GROUPBY' => '',
			'ORDERBY' => $orderby,
			'LIMIT' 	=> $limit
899
		); 
Jerome Mariette's avatar
Jerome Mariette committed
900
901
902
903
		// Then create the result hash table
		$results = array();
		$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
		while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
Jerome Mariette's avatar
Jerome Mariette committed
904
905
			$run_id = $row['run_id'];	
			if (!isset($results['run_'.$run_id])) {				
Jerome Mariette's avatar
Jerome Mariette committed
906
				$results['run_'.$run_id] = array(
907
908
					'id'			=> $run_id,  
					'directory'		=> $row['run_directory'], 
Jerome Mariette's avatar
Jerome Mariette committed
909
910
911
912
913
914
915
916
917
918
919
					'name' 			=> $row['run_name'],
					'project_name' 	=> $row['project_name'],
					'project_id' 	=> $row['project_id'],
					'hidden'		=> $row['run_hidden'],
					'species' 		=> $row['run_species'],
					'nb_sequences' 	=> $row['run_nb_sequences'],
					'full_seq_size' => $row['run_full_seq_size'],
					'date'			=> $row['run_date'],
					'data_nature'	=> $row['run_data_nature'],
					'sequencer'		=> $row['run_sequencer'],
					'type'			=> $row['run_type'],
920
					'description' 	=> $row['run_description']				
Jerome Mariette's avatar
Jerome Mariette committed
921
				);
922
			}						
Jerome Mariette's avatar
Jerome Mariette committed
923
924
925
926
927
		}
		return $results;

	}

928
929
930
931
932
933
	/**
	 * Select all information for the specified run
	 *
	 * @param	string	$run_id	the run id
	 * @return	hash table with all the run information
	 */
Jerome Mariette's avatar
Jerome Mariette committed
934
	function select_run($run_id) {
935
		
936
		// First select the run from the database
937
		$queryParts = Array( 
938
939
940
941
942
			'SELECT' => 'tx_nG6_project.uid AS project_id,'.
						'tx_nG6_project.name AS project_name,'.
						'tx_nG6_run.uid AS run_id,'.
					 	'tx_nG6_run.directory AS run_directory,'.
						'tx_nG6_run.description AS run_description, '.
Jerome Mariette's avatar
Jerome Mariette committed
943
						'tx_nG6_run.species AS run_species, '.
944
						'tx_nG6_run.name AS run_name, '.
Jerome Mariette's avatar
Jerome Mariette committed
945
946
947
948
						'tx_nG6_run.data_nature AS run_data_nature, '.
						'tx_nG6_run.sequencer AS run_sequencer, '.
						'tx_nG6_run.type AS run_type, '.
						'tx_nG6_run.full_seq_size, '.
Jerome Mariette's avatar
Jerome Mariette committed
949
						'tx_nG6_run.hidden AS run_hidden, '.
950
						'tx_nG6_run.nb_sequences, '.
951
						'tx_nG6_run.storage_size, '.
952
						'tx_nG6_run.date AS run_date',
953
954
955
956
			'FROM' => 'fe_rights '.
						'INNER JOIN tx_nG6_project ON tx_nG6_project.uid=fe_rights.project_id '.
						'INNER JOIN tx_nG6_project_run ON tx_nG6_project.uid=tx_nG6_project_run.project_id '.
						'INNER JOIN tx_nG6_run ON tx_nG6_project_run.run_id=tx_nG6_run.uid ',
957
958
959
960
			'WHERE' => 'tx_nG6_run.uid='.$run_id,
			'GROUPBY' => '',
			'ORDERBY' => 'tx_nG6_run.date DESC',
			'LIMIT' 	=> ''
961
		); 
962
963
964
		// Then create the result hash table
		$result = array();
		$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
965
966
		while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {			
			$result = array( 
Jerome Mariette's avatar
Jerome Mariette committed
967
				'id'			=> $row['run_id'],  
968
969
970
				'project_id'	=> $row['project_id'], 
				'project_name'	=> $row['project_name'], 
				'directory'		=> $row['run_directory'], 
Jerome Mariette's avatar
Jerome Mariette committed
971
				'name' 			=> $row['run_name'],
Jerome Mariette's avatar
Jerome Mariette committed
972
				'hidden'		=> $row['run_hidden'],
Jerome Mariette's avatar
Jerome Mariette committed
973
974
				'species' 		=> $row['run_species'],
				'nb_sequences' 	=> $row['nb_sequences'],
975
				'storage_size' 	=> intval($row['storage_size']),
Jerome Mariette's avatar
Jerome Mariette committed
976
				'full_seq_size' => $row['full_seq_size'],
Jerome Mariette's avatar
Jerome Mariette committed
977
				'date'			=> $row['run_date'],
Jerome Mariette's avatar
Jerome Mariette committed
978
979
980
				'data_nature' 	=> $row['run_data_nature'],
				'sequencer' 	=> $row['run_sequencer'],
				'type' 			=> $row['run_type'],
981
982
				'description' 	=> $row['run_description']				
			);					
983
984
985
		}
		return $result;
    }
986

987
988
989
990
991
992
993
994
995
996
997
998
999
1000
	/**
	 * Select all mids linked to the specified run
	 *
	 * @param	string	$run_id	the run id
	 * @return	hash table with all mids description
	 */
	function select_mid_descriptions($run_id) {
		
		// First select all analysis from the database
		$queryParts = array( 
			'SELECT' => 'mid, description ',
			'FROM' => 'tx_nG6_sample ',
			'WHERE' => 'run_id='.$run_id,
			'GROUPBY' => '',