From 843f5e0fd29577489f14164c2e0e664cc67e36fc Mon Sep 17 00:00:00 2001 From: Alessandro Cosentino Date: Wed, 20 Mar 2013 18:24:21 +0100 Subject: findAll functions in the itemmapper --- db/itemmapper.php | 52 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 19 deletions(-) (limited to 'db/itemmapper.php') diff --git a/db/itemmapper.php b/db/itemmapper.php index c6ea67209..0bf9b4d87 100644 --- a/db/itemmapper.php +++ b/db/itemmapper.php @@ -17,18 +17,14 @@ use \OCA\AppFramework\Db\MultipleObjectsReturnedException; use \OCA\AppFramework\Db\Mapper; use \OCA\AppFramework\Core\API; -class ItemMapper extends Mapper { +class ItemMapper extends NewsMapper { public function __construct(API $api){ parent::__construct($api, 'news_items'); } - - public function findAllFromFeed($feedId, $userId){ - $sql = 'SELECT * FROM `*PREFIX*news_items` ' . - 'WHERE user_id = ? ' . - 'AND feed_id = ?'; - - $result = $this->execute($sql, array($feedId, $userId)); + + protected function findAllRows($sql, $params) { + $result = $this->execute($sql, $params); $items = array(); while($row = $result->fetchRow()){ @@ -40,21 +36,37 @@ class ItemMapper extends Mapper { return $items; } - - public function find($id, $userId){ + + public function findAllFromFeed($feedId, $userId){ $sql = 'SELECT * FROM `*PREFIX*news_items` ' . 'WHERE user_id = ? ' . - 'AND id = ?'; + 'AND feed_id = ?'; - $result = $this->execute($sql, array($id, $userId)); + $params = array($feedId, $userId); + return $this->findAllRows($sql, $params); + - $row = $result->fetchRow(); - if ($row === false) { - throw new DoesNotExistException('Item ' . $id . - ' from user ' . $userId . ' not found'); - } elseif($result->fetchRow() !== false) { - throw new MultipleObjectsReturnedException('More than one result for Item with id ' . $id . ' from user ' . $userId . '!'); - } + } + /* + request: get all items of a folder of a user (unread and read) + SELECT * FROM items + JOIN feeds + ON feed.id = feed_id + WHERE user_id = ? AND status = ? AND feed.folder_id = ? + (AND id < ? LIMIT ?) + (AND items.lastmodified >= ?) + */ + + + + public function find($id, $userId){ + $sql = 'SELECT `*dbprefix*news_items`.* FROM `*dbprefix*news_items` ' . + 'JOIN `*dbprefix*news_feeds` ' . + 'ON `*dbprefix*news_feeds`.`id` = `*dbprefix*news_items`.`feed_id` ' . + 'WHERE `*dbprefix*news_items`.`id` = ? ' . + 'AND `*dbprefix*news_feeds`.`user_id` = ? '; + + $row = $this->findRow($sql, $id, $userId); $item = new Item(); $item->fromRow($row); @@ -62,7 +74,9 @@ class ItemMapper extends Mapper { return $item; } + public function findAllFromFolder($status, $feedId, $userId){ + } } -- cgit v1.2.3