-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
94 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace App\Controllers; | ||
|
||
use App\Core\BaseController; | ||
use App\Core\View; | ||
use App\Models\Zone; | ||
|
||
class ZoneController implements BaseController | ||
{ | ||
public function get() | ||
{ | ||
$zones = Zone::findAll(); | ||
View::render([ | ||
"view" => "Zone", | ||
"title" => "Zones", | ||
"layout" => "MainLayout", | ||
"data" => ["zones" => $zones] | ||
]); | ||
} | ||
|
||
public function post() {} | ||
public function put() {} | ||
public function delete() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use App\Core\BaseModel; | ||
|
||
class Zone extends BaseModel | ||
{ | ||
public $name; | ||
public $postal_code; | ||
public $point_id; | ||
|
||
protected static function getTableName() | ||
{ | ||
return 'zones'; | ||
} | ||
|
||
protected static function mapDataToModel($data) | ||
{ | ||
$zone = new Zone(); | ||
$zone->id = $data['id']; | ||
$zone->name = $data['name']; | ||
$zone->postal_code = $data['postal_code']; | ||
$zone->point_id = $data['point_id']; | ||
return $zone; | ||
} | ||
|
||
// Fetch the zone's point | ||
public function point() | ||
{ | ||
return $this->belongsTo(Point::class, 'point_id', 'id'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<div class="overflow-x-auto"> | ||
<table class="min-w-full bg-white border border-gray-300 rounded-lg shadow-md"> | ||
<thead> | ||
<tr class="bg-gray-100 text-left"> | ||
<th class="px-4 py-2 border-b">ID</th> | ||
<th class="px-4 py-2 border-b">Name</th> | ||
<th class="px-4 py-2 border-b">Postal Code</th> | ||
<th class="px-4 py-2 border-b">Latitude</th> | ||
<th class="px-4 py-2 border-b">Longitude</th> | ||
|
||
</tr> | ||
</thead> | ||
<tbody> | ||
<?php foreach ($zones as $zone): ?> | ||
<tr class="hover:bg-gray-50"> | ||
<td class="px-4 py-2 border-b"><?php echo $zone->getId(); ?></td> | ||
<td class="px-4 py-2 border-b"><?php echo $zone->name; ?></td> | ||
<td class="px-4 py-2 border-b"><?php echo $zone->postal_code; ?></td> | ||
<td class="px-4 py-2 border-b"><?php echo $zone->point()->latitude; ?></td> | ||
<td class="px-4 py-2 border-b"><?php echo $zone->point()->longitude; ?></td> | ||
</tr> | ||
<?php endforeach; ?> | ||
</tbody> | ||
</table> | ||
</div> |