<config>
<type>select</type>
<itemsProcFunc>user_itemsProcFuncforfile->files_insertExtraCodes</itemsProcFunc>
<foreign_table>tx_extdocument_list</foreign_table>
<foreign_table_where>and tx_extdocument_list.deleted=0 and tx_extdocument_list.hidden=0</foreign_table_where>
<maxitems>1000</maxitems>
<size>10</size>
<multiple>0</multiple>
<selectedListStyle>width:300px</selectedListStyle>
<itemListStyle>width:300px</itemListStyle>
</config>
<?php
/**
* ‘itemsProcFunc’ for the ‘document’ extension.
* @package TYPO3
* @subpackage shop
*/
class user_itemsProcFuncforfile {
/**
* insert ‘codes’, found in the [‘what_to_display’] array to the selector in the BE.
*
* @param array $config: extension configuration array
* @return array $config array with extra codes merged in
*/
function files_insertExtraCodes($config) {
$sql = "SELECT * FROM tx_extdocument_list where deleted=’0′ AND hidden=’0’";
if ( ! ($res = $GLOBALS[‘TYPO3_DB’]->sql_query($sql)) ) { return; }
$presets = array();
while ($row = $GLOBALS[‘TYPO3_DB’]->sql_fetch_assoc($res))
{
$filetype = end(explode(".",$row[‘file_name_tmp’]));
$presets[] = array($row[‘file_name’].’ (‘.$filetype.$this->fileSizeShow($row[‘file_size’]).’)’,$row[‘uid’]);
}
$config[‘items’] = array_merge($config[‘items’], $presets);
return $config;
}
/**
* fileSizeShow KB MB
* @param $filesize
* @return size
*/
function fileSizeShow($filesize=0) {
if ($filesize<1024) {
return ‘,’.number_format($filesize)."KB";
}elseif ($filesize<1024*1024){
return ‘,’.number_format($filesize/1024)."MB";
}else{
return ‘,’.number_format($filesize/(1024*1024))."GB";
}
}
}
?>