feat: Add City entity methods and migration for title field
- Created a new JSON file for the City entity's AST representation, detailing its methods and properties. - Added a migration to alter the cities table by adding a nullable title column.
This commit is contained in:
@@ -38,13 +38,21 @@ class CategoryImporter
|
||||
public function exportAll(string $bundle): array
|
||||
{
|
||||
$table = self::TABLES[$bundle];
|
||||
$rows = $this->db->fetchAllAssociative('SELECT * FROM ' . $table . ' ORDER BY id ASC');
|
||||
// cities export must match the shape nobat724_front/data/city.json consumes:
|
||||
// social_media as an object (not the raw JSON string) and province_name included.
|
||||
$sql = $bundle === 'cities'
|
||||
? 'SELECT c.*, p.name AS province_name FROM cities c LEFT JOIN provinces p ON p.id = c.province_id ORDER BY c.id ASC'
|
||||
: 'SELECT * FROM ' . $table . ' ORDER BY id ASC';
|
||||
$rows = $this->db->fetchAllAssociative($sql);
|
||||
foreach ($rows as &$r) {
|
||||
foreach (['id', 'status', 'weight', 'parent_id', 'specialty_id', 'province_id', 'representation_id'] as $intCol) {
|
||||
if (array_key_exists($intCol, $r) && $r[$intCol] !== null) {
|
||||
$r[$intCol] = (int) $r[$intCol];
|
||||
}
|
||||
}
|
||||
if ($bundle === 'cities' && is_string($r['social_media'] ?? null)) {
|
||||
$r['social_media'] = json_decode($r['social_media'], true);
|
||||
}
|
||||
}
|
||||
unset($r);
|
||||
return $rows;
|
||||
@@ -143,6 +151,7 @@ class CategoryImporter
|
||||
break;
|
||||
case 'cities':
|
||||
$row['site_name'] = self::optStr($raw['site_name'] ?? null);
|
||||
$row['title'] = self::optStr($raw['title'] ?? null);
|
||||
$row['province_id'] = self::nullableId($raw['province_id'] ?? null, $add, 'province_id');
|
||||
$row['representation_id'] = self::nullableId($raw['representation_id'] ?? null, $add, 'representation_id');
|
||||
$row['contact_phone'] = self::optStr($raw['contact_phone'] ?? null);
|
||||
|
||||
Reference in New Issue
Block a user