Commit 72afdc2f authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

Mise à jour de l'interface de présentation des documents publiques en...

Mise à jour de l'interface de présentation des documents publiques en intégrant les sections de document
parent ba9ec6c7
Loading
Loading
Loading
Loading
+74 −1
Changes for module/Oscar/src/Oscar/Controller/AdministrativeDocumentController.php: 74 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -10,7 +10,9 @@ namespace Oscar\Controller;

use Oscar\Entity\AbstractVersionnedDocument;
use Oscar\Entity\AdministrativeDocument;
use Oscar\Entity\AdministrativeDocumentSection;
use Oscar\Exception\OscarException;
use Oscar\Provider\Privileges;
use Oscar\Service\VersionnedDocumentService;

class AdministrativeDocumentController extends AbstractOscarController
@@ -60,11 +62,72 @@ class AdministrativeDocumentController extends AbstractOscarController
     * @return array
     */
    public function indexAction() {

        $method = $this->getHttpXMethod();
        if( $method == "POST" ){
            $this->getOscarUserContext()->check(Privileges::ADMINISTRATIVE_DOCUMENT_DELETE);
            $sectionId = $this->params()->fromPost('section_id');
            $section = null;
            if( $sectionId )
                $section = $this->getEntityManager()->getRepository(AdministrativeDocumentSection::class)->find($sectionId);

            $documentId = $this->params()->fromPost('id');
            /** @var AdministrativeDocument $document */
            $document = $this->getEntityManager()->getRepository(AdministrativeDocument::class)->find($documentId);
            if( !$document ){
                return $this->getResponseInternalError("Document introuvable");
            }

            $documents = $this->getEntityManager()->getRepository(AdministrativeDocument::class)->findBy(['fileName' => $document->getFileName()]);

            foreach ($documents as $document) {
                $document->setSection($section);
            }

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

        return [
            'documents' => $this->getVersionnedDocumentService()->getDocumentsPublished()->getQuery()->getResult()
            'documents' => $this->getAdministrativeDocumentPacked(),
            'sections' => $this->getEntityManager()->getRepository(AdministrativeDocumentSection::class)->findAll(),
            'moveable' => $this->getOscarUserContext()->hasPrivileges(Privileges::MAINTENANCE_DOCPUBSEC_MANAGE)
        ];
    }

    public function getAdministrativeDocumentPacked(){
        $query = $this->getEntityManager()->getRepository(AdministrativeDocument::class)->createQueryBuilder('d')
            ->leftJoin('d.section', s)
            ->leftJoin('d.person', 'o')
            ->orderBy('d.fileName', 'ASC')
            ->addOrderBy('d.version', 'DESC')
            ->where('d.status = :status');

        $query->setParameter('status', AbstractVersionnedDocument::STATUS_PUBLISH);

        $output = [];
        $documents = $query->getQuery()->getResult();

        /** @var AdministrativeDocument $document */
        foreach ($documents as $document) {
            $section = $document->getSection() ? $document->getSection()->getLabel() : "";
            if( !array_key_exists($section, $output) ){
                $output[$section] = [];
            }

            $filename = $document->getFileName();
            if( !array_key_exists($filename, $output[$section]) ){
                $output[$section][$filename] = [
                    'main' => $document,
                    'older' => []
                ];
            } else {
                $output[$section][$filename]['older'][] = $document;
            }
        }

        return $output;
    }

    /**
     * Procédure générique pour l'envoi des fichiers.
     *
@@ -74,15 +137,19 @@ class AdministrativeDocumentController extends AbstractOscarController
        try {
            $docId = $this->params()->fromQuery('id', null);
            $docReplaced = null;
            $section = null;
            if ($docId) {
                /** @var AdministrativeDocument $doc */
                if ($doc = $this->getEntityManager()->getRepository(AdministrativeDocument::class)->find($docId)) {
                    $docReplaced = $doc->getFileName();
                    $section = $doc->getSection();
                }
            }
            $documentService = $this->getVersionnedDocumentService();

            $documentService->performRequest($this->getRequest(), $docReplaced,
                function (AbstractVersionnedDocument $document) {

                    $this->getActivityLogService()->addUserInfo(
                        sprintf("a déposé le document '%s'",
                            $document->getFileName()), 'AdministrativeDocument',
@@ -90,6 +157,11 @@ class AdministrativeDocumentController extends AbstractOscarController
                    );

                    $this->redirect()->toRoute('administrativedocument');
                },

                function( AdministrativeDocument $document, $datas ) use ($documentService, $section){
                    $document->setSection($section);
                    return $document;
                });
            return [

@@ -119,6 +191,7 @@ class AdministrativeDocumentController extends AbstractOscarController
     * @throws OscarException
     */
    public function deleteAction() {

        $idDoc = $this->params()->fromRoute('id');
        try {
            $this->getVersionnedDocumentService()->deleteDocument($idDoc);
+7 −0
Changes for module/Oscar/src/Oscar/Entity/AdministrativeDocument.php: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -49,4 +49,11 @@ class AdministrativeDocument extends AbstractVersionnedDocument
    {
        $this->section = $section;
    }

    function __toString()
    {
        return parent::__toString(); // TODO: Change the autogenerated stub
    }


}
 No newline at end of file
+9 −2
Changes for module/Oscar/src/Oscar/Entity/AdministrativeDocumentSection.php: 9 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ class AdministrativeDocumentSection
    /**
     * @return ArrayCollection
     */
    public function getDocuments(): ArrayCollection
    public function getDocuments()
    {
        return $this->documents;
    }
@@ -75,7 +75,7 @@ class AdministrativeDocumentSection
    /**
     * @param ArrayCollection $documents
     */
    public function setDocuments(ArrayCollection $documents): void
    public function setDocuments($documents)
    {
        $this->documents = $documents;
    }
@@ -111,4 +111,11 @@ class AdministrativeDocumentSection
    {
        $this->description = $description;
    }

    public function __toString()
    {
        return $this->getLabel();
    }


}
 No newline at end of file
+1 −2
Changes for module/Oscar/src/Oscar/Service/VersionnedDocumentService.php: 1 added line, 2 removed lines.
Original line number Diff line number Diff line
@@ -105,7 +105,7 @@ class VersionnedDocumentService {
            try {
                $doc = $this->getDocument($document)->getQuery()->getSingleResult();
            } catch( \Exception $e ){
                throw new OscarException();
                throw new OscarException("Document introuvable");
            }
        } else {
            $doc = $document;
@@ -118,7 +118,6 @@ class VersionnedDocumentService {
        foreach( $documents as $d ){
            $d->setStatus(AbstractVersionnedDocument::STATUS_DELETE);
        }

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

+99 −33
Changes for module/Oscar/view/oscar/administrative-document/index.phtml: 99 added lines, 33 removed lines.
Original line number Diff line number Diff line
<?php
/**
 * @author Stéphane Bouvry<stephane.bouvry@unicaen.fr>
 * @date: 16-06-17 14:56
 * @copyright Certic (c) 2016
 */
// Organisation des données pour la vue

$docsOrganized = [];
/** @var \Oscar\Entity\AdministrativeDocument $document */
foreach( $documents as $document ) {
    if( !isset($docsOrganized[$document->getFileName()]) ) {
        $docsOrganized[$document->getFileName()] = [
            'main' => $document,
            'older' => []
        ];
        continue;
    }
    $currentDoc = &$docsOrganized[$document->getFileName()];

    if( $document->getVersion() > $currentDoc['main']->getVersion() ){
        $currentDoc['older'][] = $currentDoc['main'];
        $currentDoc['main'] = $document;
    } else {
        $currentDoc['older'][] = $document;
    }
}
?>



<div class="container">
    <h1>
        <i class="icon-book"></i> Documents pratiques
    </h1>

    <?php
    $downloadable =  $this->grant()->connected();
    foreach( $docsOrganized as $document ): ?>
    foreach( $documents as $section=>$docs ): ?>
    <h2><?= $section ?: '<em>Général</em>' ?> <small><?= count($docs) ?> document(s)</small></h2>
    <?php foreach ($docs as $document): ?>
    <article class="card">
        <h3 class="card-title">
            <i class="picto icon-doc doc-<?= $document['main']->getExtension() ?>"></i>
@@ -46,18 +18,34 @@ foreach( $documents as $document ) {
            </small>
        </h3>
        <nav class="text-right show-over">

            <?php if( $moveable): ?>
                <form action="" method="post" class="form-inline">
                    <input type="hidden" name="id" value="<?= $document['main']->getId() ?>" />
                    <select name="section_id" id="">
                        <option value="">Hors section (générale)</option>
                        <?php foreach ($sections as $section): ?>
                            <option value="<?= $section->getId() ?>"><?= $section ?></option>
                        <?php endforeach; ?>
                    </select>
                    <button type="submit">Enregistrer</button>
                </form>
            <?php endif; ?>

            <?php if($downloadable): ?>
                <a class="btn btn-default btn-xs" href="<?= $this->url('administrativedocument/download', ['id' => $document['main']->getId()]) ?>">
                    <i class="icon-download-outline"></i>
                    Télécharger le fichier
                </a>
            <?php endif; ?>

            <?php if($this->grant()->privilege(\Oscar\Provider\Privileges::ADMINISTRATIVE_DOCUMENT_NEW)): ?>
                <a class="btn btn-default btn-xs" href="<?= $this->url('administrativedocument/upload', ['id' => $document['main']->getId()]) ?>?id=<?= $document['main']->getId() ?>">
                    <i class="icon-attach-1"></i>
                    Téléverser une nouvelle version
                </a>
            <?php endif; ?>

            <?php if($this->grant()->privilege(\Oscar\Provider\Privileges::ADMINISTRATIVE_DOCUMENT_DELETE)): ?>
                <a class="btn btn-default btn-xs" href="<?= $this->url('administrativedocument/delete', ['id' => $document['main']->getId()]) ?>?id=<?= $document['main']->getId() ?>">
                    <i class="icon-trash"></i>
@@ -69,7 +57,6 @@ foreach( $documents as $document ) {
            Téléversé le <time><?= $this->moment($document['main']->getDateUpdoad())->full() ?></time>
            par <?= $document['main']->getPerson() ? $this->person($document['main']->getPerson()) : '<span class="no-data">Inconnu</span>' ?>
        </p>

        <div class="card-content versions">
            <?php if( count($document['older']) > 0 ):?>
                <h4 class="opener"><i class="icon-opener"></i> Versions précédentes</h4>
@@ -95,6 +82,85 @@ foreach( $documents as $document ) {
            <?php endif; ?>
        </div>
    </article>

    <?php /*<article class="card">
        <h3 class="card-title">
            <i class="picto icon-doc doc-<?= $document['main']->getExtension() ?>"></i>
            <?= $document['main']->getFileName() ?>
            <small>
                version <?= $document['main']->getVersion() ?>,
                <?= $this->fileSize($document['main']->getFileSize()) ?>
            </small>
        </h3>
        <nav class="text-right show-over">

            <?php if( $moveable): ?>
                <form action="" method="post" class="form-inline">
                    <input type="hidden" name="id" value="<?= $document['main']->getId() ?>" />
                    <select name="section_id" id="">
                        <option value="">Hors section (générale)</option>
                        <?php foreach ($sections as $section): ?>
                        <option value="<?= $section->getId() ?>"><?= $section ?></option>
                        <?php endforeach; ?>
                    </select>
                    <button type="submit">Enregistrer</button>
                </form>
            <?php endif; ?>

            <?php if($downloadable): ?>
            <a class="btn btn-default btn-xs" href="<?= $this->url('administrativedocument/download', ['id' => $document['main']->getId()]) ?>">
                <i class="icon-download-outline"></i>
                Télécharger le fichier
            </a>
            <?php endif; ?>
            <?php if($this->grant()->privilege(\Oscar\Provider\Privileges::ADMINISTRATIVE_DOCUMENT_NEW)): ?>
            <a class="btn btn-default btn-xs" href="<?= $this->url('administrativedocument/upload', ['id' => $document['main']->getId()]) ?>?id=<?= $document['main']->getId() ?>">
                <i class="icon-attach-1"></i>
                Téléverser une nouvelle version
            </a>
            <?php endif; ?>
            <?php if($this->grant()->privilege(\Oscar\Provider\Privileges::ADMINISTRATIVE_DOCUMENT_DELETE)): ?>
                <a class="btn btn-default btn-xs" href="<?= $this->url('administrativedocument/delete', ['id' => $document['main']->getId()]) ?>?id=<?= $document['main']->getId() ?>">
                    <i class="icon-trash"></i>
                    Supprimer
                </a>
            <?php endif; ?>
        </nav>
        <p class="text-highlight">
            Téléversé le <time><?= $this->moment($document['main']->getDateUpdoad())->full() ?></time>
            par <?= $document['main']->getPerson() ? $this->person($document['main']->getPerson()) : '<span class="no-data">Inconnu</span>' ?>
        </p>
        <p>
            <?= $document['main']->getSection() ?: "-" ?>
        </p>

        <div class="card-content versions">
            <?php if( count($document['older']) > 0 ):?>
                <h4 class="opener"><i class="icon-opener"></i> Versions précédentes</h4>
                <div class="details" style="display: none">
                <?php foreach( $document['older'] as $subdoc ): ?>
                <article class="subdoc text-highlight">
                    <?php if($downloadable): ?>
                    <a href="<?= $this->url('administrativedocument/download', ['id' => $subdoc->getId()]) ?>" download="true" >
                    <?php endif; ?>
                    <i class="picto icon-doc doc-<?= $subdoc->getExtension() ?>"></i>
                    <strong>
                        <?= $subdoc->getFileName() ?>,
                        version <?= $subdoc->getVersion() ?></small></strong>,
                        téléversé <time><?= $this->moment($subdoc->getDateUpdoad())->since() ?></time>
                        par <span class="owner"><?= $subdoc->getPerson() ? $this->person($subdoc->getPerson()) : 'Anonymous' ?></span>
                    <?php if($downloadable): ?>
                    </a>
                    <?php endif; ?>

                </article>
                <?php endforeach; ?>
                </div>
            <?php endif; ?>
        </div>
*/ ?>

    <?php endforeach; ?>
    <?php endforeach; ?>
    <hr>
    <?php if($this->grant()->privilege(\Oscar\Provider\Privileges::ADMINISTRATIVE_DOCUMENT_NEW)): ?>