Commit 4be940ed authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

Ajout des sections dans le formulaire d'upload et gestion des changement de...

Ajout des sections dans le formulaire d'upload et gestion des changement de section lors d'un réupload
parent 1191a4c7
Loading
Loading
Loading
Loading
+24 −2
Changes for module/Oscar/src/Oscar/Controller/AdministrativeDocumentController.php: 24 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -138,11 +138,13 @@ class AdministrativeDocumentController extends AbstractOscarController
            $docId = $this->params()->fromQuery('id', null);
            $docReplaced = null;
            $section = null;
            $defaultSection = null;
            if ($docId) {
                /** @var AdministrativeDocument $doc */
                if ($doc = $this->getEntityManager()->getRepository(AdministrativeDocument::class)->find($docId)) {
                    $docReplaced = $doc->getFileName();
                    $section = $doc->getSection();
                    $defaultSection = $section->getId();
                }
            }
            $documentService = $this->getVersionnedDocumentService();
@@ -160,11 +162,31 @@ class AdministrativeDocumentController extends AbstractOscarController
                },

                function( AdministrativeDocument $document, $datas ) use ($documentService, $section){
                    $document->setSection($section);
                    $sec = null;
                    $secInit = $section ? $section->getId() : null;
                    $secId = null;
                    if( $datas['section_id'] ){
                        $sec = $this->getEntityManager()->getRepository(AdministrativeDocumentSection::class)->find($datas['section_id']);
                        $secId = $sec->getId();
                    }

                    if( $secInit != $secId ){
                        $docs = $this->getEntityManager()->getRepository(AdministrativeDocument::class)->findBy([
                            'fileName' => $document->getFileName()
                        ]);
                        foreach ($docs as $doc) {
                            $doc->setSection($sec);
                        }
                        $this->getEntityManager()->flush($docs);
                    }


                    $document->setSection($sec);
                    return $document;
                });
            return [

                "defaultSection" => $defaultSection,
                "sections" => $this->getEntityManager()->getRepository(AdministrativeDocumentSection::class)->findAll()
            ];
        } catch( \Exception $e ){
            throw new OscarException($e->getMessage());
+0 −1
Changes for module/Oscar/view/oscar/administration/accueil.phtml: 0 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -287,7 +287,6 @@
            </p>
        </article>


        <h2>
            <i class="icon-lock"></i>
            Privilèges et droits d'accès
+8 −9
Changes for module/Oscar/view/oscar/administrative-document/upload.phtml: 8 added lines, 9 removed lines.
Original line number Diff line number Diff line
<div class="container">
    <h1>Téléversement d'un document administratif</h1>

    <?php if( isset($data) && $data['error'] ):?>
        <div class="alert alert-danger">
            <?= $data['error'] ?>
        </div>
    <?php endif; ?>

    <form action="" method="post" enctype="multipart/form-data">
        <div class="row">

@@ -16,8 +14,14 @@
            </div>

            <div class="col-md-6">
                <label for="type">Type de document</label>
                <small>A venir</small>
                <label for="section">Section</label>
                <select name="section_id" id="section">
                    <option value="">Général</option>
                    <?php foreach ($sections as $section): ?>
                        <option value="<?= $section->getId() ?>" <?= $defaultSection == $section->getId() ? ' selected' : '' ?>><?= $section->getLabel() ?></option>
                    <?php endforeach; ?>
                </select>

            </div>
        </div>
        <div class="row">
@@ -35,11 +39,6 @@
                </div>
            </div>
        </div>





    </form>
</div>