*/ class WikiRootBotMapper extends QBMapper { public function __construct(IDBConnection $db) { parent::__construct($db, 'educai_wiki_root_bots', WikiRootBot::class); } public function findByBotId(int $botId): ?WikiRootBot { $qb = $this->db->getQueryBuilder(); $qb->select('*') ->from($this->getTableName()) ->where($qb->expr()->eq('bot_id', $qb->createNamedParameter($botId, IQueryBuilder::PARAM_INT))) ->setMaxResults(1); try { return $this->findEntity($qb); } catch (DoesNotExistException $e) { return null; } } /** * @return array */ public function findAllActive(): array { $qb = $this->db->getQueryBuilder(); $qb->select('*') ->from($this->getTableName()) ->where($qb->expr()->eq('active', $qb->createNamedParameter(true, IQueryBuilder::PARAM_BOOL))); return $this->findEntities($qb); } public function deactivateByBotId(int $botId): void { $qb = $this->db->getQueryBuilder(); $qb->update($this->getTableName()) ->set('active', $qb->createNamedParameter(false, IQueryBuilder::PARAM_BOOL)) ->set('updated_at', $qb->createNamedParameter(time(), IQueryBuilder::PARAM_INT)) ->where($qb->expr()->eq('bot_id', $qb->createNamedParameter($botId, IQueryBuilder::PARAM_INT))); $qb->executeStatement(); } }