Commit ea9e719f authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

- Mise à jour des formats de date lors de l'exportation des projet

parent bbccd0bc
Loading
Loading
Loading
Loading
Loading
+30 −29
Original line number Diff line number Diff line
@@ -182,35 +182,36 @@ class ProjectController extends AbstractOscarController

    public function exportAction()
    {
        $id = $this->params()->fromRoute('id', null);
        if (!$id) {
            throw new OscarException(sprintf("Impossible de charger le projet, paramètre ID manquant."));
        }
        try {
            $project = $this->getProjectService()->getProject($id);
            $formatter = new ProjectToArrayFormatter();

            $rolesPerson = $this->getOscarUserContextService()->getAvailabledRolesPersonActivity();
            $rolesOrganizations = $this->getOscarUserContextService()->getAvailabledRolesOrganizationActivity();
            $milestones = $this->getProjectGrantService()->getMilestoneService()->getMilestoneTypeFlat();

            $formatter->configure($rolesPerson, $rolesOrganizations, $milestones);
            $data = $formatter->format($project);

            echo '<table border="1">';
            foreach ($data as $key=>$value) {
                echo "<tr>";
                echo "<th>".$key."</th>";
                echo "<td>".$value."</td>";
                echo "</tr>";
            }
            echo "</table>";
            die();
        } catch (\Exception $e) {
            throw new OscarException(sprintf("Impossible de charger le projet(%s)", $id));
        }
        die("DONNEES");
        return $data;
        // @todo A Supprimer
//        $id = $this->params()->fromRoute('id', null);
//        if (!$id) {
//            throw new OscarException(sprintf("Impossible de charger le projet, paramètre ID manquant."));
//        }
//        try {
//            $project = $this->getProjectService()->getProject($id);
//            $formatter = new ProjectToArrayFormatter();
//
//            $rolesPerson = $this->getOscarUserContextService()->getAvailabledRolesPersonActivity();
//            $rolesOrganizations = $this->getOscarUserContextService()->getAvailabledRolesOrganizationActivity();
//            $milestones = $this->getProjectGrantService()->getMilestoneService()->getMilestoneTypeFlat();
//
//            $formatter->configure($rolesPerson, $rolesOrganizations, $milestones);
//            $data = $formatter->format($project);
//
//            echo '<table border="1">';
//            foreach ($data as $key=>$value) {
//                echo "<tr>";
//                echo "<th>".$key."</th>";
//                echo "<td>".$value."</td>";
//                echo "</tr>";
//            }
//            echo "</table>";
//            die();
//        } catch (\Exception $e) {
//            throw new OscarException(sprintf("Impossible de charger le projet(%s)", $id));
//        }
//        die("DONNEES");
//        return $data;
    }

    /**
+8 −5
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ class ProjectToArrayFormatter implements IProjectFormater
    private array $rolesOrganization = [];
    private array $milestoneTypes = [];
    private array $numerotations = [];
    private string $dateFormat;
    private Slugify $slugger;

    const PREFIX_PERSON_ROLE = 'person';
@@ -54,13 +55,15 @@ class ProjectToArrayFormatter implements IProjectFormater
        array $rolesPerson,
        array $rolesOrganization,
        array $milestoneTypes,
        array $numerotations
        array $numerotations,
        string $dateFormat = 'Y-m-d'
    ): void {
        $this->rolesPerson = $rolesPerson;
        $this->rolesOrganization = $rolesOrganization;
        $this->milestoneTypes = $milestoneTypes;
        $this->numerotations = $numerotations;
        $this->slugger = new Slugify();
        $this->dateFormat = $dateFormat;
    }

    public function format(Project $project): array
@@ -150,9 +153,9 @@ class ProjectToArrayFormatter implements IProjectFormater
            $status[] = $activity->getStatusLabel();

            // Dates
            $startValue = $activity->getDateStartStr();
            $endValue = $activity->getDateEndStr();
            $signedValue = $activity->getDateSignedStr();
            $startValue = $activity->getDateStartStr($this->dateFormat);
            $endValue = $activity->getDateEndStr($this->dateFormat);
            $signedValue = $activity->getDateSignedStr($this->dateFormat);

            if ($startValue && ($output['absStart'] > $startValue || $output['absStart'] == "")) {
                $output['absStart'] = $startValue;
@@ -202,7 +205,7 @@ class ProjectToArrayFormatter implements IProjectFormater
            /** @var ActivityDate $m */
            foreach ($activity->getMilestones() as $m) {
                $type = $m->getType()->getLabel();
                $d = $m->getDateStartStr();
                $d = $m->getDateStartStr($this->dateFormat);

                if ($d) {
                    $milestones[$type][] = $d;
+1 −1
Original line number Diff line number Diff line
@@ -541,7 +541,7 @@ class OscarConfigurationService implements ServiceLocatorAwareInterface

    public function getExportDateFormat()
    {
        return $this->getEditableConfKey('export_dateformat', 'y-m-d');
        return $this->getEditableConfKey('export_dateformat', 'Y-m-d');
    }

    public function setExportDateFormat($string)
+2 −1
Original line number Diff line number Diff line
@@ -320,7 +320,8 @@ class ProjectService implements UseServiceContainer
                ->getMilestoneTypeFlat();

            $numerotations = $this->getProjectGrantService()->getOscarConfigurationService()->getNumerotationKeys();
            $formatter->configure($rolesPerson, $rolesOrganizations, $milestones, $numerotations);
            $dateFormat = $this->getProjectGrantService()->getOscarConfigurationService()->getExportDateFormat();
            $formatter->configure($rolesPerson, $rolesOrganizations, $milestones, $numerotations, $dateFormat);
            return $formatter;
        }
        throw new OscarException(sprintf(_("Formatteur de projet '%s' inconnue"), $format));