[TYPO3] kickstarter orderby date
Tim Boesenkool
boesenkool at gmail.com
Mon Jul 31 09:31:40 CEST 2006
I've been working in typo3 for a few years now, (non coder, but have
learned a lot).
I have still yet to completlety work out a problem with the orderby
function in the output from the kickstarter.
I have a small extension that is a simple list of files associated
with a date. I would like the default to be in chronological DESC
order.
I have modified everything else I need, and I can get the column heads
to sort correctly when clicked, but I can't get the initial page to
load correctly after a new record is added. It always defaults to the
bottom of the list.
I would be hugely appreciative if someone could look over my code and
tell me if they can see where I am wrong.
Thank you and Regards
<?php
/***************************************************************
* Copyright notice
*
* (c) 2006 Admin <tim at boesenkool.com>
* 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!
***************************************************************/
/**
* Plugin 'Carrier Reports2' for the 'user_carreports' extension.
*
* @author Admin <tim at boesenkool.com>
*/
require_once(PATH_tslib.'class.tslib_pibase.php');
class user_carreports_pi1 extends tslib_pibase {
var $prefixId = 'user_carreports_pi1'; // Same as class name
var $scriptRelPath = 'pi1/class.user_carreports_pi1.php'; // Path to
this script relative to the extension dir.
var $extKey = 'user_carreports'; // The extension key.
var $pi_checkCHash = TRUE;
/**
* Main method of your PlugIn
*
* @param string $content: The content of the PlugIn
* @param array $conf: The PlugIn Configuration
* @return The content that should be displayed on the website
*/
function main($content,$conf) {
switch((string)$conf['CMD']) {
case 'singleView':
list($t) = explode(':',$this->cObj->currentRecord);
$this->internal['currentTable']=$t;
$this->internal['currentRow']=$this->cObj->data;
return $this->pi_wrapInBaseClass($this->singleView($content,$conf));
break;
default:
if (strstr($this->cObj->currentRecord,'tt_content')) {
$conf['pidList'] = $this->cObj->data['pages'];
$conf['recursive'] = $this->cObj->data['recursive'];
}
return $this->pi_wrapInBaseClass($this->listView($content,$conf));
break;
}
}
/**
* Shows a list of database entries
*
* @param string $content: content of the PlugIn
* @param array $conf: PlugIn Configuration
* @return HTML list of table entries
*/
function listView($content,$conf) {
$this->conf=$conf; // Setting the TypoScript passed to this
function in $this->conf
$this->pi_setPiVarDefaults();
$this->pi_loadLL(); // Loading the LOCAL_LANG values
$lConf = $this->conf['listView.']; // Local settings for the listView function
if ($this->piVars['showUid']) { // If a single element should be displayed:
$this->internal['currentTable'] = 'user_carreports_f';
$this->internal['currentRow'] =
$this->pi_getRecord('user_carreports_f',$this->piVars['showUid']);
$content = $this->singleView($content,$conf);
return $content;
} else {
$items=array(
'1'=> $this->pi_getLL('list_mode_1','Mode 1'),
'2'=> $this->pi_getLL('list_mode_2','Mode 2'),
'3'=> $this->pi_getLL('list_mode_3','Mode 3'),
);
if (!isset($this->piVars['pointer'])) $this->piVars['pointer']=0;
if (!isset($this->piVars['mode'])) $this->piVars['mode']=1;
// Initializing the query parameters:
list($this->internal['orderBy'],$this->internal['descFlag'])
= explode(':',$this->piVars['sort']);
$this->internal['results_at_a_time']=t3lib_div::intInRange($lConf['results_at_a_time'],0,1000,14);
// Number of results to show in a listing.
$this->internal['maxPages']=t3lib_div::intInRange($lConf['maxPages'],0,1000,9);;
// The maximum number of "pages" in the browse-box: "Page 1",
"Page 2", etc.
$this->internal['searchFieldList']='';
// $this->internal['orderByList']='file_date';
// ALTER TABLE `user_carreports_f` ORDER BY `file_date` DESC
// Get number of records:
$res = $this->pi_exec_query('user_carreports_f',1);
list($this->internal['res_count']) =
$GLOBALS['TYPO3_DB']->sql_fetch_row($res);
// Make listing query, pass query to SQL database:
$res = $this->pi_exec_query('user_carreports_f');
$this->internal['currentTable'] = 'user_carreports_f';
// Put the whole list together:
$fullTable=''; // Clear var;
# $fullTable.=t3lib_div::view_array($this->piVars); // DEBUG: Output
the content of $this->piVars for debug purposes. REMEMBER to comment
out the IP-lock in the debug() function in t3lib/config_default.php if
nothing happens when you un-comment this line!
// Adds the mode selector.
// $fullTable.=$this->pi_list_modeSelector($items);
// Adds the whole list table
$fullTable.=$this->pi_list_makelist($res);
// Adds the search box:
// $fullTable.=$this->pi_list_searchBox();
// Adds the result browser:
$fullTable.=$this->pi_list_browseresults();
// Returns the content from the plugin.
return $fullTable;
}
}
/**
* Display a single item from the database
*
* @param string $content: The PlugIn content
* @param array $conf: The PlugIn configuration
* @return HTML of a single database entry
*/
function singleView($content,$conf) {
$this->conf=$conf;
$this->pi_setPiVarDefaults();
$this->pi_loadLL();
// This sets the title of the page for use in indexed search results:
if ($this->internal['currentRow']['title']) $GLOBALS['TSFE']->indexedDocTitle=$this->internal['currentRow']['title'];
$content='<div'.$this->pi_classParam('singleView').'>
<H2>Record "'.$this->internal['currentRow']['uid'].'" from table
"'.$this->internal['currentTable'].'":</H2>
<table>
<tr>
<td nowrap="nowrap"
valign="top"'.$this->pi_classParam('singleView-HCell').'><p>'.$this->getFieldHeader('file_name').'</p></td>
<td valign="top"><p>'.$this->getFieldContent('file_name').'</p></td>
</tr>
<tr>
<td nowrap="nowrap"
valign="top"'.$this->pi_classParam('singleView-HCell').'><p>'.$this->getFieldHeader('file_date').'</p></td>
<td valign="top"><p>'.$this->getFieldContent('file_date').'</p></td>
</tr>
<tr>
<td nowrap="nowrap"
valign="top"'.$this->pi_classParam('singleView-HCell').'><p>'.$this->getFieldHeader('opslink').'</p></td>
<td valign="top"><p>'.$this->getFieldContent('opslink').'</p></td>
</tr>
<tr>
<td nowrap="nowrap"
valign="top"'.$this->pi_classParam('singleView-HCell').'><p>'.$this->getFieldHeader('detailslink').'</p></td>
<td valign="top"><p>'.$this->getFieldContent('detailslink').'</p></td>
</tr>
<tr>
<td nowrap="nowrap"
valign="top"'.$this->pi_classParam('singleView-HCell').'><p>'.$this->getFieldHeader('instructions').'</p></td>
<td valign="top"><p>'.$this->getFieldContent('instructions').'</p></td>
</tr>
<tr>
<td nowrap="nowrap"
valign="top"'.$this->pi_classParam('singleView-HCell').'><p>'.$this->getFieldHeader('uploadfilestotheoceancarrierssection').'</p></td>
<td valign="top"><p>'.$this->getFieldContent('uploadfilestotheoceancarrierssection').'</p></td>
</tr>
<tr>
<td nowrap'.$this->pi_classParam('singleView-HCell').'><p>Last
updated:</p></td>
<td valign="top"><p>'.date('d-m-Y
H:i',$this->internal['currentRow']['tstamp']).'</p></td>
</tr>
<tr>
<td nowrap'.$this->pi_classParam('singleView-HCell').'><p>Created:</p></td>
<td valign="top"><p>'.date('d-m-Y
H:i',$this->internal['currentRow']['crdate']).'</p></td>
</tr>
</table>
<p>'.$this->pi_list_linkSingle($this->pi_getLL('back','Back'),0).'</p></div>'.
$this->pi_getEditPanel();
return $content;
}
/**
* Returns a single table row for list view
*
* @param integer $c: Counter for odd / even behavior
* @return A HTML table row
*/
function pi_list_row($c) {
$updateLink = $this->getFieldContent('opslink');
if($updateLink!=""){$updateOut='<td valign="top"
align="center" nowrap><p><a
href="'.$this->getFieldContent('opslink').'"
target="_blank">'.$this->getFieldHeader('opslink').'</a> </p></td>';}else
{$updateOut='<td valign="top" nowrap> </td>';}
$detailLink = $this->getFieldContent('detailslink');
if($detailLink!=""){$detailOut='<td valign="top"
align="center" nowrap><p><a
href="'.$this->getFieldContent('detailslink').'"
target="_blank">'.$this->getFieldHeader('detailslink').'</a> </p></td>';}
$editPanel = $this->pi_getEditPanel();
if ($editPanel) $editPanel='<TD>'.$editPanel.'</TD>';
return '<tr'.($c%2 ? $this->pi_classParam('listrow-odd') : '').'>
<td valign="top"
nowrap><p><strong>'.$this->getFieldContent('file_name').' </strong></p></td>
<td nowrap><p> </p></td>
<td valign="top"
nowrap><p>'.$this->getFieldContent('file_date').' </p></td>
<td nowrap width="100%"><p> </p></td>
'.$updateOut.'
'.$detailOut.'
</tr>
';
}
/**
* Returns a table row with column names of the table
*
* @return A HTML table row
*/
function pi_list_header() {
return '<tr'.$this->pi_classParam('listrow-header').'>
<td nowrap><p> </p></td>
<td nowrap><p> </p></td>
<th valign="top"
nowrap><p>'.$this->getFieldHeader_sortLink('file_date').'<img
src="fileadmin/template/tsi/images/carriers/up_dn.gif" alt="Sort"
width="13" height="13" /></p></th>
<td nowrap width="100%"><p> </p></td>
<th valign="top" nowrap><p>Download PDF</p></th>
<th valign="top" nowrap><p>Download PDF</p></th>
</tr>';
}
/**
* Returns the content of a given field
*
* @param string $fN: name of table field
* @return Value of the field
*/
function getFieldContent($fN) {
switch($fN) {
case 'uid':
return $this->pi_list_linkSingle($this->internal['currentRow'][$fN],$this->internal['currentRow']['file_date'],1); //
The "1" means that the display of single items is CACHED! Set to zero
to disable caching.
break;
case 'file_date':
// For a numbers-only date, use something like: %d-%m-%y
return
strftime('%a - %e %b %y',$this->internal['currentRow']['file_date']);
break;
default:
return $this->internal['currentRow'][$fN];
break;
}
}
/**
* Returns the label for a fieldname from local language array
*
* @param [type] $fN: ...
* @return [type] ...
*/
function getFieldHeader($fN) {
switch($fN) {
default:
return $this->pi_getLL('listFieldHeader_'.$fN,'['.$fN.']');
break;
}
}
/**
* Returns a sorting link for a column header
*
* @param string $fN: Fieldname
* @return The fieldlabel wrapped in link that contains sorting vars
*/
function getFieldHeader_sortLink($fN) {
return $this->pi_linkTP_keepPIvars($this->getFieldHeader($fN),array('sort'=>$fN.':'.($this->internal['descFlag']?0:1)));
}
}
if (defined('TYPO3_MODE') &&
$TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/user_carreports/pi1/class.user_carreports_pi1.php']) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/user_carreports/pi1/class.user_carreports_pi1.php']);
}
?>
More information about the TYPO3-english
mailing list