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