summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--db/itemmapper.php61
-rw-r--r--tests/db/ItemMapperTest.php98
2 files changed, 127 insertions, 32 deletions
diff --git a/db/itemmapper.php b/db/itemmapper.php
index 693dbc07c..bd223a77c 100644
--- a/db/itemmapper.php
+++ b/db/itemmapper.php
@@ -3,10 +3,22 @@
* ownCloud - News app
*
* @author Alessandro Cosentino
-* Copyright (c) 2012 - Alessandro Cosentino <cosenal@gmail.com>
+* @author Bernhard Posselt
+* @copyright 2012 Alessandro Cosentino cosenal@gmail.com
+* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
*
-* This file is licensed under the Affero General Public License version 3 or later.
-* See the COPYING-README file
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Affero General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
@@ -36,7 +48,7 @@ class ItemMapper extends NewsMapper {
return $items;
}
-
+
public function findAllFromFeed($feedId, $userId){
$sql = 'SELECT * FROM `*PREFIX*news_items` ' .
'WHERE user_id = ? ' .
@@ -46,17 +58,46 @@ class ItemMapper extends NewsMapper {
return $this->findAllRows($sql, $params);
}
- public function findAllFromFolder($userId, $folderId, $status){
- $sql = 'SELECT `*dbprefix*news_items`.* FROM `*dbprefix*news_items` ' .
+ public function findAllFromFeedByStatus($feedId, $userId, $status){
+ $sql = 'SELECT * FROM `*PREFIX*news_items` ' .
+ 'WHERE user_id = ? ' .
+ 'AND feed_id = ? ' .
+ 'AND ((`*dbprefix*news_items`.`status` & ?) > 0)';
+
+ $params = array($feedId, $userId, $status);
+ return $this->findAllRows($sql, $params);
+ }
+
+
+ public function findAllFromFolder($userId, $folderId){
+ $sql = $this->makeFindAllFromFolderQuery('');
+ $params = array($userId, $folderId);
+ return $this->findAllRows($sql, $params);
+ }
+
+ public function findAllFromFolderByStatus($userId, $folderId, $status){
+ $sql = $this->makeFindAllFromFolderQuery('AND ((`*dbprefix*news_items`.`status` & ?) > 0)');
+ $params = array($userId, $folderId, $status);
+ return $this->findAllRows($sql, $params);
+ }
+
+ public function findAllFromFolderByLastMofified($userId, $folderId, $lastModified){
+ $sql = $this->makeFindAllFromFolderQuery('AND `*dbprefix*news_items`.last_modified >= ? ');
+ $params = array($userId, $folderId, $lastModified);
+ return $this->findAllRows($sql, $params);
+ }
+
+ private function makeFindAllFromFolderQuery($custom) {
+ return '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_feeds`.`user_id` = ? ' .
'AND `*dbprefix*news_feeds`.`folder_id` = ? ' .
- 'AND ((`*dbprefix*news_items`.`status` & ?) > 0)';
-
- $params = array($userId, $folderId, $status);
- return $this->findAllRows($sql, $params);
+ $custom;
}
+
+
+
/*
request: get all items of a folder of a user (unread and read)
SELECT * FROM items
diff --git a/tests/db/ItemMapperTest.php b/tests/db/ItemMapperTest.php
index eba91758e..983bfc933 100644
--- a/tests/db/ItemMapperTest.php
+++ b/tests/db/ItemMapperTest.php
@@ -48,26 +48,6 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
);
}
-
- public function testFindAllFromFeed(){
- $userId = 'john';
- $feedId = 3;
- $rows = array(
- array('id' => $this->items[0]->getId()),
- array('id' => $this->items[1]->getId())
- );
- $sql = 'SELECT * FROM `*PREFIX*news_items` ' .
- 'WHERE user_id = ? ' .
- 'AND feed_id = ?';
-
- $this->setMapperResult($sql, array($feedId, $userId), $rows);
-
- $result = $this->itemMapper->findAllFromFeed($feedId, $userId);
-
- $this->assertEquals($this->items, $result);
-
- }
-
public function testFind(){
$userId = 'john';
$id = 3;
@@ -122,8 +102,64 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
$result = $this->itemMapper->find($id, $userId);
}
+ public function testFindAllFromFeed(){
+ $userId = 'john';
+ $feedId = 3;
+ $rows = array(
+ array('id' => $this->items[0]->getId()),
+ array('id' => $this->items[1]->getId())
+ );
+ $sql = 'SELECT * FROM `*PREFIX*news_items` ' .
+ 'WHERE user_id = ? ' .
+ 'AND feed_id = ?';
+
+ $this->setMapperResult($sql, array($feedId, $userId), $rows);
+ $result = $this->itemMapper->findAllFromFeed($feedId, $userId);
+ $this->assertEquals($this->items, $result);
+
+ }
- public function FindAllFromFolder() {
+ public function testFindAllFromFeedByStatus(){
+ $userId = 'john';
+ $feedId = 3;
+ $status = 2;
+ $rows = array(
+ array('id' => $this->items[0]->getId()),
+ array('id' => $this->items[1]->getId())
+ );
+ $sql = 'SELECT * FROM `*PREFIX*news_items` ' .
+ 'WHERE user_id = ? ' .
+ 'AND feed_id = ? ' .
+ 'AND ((`*dbprefix*news_items`.`status` & ?) > 0)';
+
+ $this->setMapperResult($sql, array($feedId, $userId, $status), $rows);
+ $result = $this->itemMapper->findAllFromFeedByStatus($feedId, $userId, $status);
+ $this->assertEquals($this->items, $result);
+
+ }
+
+ public function testFindAllFromFolder() {
+ $userId = 'john';
+ $folderId = 3;
+
+ $rows = array(
+ array('id' => $this->items[0]->getId()),
+ array('id' => $this->items[1]->getId())
+ );
+
+ $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_feeds`.`user_id` = ? ' .
+ 'AND `*dbprefix*news_feeds`.`folder_id` = ? ';
+
+ $this->setMapperResult($sql, array($userId, $folderId), $rows);
+ $result = $this->itemMapper->findAllFromFolder($userId, $folderId);
+ $this->assertEquals($this->items, $result);
+
+ }
+
+ public function testFindAllFromFolderByStatus() {
$userId = 'john';
$folderId = 3;
$status = 2;
@@ -135,7 +171,25 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
'AND ((`*dbprefix*news_items`.`status` & ?) > 0)';
$this->setMapperResult($sql, array($userId, $folderId, $status));
- $result = $this->itemMapper->findAllFromFolder($userId, $folderId, $status);
+ $result = $this->itemMapper->findAllFromFolderByStatus($userId, $folderId, $status);
}
+
+ public function testFindAllFromFolderByLastModified() {
+ $userId = 'john';
+ $folderId = 3;
+ $lastModified = 123;
+
+ $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_feeds`.`user_id` = ? ' .
+ 'AND `*dbprefix*news_feeds`.`folder_id` = ? ' .
+ 'AND `*dbprefix*news_items`.last_modified >= ? ';
+
+ $this->setMapperResult($sql, array($userId, $folderId, $lastModified));
+ $result = $this->itemMapper->findAllFromFolderByLastMofified($userId, $folderId, $lastModified);
+ }
+
+
} \ No newline at end of file