-
Notifications
You must be signed in to change notification settings - Fork 0
/
Todo.php
87 lines (77 loc) · 1.61 KB
/
Todo.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
// session_start();
class Todo
{
/**
* @var string
*/
public $task = "";
public function __construct()
{
}
/**
* create task
* @param string $task dasdadsa
* @return $_SESSION
*/
public function create($task)
{
$_SESSION['todo'][] = [
'task' => $task,
'status' => 0
];
return $_SESSION['todo'];
}
/**
* List task
* @return $_SESSION array
*/
public function list()
{
return $_SESSION['todo'] ?? [];
}
/**
* Delete task
* @param int $key
*/
public function delete($key)
{
if (isset($_SESSION['todo'][$key])) {
unset($_SESSION['todo'][$key]);
}
}
/**
* task status changed
*/
public function statusChange($key)
{
if (isset($_SESSION['todo'][$key])) {
if ($_SESSION['todo'][$key]['status'] == 1) {
$_SESSION['todo'][$key]['status'] = 0;
} else {
$_SESSION['todo'][$key]['status'] = 1;
}
}
}
/**
* update task
* @param int $key
* @param string $task
* @return void
*/
public function update($key, $task)
{
if (isset($_SESSION['todo'][$key])) {
$_SESSION['todo'][$key]['task'] = $task;
}
}
/**
* Empty task list
*/
public function clear()
{
if (isset($_SESSION['todo'])) {
unset($_SESSION['todo']);
}
}
}