Commit 14fa585b authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

- UP : La numérotation personnalisé a été ajoutée aux exports en mode PROJET,...

- UP : La numérotation personnalisé a été ajoutée aux exports en mode PROJET, attention, seul les numérotations configurées sont exportées
parent 9a971135
Loading
Loading
Loading
Loading
Loading
+34 −3
Changes for module/Oscar/src/Oscar/Formatter/ProjectToArrayFormatter.php: 34 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -13,12 +13,13 @@ class ProjectToArrayFormatter implements IProjectFormater
    private array $rolesPerson = [];
    private array $rolesOrganization = [];
    private array $milestoneTypes = [];
    private array $numerotations = [];
    private Slugify $slugger;

    const PREFIX_PERSON_ROLE = 'person';
    const PREFIX_ORGANIZATION_ROLE = 'organization';
    const PREFIX_MILESTONE = 'milestone';

    const PREFIX_NUMEROTATION = 'numerotation';


    protected function getNormalizedKey(string $label, string $prefix = '', string $suffix = ''): string
@@ -44,11 +45,21 @@ class ProjectToArrayFormatter implements IProjectFormater
        return $this->getNormalizedKey($role, self::PREFIX_MILESTONE);
    }

    public function configure(array $rolesPerson, array $rolesOrganization, array $milestoneTypes): void
    protected function getNumerotationKey(string $num): string
    {
        return $this->getNormalizedKey($num, self::PREFIX_NUMEROTATION);
    }

    public function configure(
        array $rolesPerson,
        array $rolesOrganization,
        array $milestoneTypes,
        array $numerotations
    ): void {
        $this->rolesPerson = $rolesPerson;
        $this->rolesOrganization = $rolesOrganization;
        $this->milestoneTypes = $milestoneTypes;
        $this->numerotations = $numerotations;
        $this->slugger = new Slugify();
    }

@@ -77,6 +88,11 @@ class ProjectToArrayFormatter implements IProjectFormater
        $financialImpacts = [];
        $disciplines = [];

        $numerotations = [];
        foreach ($this->numerotations as $num) {
            $numerotations[$this->getNumerotationKey($num)] = [];
        }

        // Données aggrégées
        $amount = 0.0;
        $pfi = [];
@@ -192,6 +208,14 @@ class ProjectToArrayFormatter implements IProjectFormater
                    $milestones[$type][] = $d;
                }
            }

            foreach ($this->numerotations as $num) {
                $keyNum = $this->getNumerotationKey($num);
                $value = $activity->getNumber($num);
                if ($value) {
                    $numerotations[$keyNum][] = $value;
                }
            }
        }

        $output['amount'] = $amount;
@@ -222,6 +246,10 @@ class ProjectToArrayFormatter implements IProjectFormater
            $output[$this->getMilestoneTypeKey($type)] = implode(', ', $p);
        }

        foreach ($numerotations as $key => $numbers) {
            $output[$key] = implode(', ', $numbers);
        }

        return $output;
    }

@@ -235,7 +263,6 @@ class ProjectToArrayFormatter implements IProjectFormater
        static $headers;

        if ($headers === null) {

            $headers = [
                "id" => "Id Project",
                "acronym" => "Acronyme",
@@ -271,6 +298,10 @@ class ProjectToArrayFormatter implements IProjectFormater
            foreach ($this->milestoneTypes as $t) {
                $headers[$this->getMilestoneTypeKey($t)] = $t;
            }

            foreach ($this->numerotations as $n) {
                $headers[$this->getNumerotationKey($n)] = $n;
            }
        }

        return $headers;
+16 −8
Changes for module/Oscar/src/Oscar/Service/ProjectService.php: 16 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -318,7 +318,9 @@ class ProjectService implements UseServiceContainer
                ->getAvailabledRolesOrganizationActivity();
            $milestones = $this->getProjectGrantService()->getMilestoneService()
                ->getMilestoneTypeFlat();
            $formatter->configure($rolesPerson, $rolesOrganizations, $milestones);

            $numerotations = $this->getProjectGrantService()->getOscarConfigurationService()->getNumerotationKeys();
            $formatter->configure($rolesPerson, $rolesOrganizations, $milestones, $numerotations);
            return $formatter;
        }
        throw new OscarException(sprintf(_("Formatteur de projet '%s' inconnue"), $format));
@@ -454,11 +456,9 @@ class ProjectService implements UseServiceContainer
    {
        $date = new \DateTime();
        try {

            /** @var ProjectMember $projectMember */
            foreach ($project->getPersons() as $projectMember) {
                if ($projectMember->getPerson()->getId() == $from->getId()) {

                    if ($projectMember->isActive()) {
                        $role = $projectMember->getRoleObj();
                        $projectMember->setDateEnd($date);
@@ -471,12 +471,19 @@ class ProjectService implements UseServiceContainer
                }
            }
        } catch (\Exception $e) {
          throw new OscarException(sprintf(_("Impossible de remplacer '%s' par '%s' dans le projet '%s'", $from, $to, $project)));
            throw new OscarException(
                sprintf(_("Impossible de remplacer '%s' par '%s' dans le projet '%s'", $from, $to, $project))
            );
        }
    }

    public function addProjectPerson( Project $project, Person $person, Role $role, ?\DateTime $start = null, ?\DateTime $end = null ):void
    {
    public function addProjectPerson(
        Project $project,
        Person $person,
        Role $role,
        ?\DateTime $start = null,
        ?\DateTime $end = null
    ): void {
        $this->getPersonService()->personProjectAdd($project, $person, $role, $start, $end);
    }

@@ -510,7 +517,6 @@ class ProjectService implements UseServiceContainer
        $dateStart,
        $dateEnd
    ): void {

        try {
            $update = $role->isPrincipal() != $projectPartner->getRoleObj()->isPrincipal();

@@ -525,7 +531,9 @@ class ProjectService implements UseServiceContainer
                $this->getGearmanJobLauncherService()->triggerUpdateNotificationProject($projectPartner->getProject());
            }

            $this->getGearmanJobLauncherService()->triggerUpdateSearchIndexOrganization($projectPartner->getOrganization());
            $this->getGearmanJobLauncherService()->triggerUpdateSearchIndexOrganization(
                $projectPartner->getOrganization()
            );
            $this->getGearmanJobLauncherService()->triggerUpdateSearchIndexProject($projectPartner->getProject());
        } catch (\Exception $e) {
            $msg = "Impossible de modifier l'organisation dans le projet";