mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
fix: SA: Fix many critical rules.
SA stands for Static Analysis.
This commit is contained in:
@@ -1,22 +1,6 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
* Copyright (C) 2015 Champs Libres <info@champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\ReportBundle\Timeline;
|
||||
|
||||
@@ -38,38 +22,39 @@ use Chill\MainBundle\Timeline\TimelineSingleQuery;
|
||||
*/
|
||||
class TimelineReportProvider implements TimelineProviderInterface
|
||||
{
|
||||
|
||||
|
||||
protected EntityManager $em;
|
||||
|
||||
|
||||
protected AuthorizationHelper $helper;
|
||||
|
||||
|
||||
protected CustomFieldsHelper $customFieldsHelper;
|
||||
|
||||
protected $showEmptyValues;
|
||||
|
||||
|
||||
protected bool $showEmptyValues;
|
||||
|
||||
private Security $security;
|
||||
|
||||
public function __construct(
|
||||
EntityManager $em,
|
||||
AuthorizationHelper $helper,
|
||||
Security $security,
|
||||
CustomFieldsHelper $customFieldsHelper,
|
||||
$showEmptyValues
|
||||
)
|
||||
{
|
||||
) {
|
||||
$this->em = $em;
|
||||
$this->helper = $helper;
|
||||
$this->security = $security;
|
||||
$this->customFieldsHelper = $customFieldsHelper;
|
||||
$this->showEmptyValues = $showEmptyValues;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function fetchQuery($context, array $args)
|
||||
{
|
||||
$this->checkContext($context);
|
||||
|
||||
|
||||
$report = $this->em->getClassMetadata(Report::class);
|
||||
[$where, $parameters] = $this->getWhereClause($context, $args);
|
||||
|
||||
@@ -84,7 +69,7 @@ class TimelineReportProvider implements TimelineProviderInterface
|
||||
'parameters' => $parameters
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
private function getWhereClause(string $context, array $args): array
|
||||
{
|
||||
switch ($context) {
|
||||
@@ -102,7 +87,7 @@ class TimelineReportProvider implements TimelineProviderInterface
|
||||
$report = $this->em->getClassMetadata(Report::class);
|
||||
$person = $this->em->getClassMetadata(Person::class);
|
||||
$role = new Role('CHILL_REPORT_SEE');
|
||||
$reachableCenters = $this->helper->getReachableCenters($this->security->getUser(),
|
||||
$reachableCenters = $this->helper->getReachableCenters($this->security->getUser(),
|
||||
$role);
|
||||
$reportPersonId = $report->getAssociationMapping('person')['joinColumns'][0]['name'];
|
||||
$reportScopeId = $report->getAssociationMapping('scope')['joinColumns'][0]['name'];
|
||||
@@ -123,13 +108,13 @@ class TimelineReportProvider implements TimelineProviderInterface
|
||||
}
|
||||
|
||||
// add the center id to the parameters
|
||||
$parameters[] = $center->getId();
|
||||
$parameters[] = $center->getId();
|
||||
// loop over scopes
|
||||
$scopeIds = [];
|
||||
foreach ($this->helper->getReachableScopes($this->security->getUser(),
|
||||
foreach ($this->helper->getReachableScopes($this->security->getUser(),
|
||||
$role, $center) as $scope) {
|
||||
if (\in_array($scope->getId(), $scopeIds)) {
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
$scopeIds[] = $scope->getId();
|
||||
}
|
||||
@@ -173,7 +158,7 @@ class TimelineReportProvider implements TimelineProviderInterface
|
||||
// this is the final clause that we are going to fill
|
||||
$clause = "{report}.{person_id} = ? AND {report}.{scopes_id} IN ({scopes_ids})";
|
||||
// iterate over reachable scopes
|
||||
$scopes = $this->helper->getReachableScopes($this->security->getUser(), $role,
|
||||
$scopes = $this->helper->getReachableScopes($this->security->getUser(), $role,
|
||||
$args['person']->getCenter());
|
||||
|
||||
foreach ($scopes as $scope) {
|
||||
@@ -194,16 +179,16 @@ class TimelineReportProvider implements TimelineProviderInterface
|
||||
$clause,
|
||||
[
|
||||
'{report}' => $report->getTableName(),
|
||||
'{person_id}' => $reportPersonId,
|
||||
'{person_id}' => $reportPersonId,
|
||||
'{scopes_id}' => $reportScopeId,
|
||||
'{scopes_ids}' => \implode(', ',
|
||||
'{scopes_ids}' => \implode(', ',
|
||||
\array_fill(0, \count($parameters)-1, '?'))
|
||||
]
|
||||
),
|
||||
$parameters
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
private function getFromClause(string $context): string
|
||||
{
|
||||
$report = $this->em->getClassMetadata(Report::class);
|
||||
@@ -229,30 +214,30 @@ class TimelineReportProvider implements TimelineProviderInterface
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getEntities(array $ids)
|
||||
{
|
||||
$reports = $this->em->getRepository('ChillReportBundle:Report')
|
||||
->findBy(array('id' => $ids));
|
||||
|
||||
|
||||
$result = array();
|
||||
foreach($reports as $report) {
|
||||
$result[$report->getId()] = $report;
|
||||
}
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getEntityTemplate($entity, $context, array $args)
|
||||
{
|
||||
$this->checkContext($context);
|
||||
|
||||
|
||||
return array(
|
||||
'template' => 'ChillReportBundle:Timeline:report.html.twig',
|
||||
'template_data' => array(
|
||||
@@ -262,19 +247,19 @@ class TimelineReportProvider implements TimelineProviderInterface
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
protected function getFieldsToRender(Report $entity, $context, array $args = array())
|
||||
{
|
||||
//gather all custom fields which should appears in summary
|
||||
$gatheredFields = array();
|
||||
|
||||
|
||||
if (array_key_exists('summary_fields', $entity->getCFGroup()->getOptions())) {
|
||||
// keep in memory title
|
||||
$title = null;
|
||||
$subtitle = null;
|
||||
|
||||
|
||||
foreach ($entity->getCFGroup()->getCustomFields() as $customField) {
|
||||
if (in_array($customField->getSlug(),
|
||||
if (in_array($customField->getSlug(),
|
||||
$entity->getCFGroup()->getOptions()['summary_fields'])) {
|
||||
// if we do not want to show empty values
|
||||
if ($this->showEmptyValues === false) {
|
||||
@@ -304,23 +289,23 @@ class TimelineReportProvider implements TimelineProviderInterface
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $gatheredFields;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function supportsType($type)
|
||||
{
|
||||
return $type === 'report';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* check if the context is supported
|
||||
*
|
||||
*
|
||||
* @param string $context
|
||||
* @throws \LogicException if the context is not supported
|
||||
*/
|
||||
|
Reference in New Issue
Block a user