summaryrefslogtreecommitdiffstats
path: root/lib/itemmapper.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/itemmapper.php')
-rw-r--r--lib/itemmapper.php66
1 files changed, 33 insertions, 33 deletions
diff --git a/lib/itemmapper.php b/lib/itemmapper.php
index 2f4e295b2..58894cce8 100644
--- a/lib/itemmapper.php
+++ b/lib/itemmapper.php
@@ -4,10 +4,10 @@
*
* @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;
@@ -31,7 +31,7 @@ class ItemMapper {
}
/**
- * @brief
+ * @brief
* @param row a row from the items table of the database
* @returns an object of the class OC_News_Item
*/
@@ -46,10 +46,10 @@ class ItemMapper {
$item->setAuthor($row['author']);
$item->setFeedId($row['feed_id']);
$item->setDate(Utils::dbtimestampToUnixtime($row['pub_date']));
-
+
return $item;
}
-
+
/**
* @brief Retrieve all the item corresponding to a feed from the database
* @param feedid The id of the feed in the database table.
@@ -57,7 +57,7 @@ class ItemMapper {
public function findByFeedId($feedid) {
$stmt = \OCP\DB::prepare('SELECT * FROM ' . self::tableName . ' WHERE feed_id = ? ORDER BY pub_date DESC');
$result = $stmt->execute(array($feedid));
-
+
$items = array();
while ($row = $result->fetchRow()) {
$item = $this->fromRow($row);
@@ -66,7 +66,7 @@ class ItemMapper {
return $items;
}
-
+
/**
* @brief Retrieve all the items corresponding to a feed from the database with a particular status
@@ -74,12 +74,12 @@ class ItemMapper {
* @param status one of the constants defined in OCA\News\StatusFlag
*/
public function findAllStatus($feedid, $status) {
- $stmt = \OCP\DB::prepare('SELECT * FROM ' . self::tableName . '
+ $stmt = \OCP\DB::prepare('SELECT * FROM ' . self::tableName . '
WHERE feed_id = ?
- AND ((status & ?) > 0)
+ AND ((status & ?) > 0)
ORDER BY pub_date DESC');
$result = $stmt->execute(array($feedid, $status));
-
+
$items = array();
while ($row = $result->fetchRow()) {
$item = $this->fromRow($row);
@@ -88,20 +88,20 @@ class ItemMapper {
return $items;
}
-
+
/*
* @brief Retrieve all the items from the database with a particular status
* @param status one of the constants defined in OCA\News\StatusFlag
*/
public function findEveryItemByStatus($status) {
- $stmt = \OCP\DB::prepare('SELECT ' . self::tableName . '.* FROM ' . self::tableName . '
+ $stmt = \OCP\DB::prepare('SELECT ' . self::tableName . '.* FROM ' . self::tableName . '
JOIN '. FeedMapper::tableName .' ON
'. FeedMapper::tableName .'.id = ' . self::tableName . '.feed_id
WHERE '. FeedMapper::tableName .'.user_id = ?
AND ((' . self::tableName . '.status & ?) > 0)
ORDER BY ' . self::tableName . '.pub_date DESC');
$result = $stmt->execute(array($this->userid, $status));
-
+
$items = array();
while ($row = $result->fetchRow()) {
$item = $this->fromRow($row);
@@ -112,19 +112,19 @@ class ItemMapper {
}
public function countAllStatus($feedid, $status) {
- $stmt = \OCP\DB::prepare('SELECT COUNT(*) as size FROM ' . self::tableName . '
+ $stmt = \OCP\DB::prepare('SELECT COUNT(*) as size FROM ' . self::tableName . '
WHERE feed_id = ?
AND ((status & ?) > 0)');
$result=$stmt->execute(array($feedid, $status))->fetchRow();
return $result['size'];
}
-
+
/**
* @brief Count all the items from the database with a particular status
* @param status one of the constants defined in OCA\News\StatusFlag
*/
public function countEveryItemByStatus($status) {
- $stmt = \OCP\DB::prepare('SELECT COUNT(*) as size FROM ' . self::tableName . '
+ $stmt = \OCP\DB::prepare('SELECT COUNT(*) as size FROM ' . self::tableName . '
JOIN '. FeedMapper::tableName .' ON
'. FeedMapper::tableName .'.id = ' . self::tableName . '.feed_id
WHERE '. FeedMapper::tableName .'.user_id = ?
@@ -136,7 +136,7 @@ class ItemMapper {
public function findIdFromGuid($guid_hash, $guid, $feedid) {
$stmt = \OCP\DB::prepare('
- SELECT * FROM ' . self::tableName . '
+ SELECT * FROM ' . self::tableName . '
WHERE guid_hash = ?
AND feed_id = ?
');
@@ -155,25 +155,25 @@ class ItemMapper {
* @returns The item whose status has changed.
*/
public function update(Item $item) {
-
+
$itemid = $item->getId();
$status = $item->getStatus();
-
+
$stmt = \OCP\DB::prepare('
UPDATE ' . self::tableName .
' SET status = ?
WHERE id = ?
');
-
+
$params=array(
$status,
$itemid
);
$stmt->execute($params);
-
+
return true;
}
-
+
/**
* @brief Save the feed and all its items into the database
* @returns The id of the feed in the database table.
@@ -181,11 +181,11 @@ class ItemMapper {
public function save(Item $item, $feedid) {
$guid = $item->getGuid();
$guid_hash = md5($guid);
-
+
$status = $item->getStatus();
$itemid = $this->findIdFromGuid($guid_hash, $guid, $feedid);
-
+
if ($itemid == null) {
$title = $item->getTitle();
$body = $item->getBody();
@@ -206,9 +206,9 @@ class ItemMapper {
$l = \OC_L10N::get('news');
$body = $l->t('no body');
}
-
+
$pub_date = Utils::unixtimeToDbtimestamp($item->getDate());
-
+
$params=array(
$item->getUrl(),
$title,
@@ -220,9 +220,9 @@ class ItemMapper {
$feedid,
$status
);
-
+
$stmt->execute($params);
-
+
$itemid = \OCP\DB::insertid(self::tableName);
}
else {
@@ -231,7 +231,7 @@ class ItemMapper {
$item->setId($itemid);
return $itemid;
}
-
+
/**
* @brief Retrieve an item from the database
* @param id The id of the feed in the database table.
@@ -242,16 +242,16 @@ class ItemMapper {
$row = $result->fetchRow();
$item = $this->fromRow($row);
-
+
return $item;
}
-
+
/**
* @brief Permanently delete all items belonging to a feed from the database
* @param feedid The id of the feed that we wish to delete
- * @return
+ * @return
*/
public function deleteAll($feedid) {
if ($feedid == null) {
@@ -260,7 +260,7 @@ class ItemMapper {
$stmt = \OCP\DB::prepare('DELETE FROM ' . self::tableName .' WHERE feed_id = ?');
$result = $stmt->execute(array($feedid));
-
+
return $result;
}
} \ No newline at end of file