00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00072 class t3lib_loadDBGroup {
00073
00074 var $fromTC = 1;
00075 var $registerNonTableValues=0;
00076
00077
00078 var $tableArray=Array();
00079 var $itemArray=Array();
00080 var $nonTableArray=array();
00081 var $additionalWhere=array();
00082 var $checkIfDeleted = 1;
00083 var $dbPaths=Array();
00084 var $firstTable = '';
00085 var $secondTable = '';
00086
00087
00088
00089
00099 function start($itemlist,$tablelist, $MMtable='',$MMuid=0) {
00100
00101 if (!strcmp(trim($tablelist),'*')) {
00102 $tablelist = implode(',',array_keys($GLOBALS['TCA']));
00103 }
00104
00105
00106 $tempTableArray = t3lib_div::trimExplode(',',$tablelist,1);
00107 foreach($tempTableArray as $key => $val) {
00108 $tName = trim($val);
00109 $this->tableArray[$tName] = Array();
00110 if ($this->checkIfDeleted && $GLOBALS['TCA'][$tName]['ctrl']['delete']) {
00111 $fieldN = $tName.'.'.$GLOBALS['TCA'][$tName]['ctrl']['delete'];
00112 $this->additionalWhere[$tName].=' AND NOT '.$fieldN;
00113 }
00114 }
00115
00116 if (is_array($this->tableArray)) {
00117 reset($this->tableArray);
00118 } else {return 'No tables!';}
00119
00120
00121 $this->firstTable = key($this->tableArray);
00122 next($this->tableArray);
00123 $this->secondTable = key($this->tableArray);
00124
00125
00126 if ($MMtable) {
00127 $this->readMM($MMtable,$MMuid);
00128 } else {
00129
00130 $this->readList($itemlist);
00131 }
00132 }
00133
00140 function readList($itemlist) {
00141 if ((string)trim($itemlist)!='') {
00142 $tempItemArray = t3lib_div::trimExplode(',', $itemlist);
00143 foreach($tempItemArray as $key => $val) {
00144 $isSet = 0;
00145
00146
00147 $val = strrev($val);
00148 $parts = explode('_',$val,2);
00149 $theID = strrev($parts[0]);
00150
00151
00152 if (t3lib_div::testInt($theID)) {
00153
00154 $theTable = trim($parts[1]) ? strrev(trim($parts[1])) : ($this->secondTable && $theID<0 ? $this->secondTable : $this->firstTable);
00155
00156 if ((string)$theID!='' && $theID && $theTable && isset($this->tableArray[$theTable])) {
00157
00158 $theID = $this->secondTable ? abs(intval($theID)) : intval($theID);
00159
00160 $this->itemArray[$key]['id'] = $theID;
00161 $this->itemArray[$key]['table'] = $theTable;
00162 $this->tableArray[$theTable][] = $theID;
00163
00164 $isSet=1;
00165 }
00166 }
00167
00168
00169 if (!$isSet && $this->registerNonTableValues) {
00170 $this->itemArray[$key]['id'] = $tempItemArray[$key];
00171 $this->itemArray[$key]['table'] = '_NO_TABLE';
00172 $this->nonTableArray[] = $tempItemArray[$key];
00173 }
00174 }
00175 }
00176 }
00177
00186 function readMM($tableName,$uid) {
00187 $key=0;
00188
00189
00190 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $tableName, 'uid_local='.intval($uid), '', 'sorting');
00191 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00192 $theTable = $row['tablenames'] ? $row['tablenames'] : $this->firstTable;
00193 if (($row['uid_foreign'] || $theTable=='pages') && $theTable && isset($this->tableArray[$theTable])) {
00194 $this->itemArray[$key]['id'] = $row['uid_foreign'];
00195 $this->itemArray[$key]['table'] = $theTable;
00196 $this->tableArray[$theTable][]= $row['uid_foreign'];
00197 } elseif ($this->registerNonTableValues) {
00198 $this->itemArray[$key]['id'] = $row['uid_foreign'];
00199 $this->itemArray[$key]['table'] = '_NO_TABLE';
00200 $this->nonTableArray[] = $row['uid_foreign'];
00201 }
00202 $key++;
00203 }
00204 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00205 }
00206
00215 function writeMM($tableName,$uid,$prependTableName=0) {
00216
00217
00218 $GLOBALS['TYPO3_DB']->exec_DELETEquery($tableName, 'uid_local='.intval($uid));
00219
00220
00221 $tableC = count($this->tableArray);
00222 if ($tableC) {
00223 $prep = ($tableC>1||$prependTableName) ? 1 : 0;
00224 $c=0;
00225 $tName=array();
00226
00227
00228 foreach($this->itemArray as $val) {
00229 $c++;
00230
00231 $insertFields = array(
00232 'uid_local' => $uid,
00233 'uid_foreign' => $val['id'],
00234 'sorting' => $c
00235 );
00236 if ($prep || $val['table']=='_NO_TABLE') {
00237 $insertFields['tablenames'] = $val['table'];
00238 }
00239
00240 $GLOBALS['TYPO3_DB']->exec_INSERTquery($tableName, $insertFields);
00241 }
00242 }
00243 }
00244
00251 function getValueArray($prependTableName='') {
00252
00253 $valueArray=Array();
00254 $tableC = count($this->tableArray);
00255
00256
00257 if ($tableC) {
00258
00259 $prep = ($tableC>1||$prependTableName) ? 1 : 0;
00260
00261
00262 foreach($this->itemArray as $val) {
00263 $valueArray[]=(($prep && $val['table']!='_NO_TABLE') ? $val['table'].'_' : '').
00264 $val['id'];
00265 }
00266 }
00267
00268 return $valueArray;
00269 }
00270
00279 function convertPosNeg($valueArray,$fTable,$nfTable) {
00280 if (is_array($valueArray) && $fTable) {
00281 foreach($valueArray as $key => $val) {
00282 $val = strrev($val);
00283 $parts = explode('_',$val,2);
00284 $theID = strrev($parts[0]);
00285 $theTable = strrev($parts[1]);
00286
00287 if ( t3lib_div::testInt($theID) && (!$theTable || !strcmp($theTable,$fTable) || !strcmp($theTable,$nfTable)) ) {
00288 $valueArray[$key]= $theTable && strcmp($theTable,$fTable) ? $theID*-1 : $theID;
00289 }
00290 }
00291 }
00292 return $valueArray;
00293 }
00294
00301 function getFromDB() {
00302
00303 foreach($this->tableArray as $key => $val) {
00304 if (is_array($val)) {
00305 $itemList = implode(',',$val);
00306 if ($itemList) {
00307 $from = '*';
00308 if ($this->fromTC) {
00309 $from = 'uid,pid';
00310 if ($GLOBALS['TCA'][$key]['ctrl']['label']) {
00311 $from.= ','.$GLOBALS['TCA'][$key]['ctrl']['label'];
00312 }
00313 if ($GLOBALS['TCA'][$key]['ctrl']['thumbnail']) {
00314 $from.= ','.$GLOBALS['TCA'][$key]['ctrl']['thumbnail'];
00315 }
00316 }
00317 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($from, $key, 'uid IN ('.$itemList.')'.$this->additionalWhere[$key]);
00318 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00319 $this->results[$key][$row['uid']]=$row;
00320 }
00321 }
00322 }
00323 }
00324 return $this->results;
00325 }
00326
00333 function readyForInterface() {
00334 global $TCA;
00335
00336 if (!is_array($this->itemArray)) {return false;}
00337
00338 $output=array();
00339 $perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
00340 $titleLen=intval($GLOBALS['BE_USER']->uc['titleLen']);
00341
00342 foreach($this->itemArray as $key => $val) {
00343 $theRow = $this->results[$val['table']][$val['id']];
00344 if ($theRow && is_array($TCA[$val['table']])) {
00345 $label = t3lib_div::fixed_lgd_cs(strip_tags($theRow[$TCA[$val['table']]['ctrl']['label']]),$titleLen);
00346 $label = ($label)?$label:'[...]';
00347 $output[]=str_replace(',','',$val['table'].'_'.$val['id'].'|'.rawurlencode($label));
00348 }
00349 }
00350 return implode(',',$output);
00351 }
00352 }
00353
00354
00355 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_loaddbgroup.php']) {
00356 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_loaddbgroup.php']);
00357 }
00358 ?>