['table' => 'tx_vitec_domain_model_market', 'label' => 'Markets'], 'solution' => ['table' => 'tx_vitec_domain_model_solution', 'label' => 'Solutions'], 'product' => ['table' => 'tx_vitec_domain_model_product', 'label' => 'Products'], ]; /** Scalar TCA column types a CSV cell can populate. */ private const IMPORTABLE_TYPES = ['input', 'text', 'slug', 'number', 'email', 'link', 'check', 'color']; private const EXCLUDED_FIELDS = [ 'sys_language_uid', 'l10n_parent', 'l10n_diffsource', 'l10n_source', 'l18n_parent', 'l18n_diffsource', 'starttime', 'endtime', 'hidden', ]; /** @return array */ public function all(): array { $out = []; foreach (self::MODELS as $key => $cfg) { $out[$key] = $cfg + ['key' => $key]; } return $out; } public function has(string $key): bool { return isset(self::MODELS[$key]); } /** @return array{key:string,table:string,label:string} */ public function get(string $key): array { return self::MODELS[$key] + ['key' => $key]; } /** * Importable fields of a table, derived from TCA. * * @return array fieldName => human label */ public function importableFields(string $table): array { $fields = []; foreach ($GLOBALS['TCA'][$table]['columns'] ?? [] as $name => $column) { $type = (string)($column['config']['type'] ?? ''); if (!in_array($type, self::IMPORTABLE_TYPES, true)) { continue; } if (in_array($name, self::EXCLUDED_FIELDS, true)) { continue; } if (($column['config']['renderType'] ?? '') === 'inputDateTime') { continue; } $label = (string)($column['label'] ?? $name); if (str_starts_with($label, 'LLL:')) { $translated = $GLOBALS['LANG'] ?? null ? (string)$GLOBALS['LANG']->sL($label) : ''; $label = $translated !== '' ? $translated : $name; } $fields[$name] = $label !== '' ? $label : $name; } return $fields; } /** Pid of the first existing record - the sysfolder the model lives in. */ public function detectPid(string $table): int { $qb = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table); $row = $qb->select('pid')->from($table) ->where($qb->expr()->eq('deleted', 0)) ->setMaxResults(1) ->executeQuery()->fetchAssociative(); return $row ? (int)$row['pid'] : 0; } /** * All live records with the given fields, indexed by uid. * * @param array $fields * @return array> */ public function loadRecords(string $table, array $fields): array { $select = array_values(array_unique(array_merge(['uid', 'title'], $fields))); $qb = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table); $rows = $qb->select(...$select)->from($table) ->where($qb->expr()->eq('deleted', 0)) ->orderBy('title', 'ASC') ->executeQuery()->fetchAllAssociative(); $out = []; foreach ($rows as $row) { $out[(int)$row['uid']] = $row; } return $out; } }