forked from JohanGriesel/Stratusolve-Exercise
-
Notifications
You must be signed in to change notification settings - Fork 35
/
task.class.php
47 lines (45 loc) · 1.61 KB
/
task.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
/**
* This class handles the modification of a task object
*/
class Task {
public $TaskId;
public $TaskName;
public $TaskDescription;
protected $TaskDataSource;
public function __construct($Id = null) {
$this->TaskDataSource = file_get_contents('Task_Data.txt');
if (strlen($this->TaskDataSource) > 0)
$this->TaskDataSource = json_decode($this->TaskDataSource); // Should decode to an array of Task objects
else
$this->TaskDataSource = array(); // If it does not, then the data source is assumed to be empty and we create an empty array
if (!$this->TaskDataSource)
$this->TaskDataSource = array(); // If it does not, then the data source is assumed to be empty and we create an empty array
if (!$this->LoadFromId($Id))
$this->Create();
}
protected function Create() {
// This function needs to generate a new unique ID for the task
// Assignment: Generate unique id for the new task
$this->TaskId = $this->getUniqueId();
$this->TaskName = 'New Task';
$this->TaskDescription = 'New Description';
}
protected function getUniqueId() {
// Assignment: Code to get new unique ID
return -1; // Placeholder return for now
}
protected function LoadFromId($Id = null) {
if ($Id) {
// Assignment: Code to load details here...
} else
return null;
}
public function Save() {
//Assignment: Code to save task here
}
public function Delete() {
//Assignment: Code to delete task here
}
}
?>