76 lines
2.2 KiB
PHP
76 lines
2.2 KiB
PHP
<?php
|
|
|
|
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
|
|
* @return Entity|MatrixTicket
|
|
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
|
|
* @throws DoesNotExistException
|
|
*/
|
|
public function findTicket(int $id): MatrixTicket
|
|
{
|
|
/* @var $qb IQueryBuilder */
|
|
$qb = $this->db->getQueryBuilder();
|
|
$qb->select('*')
|
|
->from('upschooling_tickets')
|
|
->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
|
|
return $this->findEntity($qb);
|
|
}
|
|
|
|
/**
|
|
* @param int $id
|
|
* @param string $userId
|
|
* @return Entity|MatrixTicket
|
|
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
|
|
* @throws DoesNotExistException
|
|
*/
|
|
public function findForUser(int $id, MatrixUser $matrixUser): MatrixTicket
|
|
{
|
|
/* @var $qb IQueryBuilder */
|
|
$qb = $this->db->getQueryBuilder();
|
|
$qb->select('*')
|
|
->from('upschooling_tickets')
|
|
->where(
|
|
$qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)),
|
|
$qb->expr()->orX(
|
|
$qb->expr()->eq('matrix_assisted_user', $qb->createNamedParameter($matrixUser->getMatrixUser(), IQueryBuilder::PARAM_STR)),
|
|
$qb->expr()->eq('matrix_helper_user', $qb->createNamedParameter($matrixUser->getMatrixUser(), IQueryBuilder::PARAM_STR))
|
|
)
|
|
);
|
|
return $this->findEntity($qb);
|
|
}
|
|
|
|
/**
|
|
* @param string $userId
|
|
* @return array
|
|
*/
|
|
public function findAllForUser(MatrixUser $matrixUser): array
|
|
{
|
|
/* @var $qb IQueryBuilder */
|
|
$qb = $this->db->getQueryBuilder();
|
|
$qb->select('*')
|
|
->from('upschooling_tickets')
|
|
->where(
|
|
$qb->expr()->orX(
|
|
$qb->expr()->eq('matrix_assisted_user', $qb->createNamedParameter($matrixUser->getMatrixUser(), IQueryBuilder::PARAM_STR)),
|
|
$qb->expr()->eq('matrix_helper_user', $qb->createNamedParameter($matrixUser->getMatrixUser(), IQueryBuilder::PARAM_STR))
|
|
)
|
|
);
|
|
return $this->findEntities($qb);
|
|
}
|
|
}
|