1
0
Fork 0
nc_ext_dav_push/lib/Db/SubscriptionMapper.php

65 lines
1.7 KiB
PHP
Raw Permalink Normal View History

2024-06-12 01:50:04 +02:00
<?php
namespace OCA\DavPush\Db;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\Entity;
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
class SubscriptionMapper extends QBMapper {
public const TABLENAME = 'dav_push_subscriptions';
public function __construct(IDBConnection $db) {
parent::__construct($db, self::TABLENAME, Subscription::class);
}
/**
* @param string $userId
* @param string $id
* @return Entity|Subscription
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
* @throws DoesNotExistException
*/
public function find(string $userId, int $id): Subscription {
/* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from(self::TABLENAME)
->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)))
->andWhere($qb->expr()->eq('user_id', $qb->createNamedParameter($userId)));
return $this->findEntity($qb);
}
2024-06-12 03:05:59 +02:00
/**
* @param string $collectionName
* @return Subscription[]
*/
2024-06-12 14:19:52 +02:00
public function findAll(string $collectionName): array {
/* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from(self::TABLENAME)
->where($qb->expr()->eq('collection_name', $qb->createNamedParameter($collectionName)));
return $this->findEntities($qb);
}
/**
* @param string $userId
* @return Subscription[]
*/
public function findAllByUser(string $userId): array {
2024-06-12 03:05:59 +02:00
/* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from(self::TABLENAME)
2024-06-12 14:19:52 +02:00
->where($qb->expr()->eq('user_id', $qb->createNamedParameter($userId)));
2024-06-12 03:05:59 +02:00
return $this->findEntities($qb);
}
2024-06-12 01:50:04 +02:00
}