-
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.
This pull request includes significant changes to the `app/src/app` directory, focusing on the addition of new fields and methods to various model classes and the creation of a new controller for managing element types. ### New Controller: * [`app/src/app/Controllers/Admin/ElementTypeController.php`](diffhunk://#diff-b853c2d8221709f16b1628ada40365adee6d7d67e0e85a419e63566f096b2318R1-R81): Added a new controller with methods for CRUD operations on element types. ### Model Updates: * [`app/src/app/Models/BaseModel.php`](diffhunk://#diff-57d475838e6428c42c3b9d5c460bea147ffb64f834e6ff8e980d351bf00c5c77R13-R16): Added `updated_at` and `deleted_at` fields and their respective getter methods. [[1]](diffhunk://#diff-57d475838e6428c42c3b9d5c460bea147ffb64f834e6ff8e980d351bf00c5c77R13-R16) [[2]](diffhunk://#diff-57d475838e6428c42c3b9d5c460bea147ffb64f834e6ff8e980d351bf00c5c77R350-R359) * [`app/src/app/Models/ElementType.php`](diffhunk://#diff-9fe6da3941cdf9002b36799641e9d90e702f85f505b34c28ba6d57805b54298dR1-R34): Created a new model for `ElementType` with fields and a method to map data to the model. ### Data Mapping Enhancements: * Updated the `mapDataToModel` method in multiple model files to include `updated_at` and `deleted_at` fields: - `Contract.php` - `Element.php` - `Incidence.php` - `Machine.php` - `Photo.php` - `Point.php` - `PruningType.php` - `Role.php` - `Route.php` - `Sensor.php` - `SensorHistory.php` - `Task.php` - `TaskType.php` - `TreeType.php` - `User.php` - `WorkOrder.php` - `WorkReport.php` ### Code Simplification: * [`app/src/app/Models/BaseModel.php`](diffhunk://#diff-57d475838e6428c42c3b9d5c460bea147ffb64f834e6ff8e980d351bf00c5c77L24-R28): Simplified the `bulkInsert` method by combining nested loops into a single line.
- Loading branch information
Showing
26 changed files
with
391 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
namespace App\Controllers\Admin; | ||
|
||
use App\Core\Session; | ||
use App\Core\View; | ||
//use App\Models\Element; | ||
use App\Models\ElementType; | ||
|
||
class ElementTypeController | ||
{ | ||
public function index($queryParams) | ||
{ | ||
$elementTypes = ElementType::findAll(); | ||
View::render([ | ||
'view' => 'Admin/ElementTypes', | ||
'title' => 'Manage Elements Types', | ||
'layout' => 'Admin/AdminLayout', | ||
'data' => ['elementTypes' => $elementTypes], | ||
]); | ||
} | ||
|
||
public function create($queryParams) | ||
{ | ||
//$elements = Element::findAll(); | ||
View::render([ | ||
'view' => 'Admin/ElementType/Create', | ||
'title' => 'Add Element Type', | ||
'layout' => 'Admin/AdminLayout', | ||
'data' => [ | ||
//'elements' => $elements, | ||
], | ||
]); | ||
} | ||
|
||
public function store($postData) | ||
{ | ||
$elementType = new ElementType(); | ||
$elementType->name = $postData['name']; | ||
$elementType->description = $postData['description']; | ||
|
||
$elementType->save(); | ||
|
||
Session::set('success', 'Type of Element created successfully'); | ||
|
||
header('Location: /admin/element-types'); | ||
} | ||
|
||
public function edit($id, $queryParams) | ||
{ | ||
$elementType = ElementType::find($id); | ||
View::render([ | ||
'view' => 'Admin/ElementType/Edit', | ||
'title' => 'Edit Element Type', | ||
'layout' => 'Admin/AdminLayout', | ||
'data' => ['elementType' => $elementType], | ||
]); | ||
} | ||
|
||
public function update($id, $postData) | ||
{ | ||
$elementType = ElementType::find($id); | ||
$elementType->name = $postData['name']; | ||
$elementType->description = $postData['description']; | ||
$elementType->save(); | ||
|
||
Session::set('success', 'Type of Element updated successfully'); | ||
|
||
header('Location: /admin/element-types'); | ||
} | ||
|
||
public function destroy($id, $queryParams) | ||
{ | ||
$elementType = ElementType::find($id); | ||
$elementType->delete(); | ||
|
||
Session::set('success', 'Type of Element deleted successfully'); | ||
|
||
header('Location: /admin/element-types'); | ||
} | ||
} |
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
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,34 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
class ElementType extends BaseModel | ||
{ | ||
public string $name; | ||
|
||
public string $description; | ||
|
||
protected static function getTableName(): string | ||
{ | ||
return 'element_types'; | ||
} | ||
|
||
protected static function mapDataToModel($data): ElementType | ||
{ | ||
$element_type = new self(); | ||
$element_type->id = $data['id']; | ||
$element_type->name = $data['name']; | ||
$element_type->description = $data['description']; | ||
$element_type->created_at = $data['created_at']; | ||
$element_type->updated_at = $data['updated_at']; | ||
$element_type->deleted_at = $data['deleted_at']; | ||
|
||
return $element_type; | ||
} | ||
|
||
//public function element(): Element | ||
//{ | ||
// return $this->belongsTo(Element::class, 'element_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
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
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
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
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
Oops, something went wrong.