62 lines
1.6 KiB
PHP
62 lines
1.6 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
|
|
* @param string $userId
|
|
* @return Entity|MatrixTicket
|
|
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
|
|
* @throws DoesNotExistException
|
|
*/
|
|
public function find(int $id, string $userId): MatrixTicket
|
|
{
|
|
/* @var $qb IQueryBuilder */
|
|
$qb = $this->db->getQueryBuilder();
|
|
$qb->select('*')
|
|
->from('upschooling_tickets', 't')
|
|
->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)))
|
|
->innerJoin(
|
|
't',
|
|
'upschooling_users',
|
|
'u',
|
|
$qb->expr()->in('u.matrix_user', ['t.matrix_assisted_user', 't.matrix_helper_user'])
|
|
)
|
|
->andWhere($qb->expr()->eq('u.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('*')
|
|
->from('upschooling_users', 'u')
|
|
->where($qb->expr()->eq('u.user_id', $qb->createNamedParameter($userId)))
|
|
->innerJoin(
|
|
'u',
|
|
'upschooling_tickets',
|
|
't',
|
|
$qb->expr()->in('u.matrix_user', ['t.matrix_assisted_user', 't.matrix_helper_user'])
|
|
);
|
|
return $this->findEntities($qb);
|
|
}
|
|
}
|