Skip to content

Commit

Permalink
Merge pull request #95 from digio-ch/issue/hc-235
Browse files Browse the repository at this point in the history
WIP: All widgets without filter
  • Loading branch information
SebastianStorz committed Sep 26, 2023
2 parents db9fdba + 42f6c00 commit 73d96d7
Show file tree
Hide file tree
Showing 33 changed files with 2,478 additions and 17 deletions.
5 changes: 5 additions & 0 deletions config/routes/app_routes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@ general:
resource: "apps/general.yml"
prefix: /general
name_prefix: general_

census:
resource: "apps/census.yml"
prefix: /census
name_prefix: census_
14 changes: 14 additions & 0 deletions config/routes/apps/census.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
preview:
path: /preview
methods: GET
controller: App\Controller\Api\Apps\CensusController::getPreview

getFilter:
path: /filter
methods: GET
controller: App\Controller\Api\Apps\CensusController:getFilterData

postFilter:
path: /filter
methods: POST
controller: App\Controller\Api\Apps\CensusController:postFilterData
21 changes: 21 additions & 0 deletions config/routes/apps/widgets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,24 @@ role_overview:
path: /role-overview
methods: GET
controller: App\Controller\Api\Apps\Widgets\RoleOverviewController:getRoleOverview

census_table:
path: /census-table
methods: GET
controller: App\Controller\Api\Apps\CensusController::getTableData

census_members:
path: /census-members
methods: GET
controller: App\Controller\Api\Apps\CensusController::getMembersData

census_development:
path: /census-development
methods: GET
controller: App\Controller\Api\Apps\CensusController::getDevelopmentData

census_treemap:
path: /census-treemap
methods: GET
controller: App\Controller\Api\Apps\CensusController::getTreemapData

87 changes: 84 additions & 3 deletions src/Command/FetchCensusCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,33 @@

namespace App\Command;

use App\Entity\Midata\CensusGroup;
use App\Model\CommandStatistics;
use App\Repository\Midata\CensusGroupRepository;
use App\Repository\Midata\GroupTypeRepository;
use App\Service\CensusAPIService;
use App\Service\GroupStructureAPIService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

class FetchCensusCommand extends StatisticsCommand
{
protected GroupStructureAPIService $apiService;
protected CensusAPIService $apiService;
protected CensusGroupRepository $censusGroupRepository;
protected GroupTypeRepository $groupTypeRepository;

public function __construct()
{
private SymfonyStyle $io;

public function __construct(
CensusAPIService $apiService,
CensusGroupRepository $censusGroupRepository,
GroupTypeRepository $groupTypeRepository
) {
$this->apiService = $apiService;
$this->censusGroupRepository = $censusGroupRepository;
$this->groupTypeRepository = $groupTypeRepository;
parent::__construct();
}

Expand All @@ -21,6 +39,69 @@ public function configure()
->setDescription('Not implemented');
}

public function execute(InputInterface $input, OutputInterface $output)
{
$this->io = new SymfonyStyle($input, $output);

$year = (int) date('Y');
$minYear = $year - 6;
$groupsToAggregate = [];
// Fetch groups
while ($year > $minYear) {
$this->io->writeln('year ' . $year);
$rawCensusData = $this->apiService->getCensusData($year);
$rawCensusGroups = $rawCensusData->getContent()['census_evaluations']['groups'];
foreach ($rawCensusGroups as $rawCensusGroup) {
$exists = $this->censusGroupRepository->findOneBy(['group_id' => $rawCensusGroup['group_id'], 'year' => $year]);
if (is_null($exists)) {
$groupsToAggregate[] = $rawCensusGroup['group_id'];
$this->mapRawCensusGroupToCensusGroup($rawCensusGroup, $year);
}
}
$year--;
}
// Aggregate Groups
foreach (array_unique($groupsToAggregate) as $groupId) {
}
return Command::SUCCESS;
}

private function mapRawCensusGroupToCensusGroup(array $rawCensusGroup, int $year)
{
$censusGroup = new CensusGroup();
$censusGroup->setGroupId($this->sanitizeValue($rawCensusGroup['group_id']));
$censusGroup->setYear($year);
$censusGroup->setGroupType($this->groupTypeRepository->findOneBy(['groupType' => $rawCensusGroup['group_type']]));
$censusGroup->setName($rawCensusGroup['group_name']);

$censusGroup->setTotalCount($this->sanitizeValue($rawCensusGroup['total']['total']));
$censusGroup->setTotalFCount($this->sanitizeValue($rawCensusGroup['total']['f']));
$censusGroup->setTotalMCount($this->sanitizeValue($rawCensusGroup['total']['m']));

$censusGroup->setLeiterFCount($this->sanitizeValue($rawCensusGroup['f']['leiter']));
$censusGroup->setBiberFCount($this->sanitizeValue($rawCensusGroup['f']['biber']));
$censusGroup->setWoelfeFCount($this->sanitizeValue($rawCensusGroup['f']['woelfe']));
$censusGroup->setPfadisFCount($this->sanitizeValue($rawCensusGroup['f']['pfadis']));
$censusGroup->setPiosFCount($this->sanitizeValue($rawCensusGroup['f']['pios']));
$censusGroup->setRoverFCount($this->sanitizeValue($rawCensusGroup['f']['rover']));
$censusGroup->setPtaFCount($this->sanitizeValue($rawCensusGroup['f']['pta']));

$censusGroup->setLeiterMCount($this->sanitizeValue($rawCensusGroup['m']['leiter']));
$censusGroup->setBiberMCount($this->sanitizeValue($rawCensusGroup['m']['biber']));
$censusGroup->setWoelfeMCount($this->sanitizeValue($rawCensusGroup['m']['woelfe']));
$censusGroup->setPfadisMCount($this->sanitizeValue($rawCensusGroup['m']['pfadis']));
$censusGroup->setPiosMCount($this->sanitizeValue($rawCensusGroup['m']['pios']));
$censusGroup->setRoverMCount($this->sanitizeValue($rawCensusGroup['m']['rover']));
$censusGroup->setPtaMCount($this->sanitizeValue($rawCensusGroup['m']['pta']));
$this->censusGroupRepository->add($censusGroup);
}

private function sanitizeValue($raw): int
{
return is_null($raw) ? 0 : $raw;
}


// TODO: Implement the statistics
public function getStats(): CommandStatistics
{
Expand Down
17 changes: 16 additions & 1 deletion src/Command/ImportFromJsonCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,22 @@ private function importGroups(OutputInterface $output)
$group->setId($gr['id']);
$metadata = $this->em->getClassMetaData(get_class($group));
$metadata->setIdGenerator(new AssignedGenerator());
$createGroupSettings = true;

/** @var GroupType $gt */
$gt = $this->em->getRepository(GroupType::class)->findOneBy(['groupType' => $gr['type']]);
$group->setGroupType($gt);

// create group settings
$groupSettings = new GroupSettings();
$groupSettings->setGroup($group);
if ($group->getGroupType()->getGroupType() === GroupType::DEPARTMENT) {
$groupSettings->setRoleOverviewFilter(GroupSettings::DEFAULT_DEPARMENT_ROLES);
} elseif ($group->getGroupType()->getGroupType() === GroupType::REGION) {
$groupSettings->setRoleOverviewFilter(GroupSettings::DEFAULT_REGION_ROLES);
} elseif ($group->getGroupType()->getGroupType() === GroupType::CANTON) {
$groupSettings->setRoleOverviewFilter(GroupSettings::DEFAULT_CANTONAL_ROLES);
}
$this->em->persist($groupSettings);
}

$group->setName(trim($gr['name']));
Expand Down
105 changes: 105 additions & 0 deletions src/Controller/Api/Apps/CensusController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php

namespace App\Controller\Api\Apps;

use App\DTO\Model\FilterRequestData\CensusRequestData;
use App\Entity\Midata\Group;
use App\Service\DataProvider\CensusDataProvider;
use App\Service\DataProvider\CensusFilterDataProvider;
use App\Service\Security\PermissionVoter;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Component\HttpFoundation\JsonResponse;

class CensusController extends AbstractController
{
private CensusDataProvider $censusDataProvider;
private CensusFilterDataProvider $censusFilterDataProvider;

public function __construct(
CensusDataProvider $censusDataProvider,
CensusFilterDataProvider $censusFilterDataProvider
) {
$this->censusDataProvider = $censusDataProvider;
$this->censusFilterDataProvider = $censusFilterDataProvider;
}

/**
* @param Group $group
* @return JsonResponse
*
* @ParamConverter("group", options={"mapping": {"groupId": "id"}})
*/
public function getPreview(Group $group)
{
$this->denyAccessUnlessGranted(PermissionVoter::VIEWER, $group);
return $this->json($this->censusDataProvider->getPreviewData($group));
}

/**
* @param Group $group
* @return JsonResponse
*
* @ParamConverter("group", options={"mapping": {"groupId": "id"}})
*/
public function getTableData(Group $group, CensusRequestData $censusRequestData)
{
$this->denyAccessUnlessGranted(PermissionVoter::VIEWER, $group);
return $this->json($this->censusDataProvider->getTableData($group, $censusRequestData));
}

/**
* @param Group $group
* @return JsonResponse
*
* @ParamConverter("group", options={"mapping": {"groupId": "id"}})
*/
public function getDevelopmentData(Group $group, CensusRequestData $censusRequestData)
{
$this->denyAccessUnlessGranted(PermissionVoter::VIEWER, $group);
return $this->json($this->censusDataProvider->getDevelopmentData($group, $censusRequestData));
}


/**
* @param Group $group
* @return JsonResponse
*
* @ParamConverter("group", options={"mapping": {"groupId": "id"}})
*/
public function getMembersData(Group $group, CensusRequestData $censusRequestData)
{
$this->denyAccessUnlessGranted(PermissionVoter::VIEWER, $group);
return $this->json($this->censusDataProvider->getMembersData($group, $censusRequestData));
}

/**
* @param Group $group
* @return JsonResponse
*
* @ParamConverter("group", options={"mapping": {"groupId": "id"}})
*/
public function getTreemapData(Group $group, CensusRequestData $censusRequestData)
{
$this->denyAccessUnlessGranted(PermissionVoter::VIEWER, $group);
return $this->json($this->censusDataProvider->getTreemapData($group, $censusRequestData));
}

/**
* @param Group $group
* @return JsonResponse
*
* @ParamConverter("group", options={"mapping": {"groupId": "id"}})
*/
public function getFilterData(Group $group)
{
$this->denyAccessUnlessGranted(PermissionVoter::VIEWER, $group);
return $this->json($this->censusFilterDataProvider->getFilterData($group));
}

public function postFilterData(Group $group, CensusRequestData $censusRequestData)
{
$this->denyAccessUnlessGranted(PermissionVoter::VIEWER, $group);
return $this->json($this->censusFilterDataProvider->setFilterData($group, $censusRequestData));
}
}
18 changes: 18 additions & 0 deletions src/Controller/Api/Apps/Widgets/FilterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,22 @@ public function getFilterData(

return $this->json($data);
}

/**
* @param Request $request
* @param Group $group
* @param FilterDataProvider $filterDataProvider
* @return JsonResponse
*
* @ParamConverter("group", options={"mapping": {"groupId": "id"}})
*/
public function getGroupTypes(
Request $request,
Group $group,
FilterDataProvider $filterDataProvider
): JsonResponse {
$this->denyAccessUnlessGranted(PermissionVoter::VIEWER, $group);
$data = $filterDataProvider->getGroupTypes($group, $request->getLocale());
return $this->json($data);
}
}
2 changes: 1 addition & 1 deletion src/Controller/Api/InviteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function createInvite(
}

if ($inviteDTO->getPermissionType() === PermissionVoter::OWNER) {
throw new ApiException(Response::HTTP_FORBIDDEN,'You may not add group Owners.');
throw new ApiException(Response::HTTP_FORBIDDEN, 'You may not add group Owners.');
}

if ($this->inviteService->inviteExists($group, $inviteDTO->getEmail())) {
Expand Down
Loading

0 comments on commit 73d96d7

Please sign in to comment.