Commit 0e821ce8 authored by Penom Nom's avatar Penom Nom
Browse files

Fix hidden analysis download bug.

parent 586daa71
......@@ -47,19 +47,19 @@ class tx_nG6_eid {
tslib_eidtools::connectDB();
$type = trim(t3lib_div::_GP('type'));
$user_id = trim(t3lib_div::_GP('user_id'));
// If the type of data requested is project
if ($type == 'project') {
$project_id = trim(t3lib_div::_GP('id'));
// Select all runs linked to the project
$project_runs = tx_nG6_db::get_project_runs($project_id, 'tx_nG6_run.date DESC');
$project_runs = tx_nG6_db::get_user_project_runs($user_id, $project_id, 'tx_nG6_run.date DESC');
// for each run
$html_tree = '';
foreach($project_runs as $run_id => $run_values) {
$html_tree .= '<li class="jstree-closed" name=\''.str_replace(array('###SPAN_NAME###', '###SPAN_DATE###'), array($run_values['name'], strftime('%d-%m-%y',$run_values['date'])), trim(t3lib_div::_GP('run_short_description'))).'\' id=\''.$run_id.'\'> <a href=\'#\'>'.str_replace(array('###SPAN_NAME###', '###SPAN_DATE###', '###SPAN_NB_SEQ###', '###SPAN_SPECIES###'), array($run_values['name'], strftime('%d-%m-%y',$run_values['date']), $run_values['nb_sequences'], $run_values['species']), trim(t3lib_div::_GP('run_description'))).'</a></li>';
}
// Then all project analysis
$project_analysis = tx_nG6_db::get_project_analysis($project_id, 'tx_nG6_analyze.name');
$project_analysis = tx_nG6_db::get_user_project_analysis($user_id, $project_id, 'tx_nG6_analyze.name');
foreach($project_analysis as $analyse_id => $analyse_values) {
$html_tree .= '<li name=\''.str_replace(array('###SPAN_NAME###'), array($analyse_values["name"]), trim(t3lib_div::_GP('analyse_description'))).'\' id=\''.$analyse_id.'\'> <a href=\'#\'>'.str_replace(array('###SPAN_NAME###'), array($analyse_values["name"]), trim(t3lib_div::_GP('analyse_description'))).'</a></li>';
}
......@@ -70,7 +70,7 @@ class tx_nG6_eid {
} else if ($type == 'run'){
$run_id = trim(t3lib_div::_GP('id'));
// Select all analysis linked to the run and the run information
$run_analysis = tx_nG6_db::get_run_analysis($run_id, 'tx_nG6_analyze.name');
$run_analysis = tx_nG6_db::get_user_run_analysis($user_id, $run_id, 'tx_nG6_analyze.name');
$run_info = tx_nG6_db::select_run($run_id);
// for each analysis
$html_tree = '';
......@@ -675,7 +675,7 @@ class tx_nG6_eid {
/**
* Returns a table with the right directories structure considering ids
*
* @param string $user_id the user id
* @param string $user_id The user id
* @param array $ids List of ids to download
* @param string $data_folder The data folder where are stored the data
* @param string $output_folder The output directory
......@@ -710,7 +710,7 @@ class tx_nG6_eid {
$ddest .= '.'.$run["project_id"]."/Run_".str_replace($char_to_replace, '_', $run["name"]).".".$id[1]."/RawData";
$dest_directories[] = $ddest;
}
foreach(tx_nG6_db::get_run_analysis($id[1], 'tx_nG6_analyze.name') as $analyse_id => $analyse_values) {
foreach(tx_nG6_db::get_user_run_analysis($user_id, $id[1], 'tx_nG6_analyze.name') as $analyse_id => $analyse_values) {
$aid = preg_split("/_/", $analyse_id);
if (!in_array($data_folder.$analyse_values["directory"], $src_directories)) {
$src_directories[] = $data_folder.$analyse_values["directory"];
......
......@@ -222,6 +222,55 @@ class tx_nG6_db {
return $projects;
}
/**
* 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;
}
/**
* Select a run from the database
*
......@@ -278,8 +327,9 @@ class tx_nG6_db {
'GROUPBY' => '',
'ORDERBY' => $orderby,
'LIMIT' => $limit
);
);
// Then create the result hash table
$results = array();
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
......@@ -307,6 +357,77 @@ class tx_nG6_db {
return $results;
}
/**
* 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;
}
/**
* Select all analysis linked to the specified project
*
......@@ -360,6 +481,70 @@ class tx_nG6_db {
return $results;
}
/**
* 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, '.
'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'],
'parent_id' => $row['analyze_parent_uid']
);
}
}
return $results;
}
/**
* Hide a project and sublevels (runs & analyzes) datas from database project
*
......@@ -702,6 +887,72 @@ class tx_nG6_db {
return $results;
}
/**
* Select all analysis linked to the specified run for the user
*
* @param string $user_id the user id
* @param string $run_id the run id
* @return hash table with all analysis information
*/
function get_user_run_analysis($user_id, $run_id, $orderby='', $limit='') {
// If the user is not logged on display demonstration project
if ($user_id == null) {
$where = 'tx_nG6_run_analyze.run_id='.$run_id.' AND tx_nG6_project.public=0 AND tx_nG6_analyze.hidden=0' ;
}
else {
$where = 'fe_users.uid='.$user_id.' AND '.'tx_nG6_run_analyze.run_id='.$run_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.params AS analyze_params, '.
'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.hidden AS analyze_hidden, '.
'tx_nG6_analyze.description AS analyze_description, '.
'tx_nG6_analyze.parent_uid AS analyze_parent_uid ',
'FROM' => 'tx_nG6_analyze '.
'INNER JOIN tx_nG6_run_analyze ON tx_nG6_analyze.uid = tx_nG6_run_analyze.analyze_id '.
'INNER JOIN tx_nG6_run ON tx_nG6_run_analyze.run_id = tx_nG6_run.uid '.
'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)) {
$analyze_id = $row['analyze_id'];
if (!isset ($results['analyse_'.$analyze_id])) {
$results['analyse_'.$analyze_id] = array(
'directory' => $row['analyze_directory'],
'name' => $row['analyze_name'],
'params' => $row['analyze_params'],
'class' => $row['analyze_class'],
'id' => $row['analyze_id'],
'hidden' => $row['analyze_hidden'],
'software' => $row['analyze_software'],
'version' => $row['analyze_version'],
'date' => $row['analyze_date'],
'description' => $row['analyze_description'],
'parent_id' => $row['analyze_parent_uid']
);
}
}
return $results;
}
/**
* Delete a run, sample and sublevel (analyzes) datas from database project
*
......
......@@ -103,7 +103,7 @@ class tx_nG6_pi5 extends tslib_pibase {
// Build the lists of all elements
if (!$GLOBALS['TSFE']->loginUser) { $user_id = null; }
else { $user_id = $GLOBALS['TSFE']->fe_user->user['uid']; }
$projects = tx_nG6_db::select_all_user_projects($user_id, 'tx_nG6_project.name');
$projects = tx_nG6_db::get_user_projects($user_id, 'tx_nG6_project.name');
$smarty->assign('projects', $projects);
return $smarty->fetch('download_view.tpl');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment