diff options
author | Sean Molenaar <sean@seanmolenaar.eu> | 2020-08-29 23:39:35 +0200 |
---|---|---|
committer | Benjamin Brahmer <info@b-brahmer.de> | 2020-09-27 15:35:31 +0200 |
commit | d00d1ab2a28f428223e52b17052c072c64784016 (patch) | |
tree | c019f85fb7ac67147dd43ca64b4ac3cda99832f7 /lib/Db/FolderMapperV2.php | |
parent | 5687baca75d47dbdffd3de74e865ad2f71ef0cb7 (diff) |
Create V2 mapper, Service and management commands
Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
Diffstat (limited to 'lib/Db/FolderMapperV2.php')
-rw-r--r-- | lib/Db/FolderMapperV2.php | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/lib/Db/FolderMapperV2.php b/lib/Db/FolderMapperV2.php new file mode 100644 index 000000000..d684e5af2 --- /dev/null +++ b/lib/Db/FolderMapperV2.php @@ -0,0 +1,87 @@ +<?php +/** + * Nextcloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Alessandro Cosentino <cosenal@gmail.com> + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright 2012 Alessandro Cosentino + * @copyright 2012-2014 Bernhard Posselt + */ + +namespace OCA\News\Db; + +use OCA\News\Utility\Time; +use OCP\AppFramework\Db\Entity; +use OCP\IDBConnection; + +/** + * Class FolderMapper + * + * @package OCA\News\Db + */ +class FolderMapperV2 extends NewsMapperV2 +{ + const TABLE_NAME = 'news_folders'; + + /** + * FolderMapper constructor. + * + * @param IDBConnection $db + * @param Time $time + */ + public function __construct(IDBConnection $db, Time $time) + { + parent::__construct($db, $time, Folder::class); + } + + /** + * Find all feeds for a user. + * + * @param string $userId The user identifier + * + * @return Entity[] + */ + public function findAllFromUser($userId): array + { + $builder = $this->db->getQueryBuilder(); + $builder->select('*') + ->from($this->tableName) + ->where('user_id = :user_id') + ->where('deleted_at = 0') + ->setParameter(':user_id', $userId); + + return $this->findEntities($builder); + } + + /** + * Find all items + * + * @return Entity[] + */ + public function findAll(): array + { + $builder = $this->db->getQueryBuilder(); + $builder->select('*') + ->from($this->tableName) + ->where('deleted_at = 0'); + + return $this->findEntities($builder); + } + + public function findFromUser(string $userId, int $id): Entity + { + $builder = $this->db->getQueryBuilder(); + $builder->select('*') + ->from($this->tableName) + ->where('user_id = :user_id') + ->where('id = :id') + ->where('deleted_at = 0') + ->setParameter(':user_id', $userId) + ->setParameter(':id', $id); + + return $this->findEntity($builder); + } +} |