diff options
author | Alessandro Cosentino <cosenal@gmail.com> | 2012-06-03 23:36:39 -0400 |
---|---|---|
committer | Alessandro Cosentino <cosenal@gmail.com> | 2012-06-03 23:36:39 -0400 |
commit | 48ca4574197d3452189eb204324f724dadf6a888 (patch) | |
tree | 20c07a8da7da0b2fecef5255bbcd5e950c7cff42 | |
parent | 3f35d59911ea3e90c4a47249b4a9e7ca49de2cdb (diff) |
renames some function; changes status of items in the database
-rw-r--r-- | lib/feedmapper.php | 7 | ||||
-rw-r--r-- | lib/foldermapper.php | 9 | ||||
-rw-r--r-- | lib/item.php | 16 | ||||
-rw-r--r-- | lib/itemmapper.php | 41 | ||||
-rw-r--r-- | templates/main.php | 56 |
5 files changed, 77 insertions, 52 deletions
diff --git a/lib/feedmapper.php b/lib/feedmapper.php index e352c7ea7..4d885579e 100644 --- a/lib/feedmapper.php +++ b/lib/feedmapper.php @@ -32,7 +32,7 @@ class OC_News_FeedMapper { * @param id The id of the feed in the database table. * @returns */ - public function find($id){ + public function findById($id){ $stmt = OCP\DB::prepare('SELECT * FROM ' . self::tableName . ' WHERE id = ?'); $result = $stmt->execute(array($id)); $row = $result->fetchRow(); @@ -85,7 +85,7 @@ class OC_News_FeedMapper { * @returns The id of the feed in the database table. */ //TODO: handle error case - public function insert(OC_News_Feed $feed, $folderid){ + public function save(OC_News_Feed $feed, $folderid){ $CONFIG_DBTYPE = OCP\Config::getSystemValue( "dbtype", "sqlite" ); if( $CONFIG_DBTYPE == 'sqlite' or $CONFIG_DBTYPE == 'sqlite3' ){ $_ut = "strftime('%s','now')"; @@ -129,8 +129,9 @@ class OC_News_FeedMapper { $items = $feed->getItems(); foreach($items as $item){ - $itemMapper->insert($item, $feedid); + $itemMapper->save($item, $feedid); } + return $feedid; } diff --git a/lib/foldermapper.php b/lib/foldermapper.php index c5adfbfbb..b751e6bcc 100644 --- a/lib/foldermapper.php +++ b/lib/foldermapper.php @@ -67,7 +67,7 @@ class OC_News_FolderMapper { * @param folder the folder to be saved * @returns The id of the folder in the database table. */ - public function insert(OC_News_Folder $folder){ + public function save(OC_News_Folder $folder){ $query = OCP\DB::prepare(' INSERT INTO ' . self::tableName . '(name, parent_id, user_id) @@ -93,12 +93,5 @@ class OC_News_FolderMapper { $folder->setId($folderid); -// $folder->getFeeds(); -// $feedMapper = new OC_News_FeedMapper($feed); -// $items = $feed->getItems(); -// foreach($items as $item){ -// $itemMapper->insert($item); -// } -// return $folderid; } }
\ No newline at end of file diff --git a/lib/item.php b/lib/item.php index ad78f07e2..a2ad69b2a 100644 --- a/lib/item.php +++ b/lib/item.php @@ -51,6 +51,16 @@ class OC_News_Item { public function getGuid(){ return $this->guid; + echo $item->getTitle() . ' - '; + if ($item->isRead()) { + echo $l->t('Read'); + } + else { + echo $l->t('Unread'); + } + echo '<br>'; + $item->setRead(); + } public function setGuid($guid){ @@ -66,7 +76,7 @@ class OC_News_Item { } public function setRead(){ - $this->status |= ~StatusFlag::Unread; + $this->status |= ~StatusFlag::Unread; } public function setUnread(){ @@ -81,6 +91,10 @@ class OC_News_Item { return ($this->status & StatusFlag::Important); } + public function setImportant(){ + $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(), ... diff --git a/lib/itemmapper.php b/lib/itemmapper.php index 05aceb28a..ea59756eb 100644 --- a/lib/itemmapper.php +++ b/lib/itemmapper.php @@ -20,7 +20,7 @@ * */ -/**e 49 +/** * This class maps an item to a row of the items table in the database. * It follows the Data Mapper pattern (see http://martinfowler.com/eaaCatalog/dataMapper.html). */ @@ -67,16 +67,17 @@ class OC_News_ItemMapper { * @brief Save the feed and all its items into the database * @returns The id of the feed in the database table. */ - public function insert(OC_News_Item $item, $feedid){ + public function save(OC_News_Item $item, $feedid){ $guid = $item->getGuid(); - + $status = $item->getStatus(); + echo $status; + $itemid = $this->findIdFromGuid($guid, $feedid); if ($itemid == null){ $title = $item->getTitle(); - $status = $item->getStatus(); - $query = OCP\DB::prepare(' + $stmt = OCP\DB::prepare(' INSERT INTO ' . self::tableName . '(url, title, guid, feed_id, status) VALUES (?, ?, ?, ?, ?) @@ -88,17 +89,32 @@ class OC_News_ItemMapper { } $params=array( - htmlspecialchars_decode($item->getUrl()), - htmlspecialchars_decode($title), - $guid, - $feedid, - $status + htmlspecialchars_decode($item->getUrl()), + htmlspecialchars_decode($title), + $guid, + $feedid, + $status ); - $query->execute($params); + $stmt->execute($params); $itemid = OCP\DB::insertid(self::tableName); } + // update item: its status might have changed + // TODO: maybe make this a new function + else { + $stmt = OCP\DB::prepare(' + UPDATE ' . self::tableName . + ' SET status = ? + WHERE id = ? + '); + + $params=array( + $status, + $itemid + ); + $stmt->execute($params); + } $item->setId($itemid); return $itemid; } @@ -117,9 +133,6 @@ class OC_News_ItemMapper { } - //TODO: the delete of an item should mark an item as deleted, not actually delete from the db - public function markAsDelete($id){ - } /** * @brief Permanently delete all items belonging to a feed from the database diff --git a/templates/main.php b/templates/main.php index 691d609d1..e64ca8912 100644 --- a/templates/main.php +++ b/templates/main.php @@ -1,57 +1,61 @@ <?php +$att = 0; +$prova = 0x2; +$att &= ~0x2; +print($att); + + $feedmapper = new OC_News_FeedMapper(); $foldermapper = new OC_News_FolderMapper(); $folder = new OC_News_Folder( 'Friends' ); -$folderid = $foldermapper->insert($folder); +$folderid = $foldermapper->save($folder); $feed = OC_News_Utils::fetch( 'http://algorithmsforthekitchen.com/blog/?feed=rss2' ); echo '<br>' . $feed->getTitle() . '<br>'; -$feedmapper->insert($feed, $folder->getId()); +$feedmapper->save($feed, $folder->getId()); $feed = $feedmapper->findWithItems($feed->getId()); echo '<br>' . $feed->getTitle() . '<br>'; $items = $feed->getItems(); foreach($items as $item) { - $item->setRead(); + + echo $item->getTitle() . ' - '; if ($item->isRead()) { echo $l->t('Read'); } else { echo $l->t('Unread'); } - - echo '<br>' . $item->getTitle() . '<br>'; + echo '<br>'; + $item->setRead(); } -$feed2 = $feedmapper->findWithItems(45); -echo '<br>' . $feed2->getTitle() . '<br>'; - +foreach($items as $item) { + echo $item->getStatus(); +} -/* -$item = $feed->get_item(1); +echo '<br>'; +$feedmapper->save($feed, $folder->getId()); -if ($item->isRead()) { - echo $l->t('Read'); -} -else { - echo $l->t('Unread'); -} +echo '<br>...after saving and reloading'; -$item->setRead(); -$item->setUnread(); -$item->setRead(); +$feed = $feedmapper->findWithItems($feed->getId()); +echo '<br>' . $feed->getTitle() . '<br>'; +$items = $feed->getItems(); -echo "<br>" . $item->get_title() . "<br>"; +foreach($items as &$item) { -if ($item->isRead()) { - echo $l->t('Read'); -} -else { - echo $l->t('Unread'); + echo $item->getTitle() . ' - '; + if ($item->isRead()) { + echo $l->t('Read'); + } + else { + echo $l->t('Unread'); + } + echo '<br>'; } -*/
\ No newline at end of file |