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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
<?php
class Entry extends Model {
private $guid;
private $title;
private $author;
private $content;
private $link;
private $date;
private $is_read;
private $is_favorite;
public function __construct ($guid = '', $title = '', $author = '', $content = '',
$link = '', $pubdate = 0, $is_read = false, $is_favorite = false) {
$this->_guid ($guid);
$this->_title ($title);
$this->_author ($author);
$this->_content ($content);
$this->_link ($link);
$this->_date ($pubdate);
$this->_isRead ($is_read);
$this->_isFavorite ($is_favorite);
}
public function id () {
return small_hash ($this->guid . Configuration::selApplication ());
}
public function guid () {
return $this->guid;
}
public function title () {
return $this->title;
}
public function author () {
return $this->author;
}
public function content () {
return $this->content;
}
public function link () {
return $this->link;
}
public function date ($raw = false) {
if ($raw) {
return $this->date;
} else {
return timestamptodate ($this->date);
}
}
public function isRead () {
return $this->is_read;
}
public function isFavorite () {
return $this->is_favorite;
}
public function _guid ($value) {
$this->guid = $value;
}
public function _title ($value) {
$this->title = $value;
}
public function _author ($value) {
$this->author = $value;
}
public function _content ($value) {
$this->content = $value;
}
public function _link ($value) {
$this->link = $value;
}
public function _date ($value) {
$this->date = $value;
}
public function _isRead ($value) {
$this->is_read = $value;
}
public function _isFavorite ($value) {
$this->is_favorite = $value;
}
}
class EntryDAO extends Model_array {
public function __construct () {
parent::__construct (PUBLIC_PATH . '/data/db/Entries.array.php');
}
public function addEntry ($values) {
$id = $values['id'];
unset ($values['id']);
if (!isset ($this->array[$id])) {
$this->array[$id] = array ();
foreach ($values as $key => $value) {
$this->array[$id][$key] = $value;
}
$this->writeFile ($this->array);
} else {
return false;
}
}
public function updateEntry ($id, $values) {
foreach ($values as $key => $value) {
$this->array[$id][$key] = $value;
}
$this->writeFile($this->array);
}
public function searchById ($id) {
$list = HelperEntry::daoToEntry ($this->array);
if (isset ($list[$id])) {
return $list[$id];
} else {
return false;
}
}
public function listEntries () {
$list = $this->array;
if (!is_array ($list)) {
$list = array ();
}
return HelperEntry::daoToEntry ($list);
}
public function listNotReadEntries () {
$list = $this->array;
$list_not_read = array ();
if (!is_array ($list)) {
$list = array ();
}
foreach ($list as $key => $entry) {
if (!$entry['is_read']) {
$list_not_read[$key] = $entry;
}
}
return HelperEntry::daoToEntry ($list_not_read);
}
public function count () {
return count ($this->array);
}
}
class HelperEntry {
public static function daoToEntry ($listDAO) {
$list = array ();
if (!is_array ($listDAO)) {
$listDAO = array ($listDAO);
}
foreach ($listDAO as $key => $dao) {
$list[$key] = new Entry (
$dao['guid'],
$dao['title'],
$dao['author'],
$dao['content'],
$dao['link'],
$dao['date'],
$dao['is_read'],
$dao['is_favorite']
);
}
return $list;
}
}
|