Commit b90f03ff authored by Jerome Mariette's avatar Jerome Mariette
Browse files

code improvment

parent 3eb28a8b
......@@ -52,14 +52,14 @@ class tx_nG6_eid {
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($user_id, $project_id, 'tx_nG6_run.date DESC');
$project_runs = tx_nG6_db::get_project_runs($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($user_id, $project_id, 'tx_nG6_analyze.name');
$project_analysis = tx_nG6_db::get_project_analysis($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>';
}
......
......@@ -64,12 +64,11 @@ class tx_nG6_db {
*/
function select_all_user_projects($user_id, $orderby='', $limit='') {
$projects = array();
// If the user is not logged on display demonstration project
if (!$GLOBALS['TSFE']->loginUser) {
$where = 'tx_nG6_project.public=0';
} else {
$where = 'fe_rights.fe_user_id='.$user_id;
}
if ($user_id == null) { $where = 'tx_nG6_project.public=0'; }
else { $where = 'fe_rights.fe_user_id='.$user_id; }
//First, get the analyzis project-scale
$queryParts = array(
'SELECT' => 'tx_nG6_project.uid AS project_id, '.
......@@ -136,19 +135,10 @@ class tx_nG6_db {
/**
* Select all runs linked to the specified project
*
* @param string $user_id the user id
* @param string $project_id the project id
* @return hash table with all runs information
*/
function get_project_runs($user_id, $project_id, $orderby='', $limit='') {
// where clause
if (!$GLOBALS['TSFE']->loginUser) {
$where = 'tx_nG6_project.public=0';
} else {
$where = 'fe_rights.fe_user_id='.$user_id;
}
$where .= ' AND tx_nG6_project.uid='.$project_id;
function get_project_runs($project_id, $orderby='', $limit='') {
// First select all runs from the database
$queryParts = Array(
......@@ -166,15 +156,15 @@ class tx_nG6_db {
'tx_nG6_run.hidden AS run_hidden, '.
'tx_nG6_project.uid AS project_id, '.
'tx_nG6_project.name AS project_name ',
'FROM' => 'fe_rights '.
'INNER JOIN tx_nG6_project ON fe_rights.project_id=tx_nG6_project.uid '.
'FROM' => 'tx_nG6_project '.
'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 ',
'WHERE' => $where,
'WHERE' => 'tx_nG6_project.uid='.$project_id,
'GROUPBY' => '',
'ORDERBY' => $orderby,
'LIMIT' => $limit
);
// Then create the result hash table
$results = array();
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
......@@ -212,19 +202,10 @@ class tx_nG6_db {
/**
* Select all analysis linked to the specified project
*
* @param string $user_id the user group
* @param string $project_id the project id
* @return hash table with all analysis information
*/
function get_project_analysis($user_id, $project_id, $orderby='', $limit='') {
// where clause
if (!$GLOBALS['TSFE']->loginUser) {
$where = 'tx_nG6_project.public=0';
} else {
$where = 'fe_rights.fe_user_id='.$user_id;
}
$where .= ' AND tx_nG6_project.uid='.$project_id;
function get_project_analysis($project_id, $orderby='', $limit='') {
// First select all analysis from the database
$queryParts = array(
......@@ -239,11 +220,10 @@ class tx_nG6_db {
'tx_nG6_analyze.description AS analyze_description, '.
'tx_nG6_analyze.parent_uid AS analyze_parent_uid, '.
'tx_nG6_analyze.hidden AS analyze_hidden ',
'FROM' => 'fe_rights '.
'INNER JOIN tx_nG6_project ON fe_rights.project_id=tx_nG6_project.uid '.
'FROM' => 'tx_nG6_project '.
'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 ',
'WHERE' => $where,
'WHERE' => 'tx_nG6_project.uid='.$project_id,
'GROUPBY' => '',
'ORDERBY' => $orderby,
'LIMIT' => $limit
......@@ -288,13 +268,13 @@ class tx_nG6_db {
function hide_project($p_id, $user_id) {
// First change all project runs
$project_runs = tx_nG6_db::get_project_runs($user_id, $p_id);
$project_runs = tx_nG6_db::get_project_runs($p_id);
foreach($project_runs as $run_id => $run_values) {
tx_nG6_db::hide_run($run_values['id'], $user_id);
}
// Then all project analysis
$project_analysis = tx_nG6_db::get_project_analysis($user_id, $p_id);
$project_analysis = tx_nG6_db::get_project_analysis($p_id);
foreach($project_analysis as $analysis_id => $analysis_values) {
tx_nG6_db::hide_analysis($analysis_values['id']);
}
......@@ -312,13 +292,13 @@ class tx_nG6_db {
function unhide_project($p_id, $user_id) {
// First change all project runs
$project_runs = tx_nG6_db::get_project_runs($user_id, $p_id);
$project_runs = tx_nG6_db::get_project_runs($p_id);
foreach($project_runs as $run_id => $run_values) {
tx_nG6_db::unhide_run($run_values['id'], $user_id);
}
// Then all project analysis
$project_analysis = tx_nG6_db::get_project_analysis($user_id, $p_id);
$project_analysis = tx_nG6_db::get_project_analysis($p_id);
foreach($project_analysis as $analysis_id => $analysis_values) {
tx_nG6_db::unhide_analysis($analysis_values['id']);
}
......@@ -362,7 +342,7 @@ class tx_nG6_db {
$res = 0;
// All runs
$project_runs = tx_nG6_db::get_project_runs($user_id, $p_id);
$project_runs = tx_nG6_db::get_project_runs($p_id);
foreach($project_runs as $run_id => $run_values) {
if ($run_values['id'] != 'undefined' && $run_values['id'] != '') {
//delete the run sublevels
......@@ -373,7 +353,7 @@ class tx_nG6_db {
// All project_analysis
if ($res == 0) {
$project_analysis = tx_nG6_db::get_project_analysis($user_id, $p_id);
$project_analysis = tx_nG6_db::get_project_analysis($p_id);
foreach($project_analysis as $analyse_id => $analyze_values) {
if ($analyze_values['id'] != 'undefined' && $analyze_values['id'] != '') {
// delete table 'analyze' entries
......@@ -405,12 +385,12 @@ class tx_nG6_db {
$full_size = 0;
// All runs
$project_runs = tx_nG6_db::get_project_runs($user_id, $p_id);
$project_runs = tx_nG6_db::get_project_runs($p_id);
foreach($project_runs as $run_id => $run_values) {
$full_size += tx_nG6_db::get_run_size($run_values['id'], $data_folder, $user_id);
}
// All analysis
$project_analysis = tx_nG6_db::get_project_analysis($user_id, $p_id);
$project_analysis = tx_nG6_db::get_project_analysis($p_id);
foreach($project_analysis as $analyse_id => $analyze_values) {
$full_size += tx_nG6_db::get_analysis_size($analyze_values['id'], $data_folder);
}
......@@ -432,11 +412,9 @@ class tx_nG6_db {
function select_all_user_runs($user_id, $orderby='', $limit='') {
// If the user is not logged on display demonstration project
if (!$GLOBALS['TSFE']->loginUser) {
$where = 'tx_nG6_project.public=0';
} else {
$where = 'fe_rights.fe_user_id='.$user_id;
}
if ($user_id == null) { $where = 'tx_nG6_project.public=0'; }
else { $where = 'fe_rights.fe_user_id='.$user_id; }
// Execute the request
$queryParts = Array(
'SELECT' => 'tx_nG6_run.uid AS run_id,'.
......@@ -1103,7 +1081,7 @@ class tx_nG6_db {
$is_admin = false;
if($GLOBALS['TSFE']->loginUser){
if(!$user_id == null){
// Project
if ($type == 'project') {
......
......@@ -143,11 +143,15 @@ class tx_nG6_pi1 extends tslib_pibase {
*/
function pi_project_view() {
$projects = array();
if (!$GLOBALS['TSFE']->loginUser) { $user_id = null; }
else { $user_id = $GLOBALS['TSFE']->fe_user->user['uid']; }
// If a single element
if ($this->piVars['project_id']) {
$projects = array('project_'.$this->piVars['project_id'] => tx_nG6_db::select_project($this->piVars['project_id']));
} else {
$projects = tx_nG6_db::select_all_user_projects($GLOBALS['TSFE']->fe_user->user['uid'], 'tx_nG6_project.name');
$projects = tx_nG6_db::select_all_user_projects($user_id, 'tx_nG6_project.name');
}
$smarty = new Smarty();
$smarty->setTemplateDir(t3lib_extMgm::extPath('nG6').'/pi1');
......@@ -205,9 +209,9 @@ class tx_nG6_pi1 extends tslib_pibase {
}
// Add some information to the table
$project_runs = tx_nG6_db::get_project_runs($GLOBALS['TSFE']->fe_user->user['uid'], $projects[key($projects)]['id']);
$project_runs = tx_nG6_db::get_project_runs($projects[key($projects)]['id']);
foreach($project_runs as $run_id => $run_values) {
if (tx_nG6_db::is_administrator($GLOBALS['TSFE']->fe_user->user['uid'], 'run', $run_values['id']) ) {
if (tx_nG6_db::is_administrator($user_id, 'run', $run_values['id']) ) {
$project_runs[$run_id]['is_run_admin'] = true;
} else {
$project_runs[$run_id]['is_run_admin'] = false;
......@@ -215,12 +219,12 @@ class tx_nG6_pi1 extends tslib_pibase {
$project_runs[$run_id]['href'] = $this->pi_list_linkSingle($run_values['name'],$run_values['id'],1, array('run_id'=>$run_values['id'], 'project_id'=>$run_values['project_id']));
}
$smarty->assign('project_runs', $project_runs);
$project_analysis = tx_nG6_db::get_project_analysis($GLOBALS['TSFE']->fe_user->user['uid'], $projects[key($projects)]['id']);
$project_analysis = tx_nG6_db::get_project_analysis($projects[key($projects)]['id']);
// Add some information to the table
foreach($project_analysis as $analysis_id => $analysis_values) {
if (tx_nG6_db::is_administrator($GLOBALS['TSFE']->fe_user->user['uid'], 'analyze', $analysis_values['id']) ) {
if (tx_nG6_db::is_administrator($user_id, 'analyze', $analysis_values['id']) ) {
$project_analysis[$analysis_id]['is_analyze_admin'] = true;
} else {
$project_analysis[$analysis_id]['is_analyze_admin'] = false;
......@@ -246,11 +250,14 @@ class tx_nG6_pi1 extends tslib_pibase {
function pi_run_view() {
$runs = array();
if (!$GLOBALS['TSFE']->loginUser) { $user_id = null; }
else { $user_id = $GLOBALS['TSFE']->fe_user->user['uid']; }
// If a single element
if ($this->piVars['run_id']) {
$runs = array('run_'.$this->piVars['run_id'] => tx_nG6_db::select_run($this->piVars['run_id']));
} else {
$runs = tx_nG6_db::select_all_user_runs($GLOBALS['TSFE']->fe_user->user['uid']);
$runs = tx_nG6_db::select_all_user_runs($user_id);
}
$smarty = new Smarty();
$smarty->setTemplateDir(t3lib_extMgm::extPath('nG6').'/pi1');
......@@ -263,7 +270,7 @@ class tx_nG6_pi1 extends tslib_pibase {
// Add some information to the table
$run_ids = "";
foreach($runs as $run_id => $run_values) {
if (tx_nG6_db::is_administrator($GLOBALS['TSFE']->fe_user->user['uid'], 'run', $run_values['id']) ) {
if (tx_nG6_db::is_administrator($user_id, 'run', $run_values['id']) ) {
$runs[$run_id]['is_admin'] = true;
} else {
$runs[$run_id]['is_admin'] = false;
......@@ -288,7 +295,7 @@ class tx_nG6_pi1 extends tslib_pibase {
$run_analysis = tx_nG6_db::get_run_analysis($GLOBALS['TSFE']->fe_user->user['uid'], $runs[key($runs)]['id']);
// Add some information to the table
foreach($run_analysis as $analysis_id => $analysis_values) {
if (tx_nG6_db::is_administrator($GLOBALS['TSFE']->fe_user->user['uid'], 'analyze', $analysis_values['id']) ) {
if (tx_nG6_db::is_administrator($user_id, 'analyze', $analysis_values['id']) ) {
$run_analysis[$analysis_id]['is_admin'] = true;
} else {
$run_analysis[$analysis_id]['is_admin'] = false;
......
......@@ -101,7 +101,9 @@ class tx_nG6_pi5 extends tslib_pibase {
$smarty->assign('tmp_url', substr($this->conf["temp"], strpos($this->conf["temp"], "fileadmin")));
// Build the lists of all elements
$projects = tx_nG6_db::select_all_user_projects($GLOBALS['TSFE']->fe_user->user['uid'], 'tx_nG6_project.name');
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');
$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