Add JSON import/export functionality for goals module
- Implement `exportToJson` and `importFromJson` methods in `goals` for serialization and deserialization. - Add `fromJson` method in `goals_criteria` to parse criteria from JSON input. - Extend `exampleRoute` for debugging with sample JSON-based goal creation. - Update `index.php` to autoload new `goals` module classes and dependencies.
This commit is contained in:
@@ -43,6 +43,31 @@ class goals_criteria implements goals_criteria_i
|
||||
$this->products = new goals_criteria_products();
|
||||
$this->start = new \DateTime();
|
||||
$this->end = new \DateTime();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception If the JSON is invalid
|
||||
*/
|
||||
public static function fromJson(string $json): goals_criteria
|
||||
{
|
||||
$data = json_decode($json, true);
|
||||
$criteria = new goals_criteria();
|
||||
|
||||
if (isset($data['type'])) {
|
||||
$criteria->type = goals_criteria_type::tryFrom($data['type']);
|
||||
}
|
||||
if (isset($data['target'])) {
|
||||
$criteria->target = $data['target'];
|
||||
}
|
||||
if (isset($data['start'])) {
|
||||
$criteria->start = new \DateTime($data['start']);
|
||||
}
|
||||
if (isset($data['end'])) {
|
||||
$criteria->end = new \DateTime($data['end']);
|
||||
}
|
||||
// Additional parsing for users, departments, products can be added here
|
||||
|
||||
return $criteria;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user