Documentation TYPO3 par Ameos

class.t3lib_loaddbgroup.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2006 Kasper Skaarhoj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00076 class t3lib_loadDBGroup {
00077                 // External, static:
00078         var $fromTC = 1;                                        // Means that only uid and the label-field is returned
00079         var $registerNonTableValues=0;          // If set, values that are not ids in tables are normally discarded. By this options they will be preserved.
00080 
00081                 // Internal, dynamic:
00082         var $tableArray=Array();                        // Contains the table names as keys. The values are the id-values for each table. Should ONLY contain proper table names.
00083         var $itemArray=Array();                         // Contains items in an numeric array (table/id for each). Tablenames here might be "_NO_TABLE"
00084         var $nonTableArray=array();                     // Array for NON-table elements
00085         var $additionalWhere=array();
00086         var $checkIfDeleted = 1;                        // deleted-column is added to additionalWhere... if this is set...
00087         var $dbPaths=Array();
00088         var $firstTable = '';                           // Will contain the first table name in the $tablelist (for positive ids)
00089         var $secondTable = '';                          // Will contain the second table name in the $tablelist (for negative ids)
00090                 // private
00091         var $MM_is_foreign = 0;         // boolean - if 1, uid_local and uid_foreign are switched, and the current table is inserted as tablename - this means you display a foreign relation "from the opposite side"
00092         var $MM_oppositeField = '';     // field name at the "local" side of the MM relation
00093         var $MM_oppositeTable = ''; // only set if MM_is_foreign is set
00094         var $MM_oppositeFieldConf = ''; // only set if MM_is_foreign is set
00095         var $MM_isMultiTableRelationship = 0;   // is empty by default; if MM_is_foreign is set and there is more than one table allowed (on the "local" side), then it contains the first table (as a fallback)
00096         var $currentTable;      // current table => Only needed for reverse relations
00097         var $undeleteRecord;            // if a record should be undeleted (so do not use the $useDeleteClause on t3lib_BEfunc)
00098 
00099 
00100         var $MM_match_fields = array(); // array of fields value pairs that should match while SELECT and will be written into MM table if $MM_insert_fields is not set
00101         var $MM_insert_fields = array();        // array of fields and value pairs used for insert in MM table
00102         var $MM_table_where = ''; // extra MM table where
00103 
00104 
00116         function start($itemlist, $tablelist, $MMtable='', $MMuid=0, $currentTable='', $conf=array())   {
00117                         // SECTION: MM reverse relations
00118                 $this->MM_is_foreign = ($conf['MM_opposite_field']?1:0);
00119                 $this->MM_oppositeField = $conf['MM_opposite_field'];
00120                 $this->MM_table_where = $conf['MM_table_where'];
00121                 $this->MM_match_fields = is_array($conf['MM_match_fields']) ? $conf['MM_match_fields'] : array();
00122                 $this->MM_insert_fields = is_array($conf['MM_insert_fields']) ? $conf['MM_insert_fields'] : $this->MM_match_fields;
00123                 
00124                 $this->currentTable = $currentTable;
00125                 if ($this->MM_is_foreign)       {
00126                         $tmp = ($conf['type']==='group'?$conf['allowed']:$conf['foreign_table']);
00127                                 // normally, $conf['allowed'] can contain a list of tables, but as we are looking at a MM relation from the foreign side, it only makes sense to allow one one table in $conf['allowed']
00128                         $tmp = t3lib_div::trimExplode(',', $tmp);
00129                         $this->MM_oppositeTable = $tmp[0];
00130                         unset($tmp);
00131 
00132                                 // only add the current table name if there is more than one allowed field
00133                         $this->MM_oppositeFieldConf = $GLOBALS['TCA'][$this->MM_oppositeTable]['columns'][$this->MM_oppositeField]['config'];
00134 
00135                         if ($this->MM_oppositeFieldConf['allowed'])     {
00136                                 $oppositeFieldConf_allowed = explode(',', $this->MM_oppositeFieldConf['allowed']);
00137                                 if (count($oppositeFieldConf_allowed) > 1)      {
00138                                         $this->MM_isMultiTableRelationship = $oppositeFieldConf_allowed[0];
00139                                 }
00140                         }
00141                 }
00142 
00143                         // SECTION:     normal MM relations
00144 
00145                         // If the table list is "*" then all tables are used in the list:
00146                 if (!strcmp(trim($tablelist),'*'))      {
00147                         $tablelist = implode(',',array_keys($GLOBALS['TCA']));
00148                 }
00149 
00150                         // The tables are traversed and internal arrays are initialized:
00151                 $tempTableArray = t3lib_div::trimExplode(',',$tablelist,1);
00152                 foreach($tempTableArray as $key => $val)        {
00153                         $tName = trim($val);
00154                         $this->tableArray[$tName] = Array();
00155                         if ($this->checkIfDeleted && $GLOBALS['TCA'][$tName]['ctrl']['delete']) {
00156                                 $fieldN = $tName.'.'.$GLOBALS['TCA'][$tName]['ctrl']['delete'];
00157                                 $this->additionalWhere[$tName].=' AND '.$fieldN.'=0';
00158                         }
00159                 }
00160 
00161                 if (is_array($this->tableArray))        {
00162                         reset($this->tableArray);
00163                 } else {return 'No tables!';}
00164 
00165                         // Set first and second tables:
00166                 $this->firstTable = key($this->tableArray);             // Is the first table
00167                 next($this->tableArray);
00168                 $this->secondTable = key($this->tableArray);    // If the second table is set and the ID number is less than zero (later) then the record is regarded to come from the second table...
00169 
00170                         // Now, populate the internal itemArray and tableArray arrays:
00171                 if ($MMtable)   {       // If MM, then call this function to do that:
00172                         $this->readMM($MMtable,$MMuid);
00173                 } elseif ($MMuid && $conf['foreign_field']) {
00174                                 // If not MM but foreign_field, the read the records by the foreign_field
00175                         $this->readForeignField($MMuid, $conf);
00176                 } else {
00177                                 // If not MM, then explode the itemlist by "," and traverse the list:
00178                         $this->readList($itemlist);
00179                                 // do automatic default_sortby, if any
00180                         if ($conf['foreign_default_sortby']) {
00181                                 $this->sortList($conf['foreign_default_sortby']);
00182                         }
00183                 }
00184         }
00185 
00192         function readList($itemlist)    {
00193                 if ((string)trim($itemlist)!='')        {
00194                         $tempItemArray = t3lib_div::trimExplode(',', $itemlist);        // Changed to trimExplode 31/3 04; HMENU special type "list" didn't work if there were spaces in the list... I suppose this is better overall...
00195                         foreach($tempItemArray as $key => $val) {
00196                                 $isSet = 0;     // Will be set to "1" if the entry was a real table/id:
00197 
00198                                         // Extract table name and id. This is un the formular [tablename]_[id] where table name MIGHT contain "_", hence the reversion of the string!
00199                                 $val = strrev($val);
00200                                 $parts = explode('_',$val,2);
00201                                 $theID = strrev($parts[0]);
00202 
00203                                         // Check that the id IS an integer:
00204                                 if (t3lib_div::testInt($theID)) {
00205                                                 // Get the table name: If a part of the exploded string, use that. Otherwise if the id number is LESS than zero, use the second table, otherwise the first table
00206                                         $theTable = trim($parts[1]) ? strrev(trim($parts[1])) : ($this->secondTable && $theID<0 ? $this->secondTable : $this->firstTable);
00207                                                 // If the ID is not blank and the table name is among the names in the inputted tableList, then proceed:
00208                                         if ((string)$theID!='' && $theID && $theTable && isset($this->tableArray[$theTable]))   {
00209                                                         // Get ID as the right value:
00210                                                 $theID = $this->secondTable ? abs(intval($theID)) : intval($theID);
00211                                                         // Register ID/table name in internal arrays:
00212                                                 $this->itemArray[$key]['id'] = $theID;
00213                                                 $this->itemArray[$key]['table'] = $theTable;
00214                                                 $this->tableArray[$theTable][] = $theID;
00215                                                         // Set update-flag:
00216                                                 $isSet=1;
00217                                         }
00218                                 }
00219 
00220                                         // If it turns out that the value from the list was NOT a valid reference to a table-record, then we might still set it as a NO_TABLE value:
00221                                 if (!$isSet && $this->registerNonTableValues)   {
00222                                         $this->itemArray[$key]['id'] = $tempItemArray[$key];
00223                                         $this->itemArray[$key]['table'] = '_NO_TABLE';
00224                                         $this->nonTableArray[] = $tempItemArray[$key];
00225                                 }
00226                         }
00227                 }
00228         }
00229 
00238         function sortList($sortby) {
00239                         // sort directly without fetching addional data
00240                 if ($sortby == 'uid') {
00241                         usort($this->itemArray, create_function('$a,$b', 'return $a["id"] < $b["id"] ? -1 : 1;'));
00242                         // only useful if working on the same table
00243                 } elseif (count($this->tableArray) == 1) {
00244                         reset($this->tableArray);
00245                         $table = key($this->tableArray);
00246                         $uidList = implode(',', current($this->tableArray));
00247 
00248                         if ($uidList) {
00249                                 $this->itemArray = array();
00250                                 $this->tableArray = array();
00251                                 
00252                                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', $table, 'uid IN ('.$uidList.')', '', $sortby);
00253                                 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00254                                         $this->itemArray[] = array('id' => $row['uid'], 'table' => $table);
00255                                         $this->tableArray[$table][] = $row['uid'];
00256                                 }
00257                                 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00258                         }
00259                 }
00260         }
00261 
00270         function readMM($tableName,$uid)        {
00271                 $key=0;
00272                 $additionalWhere = '';
00273                 
00274                 if ($this->MM_is_foreign)       {       // in case of a reverse relation
00275                         $uidLocal_field = 'uid_foreign';
00276                         $uidForeign_field = 'uid_local';
00277                         $sorting_field = 'sorting_foreign';
00278 
00279                         if ($this->MM_isMultiTableRelationship) {
00280                                 $additionalWhere .= ' AND ( tablenames="'.$this->currentTable.'"';
00281                                 if ($this->currentTable == $this->MM_isMultiTableRelationship)  {       // be backwards compatible! When allowing more than one table after having previously allowed only one table, this case applies.
00282                                         $additionalWhere .= ' OR tablenames=""';
00283                                 }
00284                                 $additionalWhere .= ' ) ';
00285                         }
00286                         $theTable = $this->MM_oppositeTable;
00287                 } else {        // default
00288                         $uidLocal_field = 'uid_local';
00289                         $uidForeign_field = 'uid_foreign';
00290                         $sorting_field = 'sorting';
00291                 }
00292 
00293 
00294                 if ($this->MM_table_where) {
00295                         $additionalWhere.= "\n".str_replace('###THIS_UID###', intval($uid), $this->MM_table_where);
00296                 }
00297                 foreach ($this->MM_match_fields as $field => $value) {
00298                         $additionalWhere.= ' AND '.$field.'='.$GLOBALS['TYPO3_DB']->fullQuoteStr($value, $tableName);
00299                 }
00300                 
00301                         // Select all MM relations:
00302                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $tableName, $uidLocal_field.'='.intval($uid).$additionalWhere, '', $sorting_field);
00303                 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))       {
00304                         if (!$this->MM_is_foreign) {    // default
00305                                 $theTable = $row['tablenames'] ? $row['tablenames'] : $this->firstTable;                // If tablesnames columns exists and contain a name, then this value is the table, else it's the firstTable...
00306                         }
00307                         if (($row[$uidForeign_field] || $theTable=='pages') && $theTable && isset($this->tableArray[$theTable]))        {
00308 
00309                                 $this->itemArray[$key]['id'] = $row[$uidForeign_field];
00310                                 $this->itemArray[$key]['table'] = $theTable;
00311                                 $this->tableArray[$theTable][]= $row[$uidForeign_field];
00312                         } elseif ($this->registerNonTableValues)        {
00313                                 $this->itemArray[$key]['id'] = $row[$uidForeign_field];
00314                                 $this->itemArray[$key]['table'] = '_NO_TABLE';
00315                                 $this->nonTableArray[] = $row[$uidForeign_field];
00316                         }
00317                         $key++;
00318                 }
00319                 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00320         }
00321 
00330         function writeMM($tableName,$uid,$prependTableName=0)   {
00331 
00332                 if ($this->MM_is_foreign)       {       // in case of a reverse relation
00333                         $uidLocal_field = 'uid_foreign';
00334                         $uidForeign_field = 'uid_local';
00335                         $sorting_field = 'sorting_foreign';
00336                 } else {        // default
00337                         $uidLocal_field = 'uid_local';
00338                         $uidForeign_field = 'uid_foreign';
00339                         $sorting_field = 'sorting';
00340                 }
00341 
00342                         // If there are tables...
00343                 $tableC = count($this->tableArray);
00344                 if ($tableC)    {
00345                         $prep = ($tableC>1||$prependTableName||$this->MM_isMultiTableRelationship) ? 1 : 0;     // boolean: does the field "tablename" need to be filled?
00346                         $c=0;
00347 
00348                         $additionalWhere_tablenames = '';
00349                         if ($this->MM_is_foreign && $prep)      {
00350                                 $additionalWhere_tablenames = ' AND tablenames="'.$this->currentTable.'"';
00351                         }
00352 
00353                         $additionalWhere = '';
00354                                 // add WHERE clause if configured
00355                         if ($this->MM_table_where) {
00356                                 $additionalWhere.= "\n".str_replace('###THIS_UID###', intval($uid), $this->MM_table_where);
00357                         }
00358                                 // Select, update or delete only those relations that match the configured fields
00359                         foreach ($this->MM_match_fields as $field => $value) {
00360                                 $additionalWhere.= ' AND '.$field.'='.$GLOBALS['TYPO3_DB']->fullQuoteStr($value, $tableName);
00361                         }
00362 
00363                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($uidForeign_field.($prep?', tablenames':''), $tableName, $uidLocal_field.'='.$uid.$additionalWhere_tablenames.$additionalWhere);
00364 
00365                         $oldMMs = array();
00366                         while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00367                                 if (!$this->MM_is_foreign && $prep)     {
00368                                         $oldMMs[] = array($row['tablenames'], $row[$uidForeign_field]);
00369                                 } else {
00370                                         $oldMMs[] = $row[$uidForeign_field];
00371                                 }
00372                         }
00373 
00374                                 // For each item, insert it:
00375                         foreach($this->itemArray as $val)       {
00376                                 $c++;
00377 
00378                                 if ($prep || $val['table']=='_NO_TABLE')        {
00379                                         if ($this->MM_is_foreign)       {       // insert current table if needed
00380                                                 $tablename = $this->currentTable;
00381                                         } else {
00382                                                 $tablename = $val['table'];
00383                                         }
00384                                 } else {
00385                                         $tablename = '';
00386                                 }
00387 
00388                                 if(!$this->MM_is_foreign && $prep) {
00389                                         $item = array($val['table'], $val['id']);
00390                                 } else {
00391                                         $item = $val['id'];
00392                                 }
00393 
00394                                 if (in_array($item, $oldMMs))   {
00395                                         unset($oldMMs[array_search($item, $oldMMs)]);   // remove the item from the $oldMMs array so after this foreach loop only the ones that need to be deleted are in there.
00396 
00397                                         $whereClause = $uidLocal_field.'='.$uid.' AND '.$uidForeign_field.'='.$val['id'];
00398                                         if ($tablename) {
00399                                                 $whereClause .= ' AND tablenames="'.$tablename.'"';
00400                                         }
00401                                         $GLOBALS['TYPO3_DB']->exec_UPDATEquery($tableName, $whereClause.$additionalWhere, array($sorting_field => $c));
00402                                 } else {
00403 
00404                                         $insertFields = $this->MM_insert_fields;
00405                                         $insertFields[$uidLocal_field] = $uid;
00406                                         $insertFields[$uidForeign_field] = $val['id'];
00407                                         $insertFields[$sorting_field] = $c;
00408                                         if($tablename)  {
00409                                                 $insertFields['tablenames'] = $tablename;
00410                                         }
00411 
00412                                         $GLOBALS['TYPO3_DB']->exec_INSERTquery($tableName, $insertFields);
00413                                 }
00414                         }
00415 
00416                                 // Delete all not-used relations:
00417                         if(is_array($oldMMs) && count($oldMMs) > 0) {
00418                                 $removeClauses = array();
00419                                 foreach($oldMMs as $mmItem) {
00420                                         if(is_array($mmItem)) {
00421                                                 $removeClauses[] = 'tablenames="'.$mmItem[0].'" AND '.$uidForeign_field.'='.$mmItem[1];
00422                                         } else {
00423                                                 $removeClauses[] = $uidForeign_field.'='.$mmItem;
00424                                         }
00425                                 }
00426                                 $deleteAddWhere = ' AND ('.implode(' OR ', $removeClauses).')';
00427                                 $GLOBALS['TYPO3_DB']->exec_DELETEquery($tableName, $uidLocal_field.'='.intval($uid).$deleteAddWhere.$additionalWhere_tablenames.$additionalWhere);
00428                         }
00429                 }
00430         }
00431 
00440         function readForeignField($uid, $conf) {
00441                 $key = 0;
00442                 $uid = intval($uid);
00443                 $whereClause = '';
00444                 $foreign_table = $conf['foreign_table'];
00445                 $foreign_table_field = $conf['foreign_table_field'];
00446                 $useDeleteClause = $this->undeleteRecord ? false : true;
00447 
00448                         // search for $uid in foreign_field, and if we have symmetric relations, do this also on symmetric_field
00449                 if ($conf['symmetric_field']) {
00450                         $whereClause = '('.$conf['foreign_field'].'='.$uid.' OR '.$conf['symmetric_field'].'='.$uid.')';
00451                 } else {
00452                         $whereClause = $conf['foreign_field'].'='.$uid;
00453                 }
00454                         // use the deleteClause (e.g. "deleted=0") on this table
00455                 if ($useDeleteClause) {
00456                         $whereClause .= t3lib_BEfunc::deleteClause($foreign_table);
00457                 }
00458                         // if it's requested to look for the parent uid AND the parent table,
00459                         // add an additional SQL-WHERE clause
00460                 if ($foreign_table_field && $this->currentTable) {
00461                         $whereClause .= ' AND '.$foreign_table_field.'='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->currentTable, $foreign_table);
00462                 }
00463                 
00464                         // get the correct sorting field
00465                 if ($conf['foreign_sortby']) {                                                                                  // specific manual sortby for data handled by this field
00466                         if ($conf['symmetric_sortby'] && $conf['symmetric_field']) {
00467                                         // sorting depends on, from which side of the relation we're looking at it
00468                                 $sortby = '
00469                                         CASE
00470                                                 WHEN '.$conf['foreign_field'].'='.$uid.'
00471                                                 THEN '.$conf['foreign_sortby'].'
00472                                                 ELSE '.$conf['symmetric_sortby'].'
00473                                         END';
00474                         } else {
00475                                         // regular single-side behaviour
00476                                 $sortby = $conf['foreign_sortby'];
00477                         }
00478                 } elseif ($conf['foreign_default_sortby']) {                                                    // specific default sortby for data handled by this field
00479                         $sortby = $conf['foreign_default_sortby'];
00480                 } elseif ($GLOBALS['TCA'][$foreign_table]['ctrl']['sortby']) {                  // manual sortby for all table records
00481                         $sortby = $GLOBALS['TCA'][$foreign_table]['ctrl']['sortby'];
00482                 } elseif ($GLOBALS['TCA'][$foreign_table]['ctrl']['default_sortby']) {  // default sortby for all table records
00483                         $sortby = $GLOBALS['TCA'][$foreign_table]['ctrl']['default_sortby'];
00484                 }
00485 
00486                         // strip a possible "ORDER BY" in front of the $sortby value
00487                 $sortby = $GLOBALS['TYPO3_DB']->stripOrderBy($sortby);
00488                         // get the rows from storage
00489                 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid', $foreign_table, $whereClause, '', $sortby);
00490 
00491                 if (count($rows)) {
00492                         foreach ($rows as $row) {
00493                                 $this->itemArray[$key]['id'] = $row['uid'];
00494                                 $this->itemArray[$key]['table'] = $foreign_table;
00495                                 $this->tableArray[$foreign_table][]= $row['uid'];
00496                                 $key++;
00497                         }
00498                 }
00499         }
00500 
00510         function writeForeignField($conf, $parentUid, $updateToUid=0, $skipSorting=false) {
00511                 $c = 0;
00512                 $foreign_table = $conf['foreign_table'];
00513                 $foreign_field = $conf['foreign_field'];
00514                 $symmetric_field = $conf['symmetric_field'];
00515                 $foreign_table_field = $conf['foreign_table_field'];
00516 
00517                         // if there are table items and we have a proper $parentUid
00518                 if (t3lib_div::testInt($parentUid) && count($this->tableArray)) {
00519                                 // if updateToUid is not a positive integer, set it to '0', so it will be ignored
00520                         if (!(t3lib_div::testInt($updateToUid) && $updateToUid > 0)) $updateToUid = 0;
00521                         $fields = 'uid,'.$foreign_field.($symmetric_field ? ','.$symmetric_field : '');
00522 
00523                                 // update all items
00524                         foreach ($this->itemArray as $val) {
00525                                 $uid = $val['id'];
00526                                 $table = $val['table'];
00527 
00528                                         // fetch the current (not overwritten) relation record if we should handle symmetric relations
00529                                 if ($conf['symmetric_field']) {
00530                                         $row = t3lib_BEfunc::getRecord($table,$uid,$fields,'',false);
00531                                         $isOnSymmetricSide = t3lib_loadDBGroup::isOnSymmetricSide($parentUid, $conf, $row);
00532                                 }
00533 
00534                                 $updateValues = array();
00535 
00536                                         // no update to the uid is requested, so this is the normal behaviour
00537                                         // just update the fields and care about sorting
00538                                 if (!$updateToUid) {
00539                                                 // Always add the pointer to the parent uid
00540                                         if ($isOnSymmetricSide) {
00541                                                 $updateValues[$symmetric_field] = $parentUid;
00542                                         } else {
00543                                                 $updateValues[$foreign_field] = $parentUid;
00544                                         }
00545                                         
00546                                                 // if it is configured in TCA also to store the parent table in the child record, just do it
00547                                         if ($foreign_table_field && $this->currentTable) {
00548                                                 $updateValues[$foreign_table_field] = $this->currentTable;
00549                                         }
00550 
00551                                                 // update sorting columns if not to be skipped
00552                                         if (!$skipSorting) {
00553                                                         // get the correct sorting field
00554                                                 if ($conf['foreign_sortby']) {                                                                  // specific manual sortby for data handled by this field 
00555                                                         $sortby = $conf['foreign_sortby'];
00556                                                 } elseif ($GLOBALS['TCA'][$foreign_table]['ctrl']['sortby']) {  // manual sortby for all table records
00557                                                         $sortby = $GLOBALS['TCA'][$foreign_table]['ctrl']['sortby'];
00558                                                 }
00559                                                         // strip a possible "ORDER BY" in front of the $sortby value
00560                                                 $sortby = $GLOBALS['TYPO3_DB']->stripOrderBy($sortby);
00561                                                 $symSortby = $conf['symmetric_sortby'];
00562         
00563                                                         // set the sorting on the right side, it depends on who created the relation, so what uid is in the symmetric_field
00564                                                 if ($isOnSymmetricSide && $symSortby) {
00565                                                         $updateValues[$symSortby] = ++$c;
00566                                                 } elseif ($sortby) {
00567                                                         $updateValues[$sortby] = ++$c;
00568                                                 }
00569                                         }
00570 
00571                                         // update to a foreign_field/symmetric_field pointer is requested, normally used on record copies
00572                                         // only update the fields, if the old uid is found somewhere - for select fields, TCEmain is doing this already!
00573                                 } else {
00574                                         if ($isOnSymmetricSide) {
00575                                                 $updateValues[$symmetric_field] = $updateToUid;
00576                                         } else {
00577                                                 $updateValues[$foreign_field] = $updateToUid;
00578                                         }
00579                                 }
00580 
00581                                 if (count($updateValues)) {
00582                                         $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, "uid='$uid'", $updateValues);
00583                                         $this->updateRefIndex($table, $uid);
00584                                 }
00585                         }
00586                 }
00587         }
00588 
00595         function getValueArray($prependTableName='')    {
00596                         // INIT:
00597                 $valueArray=Array();
00598                 $tableC = count($this->tableArray);
00599 
00600                         // If there are tables in the table array:
00601                 if ($tableC)    {
00602                                 // If there are more than ONE table in the table array, then always prepend table names:
00603                         $prep = ($tableC>1||$prependTableName) ? 1 : 0;
00604 
00605                                 // Traverse the array of items:
00606                         foreach($this->itemArray as $val)       {
00607                                 $valueArray[]=(($prep && $val['table']!='_NO_TABLE') ? $val['table'].'_' : '').
00608                                                                         $val['id'];
00609                         }
00610                 }
00611                         // Return the array
00612                 return $valueArray;
00613         }
00614 
00623         function convertPosNeg($valueArray,$fTable,$nfTable)    {
00624                 if (is_array($valueArray) && $fTable)   {
00625                         foreach($valueArray as $key => $val)    {
00626                                 $val = strrev($val);
00627                                 $parts = explode('_',$val,2);
00628                                 $theID = strrev($parts[0]);
00629                                 $theTable = strrev($parts[1]);
00630 
00631                                 if ( t3lib_div::testInt($theID) && (!$theTable || !strcmp($theTable,$fTable) || !strcmp($theTable,$nfTable)) )  {
00632                                         $valueArray[$key]= $theTable && strcmp($theTable,$fTable) ? $theID*-1 : $theID;
00633                                 }
00634                         }
00635                 }
00636                 return $valueArray;
00637         }
00638 
00645         function getFromDB()    {
00646                         // Traverses the tables listed:
00647                 foreach($this->tableArray as $key => $val)      {
00648                         if (is_array($val))     {
00649                                 $itemList = implode(',',$val);
00650                                 if ($itemList)  {
00651                                         $from = '*';
00652                                         if ($this->fromTC)      {
00653                                                 $from = 'uid,pid';
00654                                                 if ($GLOBALS['TCA'][$key]['ctrl']['label'])     {
00655                                                         $from.= ','.$GLOBALS['TCA'][$key]['ctrl']['label'];     // Titel
00656                                                 }
00657                                                 if ($GLOBALS['TCA'][$key]['ctrl']['label_alt']) {
00658                                                         $from.= ','.$GLOBALS['TCA'][$key]['ctrl']['label_alt']; // Alternative Title-Fields
00659                                                 }
00660                                                 if ($GLOBALS['TCA'][$key]['ctrl']['thumbnail']) {
00661                                                         $from.= ','.$GLOBALS['TCA'][$key]['ctrl']['thumbnail']; // Thumbnail
00662                                                 }
00663                                         }
00664                                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($from, $key, 'uid IN ('.$itemList.')'.$this->additionalWhere[$key]);
00665                                         while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))       {
00666                                                 $this->results[$key][$row['uid']]=$row;
00667                                         }
00668                                 }
00669                         }
00670                 }
00671                 return $this->results;
00672         }
00673 
00680         function readyForInterface()    {
00681                 global $TCA;
00682 
00683                 if (!is_array($this->itemArray))        {return false;}
00684 
00685                 $output=array();
00686                 $perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);             // For use when getting the paths....
00687                 $titleLen=intval($GLOBALS['BE_USER']->uc['titleLen']);
00688 
00689                 foreach($this->itemArray as $key => $val)       {
00690                         $theRow = $this->results[$val['table']][$val['id']];
00691                         if ($theRow && is_array($TCA[$val['table']]))   {
00692                                 $label = t3lib_div::fixed_lgd_cs(strip_tags(t3lib_BEfunc::getRecordTitle($val['table'], $theRow)),$titleLen);
00693                                 $label = ($label)?$label:'[...]';
00694                                 $output[]=str_replace(',','',$val['table'].'_'.$val['id'].'|'.rawurlencode($label));
00695                         }
00696                 }
00697                 return implode(',',$output);
00698         }
00699 
00706         function countItems($returnAsArray = true) {
00707                 $count = count($this->itemArray);
00708                 if ($returnAsArray) $count = array($count);
00709                 return $count;
00710         }
00711 
00721         function updateRefIndex($table,$id)     {
00722                 $refIndexObj = t3lib_div::makeInstance('t3lib_refindex');
00723                 $result = $refIndexObj->updateRefIndexTable($table,$id);
00724         }
00725 
00734         function isOnSymmetricSide($parentUid, $parentConf, $childRec) {
00735                 return t3lib_div::testInt($childRec['uid']) && $parentConf['symmetric_field'] && $parentUid == $childRec[$parentConf['symmetric_field']]
00736                         ? true
00737                         : false;
00738         }
00739 }
00740 
00741 
00742 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_loaddbgroup.php'])       {
00743         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_loaddbgroup.php']);
00744 }
00745 ?>


Généré par Les spécialistes TYPO3 avec  doxygen 1.4.6