/**
  * A function which can be used for load a batch of records from $table into internal memory of this object.
  * The function is also used to produce proper default data for new records
  * Ultimately the function will call renderRecord()
  *
  * @param	string		Table name, must be found in $TCA
  * @param	string		Comma list of id values. If $idList is "prev" then the value from $this->prevPageID is used. NOTICE: If $operation is "new", then negative ids are meant to point to a "previous" record and positive ids are PID values for new records. Otherwise (for existing records that is) it is straight forward table/id pairs.
  * @param	string		If "new", then a record with default data is returned. Further, the $id values are meant to be PID values (or if negative, pointing to a previous record). If NOT new, then the table/ids are just pointing to an existing record!
  * @return	void
  * @see renderRecord()
  */
 function fetchRecord($table, $idList, $operation)
 {
     global $TCA;
     if ((string) $idList == 'prev') {
         $idList = $this->prevPageID;
     }
     if ($TCA[$table]) {
         t3lib_div::loadTCA($table);
         // For each ID value (integer) we
         $ids = t3lib_div::trimExplode(',', $idList, 1);
         foreach ($ids as $id) {
             if (strcmp($id, '')) {
                 // If ID is not blank:
                 // For new records to be created, find default values:
                 if ($operation == 'new') {
                     // Default values:
                     $newRow = array();
                     // Used to store default values as found here:
                     // Default values as set in userTS:
                     $TCAdefaultOverride = $GLOBALS['BE_USER']->getTSConfigProp('TCAdefaults');
                     if (is_array($TCAdefaultOverride[$table . '.'])) {
                         foreach ($TCAdefaultOverride[$table . '.'] as $theF => $theV) {
                             if (isset($TCA[$table]['columns'][$theF])) {
                                 $newRow[$theF] = $theV;
                             }
                         }
                     }
                     if ($id < 0) {
                         $record = t3lib_beFunc::getRecord($table, abs($id), 'pid');
                         $pid = $record['pid'];
                         unset($record);
                     } else {
                         $pid = intval($id);
                     }
                     $pageTS = t3lib_beFunc::getPagesTSconfig($pid);
                     if (isset($pageTS['TCAdefaults.'])) {
                         $TCAPageTSOverride = $pageTS['TCAdefaults.'];
                         if (is_array($TCAPageTSOverride[$table . '.'])) {
                             foreach ($TCAPageTSOverride[$table . '.'] as $theF => $theV) {
                                 if (isset($TCA[$table]['columns'][$theF])) {
                                     $newRow[$theF] = $theV;
                                 }
                             }
                         }
                     }
                     // Default values as submitted:
                     if (is_array($this->defVals[$table])) {
                         foreach ($this->defVals[$table] as $theF => $theV) {
                             if (isset($TCA[$table]['columns'][$theF])) {
                                 $newRow[$theF] = $theV;
                             }
                         }
                     }
                     // Fetch default values if a previous record exists
                     if ($id < 0 && $TCA[$table]['ctrl']['useColumnsForDefaultValues']) {
                         // Fetches the previous record:
                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, 'uid=' . abs($id) . t3lib_BEfunc::deleteClause($table));
                         if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                             // Gets the list of fields to copy from the previous record.
                             $fArr = t3lib_div::trimExplode(',', $TCA[$table]['ctrl']['useColumnsForDefaultValues'], 1);
                             foreach ($fArr as $theF) {
                                 if (isset($TCA[$table]['columns'][$theF])) {
                                     $newRow[$theF] = $row[$theF];
                                 }
                             }
                         }
                         $GLOBALS['TYPO3_DB']->sql_free_result($res);
                     }
                     // Finally, call renderRecord:
                     $this->renderRecord($table, uniqid('NEW'), $id, $newRow);
                 } else {
                     $id = intval($id);
                     // Fetch database values
                     $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, 'uid=' . intval($id) . t3lib_BEfunc::deleteClause($table));
                     if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                         t3lib_BEfunc::fixVersioningPid($table, $row);
                         $this->renderRecord($table, $id, $row['pid'], $row);
                         $contentTable = $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable'];
                         $this->lockRecord($table, $id, $contentTable == $table ? $row['pid'] : 0);
                         // Locking the pid if the table edited is the content table.
                     }
                     $GLOBALS['TYPO3_DB']->sql_free_result($res);
                 }
             }
         }
     }
 }
 /**
  * Determines the corrected pid to be used for a new record.
  * The pid to be used can be defined by a Page TSconfig.
  *
  * @param string $table The table name
  * @param integer $parentPid The pid of the parent record
  * @return integer The corrected pid to be used for a new record
  */
 protected function getNewRecordPid($table, $parentPid = NULL)
 {
     $newRecordPid = $this->inlineFirstPid;
     $pageTS = \t3lib_beFunc::getPagesTSconfig($parentPid, TRUE);
     if (isset($pageTS['TCAdefaults.'][$table . '.']['pid']) && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($pageTS['TCAdefaults.'][$table . '.']['pid'])) {
         $newRecordPid = $pageTS['TCAdefaults.'][$table . '.']['pid'];
     } elseif (isset($parentPid) && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($parentPid)) {
         $newRecordPid = $parentPid;
     }
     return $newRecordPid;
 }
	/**
	 * Get the processed value analog to t3lib_beFunc::getProcessedValue
	 * but take additional TSconfig values into account
	 *
	 * @param  $table
	 * @param  $typeField
	 * @param  $typeValue
	 * @return
	 */
	protected function getProcessedValue($table, $typeField, $typeValue) {
		$value =  t3lib_beFunc::getProcessedValue($table, $typeField, $typeValue);
		if (!$value) {
			$TSConfig = t3lib_beFunc::getPagesTSconfig($this->id);
			if (isset($TSConfig['TCEFORM.'][$table . '.'][$typeField . '.']['addItems.'][$typeValue])) {
				$value = $TSConfig['TCEFORM.'][$table . '.'][$typeField . '.']['addItems.'][$typeValue];
			}
		}

		return $value;
	}
 /**
  * Determines the corrected pid to be used for a new record.
  * The pid to be used can be defined by a Page TSconfig.
  *
  * @param	string		$table: The table name
  * @param	integer		$parentPid: The pid of the parent record
  * @return	integer		The corrected pid to be used for a new record
  */
 protected function getNewRecordPid($table, $parentPid = null)
 {
     $newRecordPid = $this->inlineFirstPid;
     $pageTS = t3lib_beFunc::getPagesTSconfig($parentPid, true);
     if (isset($pageTS['TCAdefaults.'][$table . '.']['pid']) && t3lib_div::testInt($pageTS['TCAdefaults.'][$table . '.']['pid'])) {
         $newRecordPid = $pageTS['TCAdefaults.'][$table . '.']['pid'];
     } elseif (isset($parentPid) && t3lib_div::testInt($parentPid)) {
         $newRecordPid = $parentPid;
     }
     return $newRecordPid;
 }