From 200aebe1f4220d9d0b8f1b3807704300ced28f16 Mon Sep 17 00:00:00 2001 From: Alessandro Cosentino Date: Mon, 4 Jun 2012 18:17:11 -0400 Subject: fixes bug on status bitfield; tests storing the status in db --- lib/item.php | 28 +++++++++++----------------- lib/itemmapper.php | 2 ++ templates/main.php | 18 ++++++++++++------ 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/lib/item.php b/lib/item.php index a2ad69b2a..73fd472e1 100644 --- a/lib/item.php +++ b/lib/item.php @@ -46,21 +46,11 @@ class OC_News_Item { $this->title = $title; $this->url = $url; $this->guid = $guid; - $this->status |= StatusFlag::Unread; + $this->status |= StatusFlag::Unread; } public function getGuid(){ return $this->guid; - echo $item->getTitle() . ' - '; - if ($item->isRead()) { - echo $l->t('Read'); - } - else { - echo $l->t('Unread'); - } - echo '
'; - $item->setRead(); - } public function setGuid($guid){ @@ -76,7 +66,7 @@ class OC_News_Item { } public function setRead(){ - $this->status |= ~StatusFlag::Unread; + $this->status &= ~StatusFlag::Unread; } public function setUnread(){ @@ -84,17 +74,17 @@ class OC_News_Item { } public function isRead(){ - return ($this->status & ~StatusFlag::Unread); - } - - public function isImportant(){ - return ($this->status & StatusFlag::Important); + return !($this->status & StatusFlag::Unread); } public function setImportant(){ $this->status |= StatusFlag::Important; } + public function isImportant(){ + return ($this->status & StatusFlag::Important); + } + /** * NOTE: this is needed to store items in the database, otherwise * the status of an item should be retrieved with methods: isRead(), isImportant(), ... @@ -102,6 +92,10 @@ class OC_News_Item { public function getStatus(){ return $this->status; } + + public function setStatus($status){ + $this->status = $status; + } public function getTitle(){ return $this->title; diff --git a/lib/itemmapper.php b/lib/itemmapper.php index ea59756eb..6f7acb939 100644 --- a/lib/itemmapper.php +++ b/lib/itemmapper.php @@ -41,7 +41,9 @@ class OC_News_ItemMapper { $url = $row['url']; $title = $row['title']; $guid = $row['guid']; + $status = $row['status']; $item = new OC_News_Item($url, $title, $guid); + $item->setStatus($status); $items[] = $item; } diff --git a/templates/main.php b/templates/main.php index e64ca8912..e410baa9a 100644 --- a/templates/main.php +++ b/templates/main.php @@ -1,11 +1,5 @@ setRead(); } +foreach($items as $item) { + echo $item->getTitle() . ' - '; + if ($item->isRead()) { + echo $l->t('Read'); + } + else { + echo $l->t('Unread'); + } + echo '
'; +} + + foreach($items as $item) { echo $item->getStatus(); } -- cgit v1.2.3