1 | <?php |
||
49 | class Item extends Entity implements IAPI, \JsonSerializable { |
||
50 | |||
51 | use EntityJSONSerializer; |
||
52 | |||
53 | protected $contentHash; |
||
54 | protected $guidHash; |
||
55 | protected $guid; |
||
56 | protected $url; |
||
57 | protected $title; |
||
58 | protected $author; |
||
59 | protected $pubDate; |
||
60 | protected $body; |
||
61 | protected $enclosureMime; |
||
62 | protected $enclosureLink; |
||
63 | protected $feedId; |
||
64 | protected $status = 0; |
||
65 | protected $lastModified; |
||
66 | protected $searchIndex; |
||
67 | protected $rtl; |
||
68 | 14 | protected $fingerprint; |
|
69 | 14 | ||
70 | 14 | public function __construct() { |
|
71 | 14 | $this->addType('pubDate', 'integer'); |
|
72 | 14 | $this->addType('feedId', 'integer'); |
|
73 | 14 | $this->addType('status', 'integer'); |
|
74 | 14 | $this->addType('lastModified', 'integer'); |
|
75 | $this->addType('rtl', 'boolean'); |
||
76 | } |
||
77 | |||
78 | public function setRead() { |
||
79 | $this->markFieldUpdated('status'); |
||
80 | $this->status &= ~StatusFlag::UNREAD; |
||
81 | } |
||
82 | 4 | ||
83 | 4 | public function isRead() { |
|
84 | return !(($this->status & StatusFlag::UNREAD) === StatusFlag::UNREAD); |
||
85 | } |
||
86 | 1 | ||
87 | 1 | public function setUnread() { |
|
88 | 1 | $this->markFieldUpdated('status'); |
|
89 | 1 | $this->status |= StatusFlag::UNREAD; |
|
90 | } |
||
91 | 4 | ||
92 | 4 | public function isUnread() { |
|
93 | return !$this->isRead(); |
||
94 | } |
||
95 | |||
96 | public function setStarred() { |
||
97 | $this->markFieldUpdated('status'); |
||
98 | $this->status |= StatusFlag::STARRED; |
||
99 | } |
||
100 | |||
101 | public function isStarred() { |
||
102 | return ($this->status & StatusFlag::STARRED) === StatusFlag::STARRED; |
||
103 | } |
||
104 | |||
105 | public function setUnstarred() { |
||
106 | $this->markFieldUpdated('status'); |
||
107 | $this->status &= ~StatusFlag::STARRED; |
||
108 | } |
||
109 | |||
110 | public function isUnstarred() { |
||
111 | return !$this->isStarred(); |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * Turns entitie attributes into an array |
||
116 | */ |
||
117 | public function jsonSerialize() { |
||
118 | return [ |
||
119 | 'id' => $this->getId(), |
||
120 | 'guid' => $this->getGuid(), |
||
121 | 'guidHash' => $this->getGuidHash(), |
||
122 | 'url' => $this->getUrl(), |
||
123 | 'title' => $this->getTitle(), |
||
124 | 'author' => $this->getAuthor(), |
||
125 | 'pubDate' => $this->getPubDate(), |
||
126 | 'body' => $this->getBody(), |
||
127 | 'enclosureMime' => $this->getEnclosureMime(), |
||
128 | 'enclosureLink' => $this->getEnclosureLink(), |
||
129 | 'feedId' => $this->getFeedId(), |
||
130 | 'unread' => $this->isUnread(), |
||
131 | 'starred' => $this->isStarred(), |
||
132 | 'lastModified' => $this->getLastModified(), |
||
133 | 'rtl' => $this->getRtl(), |
||
134 | 'intro' => $this->getIntro(), |
||
135 | 'fingerprint' => $this->getFingerprint(), |
||
136 | ]; |
||
137 | } |
||
138 | |||
139 | public function toAPI() { |
||
140 | return [ |
||
141 | 'id' => $this->getId(), |
||
142 | 'guid' => $this->getGuid(), |
||
143 | 'guidHash' => $this->getGuidHash(), |
||
144 | 'url' => $this->getUrl(), |
||
145 | 'title' => $this->getTitle(), |
||
146 | 'author' => $this->getAuthor(), |
||
147 | 'pubDate' => $this->getPubDate(), |
||
148 | 'body' => $this->getBody(), |
||
149 | 'enclosureMime' => $this->getEnclosureMime(), |
||
150 | 'enclosureLink' => $this->getEnclosureLink(), |
||
151 | 'feedId' => $this->getFeedId(), |
||
152 | 'unread' => $this->isUnread(), |
||
153 | 'starred' => $this->isStarred(), |
||
154 | 'lastModified' => $this->getLastModified(), |
||
155 | 'rtl' => $this->getRtl(), |
||
156 | 'fingerprint' => $this->getFingerprint(), |
||
157 | 'contentHash' => $this->getContentHash() |
||
158 | ]; |
||
159 | } |
||
160 | |||
161 | public function toExport($feeds) { |
||
162 | return [ |
||
163 | 'guid' => $this->getGuid(), |
||
164 | 'url' => $this->getUrl(), |
||
165 | 'title' => $this->getTitle(), |
||
166 | 'author' => $this->getAuthor(), |
||
167 | 'pubDate' => $this->getPubDate(), |
||
168 | 'body' => $this->getBody(), |
||
169 | 'enclosureMime' => $this->getEnclosureMime(), |
||
170 | 'enclosureLink' => $this->getEnclosureLink(), |
||
171 | 'unread' => $this->isUnread(), |
||
172 | 'starred' => $this->isStarred(), |
||
173 | 'feedLink' => $feeds['feed' . $this->getFeedId()]->getLink(), |
||
174 | 'rtl' => $this->getRtl(), |
||
175 | ]; |
||
176 | } |
||
177 | |||
178 | public function getIntro() { |
||
181 | |||
182 | public static function fromImport($import) { |
||
183 | $item = new static(); |
||
184 | $item->setGuid($import['guid']); |
||
185 | $item->setGuidHash($import['guid']); |
||
186 | $item->setUrl($import['url']); |
||
187 | $item->setTitle($import['title']); |
||
188 | $item->setAuthor($import['author']); |
||
189 | $item->setPubDate($import['pubDate']); |
||
190 | $item->setBody($import['body']); |
||
191 | $item->setEnclosureMime($import['enclosureMime']); |
||
192 | $item->setEnclosureLink($import['enclosureLink']); |
||
193 | $item->setRtl($import['rtl']); |
||
207 | |||
208 | public function setAuthor($name) { |
||
211 | 14 | ||
212 | public function setTitle($title) { |
||
215 | 14 | ||
216 | 14 | public function generateSearchIndex() { |
|
229 | 14 | ||
230 | private function computeContentHash() { |
||
235 | |||
236 | 14 | private function computeFingerprint() { |
|
240 | 14 | ||
241 | 14 | public function setUrl($url) { |
|
247 | 14 | ||
248 | 14 | public function setBody($body) { |
|
255 | |||
256 | } |
||
257 |