diff options
author | Alessandro Cosentino <cosenal@gmail.com> | 2012-10-28 10:57:35 -0400 |
---|---|---|
committer | Alessandro Cosentino <cosenal@gmail.com> | 2012-10-28 10:57:35 -0400 |
commit | a7f7f04052ded38c94e15a4e94645f6ab2b39941 (patch) | |
tree | 0a2c06adb471d5c18535c308f7991b4c9675f876 /lib | |
parent | ff6bee25f0468d291616be9235ae556457d7fc0d (diff) |
sharing items in the News app
Diffstat (limited to 'lib')
-rw-r--r-- | lib/feedtypes.php | 1 | ||||
-rw-r--r-- | lib/itemmapper.php | 9 | ||||
-rw-r--r-- | lib/share/item.php | 44 |
3 files changed, 51 insertions, 3 deletions
diff --git a/lib/feedtypes.php b/lib/feedtypes.php index b4f7d6f3a..d330a5b2a 100644 --- a/lib/feedtypes.php +++ b/lib/feedtypes.php @@ -18,4 +18,5 @@ class FeedType { const FOLDER = 1; const STARRED = 2; const SUBSCRIPTIONS = 3; + const SHARED = 4; };
\ No newline at end of file diff --git a/lib/itemmapper.php b/lib/itemmapper.php index 92a3928d7..ba9be41a7 100644 --- a/lib/itemmapper.php +++ b/lib/itemmapper.php @@ -236,11 +236,14 @@ class ItemMapper { /** * @brief Retrieve an item from the database - * @param id The id of the feed in the database table. + * @param id The id of the item in the database table. */ public function findById($id) { - $stmt = \OCP\DB::prepare('SELECT * FROM ' . self::tableName . ' WHERE id = ?'); - $result = $stmt->execute(array($id)); + $stmt = \OCP\DB::prepare('SELECT * FROM ' . self::tableName . ' JOIN ' . FeedMapper::tableName . + ' ON ' . self::tableName . '.feed_id = ' . FeedMapper::tableName . '.id WHERE ' + . self::tableName .'.id = ? AND ' . FeedMapper::tableName . '.user_id = ? '); + $result = $stmt->execute(array($id, $this->userid)); + $row = $result->fetchRow(); $item = $this->fromRow($row); diff --git a/lib/share/item.php b/lib/share/item.php new file mode 100644 index 000000000..db9ab0f48 --- /dev/null +++ b/lib/share/item.php @@ -0,0 +1,44 @@ +<?php +/** +* ownCloud - News app +* +* @author Alessandro Cosentino +* Copyright (c) 2012 - Alessandro Cosentino <cosenal@gmail.com> +* +* This file is licensed under the Affero General Public License version 3 or later. +* See the COPYING-README file +* +*/ + +namespace OCA\News; + +class Share_Backend_News_Item implements \OCP\Share_Backend { + + const FORMAT_ITEM = 0; + + private static $item; + + public function isValidSource($itemSource, $uidOwner) { + $itemMapper = new ItemMapper($uidOwner); + $this->item = $itemMapper->findById($itemSource); + if ($this->item !== null) { + return true; + } + return false; + } + + public function generateTarget($itemSource, $shareWith, $exclude = null) { + return $this->item->getTitle(); + } + + public function formatItems($items, $format, $parameters = null) { + $formattedItems = array(); + foreach ($items as $item) { + $itemMapper = new ItemMapper($item['uid_owner']); + $formattedItem = $itemMapper->findById($item['item_source']); + $formattedItems[] = $formattedItem; + } + return $formattedItems; + } + +}
\ No newline at end of file |