*/ public static function degrees(): array { return [ 'associate' => ['zh-CN' => '大专', 'en' => 'Associate Degree'], 'bachelor' => ['zh-CN' => '本科', 'en' => "Bachelor’s Degree"], 'master' => ['zh-CN' => '硕士', 'en' => "Master’s Degree"], 'doctorate' => ['zh-CN' => '博士', 'en' => 'Doctorate'], 'other' => ['zh-CN' => '其他', 'en' => 'Other'], ]; } /** * @return array */ public static function locationCountries(): array { return [ 'cn' => ['zh-CN' => '中国', 'en' => 'China'], 'overseas' => ['zh-CN' => '海外', 'en' => 'Outside China'], ]; } /** * @return array */ public static function eventLocations(): array { return [ 'shanghai' => ['zh-CN' => '上海', 'en' => 'Shanghai'], 'suzhou' => ['zh-CN' => '苏州', 'en' => 'Suzhou'], 'shenzhen' => ['zh-CN' => '深圳', 'en' => 'Shenzhen'], ]; } /** * @return array */ public static function audiencePurposes(): array { return [ 'networking' => ['zh-CN' => '项目交流', 'en' => 'Project Networking'], 'collaboration' => ['zh-CN' => '产业合作', 'en' => 'Industry Collaboration'], 'investment' => ['zh-CN' => '投资对接', 'en' => 'Investor Meetings'], 'study' => ['zh-CN' => '学习参访', 'en' => 'Study Visit'], 'media' => ['zh-CN' => '媒体报道', 'en' => 'Media Coverage'], 'other' => ['zh-CN' => '其他', 'en' => 'Other'], ]; } /** * @return array */ public static function legacyMap(string $kind): array { return match ($kind) { 'degree' => [ '大专' => 'associate', '本科' => 'bachelor', '硕士' => 'master', '博士' => 'doctorate', '其他' => 'other', ], 'location_country' => [ '中国' => 'cn', '海外' => 'overseas', ], 'event_location' => [ '上海' => 'shanghai', '苏州' => 'suzhou', '深圳' => 'shenzhen', ], 'purpose', 'audience_purpose' => [ '项目交流' => 'networking', '产业合作' => 'collaboration', '投资对接' => 'investment', '学习参访' => 'study', '媒体报道' => 'media', '其他' => 'other', ], default => [], }; } public static function normalize(string $kind, ?string $raw): ?string { if ($raw === null) { return null; } $value = trim($raw); if ($value === '') { return ''; } $map = self::legacyMap($kind); return $map[$value] ?? $value; } /** * @param array $catalog * @return list */ public static function codes(array $catalog): array { return array_keys($catalog); } /** * @param array $catalog * @return list */ public static function acceptedValues(array $catalog, string $kind): array { return array_values(array_unique([ ...self::codes($catalog), ...array_keys(self::legacyMap($kind)), ])); } /** * @param array $catalog */ public static function label(array $catalog, string $code, string $locale = PortalLocale::ZH): string { $normalized = self::normalize( $catalog === self::degrees() ? 'degree' : ($catalog === self::locationCountries() ? 'location_country' : ($catalog === self::eventLocations() ? 'event_location' : 'purpose')), $code ) ?? $code; $row = $catalog[$normalized] ?? null; if ($row === null) { return $code; } return $locale === PortalLocale::EN ? ($row['en'] ?? $row['zh-CN']) : ($row['zh-CN'] ?? $row['en'] ?? $code); } /** * @param array $catalog * @return list */ public static function schemaOptions(array $catalog): array { $out = []; foreach ($catalog as $code => $labels) { $out[] = [ 'value' => $code, 'label' => $labels['zh-CN'], 'label_i18n' => ['en' => $labels['en']], ]; } return $out; } }