summaryrefslogtreecommitdiffstats
path: root/db/itemmapper.php
diff options
context:
space:
mode:
authorAlessandro Cosentino <cosenal@gmail.com>2013-03-20 14:28:29 +0100
committerAlessandro Cosentino <cosenal@gmail.com>2013-03-20 14:28:29 +0100
commit46a7c39bcb7b5ac18dff552fafb7d75e1ef27803 (patch)
tree4db89b4dee06a5d66b71014213420619f8895948 /db/itemmapper.php
parent0f0a7f0c473ba9c7ddbf4321ffb264fe2b58e33b (diff)
test find method
Diffstat (limited to 'db/itemmapper.php')
-rw-r--r--db/itemmapper.php30
1 files changed, 27 insertions, 3 deletions
diff --git a/db/itemmapper.php b/db/itemmapper.php
index e79cabb7c..c6ea67209 100644
--- a/db/itemmapper.php
+++ b/db/itemmapper.php
@@ -12,16 +12,17 @@
namespace OCA\News\Db;
+use \OCA\AppFramework\Db\DoesNotExistException;
+use \OCA\AppFramework\Db\MultipleObjectsReturnedException;
use \OCA\AppFramework\Db\Mapper;
use \OCA\AppFramework\Core\API;
class ItemMapper extends Mapper {
public function __construct(API $api){
- parent::__construct($api);
+ parent::__construct($api, 'news_items');
}
-
public function findAllFromFeed($feedId, $userId){
$sql = 'SELECT * FROM `*PREFIX*news_items` ' .
'WHERE user_id = ? ' .
@@ -30,7 +31,7 @@ class ItemMapper extends Mapper {
$result = $this->execute($sql, array($feedId, $userId));
$items = array();
- foreach($result->fetchRow() as $row){
+ while($row = $result->fetchRow()){
$item = new Item();
$item->fromRow($row);
@@ -39,6 +40,29 @@ class ItemMapper extends Mapper {
return $items;
}
+
+ public function find($id, $userId){
+ $sql = 'SELECT * FROM `*PREFIX*news_items` ' .
+ 'WHERE user_id = ? ' .
+ 'AND id = ?';
+
+ $result = $this->execute($sql, array($id, $userId));
+
+ $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 . '!');
+ }
+
+ $item = new Item();
+ $item->fromRow($row);
+
+ return $item;
+ }
+
+
}