summaryrefslogtreecommitdiffstats
path: root/db/foldermapper.php
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-10-21 16:45:36 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-10-21 16:45:36 +0200
commit42d69a95f3276a2d6089ca68f635c4e2f6aa7a23 (patch)
tree6a17fd7998f291e6dec1d996c1e7c724b92b8e58 /db/foldermapper.php
parent0e6598b0734fb927109f745d9c0f3a8605a30ca5 (diff)
convert tabs indention to indention with 4 spaces because of mixing of both variants in code and better readability on github and websites because you cant set the indention width there and 8 spaces will be used for a tab
Diffstat (limited to 'db/foldermapper.php')
-rw-r--r--db/foldermapper.php168
1 files changed, 84 insertions, 84 deletions
diff --git a/db/foldermapper.php b/db/foldermapper.php
index 2c4d2aca5..bce599b45 100644
--- a/db/foldermapper.php
+++ b/db/foldermapper.php
@@ -18,90 +18,90 @@ use \OCP\AppFramework\Db\Entity;
class FolderMapper extends NewsMapper {
- public function __construct(IDb $db) {
- parent::__construct($db, 'news_folders', '\OCA\News\Db\Folder');
- }
-
- public function find($id, $userId){
- $sql = 'SELECT * FROM `*PREFIX*news_folders` ' .
- 'WHERE `id` = ? ' .
- 'AND `user_id` = ?';
-
- return $this->findEntity($sql, [$id, $userId]);
- }
-
-
- public function findAllFromUser($userId){
- $sql = 'SELECT * FROM `*PREFIX*news_folders` ' .
- 'WHERE `user_id` = ? ' .
- 'AND `deleted_at` = 0';
- $params = [$userId];
-
- return $this->findEntities($sql, $params);
- }
-
-
- public function findByName($folderName, $userId){
- $sql = 'SELECT * FROM `*PREFIX*news_folders` ' .
- 'WHERE `name` = ? ' .
- 'AND `user_id` = ?';
- $params = [$folderName, $userId];
-
- return $this->findEntities($sql, $params);
- }
-
-
- public function delete(Entity $entity){
- parent::delete($entity);
-
- // someone please slap me for doing this manually :P
- // we needz CASCADE + FKs please
- $sql = 'DELETE FROM `*PREFIX*news_feeds` WHERE `folder_id` = ?';
- $params = [$entity->getId()];
- $this->execute($sql, $params);
-
- $sql = 'DELETE FROM `*PREFIX*news_items` WHERE `feed_id` NOT IN '.
- '(SELECT `feeds`.`id` FROM `*PREFIX*news_feeds` `feeds`)';
-
- $this->execute($sql);
- }
-
-
- /**
- * @param int $deleteOlderThan if given gets all entries with a delete date
- * older than that timestamp
- * @param string $userId if given returns only entries from the given user
- * @return array with the database rows
- */
- public function getToDelete($deleteOlderThan=null, $userId=null) {
- $sql = 'SELECT * FROM `*PREFIX*news_folders` ' .
- 'WHERE `deleted_at` > 0 ';
- $params = [];
-
- // sometimes we want to delete all entries
- if ($deleteOlderThan !== null) {
- $sql .= 'AND `deleted_at` < ? ';
- $params[] = $deleteOlderThan;
- }
-
- // we need to sometimes only delete feeds of a user
- if($userId !== null) {
- $sql .= 'AND `user_id` = ?';
- $params[] = $userId;
- }
-
- return $this->findEntities($sql, $params);
- }
-
-
- /**
- * Deletes all folders of a user
- * @param string $userId the name of the user
- */
- public function deleteUser($userId) {
- $sql = 'DELETE FROM `*PREFIX*news_folders` WHERE `user_id` = ?';
- $this->execute($sql, [$userId]);
- }
+ public function __construct(IDb $db) {
+ parent::__construct($db, 'news_folders', '\OCA\News\Db\Folder');
+ }
+
+ public function find($id, $userId){
+ $sql = 'SELECT * FROM `*PREFIX*news_folders` ' .
+ 'WHERE `id` = ? ' .
+ 'AND `user_id` = ?';
+
+ return $this->findEntity($sql, [$id, $userId]);
+ }
+
+
+ public function findAllFromUser($userId){
+ $sql = 'SELECT * FROM `*PREFIX*news_folders` ' .
+ 'WHERE `user_id` = ? ' .
+ 'AND `deleted_at` = 0';
+ $params = [$userId];
+
+ return $this->findEntities($sql, $params);
+ }
+
+
+ public function findByName($folderName, $userId){
+ $sql = 'SELECT * FROM `*PREFIX*news_folders` ' .
+ 'WHERE `name` = ? ' .
+ 'AND `user_id` = ?';
+ $params = [$folderName, $userId];
+
+ return $this->findEntities($sql, $params);
+ }
+
+
+ public function delete(Entity $entity){
+ parent::delete($entity);
+
+ // someone please slap me for doing this manually :P
+ // we needz CASCADE + FKs please
+ $sql = 'DELETE FROM `*PREFIX*news_feeds` WHERE `folder_id` = ?';
+ $params = [$entity->getId()];
+ $this->execute($sql, $params);
+
+ $sql = 'DELETE FROM `*PREFIX*news_items` WHERE `feed_id` NOT IN '.
+ '(SELECT `feeds`.`id` FROM `*PREFIX*news_feeds` `feeds`)';
+
+ $this->execute($sql);
+ }
+
+
+ /**
+ * @param int $deleteOlderThan if given gets all entries with a delete date
+ * older than that timestamp
+ * @param string $userId if given returns only entries from the given user
+ * @return array with the database rows
+ */
+ public function getToDelete($deleteOlderThan=null, $userId=null) {
+ $sql = 'SELECT * FROM `*PREFIX*news_folders` ' .
+ 'WHERE `deleted_at` > 0 ';
+ $params = [];
+
+ // sometimes we want to delete all entries
+ if ($deleteOlderThan !== null) {
+ $sql .= 'AND `deleted_at` < ? ';
+ $params[] = $deleteOlderThan;
+ }
+
+ // we need to sometimes only delete feeds of a user
+ if($userId !== null) {
+ $sql .= 'AND `user_id` = ?';
+ $params[] = $userId;
+ }
+
+ return $this->findEntities($sql, $params);
+ }
+
+
+ /**
+ * Deletes all folders of a user
+ * @param string $userId the name of the user
+ */
+ public function deleteUser($userId) {
+ $sql = 'DELETE FROM `*PREFIX*news_folders` WHERE `user_id` = ?';
+ $this->execute($sql, [$userId]);
+ }
} \ No newline at end of file