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-09-18 17:28:10 +00:00
|
|
|
class TicketMapper extends QBMapper
|
|
|
|
{
|
|
|
|
public function __construct(IDBConnection $db)
|
|
|
|
{
|
|
|
|
parent::__construct($db, 'upschooling_tickets', MatrixTicket::class);
|
2021-08-21 14:17:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $id
|
|
|
|
* @param string $userId
|
2021-09-18 17:28:10 +00:00
|
|
|
* @return Entity|MatrixTicket
|
2021-08-21 14:17:14 +00:00
|
|
|
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
|
|
|
|
* @throws DoesNotExistException
|
|
|
|
*/
|
2021-09-19 14:55:30 +00:00
|
|
|
public function find(int $id, MatrixUser $matrixUser): MatrixTicket
|
2021-09-18 17:28:10 +00:00
|
|
|
{
|
2021-08-21 14:17:14 +00:00
|
|
|
/* @var $qb IQueryBuilder */
|
|
|
|
$qb = $this->db->getQueryBuilder();
|
|
|
|
$qb->select('*')
|
2021-09-19 14:55:30 +00:00
|
|
|
->from('upschooling_tickets')
|
2021-08-21 14:17:14 +00:00
|
|
|
->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']));
|
2021-08-21 14:17:14 +00:00
|
|
|
return $this->findEntity($qb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $userId
|
|
|
|
* @return array
|
|
|
|
*/
|
2021-09-19 14:55:30 +00:00
|
|
|
public function findAll(MatrixUser $matrixUser): array
|
2021-09-18 17:28:10 +00:00
|
|
|
{
|
2021-08-21 14:17:14 +00:00
|
|
|
/* @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']));
|
2021-08-21 14:17:14 +00:00
|
|
|
return $this->findEntities($qb);
|
|
|
|
}
|
|
|
|
}
|