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);
|
||||
|
||||
@@ -224,6 +224,7 @@ class LocationController extends BaseController
|
||||
if (array_key_exists('representation_id', $data))
|
||||
$city->setRepresentationId($data['representation_id'] !== null ? (int) $data['representation_id'] : null);
|
||||
if (array_key_exists('site_name', $data)) $city->setSiteName($data['site_name']);
|
||||
if (array_key_exists('title', $data)) $city->setTitle($data['title']);
|
||||
if (array_key_exists('contact_phone', $data)) $city->setContactPhone($data['contact_phone']);
|
||||
if (array_key_exists('email', $data)) $city->setEmail($data['email']);
|
||||
if (array_key_exists('description', $data)) $city->setDescription($data['description']);
|
||||
|
||||
@@ -27,6 +27,9 @@ class City
|
||||
#[ORM\Column(name: 'site_name', type: 'string', length: 255, nullable: true)]
|
||||
private ?string $siteName = null;
|
||||
|
||||
#[ORM\Column(type: 'string', length: 255, nullable: true)]
|
||||
private ?string $title = null;
|
||||
|
||||
#[ORM\Column(type: 'smallint')]
|
||||
private int $status = 1;
|
||||
|
||||
@@ -78,6 +81,7 @@ class City
|
||||
public function getUuid(): string { return $this->uuid; }
|
||||
public function getName(): string { return $this->name; }
|
||||
public function getSiteName(): ?string { return $this->siteName; }
|
||||
public function getTitle(): ?string { return $this->title; }
|
||||
public function getStatus(): int { return $this->status; }
|
||||
public function getWeight(): int { return $this->weight; }
|
||||
public function getProvince(): ?Province { return $this->province; }
|
||||
@@ -94,6 +98,7 @@ class City
|
||||
|
||||
public function setName(string $v): self { $this->name = $v; return $this; }
|
||||
public function setSiteName(?string $v): self { $this->siteName = $v; return $this; }
|
||||
public function setTitle(?string $v): self { $this->title = $v; return $this; }
|
||||
public function setStatus(int $v): self { $this->status = $v; return $this; }
|
||||
public function setWeight(int $v): self { $this->weight = $v; return $this; }
|
||||
public function setProvince(?Province $v): self { $this->province = $v; return $this; }
|
||||
@@ -115,6 +120,7 @@ class City
|
||||
'uuid' => $this->uuid,
|
||||
'name' => $this->name,
|
||||
'site_name' => $this->siteName,
|
||||
'title' => $this->title,
|
||||
'status' => $this->status,
|
||||
'weight' => $this->weight,
|
||||
'province_id' => $this->province?->getId(),
|
||||
|
||||
Reference in New Issue
Block a user