<?php

declare(strict_types=1);

namespace Medienreaktor\Courses\Domain\Repository;


use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
 * This file is part of the "Courses" Extension for TYPO3 CMS.
 *
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
 *
 * (c) 2023 Matthias Schieber <matthias.schieber@medienreaktor.de>, Medienreaktor
 */

/**
 * The repository for Professions
 */
class ProfessionRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
{
    /**
     * @param $id
     */
    public function findByImportId($id)
    {
        $query = $this->createQuery();
        $query->getQuerySettings()->setRespectStoragePage(false);
        $query->matching($query->equals("profession_id", $id));
        return $query->execute();
    }
    public function removeImportedEntities(): void
    {
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_courses_domain_model_profession');
        $affectedRows = $queryBuilder->delete('tx_courses_domain_model_profession')->executeStatement();
    }
    /**
     * @param $title
     */
    public function findByName(string $title)
    {
        $query = $this->createQuery();
        $query->getQuerySettings()->setRespectStoragePage(false);
        $query->matching($query->equals("title", $title));

        return $query->execute();
    }

}
