Commit fd852934 authored by Penom Nom's avatar Penom Nom
Browse files

navigation links for projects, runs and analyzes

parent e8cdc79d
...@@ -3,7 +3,7 @@ plugin.tx_nG6_pi1 { ...@@ -3,7 +3,7 @@ plugin.tx_nG6_pi1 {
pidList = pidList =
recursive = recursive =
view = view =
results_at_a_time = 100 results_at_a_time = 20
data = /tools/typoweb/ng6/fileadmin data = /tools/typoweb/ng6/fileadmin
} }
plugin.tx_nG6_pi2 { plugin.tx_nG6_pi2 {
......
...@@ -47,11 +47,13 @@ class tx_nG6_pi1 extends tslib_pibase { ...@@ -47,11 +47,13 @@ class tx_nG6_pi1 extends tslib_pibase {
if (strstr($this->cObj->currentRecord,'tt_content')) { if (strstr($this->cObj->currentRecord,'tt_content')) {
$conf['pidList'] = $this->cObj->data['pages']; $conf['pidList'] = $this->cObj->data['pages'];
} }
$this->conf=$conf; // Setting the TypoScript passed to this function in $this->conf $this->conf=$conf; // Setting the TypoScript passed to this function in $this->conf
$this->internal['results_at_a_time'] = $conf["results_at_a_time"];
$this->pi_setPiVarDefaults(); $this->pi_setPiVarDefaults();
$this->pi_USER_INT_obj=1; // Configuring so caching is not expected. This value means that no cHash params are ever set. We do this, because it's a USER_INT object! $this->pi_USER_INT_obj=1; // Configuring so caching is not expected. This value means that no cHash params are ever set. We do this, because it's a USER_INT object!
$this->pi_loadLL(); // Loading the LOCAL_LANG values $this->pi_loadLL(); // Loading the LOCAL_LANG values
if ($this->userIsAuthorized()) { if ($this->userIsAuthorized()) {
switch((string)$this->conf['view']) { switch((string)$this->conf['view']) {
case 'project': case 'project':
...@@ -99,6 +101,16 @@ class tx_nG6_pi1 extends tslib_pibase { ...@@ -99,6 +101,16 @@ class tx_nG6_pi1 extends tslib_pibase {
$this->internal['currentRow'] = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res); $this->internal['currentRow'] = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
return $this->pi_project_single_view(); return $this->pi_project_single_view();
} else { } else {
if (isset($this->piVars['project_page'])) //project position
{
$current_page = intval($this->internal['results_at_a_time']) * (intval($this->piVars['project_page']) -1);
$limit = "$current_page".",". $this->internal['results_at_a_time'] ;
}
else
$limit = '0,'.$this->internal['results_at_a_time'] ;
// If the user is not logged on display demonstration project // If the user is not logged on display demonstration project
if (!$GLOBALS['TSFE']->loginUser) { if (!$GLOBALS['TSFE']->loginUser) {
$where = 'fe_group=0'; $where = 'fe_group=0';
...@@ -111,12 +123,22 @@ class tx_nG6_pi1 extends tslib_pibase { ...@@ -111,12 +123,22 @@ class tx_nG6_pi1 extends tslib_pibase {
'WHERE' => $where, 'WHERE' => $where,
'GROUPBY' => '', 'GROUPBY' => '',
'ORDERBY' => '', 'ORDERBY' => '',
'LIMIT' => '' 'LIMIT' => $limit
); );
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts); $res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
// If there is at least one result // If there is at least one result
if ($GLOBALS['TYPO3_DB']->sql_num_rows($res) > 0) { if ($GLOBALS['TYPO3_DB']->sql_num_rows($res) > 0) {
return $this->pi_project_list_view($res); //request total in DB
$select = 'tx_nG6_project.uid';
$from = $queryParts['FROM'];
$where = $queryParts['WHERE'];
$total_count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows($select, $from, $where);
//generate HTML
$project_list= $this->pi_project_list_view($res);
$nav_links = $this->pi_navigation_link_view('project_page', $this->piVars['project_page'], $total_count);
return $project_list ."\n". $nav_links;
} else { // If no results } else { // If no results
return $this->getFieldHeader('no_raw'); return $this->getFieldHeader('no_raw');
} }
...@@ -188,6 +210,7 @@ class tx_nG6_pi1 extends tslib_pibase { ...@@ -188,6 +210,7 @@ class tx_nG6_pi1 extends tslib_pibase {
*/ */
function pi_run_view() { function pi_run_view() {
if ($this->piVars['run_id']) { // If a single element should be displayed: if ($this->piVars['run_id']) { // If a single element should be displayed:
$queryParts = array( $queryParts = array(
'SELECT' => 'tx_nG6_run.uid AS run_id, tx_nG6_run.name AS name, tx_nG6_project.name AS project_name,' . 'SELECT' => 'tx_nG6_run.uid AS run_id, tx_nG6_run.name AS name, tx_nG6_project.name AS project_name,' .
'tx_nG6_run.date AS date, tx_nG6_run.species AS run_species, tx_nG6_run.data_nature AS run_data_nature,' . 'tx_nG6_run.date AS date, tx_nG6_run.species AS run_species, tx_nG6_run.data_nature AS run_data_nature,' .
...@@ -201,11 +224,21 @@ class tx_nG6_pi1 extends tslib_pibase { ...@@ -201,11 +224,21 @@ class tx_nG6_pi1 extends tslib_pibase {
'GROUPBY' => '', 'GROUPBY' => '',
'ORDERBY' => '', 'ORDERBY' => '',
'LIMIT' => '' 'LIMIT' => ''
); );
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
$this->internal['currentRow'] = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res); $res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
$this->internal['currentRow'] = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
return $this->pi_run_single_view(); return $this->pi_run_single_view();
} else { } else {
if (isset($this->piVars['run_page'])) //run position
{
$current_page = intval($this->internal['results_at_a_time']) * (intval($this->piVars['run_page']) -1);
$limit = "$current_page".",". $this->internal['results_at_a_time'] ;
}
else
$limit = '0,'.$this->internal['results_at_a_time'] ;
// First off, build the rigth sql request // First off, build the rigth sql request
if ($this->piVars['project_id']) { if ($this->piVars['project_id']) {
$where = 'tx_nG6_project_run.project_id='.$this->piVars['project_id']; $where = 'tx_nG6_project_run.project_id='.$this->piVars['project_id'];
...@@ -213,11 +246,11 @@ class tx_nG6_pi1 extends tslib_pibase { ...@@ -213,11 +246,11 @@ class tx_nG6_pi1 extends tslib_pibase {
} else { } else {
if (!$GLOBALS['TSFE']->loginUser) { // If the user is not logged on if (!$GLOBALS['TSFE']->loginUser) { // If the user is not logged on
$where = 'project_id IN ('.$GLOBALS['TYPO3_DB']->SELECTquery('uid', 'tx_nG6_project', 'fe_group=0').')'; $where = 'project_id IN ('.$GLOBALS['TYPO3_DB']->SELECTquery('uid', 'tx_nG6_project', 'fe_group=0').')';
} else { } else {
$where = 'project_id IN ('.$GLOBALS['TYPO3_DB']->SELECTquery('uid', 'tx_nG6_project', 'fe_group IN('.$this->getCurrentUserGroups().')').')'; $where = 'project_id IN ('.$GLOBALS['TYPO3_DB']->SELECTquery('uid', 'tx_nG6_project', 'fe_group IN('.$this->getCurrentUserGroups().')').')';
}
} }
// Then execute it }
// Then execute it
$queryParts = array( $queryParts = array(
'SELECT' => 'tx_nG6_run.uid AS run_id, tx_nG6_run.name AS name, tx_nG6_project.name AS project_name,' . 'SELECT' => 'tx_nG6_run.uid AS run_id, tx_nG6_run.name AS name, tx_nG6_project.name AS project_name,' .
'tx_nG6_run.date AS date, tx_nG6_run.species AS run_species, tx_nG6_run.data_nature AS run_data_nature,' . 'tx_nG6_run.date AS date, tx_nG6_run.species AS run_species, tx_nG6_run.data_nature AS run_data_nature,' .
...@@ -229,15 +262,25 @@ class tx_nG6_pi1 extends tslib_pibase { ...@@ -229,15 +262,25 @@ class tx_nG6_pi1 extends tslib_pibase {
'WHERE' => $where, 'WHERE' => $where,
'GROUPBY' => '', 'GROUPBY' => '',
'ORDERBY' => 'tx_nG6_run.date DESC', 'ORDERBY' => 'tx_nG6_run.date DESC',
'LIMIT' => '' 'LIMIT' => $limit
); );
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts); $res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
if ($GLOBALS['TYPO3_DB']->sql_num_rows($res) > 0) { // There is some results to display if ($GLOBALS['TYPO3_DB']->sql_num_rows($res) > 0) { // There is some results to display
return $this->pi_run_list_view($res); //request total in DB
} else { // no results $select = 'tx_nG6_run.uid';
return $this->getFieldHeader('no_raw'); $from = $queryParts['FROM'];
} $where = $queryParts['WHERE'];
$total_count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows($select, $from, $where);
//generate HTML
$run_list= $this->pi_run_list_view($res);
$nav_links = $this->pi_navigation_link_view('run_page', $this->piVars['run_page'], $total_count);
return $run_list ."\n". $nav_links;
} else { // no results
return $this->getFieldHeader('no_raw');
}
} }
} }
...@@ -247,7 +290,7 @@ class tx_nG6_pi1 extends tslib_pibase { ...@@ -247,7 +290,7 @@ class tx_nG6_pi1 extends tslib_pibase {
* @param ressource $res: A database result ressource * @param ressource $res: A database result ressource
* @return A HTML list if result items * @return A HTML list if result items
*/ */
function pi_run_list_view($res) { function pi_run_list_view($res) {
$nb_run = 0; $nb_run = 0;
if ($this->piVars['project_id']) { if ($this->piVars['project_id']) {
$content = '<br /> <h3> '.$this->getFieldHeader('runs_done').'</h3> <br />'; $content = '<br /> <h3> '.$this->getFieldHeader('runs_done').'</h3> <br />';
...@@ -283,13 +326,13 @@ class tx_nG6_pi1 extends tslib_pibase { ...@@ -283,13 +326,13 @@ class tx_nG6_pi1 extends tslib_pibase {
} else { } else {
$user_groups = t3lib_div::intExplode(',',$this->getCurrentUserGroups()); $user_groups = t3lib_div::intExplode(',',$this->getCurrentUserGroups());
$user_allowed = false; $user_allowed = false;
foreach($this->getSuperGroupsOf($this->internal['currentRow']['project_fe_group']) AS $valeur) { foreach($this->getSuperGroupsOf($this->internal['currentRow']['project_fe_group']) AS $valeur) {
if (in_array($valeur, $user_groups)) { if (in_array($valeur, $user_groups)) {
$user_allowed = true; $user_allowed = true;
$nb_run++; $nb_run++;
} }
} }
if ($user_allowed) { if ($user_allowed) {
$content .= '<tr> $content .= '<tr>
<td '.$this->pi_classParam('hidden').' >'.$this->getFieldContent('name', array('run_id'=>$this->internal['currentRow']['run_id'], 'project_id'=>$this->piVars['project_id'])).'</td> <td '.$this->pi_classParam('hidden').' >'.$this->getFieldContent('name', array('run_id'=>$this->internal['currentRow']['run_id'], 'project_id'=>$this->piVars['project_id'])).'</td>
<td '.$this->pi_classParam('hidden').' >'.$this->getFieldContent('project_name').'</td> <td '.$this->pi_classParam('hidden').' >'.$this->getFieldContent('project_name').'</td>
...@@ -302,11 +345,12 @@ class tx_nG6_pi1 extends tslib_pibase { ...@@ -302,11 +345,12 @@ class tx_nG6_pi1 extends tslib_pibase {
<td '.$this->pi_classParam('hidden').' >'.$this->getFieldContent('run_description').'</td> <td '.$this->pi_classParam('hidden').' >'.$this->getFieldContent('run_description').'</td>
<td '.$this->pi_classParam('hidden').' >'.$this->getFieldContent('run_sequencer').'</td> <td '.$this->pi_classParam('hidden').' >'.$this->getFieldContent('run_sequencer').'</td>
</tr>'; </tr>';
} }
} }
} }
if ($nb_run > 0) { if ($nb_run > 0) {
return $content .= '</table>'; $content .= "\n".'</table>' ;
return $content;
} else { } else {
return ''; return '';
} }
...@@ -318,7 +362,7 @@ class tx_nG6_pi1 extends tslib_pibase { ...@@ -318,7 +362,7 @@ class tx_nG6_pi1 extends tslib_pibase {
* @param ressource $res: A database result ressource * @param ressource $res: A database result ressource
* @return HTML of a single database entry * @return HTML of a single database entry
*/ */
function pi_run_single_view() { function pi_run_single_view() {
$content = '<div'.$this->pi_classParam('singleView').'><h2>Run '.$this->internal['currentRow']['name'].' :</h2>'; $content = '<div'.$this->pi_classParam('singleView').'><h2>Run '.$this->internal['currentRow']['name'].' :</h2>';
$content .= '<p><strong>'.$this->getFieldContent('run_description').'</strong></p> </div> $content .= '<p><strong>'.$this->getFieldContent('run_description').'</strong></p> </div>
<table'.$this->pi_classParam('listrow').'> <table'.$this->pi_classParam('listrow').'>
...@@ -360,6 +404,7 @@ class tx_nG6_pi1 extends tslib_pibase { ...@@ -360,6 +404,7 @@ class tx_nG6_pi1 extends tslib_pibase {
</tr> </tr>
</table>'; </table>';
$content .= $this->pi_analyze_view('run'); $content .= $this->pi_analyze_view('run');
return $content.$this->pi_getEditPanel(); return $content.$this->pi_getEditPanel();
} }
...@@ -370,6 +415,7 @@ class tx_nG6_pi1 extends tslib_pibase { ...@@ -370,6 +415,7 @@ class tx_nG6_pi1 extends tslib_pibase {
* * @return HTML list of table entries * * @return HTML list of table entries
*/ */
function pi_analyze_view($type) { function pi_analyze_view($type) {
if ($type == 'analyze') { // If a single element should be displayed: if ($type == 'analyze') { // If a single element should be displayed:
$queryParts = array( $queryParts = array(
'SELECT' => '*', 'SELECT' => '*',
...@@ -383,6 +429,16 @@ class tx_nG6_pi1 extends tslib_pibase { ...@@ -383,6 +429,16 @@ class tx_nG6_pi1 extends tslib_pibase {
$this->internal['currentRow'] = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res); $this->internal['currentRow'] = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
return $this->pi_analyze_single_view(); return $this->pi_analyze_single_view();
} else { } else {
if (isset($this->piVars['analyze_page'])) //run position
{
$current_page = intval($this->internal['results_at_a_time']) * (intval($this->piVars['analyze_page']) -1);
$limit = "$current_page".",". $this->internal['results_at_a_time'] ;
}
else
$limit = '0,'.$this->internal['results_at_a_time'] ;
if ($type == 'run') { if ($type == 'run') {
// Selects Analyzis done on this run // Selects Analyzis done on this run
$queryParts = array( $queryParts = array(
...@@ -397,7 +453,7 @@ class tx_nG6_pi1 extends tslib_pibase { ...@@ -397,7 +453,7 @@ class tx_nG6_pi1 extends tslib_pibase {
'WHERE' => 'tx_nG6_run_analyze.run_id = '.$this->piVars['run_id'], 'WHERE' => 'tx_nG6_run_analyze.run_id = '.$this->piVars['run_id'],
'GROUPBY' => '', 'GROUPBY' => '',
'ORDERBY' => 'tx_nG6_analyze.name', 'ORDERBY' => 'tx_nG6_analyze.name',
'LIMIT' => '' 'LIMIT' => $limit
); );
} elseif ($type == 'project') { } elseif ($type == 'project') {
// Selects Analyzis done on this project // Selects Analyzis done on this project
...@@ -410,13 +466,19 @@ class tx_nG6_pi1 extends tslib_pibase { ...@@ -410,13 +466,19 @@ class tx_nG6_pi1 extends tslib_pibase {
'WHERE' => 'tx_nG6_project_analyze.project_id = '.$this->piVars['project_id'], 'WHERE' => 'tx_nG6_project_analyze.project_id = '.$this->piVars['project_id'],
'GROUPBY' => '', 'GROUPBY' => '',
'ORDERBY' => 'tx_nG6_analyze.name', 'ORDERBY' => 'tx_nG6_analyze.name',
'LIMIT' => '' 'LIMIT' => $limit
); );
} }
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts); $res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
$content=''; $content='';
if ($GLOBALS['TYPO3_DB']->sql_num_rows($res) > 0) { if ($GLOBALS['TYPO3_DB']->sql_num_rows($res) > 0) {
$content.=$this->pi_analyze_list_view($res); $select = 'tx_nG6_analyze.uid';
$from = $queryParts['FROM'];
$where = $queryParts['WHERE'];
$total_count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows($select, $from, $where);
$analyze_list=$this->pi_analyze_list_view($res , $total_count);
$nav_links = $this->pi_navigation_link_view('analyze_page', $this->piVars['analyze_page'], $total_count);
$content.= $analyze_list ."\n".$nav_links;
} }
return $content; return $content;
} }
...@@ -466,8 +528,9 @@ class tx_nG6_pi1 extends tslib_pibase { ...@@ -466,8 +528,9 @@ class tx_nG6_pi1 extends tslib_pibase {
} }
} }
} }
if ($nb_analyse > 0) { if ($nb_analyse > 0) {
return $content .= '</table>'; $content .= "\n".'</table>' ;
return $content ;
} else { } else {
return ''; return '';
} }
...@@ -764,6 +827,50 @@ class tx_nG6_pi1 extends tslib_pibase { ...@@ -764,6 +827,50 @@ class tx_nG6_pi1 extends tslib_pibase {
return $reslist; return $reslist;
} }
/**
* Display links for navigation in run lists or analyse lists. Called only if $end>1
*
* @param $name name of the variable set in GET: run_page or analyze_page
* @param $start current page number
* @param $maxline current total number of rows
*
* @return HTML navigation links
*/
function pi_navigation_link_view($name, $start, $total_count)
{
$start = intval($start);
//max page number
$end = $total_count/$this->internal['results_at_a_time'] ;
$end = ceil($end) ;
//repair URL mistakes caused by the nasty user
if ($start > $end)
$start = $end;
if (($start < 1) or (! $start))
$start = 1;
$start=(string)$start ; $end=(string)$end ;
//create navigation links
$go_back = $this->pi_linkTP_keepPIvars ('<<', array ($name => 1)) .' '. $this->pi_linkTP_keepPIvars ('<', array ($name => $start-1));
$go_ahead= $this->pi_linkTP_keepPIvars ('>', array ($name => $start+1)).' '.$this->pi_linkTP_keepPIvars ('>>', array ($name => $end));
$current_pos = 'page '.$start. '/'.$end;
if( $end == '1' ) { //do nothing
return '' ;
}
elseif($start == '1') { //don't display << nor <
$go_back = '';
}
elseif($start == $end) { //don't display > nor >>
$go_ahead = '';
}
else { //display both
}
$content = '<div align="right">'.$go_back .' '. $current_pos .' '. $go_ahead .'</div>' ;
return $content;
}
......
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