2022-04-23 14:55:05 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace OCA\UPschooling\Db;
|
|
|
|
|
|
|
|
use Doctrine\DBAL\Types\Type;
|
|
|
|
use OCP\AppFramework\Db\DoesNotExistException;
|
|
|
|
use OCP\AppFramework\Db\Entity;
|
|
|
|
use OCP\AppFramework\Db\QBMapper;
|
|
|
|
use OCP\DB\QueryBuilder\IQueryBuilder;
|
|
|
|
use OCP\IDBConnection;
|
|
|
|
|
|
|
|
class ChatMapper extends QBMapper
|
|
|
|
{
|
|
|
|
public function __construct(IDBConnection $db)
|
|
|
|
{
|
|
|
|
parent::__construct($db, 'upschooling_chats', MatrixChat::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $ticketId
|
|
|
|
* @return array array of Entity|MatrixChat
|
|
|
|
*/
|
|
|
|
public function findForTicket(int $ticketId): array
|
|
|
|
{
|
|
|
|
/* @var $qb IQueryBuilder */
|
|
|
|
$qb = $this->db->getQueryBuilder();
|
|
|
|
$qb->select('*')
|
|
|
|
->from('upschooling_chats')
|
|
|
|
->where($qb->expr()->eq('ticket_id', $qb->createNamedParameter($ticketId, IQueryBuilder::PARAM_INT)));
|
|
|
|
return $this->findEntities($qb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $ticketId
|
|
|
|
* @return Entity|MatrixChat
|
|
|
|
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
|
|
|
|
* @throws DoesNotExistException
|
|
|
|
*/
|
|
|
|
public function findCurrent(int $ticketId): MatrixChat
|
|
|
|
{
|
|
|
|
/* @var $qb IQueryBuilder */
|
|
|
|
$qb = $this->db->getQueryBuilder();
|
|
|
|
$qb->select('*')
|
|
|
|
->from('upschooling_chats')
|
|
|
|
->where(
|
|
|
|
$qb->expr()->eq('ticket_id', $qb->createNamedParameter($ticketId, IQueryBuilder::PARAM_INT)),
|
2022-04-30 14:03:39 +00:00
|
|
|
$qb->expr()->isNull('date_end')
|
2022-04-23 14:55:05 +00:00
|
|
|
);
|
|
|
|
return $this->findEntity($qb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param \DateTime $dateTime
|
|
|
|
* @return mixed The database representation of the datetime with timezone.
|
|
|
|
* @throws \Doctrine\DBAL\Exception
|
|
|
|
* @throws \Doctrine\DBAL\Types\ConversionException
|
|
|
|
*/
|
|
|
|
public function convertDateTimeTz(\DateTime $dateTime)
|
|
|
|
{
|
|
|
|
$dateTimeTzType = Type::getType("datetimetz");
|
|
|
|
return $dateTimeTzType->convertToDatabaseValue($dateTime, $this->db->getDatabasePlatform());
|
|
|
|
}
|
|
|
|
}
|