From a6e57a9a1f4427de872c4bf0050cc0ee38d2adfe Mon Sep 17 00:00:00 2001 From: Alessandro Cosentino Date: Tue, 29 May 2012 16:07:12 -0400 Subject: adds indices to database schema --- lib/itemmapper.php | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) (limited to 'lib/itemmapper.php') diff --git a/lib/itemmapper.php b/lib/itemmapper.php index c8368ba9e..65f1eb2e2 100644 --- a/lib/itemmapper.php +++ b/lib/itemmapper.php @@ -20,25 +20,19 @@ * */ -/** +/**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). */ class OC_News_ItemMapper { const tableName = '*PREFIX*news_items'; - private $feed; - - public function __construct(OC_News_Feed $feed){ - $this->feed = $feed; - } /** - * @brief Retrieve an item from the database - * @param id The id of the feed in the database table. + * @brief Retrieve all the item corresponding to a feed from the database + * @param feedid The id of the feed in the database table. */ - public function findAll(){ - $feedid = $this->feed->getId(); + public function findAll($feedid){ $stmt = OCP\DB::prepare('SELECT * FROM ' . self::tableName . ' WHERE feedid = ?'); $result = $stmt->execute(array($feedid)); @@ -46,7 +40,8 @@ class OC_News_ItemMapper { while ($row = $result->fetchRow()) { $url = $row['url']; $title = $row['title']; - $items[] = new OC_News_Item($url, $title); + $guid = $row['guid']; + $items[] = new OC_News_Item($url, $title, $guid); } return $items; @@ -56,18 +51,16 @@ 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 = $this->feed->getId(); + public function insert(OC_News_Item $item, $feedid){ + $guid = $item->getGuid(); + $title = $item->getTitle(); $query = OCP\DB::prepare(' INSERT INTO ' . self::tableName . - '(url, title, feedid) - VALUES (?, ?, ?) + '(url, title, guid, feedid) + VALUES (?, ?, ?, ?) '); - $title = $item->getTitle(); - if(empty($title)) { $l = OC_L10N::get('news'); $title = $l->t('no title'); @@ -76,6 +69,7 @@ class OC_News_ItemMapper { $params=array( htmlspecialchars_decode($item->getUrl()), htmlspecialchars_decode($title), + $guid, $feedid ); -- cgit v1.2.3