summaryrefslogtreecommitdiffstats
path: root/db/itemmapper.php
diff options
context:
space:
mode:
authorAlessandro Cosentino <cosenal@gmail.com>2013-03-20 18:24:21 +0100
committerAlessandro Cosentino <cosenal@gmail.com>2013-03-20 18:24:21 +0100
commit843f5e0fd29577489f14164c2e0e664cc67e36fc (patch)
tree25caaa7415335e0141aa993793e7886545c9fa96 /db/itemmapper.php
parent97855d5d6aa19bb1b02934b8415fb56651e63304 (diff)
findAll functions in the itemmapper
Diffstat (limited to 'db/itemmapper.php')
-rw-r--r--db/itemmapper.php52
1 files changed, 33 insertions, 19 deletions
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){
+ }
}