Nextcloud-App/lib/Db/TicketMapper.php

46 lines
1.2 KiB
PHP
Raw Normal View History

<?php
2021-08-21 14:25:23 +00:00
namespace OCA\UPschooling\Db;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\Entity;
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
2021-08-22 15:03:19 +00:00
class TicketMapper extends QBMapper {
public function __construct(IDBConnection $db) {
2021-08-22 15:03:19 +00:00
parent::__construct($db, 'upschooling', Ticket::class);
}
/**
* @param int $id
* @param string $userId
2021-08-22 15:03:19 +00:00
* @return Entity|Ticket
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
* @throws DoesNotExistException
*/
2021-08-22 15:03:19 +00:00
public function find(int $id, string $userId): Ticket {
/* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder();
$qb->select('*')
2021-08-21 14:25:23 +00:00
->from('upschooling')
->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)))
->andWhere($qb->expr()->eq('user_id', $qb->createNamedParameter($userId)));
return $this->findEntity($qb);
}
/**
* @param string $userId
* @return array
*/
public function findAll(string $userId): array {
/* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder();
$qb->select('*')
2021-08-21 14:25:23 +00:00
->from('upschooling')
->where($qb->expr()->eq('user_id', $qb->createNamedParameter($userId)));
return $this->findEntities($qb);
}
}