Commit aa792c71 authored by Stéphane Bouvry's avatar Stéphane Bouvry
Browse files

Procédure de conversion des anciens créneaux (Unicaen)

parent d94bc071
Loading
Loading
Loading
Loading
+2 −1
Changes for install/demo/persons.json: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -39,7 +39,8 @@
    "lastname": "Grossmann",
    "mail": "marcel.grossmann@jacksay.com",
    "login": "marcelgrossmann",
    "uid": "marcelgrossmann"
    "uid": "marcelgrossmann",
    "referents": ["maxplank"]
  },
  {
    "firstname": "Max",
+2 −1
Changes for module/Oscar/config/module.config.php: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -207,7 +207,8 @@ return array(
                        'usurpation', 'excel', 'organizationLeader',
                        'declarant', 'declarantAPI', 'validationActivity',
                        'validationActivity2', 'validationHWPPerson', 'validatePersonPeriod',
                        'importIcal', 'declarations', 'resumeActivity'
                        'importIcal', 'declarations', 'resumeActivity',
                        'resolveInvalidLabels'
                    ],
                    'roles' => ['user']
                ],
+6 −0
Changes for module/Oscar/config/routes.yml: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -78,6 +78,12 @@ timesheet:
            controller: Timesheet
    may_terminate: false
    child_routes:
        activity:
            type: segment
            options:
                route: /resolve-invalid-labels
                defaults:
                    action: resolveInvalidLabels
        activity:
            type: segment
            options:
+37 −0
Changes for module/Oscar/src/Oscar/Controller/TimesheetController.php: 37 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -1125,6 +1125,43 @@ class TimesheetController extends AbstractOscarController
        return [];
    }

    public function resolveInvalidLabelsAction(){

        // TODO
        // $this->getOscarUserContext()->check(Privileges::)

        $invalidLabels = $this->getTimesheetService()->getInvalidLabels();
        $destinations = $this->getTimesheetService()->getOthersWP();
        $message = "";

        if( $this->getHttpXMethod() == 'POST' ){

            $correspondances = $this->params()->fromPost('labels');
            $resolve = [];

            foreach( $correspondances as $correspondance=>$destination ){
                if( $destination == "" ) continue;

                if( !in_array($correspondance, $invalidLabels) ){
                    throw new OscarException(sprintf("Opération interrompue : L'intitulé %s n'existe pas", $correspondance));
                }
                if( !array_key_exists($destination, $destinations) ){
                    throw new OscarException(sprintf("Opération interrompue : La destination %s n'existe pas", $correspondance));
                }

                $resolve[$correspondance] = $destination;
            }
            $this->getTimesheetService()->maintenanceConvertHorsLots($resolve);
            $message = "Opération terminée";
        }

        return [
            'message' => $message,
            'datas' => $invalidLabels,
            'othersWP'=> $destinations
        ];
    }

    /**
     * Déclaration des heures.
     */
+46 −0
Changes for module/Oscar/src/Oscar/Service/TimesheetService.php: 46 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -2967,6 +2967,52 @@ class TimesheetService implements ServiceLocatorAwareInterface, EntityManagerAwa
        return $validations;
    }

    public function getInvalidLabels(){
        $output = [];

        $horsLots = [];
        foreach ($this->getOthersWP() as $other) {
            $horsLots[] = $other['code'];
        }

        //
        $query = $this->getEntityManager()->getRepository(TimeSheet::class)->createQueryBuilder('t')
            ->select('DISTINCT t.label')
            ->where('t.label NOT IN(:othersWP) AND t.activity IS NULL')
            ->getQuery()
            ->setParameters([
                'othersWP' => $horsLots
            ]);

        foreach( $query->getArrayResult() as $d ){
            $output[] = $d['label'];

        }

        return $output;
    }

    public function maintenanceConvertHorsLots( $correspondances ){

        $labels = array_keys($correspondances);
        $query = $this->getEntityManager()->getRepository(TimeSheet::class)->createQueryBuilder('t')
            ->where('t.label IN(:othersWP) AND t.activity IS NULL')
            ->getQuery()
            ->setParameters([
                'othersWP' => $labels
            ]);
        /** @var TimeSheet $timesheet */
        foreach ($query->getResult() as $timesheet){
            $oldLabel = $timesheet->getLabel();
            $newLabel = $correspondances[$oldLabel];

            $timesheet->setLabel($newLabel)
                ->setComment($timesheet->getComment() . " " . $oldLabel);
        }

        $this->getEntityManager()->flush();
    }

    public function validation(ValidationPeriod $period, Person $validateur, $message = "")
    {
        if ($period->isValidator($validateur)) {
Loading