Hallo zusammen ... auch auf die Gefahr hin, dass die Frage schonmal gestellt wurde und ich einfach nur zu blöd zum Bedienen einer Suchmaschine bin:
wie stelle ich es an, dass anstatt der UID ein anderer Parameter (z.B. Titel) automatisch und in alphabetischer Reihenfolge in der Listenansicht ausgegeben wird?
Ich habe das CD-Tut von Kasper als Anfang genommen und eine Art Videodatenbank analog dazu erstellt. Im Prinzip sieht das auch alles ganz schön aus, aber in der Listenansicht kommt ständig die Sortierung nach UID und nicht automatisch nach Titel
Die class.tx_vtlmoviedatabase_pi1.php sieht so aus:
...require_once(PATH_tslib.'class.tslib_pibase.php');
/**
* Plugin 'Movie database' for the 'vtl_moviedatabase' extension.
*
* @author Thomas Aurich <xxxx>
* @package TYPO3
* @subpackage tx_vtlmoviedatabase
*/
class tx_vtlmoviedatabase_pi1 extends tslib_pibase {
var $prefixId = 'tx_vtlmoviedatabase_pi1'; // Same as class name
var $scriptRelPath = 'pi1/class.tx_vtlmoviedatabase_pi1.php'; // Path to this script relative to the extension dir.
var $extKey = 'vtl_moviedatabase'; // 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'] = 'tx_vtlmoviedatabase_movies';
$this->internal['currentRow'] = $this->pi_getRecord('tx_vtlmoviedatabase_movies',$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,20); // Number of results to show in a listing.
$this->internal['maxPages']=t3lib_div::intInRange($lConf['maxPages'],0,1000,2);; // The maximum number of "pages" in the browse-box: "Page 1", "Page 2", etc.
$this->internal['searchFieldList']='title,year,artist,description';
$this->internal['orderByList']='title,year,artist,uid';
// Get number of records:
$res = $this->pi_exec_query('tx_vtlmoviedatabase_movies',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('tx_vtlmoviedatabase_movies');
$this->internal['currentTable'] = 'tx_vtlmoviedatabase_movies';
// 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 search box:
$fullTable.=$this->pi_list_searchBox();
// Adds the result browser:
$fullTable.=$this->pi_list_browseresults();
// Adds the mode selector.
# $fullTable.=$this->pi_list_modeSelector($items);
// Adds the whole list table
$fullTable.=$this->pi_list_makelist($res);
// 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 border="0" cellpadding="5" cellspacing="5" width="100%">
<tr valign="top">
<td width="70%" bgcolor="#FFFFCC">
<!--Table list-->
<table cellpadding="2" border="0" cellspacing="2">
<tr valign="top">
<td nowrap="nowrap" valign="top" this-="">pi_classParam('singleView-HCell').' width="100px"><b><p>'.$this->getFieldHeader('title').'</p></b></td>
<td valign="top"><p>'.$this->getFieldContent('title').'</p></td>
</tr>
<tr valign="top">
<td nowrap="nowrap" valign="top" this-="">pi_classParam('singleView-HCell').'><p>'.$this->getFieldHeader('year').'</p></td>
<td valign="top"><p>'.$this->getFieldContent('year').'</p></td>
</tr>
<tr valign="top">
<td nowrap="nowrap" valign="top" this-="">pi_classParam('singleView-HCell').'><p>'.$this->getFieldHeader('artist').'</p></td>
<td valign="top"><p>'.$this->getFieldContent('artist').'</p></td>
</tr>
<tr valign="top">
<td nowrap="nowrap" valign="top" this-="">pi_classParam('singleView-HCell').'><p>'.$this->getFieldHeader('category').'</p></td>
<td valign="top"><p>'.$this->getFieldContent('category').'</p></td>
</tr>
</table>
<!--Table list-->
</td>
<td width="30%">
<!--Table picture-->
<table cellspacing="5" cellpadding="5" border="0">
<tr valign="top">
<td><td valign="top"><p>'.$this->getFieldContent('coverimage').'</p></td> </td>
</tr>
</table>
<!--Table picture-->
</td>
</tr>
<tr valign="top">
<td nowrap="nowrap" align="left" colspan="2" this-="">pi_classParam('singleView-HCell').'><p><b>'.$this->getFieldHeader('description').'</b></p></td>
</tr>
<tr valign="top">
<td colspan="2"><p>'.$this->getFieldContent('description').'</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) {
$editPanel = $this->pi_getEditPanel();
if ($editPanel) $editPanel='<td>'.$editPanel.'</td>';
return '<tr'.($c%2 this-="">pi_classParam('listrow-odd') : '').' valign="top" >
<td valign="top" class="movie_list_row"><p>'.$this->getFieldContent('title').'</p></td>
<td valign="top" class="movie_list_row"><p>'.$this->getFieldContent('year').'</p></td>
<td valign="top" class="movie_list_row"><p>'.$this->getFieldContent('artist').'</p></td>
<td valign="top" class="movie_list_row"><p>'.$this->getFieldContent('category').'</p></td>
</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').' valign="top" >
<td class="movie_list_header" width="35%"><p>'.$this->getFieldHeader_sortLink('title').'</p></td>
<td class="movie_list_header" width="*"><p>'.$this->getFieldHeader_sortLink('year').'</p></td>
<td class="movie_list_header" width="35%"><p>'.$this->getFieldHeader_sortLink('artist').'</p></td>
<td nowrap="" class="movie_list_header" width="10%"></td>
</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']['uid'],1); // The "1" means that the display of single items is CACHED! Set to zero to disable caching.
break;
case "title":
// This will wrap the title in a link.
return $this->pi_list_linkSingle($this->internal['currentRow']['title'],$this->internal['currentRow']['uid'],1);
break;
case "coverimage":
$imgTSConfig=$this->conf['coverImageCObject.'];
$bilder=t3lib_div::trimExplode(",",$this->internal['currentRow']["$fN"]);
$i=0;
$spalten=3;
foreach($bilder as $bild)
{
if(($i%$spalten) == 0)
{
$content.='';
}
$imgTSConfig['file']='uploads/tx_vtlmoviedatabase/'.$bild;
$content.=$this->cObj->IMAGE($imgTSConfig);
$content.= ' ';
$i++;
}
return $content;
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) {
case "title":
return $this->pi_getLL('listFieldHeader_title','<em>title</em>');
break;
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/vtl_moviedatabase/pi1/class.tx_vtlmoviedatabase_pi1.php']) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/vtl_moviedatabase/pi1/class.tx_vtlmoviedatabase_pi1.php']);
}
?>
und die ext_tables.php so
<?php
if (!defined ('TYPO3_MODE')) die ('Access denied.');
t3lib_extMgm::allowTableOnStandardPages('tx_vtlmoviedatabase_movies');
t3lib_extMgm::addToInsertRecords('tx_vtlmoviedatabase_movies');
$TCA["tx_vtlmoviedatabase_movies"] = array (
"ctrl" => array (
'title' => 'LLL:EXT:vtl_moviedatabase/locallang_db.xml:tx_vtlmoviedatabase_movies',
'label' => 'title',
'tstamp' => 'tstamp',
'crdate' => 'crdate',
'cruser_id' => 'cruser_id',
'type' => 'title',
'default_sortby' => "ORDER BY title",
'delete' => 'deleted',
'enablecolumns' => array (
'disabled' => 'hidden',
),
'dynamicConfigFile' => t3lib_extMgm::extPath($_EXTKEY).'tca.php',
'iconfile' => t3lib_extMgm::extRelPath($_EXTKEY).'icon_tx_vtlmoviedatabase_movies.gif',
),
"feInterface" => array (
"fe_admin_fieldList" => "title, year, artist, category, coverimage, description",
"label" => "title",
)
);
t3lib_div::loadTCA('tt_content');
$TCA['tt_content']['types']['list']['subtypes_excludelist'][$_EXTKEY.'_pi1']='layout,select_key';
t3lib_extMgm::addPlugin(array('LLL:EXT:vtl_moviedatabase/locallang_db.xml:tt_content.list_type_pi1', $_EXTKEY.'_pi1'),'list_type');
t3lib_extMgm::addStaticFile($_EXTKEY,'pi1/static/','Movie database');
if (TYPO3_MODE=="BE") $TBE_MODULES_EXT["xMOD_db_new_content_el"]["addElClasses"]["tx_vtlmoviedatabase_pi1_wizicon"] = t3lib_extMgm::extPath($_EXTKEY).'pi1/class.tx_vtlmoviedatabase_pi1_wizicon.php';
?>
Kann mir jemand einen Tipp geben? Danke!