Skip to content

Commit

Permalink
update contact repository
Browse files Browse the repository at this point in the history
  • Loading branch information
KaydenLiss committed Aug 9, 2023
1 parent 7571733 commit fa19ef2
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 52 deletions.
4 changes: 2 additions & 2 deletions src/Controller/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function dashboard(Request $request,
$av = $transferRepository->findActiveOrderProcessingsByTeamPath($teamPath);
$processes = $processRepository->findActiveByTeam($currentTeam);
$vvtDsfa = $impactAssessmentRepository->findActiveByTeam($currentTeam);
$kontakte = $contactRepository->findActiveByTeamPath($teamPath);
$contacts = $contactRepository->findActiveByTeam($currentTeam);
$tom = $tomRepository->findActiveByTeam($currentTeam);
$forms = $formRepository->findPublicByTeam($currentTeam);
$policies = $policyRepository->findPublicByTeam($currentTeam);
Expand All @@ -111,7 +111,7 @@ public function dashboard(Request $request,
'daten' => $daten,
'vvt' => $processes,
'dsfa' => $vvtDsfa,
'kontakte' => $kontakte,
'kontakte' => $contacts,
'kAudit' => $kritischeAudits,
'kVvt' => $criticalProcesses,
'openDsfa' => $openDsfa,
Expand Down
9 changes: 4 additions & 5 deletions src/Controller/KontaktController.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,10 @@ public function editKontakt(
'form' => $form->createView(),
'kontakt' => $kontakt,
'errors' => $errors,
'title' => $this->translator->trans(id: 'contact.create', domain: 'kontakt'),
'title' => $this->translator->trans(id: 'contact.edit', domain: 'kontakt'),
'snack' => $request->get('snack'),
'isEditable' => $isEditable,
'currentTeam' => $team,
]);
}

Expand All @@ -167,19 +168,17 @@ public function index(
SecurityService $securityService,
CurrentTeamService $currentTeamService,
KontakteRepository $contactRepository,
TeamRepository $teamRepository,
): Response
{
$team = $currentTeamService->getCurrentTeam($this->getUser());
if ($securityService->teamCheck($team) === false) {
return $this->redirectToRoute('dashboard');
}

$teamPath = $teamRepository->getPath($team);
$kontakte = $contactRepository->findActiveByTeamPath($teamPath);
$contacts = $contactRepository->findAllByTeam($team);

return $this->render('kontakt/index.html.twig', [
'kontakte' => $kontakte,
'kontakte' => $contacts,
'title' => $this->translator->trans(id: 'contact', domain: 'general'),
'currentTeam' => $team,
]);
Expand Down
103 changes: 65 additions & 38 deletions src/Repository/KontakteRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace App\Repository;

use App\Entity\Kontakte;
use App\Entity\Team;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\QueryBuilder;
use Doctrine\Persistence\ManagerRegistry;

/**
Expand All @@ -14,59 +16,84 @@
*/
class KontakteRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
public function __construct(
ManagerRegistry $registry,
private readonly TeamRepository $teamRepository,
)
{
parent::__construct($registry, Kontakte::class);
}

// /**
// * @return Kontakte[] Returns an array of Kontakte objects
// */
/*
public function findByExampleField($value)
public function findActiveByTeam(Team $team)
{
return $this->createQueryBuilder('k')
->andWhere('k.exampleField = :val')
->setParameter('val', $value)
->orderBy('k.id', 'ASC')
->setMaxResults(10)
->getQuery()
->getResult()
;
$queryBuilder = $this->getBaseQueryBuilder();
$this->filterByTeam(queryBuilder: $queryBuilder, team: $team);
return $queryBuilder->getQuery()->getResult();
}
*/

/*
public function findOneBySomeField($value): ?Kontakte
public function findAllByTeam(Team $team)
{
return $this->createQueryBuilder('k')
->andWhere('k.exampleField = :val')
->setParameter('val', $value)
->getQuery()
->getOneOrNullResult()
;
$queryBuilder = $this->getBaseQueryBuilder();
$this->filterByTeam(queryBuilder: $queryBuilder, team: $team, all: true);
return $queryBuilder->getQuery()->getResult();
}

public function findIsInheritedById(string $id) : bool
{
$queryBuilder = $this->getBaseQueryBuilder();
$this->filterById(queryBuilder: $queryBuilder, id: $id);
$this->filterByInherited(queryBuilder: $queryBuilder);
$result = $queryBuilder->getQuery()->getResult();
return count($result) > 0;
}
*/

public function findActiveByTeam($value)
public function findIsUsedByTeamAndId(Team $team, string $id) : bool
{
return $this->createQueryBuilder('a')
->andWhere('a.team = :val')
->andWhere('a.activ = 1')
->setParameter('val', $value)
->getQuery()
->getResult()
$queryBuilder = $this->getBaseQueryBuilder();
$this->filterByTeam(queryBuilder: $queryBuilder, team: $team);
$this->filterById(queryBuilder: $queryBuilder, id: $id);
$result = $queryBuilder->getQuery()->getResult();
return count($result) > 0;
}

private function getBaseQueryBuilder() :QueryBuilder
{
return $this->createQueryBuilder('c')
->leftJoin('c.datenweitergaben', 'dw')
->leftJoin('dw.verfahren', 'process')
->andWhere('c.activ = 1')
;
}

public function findActiveByTeamPath(array $teamPath)
private function filterByTeam(QueryBuilder $queryBuilder, Team $team, bool $all = false) :void
{
return $this->createQueryBuilder('a')
->andWhere('a.team IN (:teamPath)')
->andWhere('a.activ = 1')
$teamPath = $this->teamRepository->getPath($team);
$queryBuilder
->andWhere('c.team = :team OR (process.activ = 1 AND process.inherited = 1 AND process.team IN (:teamPath))')
->setParameter('teamPath', $teamPath)
->getQuery()
->getResult()
;
->setParameter('team', $team)
;

if (!$all) {
$ignored = $team->getIgnoredInheritances();
if (count($ignored)) {
$queryBuilder
->andWhere('process NOT IN (:ignored) OR c.team = :team')
->setParameter('ignored', $ignored);
}
}
}

private function filterById(QueryBuilder $queryBuilder, string $id) :void
{
$queryBuilder
->andWhere('c.id = :id')
->setParameter('id', $id);
}

private function filterByInherited(QueryBuilder $queryBuilder) :void
{
$queryBuilder
->andWhere('process.activ = 1 AND process.inherited = 1');
}
}
2 changes: 1 addition & 1 deletion src/Repository/PoliciesRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private function getBaseQueryBuilder(Team $team) :QueryBuilder

return $this->createQueryBuilder('a')
->innerJoin('a.processes', 'process')
->andWhere('a.team = :team OR (process.team = :team OR process.inherited = 1) AND process.activ = 1 AND process.team IN (:teamPath)')
->andWhere('a.team = :team OR process.inherited = 1 AND process.activ = 1 AND process.team IN (:teamPath)')
->andWhere('a.activ = 1')
->setParameter('teamPath', $teamPath)
->setParameter('team', $team)
Expand Down
2 changes: 1 addition & 1 deletion src/Repository/TomRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private function getBaseQueryBuilder(Team $team) :QueryBuilder

return $this->createQueryBuilder('a')
->innerJoin('a.vvts', 'process')
->andWhere('a.team = :team OR (process.team = :team OR process.inherited = 1) AND process.activ = 1 AND process.team IN (:teamPath)')
->andWhere('a.team = :team OR process.inherited = 1 AND process.activ = 1 AND process.team IN (:teamPath)')
->andWhere('a.activ = 1')
->setParameter('teamPath', $teamPath)
->setParameter('team', $team)
Expand Down
10 changes: 5 additions & 5 deletions src/Service/InheritanceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
use App\Entity\Software;
use App\Entity\Team;
use App\Entity\Tom;
use App\Repository\KontakteRepository;
use App\Repository\SoftwareRepository;
use Doctrine\Common\Collections\Collection;

class InheritanceService
{
public function __construct(
private readonly SoftwareRepository $softwareRepository
private readonly SoftwareRepository $softwareRepository,
private readonly KontakteRepository $contactRepository,
)
{

Expand Down Expand Up @@ -51,14 +53,12 @@ public function checkTeamUsesPolicy(Team $team, Policies $policy): bool

public function checkContactIsInherited(Kontakte $contact): bool
{
// TODO: implement
return true;
return $this->contactRepository->findIsInheritedById($contact->getId());
}

public function checkTeamUsesContact(Team $team, Kontakte $contact): bool
{
// TODO: implement
return true;
return $this->contactRepository->findIsUsedByTeamAndId($team, $contact->getId());
}

public function checkTransferIsInherited(Datenweitergabe $transfer): bool
Expand Down
4 changes: 4 additions & 0 deletions templates/kontakt/edit.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

<h2 class="h2-responsive">{{ title }}</h2>
{{ include('base/__approvedBy.html.twig', {'data':kontakt}) }}
{% set inherited = contactInherited(kontakt) %}
{% set used = teamUsesContact(currentTeam, kontakt) %}
{% include 'base/__inheritanceInfo.html.twig' with {team:kontakt.team, currentTeam:currentTeam, used:used, inherited:inherited} %}
{% include 'base/__flashMessage.html.twig' with {app:app} %}

<div class="card card-body {% if kontakt.approved or not kontakt.activ == 1 %}disabled{% endif %}">
{{ form_start(form) }}
Expand Down
1 change: 1 addition & 0 deletions translations/kontakt/kontakt.de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ client: Auftraggeber
contractor: Auftragnehmer
contact:
create: Kontakt erstellen
edit: Kontakt bearbeiten

0 comments on commit fa19ef2

Please sign in to comment.