-
Notifications
You must be signed in to change notification settings - Fork 7
/
TodoEx.php
116 lines (105 loc) · 2.69 KB
/
TodoEx.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
/*
Copyright 2014-2019 Ondrej Novy
This file is part of otodo.
otodo is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
otodo is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with otodo. If not, see <http://www.gnu.org/licenses/>.
*/
class TodoEx extends Todo {
private $due;
private $rec;
protected $validExtensions = array('due', 'rec', 'recurrent');
protected function clean() {
parent::clean();
$this->due = null;
$this->rec = null;
}
protected function parseAddons() {
parent::parseAddons();
if (isset($this->addons['due'])) {
$this->due = $this->parseDate($this->addons['due']);
}
if (isset($this->addons['rec'])) {
$this->rec = new Recurrent($this->addons['rec']);
}
if (isset($this->addons['recurrent'])) {
$val = $this->addons['recurrent'];
if ($val[0] === '+') {
$val = substr($val, 1);
} else {
$val = '+' . $val;
}
$this->rec = new Recurrent($val);
unset($this->addons['recurrent']);
$this->addons['rec'] = $this->rec->toString();
}
}
public function markDone() {
if ($this->rec) {
$t = clone $this;
$t->creationDate = new DateTime('today');
$t->due = $this->rec->recurr($this->due);
$t->addons['due'] = $t->due->format('Y-m-d');
$this->todos[] = $t;
}
parent::markDone();
}
public function __set($name, $value) {
switch ($name) {
case 'due':
$this->due = $value;
if ($value === null) {
unset($this->addons['due']);
} else {
assert($value instanceof DateTime);
$this->addons['due'] = $value->format('Y-m-d');
}
break;
case 'rec':
$this->rec = $value;
if ($value === null) {
unset($this->addons['rec']);
} else {
assert($value instanceof Recurrent);
$this->addons['rec'] = $value->toString();
}
break;
default:
parent::__set($name, $value);
break;
}
}
public function __get($name) {
switch ($name) {
case 'due':
return $this->due;
break;
case 'rec':
return $this->rec;
break;
default:
return parent::__get($name);
break;
}
}
/**
* @codeCoverageIgnore
*/
public function debug() {
parent::debug();
if ($this->due !== null) {
echo 'Due: ' . $this->due->format('Y-m-d') . PHP_EOL;
}
if ($this->rec !== null) {
echo 'Recurrent: ' . $this->rec->toString() . PHP_EOL;
}
}
}