/**
  * Generates a list of tx_dam db fields which are needed to get a proper info about the record.
  *
  * @param	boolean		$prependTableName If set the fields are prepended with table.
  * @param	array		$addFields Field list array which should be appended to the list
  * @return	string		Comma list of fields with table name prepended
  */
 function getMetaInfoFieldList($prependTableName = TRUE, $addFields = array())
 {
     global $TCA;
     $infoFields = tx_dam_db::getTCAFieldListArray('tx_dam', TRUE, $addFields);
     $infoFieldsTCA = explode(',', $TCA['tx_dam']['ctrl']['txdamInterface']['info_fieldList_add']);
     foreach ($infoFieldsTCA as $field) {
         if ($field = trim($field)) {
             $infoFields[$field] = $field;
         }
     }
     $infoFields['file_name'] = 'file_name';
     $infoFields['file_dl_name'] = 'file_dl_name';
     $infoFields['file_path'] = 'file_path';
     $infoFields['file_size'] = 'file_size';
     $infoFields['file_type'] = 'file_type';
     $infoFields['file_ctime'] = 'file_ctime';
     $infoFields['file_mtime'] = 'file_mtime';
     $infoFields['file_hash'] = 'file_hash';
     $infoFields['file_mime_type'] = 'file_mime_type';
     $infoFields['file_mime_subtype'] = 'file_mime_subtype';
     $infoFields['media_type'] = 'media_type';
     $infoFields['file_status'] = 'file_status';
     $infoFields['index_type'] = 'index_type';
     $infoFields['parent_id'] = 'parent_id';
     $infoFields = tx_dam_db::compileFieldList('tx_dam', $infoFields, FALSE, $prependTableName);
     return $infoFields;
 }
 /**
  * Builds the array of reference items
  *
  * @param	array		$rows: Array of reference records
  * @param	array		$columns: Array of column names required from the entries
  * @return	void
  */
 function processEntries($rows, $columns)
 {
     foreach ($rows as $damRow) {
         $refTable = $damRow['tablenames'];
         if ($refTable) {
             // Get main fields from TCA
             $selectFields = tx_dam_db::getTCAFieldListArray($refTable, TRUE);
             $orderBy = in_array('tstamp', $selectFields) ? 'tstamp DESC' : '';
             $selectFields = tx_dam_db::compileFieldList($refTable, $selectFields, FALSE);
             $selectFields = $selectFields ? $selectFields : $refTable . '.uid,' . $refTable . '.pid';
             // Query for non-deleted tables only
             $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($selectFields, $refTable, $refTable . '.uid=' . intval($damRow['uid_foreign']) . t3lib_BEfunc::deleteClause($refTable), '', $orderBy, 40);
             // Assemble data
             while ($refRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                 $pageRow = t3lib_BEfunc::getRecord('pages', $refRow['pid']);
                 if (is_array($pageRow)) {
                     $item = array();
                     $item = $damRow;
                     $rootline = t3lib_BEfunc::BEgetRootLine($pageRow['uid']);
                     $pageOnClick = t3lib_BEfunc::viewOnClick($pageRow['uid'], '', $rootline);
                     foreach ($columns as $element) {
                         switch ($element) {
                             case 'page':
                                 $item[$element] = $pageRow;
                                 $item['pid'] = $pageRow['uid'];
                                 break;
                             case 'content_element':
                                 $item[$element] = $refRow;
                                 break;
                             case 'content_field':
                                 // Create sortable item for reference field
                                 $item[$element] = '';
                                 if ($item['ident']) {
                                     $item[$element] = trim($GLOBALS['LANG']->sL(t3lib_befunc::getItemLabel($refTable, $item['ident'])));
                                 } else {
                                     if ($item['field']) {
                                         $item[$element] = trim($GLOBALS['LANG']->sL(t3lib_befunc::getItemLabel($refTable, $item['field'])));
                                     }
                                 }
                                 // Removing trailing : from field label, if any
                                 if (substr($item[$element], -1) == ':') {
                                     $item[$element] = substr($item[$element], 0, -1);
                                 }
                                 break;
                             case 'content_age':
                                 $item[$element] = $refRow['tstamp'];
                                 break;
                             default:
                                 break;
                         }
                     }
                     $this->entries[] = $item;
                 }
             }
         }
     }
 }