Nextcloud-App/lib/Db/TicketMapper.php

50 lines
1.3 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;
class TicketMapper extends QBMapper
{
public function __construct(IDBConnection $db)
{
parent::__construct($db, 'upschooling_tickets', MatrixTicket::class);
}
/**
* @param int $id
* @param string $userId
* @return Entity|MatrixTicket
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
* @throws DoesNotExistException
*/
2021-09-19 14:55:30 +00:00
public function find(int $id, MatrixUser $matrixUser): MatrixTicket
{
/* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder();
$qb->select('*')
2021-09-19 14:55:30 +00:00
->from('upschooling_tickets')
->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)))
2021-09-19 14:55:30 +00:00
->andWhere($qb->expr()->in($matrixUser->getMatrixUser(), ['matrix_assisted_user', 'matrix_helper_user']));
return $this->findEntity($qb);
}
/**
* @param string $userId
* @return array
*/
2021-09-19 14:55:30 +00:00
public function findAll(MatrixUser $matrixUser): array
{
/* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder();
$qb->select('*')
2021-09-19 14:55:30 +00:00
->from('upschooling_tickets')
->where($qb->expr()->in($matrixUser->getMatrixUser(), ['matrix_assisted_user', 'matrix_helper_user']));
return $this->findEntities($qb);
}
}